[cfe-dev] Creation of Global Vars on the fly in Parser

Daniel Powell divot.powell at googlemail.com
Mon Apr 2 12:00:38 PDT 2012


I'm attempting to write a code generator that adds in additional classes
and global instances of those classes upon discovery of a pragma statement.
This is happening in the Parser, calling the appropriate Sema actions to
create and insert these into the AST on the fly.

I have it generating both the class and instances and inserting them both
into the AST, however when it comes to code generation it complains that it
cannot emit a local variable declaration as a global one. Some further
looking into things show that my instance declaration returns false when
isFileVarDecl() is called, I think indicating that it hasn't been declared
in a FileContext. Could this be a problem with my Class Declaration or is
it more likely to be my actual Instance Declaration causing this.

One thing I'm suspicious of is that the actions for these declarations are
being called halfway through parsing a function, however I have been using
completely separate DeclSpec's and ParsingDeclarators for this and am
passing the decl's created up the chain to a point before the function decl
is used. Could the context during function creation be causing the problem?
I'm having trouble getting my head around all the different contexts that
are passed around and how they are used..

I can provide more info and code if that'll help..



Daniel Powell
divot.powell at googlemail.com

The University of Edinburgh
Institute for Computer Systems Architecture
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120402/35fa00f0/attachment.html>

More information about the cfe-dev mailing list