瀏覽代碼

fix code generation

Vladislav Folts 10 年之前
父節點
當前提交
813025a2d6

+ 8 - 8
src/eberon/eberon_context.js

@@ -493,21 +493,23 @@ var RecordDecl = Context.RecordDecl.extend({
         return EberonRecord.makeRecordField(field, type, this.__type);
     },
     _generateBaseConstructorCallCode: function(){
-        var actualConstructor = EberonRecord.constructor$(this.type());
-        if (!actualConstructor || !actualConstructor.args().length)
+        var base = Type.recordBase(this.type());
+        if (!base)
+            return "";
+        var baseConstructor = EberonRecord.constructor$(base);
+        if (!baseConstructor || !baseConstructor.args().length)
             return Context.RecordDecl.prototype._generateBaseConstructorCallCode.call(this);
         
-        var result = this._qualifiedBaseConstructor();
-        return result ? result + ".apply(this, arguments);\n" : "";
+        return this._qualifiedBaseConstructor() + ".apply(this, arguments);\n";
     },
     endParse: function(){
         var type = this.type();
         if (!type.customConstructor)
             return Context.RecordDecl.prototype.endParse.call(this);
 
+        this.codeGenerator().write(this._generateInheritance());
         type.setRecordInitializationCode(
-            this._generateBaseConstructorCallCode(),
-            this._generateInheritance());
+            this._generateBaseConstructorCallCode());
     }
 });
 
@@ -704,8 +706,6 @@ var ProcOrMethodDecl = Context.ProcDecl.extend({
                     throw new Errors.Error("base record constructor has parameters but was not called (use '| SUPER' to pass parameters to base constructor)");
                 if (this.__baseConstructorWasCalled && (!baseConstructor || !baseConstructor.args().length))
                     throw new Errors.Error("base record constructor has no parameters and will be called automatically (do not use '| SUPER' to call base constructor)");
-                
-                this.codeGenerator().write(this.__boundType.inheritanceCode);
             }
             else
                 this.__boundType.defineMethod(this.__methodId, this.__methodType);

+ 7 - 3
test/expected/eberon/constructor.js

@@ -7,6 +7,10 @@ var RTL$ = {
     }
 };
 var m = function (){
+RTL$.extend(Derived, T);
+RTL$.extend(RecordWithFieldDerived, T);
+RTL$.extend(DerivedRecordWithParamConstructor, RecordWithParamConstructor);
+RTL$.extend(DerivedRecordWithParamConstructorBaseWithNoParameters, T);
 function DerivedRecordWithParamConstructorWithoutConstructor(){
 	RecordWithParamConstructor.apply(this, arguments);
 }
@@ -32,14 +36,12 @@ function T(){
 function Derived(){
 	T.call(this);
 }
-RTL$.extend(Derived, T);
 function RecordWithField(){
 	this.i = 0;
 }
 function RecordWithFieldDerived(){
 	T.call(this);
 }
-RTL$.extend(RecordWithFieldDerived, T);
 
 function passAsArgument(o/*T*/){
 }
@@ -48,7 +50,9 @@ function RecordWithParamConstructor(a/*INTEGER*/){
 function DerivedRecordWithParamConstructor(){
 	RecordWithParamConstructor.call(this, 123);
 }
-RTL$.extend(DerivedRecordWithParamConstructor, RecordWithParamConstructor);
+function DerivedRecordWithParamConstructorBaseWithNoParameters(a/*INTEGER*/){
+	T.call(this);
+}
 function InitializeField(){
 	this.i = 123;
 }

+ 7 - 0
test/input/eberon/constructor.ob

@@ -26,6 +26,10 @@ TYPE
         PROCEDURE DerivedRecordWithParamConstructor();
     END;
 
+    DerivedRecordWithParamConstructorBaseWithNoParameters = RECORD(T)
+        PROCEDURE DerivedRecordWithParamConstructorBaseWithNoParameters(a: INTEGER);
+    END;
+
     DerivedRecordWithParamConstructorWithoutConstructor = RECORD(RecordWithParamConstructor)
     END;
 
@@ -109,6 +113,9 @@ PROCEDURE DerivedRecordWithParamConstructor.DerivedRecordWithParamConstructor()
     | SUPER(123);
 END;
 
+PROCEDURE DerivedRecordWithParamConstructorBaseWithNoParameters.DerivedRecordWithParamConstructorBaseWithNoParameters(a: INTEGER);
+END;
+
 PROCEDURE InitializeField.InitializeField()
     | i(123);
 END;

+ 13 - 0
test/input/eberon/run/constructor.ob

@@ -15,6 +15,12 @@ TYPE
     Derived = RECORD(ConstructorWithParam)
     END;
 
+    TypeExtensionShouldBeMadeBeforeAnyMethodDefinition = RECORD(T)
+        PROCEDURE TypeExtensionShouldBeMadeBeforeAnyMethodDefinition();
+
+        PROCEDURE method();
+    END;
+
 PROCEDURE T.T();
 BEGIN
     SELF.i := 3;
@@ -24,7 +30,14 @@ PROCEDURE ConstructorWithParam.ConstructorWithParam(i: INTEGER)
     | i(i);
 END;
 
+PROCEDURE TypeExtensionShouldBeMadeBeforeAnyMethodDefinition.method();
+END;
+
+PROCEDURE TypeExtensionShouldBeMadeBeforeAnyMethodDefinition.TypeExtensionShouldBeMadeBeforeAnyMethodDefinition();
+END;
+
 BEGIN
     ASSERT(T().i = 3);
     ASSERT(Derived(123).i = 123);
+    TypeExtensionShouldBeMadeBeforeAnyMethodDefinition().method();
 END m.