From cfd73c6d85001a128ffc498d1b99b047e286e189 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 8 Jun 2012 03:11:13 -0700 Subject: [PATCH] When messages took no arguments, type returned NULL. --- Cycript.yy.in | 21 +++++++++------------ ObjectiveC/Replace.cpp | 16 +++++++++++++--- ObjectiveC/Syntax.hpp | 10 ++++++++++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Cycript.yy.in b/Cycript.yy.in index 6a4f179..15b7673 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -449,9 +449,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %type BoxableExpression %type CategoryStatement %type ClassExpression +%type ClassFieldListOpt +%type ClassFields %type ClassStatement %type ClassSuperOpt -%type ClassFieldList %type ClassMessageDeclaration %type ClassMessageDeclarationListOpt %type ClassName @@ -1300,17 +1301,13 @@ ClassSuperOpt | { $$ = NULL; } ; -ClassField - : Expression Identifier ";" - ; - -ClassFieldList - : BRACE ClassFieldListOpt "}" { $$ = NULL; } +ClassFieldListOpt + : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); } + | { $$ = NULL; } ; -ClassFieldListOpt - : ClassFieldListOpt ClassField - | +ClassFields + : BRACE ClassFieldListOpt "}" { $$ = $2; } ; MessageScope @@ -1378,11 +1375,11 @@ ClassProtocolListOpt ; ClassExpression - : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); } + : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); } ; ClassStatement - : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } + : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } ; CategoryName diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 3e267ae..99de585 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -32,7 +32,7 @@ static CYExpression *MessageType(CYContext &context, CYExpression *type, CYMessa if (extra != NULL) left = $ CYAdd(left, extra); - if (next == NULL) + if (next == NULL || next->name_ == NULL) return left; CYExpression *right(next->TypeSignature(context)); @@ -78,8 +78,18 @@ CYStatement *CYClassStatement::Replace(CYContext &context) { return $E(Replace_(context)); } -CYStatement *CYField::Replace(CYContext &context) const { - return NULL; +CYStatement *CYField::Replace(CYContext &context) const { $T(NULL) + CYVariable *cyn($V("$cyn")); + CYVariable *cyt($V("$cyt")); + + CYExpression *type($C0($M(type_, $S("toString")))); + + return $ CYBlock($$->* + next_->Replace(context)->* + $E($ CYAssign(cyt, type))->* + $E($ CYAssign(cyn, $N1($V("Type"), cyt)))->* + $E($C5($V("class_addIvar"), $V("$cyc"), $S(name_->Word()), $M(cyn, $S("size")), $M(cyn, $S("alignment")), cyt)) + ); } CYStatement *CYImport::Replace(CYContext &context) { diff --git a/ObjectiveC/Syntax.hpp b/ObjectiveC/Syntax.hpp index a9a9798..580ea3a 100644 --- a/ObjectiveC/Syntax.hpp +++ b/ObjectiveC/Syntax.hpp @@ -77,6 +77,16 @@ struct CYSelector : struct CYField : CYNext { + CYExpression *type_; + CYIdentifier *name_; + + CYField(CYExpression *type, CYIdentifier *name, CYField *next = NULL) : + CYNext(next), + type_(type), + name_(name) + { + } + CYStatement *Replace(CYContext &context) const; void Output(CYOutput &out) const; }; -- 2.45.2