[cfe-dev] #pragmas in the AST.

steve naroff snaroff at apple.com
Tue Dec 9 06:36:22 PST 2008


On Dec 9, 2008, at 6:58 AM, Paolo Bolzoni wrote:

> On Tue, 9 Dec 2008 05:59:32 -0500
> steve naroff <snaroff at apple.com> wrote:
>
> Hi snaroff,
> I am probably missing the obvious then, how the following phases of
> compilation knows if I set or I didn't set a pragma?
>
> Example, from C99 standard, speaking of pragma STDC FENU_ACCESS:
> '''
> When outside external declarations, the pragma takes effect from its
> occurrence until another FENV_ACCESS pragma is encountered, or until  
> the end
> of the translation unit.
> When inside a compound statement, the pragma takes effect from its  
> occurrence
> until another FENV_ACCESS pragma is encountered (including within a  
> nested
> compound statement), or until the end of the compound statement;
> '''
>
> If the ast forgets about pragmas, how can I know if a certain  
> statement have
> FENU_ACCESS on?
>

Hi Paolo,

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.

HTH,

snaroff

> Thanks,
> pb
>
>
>
>
>> Hi Paolo,
>>
>> Pragma's are preprocessing directives. Since they aren't integrated
>> with the C grammar (and aren't declarations in the language), they
>> aren't represented in the AST.
>>
>> snaroff
>>
>> On Dec 9, 2008, at 5:35 AM, Paolo Bolzoni wrote:
>>
>>>
>>> dear cfe-list,
>>> I'd like to know how the AST represents eventual pragmas of the
>>> original
>>> source code. As far I understood the pragmas disappear, or at least
>>> aren't
>>> global declarations.
>>>
>>>
>>> I am overall interested about the standard pragmas (#pragma STDC,  
>>> for
>>> example C99 7.6.1).
>>>
>>> Thanks.
>>> pb
> _______________________________________________
> 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