fbdoc  1.0.1
FreeBASIC documentation tool
fbdoc_emitters.bas File Reference

Code for EmitterIF and auxiliary functions. More...

#include "fbdoc_options.bi"
#include "fbdoc_version.bi"
Include dependency graph for fbdoc_emitters.bas:

Go to the source code of this file.

Functions

SUB_CDECL emit_comments (BYVAL_AS_Parser_PTR P, BYVAL_AS_INTEGER Stop_)
 Handler to export comments. More...
 
SUB_CDECL cppNam (BYVAL_AS_Parser_PTR P)
 Export the name (including double colons for member functions) More...
 
SUB_CDECL cNam (BYVAL_AS_Parser_PTR P)
 Export the name (including dots for member functions) More...
 
SUB_CDECL CreateIni (BYVAL_AS_Parser_PTR P)
 Export the initializer(s) for a variable. More...
 
SUB_CDECL cArrDim (BYVAL_AS_Parser_PTR P)
 The dimension of a variable. More...
 
SUB_CDECL cppCreateTypNam (BYVAL_AS_Parser_PTR P)
 Create pseude C declaration. More...
 
SUB_CDECL cCreateTypNam (BYVAL_AS_Parser_PTR P)
 Create C declaration. More...
 
SUB_CDECL cppEntryListParameter (BYVAL_AS_Parser_PTR P)
 Handler for a parameter declaration in CPP style. More...
 
SUB_CDECL cEntryListParameter (BYVAL_AS_Parser_PTR P)
 Handler for a parameter declaration in C-style. More...
 
SUB_CDECL cppCreateFunction (BYVAL_AS_Parser_PTR P)
 Create a function declaration. More...
 
SUB_CDECL cCreateFunction (BYVAL_AS_Parser_PTR P)
 Create a function declaration. More...
 
SUB_CDECL emit_error (BYVAL_AS_Parser_PTR P)
 Emitter for an error message. More...
 
SUB_CDECL emit_source (BYVAL_AS_Parser_PTR P, BYVAL_AS_INTEGER E)
 Handler to exporting FreeBASIC source code. More...
 
SUB_CDECL geany_init (BYVAL_AS_Parser_PTR P)
 Handler to initialize the source code export. More...
 
SUB_CDECL geany_exit (BYVAL_AS_Parser_PTR P)
 Handler to finalize the export of source code. More...
 

Detailed Description

Code for EmitterIF and auxiliary functions.

This file contains the main source for EmitterIF, used by all emitters. The Parser calls the matching function in the active EmitterIF, after scanning a relevant construct. The emitter function extracts the necessary information from the parser data, formats it as desired and sends it to the output stream.

The file also includes some helper functions to extract code and comments from the original source. And it contains the standard emitter to translate to pseudo C intermediate format, either in C or CPP style (the later is default, used for the Doxygen documentation back-end).

This format includes minimal C source code and all the documentation comments (multi line comment blocks or line end). In order to get the links working, which connects the documentation context and the source code listings, the emitter places all C constructs in the same line number as in the FB code. Also inside the lines, the emitter tries to place all constructs similar as in the FB source (but a comment inside a statement will be placed at the end of the corresponding C statement).

Definition in file fbdoc_emitters.bas.

Function Documentation

◆ emit_comments()

SUB_CDECL emit_comments ( BYVAL_AS_Parser_PTR  P,
BYVAL_AS_INTEGER  Stop_ 
)

Handler to export comments.

Parameters
Pthe parser calling this handler
Stop_the end position in the input buffer

Export the comments between the last position SrcBgn (= source begin) and the Stop_ position. After processing, the Stop_ position gets the new SrcBgn.

Definition at line 39 of file fbdoc_emitters.bas.

Here is the caller graph for this function:

◆ cppNam()

SUB_CDECL cppNam ( BYVAL_AS_Parser_PTR  P)

Export the name (including double colons for member functions)

Parameters
Pthe parser calling this emitter

This property reads the name of a construct from the input buffer and emits all words, concatenated by double colons.

Returns
the name including dots (colons)

Definition at line 89 of file fbdoc_emitters.bas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cNam()

SUB_CDECL cNam ( BYVAL_AS_Parser_PTR  P)

Export the name (including dots for member functions)

Parameters
Pthe parser calling this emitter

This sub reads the name of a construct from the input buffer and emits all words as in the original source.

Returns
the name including dots (colons)

Definition at line 114 of file fbdoc_emitters.bas.

Here is the caller graph for this function:

◆ CreateIni()

SUB_CDECL CreateIni ( BYVAL_AS_Parser_PTR  P)

Export the initializer(s) for a variable.

Parameters
Pthe parser calling this emitter

This sub reads the initializer from the input buffer and emits them unchanged. This may be a bunch of text in case of an array initializer.

Definition at line 136 of file fbdoc_emitters.bas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cArrDim()

SUB_CDECL cArrDim ( BYVAL_AS_Parser_PTR  P)

The dimension of a variable.

Parameters
Pthe parser calling this emitter

This property reads the dimension of a construct from the input buffer.

Returns
the name including round or squared brackets

Definition at line 188 of file fbdoc_emitters.bas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cppCreateTypNam()

SUB_CDECL cppCreateTypNam ( BYVAL_AS_Parser_PTR  P)

Create pseude C declaration.

Parameters
Pthe parser calling this emitter

Create a declaration for the construct at the current parser position using FB style. All FB keywords gets mangled to a single word to get a FreeBASIC look-and-feel in the documentation. Ie. we emit

  • "SUB Name();" (instead of "void Name(void);")
  • "INTEGER varnam" (instead of "int varname")
  • "BYREF_AS_STRING strng" (instead of "char** strng")
  • "FUNCTION_CDECL_AS_SINGLE xyz CDECL(BYVAL_AS_BYTE C)" (instead of "float xyz(char C)")
  • ...

The C lexer of the back-end (gtk-doc or Doxygen) interprets this single word as a C type declaration (or macro) and can handle FB source code that way.

Exeptions handled in this SUB:

  • TypTok = 0: no type, emit only the name (with a space in front)
  • NymTok = 0: no name, emit type and exit

Definition at line 238 of file fbdoc_emitters.bas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cCreateTypNam()

SUB_CDECL cCreateTypNam ( BYVAL_AS_Parser_PTR  P)

Create C declaration.

Parameters
Pthe parser calling this emitter

Create a C declaration for the construct at the current parser position. All FB keywords gets translated to their C expressions. Ie. we emit

  • "void Name(void);" (instead of "SUB Name();")
  • "int varname" (instead of "INTEGER varnam")
  • "char** strng" (instead of "BYREF_AS_STRING strng")
  • "float xyz(char C)" (instead of "FUNCTION_CDECL_AS_SINGLE xyz CDECL(BYVAL_AS_BYTE C)")
  • ...

The C source code is very useful when you use a library compiled with FreeBASIC in a other language like C or C++. fbdoc can auto-generate the header files (just check initializers and array dimensioning manually).

Exeptions handled in this SUB:

  • TypTok = 0: no type, emit only the name (with a space in from)
  • NymTok = 0: no name, emit type and exit
  • ParTok <> 0: parameter list, emit name and exit (no default value)

Definition at line 289 of file fbdoc_emitters.bas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cppEntryListParameter()

SUB_CDECL cppEntryListParameter ( BYVAL_AS_Parser_PTR  P)

Handler for a parameter declaration in CPP style.

Parameters
Pthe parser calling this handler

Generate a declaration for a parameter list. The declaration may be empty (), may have no name (prototype declaration) or may by an ellipsis ( ... ). Initializers get emitted "as-is".

We emit a space in front and a comma behind the parameter. When done the first space gets replaced by a '(' and the last comma gets replaced by a ')'.

Definition at line 348 of file fbdoc_emitters.bas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cEntryListParameter()

SUB_CDECL cEntryListParameter ( BYVAL_AS_Parser_PTR  P)

Handler for a parameter declaration in C-style.

Parameters
Pthe parser calling this handler

Generate a declaration for a parameter list. The declaration may be empty (), may have no name (prototype declaration) or may by an ellipsis ( ... ). Initializers get emitted "as-is", this means you have to check if they contain FB keywords (and translate manually, if so).

We emit a space in front and a comma behind the parameter. When done the first space gets replaced by a '(' and the last comma gets replaced by a ')'.

Definition at line 385 of file fbdoc_emitters.bas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cppCreateFunction()

SUB_CDECL cppCreateFunction ( BYVAL_AS_Parser_PTR  P)

Create a function declaration.

Parameters
Pthe parser calling this handler

Generate a declaration for a function (SUB, FUNCTION, DESTRUCTOR, CONSTRUCTOR, PROPERTY). We emit a type, a name and a parameter list.

Exceptions:

  • in a declaration a CONSTRUCTOR or DESTRUCTOR have no name

Definition at line 415 of file fbdoc_emitters.bas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cCreateFunction()

SUB_CDECL cCreateFunction ( BYVAL_AS_Parser_PTR  P)

Create a function declaration.

Parameters
Pthe parser calling this handler

Generate a declaration for a function (SUB, FUNCTION, DESTRUCTOR, CONSTRUCTOR, PROPERTY). We emit a type, a name and the parameter list.

Exceptions:

  • in a declaration a CONSTRUCTOR or DESTRUCTOR has no name. We use the block name instead.

Definition at line 456 of file fbdoc_emitters.bas.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_error()

SUB_CDECL emit_error ( BYVAL_AS_Parser_PTR  P)

Emitter for an error message.

Parameters
Pthe parser calling this handler

Generate an error output. When the parser detects an error it calls this function. Depending on the run-mode we do or do not emit an information. In mode –geany-mode (-g) the error message gets shown in the status line (or in the debug window).

Definition at line 491 of file fbdoc_emitters.bas.

Here is the caller graph for this function:

◆ emit_source()

SUB_CDECL emit_source ( BYVAL_AS_Parser_PTR  P,
BYVAL_AS_INTEGER  E 
)

Handler to exporting FreeBASIC source code.

Parameters
Pthe parser calling this handler
Ethe end position in the input buffer

Extract original source code from the input buffer Parser::Buf. The code starts at the last position and gets extracted up to the line end before the given position. This line end gets stored as the new 'last position'.

Definition at line 513 of file fbdoc_emitters.bas.

Here is the caller graph for this function:

◆ geany_init()

SUB_CDECL geany_init ( BYVAL_AS_Parser_PTR  P)

Handler to initialize the source code export.

Parameters
Pthe parser calling this handler

This emitter gets called before the parser starts its parsing process. It initializes the FB source code emission.

Definition at line 530 of file fbdoc_emitters.bas.

Here is the caller graph for this function:

◆ geany_exit()

SUB_CDECL geany_exit ( BYVAL_AS_Parser_PTR  P)

Handler to finalize the export of source code.

Parameters
Pthe parser calling this handler

This emitter gets called after the parser ends its parsing process. It sends the rest of the FB source code to the output stream.

Definition at line 542 of file fbdoc_emitters.bas.

Here is the caller graph for this function: