FROM M2LexBuf IMPORT currentstring, currenttoken, GetToken, InsertToken,
InsertTokenAndRewind, GetTokenNo, MakeVirtualTok ;
-FROM M2Error IMPORT ErrorStringAt, WriteFormat1, WriteFormat2 ;
+FROM M2MetaError IMPORT MetaErrorStringT0 ;
FROM NameKey IMPORT NulName, Name, makekey ;
FROM DynamicStrings IMPORT String, InitString, KillString, Mark, ConCat, ConCatChar ;
FROM M2Printf IMPORT printf0 ;
PushConstType,
PushConstAttributeType,
PushConstAttributePairType,
- PushRType ;
+ PushRType,
+ CheckNotVar ;
FROM SymbolTable IMPORT MakeGnuAsm, PutGnuAsmVolatile, PutGnuAsm, PutGnuAsmInput,
PutGnuAsmOutput, PutGnuAsmTrash, PutGnuAsmVolatile,
Pass1 = FALSE ;
VAR
- WasNoError : BOOLEAN ;
+ InConstParameter,
+ InConstBlock,
+ seenError : BOOLEAN ;
PROCEDURE ErrorString (s: String) ;
BEGIN
- ErrorStringAt (s, GetTokenNo ()) ;
- WasNoError := FALSE
+ MetaErrorStringT0 (GetTokenNo (), s) ;
+ seenError := TRUE
END ErrorString ;
PROCEDURE ErrorArrayAt (a: ARRAY OF CHAR; tok: CARDINAL) ;
BEGIN
- ErrorStringAt (InitString(a), tok)
+ MetaErrorStringT0 (tok, InitString (a))
END ErrorArrayAt ;
str := DescribeStop(s0, s1, s2) ;
str := ConCat(InitString('syntax error,'), Mark(str)) ;
- ErrorStringAt(str, GetTokenNo())
+ MetaErrorStringT0 (GetTokenNo (), str)
END WarnMissingToken ;
PROCEDURE CompilationUnit () : BOOLEAN ;
BEGIN
- WasNoError := TRUE ;
+ seenError := FALSE ;
FileUnit(SetOfStop0{eoftok}, SetOfStop1{}, SetOfStop2{}) ;
- RETURN( WasNoError )
+ RETURN NOT seenError
END CompilationUnit ;
END Real ;
% module PCBuild end
+BEGIN
+ InConstParameter := FALSE ;
+ InConstBlock := FALSE
END PCBuild.
% rules
error 'ErrorArray' 'ErrorString'
=:
ConstantDeclaration := % VAR top: CARDINAL ; %
+ % InConstBlock := TRUE %
% top := Top() %
% PushAutoOn %
( Ident "=" % StartDesConst %
% EndDesConst %
% PopAuto %
% Assert(top=Top()) %
+ % InConstBlock := FALSE %
=:
ConstExpression := % VAR top: CARDINAL ; %
% VAR tokpos: CARDINAL ; %
% tokpos := GetTokenNo () %
(
- PushQualident
+ PushQualident % IF (NOT InConstParameter) AND InConstBlock
+ THEN
+ CheckNotVar (tokpos)
+ END %
( ConstructorOrConstActualParameters | % PushConstType %
% PopNothing %
)
Constructor ) % PopAuto %
=:
-ConstActualParameters := % PushT(0) %
- "(" [ ConstExpList ] ")" =:
+ConstActualParameters := % VAR oldConstParameter: BOOLEAN ; %
+ % oldConstParameter := InConstParameter %
+ % InConstParameter := TRUE %
+ % PushT(0) %
+ "(" [ ConstExpList ] ")"
+ % InConstParameter := oldConstParameter %
+ =:
ConstExpList := % VAR n: CARDINAL ; %
ConstExpression % PopT(n) %
the import/export symbols and assigns types to constructors.
*)
-EXPORT QUALIFIED PCStartBuildDefModule,
- PCEndBuildDefModule,
- PCStartBuildImpModule,
- PCEndBuildImpModule,
- PCStartBuildProgModule,
- PCEndBuildProgModule,
- PCStartBuildInnerModule,
- PCEndBuildInnerModule,
- PCBuildProcedureHeading,
- PCStartBuildProcedure,
- PCEndBuildProcedure,
- BuildNulName,
- BuildConst,
- PCBuildImportOuterModule,
- PCBuildImportInnerModule,
- StartDesConst,
- EndDesConst,
- BuildRelationConst,
- BuildUnaryConst,
- BuildBinaryConst,
- PushInConstructor,
- PopInConstructor,
- SkipConst,
- PushConstType,
- PushConstAttributeType,
- PushConstAttributePairType,
- PushConstructorCastType,
- PushRType,
- PushConstFunctionType,
- PushIntegerType,
- PushStringType,
- ResolveConstTypes ;
+
+(*
+ CheckNotVar - checks to see that the top of stack is not a variable.
+*)
+
+PROCEDURE CheckNotVar (tok: CARDINAL) ;
(*
IsParameterVar, PutProcTypeParam,
PutProcTypeVarParam, IsParameterUnbounded,
PutFunction, PutProcTypeParam,
- GetType,
+ GetType, IsVar,
IsAModula2Type, GetDeclaredMod ;
FROM M2Batch IMPORT MakeDefinitionSource,
END GetSkippedType ;
+(*
+ CheckNotVar - checks to see that the top of stack is not a variable.
+*)
+
+PROCEDURE CheckNotVar (tok: CARDINAL) ;
+VAR
+ const: CARDINAL ;
+BEGIN
+ const := OperandT (1) ;
+ IF (const # NulSym) AND IsVar (const)
+ THEN
+ MetaErrorT1 (tok, 'not expecting a variable {%Aad} as a term in a constant expression', const)
+ END
+END CheckNotVar ;
+
+
(*
StartBuildDefinitionModule - Creates a definition module and starts
a new scope.