From: Jay Freeman (saurik) Date: Mon, 30 Nov 2015 21:27:16 +0000 (-0800) Subject: Drop support for ObjC @implementation expressions. X-Git-Tag: v0.9.590~259 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/ec18682d83264996954ab6473ea3d342ac8affc5 Drop support for ObjC @implementation expressions. --- diff --git a/Cycript.l.in b/Cycript.l.in index ec251b6..38a9459 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -46,9 +46,6 @@ typedef cy::parser::token tk; // do /not/ fold token to the return: this is a macro and the ordering is dependent #define F(value, highlight) do { \ int token(value); \ -@begin ObjectiveC - yyextra->no_.AtImplementation = false; \ -@end yyextra->no_.Class = false; \ yyextra->no_.Function = false; \ yyextra->no_.NewLine = false; \ @@ -412,7 +409,7 @@ XMLName {XMLNameStart}{XMLNamePart}* @begin ObjectiveC "@end" L C F(tk::At_end_, hi::Meta); "@false" L C F(tk::At_false_, hi::Constant); -"@implementation" L C F(yyextra->no_.AtImplementation ? tk::At_implementation__ : tk::At_implementation_, hi::Meta); +"@implementation" L C F(tk::At_implementation_, hi::Meta); "@import" L C F(tk::At_import_, hi::Special); "@NO" L C F(tk::At_NO_, hi::Constant); "@null" L C F(tk::At_null_, hi::Constant); diff --git a/Cycript.yy.in b/Cycript.yy.in index 908d4ca..289283e 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -254,7 +254,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, vo @begin ObjectiveC %token At_implementation_ "@implementation" -%token At_implementation__ ";@implementation" %token At_import_ "@import" %token At_end_ "@end" %token At_selector_ "@selector" @@ -515,7 +514,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, vo @begin ObjectiveC %type BoxableExpression %type CategoryStatement -%type ClassExpression %type ClassFieldListOpt %type ClassFields %type ClassStatement @@ -523,7 +521,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, vo %type ClassMessageDeclaration %type ClassMessageDeclarationListOpt %type ClassName -%type ClassNameOpt %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt @@ -610,14 +607,8 @@ LexNoFunction : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::_function_)) yyla.type = yytranslate_(token::_function__); } ; -LexNoAtImplementation : -@begin ObjectiveC - { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::At_implementation_)) yyla.type = yytranslate_(token::At_implementation__); } -@end - ; - LexSetStatement - : LexNoBrace LexNoClass LexNoFunction LexNoAtImplementation + : LexNoBrace LexNoClass LexNoFunction ; /* }}} */ /* Virtual Tokens {{{ */ @@ -1562,11 +1553,6 @@ ClassName | "(" AssignmentExpression ")" { $$ = $2; } ; -ClassNameOpt - : ClassName { $$ = $1; } - | { $$ = NULL; } - ; - // XXX: this should be AssignmentExpressionNoRight ClassProtocols : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); } @@ -1582,12 +1568,8 @@ ClassProtocolListOpt | { $$ = NULL; } ; -ClassExpression - : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); } - ; - ClassStatement - : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } + : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } ; CategoryName @@ -1595,11 +1577,7 @@ CategoryName ; CategoryStatement - : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); } - ; - -PrimaryExpression - : ClassExpression { $$ = $1; } + : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); } ; Statement__ diff --git a/Driver.hpp b/Driver.hpp index 3f0a960..634177a 100644 --- a/Driver.hpp +++ b/Driver.hpp @@ -46,7 +46,6 @@ class _visible CYDriver { bool last_; struct { - bool AtImplementation; bool Class; bool Function; bool OpenBrace; diff --git a/Execute.cpp b/Execute.cpp index 9f45354..89a796a 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -358,14 +358,6 @@ static JSValueRef System_print(JSContextRef context, JSObjectRef object, JSObjec return CYJSUndefined(context); } CYCatch(NULL) } -static size_t Nonce_(0); - -static JSValueRef $cyq(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { - CYPool pool; - const char *name(pool.strcat(CYPoolCString(pool, context, arguments[0]), pool.itoa(Nonce_++), NULL)); - return CYCastJSValue(context, name); -} CYCatch(NULL) } - static void (*JSSynchronousGarbageCollectForDebugging$)(JSContextRef); _visible void CYGarbageCollect(JSContextRef context) { @@ -1927,8 +1919,6 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) { CYSetPrototype(context, last, all); } - CYSetProperty(context, global, CYJSString("$cyq"), &$cyq, kJSPropertyAttributeDontEnum); - JSObjectRef System(JSObjectMake(context, NULL, NULL)); CYSetProperty(context, cy, CYJSString("System"), System); diff --git a/ObjectiveC/Output.cpp b/ObjectiveC/Output.cpp index ee41e48..9d0caa0 100644 --- a/ObjectiveC/Output.cpp +++ b/ObjectiveC/Output.cpp @@ -36,15 +36,12 @@ void CYCategory::Output(CYOutput &out, CYFlags flags) const { out << ';'; } -void CYClass::Output(CYOutput &out, CYFlags flags) const { +void CYClassStatement::Output(CYOutput &out, CYFlags flags) const { // XXX: I don't necc. need the ()s out << "(function($cys,$cyp,$cyc,$cyn,$cyt,$cym){"; out << "$cyp=object_getClass($cys);"; out << "$cyc=objc_allocateClassPair($cys,"; - if (name_ != NULL) - name_->ClassName(out, false); - else - out << "$cyq(\"CY$\")"; + name_->ClassName(out, false); out << ",0);"; out << "$cym=object_getClass($cyc);"; if (fields_ != NULL) @@ -66,14 +63,6 @@ void CYClass::Output(CYOutput &out, CYFlags flags) const { out << "))"; } -void CYClassExpression::Output(CYOutput &out, CYFlags flags) const { - CYClass::Output(out, flags); -} - -void CYClassStatement::Output(CYOutput &out, CYFlags flags) const { - CYClass::Output(out, flags); -} - void CYClassField::Output(CYOutput &out) const { } diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 086287b..1b71e02 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -50,12 +50,12 @@ CYStatement *CYCategory::Replace(CYContext &context) { ), name_->ClassName(context, true))); } -CYExpression *CYClass::Replace_(CYContext &context) { +CYStatement *CYClassStatement::Replace(CYContext &context) { CYVariable *cyc($V("$cyc")), *cys($V("$cys")); - CYExpression *name(name_ != NULL ? name_->ClassName(context, false) : $C1($V("$cyq"), $S("CY$"))); + CYExpression *name(name_->ClassName(context, false)); - return $C1($F(NULL, $P6($L("$cys"), $L("$cyp"), $L("$cyc"), $L("$cyn"), $L("$cyt"), $L("$cym")), $$->* + return $E($C1($F(NULL, $P6($L("$cys"), $L("$cyp"), $L("$cyc"), $L("$cyn"), $L("$cyt"), $L("$cym")), $$->* $E($ CYAssign($V("$cyp"), $C1($V("object_getClass"), cys)))->* $E($ CYAssign(cyc, $C3($V("objc_allocateClassPair"), cys, name, $D(0))))->* $E($ CYAssign($V("$cym"), $C1($V("object_getClass"), cyc)))->* @@ -64,15 +64,7 @@ CYExpression *CYClass::Replace_(CYContext &context) { messages_->Replace(context, false)->* $E($C1($V("objc_registerClassPair"), cyc))->* $ CYReturn(cyc) - ), super_ == NULL ? $ CYNull() : super_); -} - -CYExpression *CYClassExpression::Replace(CYContext &context) { - return Replace_(context); -} - -CYStatement *CYClassStatement::Replace(CYContext &context) { - return $E(Replace_(context)); + ), super_ == NULL ? $ CYNull() : super_)); } CYStatement *CYClassField::Replace(CYContext &context) const { $T(NULL) diff --git a/ObjectiveC/Syntax.hpp b/ObjectiveC/Syntax.hpp index 0f3cc38..d7a74cd 100644 --- a/ObjectiveC/Syntax.hpp +++ b/ObjectiveC/Syntax.hpp @@ -181,14 +181,16 @@ struct CYProtocol : void Output(CYOutput &out) const; }; -struct CYClass { +struct CYClassStatement : + CYStatement +{ CYClassName *name_; CYExpression *super_; CYProtocol *protocols_; CYClassField *fields_; CYMessage *messages_; - CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) : + CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) : name_(name), super_(super), protocols_(protocols), @@ -197,37 +199,6 @@ struct CYClass { { } - virtual ~CYClass() { - } - - CYExpression *Replace_(CYContext &context); - virtual void Output(CYOutput &out, CYFlags flags) const; -}; - -struct CYClassExpression : - CYClass, - CYExpression -{ - CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) : - CYClass(name, super, protocols, fields, messages) - { - } - - CYPrecedence(0) - - virtual CYExpression *Replace(CYContext &context); - virtual void Output(CYOutput &out, CYFlags flags) const; -}; - -struct CYClassStatement : - CYClass, - CYStatement -{ - CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) : - CYClass(name, super, protocols, fields, messages) - { - } - CYCompact(None) virtual CYStatement *Replace(CYContext &context);