Next: Identifiers denoting required entities
Up: Name Analysis
Previous: Name Analysis
Regions
The abstract syntax tree combines formal parameter lists and routine bodies
into single trees that do not contain the routine identifier.
These trees form the regions within which identifiers are declared:
SYMBOL program INHERITS RangeScope END;
SYMBOL ProcBody INHERITS RangeScope END;
SYMBOL FuncBody INHERITS RangeScope END;
SYMBOL Body INHERITS RangeScope END;
SYMBOL ProcHead INHERITS RangeScope END;
SYMBOL FuncHead INHERITS RangeScope END;
This macro is defined in definitions 3, 4, 5, 7, and 8.
This macro is invoked in definition 2.
If a function or procedure is declared forward, then the Formals at
the forward declaration combine with the block at the required
subsequent identification.
We use the attribute IsForward to signal the presence of a forward
declaration.
It is set to 0 by a symbol computation that is overridden in exactly the
case of the forward declaration:
ATTR IsForward: int;
SYMBOL block COMPUTE SYNT.IsForward=0; END;
RULE: block ::= 'forward' COMPUTE block.IsForward=1; END;
This macro is defined in definitions 3, 4, 5, 7, and 8.
This macro is invoked in definition 2.
A void chain can be used to ensure that forward declarations are processed
in textual order:
CHAIN ForwardRoutine: VOID;
SYMBOL program COMPUTE CHAINSTART HEAD.ForwardRoutine="yes"; END;
This macro is defined in definitions 3, 4, 5, 7, and 8.
This macro is invoked in definition 2.
The environment of a forward-declared procedure or function must be
conveyed from the forward declaration to the identification
(non-forward declaration), and that requires a property of the identifier.
Each procedure or function identifier must also carry a property that
reflects the state of the forward definition process:
RtnEnv: Environment; "envmod.h"
FwdState: int;
This macro is attached to a product file.
FwdState is coded as follows:
- 0
- No declaration of this identifer has been seen.
- 1
- A forward has been seen, but there has been no identification.
- 2
- This identifier has been declared.
The value of FwdState when ForwardRoutine reaches a node is coded
in the .FwdState rule attribute, and is updated as follows:
ATTR FwdState: int;
RULE: Decl ::= 'procedure' PrcIdDef ProcBody COMPUTE
.FwdState=GetFwdState(PrcIdDef.Key,0) <- Decl.ForwardRoutine;
Decl.ForwardRoutine=
IF(NOT(ProcBody CONSTITUENT block.IsForward SHIELD (Formals,block)),
ResetFwdState(PrcIdDef.Key,2),
IF(EQ(.FwdState,0),
ORDER(
ResetFwdState(PrcIdDef.Key,1),
ResetRtnEnv(PrcIdDef.Key,ProcBody.Env))));
END;
RULE: Decl ::= 'function' FncIdDef FuncBody COMPUTE
.FwdState=GetFwdState(FncIdDef.Key,0) <- Decl.ForwardRoutine;
Decl.ForwardRoutine=
IF(NOT(FuncBody CONSTITUENT block.IsForward SHIELD (Formals,block)),
ResetFwdState(FncIdDef.Key,2),
IF(EQ(.FwdState,0),
ORDER(
ResetFwdState(FncIdDef.Key,1),
ResetRtnEnv(FncIdDef.Key,FuncBody.Env))));
END;
RULE: Decl ::= 'function' FncIdUse ';' Body COMPUTE
.FwdState=GetFwdState(FncIdUse.Key,0) <- Decl.ForwardRoutine;
Decl.ForwardRoutine=ResetFwdState(FncIdUse.Key,2);
END;
This macro is defined in definitions 3, 4, 5, 7, and 8.
This macro is invoked in definition 2.
The environment for a procedure or function needs to be set to the saved
value under appropriate circumstances:
RULE: Decl ::= 'procedure' PrcIdDef ProcBody COMPUTE
ProcBody.Env=
IF(EQ(.FwdState,1),
GetRtnEnv(PrcIdDef.Key,NoEnv),
NewScope(INCLUDING AnyScope.Env));
END;
RULE: Decl ::= 'function' FncIdUse ';' Body COMPUTE
Body.Env=
IF(EQ(.FwdState,1),
GetRtnEnv(FncIdUse.Key,NoEnv),
NewScope(INCLUDING AnyScope.Env));
END;
This macro is defined in definitions 3, 4, 5, 7, and 8.
This macro is invoked in definition 2.
Next: Identifiers denoting required entities
Up: Name Analysis
Previous: Name Analysis
2008-08-29