2
0
Эх сурвалжийг харах

fix code generation when array field is passed as VAR

Vladislav Folts 11 жил өмнө
parent
commit
06ecbc59c5

+ 5 - 5
src/context.js

@@ -390,13 +390,13 @@ exports.Designator = ChainedContext.extend({
             new DesignatorInfo(code, refCode, this.__currentType, this.__info, this.__scope));
     },
     __makeRefCode: function(code){
+        if ((this.__currentType instanceof Type.Array)
+            || (this.__currentType instanceof Type.Record)
+            || (this.__info instanceof Type.VariableRef))
+            return code;
         if (this.__derefCode)
             return this.rtl().makeRef(this.__derefCode, this.__propCode);
-        if (!(this.__currentType instanceof Type.Array)
-            && !(this.__currentType instanceof Type.Record)
-            && !(this.__info instanceof Type.VariableRef))
-            return "{set: function($v){" + code + " = $v;}, get: function(){return " + code + ";}}";
-        return code;
+        return "{set: function($v){" + code + " = $v;}, get: function(){return " + code + ";}}";
     }
 });
 

+ 16 - 14
test/expected/var_parameter.js

@@ -1,18 +1,4 @@
 var RTL$ = {
-    extend: function extend(methods){
-        function Type(){
-            for(var m in methods)
-                this[m] = methods[m];
-        }
-        Type.prototype = this.prototype;
-
-        var result = methods.init;
-        result.prototype = new Type(); // inherit this.prototype
-        result.prototype.constructor = result; // to see constructor name in diagnostic
-        
-        result.extend = extend;
-        return result;
-    },
     makeArray: function (/*dimensions, initializer*/){
         var forward = Array.prototype.slice.call(arguments);
         var result = new Array(forward.shift());
@@ -31,6 +17,20 @@ var RTL$ = {
                 result[i] = this.makeArray.apply(this, forward);
         return result;
     },
+    extend: function extend(methods){
+        function Type(){
+            for(var m in methods)
+                this[m] = methods[m];
+        }
+        Type.prototype = this.prototype;
+
+        var result = methods.init;
+        result.prototype = new Type(); // inherit this.prototype
+        result.prototype.constructor = result; // to see constructor name in diagnostic
+        
+        result.extend = extend;
+        return result;
+    },
     makeRef: function (obj, prop){
         return {set: function(v){ obj[prop] = v; },
                 get: function(){ return obj[prop]; }};
@@ -40,6 +40,7 @@ var m = function (){
 var R = RTL$.extend({
 	init: function R(){
 		this.i = 0;
+		this.a = RTL$.makeArray(3, 0);
 		this.p = null;
 	}
 });
@@ -84,6 +85,7 @@ function p3(i/*VAR INTEGER*/, b/*VAR BOOLEAN*/){
 	p1(RTL$.makeRef(r.p, "i"), RTL$.makeRef(ar[j].p, "i"));
 	p2(ar[j].p.i, r.p.i == ar[j].p.i);
 	j = array(ai);
+	j = array(r.a);
 }
 p3({set: function($v){i = $v;}, get: function(){return i;}}, {set: function($v){b = $v;}, get: function(){return b;}});
 }();

+ 3 - 2
test/input/var_parameter.ob

@@ -1,6 +1,6 @@
 MODULE m;
 
-TYPE R = RECORD i: INTEGER; p: POINTER TO R END;
+TYPE R = RECORD i: INTEGER; a: ARRAY 3 OF INTEGER; p: POINTER TO R END;
 
 VAR 
 	i: INTEGER;
@@ -48,7 +48,8 @@ BEGIN
 	p1(r.p.i, ar[j].p.i);
 	p2(ar[j].p.i, r.p.i = ar[j].p.i);
 
-	j := array(ai)
+	j := array(ai);
+	j := array(r.a);
 END p3;
 
 BEGIN