From ee668df440e1be883e8d39fe065c99ca1474ed3b Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Fri, 21 Feb 2014 12:27:52 +0100 Subject: [PATCH 1/2] Fixed: Ivars with accessors in a Category failed with duplicate ivar error --- Objective-J/ObjJAcornCompiler.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index 3f684bb77..ba69ecb53 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -1663,6 +1663,8 @@ ClassDeclarationStatement: function(node, st, c) { compiler.currentSuperMetaClass = "objj_getMetaClass(\"" + className + "\").super_class"; var firstIvarDeclaration = true, + ivars = classDef.ivars, + classDefIvars = [], hasAccessors = false; // Then we add all ivars @@ -1672,7 +1674,6 @@ ClassDeclarationStatement: function(node, st, c) { var ivarDecl = node.ivardeclarations[i], ivarType = ivarDecl.ivartype ? ivarDecl.ivartype.name : null, ivarName = ivarDecl.id.name, - ivars = classDef.ivars, ivar = {"type": ivarType, "name": ivarName}, accessors = ivarDecl.accessors; @@ -1694,7 +1695,10 @@ ClassDeclarationStatement: function(node, st, c) { if (ivarDecl.outlet) ivar.outlet = true; - ivars[ivarName] = ivar; + + // Store the classDef ivars into array and add them later when accessors are created to prevent ivar duplicate error when generating accessors + classDefIvars.push(ivar); + if (!classScope.ivars) classScope.ivars = Object.create(null); classScope.ivars[ivarName] = {type: "ivar", name: ivarName, node: ivarDecl.id, ivar: ivar}; @@ -1784,7 +1788,16 @@ ClassDeclarationStatement: function(node, st, c) { compiler.imBuffer.concat(imBuffer); } - // We will store the classDef first after accessors are done so we don't get a duplicate class error + // We will store the ivars into the classDef first after accessors are done so we don't get a duplicate ivars error when generating accessors + for (var ivarSize = classDefIvars.length, i = 0; i < ivarSize; i++) { + var ivar = classDefIvars[i], + ivarName = ivar.name; + + // Store the ivar into the classDef + ivars[ivarName] = ivar; + } + + // We will store the classDef first after accessors are done so we don't get a duplicate class error when generating accessors compiler.classDefs[className] = classDef; var bodies = node.body, From a740f6073465350f0579e73342727ea42e8d6a6d Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 17 Apr 2014 16:18:21 +0200 Subject: [PATCH 2/2] Fixed: Added test case --- .../Preprocessor/OutputTests/Class/accessors.j | 11 +++++++++++ .../Preprocessor/OutputTests/Class/accessors.js | 13 +++++++++++++ .../Preprocessor/OutputTests/OutputTest.j | 1 + 3 files changed, 25 insertions(+) create mode 100644 Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.j create mode 100644 Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.js diff --git a/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.j b/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.j new file mode 100644 index 000000000..fe7fcc5de --- /dev/null +++ b/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.j @@ -0,0 +1,11 @@ + +@implementation Class +{ +} +@end + +@implementation Class (Accessors) +{ + Type ivar @accessors; +} +@end diff --git a/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.js b/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.js new file mode 100644 index 000000000..9db2e1754 --- /dev/null +++ b/Tests/Objective-J/Preprocessor/OutputTests/Class/accessors.js @@ -0,0 +1,13 @@ +var the_class=objj_allocateClassPair(Nil,"Class"),meta_class=the_class.isa; +objj_registerClassPair(the_class); +var the_class=objj_getClass("Class"); +if(!the_class){ +throw new SyntaxError("*** Could not find definition for class \"Class\""); +} +var meta_class=the_class.isa; +class_addIvars(the_class,[new objj_ivar("ivar")]); +class_addMethods(the_class,[new objj_method(sel_getUid("ivar"),function $Class__ivar(_1,_2){ +return _1.ivar; +},["Type"]),new objj_method(sel_getUid("setIvar:"),function $Class__setIvar_(_3,_4,_5){ +_3.ivar=_5; +},["void","Type"])]); \ No newline at end of file diff --git a/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j b/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j index 302ce7823..00db05981 100644 --- a/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j +++ b/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j @@ -6,6 +6,7 @@ var FILENAMES = [ "Class/root-class", "Class/root-class-one-ivar", "Class/root-class-multiple-ivars", + "Class/accessors", "Messages/no-parameters", "Messages/one-parameter",