[cfe-dev] #pragmas in the AST.

Chris Lattner clattner at apple.com
Tue Dec 9 10:44:30 PST 2008


On Dec 9, 2008, at 6:36 AM, steve naroff wrote:
> I haven't worked on clang's pragma support, however I looked briefly
> at the code and here are a few points:
>
> - The low-level pragma handling is done by Lex/Preprocessor (as I
> would expect).
> - The PragmaHandler class calls out to the Action module when
> appropriate. For example, Sema implements ActOnPragmaPack() to handle
> "#pragma pack(*)".
> - Sema is then be responsible for making sure the pragma is reflected
> in the AST (when it's instantiated).
>
> SInce clang doesn't support many pragma's (yet), most are being
> ignored by Sema (and the AST's). Maybe this added to your confusion...
>
> If you have a specific pragma you are interested in, you might try
> implementing your own PragmaHandler to see how the pieces currently
> fit together.

Yep, Steve's right.  When we eventually support FENV_ACCESS (for  
example) there are two reasonable ways to implement it:

1) make it synthesize a 'FENV_ACCESS statement' of some sort when in  
function scope.  I don't really like this, but it is possible.
2) make it set the current mode in Sema, have the scope mechanism  
maintain the mode as part of the scope stack.  When any fp operation  
is seen, the AST node for that fp operation would be tagged with the  
mode it is in.

-Chris



More information about the cfe-dev mailing list