Local binding DECLs

Daniel Berlin dberlin@dberlin.org
Mon May 12 07:30:00 GMT 2003


On Monday, May 12, 2003, at 02:44  AM, Stephen Biggs wrote:

> On Mon, 2003-05-12 at 04:13, Richard Henderson wrote:
>> On Sun, May 11, 2003 at 10:04:20AM +0300, Stephen Biggs wrote:
>>> Ok... is there ANY way to find out if the FUNCTION_DECL I am handed 
>>> at
>>> any time (preferably in ENCODE_SECTION) is declared in a function 
>>> block
>>> as opposed to globally?
>>
>> *Declared*?  I.e. to distinguish
>>
>> 	extern void foo();
>> 	void bar() { foo(); }
>>
>> from
>>
>> 	void bar() {
>> 	  extern void foo();
>> 	  foo();
>> 	}
>>
>> Absolutely not.  That question doesn't even make sense.
>>
>>
>> r~
>>
> Sure it does, if you have, for example:
>
> void bar() {
>   static void foo();
>   foo();
> }
>
> void bar1() {
>   static int foo();
>   foo();
> }
>
> void bar2() {
>   static int foo(int);
>   int a = foo(3);
> }
> foo() {}
>
> This compiles.
>
> I see nothing that gives me the ability to know that any particular 
> DECL
> is declared inside a particular function.
>


Errr, won't DECL_CONTEXT do what you want?
 From tree.h:
/*  For FIELD_DECLs, this is the
     RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node that the field is
     a member of.  For VAR_DECL, PARM_DECL, FUNCTION_DECL, LABEL_DECL,
     and CONST_DECL nodes, this points to either the FUNCTION_DECL for 
the
     containing function, the RECORD_TYPE or UNION_TYPE for the 
containing
     type, or NULL_TREE if the given decl has "file scope".  */
#define DECL_CONTEXT(NODE) (DECL_CHECK (NODE)->decl.context)


DECL_CONTEXT on a contained function_decl should give you the 
containing function_decl (or NULL_TREE if it's not contained/is file 
scope), as the comment says.
Does it not work?
I haven't really been following till now.
--Dan



More information about the Gcc mailing list