Browse Source

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 years ago
parent
commit
bbdfaf6b4f

+ 42 - 2
source/FoxFingerPrinter.Mod

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

+ 5 - 5
source/FoxIntermediateBackend.Mod

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

+ 1 - 1
source/FoxIntermediateCode.Mod

@@ -449,7 +449,7 @@ TYPE
 
 
 		(* create a new section and enter it *)
 		(* create a new section and enter it *)
 		NEW(section, type, 0 (* initial priority = 0 *), name, syntaxTreeSymbol, dump);
 		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);
 		list.AddSection(section);
 		RETURN section
 		RETURN section
 	END NewSection;
 	END NewSection;

+ 1 - 1
source/FoxPrintout.Mod

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

+ 2 - 0
source/FoxSemanticChecker.Mod

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