Prechádzať zdrojové kódy

fix copy record with special JS fields

Vladislav Folts 10 rokov pred
rodič
commit
6787585cf0

BIN
bin/compiled.zip


+ 1 - 1
src/context.js

@@ -1787,7 +1787,7 @@ exports.RecordDecl = ChainedContext.extend({
         var ownFields = Type.recordOwnFields(this.__type);
         for(var f in ownFields){
             var fieldType = ownFields[f].type();
-            result += "this." + Type.mangleField(f, fieldType) + " = " + fieldType.initializer(this) + ";\n";
+            result += "this." + Type.mangleField(f) + " = " + fieldType.initializer(this) + ";\n";
         }
         return result;
     },

+ 4 - 4
src/eberon/EberonConstructor.ob

@@ -41,15 +41,15 @@ BEGIN
     RETURN Code.makeSimpleExpression(code, NIL);
 END;
 
-PROCEDURE fieldInitLval(field: STRING; type: Types.PStorageType): STRING;
-    RETURN "this." + Types.mangleField(field, type);
+PROCEDURE fieldInitLval(field: STRING): STRING;
+    RETURN "this." + Types.mangleField(field);
 END;
 
 PROCEDURE RecordInitCall.make(args: ARRAY OF Code.PExpression; cx: LanguageContext.PType): Code.PExpression;
 BEGIN
     e <- SUPER(args, cx);
     t <- e.type()(Types.PStorageType);
-    RETURN Code.makeSimpleExpression(fieldInitLval(SELF.field, t) + " = " + e.code(), t);
+    RETURN Code.makeSimpleExpression(fieldInitLval(SELF.field) + " = " + e.code(), t);
 END;
 
 PROCEDURE makeCallGenerator(
@@ -86,7 +86,7 @@ BEGIN
             Errors.raise("type mismatch: field '" + SELF.field + "' is '" + SELF.type.description()
                          + "' and cannot be initialized using '" + e.type().description() + "' expression");
     END;
-    lval <- fieldInitLval(SELF.field, SELF.type);
+    lval <- fieldInitLval(SELF.field);
     SELF.code := lval + " = " + op.clone(SELF.cx.rtl, e);
 END;
         

+ 1 - 1
src/eberon/EberonRecord.ob

@@ -502,7 +502,7 @@ BEGIN
         IF key IN r.fieldsInit THEN
             code := r.fieldsInit[key];
         ELSE
-            code := "this." + Types.mangleField(key, type) 
+            code := "this." + Types.mangleField(key) 
                     + " = " + type.initializer(cx^);
         END;
         result := result + code + ";" + Stream.kCR;

+ 1 - 1
src/eberon/EberonTypes.ob

@@ -73,7 +73,7 @@ PROCEDURE MethodField.asVar(isReadOnly: BOOLEAN; cx: Context.Type): Types.PId;
 END;
 
 PROCEDURE MethodField.designatorCode(leadCode: STRING; cx: Context.Type): Types.PFieldCode;
-    RETURN NEW Types.FieldCode(leadCode + "." + Types.mangleField(SELF.method.name, SELF.method), "", "");
+    RETURN NEW Types.FieldCode(leadCode + "." + Types.mangleField(SELF.method.name), "", "");
 END;
 
 END EberonTypes.

+ 3 - 3
src/ob/Types.ob

@@ -760,7 +760,7 @@ BEGIN
     RETURN result;
 END;
 
-PROCEDURE mangleField*(id: STRING; type: PStorageType): STRING;
+PROCEDURE mangleField*(id: STRING): STRING;
     RETURN mangleJSProperty(id);
 END;
 
@@ -780,7 +780,7 @@ PROCEDURE RecordField.designatorCode(leadCode: STRING; cx: Context.Type): PField
 CONST
     kQuote = 22X;
 BEGIN
-    codeId <- mangleField(SELF.mIdentdef.id(), SELF.mType);
+    codeId <- mangleField(SELF.mIdentdef.id());
     RETURN NEW FieldCode(leadCode + "." + codeId, leadCode, kQuote + codeId + kQuote);
 END;
 
@@ -808,7 +808,7 @@ BEGIN
         IF LEN(result) # 0 THEN
             result := result + ", ";
         END;
-        result := result + k + ": " + pGenerateTypeInfo(v.type());
+        result := result + mangleField(k) + ": " + pGenerateTypeInfo(v.type());
     END;
     RETURN result;
 END;

+ 17 - 0
test/input/run/copy.ob

@@ -83,6 +83,22 @@ BEGIN
 	ASSERT(r2.field = 2);
 END testBaseCopy;
 
+PROCEDURE testMangleFields(); 
+	TYPE     
+		T = RECORD         
+			constructor: INTEGER;         
+			prototype: CHAR     
+			END; 
+	VAR     
+		r1, r2: T; 
+BEGIN
+	r1.constructor := 123;     
+	r1.prototype := "a";     
+	r2 := r1;
+	ASSERT(r2.constructor = 123); 
+	ASSERT(r2.prototype = "a"); 
+END testMangleFields;
+
 BEGIN
 	a1[0].i1 := 123;
 	a1[0].proc1 := proc1;
@@ -100,4 +116,5 @@ BEGIN
 	testPointerAndRecordFieldsCopy();
 	testRecordArraysCopy();
 	testBaseCopy();
+	testMangleFields();
 END m.