浏览代码

Added heuristic check for forbidden variable access for len argument of ARRAY len OF Type (allowed are only properties, currently)

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6466 8c9fc860-2736-0410-a75d-ab315db34111
felixf 9 年之前
父节点
当前提交
9b39e6259c
共有 4 个文件被更改,包括 20 次插入8 次删除
  1. 0 4
      source/FoxCompiler.Mod
  2. 1 1
      source/FoxIntermediateBackend.Mod
  3. 2 2
      source/FoxParser.Mod
  4. 17 1
      source/FoxSemanticChecker.Mod

+ 0 - 4
source/FoxCompiler.Mod

@@ -170,10 +170,6 @@ TYPE
 				activeCellsSpecification.DefineDevices(system);
 				Global.OperatorDefined(system, Scanner.Questionmarks, TRUE);
 			END;
-			Global.NewBuiltin(Global.Connect,"CONNECT",system.globalScope,FALSE);
-			Global.NewBuiltin(Global.Receive,"RECEIVE",system.globalScope,FALSE);
-			Global.NewBuiltin(Global.Send,"SEND",system.globalScope,FALSE);
-			Global.NewBuiltin(Global.Delegate,"DELEGATE",system.globalScope,FALSE);
 			IF options.activeCellsBackend = NIL THEN FinalMessage(TRUE,"could not install activeCells backend"); RETURN FALSE END;
 		END;
 		options.frontend.Initialize(diagnostics, reader, source, position, ActiveCellsFlag IN flags);

+ 1 - 1
source/FoxIntermediateBackend.Mod

@@ -1365,7 +1365,7 @@ TYPE
 		VAR prevDump: Streams.Writer;
 		VAR body: SyntaxTree.Body;
 		BEGIN
-			ASSERT(~procedure.type(SyntaxTree.ProcedureType).noPAF);
+			ASSERT((procedure = NIL) OR ~procedure.type(SyntaxTree.ProcedureType).noPAF);
 			prevSection := SELF.section;
 			SELF.section := section;
 			prevDump := dump;

+ 2 - 2
source/FoxParser.Mod

@@ -4,7 +4,7 @@ MODULE FoxParser;   (**  AUTHOR "fof & fn"; PURPOSE "Oberon Compiler: Parser";
 IMPORT Basic := FoxBasic, Scanner := FoxScanner, D := Debugging, SyntaxTree := FoxSyntaxTree, Global := FoxGlobal,  Diagnostics;
 
 CONST
-	Trace = FALSE;
+	Trace = FALSE;	
 	CascadedWithSupport = TRUE;
 	Lax=FALSE;
 
@@ -153,7 +153,7 @@ CONST
 
 	Number               = Integer | Real.
 
-	Integer              = Digit {Digit} | Digit {HexDigit} 'H'.
+	Integer              = Digit {Digit} | '0' 'x' {HexDigit} | Digit {HexDigit} 'H' .
 
 	Real                 = Digit {Digit} '.' {Digit} [ScaleFactor].
 

+ 17 - 1
source/FoxSemanticChecker.Mod

@@ -107,6 +107,7 @@ TYPE
 		activeCellsSpecification: ActiveCells.Specification;
 		replacements*: Replacement;
 		cellsAreObjects: BOOLEAN;
+		variableAccessed: BOOLEAN;
 
 		PROCEDURE &InitChecker*(diagnostics: Diagnostics.Diagnostics; verboseErrorMessage,useDarwinCCalls,cooperative: BOOLEAN; system: Global.System; symbolFileFormat: Formats.SymbolFileFormat; activeCellsSpecification: ActiveCells.Specification; VAR importCache: SyntaxTree.ModuleScope);
 		BEGIN
@@ -526,8 +527,13 @@ TYPE
 				END;
 				IF x.length # NIL THEN
 				
+					variableAccessed := FALSE;
 					e := ResolveExpression(x.length);
-					IF e.resolved = NIL THEN
+			
+					IF (e.resolved = NIL) THEN
+						IF variableAccessed THEN
+							Error(e.position, Diagnostics.Invalid, "forbidden variable access");
+						END;
 						x.SetLength(e); x.SetForm(SyntaxTree.SemiDynamic);
 					ELSE
 						x.SetLength(ConstantIntegerGeq0(e (*x.length*)));
@@ -3548,6 +3554,7 @@ TYPE
 				assignable := assignable & (SyntaxTree.InternalWrite IN symbol.access);
 			END;
 
+				
 			assignable := assignable & ((symbol IS SyntaxTree.Variable) OR (symbol IS SyntaxTree.Parameter)
 				& (symbol(SyntaxTree.Parameter).kind # SyntaxTree.ConstParameter) & ~(symbol(SyntaxTree.Parameter).ownerType IS SyntaxTree.CellType));
 
@@ -3558,6 +3565,10 @@ TYPE
 			IF symbol IS SyntaxTree.Constant THEN
 				result.SetResolved(symbol(SyntaxTree.Constant).value.resolved);
 			END;
+			
+			IF (symbol IS SyntaxTree.Variable) & ~(symbol IS SyntaxTree.Property) THEN
+				variableAccessed := TRUE
+			END;
 
 			IF (left = NIL) OR (left IS SyntaxTree.SelfDesignator) OR (left IS SyntaxTree.DereferenceDesignator) & (left(SyntaxTree.DereferenceDesignator).left IS SyntaxTree.SelfDesignator) THEN
 				IF GetGuard(symbol,guardType) THEN
@@ -6370,13 +6381,17 @@ TYPE
 			- check symbol
 		**)
 		PROCEDURE VisitTypeDeclaration(typeDeclaration: SyntaxTree.TypeDeclaration);
+		VAR prevScope: SyntaxTree.Scope;
 		BEGIN
 			IF Trace THEN D.Str("VisitTypeDeclaration "); D.Str0(typeDeclaration.name);  D.Ln;  END;
 			IF SymbolNeedsResolution(typeDeclaration) THEN
+				prevScope := currentScope;
+				currentScope := typeDeclaration.scope;
 				typeDeclaration.SetType(SyntaxTree.typeDeclarationType);
 				typeDeclaration.SetDeclaredType(ResolveType(typeDeclaration.declaredType));
 				CheckSymbolVisibility(typeDeclaration);
 				typeDeclaration.SetState(SyntaxTree.Resolved);
+				currentScope := prevScope;
 			END;
 		END VisitTypeDeclaration;
 
@@ -6465,6 +6480,7 @@ TYPE
 		BEGIN
 			IF Trace THEN D.Str("VisitVariable "); D.Str0(variable.name);  D.Ln;  END;
 			IF SymbolNeedsResolution(variable) THEN
+
 				modifiers := variable.modifiers;
 				(*
 				flags := Flags(variable.modifiers,{SyntaxTree.UntracedFlag, SyntaxTree.AlignedFlag, SyntaxTree.FixedFlag});