Skip to content

Commit

Permalink
Remove category support in preparation for #165
Browse files Browse the repository at this point in the history
  • Loading branch information
iccir committed Mar 3, 2023
1 parent 1c47adc commit a466cc6
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 151 deletions.
21 changes: 0 additions & 21 deletions lib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -288,7 +268,6 @@ function msgSend(receiver, selector)
var nilscript = {
_id: 0,
_registerClass: _registerClass,
_registerCategory: _registerCategory,
_c: _classSymbolToClassMap,
_g: { },
_reset: _reset,
Expand Down
29 changes: 4 additions & 25 deletions src/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ build()

let traverser = new Traverser(nsFile.ast);

let currentClass, currentMethod, currentCategoryName;
let currentClass, currentMethod;
let currentProtocol;

let usedSelectorMap = { };
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -542,7 +522,6 @@ build()
if (type === Syntax.NSClassImplementation) {
currentClass = null;
currentMethod = null;
currentCategoryName = null;

} else if (type === Syntax.NSProtocolDefinition) {
currentProtocol = null;
Expand Down
19 changes: 2 additions & 17 deletions src/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ generate()
let methodNodeClasses = [ ];

let currentClass;
let currentCategoryName;
let currentMethodNode;

let methodUsesSelfVar = false;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 + ") { " +
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -1271,7 +1257,6 @@ generate()
}

currentClass = null;
currentCategoryName = null;

} else if (type === Syntax.NSMethodDefinition) {
finishScope(scope, methodUsesSelfVar);
Expand Down
8 changes: 0 additions & 8 deletions src/model/NSClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 => {
Expand All @@ -82,7 +77,6 @@ saveState()
name: this.name,
inheritedNames: this.inheritedNames,
didSynthesis: !!this.didSynthesis,
placeholder: this.placeholder,

properties: _.values(this._propertyMap),

Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 4 additions & 16 deletions src/model/NSModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
36 changes: 0 additions & 36 deletions test/multi/TestErrors.ns
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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

Expand Down
28 changes: 0 additions & 28 deletions test/single/Categories.ns

This file was deleted.

0 comments on commit a466cc6

Please sign in to comment.