]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
On iOS 9, JSObjectGetPrototype changes JSValueRef.
[cycript.git] / Cycript.yy.in
index a11643f13e89573e01cd27a71c9538af67afaaf4..b2f56299b09274dee2fae9221cb7cb3c6c31fffd 100644 (file)
@@ -1,21 +1,21 @@
 /* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2013  Jay Freeman (saurik)
+ * Copyright (C) 2009-2014  Jay Freeman (saurik)
 */
 
-/* GNU General Public License, Version 3 {{{ */
+/* GNU Affero General Public License, Version 3 {{{ */
 /*
- * Cycript is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation, either version 3 of the License,
- * or (at your option) any later version.
- *
- * Cycript is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Cycript.  If not, see <http://www.gnu.org/licenses/>.
+ * GNU Affero General Public License for more details.
+
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/
 /* }}} */
 
@@ -85,6 +85,13 @@ typedef struct {
         CYTrue *true_;
         CYWord *word_;
 
+@begin C
+        CYTypeModifier *modifier_;
+        CYTypeSpecifier *specifier_;
+        CYTypedIdentifier *typedIdentifier_;
+        CYTypedParameter *typedParameter_;
+@end
+
 @begin ObjectiveC
         CYClassName *className_;
         CYField *field_;
@@ -92,9 +99,6 @@ typedef struct {
         CYMessageParameter *messageParameter_;
         CYProtocol *protocol_;
         CYSelectorPart *selector_;
-        CYTypeModifier *modifier_;
-        CYTypedIdentifier *typedIdentifier_;
-        CYTypedParameter *typedParameter_;
 @end
 
 @begin E4X
@@ -106,12 +110,17 @@ typedef struct {
 } YYSTYPE;
 
 #define YYSTYPE YYSTYPE
-@if Bison24 }
 
 @if Bison24 %code provides {
 int cylex(YYSTYPE *, cy::location *, void *);
 @if Bison24 }
 
+@if Bison23 %}
+@if Bison23 %union {
+@if Bison23 }
+@if Bison23 %{
+
+@if Bison24 }
 @if Bison23 %}
 
 %name-prefix="cy"
@@ -234,13 +243,19 @@ int cylex(YYSTYPE *, cy::location *, void *);
 
 @begin C
 %token <identifier_> Typedef "typedef"
+%token <identifier_> Unsigned "unsigned"
+%token <identifier_> Signed "signed"
+%token <identifier_> Extern "extern"
+@end
+
+@begin C
+%token AtEncode "@encode"
 @end
 
 @begin ObjectiveC
 %token AtImplementation "@implementation"
 %token AtImplementation_ ";@implementation"
 %token AtImport "@import"
-%token AtEncode "@encode"
 %token AtEnd "@end"
 %token AtSelector "@selector"
 %token <identifier_> Yes "YES"
@@ -406,6 +421,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <expression_> FunctionExpression
 %type <identifier_> Identifier
 %type <identifier_> IdentifierOpt
+%type <identifier_> IdentifierType
 %type <word_> IdentifierName
 %type <statement_> IfStatement
 %type <expression_> Initialiser
@@ -422,6 +438,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <member_> MemberAccess
 %type <expression_> MemberExpression_
 %type <expression_> MemberExpression
+%type <module_> Module
 %type <expression_> MultiplicativeExpression
 %type <expression_> NewExpression
 %type <null_> NullLiteral
@@ -468,8 +485,25 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <word_> WordOpt
 %type <expression_> Variable
 
-@begin ObjectiveC
+@begin C
 %type <typedIdentifier_> ArrayedType
+%type <modifier_> FunctionedType
+%type <specifier_> IntegerType
+%type <specifier_> IntegerTypeOpt
+%type <typedIdentifier_> PrefixedType
+%type <specifier_> PrimitiveType
+%type <typedIdentifier_> TypeParenthetical
+%type <typedIdentifier_> TypeSignifier
+%type <typedIdentifier_> SuffixedType
+%type <modifier_> TypeQualifierLeft
+%type <typedIdentifier_> TypeQualifierRight
+%type <typedIdentifier_> TypedIdentifier
+%type <typedParameter_> TypedParameterList_
+%type <typedParameter_> TypedParameterList
+%type <typedParameter_> TypedParameterListOpt
+@end
+
+@begin ObjectiveC
 %type <expression_> BoxableExpression
 %type <statement_> CategoryStatement
 %type <expression_> ClassExpression
@@ -484,8 +518,6 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <protocol_> ClassProtocolListOpt
 %type <protocol_> ClassProtocols
 %type <protocol_> ClassProtocolsOpt
-%type <expression_> EncodedType
-%type <modifier_> FunctionedType
 %type <expression_> MessageExpression
 %type <messageParameter_> MessageParameter
 %type <messageParameter_> MessageParameters
@@ -493,9 +525,6 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <messageParameter_> MessageParameterListOpt
 %type <bool_> MessageScope
 %type <typedIdentifier_> ModifiedType
-%type <module_> Module
-%type <typedIdentifier_> PrefixedType
-%type <expression_> PrimitiveType
 %type <argument_> SelectorCall_
 %type <argument_> SelectorCall
 %type <selector_> SelectorExpression_
@@ -503,16 +532,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <selector_> SelectorExpressionOpt
 %type <argument_> SelectorList
 %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
-%type <typedParameter_> TypedParameterListOpt
+%type <typedIdentifier_> TypeOpt
 %type <argument_> VariadicCall
 @end
 
@@ -656,15 +676,9 @@ WordOpt
     | { $$ = NULL; }
     ;
 
-Identifier
+IdentifierType
     : Identifier_ { $$ = $1; }
 
-@begin C
-    | "typedef" { $$ = $1; }
-    | "YES" { $$ = $1; }
-    | "NO" { $$ = $1; }
-@end
-
     | "implements" { $$ = $1; }
     | "interface" { $$ = $1; }
     | "package" { $$ = $1; }
@@ -676,19 +690,14 @@ Identifier
     | "abstract" { $$ = $1; }
     | "boolean" { $$ = $1; }
     | "byte" { $$ = $1; }
-    | "char" { $$ = $1; }
     | "double" { $$ = $1; }
     | "final" { $$ = $1; }
     | "float" { $$ = $1; }
     | "goto" { $$ = $1; }
-    | "int" { $$ = $1; }
-    | "long" { $$ = $1; }
     | "native" { $$ = $1; }
-    | "short" { $$ = $1; }
     | "synchronized" { $$ = $1; }
     | "throws" { $$ = $1; }
     | "transient" { $$ = $1; }
-    | "volatile" { $$ = $1; }
 
     // XXX: currently I only have this as Word
     // | "let" { $$ = $1; }
@@ -699,6 +708,25 @@ Identifier
     | "of" { $$ = $1; }
     ;
 
+Identifier
+    : IdentifierType
+    | "char" { $$ = $1; }
+    | "int" { $$ = $1; }
+    | "long" { $$ = $1; }
+    | "short" { $$ = $1; }
+    | "volatile" { $$ = $1; }
+@begin C
+    | "typedef" { $$ = $1; }
+    | "unsigned" { $$ = $1; }
+    | "signed" { $$ = $1; }
+    | "extern" { $$ = $1; }
+@end
+@begin ObjectiveC
+    | "YES" { $$ = $1; }
+    | "NO" { $$ = $1; }
+@end
+    ;
+
 IdentifierOpt
     : Identifier { $$ = $1; }
     | { $$ = NULL; }
@@ -1019,6 +1047,7 @@ LogicalORExpression
 ConditionalExpression
     : LogicalORExpression { $$ = $1; }
     | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
+    | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
     ;
 /* }}} */
 /* 11.13 Assignment Operators {{{ */
@@ -1042,11 +1071,11 @@ AssignmentExpression
 /* 11.14 Comma Operator {{{ */
 Expression_
     : "," Expression { $$ = $2; }
-    | { $$ = CYNew CYCompound(); }
+    | { $$ = NULL; }
     ;
 
 Expression
-    : AssignmentExpression Expression_ { $2->AddPrev($1); $$ = $2; }
+    : AssignmentExpression Expression_ { $$ = CYNew CYCompound($1, $2); }
     ;
 
 ExpressionOpt
@@ -1382,14 +1411,14 @@ ProgramBodyOpt
     ;
 /* }}} */
 
-@begin ObjectiveC
-/* Cycript (Objective-C): Type Encoding {{{ */
+@begin C
+/* Cycript (C): Type Encoding {{{ */
 TypeParenthetical
     : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
     ;
 
 TypeSignifier
-    : Identifier { $$ = CYNew CYTypedIdentifier($1); }
+    : IdentifierType { $$ = CYNew CYTypedIdentifier($1); }
     | TypeParenthetical { $$ = $1; }
     ;
 
@@ -1407,6 +1436,7 @@ SuffixedType
     : ArrayedType { $$ = $1; }
     | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
     | TypeParenthetical FunctionedType { $$ = $1; CYSetLast($2) = $$->modifier_; $$->modifier_ = $2; }
+    | IdentifierType FunctionedType { $$ = CYNew CYTypedIdentifier($1); CYSetLast($2) = $$->modifier_; $$->modifier_ = $2; }
     | FunctionedType { $$ = CYNew CYTypedIdentifier(); CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
     ;
 
@@ -1415,34 +1445,51 @@ PrefixedType
     ;
 
 TypeQualifierLeft
-    : "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
-    /* XXX: | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); } */
-    | { $$ = NULL; }
+    : { $$ = NULL; }
+    | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
+    | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
     ;
 
 TypeQualifierRight
-    : "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
-    | PrefixedType { $$ = $1; }
+    : PrefixedType { $$ = $1; }
     | SuffixedType { $$ = $1; }
+    | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
+    | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
     ;
 
-PrimitiveType
-    : Variable { $$ = $1; }
-    | "void" { $$  = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); }
+IntegerType
+    : "int" { $$ = CYNew CYTypeVariable("int"); }
+    | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
+    | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
+    | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
+    | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
     ;
 
-TypedIdentifier
-    : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->type_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
+IntegerTypeOpt
+    : IntegerType { $$ = $1; }
+    | { $$ = CYNew CYTypeVariable("int"); }
     ;
 
-EncodedType
-    : TypedIdentifier { $$ = CYNew CYEncodedType($1); }
+PrimitiveType
+    : IdentifierType { $$ = CYNew CYTypeVariable($1); }
+    | IntegerType { $$ = $1; }
+    | "void" { $$ = CYNew CYTypeVoid(); }
+    | "char" { $$ = CYNew CYTypeVariable("char"); }
+    | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
+    | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
+    ;
+
+TypedIdentifier
+    : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
     ;
 
 PrimaryExpression
-    : AtEncode "(" EncodedType ")" { $$ = $3; }
+    : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
     ;
 /* }}} */
+@end
+
+@begin ObjectiveC
 /* Cycript (Objective-C): @class Declaration {{{ */
 ClassSuperOpt
     /* XXX: why the hell did I choose MemberExpression? */
@@ -1451,7 +1498,7 @@ ClassSuperOpt
     ;
 
 ClassFieldListOpt
-    : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); }
+    : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $3); }
     | LexSetRegExp { $$ = NULL; }
     ;
 
@@ -1465,7 +1512,7 @@ MessageScope
     ;
 
 TypeOpt
-    : "(" LexSetRegExp EncodedType ")" { $$ = $3; }
+    : "(" LexSetRegExp TypedIdentifier ")" { $$ = $3; }
     | { $$ = NULL; }
     ;
 
@@ -1596,7 +1643,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); }
@@ -1606,6 +1655,8 @@ Declaration__
     : "@import" Module { $$ = CYNew CYImport($2); }
     ;
 /* }}} */
+
+@begin ObjectiveC
 /* Cycript (Objective-C): Boxed Expressions {{{ */
 BoxableExpression
     : NullLiteral { $$ = $1; }
@@ -1625,7 +1676,7 @@ PrimaryExpression
 /* }}} */
 /* Cycript (Objective-C): Block Expressions {{{ */
 ModifiedType
-    : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->type_ = $2; $$->modifier_ = $1; }
+    : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->specifier_ = $2; $$->modifier_ = $1; }
     | ModifiedType "*" { $$ = $1; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
     ;
 
@@ -1633,6 +1684,11 @@ PrimaryExpression
     : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); }
     ;
 /* }}} */
+/* Cycript (Objective-C): Instance Literals {{{ */
+PrimaryExpression
+    : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
+    ;
+/* }}} */
 @end
 
 @begin C
@@ -1677,9 +1733,15 @@ PrimaryExpression
 /* }}} */
 /* Cycript (C): Type Definitions {{{ */
 Statement__
-    : "typedef" TypedIdentifier Terminator { $$ = CYNew CYTypeDefinition($2); }
+    : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) YYABORT; } Terminator { $$ = CYNew CYTypeDefinition($2); }
+    ;
+/* }}} */
+/* Cycript (C): extern "C" {{{ */
+Statement__
+    : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) YYABORT; } TypedIdentifier Terminator { $$ = CYNew CYExternal($2, $4); }
     ;
 /* }}} */
+
 @end
 
 /* YUI: Documentation Comments {{{ */