From 104cc5f53dbc8b068040a1249b5b0580ee34b3c1 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 11 Nov 2015 01:50:03 -0800 Subject: [PATCH] Move message parameter name into typed identifier. --- Cycript.yy.in | 8 ++++---- ObjectiveC/Output.cpp | 4 ++-- ObjectiveC/Replace.cpp | 13 ++++--------- ObjectiveC/Syntax.hpp | 6 ++---- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Cycript.yy.in b/Cycript.yy.in index 9ae389c..298d16f 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -1490,12 +1490,12 @@ MessageScope ; TypeOpt - : "(" LexSetRegExp TypedIdentifier ")" { $$ = $3; } - | { $$ = NULL; } + : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; } + | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); } ; MessageParameter - : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); } + : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); } ; MessageParameterList @@ -1509,7 +1509,7 @@ MessageParameterListOpt MessageParameters : MessageParameterList { $$ = $1; } - | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); } + | Word { $$ = CYNew CYMessageParameter($1, NULL); } ; ClassMessageDeclaration diff --git a/ObjectiveC/Output.cpp b/ObjectiveC/Output.cpp index fa96e32..b9a9b6b 100644 --- a/ObjectiveC/Output.cpp +++ b/ObjectiveC/Output.cpp @@ -88,8 +88,8 @@ void CYMessage::Output(CYOutput &out, bool replace) const { CYForEach (parameter, parameters_) if (parameter->tag_ != NULL) { out << ' ' << *parameter->tag_; - if (parameter->name_ != NULL) - out << ':' << *parameter->name_; + if (parameter->type_ != NULL) + out << ':' << *parameter->type_->identifier_; } out << code_; diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 62a28c5..15361f2 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -25,14 +25,11 @@ #include static CYExpression *MessageType(CYContext &context, CYTypedIdentifier *type, CYMessageParameter *next, CYExpression *extra = NULL) { - if (type == NULL) - return NULL; - CYExpression *left($C0($M(type->Replace(context), $S("toString")))); if (extra != NULL) left = $ CYAdd(left, extra); - if (next == NULL || next->name_ == NULL) + if (next == NULL || next->type_ == NULL) return left; CYExpression *right(next->TypeSignature(context)); @@ -102,12 +99,10 @@ CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NUL CYVariable *self($V("self")); CYVariable *_class($V(instance_ ? "$cys" : "$cyp")); - CYExpression *type(TypeSignature(context) ?: $C1($M(cyn, $S("type")), _class)); - return $ CYBlock($$->* next_->Replace(context, replace)->* $E($ CYAssign(cyn, parameters_->Selector(context)))->* - $E($ CYAssign(cyt, type))->* + $E($ CYAssign(cyt, TypeSignature(context)))->* $E($C4($V(replace ? "class_replaceMethod" : "class_addMethod"), $V(instance_ ? "$cyc" : "$cym"), cyn, @@ -126,7 +121,7 @@ CYExpression *CYMessage::TypeSignature(CYContext &context) const { CYFunctionParameter *CYMessageParameter::Parameters(CYContext &context) const { $T(NULL) CYFunctionParameter *next(next_->Parameters(context)); - return name_ == NULL ? next : $ CYFunctionParameter($ CYDeclaration(name_), next); + return type_ == NULL ? next : $ CYFunctionParameter($ CYDeclaration(type_->identifier_), next); } CYSelector *CYMessageParameter::Selector(CYContext &context) const { @@ -135,7 +130,7 @@ CYSelector *CYMessageParameter::Selector(CYContext &context) const { CYSelectorPart *CYMessageParameter::SelectorPart(CYContext &context) const { $T(NULL) CYSelectorPart *next(next_->SelectorPart(context)); - return tag_ == NULL ? next : $ CYSelectorPart(tag_, name_ != NULL, next); + return tag_ == NULL ? next : $ CYSelectorPart(tag_, type_ != NULL, next); } CYExpression *CYMessageParameter::TypeSignature(CYContext &context) const { diff --git a/ObjectiveC/Syntax.hpp b/ObjectiveC/Syntax.hpp index fe97782..4cee64f 100644 --- a/ObjectiveC/Syntax.hpp +++ b/ObjectiveC/Syntax.hpp @@ -130,12 +130,10 @@ struct CYMessageParameter : { CYWord *tag_; CYTypedIdentifier *type_; - CYIdentifier *name_; - CYMessageParameter(CYWord *tag, CYTypedIdentifier *type, CYIdentifier *name) : + CYMessageParameter(CYWord *tag, CYTypedIdentifier *type) : tag_(tag), - type_(type), - name_(name) + type_(type) { } -- 2.45.2