]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
Avoid dependency hell by overriding location type.
[cycript.git] / Cycript.yy.in
index 9aea79d36a445a47a16956a6efed199025f40e13..9cf3b8ef358900e6a8538fcbcede1ce5beb95f31 100644 (file)
@@ -1,33 +1,30 @@
 /* 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/>.
 **/
 /* }}} */
 
-@if Bison23 %{
-
-@if Bison24 %code top {
+%code top {
 #define cyscanner driver.scanner_
 #define YYSTACKEXPANDABLE 1
-@if Bison23 #define yyerrok (yyerrstatus_ = 0)
-@if Bison24 }
+}
 
-@if Bison24 %code requires {
+%code requires {
 #include "Driver.hpp"
 #include "Parser.hpp"
 #define CYNew new($pool)
@@ -110,18 +107,15 @@ typedef struct {
 } YYSTYPE;
 
 #define YYSTYPE YYSTYPE
-@if Bison24 }
-
-@if Bison24 %code provides {
-int cylex(YYSTYPE *, cy::location *, void *);
-@if Bison24 }
+}
 
-@if Bison23 %}
+%code provides {
+int cylex(YYSTYPE *, CYLocation *, void *);
+}
 
-%name-prefix="cy"
+%name-prefix "cy"
 
-@if Bison23 %skeleton "lalr1.cc"
-@if Bison24 %language "C++"
+%language "C++"
 
 %initial-action {
     @$.begin.filename = @$.end.filename = &driver.filename_;
@@ -130,6 +124,8 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %locations
 %defines
 
+%define api.location.type { CYLocation }
+
 //%glr-parser
 //%expect 1
 
@@ -240,6 +236,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %token <identifier_> Typedef "typedef"
 %token <identifier_> Unsigned "unsigned"
 %token <identifier_> Signed "signed"
+%token <identifier_> Extern "extern"
 @end
 
 @begin C
@@ -438,7 +435,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <null_> NullLiteral
 %type <literal_> ObjectLiteral
 %type <compound_> Parenthetical
-%type <compound_> ParentheticalOpt
+//%type <compound_> ParentheticalOpt
 %type <expression_> PostfixExpression
 %type <expression_> PrimaryExpression
 %type <statement_> Program
@@ -481,7 +478,6 @@ int cylex(YYSTYPE *, cy::location *, void *);
 
 @begin C
 %type <typedIdentifier_> ArrayedType
-%type <expression_> EncodedType
 %type <modifier_> FunctionedType
 %type <specifier_> IntegerType
 %type <specifier_> IntegerTypeOpt
@@ -527,7 +523,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <selector_> SelectorExpressionOpt
 %type <argument_> SelectorList
 %type <word_> SelectorWordOpt
-%type <expression_> TypeOpt
+%type <typedIdentifier_> TypeOpt
 %type <argument_> VariadicCall
 @end
 
@@ -582,16 +578,16 @@ LexSetRegExp
     ;
 
 LexNoBrace
-    : { if (yychar == yyempty_) driver.no_.OpenBrace = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
+    : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
     ;
 
 LexNoFunction
-    : { if (yychar == yyempty_) driver.no_.Function = true; else if (yychar == token::Function) yychar = token::Function_; }
+    : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::Function)) yyla.type = yytranslate_(token::Function_); }
     ;
 
 LexNoAtImplementation :
 @begin ObjectiveC
-    { if (yychar == yyempty_) driver.no_.AtImplementation = true; else if (yychar == token::AtImplementation) yychar = token::AtImplementation_; }
+    { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::AtImplementation)) yyla.type = yytranslate_(token::AtImplementation_); }
 @end
     ;
 
@@ -714,6 +710,7 @@ Identifier
     | "typedef" { $$ = $1; }
     | "unsigned" { $$ = $1; }
     | "signed" { $$ = $1; }
+    | "extern" { $$ = $1; }
 @end
 @begin ObjectiveC
     | "YES" { $$ = $1; }
@@ -754,12 +751,12 @@ BooleanLiteral
 
 /* 7.9 Automatic Semicolon Insertion {{{ */
 StrictSemi
-    : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
+    : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
     ;
 
 Terminator
     : ";"
-    | error { if (yychar != yyeof_ && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
+    | error { if (yyla.type_get() != yyeof_ && yyla.type != token::CloseBrace && !yyla.value.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
     ;
 
 TerminatorOpt
@@ -773,10 +770,10 @@ Parenthetical
     : "(" LexPushInOff Expression ")" LexPopIn { $$ = $3; }
     ;
 
-ParentheticalOpt
+/*ParentheticalOpt
     : Parenthetical { $$ = $1; }
     | { $$ = NULL; }
-    ;
+    ;*/
 
 Variable
     : Identifier { $$ = CYNew CYVariable($1); }
@@ -1430,6 +1427,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; }
     ;
 
@@ -1476,12 +1474,8 @@ TypedIdentifier
     : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
     ;
 
-EncodedType
-    : TypedIdentifier { $$ = CYNew CYEncodedType($1); }
-    ;
-
 PrimaryExpression
-    : "@encode" "(" EncodedType ")" { $$ = $3; }
+    : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
     ;
 /* }}} */
 @end
@@ -1509,7 +1503,7 @@ MessageScope
     ;
 
 TypeOpt
-    : "(" LexSetRegExp EncodedType ")" { $$ = $3; }
+    : "(" LexSetRegExp TypedIdentifier ")" { $$ = $3; }
     | { $$ = NULL; }
     ;
 
@@ -1730,9 +1724,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 {{{ */