Next: Binding identifier occurrences
Up: Identifier classification
Previous: Reporting the classification
The following information is sufficient to track the current context for
the purposes of classifying identifier occurrences:
State variable declarations[30]
:
typedef struct {
int SynCode; /* Identifier classification on the basis of context */
int BindingOK; /* 1 if identifiers should be bound in this context */
} IdProperties;
extern IdProperties Context;
This macro is defined in definitions 30, 37, and 39.
This macro is invoked in definition 56.
It is not possible to set the value of Context before each declaration,
because that leads to a conflict in the grammar.
Therefore the value must be reset at the beginning of the compilation
and the end of each declaration:
Context.SynCode = identifier; Context.BindingOK = 1;
This macro is invoked in definitions 12 and 59.
The classification is set to typedef_def when the storage class
specifier typedef is accepted by the parser:
Accept a typedef specifier[32]
:
Context.SynCode = typedef_def;
This macro is invoked in definition 13.
A struct_declaration may be nested within a normal declaration or
another structure or union.
Since the possible nesting depth is arbitrary, a stack is needed:
Instantiate a stack module for state values[33]
:
$/Adt/Stack.gnrc +instance=IdState +referto=IdProperties :inst
This macro is invoked in definition 57.
The classification set to either member_def (for a struct or union
declaration) or to identifier (for any other declaration).
In addition, the binding permission should be set for an object or function
declaration, but not for function prototypes.
Nest[34]
:
BeginDeclaration(
,
);
This macro is invoked in definitions 13, 15, 17, 18, 21, and 54.
BeginDeclaration(int c, int b)[35]
:
{
IdStateStackPush(Context);
Context.SynCode = c; Context.BindingOK = b;
}
This macro is invoked in definition 55.
Context = IdStateStackTop; IdStateStackPop;
This macro is invoked in definitions 13, 15, 17, 18, 21, and 54.
Next: Binding identifier occurrences
Up: Identifier classification
Previous: Reporting the classification
2008-08-30