Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix for super not working for class methods.
Closes cappuccino#227.

Reviewed by me.
  • Loading branch information
Francisco Ryan Tolmasky I committed Jul 24, 2009
1 parent 12d03a5 commit 4824f22
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Objective-J/preprocess.js
Expand Up @@ -170,13 +170,15 @@ var objj_preprocessor = function(aString, aSourceFile, aBundle, flags)
{
this._currentClass = "";
this._currentSuperClass = "";
this._currentSuperMetaClass = "";

this._file = aSourceFile;
this._fragments = [];
this._preprocessed = new objj_stringBuffer();
this._tokens = new objj_lexer(aString);
this._flags = flags;
this._bundle = aBundle;
this._classMethod = false;

this.preprocess(this._tokens, this._preprocessed);
//alert(this._preprocessed + "");
Expand Down Expand Up @@ -262,8 +264,7 @@ objj_preprocessor.prototype.brackets = function(/*objj_lexer*/ tokens, /*objj_st
if (tuples[0][0].atoms[0] == TOKEN_SUPER)
{
CONCAT(aStringBuffer, "objj_msgSendSuper(");
CONCAT(aStringBuffer, "{ receiver:self, super_class:" + this._currentSuperClass + " }");

CONCAT(aStringBuffer, "{ receiver:self, super_class:" + (this._classMethod ? this._currentSuperMetaClass : this._currentSuperClass ) + " }");
}
else
{
Expand Down Expand Up @@ -350,14 +351,15 @@ objj_preprocessor.prototype.implementation = function(tokens, /*objj_stringBuffe
category = NO,
class_name = tokens.skip_whitespace(),
superclass_name = "Nil",

instance_methods = new objj_stringBuffer(),
class_methods = new objj_stringBuffer();

if (!(/^\w/).test(class_name))
objj_exception_throw(new objj_exception(OBJJParseException, "*** Expected class name, found \"" + class_name + "\"."));

this._currentSuperClass = NULL;
this._currentSuperMetaClass = NULL;
this._currentClass = class_name;

// If we reach an open parenthesis, we are declaring a category.
Expand All @@ -376,12 +378,18 @@ objj_preprocessor.prototype.implementation = function(tokens, /*objj_stringBuffe
CONCAT(buffer, "var meta_class = the_class.isa;");

var superclass_name = dictionary_getValue(SUPER_CLASSES, class_name);

// FIXME: We should have a better solution for this case, although it's actually not much slower than the real case.
if (!superclass_name)
{
this._currentSuperClass = "objj_getClass(\"" + class_name + "\").super_class";
this._currentSuperMetaClass = "objj_getMetaClass(\"" + class_name + "\").super_class";
}
else
{
this._currentSuperClass = "objj_getClass(\"" + superclass_name + "\")";
this._currentSuperMetaClass = "objj_getMeraClass(\"" + superclass_name + "\")";
}
}
else
{
Expand All @@ -394,7 +402,9 @@ objj_preprocessor.prototype.implementation = function(tokens, /*objj_stringBuffe
objj_exception_throw(new objj_exception(OBJJParseException, "*** Expected class name, found \"" + token + "\"."));

superclass_name = token;

this._currentSuperClass = "objj_getClass(\"" + superclass_name + "\")";
this._currentSuperMetaClass = "objj_getMetaClass(\"" + superclass_name + "\")";

dictionary_setValue(SUPER_CLASSES, class_name, superclass_name);

Expand Down Expand Up @@ -503,6 +513,8 @@ objj_preprocessor.prototype.implementation = function(tokens, /*objj_stringBuffe
{
if (token == TOKEN_PLUS)
{
this._classMethod = true;

if (IS_NOT_EMPTY(class_methods))
CONCAT(class_methods, ", ");

Expand All @@ -511,6 +523,8 @@ objj_preprocessor.prototype.implementation = function(tokens, /*objj_stringBuffe

else if (token == TOKEN_MINUS)
{
this._classMethod = false;

if (IS_NOT_EMPTY(instance_methods))
CONCAT(instance_methods, ", ");

Expand Down

0 comments on commit 4824f22

Please sign in to comment.