pro64-support
[Top] [All Lists]

Still a question about scope

To: sgi <pro64-support@xxxxxxxxxxx>
Subject: Still a question about scope
From: Peng Zhao <pengzhao@xxxxxxxxxxxxxx>
Date: Thu, 23 Aug 2001 14:43:40 -0600 (MDT)
Sender: owner-pro64-support@xxxxxxxxxxx
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.

        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?


        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


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