/'* \file fb-doc_emit_callees.bas
\brief Emitter for the file \em fb-doc.lfn.

This file contains emitter functions for the \ref EmitterIF to 
generate the file \em fb-doc.lfn for the Doxygen Back-end. It's the 
default emitter in \em --list mode.

The emitters writes the names of all functions (SUB / FUNCTION / 
PROPERTY) to the output stream, one in a line, separated by a new 
line character "CHR(10)".

'/

CONST CALLEE_TR = !"\n" '*< Separator for entries in file \em fb-doc.lfn.

/'* \brief Emitter to generate a declaration line
\param P the parser calling this emitter

This emitter gets called when the parser is in a declaration (VAR / 
DIM / CONST / COMMON / EXTERN / STATIC). It generates a line for 
each variable name and sends it (them) to the output stream.

'/
SUB callees_decl_ CDECL(BYVAL P AS Parser PTR)
  WITH *P
    SELECT CASE AS CONST *.StaTok
    CASE .TOK_SUB, .TOK_FUNC, .TOK_PROP, .TOK_OPER ' , .TOK_CTOR, .TOK_DTOR
    CASE ELSE : EXIT SUB
    END SELECT : IF 0 = .NamTok ORELSE 0 = .FunTok THEN EXIT SUB
    
    cNam(P)
    Code(CALLEE_TR)
  END WITH
END SUB


/'* \brief Emitter to start parsing of blocks
\param P the parser calling this emitter

This emitter gets called when the parser finds a block (TYPE / UNION 
/ ENUM). It starts the scanning process in the block.

'/
SUB callees_class_ CDECL(BYVAL P AS Parser PTR)
  WITH *P
    IF OPT->AllCallees THEN .parseBlockTyUn(@callees_decl_)
  END WITH
END SUB


/'* \brief Emitter to generate a line for a function name
\param P the parser calling this emitter

This emitter gets called when the parser finds a function (SUB / 
FUNCTION / PROPERTY). It generates a line with the name of the 
function and sends it to the output stream.

'/
SUB callees_func_ CDECL(BYVAL P AS Parser PTR) ' !!! ToDo member functions
  WITH *P
    cNam(P)
    Code(CALLEE_TR)
  END WITH
END SUB


/'* \brief Emitter to import a source file
\param P the parser calling this emitter

This emitter gets called when the parser finds an \#INCLUDE 
statement and option \em --recursiv is given. It checks if the file 
has been done allready. If not, it creates a new #Parser and starts 
the scanning process.

'/
SUB callees_include CDECL(BYVAL P AS Parser PTR)
  WITH *P
    IF 0 = OPT->InTree THEN EXIT SUB
    VAR n = .SubStr(.NamTok) : n = MID(n, 2, LEN(n) - 2)

    STATIC AS STRING done
    VAR f = !"\n" & CURDIR & SLASH & n & !"\n"
    IF .DivTok THEN IF INSTR(done, f) THEN EXIT SUB
    done &= f

    VAR fnr = FREEFILE : IF OPEN(n FOR INPUT AS #fnr) THEN EXIT SUB ELSE CLOSE #fnr
    VAR oldpath = CURDIR
    VAR c = INSTRREV(n, SLASH) : IF c THEN CHDIR(LEFT(n, c - 1))
    VAR pars = NEW Parser(OPT->EmitIF)

    PRINT : MSG_LINE(n)
    pars->Ocha = .Ocha
    pars->File_(MID(n, c + 1))

    DELETE pars : IF c THEN CHDIR(oldpath)
  END WITH
END SUB


WITH_NEW_EMITTER("Callees")
  .Clas_ = @callees_class_
  .Unio_ = @callees_class_
  .Func_ = @callees_func_
  .Decl_ = @callees_decl_
  .Incl_ = @callees_include
END WITH

