Sfoglia il codice sorgente

Improved fictive offsets

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6684 8c9fc860-2736-0410-a75d-ab315db34111
felixf 9 anni fa
parent
commit
448f472e3d
3 ha cambiato i file con 9 aggiunte e 2 eliminazioni
  1. 4 1
      source/FoxGlobal.Mod
  2. 5 0
      source/FoxSemanticChecker.Mod
  3. 0 1
      source/FoxSyntaxTree.Mod

+ 4 - 1
source/FoxGlobal.Mod

@@ -289,7 +289,7 @@ TYPE
 		END AddCapability;
 
 		PROCEDURE GenerateRecordOffsets*(x: SyntaxTree.RecordType): BOOLEAN; (* normally done in checker but the binary symbol file format makes this necessary *)
-		VAR baseType: SyntaxTree.RecordType; offset,size: LONGINT; alignment, thisAlignment: LONGINT; variable: SyntaxTree.Variable;
+		VAR baseType: SyntaxTree.RecordType; offset,baseOffset, size: LONGINT; alignment, thisAlignment: LONGINT; variable: SyntaxTree.Variable;
 		BEGIN
 			baseType :=x.GetBaseRecord();
 			IF (baseType  # NIL) & (baseType.sizeInBits < 0) THEN
@@ -302,6 +302,7 @@ TYPE
 				offset := 0; alignment := x.alignmentInBits;
 				IF alignment <= 0 THEN alignment := dataUnit END;
 			END;
+			baseOffset := offset;
 
 			variable := x.recordScope.firstVariable;
 			WHILE (variable # NIL) DO
@@ -319,6 +320,8 @@ TYPE
 
 					variable.SetOffset(offset);
 					INC(offset,size);
+				ELSE
+					variable.SetOffset(baseOffset + variable.fictiveOffset * dataUnit);
 				END;
 				variable := variable.nextVariable;
 			END;

+ 5 - 0
source/FoxSemanticChecker.Mod

@@ -2948,6 +2948,8 @@ TYPE
 						Printout.Info("left",left);
 						Printout.Info("right",right);
 					END;
+				ELSIF IsUnsafePointer(left.type) THEN
+					Error(binaryExpression.position,Diagnostics.Invalid,"forbidden type test on unsafe pointer");
 				ELSIF (leftType.SameType(right(SyntaxTree.SymbolDesignator).symbol(SyntaxTree.TypeDeclaration).declaredType.resolved)) & ~(leftType IS SyntaxTree.PointerType) THEN
 					NewBool(TRUE)
 				ELSIF right(SyntaxTree.SymbolDesignator).symbol(SyntaxTree.TypeDeclaration).declaredType.resolved IS SyntaxTree.AnyType THEN
@@ -6107,6 +6109,8 @@ TYPE
 				END;
 			ELSIF ~(left.type.resolved = type.resolved) & ~IsExtensibleDesignator(left) THEN (* left is not extensible *)
 				Error(position,Diagnostics.Invalid,"variable cannot be extended");
+			ELSIF IsUnsafePointer(left.type) THEN
+				Error(position,Diagnostics.Invalid,"forbidden type guard on unsafe pointer");
 			ELSE
 				result := SyntaxTree.NewTypeGuardDesignator(position,left,type);
 				result.SetType(type);
@@ -6602,6 +6606,7 @@ TYPE
 					END;
 					variable.SetFictive(value);
 					variable.SetOffset(value*system.dataUnit);
+					IF ContainsPointer(variable.type) THEN variable.SetUntraced(TRUE) END;
 				END;
 				IF HasFlag(modifiers, Global.NameRegister, position) THEN variable.SetUseRegister(TRUE) END;
 				IF variable.type.resolved IS SyntaxTree.CellType THEN

+ 0 - 1
source/FoxSyntaxTree.Mod

@@ -3237,7 +3237,6 @@ TYPE
 		BEGIN
 			fictive := TRUE;
 			fictiveOffset := offset;
-			SetUntraced(TRUE);
 		END SetFictive;
 		
 		PROCEDURE SetModifiers*(flag: Modifier);