fb-doc  0.4.0
FreeBASIC documentation tool
py_ctypes.bas File Reference

Example code for an external emitter for Python bindings. More...

Include dependency graph for py_ctypes.bas:

Go to the source code of this file.

Macros

#define NEW_ENTRY   /* Code(NL & NL & "# " & MID(.Fnam, INSTRREV(.Fnam, SLASH) + 1) & ": " & .LineNo) */
 Macro to place a comment in to the output (file name and line number) More...
 

Functions

SUB genNLiteral (BYREF_AS_STRING T)
 Transform number literals. More...
 
FUNCTION_AS_STRING genCType (BYVAL_AS_Parser_PTR P)
 Transform a FB type in to a ctype. More...
 
SUB_CDECL py_entryListPara (BYVAL_AS_Parser_PTR P)
 Emitter to extract the types of a parameter list. More...
 
SUB_CDECL py_emitEnumNames (BYVAL_AS_Parser_PTR P)
 Emitter to generate a line for a ENUM block entry. More...
 
SUB_CDECL py_emitBlockNames (BYVAL_AS_Parser_PTR P)
 Emitter to generate a line for a TYPE / UNION block entry. More...
 
SUB_CDECL py_function (BYVAL_AS_Parser_PTR P)
 Emitter called when the Parser is on top of a function body. More...
 
SUB_CDECL py_declare (BYVAL_AS_Parser_PTR P)
 Emitter called when the Parser is at a variable declaration. More...
 
SUB_CDECL py_enum (BYVAL_AS_Parser_PTR P)
 Emitter called when the Parser is at the start of a ENUM block. More...
 
SUB_CDECL py_union (BYVAL_AS_Parser_PTR P)
 Emitter called when the Parser is at the start of a UNION block. More...
 
SUB_CDECL py_class (BYVAL_AS_Parser_PTR P)
 Emitter called when the Parser is at the start of a TYPE block. More...
 
SUB_CDECL py_define (BYVAL_AS_Parser_PTR P)
 Emitter called when the Parser is at an #DEFINE line or at the start of a #MACRO More...
 
SUB_CDECL py_include (BYVAL_AS_Parser_PTR P)
 Emitter called when the Parser is at an #INCLUDE line. More...
 
SUB_CDECL py_init (BYVAL_AS_Parser_PTR P)
 Emitter called when the Parser is at an #INCLUDE line. More...
 
SUB_CDECL py_exit (BYVAL_AS_Parser_PTR P)
 Emitter called when the Parser is at an #INCLUDE line. More...
 
SUB_CDECL py_CTOR (BYVAL_AS_Options_PTR O)
 Constructor called before the first input gets parsed. More...
 
SUB_CDECL EmitterInit (BYVAL_AS_EmitterIF_PTR Emi, BYREF_AS_STRING Par)
 Initialize the EmitterIF and evaluate parameters. More...
 

Variables

LONG ENUM_COUNT
 A counter for ENUM blocks. More...
 
STRING T0
 The first type block. More...
 
STRING T1
 The second type block. More...
 
STRING T2
 The list of type names (, separated) More...
 
STRING CLASSES
 The list of class names (!"\\n" separated) More...
 
STRING LIBRARY
 The name of the binary to build. More...
 
STRING HEADER
 The header for the output. More...
 

Detailed Description

Example code for an external emitter for Python bindings.

This file contains example source code for an external emitter. The emitter outputs Python declarations from the FB headers, in order to generate Python bindings based on ctypes for libraries compiled in FB.

Since
0.4.0

Definition in file py_ctypes.bas.

Macro Definition Documentation

#define NEW_ENTRY   /* Code(NL & NL & "# " & MID(.Fnam, INSTRREV(.Fnam, SLASH) + 1) & ": " & .LineNo) */

Macro to place a comment in to the output (file name and line number)

Definition at line 17 of file py_ctypes.bas.

Function Documentation

SUB genNLiteral ( BYREF_AS_STRING  T)

Transform number literals.

Parameters
TThe string to work on

This procedure checks a string for numerical literals and transforms the FB notation to Python equivalents.

Since
0.4.0

Definition at line 38 of file py_ctypes.bas.

Here is the caller graph for this function:

FUNCTION_AS_STRING genCType ( BYVAL_AS_Parser_PTR  P)

Transform a FB type in to a ctype.

Parameters
PThe parser calling this emitter
Returns
A string containing the type

This function transforms a FB type in to the ctypes equivalent in case of a standard type. Otherwise the original type symbol gets returned. Pointers get enclosed by POINTER(...), but ZSTRING PTR gets transformed to c_char_p.

Since
0.4.0

Definition at line 63 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_entryListPara ( BYVAL_AS_Parser_PTR  P)

Emitter to extract the types of a parameter list.

Parameters
PThe parser calling this emitter

This emitter collects the types of the parameter list in global variable T2, to be used in py_function().

Since
0.4.0

Definition at line 100 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_emitEnumNames ( BYVAL_AS_Parser_PTR  P)

Emitter to generate a line for a ENUM block entry.

Parameters
PThe parser calling this emitter

This emitter gets called when the parser is in a block (ENUM). It generates a line for each member and stores it (them) in the out variable.

Since
0.4.0

Definition at line 116 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_emitBlockNames ( BYVAL_AS_Parser_PTR  P)

Emitter to generate a line for a TYPE / UNION block entry.

Parameters
PThe parser calling this emitter

This emitter gets called when the parser is in a block (TYPE UNION). It generates a line for each member and stores it (them) in the output variable.

Since
0.4.0

Definition at line 151 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_function ( BYVAL_AS_Parser_PTR  P)

Emitter called when the Parser is on top of a function body.

Parameters
PThe parser calling this emitter

FIXME

Since
0.4.0

Definition at line 199 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_declare ( BYVAL_AS_Parser_PTR  P)

Emitter called when the Parser is at a variable declaration.

Parameters
PThe parser calling this emitter

FIXME

Since
0.4.0

Definition at line 234 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_enum ( BYVAL_AS_Parser_PTR  P)

Emitter called when the Parser is at the start of a ENUM block.

Parameters
PThe parser calling this emitter

FIXME

Since
0.4.0

Definition at line 255 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_union ( BYVAL_AS_Parser_PTR  P)

Emitter called when the Parser is at the start of a UNION block.

Parameters
PThe parser calling this emitter

FIXME

Since
0.4.0

Definition at line 271 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_class ( BYVAL_AS_Parser_PTR  P)

Emitter called when the Parser is at the start of a TYPE block.

Parameters
PThe parser calling this emitter

FIXME

Since
0.4.0

Definition at line 286 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_define ( BYVAL_AS_Parser_PTR  P)

Emitter called when the Parser is at an #DEFINE line or at the start of a #MACRO

Parameters
PThe parser calling this emitter

FIXME

Since
0.4.0

Definition at line 313 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_include ( BYVAL_AS_Parser_PTR  P)

Emitter called when the Parser is at an #INCLUDE line.

Parameters
PThe parser calling this emitter

FIXME

Since
0.4.0

Definition at line 339 of file py_ctypes.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL py_init ( BYVAL_AS_Parser_PTR  P)

Emitter called when the Parser is at an #INCLUDE line.

Parameters
PThe parser calling this emitter

FIXME

Since
0.4.0

Definition at line 353 of file py_ctypes.bas.

Here is the caller graph for this function:

SUB_CDECL py_exit ( BYVAL_AS_Parser_PTR  P)

Emitter called when the Parser is at an #INCLUDE line.

Parameters
PThe parser calling this emitter

FIXME

Since
0.4.0

Definition at line 365 of file py_ctypes.bas.

Here is the caller graph for this function:

SUB_CDECL py_CTOR ( BYVAL_AS_Options_PTR  O)

Constructor called before the first input gets parsed.

Parameters
OThe Options UDT calling this constructor

FIXME

Since
0.4.0

Definition at line 377 of file py_ctypes.bas.

Here is the caller graph for this function:

SUB_CDECL EmitterInit ( BYVAL_AS_EmitterIF_PTR  Emi,
BYREF_AS_STRING  Par 
)

Initialize the EmitterIF and evaluate parameters.

Parameters
EmiThe newly created EmitterIF to fill with our callbacks
ParAdditional command line parameters, not parsed by fb-doc

FIXME

Since
0.4.0

Definition at line 404 of file py_ctypes.bas.

Here is the call graph for this function:

Variable Documentation

LONG ENUM_COUNT

A counter for ENUM blocks.

Definition at line 19 of file py_ctypes.bas.

STRING T0

The first type block.

Definition at line 21 of file py_ctypes.bas.

STRING T1

The second type block.

Definition at line 21 of file py_ctypes.bas.

STRING T2

The list of type names (, separated)

Definition at line 21 of file py_ctypes.bas.

STRING CLASSES

The list of class names (!"\\n" separated)

Definition at line 21 of file py_ctypes.bas.

STRING LIBRARY

The name of the binary to build.

Definition at line 21 of file py_ctypes.bas.

STRING HEADER

The header for the output.

Definition at line 21 of file py_ctypes.bas.