X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/fd5cdf97150f0c0f2126d61f6e91511cc6b22936..79492f212da2fcaa4ce44d00fc08530e1630d05b:/Cycript.yy.in diff --git a/Cycript.yy.in b/Cycript.yy.in index 3a31f1e..b2f5629 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -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 . + * 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 . **/ /* }}} */ @@ -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 @@ -107,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" @@ -237,13 +245,17 @@ int cylex(YYSTYPE *, cy::location *, void *); %token Typedef "typedef" %token Unsigned "unsigned" %token Signed "signed" +%token 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 Yes "YES" @@ -426,6 +438,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type MemberAccess %type MemberExpression_ %type MemberExpression +%type Module %type MultiplicativeExpression %type NewExpression %type NullLiteral @@ -472,8 +485,25 @@ int cylex(YYSTYPE *, cy::location *, void *); %type WordOpt %type Variable -@begin ObjectiveC +@begin C %type ArrayedType +%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 +518,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 +525,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 +532,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 TypeOpt %type VariadicCall @end @@ -705,6 +719,9 @@ Identifier | "typedef" { $$ = $1; } | "unsigned" { $$ = $1; } | "signed" { $$ = $1; } + | "extern" { $$ = $1; } +@end +@begin ObjectiveC | "YES" { $$ = $1; } | "NO" { $$ = $1; } @end @@ -1394,8 +1411,8 @@ ProgramBodyOpt ; /* }}} */ -@begin ObjectiveC -/* Cycript (Objective-C): Type Encoding {{{ */ +@begin C +/* Cycript (C): Type Encoding {{{ */ TypeParenthetical : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; } ; @@ -1419,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; } ; @@ -1465,14 +1483,13 @@ 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 + +@begin ObjectiveC /* Cycript (Objective-C): @class Declaration {{{ */ ClassSuperOpt /* XXX: why the hell did I choose MemberExpression? */ @@ -1495,7 +1512,7 @@ MessageScope ; TypeOpt - : "(" LexSetRegExp EncodedType ")" { $$ = $3; } + : "(" LexSetRegExp TypedIdentifier ")" { $$ = $3; } | { $$ = NULL; } ; @@ -1626,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); } @@ -1636,6 +1655,8 @@ Declaration__ : "@import" Module { $$ = CYNew CYImport($2); } ; /* }}} */ + +@begin ObjectiveC /* Cycript (Objective-C): Boxed Expressions {{{ */ BoxableExpression : NullLiteral { $$ = $1; } @@ -1712,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 {{{ */