[help] the process from c source file to generic structure

Andi Hellmund mail@andihellmund.com
Fri May 28 18:58:00 GMT 2010


Hey,

> but now I confused with the process from c source file to generic structure
> as far as I know : c_parser_translation_unit() means parse a translation
> unit 

Yes

> 1st   Is the production of PARSE a so-called generic structure

Sorry, but I don't understand that question ...


> 2nd  What the translation unit means ?   the whole source file ?

Yes, right. A translation unit is a complete source file after 
pre-processing.


> 3nd  According to the explanation:
>    translation-unit:
>      external-declarations
> 
> Is that means  c_parser_translation_unit()  only in charge of parse
> external-declarations?
> What about internal-declarations?

The internal declarations (e.g. global variables with keyword static) 
are parsed as well. The 'external' just means - according to ISO C99, 
6.9 - that the declaration is outside of a function.

 > int foo()
 > {
 >     my_function_begin;
 >     first statement;
 >     …
 >    last statement;
 >     my_function_end;
 > }

Maybe, it's easier to implement your stuff as a separate pass instead of 
tweaking the C parser. For example, there's already a lot of profiling 
code in GCC which more-or-less does what you try to do and as far as I 
understand, this code is also implemented as as an optimization pass. 
For a reference on how-to implement a pass, please check 
http://gcc.gnu.org/wiki/WritingANewPass (I hope this is still 
up-to-date) and the source file gcc/passes.c for an entry point.

Andi




More information about the Gcc-help mailing list