(*
- DoVariableDeclaration -
+ DoVariableDeclaration - create a corresponding gcc variable and add the association
+ between the front end symbol var and the gcc tree.
*)
-PROCEDURE DoVariableDeclaration (var, module: CARDINAL; name: ADDRESS;
+PROCEDURE DoVariableDeclaration (var: CARDINAL; name: ADDRESS;
isImported, isExported,
isTemporary, isGlobal: BOOLEAN;
scope: Tree) ;
(*
There are two issues to deal with:
- (i) LeftValue is really a pointer to GetSType(Son), which is built
+ (i) LeftValue is really a pointer to GetSType (var), which is built
here.
(ii) Front end might have specified the back end use a particular
data type, in which case we use the specified type.
varType := SkipType (GetVarBackEndType (var)) ;
IF varType=NulSym
THEN
- (* we have not explicity told back end the type, so build it *)
+ (* We have not explicity told back end the type, so build it. *)
varType := GetSType (var) ;
IF IsVariableAtAddress (var)
THEN
type := BuildPointerType (Mod2Gcc (varType))
END
ELSE
+ (* We have been requested to use varType. *)
type := Mod2Gcc (varType)
END ;
Assert (AllDependantsFullyDeclared (varType))
type := Mod2Gcc (GetDType (var))
END ;
location := TokenToLocation (GetDeclaredMod (var)) ;
- (* The M2LINK module global variables are a special case and have initializers. *)
PreAddModGcc (var, DeclareKnownVariable (location,
name, type,
isExported, isImported, isTemporary,
decl := FindOuterModule (variable) ;
Assert (AllDependantsFullyDeclared (GetSType (variable))) ;
PushBinding (ModSym) ;
- DoVariableDeclaration (variable, decl,
+ DoVariableDeclaration (variable,
KeyToCharStar (GetFullSymName (variable)),
(* in Modula-2 we are allowed to import from ourselves, but we do not present this to GCC *)
IsEffectivelyImported(ModSym, variable) AND (GetMainModule () # decl),
decl := FindOuterModule (variable) ;
Assert (AllDependantsFullyDeclared (GetSType (variable))) ;
PushBinding (mainModule) ;
- DoVariableDeclaration (variable, decl,
+ DoVariableDeclaration (variable,
KeyToCharStar (GetFullSymName (variable)),
(NOT IsSourceSeen (decl)) AND
IsEffectivelyImported (mainModule, variable) AND (GetMainModule () # decl),
PROCEDURE DeclareLocalVariable (var: CARDINAL) ;
BEGIN
Assert (AllDependantsFullyDeclared (var)) ;
- DoVariableDeclaration (var, NulSym,
+ DoVariableDeclaration (var,
KeyToCharStar (GetFullSymName (var)),
FALSE, (* local variables cannot be imported *)
FALSE, (* or exported *)
Var := GetNth (sym, i) ;
WHILE Var # NulSym DO
Assert (AllDependantsFullyDeclared (GetSType (Var))) ;
- DoVariableDeclaration (Var, NulSym,
+ DoVariableDeclaration (Var,
KeyToCharStar (GetFullSymName (Var)),
FALSE, (* inner module variables cannot be imported *)
FALSE, (* or exported (as far as GCC is concerned) *)
END ErrorArray ;
-PROCEDURE ErrorArrayAt (a: ARRAY OF CHAR; tok: CARDINAL) ;
-BEGIN
- ErrorStringAt (InitString(a), tok)
-END ErrorArrayAt ;
-
% declaration PHBuild begin
END MissingToken ;
-(*
- CheckAndInsert -
-*)
-
-PROCEDURE CheckAndInsert (t: toktype; stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) : BOOLEAN ;
-BEGIN
- IF ((ORD(t)<32) AND (t IN stopset0)) OR
- ((ORD(t)>=32) AND (ORD(t)<64) AND (t IN stopset1)) OR
- ((ORD(t)>=64) AND (t IN stopset2))
- THEN
- WarnMissingToken(t) ;
- InsertTokenAndRewind(t) ;
- RETURN( TRUE )
- ELSE
- RETURN( FALSE )
- END
-END CheckAndInsert ;
-
-
-(*
- InStopSet
-*)
-
-PROCEDURE InStopSet (t: toktype; stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) : BOOLEAN ;
-BEGIN
- IF ((ORD(t)<32) AND (t IN stopset0)) OR
- ((ORD(t)>=32) AND (ORD(t)<64) AND (t IN stopset1)) OR
- ((ORD(t)>=64) AND (t IN stopset2))
- THEN
- RETURN( TRUE )
- ELSE
- RETURN( FALSE )
- END
-END InStopSet ;
-
-
-(*
- PeepToken - peep token checks to see whether the stopset is satisfied by currenttoken
- If it is not then it will insert a token providing the token
- is one of ; ] ) } . OF END ,
-
- if the stopset contains <identtok> then we do not insert a token
-*)
-
-PROCEDURE PeepToken (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ;
-BEGIN
- (* and again (see above re: ORD)
- *)
- IF (NOT (((ORD(currenttoken)<32) AND (currenttoken IN stopset0)) OR
- ((ORD(currenttoken)>=32) AND (ORD(currenttoken)<64) AND (currenttoken IN stopset1)) OR
- ((ORD(currenttoken)>=64) AND (currenttoken IN stopset2)))) AND
- (NOT InStopSet(identtok, stopset0, stopset1, stopset2))
- THEN
- (* SyntaxCheck would fail since currentoken is not part of the stopset
- we check to see whether any of currenttoken might be a commonly
- omitted token. *)
- IF CheckAndInsert(semicolontok, stopset0, stopset1, stopset2) OR
- CheckAndInsert(rsbratok, stopset0, stopset1, stopset2) OR
- CheckAndInsert(rparatok, stopset0, stopset1, stopset2) OR
- CheckAndInsert(rcbratok, stopset0, stopset1, stopset2) OR
- CheckAndInsert(periodtok, stopset0, stopset1, stopset2) OR
- CheckAndInsert(oftok, stopset0, stopset1, stopset2) OR
- CheckAndInsert(endtok, stopset0, stopset1, stopset2) OR
- CheckAndInsert(commatok, stopset0, stopset1, stopset2)
- THEN
- END
- END
-END PeepToken ;
-
-
(*
Expect -
*)
{ "." Ident } % END %
=:
-PushQualident := % VAR name : Name ;
- init, ip1 : CARDINAL ;
- tok, tokstart: CARDINAL ; %
- % PushAutoOn %
- Ident % IF IsAutoPushOn()
- THEN
- PopTtok (name, tokstart) ;
- tok := tokstart ;
- init := GetSym (name) ;
- IF init=NulSym
- THEN
- PushTFntok (NulSym, NulSym, name, tok)
- ELSE
- WHILE IsDefImp (init) OR IsModule (init) DO
- IF currenttoken # periodtok
- THEN
- ErrorArrayAt ("expecting '.' after module in the construction of a qualident", tok) ;
- IF tok#tokstart
- THEN
- tok := MakeVirtualTok (tokstart, tokstart, tok)
- END ;
- PushTtok (init, tok) ;
- PopAuto ;
- RETURN
- ELSE
- Expect (periodtok, stopset0, stopset1, stopset2 + SetOfStop2{identtok}) ;
- StartScope (init) ;
- Ident (stopset0, stopset1, stopset2) ;
- PopTtok (name, tok) ;
- ip1 := GetSym (name) ;
- IF ip1 = NulSym
- THEN
- ErrorArrayAt ("unknown ident in the construction of a qualident", tok) ;
- EndScope ;
- IF tok#tokstart
- THEN
- tok := MakeVirtualTok (tokstart, tokstart, tok)
- END ;
- PushTFntok (NulSym, NulSym, name, tok) ;
- PopAuto ;
- RETURN
- ELSE
- PutIncluded (ip1)
- END ;
- EndScope ;
- CheckCanBeImported (init, ip1) ;
- init := ip1
- END
- END ;
- IF tok#tokstart
- THEN
- tok := MakeVirtualTok (tokstart, tokstart, tok)
- END ;
- IF IsProcedure (init) OR IsProcType (init)
- THEN
- PushTtok (init, tok)
- ELSE
- PushTFtok (init, GetType(init), tok)
- END
- END
- ELSE %
- { "." Ident } % END %
- % PopAuto %
- =:
-
ConstantDeclaration := % PushAutoOn %
% VAR tokno: CARDINAL ; %
( Ident "=" % tokno := GetTokenNo () %
% Assert (n = Top ()) %
=:
--- SimpleDes := { "." Ident | "[" ExpList "]" | "^" } =:
-SimpleDes := { SubDesignator } =:
-
-ActualParameters := "("
- ( ExpList | % (* epsilon *) %
- ) ")" =:
-
ConstActualParameters := "(" % BuildSizeCheckStart %
( ConstExpList | % BuildNulParam %
) ")" =:
StatementSequence
}
[ "ELSE"
- StatementSequence ] "END"
+ StatementSequence ] "END"
=:
CaseStatement := "CASE"