Przeglądaj źródła

bug fix for specific pointer to pointer declaration

Vladislav Folts 11 lat temu
rodzic
commit
8ff151821c
3 zmienionych plików z 14 dodań i 16 usunięć
  1. 9 12
      src/context.js
  2. 1 2
      test/input/pointer.ob
  3. 4 2
      test/test_unit.js

+ 9 - 12
src/context.js

@@ -562,13 +562,18 @@ exports.ProcParams = ChainedContext.extend({
 exports.PointerDecl = ChainedContext.extend({
     init: function PointerDecl(context){
         ChainedContext.prototype.init.call(this, context);
-        this.__base = undefined;
-   } ,
+    },
     setType: function(type){
         if (!(type instanceof Type.ForwardRecord) && !(type instanceof Type.Record))
             throw new Errors.Error(
                 "RECORD is expected as a POINTER base type, got '" + type.description() + "'");
-        this.__base = type;
+
+        var parent = this.parent();
+        var name = parent.isAnonymousDeclaration() 
+            ? undefined
+            : parent.genTypeName();
+        var pointerType = new Type.Pointer(name, type);
+        parent.setType(pointerType);
     },
     findSymbol: function(id){
         var parent = this.parent();
@@ -587,15 +592,7 @@ exports.PointerDecl = ChainedContext.extend({
             );
     },
     isAnonymousDeclaration: function(){return true;},
-    exportField: function(field){this.parent().exportField(field);},
-    endParse: function(){
-        var parent = this.parent();
-        var name = parent.isAnonymousDeclaration() 
-            ? undefined
-            : parent.genTypeName();
-        var type = new Type.Pointer(name, this.__base);
-        parent.setType(type);
-    }
+    exportField: function(field){this.parent().exportField(field);}
 });
 
 exports.ArrayDecl = ChainedContext.extend({

+ 1 - 2
test/input/pointer.ob

@@ -1,7 +1,7 @@
 MODULE m;
 TYPE
 	T = RECORD p: POINTER TO T; i: INTEGER END;
-	T2 = POINTER TO RECORD p: POINTER TO T(*2*) END;
+	T2 = POINTER TO RECORD p: POINTER TO T END;
 
     PForward = POINTER TO Forward;
     Forward = RECORD END;
@@ -18,7 +18,6 @@ BEGIN
 
 	NEW(r2);
 	NEW(r2.p);
-	(*r2.p := r2;*)
 
 	NEW(pf);
 

+ 4 - 2
test/test_unit.js

@@ -326,8 +326,10 @@ var testSuite = {
     fail(["T = POINTER TO INTEGER",
           "RECORD is expected as a POINTER base type, got 'INTEGER'"],
          ["T = POINTER TO POINTER TO RECORD END",
-          "RECORD is expected as a POINTER base type, got 'POINTER TO anonymous RECORD'"]
-          )
+          "RECORD is expected as a POINTER base type, got 'POINTER TO anonymous RECORD'"],
+         ["T = POINTER TO RECORD p: POINTER TO T END",
+          "RECORD is expected as a POINTER base type, got 'T'"]
+        )
     ),
 "POINTER forward declaration": testWithContext(
     context(Grammar.module, ""),