From: Jay Freeman (saurik) Date: Sat, 19 Dec 2015 02:23:20 +0000 (-0800) Subject: Add typedef-expressions syntax to replace @encode. X-Git-Tag: v0.9.590~182 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/64a505ff07b28093bb91a680f8a2c2292327e896?ds=sidebyside Add typedef-expressions syntax to replace @encode. --- diff --git a/Execute.cpp b/Execute.cpp index c71bc9f..bb337ba 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1484,7 +1484,7 @@ static JSValueRef Type_callAsFunction_toCYON(JSContextRef context, JSObjectRef o std::stringbuf out; CYOptions options; CYOutput output(out, options); - (new(pool) CYEncodedType(Decode(pool, internal->type_)))->Output(output, CYNoFlags); + (new(pool) CYTypeExpression(Decode(pool, internal->type_)))->Output(output, CYNoFlags); return CYCastJSValue(context, CYJSString(out.str().c_str())); } CYCatch(NULL) } diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 04ed11c..6dd8e55 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -133,7 +133,7 @@ CYTarget *CYBox::Replace(CYContext &context) { } CYTarget *CYObjCBlock::Replace(CYContext &context) { - return $C1($ CYEncodedType(($ CYTypedIdentifier(*typed_))->Modify($ CYTypeBlockWith(parameters_))), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_)); + return $C1($ CYTypeExpression(($ CYTypedIdentifier(*typed_))->Modify($ CYTypeBlockWith(parameters_))), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_)); } CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL) diff --git a/Output.cpp b/Output.cpp index 2125d75..cbd853f 100644 --- a/Output.cpp +++ b/Output.cpp @@ -640,6 +640,10 @@ void CYTypeDefinition::Output(CYOutput &out, CYFlags flags) const { out << "typedef" << ' ' << *typed_; } +void CYTypeExpression::Output(CYOutput &out, CYFlags flags) const { + out << '(' << "typedef" << ' ' << *typed_ << ')'; +} + void CYLexical::Output(CYOutput &out, CYFlags flags) const { out << "let" << ' '; bindings_->Output(out, flags); // XXX: flags diff --git a/Parser.ypp.in b/Parser.ypp.in index 50cacb3..8e0576d 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -2222,6 +2222,10 @@ IdentifierNoOf Statement__ : "typedef" NewLineNot TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($typed); } ; + +PrimaryExpression + : "(" LexOf "typedef" NewLineOpt TypedIdentifier[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); } ")" { $$ = CYNew CYTypeExpression($typed); } + ; /* }}} */ /* Cycript (C): extern "C" {{{ */ IdentifierNoOf diff --git a/Replace.cpp b/Replace.cpp index d2704cb..c812c35 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -1149,7 +1149,9 @@ CYTarget *CYTypeConstant::Replace_(CYContext &context, CYTarget *type) { } CYStatement *CYTypeDefinition::Replace(CYContext &context) { - return $E($ CYAssign($V(typed_->identifier_), typed_->Replace(context))); + CYIdentifier *identifier(typed_->identifier_); + typed_->identifier_ = NULL; + return $ CYLexical(false, $B1($B(identifier, $ CYTypeExpression(typed_)))); } CYTarget *CYTypeError::Replace(CYContext &context) { @@ -1157,6 +1159,10 @@ CYTarget *CYTypeError::Replace(CYContext &context) { return NULL; } +CYTarget *CYTypeExpression::Replace(CYContext &context) { + return typed_->Replace(context); +} + CYTarget *CYTypeModifier::Replace(CYContext &context, CYTarget *type) { $T(type) return Replace_(context, type); } diff --git a/Syntax.hpp b/Syntax.hpp index d7d783b..89bca73 100644 --- a/Syntax.hpp +++ b/Syntax.hpp @@ -2256,6 +2256,22 @@ struct CYExternal : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYTypeExpression : + CYTarget +{ + CYTypedIdentifier *typed_; + + CYTypeExpression(CYTypedIdentifier *typed) : + typed_(typed) + { + } + + CYPrecedence(0) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYTypeDefinition : CYStatement {