From: Jay Freeman (saurik) Date: Sat, 11 Oct 2014 09:10:13 +0000 (-0700) Subject: Repair support for compiling without Objective-C. X-Git-Tag: v0.9.503~26 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/7b750785c5d53fef6b885cc1fc4bd02ba6daeb1b Repair support for compiling without Objective-C. --- diff --git a/Cycript.yy.in b/Cycript.yy.in index 3a31f1e..0f16b6e 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -79,13 +79,19 @@ typedef struct { CYProperty *property_; CYPropertyName *propertyName_; CYRubyProc *rubyProc_; - CYTypeSpecifier *specifier_; CYStatement *statement_; CYString *string_; CYThis *this_; CYTrue *true_; CYWord *word_; +@begin C + CYTypeModifier *modifier_; + CYTypeSpecifier *specifier_; + CYTypedIdentifier *typedIdentifier_; + CYTypedParameter *typedParameter_; +@end + @begin ObjectiveC CYClassName *className_; CYField *field_; @@ -93,9 +99,6 @@ typedef struct { CYMessageParameter *messageParameter_; CYProtocol *protocol_; CYSelectorPart *selector_; - CYTypeModifier *modifier_; - CYTypedIdentifier *typedIdentifier_; - CYTypedParameter *typedParameter_; @end @begin E4X @@ -426,6 +429,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type MemberAccess %type MemberExpression_ %type MemberExpression +%type Module %type MultiplicativeExpression %type NewExpression %type NullLiteral @@ -472,8 +476,26 @@ int cylex(YYSTYPE *, cy::location *, void *); %type WordOpt %type Variable -@begin ObjectiveC +@begin C %type ArrayedType +%type EncodedType +%type FunctionedType +%type IntegerType +%type IntegerTypeOpt +%type PrefixedType +%type PrimitiveType +%type TypeParenthetical +%type TypeSignifier +%type SuffixedType +%type TypeQualifierLeft +%type TypeQualifierRight +%type TypedIdentifier +%type TypedParameterList_ +%type TypedParameterList +%type TypedParameterListOpt +@end + +@begin ObjectiveC %type BoxableExpression %type CategoryStatement %type ClassExpression @@ -488,10 +510,6 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt -%type EncodedType -%type FunctionedType -%type IntegerType -%type IntegerTypeOpt %type MessageExpression %type MessageParameter %type MessageParameters @@ -499,9 +517,6 @@ int cylex(YYSTYPE *, cy::location *, void *); %type MessageParameterListOpt %type MessageScope %type ModifiedType -%type Module -%type PrefixedType -%type PrimitiveType %type SelectorCall_ %type SelectorCall %type SelectorExpression_ @@ -509,16 +524,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type SelectorExpressionOpt %type SelectorList %type SelectorWordOpt -%type SuffixedType %type TypeOpt -%type TypeParenthetical -%type TypeQualifierLeft -%type TypeQualifierRight -%type TypeSignifier -%type TypedIdentifier -%type TypedParameterList_ -%type TypedParameterList -%type TypedParameterListOpt %type VariadicCall @end @@ -705,6 +711,8 @@ Identifier | "typedef" { $$ = $1; } | "unsigned" { $$ = $1; } | "signed" { $$ = $1; } +@end +@begin ObjectiveC | "YES" { $$ = $1; } | "NO" { $$ = $1; } @end @@ -1394,8 +1402,8 @@ ProgramBodyOpt ; /* }}} */ -@begin ObjectiveC -/* Cycript (Objective-C): Type Encoding {{{ */ +@begin C +/* Cycript (C): Type Encoding {{{ */ TypeParenthetical : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; } ; @@ -1473,6 +1481,9 @@ PrimaryExpression : "@encode" "(" EncodedType ")" { $$ = $3; } ; /* }}} */ +@end + +@begin ObjectiveC /* Cycript (Objective-C): @class Declaration {{{ */ ClassSuperOpt /* XXX: why the hell did I choose MemberExpression? */ @@ -1626,7 +1637,9 @@ PrimaryExpression | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); } ; /* }}} */ -/* Cycript (Objective-C): @import Directive {{{ */ +@end + +/* Cycript: @import Directive {{{ */ Module : Module "." Word { $$ = CYNew CYModule($3, $1); } | Word { $$ = CYNew CYModule($1); } @@ -1636,6 +1649,8 @@ Declaration__ : "@import" Module { $$ = CYNew CYImport($2); } ; /* }}} */ + +@begin ObjectiveC /* Cycript (Objective-C): Boxed Expressions {{{ */ BoxableExpression : NullLiteral { $$ = $1; } diff --git a/ObjectiveC/Output.cpp b/ObjectiveC/Output.cpp index d67971f..203a432 100644 --- a/ObjectiveC/Output.cpp +++ b/ObjectiveC/Output.cpp @@ -77,10 +77,6 @@ void CYClassStatement::Output(CYOutput &out, CYFlags flags) const { void CYField::Output(CYOutput &out) const { } -void CYImport::Output(CYOutput &out, CYFlags flags) const { - out << "@import"; -} - void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const { out << '#'; number_->Output(out, CYRight(flags)); @@ -99,12 +95,6 @@ void CYMessage::Output(CYOutput &out, bool replace) const { out << code_; } -void CYModule::Output(CYOutput &out) const { - out << part_; - if (next_ != NULL) - out << '.' << next_; -} - void CYBox::Output(CYOutput &out, CYFlags flags) const { out << '@'; value_->Output(out, Precedence(), CYRight(flags)); diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 1502aa2..9de4c09 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -92,10 +92,6 @@ CYStatement *CYField::Replace(CYContext &context) const { $T(NULL) ); } -CYStatement *CYImport::Replace(CYContext &context) { - return $ CYVar($L1($L(module_->part_->Word(), $C1($V("require"), module_->Replace(context, "/"))))); -} - CYExpression *CYInstanceLiteral::Replace(CYContext &context) { return $N1($V("Instance"), number_); } @@ -146,12 +142,6 @@ CYExpression *CYMessageParameter::TypeSignature(CYContext &context) const { return MessageType(context, type_, next_); } -CYString *CYModule::Replace(CYContext &context, const char *separator) const { - if (next_ == NULL) - return $ CYString(part_); - return $ CYString($pool.strcat(next_->Replace(context, separator)->Value(), separator, part_->Word(), NULL)); -} - CYExpression *CYBox::Replace(CYContext &context) { return $C1($M($V("Instance"), $S("box")), value_); } diff --git a/ObjectiveC/Syntax.hpp b/ObjectiveC/Syntax.hpp index e04f71d..7578d7e 100644 --- a/ObjectiveC/Syntax.hpp +++ b/ObjectiveC/Syntax.hpp @@ -183,36 +183,6 @@ struct CYProtocol : void Output(CYOutput &out) const; }; -struct CYModule : - CYNext, - CYThing -{ - CYWord *part_; - - CYModule(CYWord *part, CYModule *next = NULL) : - CYNext(next), - part_(part) - { - } - - CYString *Replace(CYContext &context, const char *separator) const; - void Output(CYOutput &out) const; -}; - -struct CYImport : - CYStatement -{ - CYModule *module_; - - CYImport(CYModule *module) : - module_(module) - { - } - - virtual CYStatement *Replace(CYContext &context); - virtual void Output(CYOutput &out, CYFlags flags) const; -}; - struct CYClass { CYClassName *name_; CYExpression *super_; diff --git a/Output.cpp b/Output.cpp index 3794c49..778acb5 100644 --- a/Output.cpp +++ b/Output.cpp @@ -440,6 +440,10 @@ void CYIfComprehension::Output(CYOutput &out) const { out << "if" << ' ' << '(' << *test_ << ')' << next_; } +void CYImport::Output(CYOutput &out, CYFlags flags) const { + out << "@import"; +} + void CYIndirectMember::Output(CYOutput &out, CYFlags flags) const { object_->Output(out, Precedence(), CYLeft(flags)); if (const char *word = property_->Word()) @@ -547,6 +551,12 @@ void CYLetStatement::Output(CYOutput &out, CYFlags flags) const { code_->Single(out, CYRight(flags)); } +void CYModule::Output(CYOutput &out) const { + out << part_; + if (next_ != NULL) + out << '.' << next_; +} + namespace cy { namespace Syntax { diff --git a/Parser.hpp b/Parser.hpp index fab18af..c7894ce 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -1851,6 +1851,36 @@ struct CYLambda : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYModule : + CYNext, + CYThing +{ + CYWord *part_; + + CYModule(CYWord *part, CYModule *next = NULL) : + CYNext(next), + part_(part) + { + } + + CYString *Replace(CYContext &context, const char *separator) const; + void Output(CYOutput &out) const; +}; + +struct CYImport : + CYStatement +{ + CYModule *module_; + + CYImport(CYModule *module) : + module_(module) + { + } + + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYTypeDefinition : CYStatement { diff --git a/Replace.cpp b/Replace.cpp index b658cf7..1cb020c 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -507,6 +507,10 @@ CYStatement *CYIfComprehension::Replace(CYContext &context, CYStatement *stateme return $ CYIf(test_, CYComprehension::Replace(context, statement)); } +CYStatement *CYImport::Replace(CYContext &context) { + return $ CYVar($L1($L(module_->part_->Word(), $C1($V("require"), module_->Replace(context, "/"))))); +} + CYExpression *CYIndirect::Replace(CYContext &context) { return $M(rhs_, $S("$cyi")); } @@ -534,6 +538,12 @@ CYStatement *CYLetStatement::Replace(CYContext &context) { return $E($ CYCall(CYNonLocalize(context, $ CYFunctionExpression(NULL, declarations_->Parameter(context), code_)), declarations_->Argument(context))); } +CYString *CYModule::Replace(CYContext &context, const char *separator) const { + if (next_ == NULL) + return $ CYString(part_); + return $ CYString($pool.strcat(next_->Replace(context, separator)->Value(), separator, part_->Word(), NULL)); +} + CYExpression *CYMultiply::Replace(CYContext &context) { CYInfix::Replace(context);