// 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; \
@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);
@begin ObjectiveC
%token At_implementation_ "@implementation"
-%token At_implementation__ ";@implementation"
%token At_import_ "@import"
%token At_end_ "@end"
%token At_selector_ "@selector"
@begin ObjectiveC
%type <expression_> BoxableExpression
%type <statement_> CategoryStatement
-%type <expression_> ClassExpression
%type <classField_> ClassFieldListOpt
%type <classField_> ClassFields
%type <statement_> ClassStatement
%type <message_> ClassMessageDeclaration
%type <message_> ClassMessageDeclarationListOpt
%type <className_> ClassName
-%type <className_> ClassNameOpt
%type <protocol_> ClassProtocolListOpt
%type <protocol_> ClassProtocols
%type <protocol_> ClassProtocolsOpt
: { 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 {{{ */
| "(" AssignmentExpression ")" { $$ = $2; }
;
-ClassNameOpt
- : ClassName { $$ = $1; }
- | { $$ = NULL; }
- ;
-
// XXX: this should be AssignmentExpressionNoRight
ClassProtocols
: ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
| { $$ = 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
;
CategoryStatement
- : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
- ;
-
-PrimaryExpression
- : ClassExpression { $$ = $1; }
+ : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
;
Statement__
bool last_;
struct {
- bool AtImplementation;
bool Class;
bool Function;
bool OpenBrace;
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) {
CYSetPrototype(context, last, all);
}
- CYSetProperty(context, global, CYJSString("$cyq"), &$cyq, kJSPropertyAttributeDontEnum);
-
JSObjectRef System(JSObjectMake(context, NULL, NULL));
CYSetProperty(context, cy, CYJSString("System"), System);
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)
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 {
}
), 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)))->*
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)
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),
{
}
- 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);