Next: Checking for definition errors
Up: Name Analysis
Previous: Name spaces and scopes
Identifier occurrences
Section 6.1.2.1 of the standard says that tags are bound just after
their appearance in the text, enumeration constants are bound after their
enumerator, and any other identifier is bound after its declarator.
This means that the IdDefScope computational role is sometimes
inherited by an identifier occurrence, and sometimes by a larger construct
with an identifier occurrence as a component.
The client of the name analysis modules must compute a Sym attribute
for every node whose left-hand-side symbol inherits IdDefScope;
IdDefScope attaches a Bind attribute and a Key attribute to
that node.
Identifier occurrences that are components of larger constructs binding
those identifiers inherit the IdInDeclarator role, which both acts as a
source for the larger construct's Sym attribute and establishes a
Key attribute for the identifier occurrence.
The larger construct must inherit the DeclaratorWithId role, and there
must be a 1-1 correspondence between a symbol inheriting
DeclaratorWithId and one of its children that inherits
IdInDeclarator.
Identifier occurrences[5]
:
SYMBOL LabelDef INHERITS IdentOcc, LabelIdDefScope END;
SYMBOL LabelUse INHERITS IdentOcc, LabelIdUseEnv END;
SYMBOL TagDef INHERITS IdentOcc, TagIdDefScope END;
SYMBOL TagUse INHERITS IdentOcc, TagIdUseEnv END;
SYMBOL ForwardDef INHERITS IdentOcc, TagIdDefScope END;
SYMBOL ForwardUse INHERITS IdentOcc, TagIdUseEnv END;
SYMBOL MemberIdDef INHERITS IdentOcc, MemberIdDefScope END;
SYMBOL MemberIdUse INHERITS IdentOcc, MemberQualIdUse END;
SYMBOL TypeIdDef INHERITS IdentOcc, IdInDeclarator END;
SYMBOL TypeIdUse INHERITS IdentOcc, IdUseEnv END;
SYMBOL InitDecl INHERITS DeclaratorWithId END;
SYMBOL FunctionDecl INHERITS DeclaratorWithId END;
SYMBOL ParameterDecl INHERITS DeclaratorWithId END;
SYMBOL enumerator INHERITS DeclaratorWithId END;
SYMBOL enumeration_constant
INHERITS IdentOcc, IdInDeclarator END;
SYMBOL IdDef INHERITS IdentOcc, IdInDeclarator END;
SYMBOL IdUse INHERITS IdentOcc, IdUseEnv END;
SYMBOL parameter_id INHERITS IdentOcc, IdUseEnv END;
This macro is defined in definitions 5, 6, and 7.
This macro is invoked in definition 1.
A MemberIdUse is bound in the scope of the structure or union resulting
from the expression preceeding the access operator:
Identifier occurrences[6]
:
SYMBOL struct_declaration_list COMPUTE
INH.MemberScopeKey=THIS.Type;
END;
SYMBOL MemberDecl INHERITS DeclaratorWithId COMPUTE
SYNT.Sym=NoStrIndex;
END;
This macro is defined in definitions 5, 6, and 7.
This macro is invoked in definition 1.
The behavior of ForwardUse described in Section 6.5.2.3 does not quite fit
the IdUseEnv computational roles of the AlgScope module:
There may be no defining occurrences of tag in its environment, but
nevertheless it should have a binding.
This can be arranged by creating a default binding in the root scope:
Identifier occurrences[7]
:
RULE: ForwardUse ::= identifier
COMPUTE
ForwardUse.GotDefaultBinding=
BindIdn(INCLUDING Source.TagEnv,identifier);
END;
SYMBOL Source COMPUTE
SYNT.TagGotKeys=
CONSTITUENTS ForwardUse.GotDefaultBinding <- THIS.TagGotLocKeys;
END;
This macro is defined in definitions 5, 6, and 7.
This macro is invoked in definition 1.
Next: Checking for definition errors
Up: Name Analysis
Previous: Name spaces and scopes
2008-08-30