next up previous
Next: Applied occurrences of names Up: Scope of a simple Previous: Anonymous classes

Parameter and variable declarations

The scope of a parameter is the entire body of the method, constructor or exception handler in which it is declared. The scope of a local variable declaration in a block is the rest of the block in which the declaration appears, starting with its own initializer and including any further declarators to the right in the local variable declaration. The scope of a local variable declared in the ForInit part of a for statement includes its own initializer, any further declarators to the right in the ForInit part of the for statement, the Expression and ForUpdate parts of the for statement, and the contained Statement. The scope of the parameter of a CatchClause is the Block of that clause.

Scopes[20]:

TREE SYMBOL MethodDeclaration      INHERITS VarRangeScope END;
TREE SYMBOL ConstructorDeclaration INHERITS VarRangeScope END;
TREE SYMBOL Block                  INHERITS VarRangeScope END;
TREE SYMBOL ForStatement           INHERITS VarRangeScope END;
TREE SYMBOL CatchClause            INHERITS VarRangeScope END;
This macro is defined in definitions 11, 12, 14, 15, 16, 17, 18, 19, and 20.
This macro is invoked in definition 2.

Although a parameter actually obeys Algol scope rules rather than C scope rules, its declaration occurs syntactically at the beginning of the construct that is its scope. In this case, the Algol scope rules and C scope rules have the same effect. Therefore we can use the Eli CScope module to implement the scope rules for parameters. This simplifies the analysis of applied occurrences, because parameters and local variables are disambiguated in the same way.


next up previous
Next: Applied occurrences of names Up: Scope of a simple Previous: Anonymous classes
2008-09-11