pro64-support
[Top] [All Lists]

Re: Still a question about scope

To: Peng Zhao <pengzhao@xxxxxxxxxxxxxx>
Subject: Re: Still a question about scope
From: Chandrasekhar Murthy <murthy@xxxxxxx>
Date: Fri, 24 Aug 2001 11:28:58 -0700
Cc: sgi <pro64-support@xxxxxxxxxxx>
References: <Pine.LNX.4.21.0108231425001.722-100000@xxxxxxxxxxxxxxxxxxxx>
Sender: owner-pro64-support@xxxxxxxxxxx
Peng Zhao wrote:

> Hi,
>
>         "Whirl Symbol Table Specification" says (bottom of page 4),
> "Associated with each PU, a SCOPE array is defined for specifying the list
> of visible tables, ..., index 2 refers to the local symbol tables. A
> nested procedure will have an index starting at 3, depending on the level
> of nesting."
>
>         Here is my understanding, please correct me if I am wrong.
>
>         1. the nested procedure means a procedure defined in another
> procedure. Like:
>
>         void A()
>         {
>                 // local variables for A()
>                 ...
>
>                 int B()
>                 {
>                         .....
>                 }
>         }
>
>         but if A calls another procedure C, C is not a nested procedure.
>

That is correct assuming that C is not defined in the scope of A.

>
>         2. Each procedure in the program has a scope table for itself. and
> index 1 always points to the global symbol table. The 2nd element of the
> scope table always points to the local symbol table.
>
>         Now the question comes:
>
>         I have the following programs:
>
>         main()
>         {
>                 int a ;
>                 void A()
>                 {
>                         int b;
>                         printf("a=%d,b=%d\n",a,b);
>
>                 }
>                 printf("--------------------\n"); }
>         }
>
>
> I get the whirl tree for A(),
>
>         LOC 1 8 int b;
>         LOC 1 9 printf("a=%d,b=%d\n",a,b);
>    U8LDA [[0]] <1,23,(11_bytes)_"a=%d,b=%d\n\000"> T<32,anon_ptr.,8>
>   U8PARM #2 T<29,anon_ptr.,8> # by_value
>    I4I4LDID [[0]] <2,1,a> T<4,.predef_I4,4>
>   I4PARM #2 T<4,.predef_I4,4> # by_value
>    I4I4LDID [[0]] <3,1,b> T<4,.predef_I4,4>
>   I4PARM #2 T<4,.predef_I4,4> # by_value
>  VCALL #126 <1,22,printf> # flags 0x7e
>
> there is <2,1,a> and <3,1,b>
>
>         Can I draw the conclusion that in a nested procedure, the local
> symbol table will not be the second element of its scope array?
>
>         e.g.
>         if we have four procedures, and A > B > C > D, in which
> "x>y" means y is nested in x.
>         Then the lexical level of A,B,C and D's symbol table will be
> 2,3,4,5, respectively. Right?
>

That is correct.

>
>         3. And if  A>B,  and B wants to access a variable(say X) in A,
> there is no need for B's local symbol table to hold any information about
> X. It is just like a local variable to B, though the whirl node's related
> field (about the lexical level) should be modified. Right?
>
>
>         Thanks

You are correct in assuming that B's local symbol table should not hold
any information about X.  I would not view X as being a local variable
in B as it is defined outside the scope of B.   Most of the WHIRL
generation routines deal with ST*, but if you are dealing with ST_IDX,
you need to set the right nesting level.

Murthy



<Prev in Thread] Current Thread [Next in Thread>