girtobac  0.4
Create FB Headers from GObject Introspection *.gir files
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
girtobac.bas File Reference

Main source code file. More...

#include "../Gir/GLib-2.0.bi"
#include "girtobac_text.bi"
#include "girtobac_RepData.bas"
Include dependency graph for girtobac.bas:

Go to the source code of this file.

Classes

class  Context
 TYPE struct used in the parsers. More...
 

Macros

#define _START_PARSER(_N_)
 Macro to start a parser. More...
 
#define _END_PARSER(_N_)
 Macro to complete a start parser and open an end parser. More...
 
#define _NEW_PARSER(_N_)
 Macro to complete an end parser and initialize the GMarkupParser UDT. More...
 
#define _START_FUNC()
 Generate code to start parsing a function. More...
 
#define _END_FUNC()
 Generate code to end parsing a function. More...
 
#define PARSE(_N_)
 Macro to run a parser. More...
 

Enumerations

enum  TypeFlags {
  TYPE_VAR, TYPE_SUB, TYPE_FUN, TYPE_VARARG,
  TYPE_ARRAY, TYPE_LIST
}
 ENUM used to specify a type. More...
 

Functions

FUNCTION_AS_CONST_gchar_PTR find_value (BYVAL_AS_CONST_gchar_PTR Nam, BYVAL_AS_CONST_gchar_PTR_PTR AttNams, BYVAL_AS_CONST_gchar_PTR_PTR AttVals)
 Find an attribute by its name. More...
 
FUNCTION_AS_STRING fb_type (BYVAL_AS_ANY_PTR Ud)
 Generate an FB type. More...
 
SUB_CDECL start_type (BYVAL_AS_GMarkupParseContext_PTR, BYVAL_AS_CONST_gchar_PTR, BYVAL_AS_CONST_gchar_PTR_PTR, BYVAL_AS_CONST_gchar_PTR_PTR, BYVAL_AS_gpointer, BYVAL_AS_GError_PTR_PTR)
 Forward declaration (due to circular references) More...
 
SUB_CDECL end_type (BYVAL_AS_GMarkupParseContext_PTR, BYVAL_AS_CONST_gchar_PTR, BYVAL_AS_gpointer, BYVAL_AS_GError_PTR_PTR)
 Forward declaration (due to circular references) More...
 
SUB_CDECL para_parser ()
 The GMarkupParser for the parameter lists. More...
 
SUB_CDECL func_parser ()
 The GMarkupParser for the functions (function, method, constructor, callback) More...
 
SUB_CDECL type_parser ()
 The GMarkupParser for the types. More...
 
SUB_CDECL class_parser ()
 The GMarkupParser for the interfaces, records and classes (OOP style -> ToDo) More...
 
SUB_CDECL udt_parser ()
 The GMarkupParser for the interfaces, records and classes (C-like style) More...
 
SUB_CDECL unio_parser ()
 The GMarkupParser for the union blocks. More...
 
SUB_CDECL enum_parser ()
 The GMarkupParser for the enum blocks. More...
 
SUB_CDECL pass1_parser ()
 The GMarkupParser for the first pass. More...
 
SUB_CDECL passX_parser ()
 The GMarkupParser for the second pass. More...
 
SUB_CDECL pass4_parser ()
 The GMarkupParser for last pass. More...
 
int main ()
 

Variables

const VAR OOP = 0
 a flag to generate classic (C-like) headers or OOP style (currently only classic style is supported since fbc isn't ready yet) More...
 
static GMarkupParser Skip_parser = TYPE(NULL, NULL, NULL, NULL, NULL)
 The GMarkupParser for skipping XML-tags. More...
 
static GMarkupParser Type_parser = TYPE(@start_type, @end_type, NULL, NULL, NULL)
 The GMarkupParser for the type XML-tags. More...
 

Detailed Description

Main source code file.

This file contains the main source code. Compile this file with the FreeBasic compiler fbc to create an executable GirToBac tool.

The main content of this file are different parsers used by the GMarkupParser . Each parser is declared as a UDT containing five function adresses. Only two are used here (start_element and end_element). For better readability macros are used for the relapsing part of the function declarations and the UDT declarations of each parser. Additionally, labels are placed in front of each parser to get a mark in the IDE labels list for easy jumping between the parser definitions. (The labels aren't used in the source code.)

Definition in file girtobac.bas.

Macro Definition Documentation

#define _START_PARSER (   _N_)
Value:
/* (multi line FreeBASIC #MACRO)
SUB start_##_N_ CDECL( _
BYVAL ctx AS GMarkupParseContext PTR, _
BYVAL element_name AS CONST gchar PTR, _
BYVAL AttNams AS CONST gchar PTR PTR, _
BYVAL AttVals AS CONST gchar PTR PTR, _
BYVAL UserData AS gpointer, _
BYVAL error_ AS GError PTR PTR)
WITH PEEK(Context, UserData)
#ENDMACRO */

Macro to start a parser.

Each parser uses the same parameter list for the start function. This macro generates the code for such a procedure (SUB) and opens a WITH block to support access to the Context data.

It's designed to be used in combination with the _END_PARSER() macro.

Definition at line 129 of file girtobac.bas.

#define _END_PARSER (   _N_)
Value:
/* (multi line FreeBASIC #MACRO)
CASE ELSE
'PRINT #.FnrBi, NL " ' " & __FB_FUNCTION__ & " Skipping " & *element_name _
' & " """ & *find_value("name", AttNams, AttVals) & """";
g_markup_parse_context_push(ctx, @Skip_parser, UserData) '& skip_parser();
END SELECT
END WITH
END SUB
SUB end_##_N_ CDECL( _
BYVAL ctx AS GMarkupParseContext PTR, _
BYVAL element_name AS CONST gchar PTR, _
BYVAL UserData AS gpointer, _
BYVAL error_ AS GError PTR PTR)
WITH PEEK(Context, UserData)
#ENDMACRO */

Macro to complete a start parser and open an end parser.

Each parser uses the same code for ending a start function and the same parameter list for the end function. This macro generates the code to finish the start procedure (END WITH/END SUB), open an end procedure (SUB with constant parameter list) and opens a WITH block to support access to the Context data.

It's designed to be used after the _START_PARSER() macro and in combination with the _NEW_PARSER() macro.

Definition at line 152 of file girtobac.bas.

#define _NEW_PARSER (   _N_)
Value:
/* (multi line FreeBASIC #MACRO)
CASE ELSE
g_markup_parse_context_pop(ctx)
END SELECT
END WITH
END SUB
STATIC SHARED AS GMarkupParser _N_##_parser = TYPE(@start_##_N_, @end_##_N_, NULL, NULL, NULL)
#ENDMACRO */

Macro to complete an end parser and initialize the GMarkupParser UDT.

Each parser uses the same code for ending an end procedure. This macro generates the code to finish the end procedure and generates a structure (TYPE) to use the parser. This TYPE contains two functions (procedures for start and end of a XML tag).

It's designed to be used after the _END_PARSER() macro.

Definition at line 179 of file girtobac.bas.

#define _START_FUNC ( )
Value:
/* (multi line FreeBASIC #MACRO)
.ParaCnt = 0 : .ParaStr = "(" : .FunTyp = ""
.GErrr = find_value("throws", AttNams, AttVals)
IF OOP THEN
.FunNam = *FB_NAM.rep(find_value("name", AttNams, AttVals))
.FunDll = *find_value("c:identifier", AttNams, AttVals)
ELSE
.FunNam = *FB_NAM.rep(find_value("c:identifier", AttNams, AttVals))
END IF
g_markup_parse_context_push(ctx, @Func_parser, UserData) '& func_parser();
#ENDMACRO */

Generate code to start parsing a function.

This macro is used to start the function parser. The snipped is used several times, so this macro makes it unique (single source).

Definition at line 201 of file girtobac.bas.

#define _END_FUNC ( )
Value:
/* (multi line FreeBASIC #MACRO)
IF .GErrr THEN
IF .ParaCnt THEN .ParaStr &= ", "
.ParaStr &= "BYVAL AS GError PTR PTR" : .ParaCnt += 1
END IF
g_markup_parse_context_pop(ctx)
.type_flg = IIF(LEN(.FunTyp), TYPE_FUN, TYPE_SUB)
.ParaStr &= ")"
#ENDMACRO */

Generate code to end parsing a function.

This macro is used to end the function parser. The snipped is used several times, so this macro makes it unique (single source).

Definition at line 219 of file girtobac.bas.

#define PARSE (   _N_)
Value:
/* (multi line FreeBASIC #MACRO)
SCOPE
VAR ctx = g_markup_parse_context_new(@pass##_N_##_parser, 0, @UDat, NULL)
IF g_markup_parse_context_parse(ctx, buffer, length, @errr) THEN _
IF 0 = g_markup_parse_context_end_parse(ctx, @errr) THEN _
g_print(!"Cannot parse %s (invalid content)\n", filename, NULL)
g_markup_parse_context_free(ctx)
END SCOPE
#ENDMACRO */

Macro to run a parser.

This macro creates a parser context and runs the given parser once.

Definition at line 873 of file girtobac.bas.

Enumeration Type Documentation

enum TypeFlags

ENUM used to specify a type.

These enums are used to specify a type. This may be an return value from a function, a parameter in a parameter list or a member field in a TYPE or UNION.

Enumerator
TYPE_VAR 

a variable

TYPE_SUB 

a SUB (function of type 'void')

TYPE_FUN 

a FUNCTION

TYPE_VARARG 

a variadic parameter (in a parameter list)

TYPE_ARRAY 

an Array (C-like)

TYPE_LIST 

a list (GLib type)

Definition at line 41 of file girtobac.bas.

Function Documentation

FUNCTION_AS_CONST_gchar_PTR find_value ( BYVAL_AS_CONST_gchar_PTR  Nam,
BYVAL_AS_CONST_gchar_PTR_PTR  AttNams,
BYVAL_AS_CONST_gchar_PTR_PTR  AttVals 
)

Find an attribute by its name.

Parameters
NamThe attribute name
AttNamsThe GLib array of attribute names (zero terminated)
AttValsThe GLib array of attribute values
Returns
A pointer to the attribute value (or zero)

The GLib XML parser lists all attributes found in a tag and their values in the arrays AttNams and AttVals. This function finds an attribute by its name and returns its value. Otherwise it returns zero if the specified attribute isn't present.

Definition at line 107 of file girtobac.bas.

Here is the caller graph for this function:

FUNCTION_AS_STRING fb_type ( BYVAL_AS_ANY_PTR  Ud)

Generate an FB type.

Parameters
UdThe data in the Context
Returns
An FB type string

Type declarations may need adaptions. We have to follow the rules defined in the *.GirToBac file to change some types. Also they may contain '*' characters to be translated to 'PTR' strings for FB.

In seldom cases a *.gir declaration doesn't contain an entry for a C type. Then we try repairing it by using the type used in the namespace instead.

Definition at line 243 of file girtobac.bas.

SUB_CDECL start_type ( BYVAL_AS_GMarkupParseContext_PTR  ,
BYVAL_AS_CONST_gchar_PTR  ,
BYVAL_AS_CONST_gchar_PTR_PTR  ,
BYVAL_AS_CONST_gchar_PTR_PTR  ,
BYVAL_AS_gpointer  ,
BYVAL_AS_GError_PTR_PTR   
)

Forward declaration (due to circular references)

SUB_CDECL end_type ( BYVAL_AS_GMarkupParseContext_PTR  ,
BYVAL_AS_CONST_gchar_PTR  ,
BYVAL_AS_gpointer  ,
BYVAL_AS_GError_PTR_PTR   
)

Forward declaration (due to circular references)

SUB_CDECL para_parser ( )

The GMarkupParser for the parameter lists.

Definition at line 294 of file girtobac.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL func_parser ( )

The GMarkupParser for the functions (function, method, constructor, callback)

Definition at line 332 of file girtobac.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL type_parser ( )

The GMarkupParser for the types.

Definition at line 356 of file girtobac.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL class_parser ( )

The GMarkupParser for the interfaces, records and classes (OOP style -> ToDo)

Definition at line 411 of file girtobac.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL udt_parser ( )

The GMarkupParser for the interfaces, records and classes (C-like style)

Definition at line 531 of file girtobac.bas.

Here is the call graph for this function:

SUB_CDECL unio_parser ( )

The GMarkupParser for the union blocks.

Definition at line 582 of file girtobac.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL enum_parser ( )

The GMarkupParser for the enum blocks.

Definition at line 628 of file girtobac.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL pass1_parser ( )

The GMarkupParser for the first pass.

Definition at line 648 of file girtobac.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL passX_parser ( )

The GMarkupParser for the second pass.

Definition at line 727 of file girtobac.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

SUB_CDECL pass4_parser ( )

The GMarkupParser for last pass.

Definition at line 839 of file girtobac.bas.

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( )

Definition at line 883 of file girtobac.bas.

Here is the call graph for this function:

Variable Documentation

const VAR OOP = 0

a flag to generate classic (C-like) headers or OOP style (currently only classic style is supported since fbc isn't ready yet)

Definition at line 31 of file girtobac.bas.

GMarkupParser Skip_parser = TYPE(NULL, NULL, NULL, NULL, NULL)
static

The GMarkupParser for skipping XML-tags.

Definition at line 190 of file girtobac.bas.

GMarkupParser Type_parser = TYPE(@start_type, @end_type, NULL, NULL, NULL)
static

The GMarkupParser for the type XML-tags.

Definition at line 290 of file girtobac.bas.