[cfe-dev] Pragma information in AST processing

Daniel Dunbar daniel at zuster.org
Tue Jun 9 20:18:01 PDT 2009


Hi Peter,

On Tue, Jun 9, 2009 at 4:02 AM, Peter Thoman<peter.thoman at uibk.ac.at> wrote:
> Hi, this is my first post to the list.
>
> For what I'm currently working on I'd like to use some information
> extracted from pragmas in an AST visiting/transformation pass. Since (as
> far as I can see) pragma information is only available in the
> preprocessing pass I currently see 2 ways of doing this, both using
> PragmaHandlers in the preprocessor:

What kind of information do you want to extract from pragmas? Are you
planning on adding specific pragmas for your problem, or you want to
do something with existing pragmas which clang handles?

> (1) collect a list of the pragmas, their information and the associated
> source locations during preprocessing, then in the AST visitor check if
> we are at a location on a line directly after some pragma and if so
> process based on the information collected previously
> (2) rewrite the pragmas to some dummy function call, which will be
> visible in the AST and can be used for further processing during AST
> traversal
>
> Neither of these options seems particularly clean to me so I would
> appreciate if someone who is more experienced with clang can think of a
> better solution. Otherwise I'll go ahead with the first option.

The way we currently handle pragmas is generally to attach attributes
to other AST nodes in the pragma handler. This is relatively clean,
but does have the downside that there is no easy way to determine that
the attribute came from a pragma instead of being specified manually.

Eventually I can imagine that we will want to have an explicit
representation in the AST of the pragma (for example, if we want to be
able to print the parse AST back out in exactly the form the user
specified it). However, if your problem can be fit into the existing
model that will probably be much less work. Can you tell us more about
what you are trying to do?

 - Daniel

> Cheers,
>  Peter
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>




More information about the cfe-dev mailing list