Browse Source

detect recursive conversions

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7830 8c9fc860-2736-0410-a75d-ab315db34111
felixf 7 years ago
parent
commit
df9cac450f
1 changed files with 22 additions and 9 deletions
  1. 22 9
      source/FoxSemanticChecker.Mod

+ 22 - 9
source/FoxSemanticChecker.Mod

@@ -88,6 +88,7 @@ TYPE
 		system-: Global.System;
 		system-: Global.System;
 		symbolFileFormat-: Formats.SymbolFileFormat;
 		symbolFileFormat-: Formats.SymbolFileFormat;
 		backendName-: ARRAY 32 OF CHAR;
 		backendName-: ARRAY 32 OF CHAR;
+		inConversion: LONGINT;
 
 
 
 
 		(* temporary variables for the visitors
 		(* temporary variables for the visitors
@@ -140,6 +141,7 @@ TYPE
 			withEntries := NIL;
 			withEntries := NIL;
 			SELF.cellsAreObjects := system.cellsAreObjects;
 			SELF.cellsAreObjects := system.cellsAreObjects;
 			COPY(backend, backendName);
 			COPY(backend, backendName);
+			inConversion := 0;
 		END InitChecker;
 		END InitChecker;
 
 
 		(** report error **)
 		(** report error **)
@@ -2631,15 +2633,26 @@ TYPE
 				(* no type can be converted to an array-structured object type *)
 				(* no type can be converted to an array-structured object type *)
 				HALT(100)
 				HALT(100)
 			ELSIF (type IS SyntaxTree.MathArrayType) THEN
 			ELSIF (type IS SyntaxTree.MathArrayType) THEN
-				IF expression.type.resolved IS SyntaxTree.MathArrayType THEN
-					result := MathArrayConversion(position, expression,type);
-				ELSIF IsArrayStructuredObjectType(expression.type) THEN
-					expression := ConvertToMathArray(expression);
-					type := MathArrayStructureOfType(type);
-					result := MathArrayConversion(position, expression, type)
-				ELSE
-					Error(expression.position,"cannot convert non array type to array type")
-				END;
+					IF inConversion>5 THEN 
+						Error(expression.position,"recursive Conversion");
+						IF VerboseErrorMessage THEN
+							Printout.Info("expression",expression);
+							Printout.Info("type",type);
+						END;
+					END;
+					INC(inConversion); 
+					IF inConversion < 10 THEN 
+						IF expression.type.resolved IS SyntaxTree.MathArrayType THEN
+							result := MathArrayConversion(position, expression,type);
+						ELSIF IsArrayStructuredObjectType(expression.type) THEN
+							expression := ConvertToMathArray(expression);
+							type := MathArrayStructureOfType(type);
+							result := MathArrayConversion(position, expression, type)
+						ELSE
+							Error(expression.position,"cannot convert non array type to array type")
+						END;
+					END;
+					DEC(inConversion);
 			ELSIF (expression.type.resolved IS SyntaxTree.MathArrayType) THEN
 			ELSIF (expression.type.resolved IS SyntaxTree.MathArrayType) THEN
 					IF (expression.type.resolved(SyntaxTree.MathArrayType).form # SyntaxTree.Static)
 					IF (expression.type.resolved(SyntaxTree.MathArrayType).form # SyntaxTree.Static)
 						OR ~(type IS SyntaxTree.ArrayType) THEN
 						OR ~(type IS SyntaxTree.ArrayType) THEN