diff --git a/lib/runtime.js b/lib/runtime.js index 3cd6f3e..266faa8 100644 --- a/lib/runtime.js +++ b/lib/runtime.js @@ -104,26 +104,6 @@ function throwUnrecognizedSelector(receiver, selector) } -function _registerCategory(classSymbol, callback) -{ - _callWhenClassReady(classSymbol, function() { - var cls = _classSymbolToClassMap[classSymbol]; - var instance_methods = { }; - var class_methods = { }; - - callback(class_methods, instance_methods); - - mixin(class_methods, cls, true, function(key, method) { - method.displayName = _getMethodDisplayName(classSymbol, key, "+"); - }); - - mixin(instance_methods, cls.prototype, true, function(key, method) { - method.displayName = _getMethodDisplayName(classSymbol, key, "-"); - }); - }); -} - - function _registerClass(classSymbol, superSymbol, callback) { var isSubclassOfBase = false; @@ -288,7 +268,6 @@ function msgSend(receiver, selector) var nilscript = { _id: 0, _registerClass: _registerClass, - _registerCategory: _registerCategory, _c: _classSymbolToClassMap, _g: { }, _reset: _reset, diff --git a/src/Builder.js b/src/Builder.js index b97510b..eb44fb5 100644 --- a/src/Builder.js +++ b/src/Builder.js @@ -34,7 +34,7 @@ build() let traverser = new Traverser(nsFile.ast); - let currentClass, currentMethod, currentCategoryName; + let currentClass, currentMethod; let currentProtocol; let usedSelectorMap = { }; @@ -124,34 +124,18 @@ build() function handleNSClassImplementation(node) { let className = node.id.name; - let categoryName = node.category; let result; let inheritedNames = node.inheritanceList ? _.map(node.inheritanceList.ids, id => id.name) : [ ]; - let nsClass; - if (categoryName) { - nsClass = model.classes[className]; - - if (!nsClass) { - nsClass = new Model.NSClass(null, className); - nsClass.placeholder = true; - model.addClass(nsClass); - } - - } else { - nsClass = new Model.NSClass(makeLocation(node), className, inheritedNames); - model.addClass(nsClass); - } + let nsClass = new Model.NSClass(makeLocation(node), className, inheritedNames); + model.addClass(nsClass); currentClass = nsClass; - currentCategoryName = categoryName; - if (!categoryName) { - declaredClasses.push(nsClass.name) - } + declaredClasses.push(nsClass.name) } function handleNSProtocolDefinition(node) @@ -197,10 +181,6 @@ build() let setterEnabled = true; let setterCopies = false; - if (currentCategoryName) { - Utils.throwError(NSError.NotYetSupported, "@property is not yet supported in a category's implementation", node); - } - for (let i = 0, length = node.attributes.length; i < length; i++) { let attribute = node.attributes[i]; let attributeName = attribute.name; @@ -542,7 +522,6 @@ build() if (type === Syntax.NSClassImplementation) { currentClass = null; currentMethod = null; - currentCategoryName = null; } else if (type === Syntax.NSProtocolDefinition) { currentProtocol = null; diff --git a/src/Generator.js b/src/Generator.js index 2400264..d6d4b8c 100644 --- a/src/Generator.js +++ b/src/Generator.js @@ -111,7 +111,6 @@ generate() let methodNodeClasses = [ ]; let currentClass; - let currentCategoryName; let currentMethodNode; let methodUsesSelfVar = false; @@ -261,14 +260,6 @@ generate() node ); } - - if (currentCategoryName) { - Utils.throwError( - NSError.CannotUseInstanceVariable, - `Use of instance variable "${node.name}" inside of category`, - node - ); - } } function checkRestrictedUsage(node) @@ -531,11 +522,7 @@ generate() let classSymbolAsString = classSymbol ? `"${classSymbol}"` : null; let superSymbolAsString = superSymbol ? `"${superSymbol}"` : null; - if (node.category) { - startText = `${NSRootVariable}._registerCategory(${classSymbolAsString},`; - } else { - startText = `${NSRootVariable}._registerClass(${classSymbolAsString},${superSymbolAsString},`; - } + startText = `${NSRootVariable}._registerClass(${classSymbolAsString},${superSymbolAsString},`; startText = startText + "function(" + NSClassMethodsVariable + ", " + NSInstanceMethodsVariable + ") { " + @@ -1166,7 +1153,6 @@ generate() } else if (type === Syntax.NSClassImplementation) { currentClass = model.classes[node.id.name]; - currentCategoryName = node.category; _.each(currentClass.prepareWarnings, warning => { warnings.push(warning); @@ -1254,7 +1240,7 @@ generate() }, function(node, parent) { let type = node.type; - if (type === Syntax.NSClassImplementation && !node.category) { + if (type === Syntax.NSClassImplementation) { if (optionWarnUnusedPrivates) { _.each(currentClass.getAllProperties(), property => { let { name, location, ivar, getter, setter } = property; @@ -1271,7 +1257,6 @@ generate() } currentClass = null; - currentCategoryName = null; } else if (type === Syntax.NSMethodDefinition) { finishScope(scope, methodUsesSelfVar); diff --git a/src/model/NSClass.js b/src/model/NSClass.js index e0532ae..9fc246c 100644 --- a/src/model/NSClass.js +++ b/src/model/NSClass.js @@ -25,10 +25,6 @@ constructor(location, name, inheritedNames) this.name = name; this.inheritedNames = inheritedNames || [ ]; - // For category definitions that appear before the implementation - // Also used when a class defines a superclass that hasn't been traversed yet - this.placeholder = false; - // Is this class in the current compilation unit? *not archived* this.local = true; @@ -58,7 +54,6 @@ loadState(state) this.location = state.location; this.name = state.name; this.inheritedNames = state.inheritedNames || [ ]; - this.placeholder = state.placeholder; this.didSynthesis = state.didSynthesis; _.each(state.properties, p => { @@ -82,7 +77,6 @@ saveState() name: this.name, inheritedNames: this.inheritedNames, didSynthesis: !!this.didSynthesis, - placeholder: this.placeholder, properties: _.values(this._propertyMap), @@ -208,8 +202,6 @@ inherit(model) if (cls) { if (mySuperclass) { throw Utils.makeError(NSError.InheritanceError, `Cannot inherit from both "${name}" and "${mySuperclass.name}"`, location); - } else if (cls.placeholder) { - throw Utils.makeError(NSError.InheritanceError, `Cannot find non-category implementation of "${name}"`, location); } else { mySuperclass = cls; } diff --git a/src/model/NSModel.js b/src/model/NSModel.js index c608abb..28dab9b 100644 --- a/src/model/NSModel.js +++ b/src/model/NSModel.js @@ -381,25 +381,13 @@ addClass(nsClass) let name = nsClass.name; let existing = this.classes[name]; - // We have an existing placeholder, copy over methods in case it's a category - if (existing && existing.placeholder) { - _.each(existing.getAllMethods(), m => nsClass.addMethod(m)); + if (existing) { + Utils.throwError(NSError.DuplicateClass, `Duplicate declaration of class "${name}"`); } - // Ensure we aren't overwriting a non-placeholder with a placeholder - if (!existing || existing.placeholder) { - this.classes[name] = nsClass; - } + this.classes[name] = nsClass; - // We have an existing non-placeholder and a new non-placeholder - if (existing && !existing.placeholder && !nsClass.placeholder) { - Utils.throwError(NSError.DuplicateClass, `Duplicate declaration of class "${name}"`); - } - - // Register a non-placeholder - if (!nsClass.placeholder) { - this.registerDeclaration(name); - } + this.registerDeclaration(name); } diff --git a/test/multi/TestErrors.ns b/test/multi/TestErrors.ns index 6be8b97..389b49f 100644 --- a/test/multi/TestErrors.ns +++ b/test/multi/TestErrors.ns @@ -305,24 +305,6 @@ function test() { @end -// -------------------------------------------------------------------- -// @name Category No Ivars - -@class CategoryNoIvars (CategoryName) { //@error NilScriptParseError - -} - -@end - - -// -------------------------------------------------------------------- -// @name Category Properties Not Yet Supported - -@class CategoryNoProperties (CategoryName) -@property foo: String; //@error NilScriptNotYetSupportedError -@end - - // -------------------------------------------------------------------- // @name Warn Unused Privates // @opts { "warn-unused-privates": true } @@ -365,24 +347,6 @@ function test() { @end - -// -------------------------------------------------------------------- -// @name Cannot Use Instance Variable 2 - -@class Foo -@property theProperty: id; -@end - -@class Foo (TheCategory) - -- (void) doSomethingWithTheProperty -{ - [_theProperty doSomething]; //@error NilScriptCannotUseInstanceVariableError -} - -@end - - // -------------------------------------------------------------------- // @name Unknown Super Class diff --git a/test/single/Categories.ns b/test/single/Categories.ns deleted file mode 100644 index d56112f..0000000 --- a/test/single/Categories.ns +++ /dev/null @@ -1,28 +0,0 @@ -var assert = require("assert"); - - -@class CategoryTests (BeforeImplementation) -- (String) alpha { return "Alpha"; } -@end - -@class CategoryTests -- (String) beta { return "Beta"; } - -- (BOOL) runTests -{ - assert.equal([self alpha], "Alpha"); - assert.equal([self beta], "Beta"); - assert.equal([self gamma], "Gamma"); - - return true; -} - -@end - -@class CategoryTests (AfterImplementation) -- (String) gamma { return "Gamma"; } -@end - - -var instance = [[CategoryTests alloc] init]; -[instance runTests]