| GirToBac 0.0 Create FB Headers from GObject Introspection *.gir files

- Main Page
- Tutorial
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Enumerations Macros Pages
Data Structures | Macros | Enumerations | Functions | Variables
GirToBac.bas File Reference

Main source code file. More...

`#include "glib.bi"`
`#include "GirToBac_RepData.bas"`

Go to the source code of this file.

## Data Structures

class | UserUDT
| TYPE struct used the parsers. More...

## Macros

#define | NL !"\n" &
| New line character macro (for better readability)
#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)
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 parameter lists.
SUB_CDECL | Func_parser ()
| The GMarkupParser for functions (function, method, constructor, callback)
SUB_CDECL | Type_parser ()
| The GMarkupParser for types.
SUB_CDECL | Class_parser ()
| The GMarkupParser for interfaces, records and classes (OOP style -> ToDo)
SUB_CDECL | UDT_parser ()
| The GMarkupParser for interfaces, records and classes (C-like style)
SUB_CDECL | Unio_parser ()
| The GMarkupParser for unions.
SUB_CDECL | Enum_parser ()
| The GMarkupParser for enums.
SUB_CDECL | pass1_parser ()
| The GMarkupParser for first pass.
SUB_CDECL | passX_parser ()
| The GMarkupParser for second pass.
SUB_CDECL | pass4_parser ()
| The GMarkupParser for last pass.

## Variables

const VAR | OOP = 0
| a flag to generate classic (C-like) headers or OOP style (currently only classic style is supported)
static GMarkupParser | skip_parser = TYPE(NULL, NULL, NULL, NULL, NULL)
| The GMarkupParser for skipping XML-tags.
static GMarkupParser | type_parser = TYPE(@start_type, @end_type, NULL, NULL, NULL)
| The GMarkupParser for the type XML-tags.
VAR | c = find_value("c:type", AttNams, AttVals)
| local variable
VAR | n = find_value("name", AttNams, AttVals)
| local variable
VAR | t = find_value("c:type", AttNams, AttVals)
| local variable
VAR | bits = find_value("bits", AttNams, AttVals)
| local variable
VAR | r = find_value("readable", AttNams, AttVals)
| local variable
VAR | w = find_value("writable", AttNams, AttVals)
| local variable
VAR | dll = "__" & .BlockCnt
| local variable
VAR | p = INSTR(.ParaStr, ", ")
| local variable
VAR | par = "("
| local variable
VAR | parcall = UCASE(.NamSpace & "_" & .Nams(.Level)) & "(@THIS)"
| local variable
VAR | nam = *FB_NAM.rep(find_value("name", AttNams, AttVals))
| local variable
VAR | value = find_value("value", AttNams, AttVals)
| local variable
VAR | g = find_value("glib:get-type", AttNams, AttVals)
| local variable
VAR | s = find_value("glib:type-struct", AttNams, AttVals)
| local variable
VAR | t1 = UCASE(.NamSpace) & "_"
| local variable
VAR | t2 = UCASE(MID(*g, p + 1, LEN(*g) - p - 9))
| local variable
VAR | t3 = t1 & "TYPE_" & t2
| local variable
VAR | t4 = t3 & ", " & *g
| local variable
VAR | t5 = .NamSpace & *s
| local variable
VAR | filename = COMMAND(1)
| input file name

## 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(UserUDT, 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 UserUDT data.

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

Definition at line 170 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)
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(UserUDT, 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 UserUDT data.

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

Definition at line 193 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 220 of file GirToBac.bas.

#define _START_FUNC | ( | ) |  |

Value:
/* (multi line FreeBasic #MACRO)
.ParaCnt = 0 : .ParaStr = "(" : .FunTyp = ""
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)
#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 242 of file GirToBac.bas.

#define _END_FUNC | ( | ) |  |

Value:
/* (multi line FreeBasic #MACRO)
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 259 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 905 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.

Definition at line 79 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

  Nam | The attribute name
  AttNams | The GLib array of attribute names (zero terminated)
  AttVals | The 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 144 of file GirToBac.bas.

FUNCTION_AS_STRING fb_type | ( | BYVAL_AS_ANY_PTR | Ud) |  |

Generate an FB type.

Parameters

  Ud | The data in the UserUDT

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 279 of file GirToBac.bas.