From 586c9d3139654a0dfd6687e4601a1874fb6d0674 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Fri, 18 Jan 2013 21:23:11 +0100 Subject: [PATCH] Fixed "Can't find superclass 'MyClass' " problem when compiling accessors to class with superclass in same file. --- Objective-J/ObjJAcornCompiler.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index 6f9460867..f893b5e17 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -116,7 +116,7 @@ var currentCompilerFlags = ""; var reservedIdentifiers = exports.acorn.makePredicate("self _cmd undefined localStorage arguments"); -var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, /*unsigned*/ pass) +var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, /*unsigned*/ pass, /* Dictionary */ classDefs) { this.source = aString; this.URL = new CFURL(aURL); @@ -144,7 +144,7 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* this.dependencies = []; this.flags = flags | ObjJAcornCompiler.Flags.IncludeDebugSymbols; - this.classDefs = Object.create(null); + this.classDefs = classDefs ? classDefs : Object.create(null); this.lastPos = 0; compile(this.tokens, new Scope(null ,{ compiler: this }), pass === 2 ? pass2 : pass1); } @@ -157,9 +157,9 @@ exports.ObjJAcornCompiler.compileToExecutable = function(/*String*/ aString, /*C return new ObjJAcornCompiler(aString, aURL, flags, 2).executable(); } -exports.ObjJAcornCompiler.compileToIMBuffer = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +exports.ObjJAcornCompiler.compileToIMBuffer = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, classDefs) { - return new ObjJAcornCompiler(aString, aURL, flags, 2).IMBuffer(); + return new ObjJAcornCompiler(aString, aURL, flags, 2, classDefs).IMBuffer(); } exports.ObjJAcornCompiler.compileFileDependencies = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) @@ -438,7 +438,6 @@ ClassDeclarationStatement: function(node, st, c) { throw new SyntaxError(st.compiler.error_message("Can't find superclass " + node.superclassname.name, node.superclassname)); classDef = {"className": className, "superClassName": node.superclassname.name, "ivars": Object.create(null), "methods": Object.create(null)}; - st.compiler.classDefs[className] = classDef; CONCAT(saveJSBuffer, "{var the_class = objj_allocateClassPair(" + node.superclassname.name + ", \"" + className + "\"),\nmeta_class = the_class.isa;"); } @@ -455,7 +454,6 @@ ClassDeclarationStatement: function(node, st, c) { else { classDef = {"className": className, "superClassName": null, "ivars": Object.create(null), "methods": Object.create(null)}; - st.compiler.classDefs[className] = classDef; CONCAT(saveJSBuffer, "{var the_class = objj_allocateClassPair(Nil, \"" + className + "\"),\nmeta_class = the_class.isa;"); } @@ -553,13 +551,16 @@ ClassDeclarationStatement: function(node, st, c) { // Remove all @accessors or we will get a recursive loop in infinity var b = getterSetterBuffer.toString().replace(/@accessors(\(.*\))?/g, ""); - var imBuffer = ObjJAcornCompiler.compileToIMBuffer(b, "Accessors", st.compiler.flags); + var imBuffer = ObjJAcornCompiler.compileToIMBuffer(b, "Accessors", st.compiler.flags, st.compiler.classDefs); // Add the accessors methods first to instance method buffer. // This will allow manually added set and get methods to override the compiler generated CONCAT(st.compiler.imBuffer, imBuffer); } + // We will store the classDef first after accessors are done so we don't get a duplicate class error + st.compiler.classDefs[className] = classDef; + if (node.body.length > 0) { st.compiler.lastPos = node.body[0].start;