fbc plugins

General FreeBASIC programming questions.
Posts: 231
Joined: Mar 12, 2006 16:25

fbc plugins

Postby RockTheSchock » Aug 16, 2016 2:00

I am trying to implement a plugin extension for fbc. I am successfully loading plugins and call init and visitor functions. But where should i put the callback visitor functions in the compiler? I am absolutly lost.

I tried in ast-node-proc at the end of:

function astAdd( byval n as ASTNODE ptr ) as ASTNODE ptr
function astAddAfter ...

Maybe i should put the callbacks somewhere else eg

parser-toplevel.bas -> sub cProgram()
or before in the lexer?
or at the end when the ast is completly built?
Site Admin
Posts: 3212
Joined: Jul 28, 2005 14:45
Location: Germany

Re: fbc plugins

Postby dkl » Aug 16, 2016 17:46


if you want to look at AST right before it's emitted, I recommend putting the callback above the main astLoad() call (ast-node-proc.bas(150)). That's where I like to put astDumpSmall() calls when debugging...

Putting it into astAdd[After]() behind the astUpdate() calls would probably also work though, because I don't think the AST nodes will be modified later once they were astAdd'ed. Putting callbacks in the lexer only makes sense if you want to see the chars read from file (hReadChar()) or tokens produced by it (lexNextToken()).

fbc doesn't keep the complete AST/symbol table for the whole input file, only for one procedure at a time. The exceptions to that are the implicit main() (because its statements can be mixed with normal procedures) and Private procedures (to allow omitting them if unused), and the global namespace w.r.t. symbol tables.

Return to “General”

Who is online

Users browsing this forum: Google [Bot] and 5 guests