瀏覽代碼

Improved fingerprinting: many more cases don't go unnoticed
It is currently still posssible that a change in the objects interface goes unnoticed when an importing module only accesses the method table (because then there is no need to access the type declaration which carries the fingerprint)

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7265 8c9fc860-2736-0410-a75d-ab315db34111

felixf 8 年之前
父節點
當前提交
bbdfaf6b4f

+ 42 - 2
source/FoxFingerPrinter.Mod

@@ -361,6 +361,8 @@ TYPE
 
 				IF x.form = SyntaxTree.Static THEN FPNumber(fp,x.staticLength) END;
 				fingerprint.shallow := fp;
+				fingerprint.public := fingerprint.shallow;
+				fingerprint.private := fingerprint.shallow;
 				x.SetFingerPrint(fingerprint);
 				SELF.deep := deep;
 			END;
@@ -408,6 +410,8 @@ TYPE
 				END;
 				IF x.form = SyntaxTree.Static THEN FPNumber(fp,x.staticLength) END;
 				fingerprint.shallow := fp;
+				fingerprint.public := fingerprint.shallow;
+				fingerprint.private := fingerprint.shallow;
 				fingerprint.shallowAvailable := TRUE;
 				x.SetFingerPrint(fingerprint);
 				SELF.deep := deep;
@@ -482,7 +486,7 @@ TYPE
 		PrivateFP(PointerType)     = 0.
 		*)
 		PROCEDURE VisitPointerType(x: SyntaxTree.PointerType);
-		VAR fingerprint: FingerPrint; fp: LONGINT; deep: BOOLEAN;
+		VAR fingerprint,typeFP: FingerPrint; fp: LONGINT; deep: BOOLEAN;
 		BEGIN
 			IF Trace THEN TraceEnter("PointerType");  END;
 			fingerprint := x.fingerprint;
@@ -508,8 +512,11 @@ TYPE
 					fingerprint.deepAvailable := TRUE;
 				END;
 				*)
+				x.SetFingerPrint(fingerprint);
 				SELF.deep := deep;
 			END;
+			
+			
 			IF Trace THEN TraceExit("PointerType",fingerprint) END;
 
 			SELF.fingerprint := fingerprint;
@@ -566,6 +573,8 @@ TYPE
 				FPString(fp,name);
 				FPSignature(fp,procedure.type(SyntaxTree.ProcedureType),procedure IS SyntaxTree.Operator );
 				fingerprint.shallow := fp;
+				fingerprint.public := fingerprint.shallow;
+				fingerprint.private := fingerprint.shallow;
 				fingerprint.shallowAvailable := TRUE;
 				procedure.SetFingerPrint(fingerprint)
 			ELSE
@@ -654,6 +663,8 @@ TYPE
 				END;
 
 				fingerprint.shallow := fp;
+				fingerprint.public := fingerprint.shallow;
+				fingerprint.private := fingerprint.shallow;
 				fingerprint.shallowAvailable := TRUE;
 
 				x.SetFingerPrint(fingerprint);
@@ -721,6 +732,8 @@ TYPE
 					END;
 					variable := variable.nextVariable;
 				END;
+				FPNumber(fingerprint.private, SHORT(x.sizeInBits DIV 8));
+				FPNumber(fingerprint.public, SHORT(x.sizeInBits DIV 8));
 
 				flags := {};
 				IF x.recordScope.bodyProcedure # NIL THEN
@@ -966,6 +979,7 @@ TYPE
 		PROCEDURE VisitTypeDeclaration(x: SyntaxTree.TypeDeclaration);
 		VAR fp: LONGINT;
 			fingerprint: FingerPrint; deep: BOOLEAN;
+			typeFP: FingerPrint;
 		BEGIN
 			fingerprint := x.fingerprint;
 
@@ -978,15 +992,29 @@ TYPE
 				FPName(fp,x.name);
 				IF Trace THEN TraceIndent; D.String("access="); D.Set(x.access); D.Ln;  END;
 				FPVisibility(fp, x.access);
-
 				x.declaredType.Accept(SELF);
 				FPNumber(fp, SELF.fingerprint.shallow);
 				fingerprint.shallow := fp;
+				fingerprint.public := fp;
+				fingerprint.private := fp;
 				fingerprint.shallowAvailable := TRUE;
 				x.SetFingerPrint(fingerprint);
 				SELF.deep := deep;
 				IF Trace THEN TraceExit("TypeDeclaration",fingerprint) END;
 			END;
+			
+			IF deep & ~fingerprint.deepAvailable THEN
+				fingerprint := x.fingerprint;
+				typeFP := TypeFP(x.declaredType);
+				IF x.declaredType.resolved IS SyntaxTree.PointerType THEN
+					typeFP := TypeFP(x.declaredType.resolved(SyntaxTree.PointerType).pointerBase);
+				END;
+				FPNumber(fingerprint.public, typeFP.public);
+				FPNumber(fingerprint.private, typeFP.private);
+				fingerprint.deepAvailable := TRUE;
+				x.SetFingerPrint(fingerprint);
+			END;
+
 			SELF.fingerprint := fingerprint
 		END VisitTypeDeclaration;
 
@@ -1014,6 +1042,8 @@ TYPE
 				FPNumber(fp, fpTypeBasic);
 				FPValue(fp, x.value);
 				fingerprint.shallow := fp;
+				fingerprint.public := fingerprint.shallow;
+				fingerprint.private := fingerprint.shallow;
 				fingerprint.shallowAvailable := TRUE;
 				x.SetFingerPrint(fingerprint);
 				SELF.deep := deep;
@@ -1040,6 +1070,8 @@ TYPE
 				x.type.Accept(SELF);
 				FPNumber(fp,SELF.fingerprint.shallow);
 				fingerprint.shallow := fp;
+				fingerprint.public := fingerprint.shallow;
+				fingerprint.private := fingerprint.shallow;
 				fingerprint.shallowAvailable := TRUE;
 				x.SetFingerPrint(fingerprint);
 				SELF.deep := deep;
@@ -1072,6 +1104,8 @@ TYPE
 				x.type.Accept(SELF);
 				FPNumber(fp,SELF.fingerprint.shallow);
 				fingerprint.shallow := fp;
+				fingerprint.public := fingerprint.shallow;
+				fingerprint.private := fingerprint.shallow;
 				fingerprint.shallowAvailable := TRUE;
 				x.SetFingerPrint(fingerprint);
 				SELF.deep := deep;
@@ -1124,6 +1158,8 @@ TYPE
 						FPSignature(fp,x.type(SyntaxTree.ProcedureType),x IS SyntaxTree.Operator);
 					END;
 					fingerprint.shallow := fp;
+					fingerprint.public := fingerprint.shallow;
+					fingerprint.private := fingerprint.shallow;
 					fingerprint.shallowAvailable := TRUE;
 					x.SetFingerPrint(fingerprint);
 					SELF.deep := deep;
@@ -1156,6 +1192,8 @@ TYPE
 				IF Trace THEN TraceIndent; D.Str("Module Name ");D.Hex(fp,-8);  D.Ln; END;
 
 				fingerprint.shallow := fp;
+				fingerprint.public := fingerprint.shallow;
+				fingerprint.private := fingerprint.shallow;
 				fingerprint.shallowAvailable := TRUE;
 				x.SetFingerPrint(fingerprint);
 				SELF.deep := deep;
@@ -1199,6 +1237,8 @@ TYPE
 		PROCEDURE VisitSymbol(x: SyntaxTree.Symbol);
 		BEGIN
 			fingerprint.shallow := 0;
+			fingerprint.public := fingerprint.shallow;
+			fingerprint.private := fingerprint.shallow;
 			fingerprint.shallowAvailable := TRUE;
 			x.SetFingerPrint(fingerprint);
 		END VisitSymbol;

+ 5 - 5
source/FoxIntermediateBackend.Mod

@@ -1443,7 +1443,7 @@ TYPE
 		BEGIN
 			fingerPrint := fingerPrinter.SymbolFP(symbol);
 			string := "[";
-			Strings.IntToHexStr(fingerPrint.shallow, 8, fingerPrintString);
+			Strings.IntToHexStr(fingerPrint.public, 8, fingerPrintString);
 			Strings.Append(string, fingerPrintString);
 			Strings.Append(string, "]");
 		END GetFingerprintString;
@@ -5866,7 +5866,7 @@ TYPE
 							(* push fingerprint *)
 							(* IF dump # NIL THEN dump.String("push fingerprint"); dump.Ln; dump.Update END; *) (* TENTATIVE *)
 							fingerPrint := fingerPrinter.TypeFP(formalParameter.type.resolved);
-							Emit(Push(position,IntermediateCode.Immediate(IntermediateCode.GetType(system, system.longintType), fingerPrint.shallow))) (* TODO: push the type's fingerprint *)
+							Emit(Push(position,IntermediateCode.Immediate(IntermediateCode.GetType(system, system.longintType), fingerPrint.public))) (* TODO: push the type's fingerprint *)
 						END
 					END;
 					formalParameter := formalParameter.nextParameter
@@ -6262,7 +6262,7 @@ TYPE
 					(* non-pointer to record type: push fingerprint *)
 					(* IF dump # NIL THEN dump.String("push fingerprint"); dump.Ln; dump.Update END; *) (* TENTATIVE *)
 					fingerPrint := fingerPrinter.TypeFP(type.resolved);
-					arg := IntermediateCode.Immediate(IntermediateCode.GetType(system, system.longintType), fingerPrint.shallow)
+					arg := IntermediateCode.Immediate(IntermediateCode.GetType(system, system.longintType), fingerPrint.public)
 				END;
 				operatorInitializationCodeSection.Emit(Push(position,arg))
 			END PushTypeInfo;
@@ -11036,7 +11036,7 @@ TYPE
 		PROCEDURE GetFingerprint(symbol: SyntaxTree.Symbol): LONGINT;
 		BEGIN
 			IF (symbol # NIL) THEN
-				RETURN fingerPrinter.SymbolFP(symbol).shallow
+				RETURN fingerPrinter.SymbolFP(symbol).public
 			ELSE
 				RETURN 0
 			END;
@@ -11736,7 +11736,7 @@ TYPE
 				IF (symbol = NIL) OR (symbol # NIL) & (symbol.type # Sections.InlineCodeSection) THEN
 					IF (symbol # NIL) & (symbol.symbol # NIL) THEN 
 						fingerPrint := fingerPrinter.SymbolFP(symbol.symbol);
-						Longint(source,fingerPrint.shallow);
+						Longint(source,fingerPrint.public);
 					ELSE
 						Longint(source, 0);
 					END;

+ 1 - 1
source/FoxIntermediateCode.Mod

@@ -449,7 +449,7 @@ TYPE
 
 		(* create a new section and enter it *)
 		NEW(section, type, 0 (* initial priority = 0 *), name, syntaxTreeSymbol, dump);
-		IF syntaxTreeSymbol # NIL THEN section.SetFingerprint(syntaxTreeSymbol.fingerprint.shallow) END;
+		IF syntaxTreeSymbol # NIL THEN section.SetFingerprint(syntaxTreeSymbol.fingerprint.public) END;
 		list.AddSection(section);
 		RETURN section
 	END NewSection;

+ 1 - 1
source/FoxPrintout.Mod

@@ -1229,7 +1229,7 @@ TYPE
 				IF x.isInline & (mode = SymbolFile) THEN
 					IF fingerPrinter = NIL THEN NEW(fingerPrinter) END;
 					fp := fingerPrinter.SymbolFP(x);
-					Value(Global.NameFingerprint, fp.shallow, first) 
+					Value(Global.NameFingerprint, fp.public, first) 
 				END;
 				FlagEnd(first);
 

+ 2 - 0
source/FoxSemanticChecker.Mod

@@ -6912,6 +6912,8 @@ TYPE
 				IF HasValue(modifiers, Global.NameFingerprint, position, value) THEN 
 					SyntaxTree.InitFingerPrint(fp);
 					fp.shallow := value;
+					fp.public := value;
+					fp.private := value;
 					fp.shallowAvailable := TRUE;
 					procedure.SetFingerPrint(fp);
 				END;