]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
Avoid libffi runtime code generation API on ARM64.
[cycript.git] / Cycript.yy.in
index 047983b940fffb71335c46bfa8a1e9f252d0d5a3..8593f2613080664cdffe89e398cc10e993a15a33 100644 (file)
@@ -28,6 +28,7 @@
 @if Bison24 }
 
 @if Bison24 %code requires {
+#include "Driver.hpp"
 #include "Parser.hpp"
 #define CYNew new($pool)
 
@@ -90,7 +91,7 @@ typedef struct {
         CYMessageParameter *messageParameter_;
         CYProtocol *protocol_;
         CYSelectorPart *selector_;
-        CYTypeModifier *type_;
+        CYTypeModifier *modifier_;
         CYTypedIdentifier *typedIdentifier_;
         CYTypedParameter *typedParameter_;
 @end
@@ -223,10 +224,16 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %token OpenBracket "["
 %token CloseBracket "]"
 
+%token AtError "@error"
+
 @begin Java
 %token AtClass "@class"
 @end
 
+@begin C
+%token <identifier_> Typedef "typedef"
+@end
+
 @begin ObjectiveC
 %token AtImplementation "@implementation"
 %token AtImplementation_ ";@implementation"
@@ -234,6 +241,8 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %token AtEncode "@encode"
 %token AtEnd "@end"
 %token AtSelector "@selector"
+%token <identifier_> Yes "YES"
+%token <identifier_> No "NO"
 @end
 
 %token <false_> False "false"
@@ -458,6 +467,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <expression_> Variable
 
 @begin ObjectiveC
+%type <typedIdentifier_> ArrayedType
 %type <expression_> BoxableExpression
 %type <statement_> CategoryStatement
 %type <expression_> ClassExpression
@@ -473,16 +483,16 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <protocol_> ClassProtocols
 %type <protocol_> ClassProtocolsOpt
 %type <expression_> EncodedType
+%type <modifier_> FunctionedType
 %type <expression_> MessageExpression
 %type <messageParameter_> MessageParameter
 %type <messageParameter_> MessageParameters
 %type <messageParameter_> MessageParameterList
 %type <messageParameter_> MessageParameterListOpt
 %type <bool_> MessageScope
-%type <type_> ModifiedType
+%type <typedIdentifier_> ModifiedType
 %type <typedIdentifier_> PrefixedType
 %type <expression_> PrimitiveType
-%type <type_> QualifiedType
 %type <argument_> SelectorCall_
 %type <argument_> SelectorCall
 %type <selector_> SelectorExpression_
@@ -492,6 +502,10 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <word_> SelectorWordOpt
 %type <typedIdentifier_> SuffixedType
 %type <expression_> TypeOpt
+%type <typedIdentifier_> TypeParenthetical
+%type <modifier_> TypeQualifierLeft
+%type <typedIdentifier_> TypeQualifierRight
+%type <typedIdentifier_> TypeSignifier
 %type <typedIdentifier_> TypedIdentifier
 %type <typedParameter_> TypedParameterList_
 %type <typedParameter_> TypedParameterList
@@ -642,6 +656,12 @@ WordOpt
 Identifier
     : Identifier_ { $$ = $1; }
 
+@begin C
+    | "typedef" { $$ = $1; }
+    | "YES" { $$ = $1; }
+    | "NO" { $$ = $1; }
+@end
+
     | "implements" { $$ = $1; }
     | "interface" { $$ = $1; }
     | "package" { $$ = $1; }
@@ -743,7 +763,6 @@ PrimaryExpression
     | Literal { $$ = $1; }
     | ArrayLiteral { $$ = $1; }
     | ObjectLiteral { $$ = $1; }
-    | FunctionExpression { $$ = $1; }
     | Parenthetical { $$ = $1; }
     | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
     ;
@@ -840,6 +859,7 @@ MemberExpression_
 
 MemberExpression
     : LexSetRegExp PrimaryExpression { $$ = $2; }
+    | LexSetRegExp FunctionExpression { $$ = $2; }
     | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
     | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
     ;
@@ -1348,40 +1368,58 @@ ProgramBodyOpt
 
 @begin ObjectiveC
 /* Cycript (Objective-C): Type Encoding {{{ */
+TypeParenthetical
+    : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
+    ;
+
+TypeSignifier
+    : Identifier { $$ = CYNew CYTypedIdentifier($1); }
+    | TypeParenthetical { $$ = $1; }
+    ;
+
+ArrayedType
+    : ArrayedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
+    | TypeSignifier { $$ = $1; }
+    | { $$ = CYNew CYTypedIdentifier(); }
+    ;
+
+FunctionedType
+    : "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypeFunctionWith($3); }
+    ;
+
 SuffixedType
-    : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); }
-    | "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
-    | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3); $$ = $1; }
+    : ArrayedType { $$ = $1; }
+    | TypeParenthetical FunctionedType { $$ = $1; CYSetLast($2) = $$->modifier_; $$->modifier_ = $2; }
+    | FunctionedType { $$ = CYNew CYTypedIdentifier(); CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
     ;
 
 PrefixedType
-    : SuffixedType { $$ = $1; }
-    | "const" PrefixedType { CYSetLast($2->type_) = CYNew CYTypeConstant(); $$ = $2; }
-    | "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; }
+    : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
     ;
 
-PrimitiveType
-    : Variable { $$ = $1; }
-    | "void" { $$  = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); }
+TypeQualifierLeft
+    : "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
+    /* XXX: | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); } */
+    | { $$ = NULL; }
     ;
 
-QualifiedType
-    : PrimitiveType { $$ = CYNew CYTypeVariable($1); }
-    | "const" QualifiedType { $$ = CYNew CYTypeConstant($2); }
+TypeQualifierRight
+    : "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
+    | PrefixedType { $$ = $1; }
+    | SuffixedType { $$ = $1; }
     ;
 
-ModifiedType
-    : QualifiedType { $$ = $1; }
-    | QualifiedType "*" { $$ = CYNew CYTypePointerTo($1); }
-    | QualifiedType "const" { $$ = CYNew CYTypeConstant($1); }
+PrimitiveType
+    : Variable { $$ = $1; }
+    | "void" { $$  = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); }
     ;
 
 TypedIdentifier
-    : QualifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;}
+    : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->type_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
     ;
 
 EncodedType
-    : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); }
+    : TypedIdentifier { $$ = CYNew CYEncodedType($1); }
     ;
 
 PrimaryExpression
@@ -1567,6 +1605,8 @@ BoxableExpression
     | ArrayLiteral { $$ = $1; }
     | ObjectLiteral { $$ = $1; }
     | Parenthetical { $$ = $1; }
+    | "YES" { $$ = CYNew CYTrue(); }
+    | "NO" { $$ = CYNew CYFalse(); }
     ;
 
 PrimaryExpression
@@ -1574,18 +1614,9 @@ PrimaryExpression
     ;
 /* }}} */
 /* Cycript (Objective-C): Block Expressions {{{ */
-TypedParameterList_
-    : "," TypedParameterList { $$ = $2; }
-    | { $$ = NULL; }
-    ;
-
-TypedParameterList
-    : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
-    ;
-
-TypedParameterListOpt
-    : TypedParameterList { $$ = $1; }
-    | { $$ = NULL; }
+ModifiedType
+    : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->type_ = $2; $$->modifier_ = $1; }
+    | ModifiedType "*" { $$ = $1; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
     ;
 
 PrimaryExpression
@@ -1615,6 +1646,30 @@ Var_
     : "auto"
     ;
 /* }}} */
+/* Cycript (C): Lambda Expressions {{{ */
+TypedParameterList_
+    : "," TypedParameterList { $$ = $2; }
+    | { $$ = NULL; }
+    ;
+
+TypedParameterList
+    : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
+    ;
+
+TypedParameterListOpt
+    : TypedParameterList { $$ = $1; }
+    | { $$ = NULL; }
+    ;
+
+PrimaryExpression
+    : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
+    ;
+/* }}} */
+/* Cycript (C): Type Definitions {{{ */
+Statement__
+    : "typedef" TypedIdentifier Terminator { $$ = CYNew CYTypeDefinition($2); }
+    ;
+/* }}} */
 @end
 
 /* YUI: Documentation Comments {{{ */