瀏覽代碼

Added find in all object scopes (type and supertype)

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6651 8c9fc860-2736-0410-a75d-ab315db34111
felixf 9 年之前
父節點
當前提交
d10e8e725a
共有 3 個文件被更改,包括 46 次插入43 次删除
  1. 9 1
      source/FoxInterpreter.Mod
  2. 36 2
      source/FoxInterpreterSymbols.Mod
  3. 1 40
      source/Generic.Modules.Mod

+ 9 - 1
source/FoxInterpreter.Mod

@@ -938,7 +938,15 @@ TYPE
 		END VisitStatement;
 
 		PROCEDURE VisitProcedureCallStatement*(x: SyntaxTree.ProcedureCallStatement);
-		BEGIN x.call.Accept(SELF) END VisitProcedureCallStatement;
+		VAR call: SyntaxTree.Designator;
+		BEGIN
+			IF ~(x.call IS SyntaxTree.ParameterDesignator) THEN
+				call := SyntaxTree.NewParameterDesignator(x.position,x.call,SyntaxTree.NewExpressionList());
+			ELSE
+				call := x.call;
+			END;
+			call.Accept(SELF);
+		END VisitProcedureCallStatement;
 
 		PROCEDURE LoadValue;
 		BEGIN

+ 36 - 2
source/FoxInterpreterSymbols.Mod

@@ -312,7 +312,7 @@ TYPE
 			b: BOOLEAN;
 			set: SET;
 		BEGIN
-			IF index >= LEN(proc.parameters) THEN RETURN FALSE END; 
+			IF (proc.parameters = NIL) OR (index >= LEN(proc.parameters)) THEN RETURN FALSE END; 
 			type := proc.parameters[index].type;
 			INC(index);
 			
@@ -388,6 +388,7 @@ TYPE
 				RETURN set;
 			| sfTypeAny, sfTypeObject, sfTypePointerToRecord:  (* pointers are passed as varpars *)
 				RETURN NIL;
+			| 0X: RETURN NIL;
 			END;
 			RETURN NIL;
 		END Evaluate;
@@ -473,6 +474,8 @@ TYPE
 			 THEN
 				SYSTEM.GET(address, value);
 				SYSTEM.GET(value-SIZEOF(ADDRESS), type); (*  type desc *)
+				RETURN FindInType(SELF, value, type, name);
+				(*
 				SYSTEM.GET(type-SIZEOF(ADDRESS), typeInfo); (* type info*)
 				IF FindProc(typeInfo.procedures, name,num) THEN
 					NEW(proc, SELF, name, typeInfo.procedures[num]);
@@ -484,8 +487,11 @@ TYPE
 					RETURN f;
 				ELSE HALT(101);
 				END;
+				*)
 			ELSIF field.type.class = sfTypeRecord THEN
 				type := field.type.type;
+				RETURN FindInType(SELF, address, type, name);
+				(*
 				SYSTEM.GET(type-SIZEOF(ADDRESS), typeInfo); (* type info*)
 				IF FindProc(typeInfo.procedures, name,num) THEN
 					NEW(proc, SELF, name, typeInfo.procedures[num]);
@@ -497,12 +503,37 @@ TYPE
 					RETURN f;
 				ELSE HALT(101);
 				END;
+				*)
 			ELSE HALT(100); 
 			END;
 		END Find;
 		
 	END FieldResult;
 
+	(* traverse types and supertypes for first occurence of symbol name *) 	
+	PROCEDURE FindInType(scope: Result; address: ADDRESS; type: ADDRESS; CONST name: ARRAY OF CHAR): Result;
+	VAR tag: ADDRESS; typeInfo: Modules.TypeDesc; i, num: LONGINT; 
+			proc: ProcedureResult; f: FieldResult;	
+	BEGIN
+		FOR i := 15 TO 0 BY -1 DO
+			SYSTEM.GET(type-(2+i)*SIZEOF(ADDRESS), tag); 
+			IF tag # NIL THEN
+				SYSTEM.GET(tag-SIZEOF(ADDRESS), typeInfo); 
+				IF FindProc(typeInfo.procedures, name,num) THEN
+					NEW(proc, scope, name, typeInfo.procedures[num]);
+					proc.address := typeInfo.procedures[num].address;
+					RETURN proc
+				ELSIF FindField(typeInfo.fields, name, num) THEN
+					NEW(f, name, typeInfo.fields[num]);
+					f.address := address + typeInfo.fields[num].offset;
+					RETURN f;
+				END;
+			END;
+		END;
+		RETURN NIL; 
+	END FindInType;
+	
+TYPE
 	Value*= OBJECT(Result)
 
 		PROCEDURE & InitValue;
@@ -600,6 +631,8 @@ TYPE
 			IF value # NIL THEN 
 				address := value; 
 				SYSTEM.GET(address-SIZEOF(ADDRESS), type); (*  type desc *)
+				RETURN FindInType(SELF, address, type, name);
+				(*
 				SYSTEM.GET(type-SIZEOF(ADDRESS), typeInfo); (* type info*)
 				IF FindProc(typeInfo.procedures, name,num) THEN
 					NEW(proc, SELF, name, typeInfo.procedures[num]);
@@ -607,10 +640,11 @@ TYPE
 					RETURN proc
 				ELSIF FindField(typeInfo.fields, name, num) THEN
 					NEW(f, name, typeInfo.fields[num]);
-					f.address := v + typeInfo.fields[num].offset;
+					f.address := address + typeInfo.fields[num].offset;
 					RETURN f;
 				ELSE HALT(101);
 				END;
+				*)
 			ELSE
 				RETURN NIL;
 			END;

+ 1 - 40
source/Generic.Modules.Mod

@@ -65,46 +65,7 @@ TYPE
 		type*: ADDRESS; (* type descriptor or additional information *)
 	END;
 	
-	VAR
-	(*
-		EntryType = POINTER TO EntryTypeDesc;
-		shortint: EntryType;
-		integer: EntryType;
-		longint: EntryType;
-		hugeint: EntryType;
-		size: EntryType;
-		address: EntryType;
-		real: EntryType;
-		longreal: EntryType;
-		set: EntryType;
-		...
-	*)
-
-	(*
-	Type = POINTER {UNSAFE} TO RECORD
-		class: CHAR
-	END;
-	
-	BaseType = POINTER {UNSAFE} TO RECORD(Type)
-		size: INTEGER;
-		type: ADDRESS;
-	END;
-	
-	StaticArrayType = POINTER {UNSAFE} TO RECORD(Type)
-		size: SIZE;
-		base: POINTER {UNSAFE} TO Base;
-	END;
-	
-	DynamicArrayType = POINTER {UNSAFE} TO RECORD(Type)
-		base: POINTER {UNSAFE} TO Type;
-	END;
-	
-	RecordType = POINTER {UNSAFE} TO RECORD(Type)
-		type: ADDRESS;
-	END;
-	*)
-
-	FieldEntry*= RECORD
+	FieldEntry* = RECORD
 		name*: DynamicName;
 		offset*: SIZE; (* offset of this type *)
 		type*: EntryType;