/* 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/>.
**/
/* }}} */
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_;
CYMessageParameter *messageParameter_;
CYProtocol *protocol_;
CYSelectorPart *selector_;
- CYTypeModifier *modifier_;
- CYTypedIdentifier *typedIdentifier_;
- CYTypedParameter *typedParameter_;
@end
@begin E4X
} 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"
%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"
%type <member_> MemberAccess
%type <expression_> MemberExpression_
%type <expression_> MemberExpression
+%type <module_> Module
%type <expression_> MultiplicativeExpression
%type <expression_> NewExpression
%type <null_> NullLiteral
%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
%type <protocol_> ClassProtocolListOpt
%type <protocol_> ClassProtocols
%type <protocol_> ClassProtocolsOpt
-%type <expression_> EncodedType
-%type <modifier_> FunctionedType
-%type <specifier_> IntegerType
-%type <specifier_> IntegerTypeOpt
%type <expression_> MessageExpression
%type <messageParameter_> MessageParameter
%type <messageParameter_> MessageParameters
%type <messageParameter_> MessageParameterListOpt
%type <bool_> MessageScope
%type <typedIdentifier_> ModifiedType
-%type <module_> Module
-%type <typedIdentifier_> PrefixedType
-%type <specifier_> PrimitiveType
%type <argument_> SelectorCall_
%type <argument_> SelectorCall
%type <selector_> SelectorExpression_
%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
| "typedef" { $$ = $1; }
| "unsigned" { $$ = $1; }
| "signed" { $$ = $1; }
+ | "extern" { $$ = $1; }
+@end
+@begin ObjectiveC
| "YES" { $$ = $1; }
| "NO" { $$ = $1; }
@end
/* 11.14 Comma Operator {{{ */
Expression_
: "," Expression { $$ = $2; }
- | { $$ = CYNew CYCompound(); }
+ | { $$ = NULL; }
;
Expression
- : AssignmentExpression Expression_ { $2->AddPrev($1); $$ = $2; }
+ : AssignmentExpression Expression_ { $$ = CYNew CYCompound($1, $2); }
;
ExpressionOpt
;
/* }}} */
-@begin ObjectiveC
-/* Cycript (Objective-C): Type Encoding {{{ */
+@begin C
+/* Cycript (C): Type Encoding {{{ */
TypeParenthetical
: "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
;
: 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; }
;
IntegerTypeOpt
: IntegerType { $$ = $1; }
- |
+ | { $$ = CYNew CYTypeVariable("int"); }
;
PrimitiveType
: TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
;
-EncodedType
- : TypedIdentifier { $$ = CYNew CYEncodedType($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? */
;
ClassFieldListOpt
- : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); }
+ : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $3); }
| LexSetRegExp { $$ = NULL; }
;
;
TypeOpt
- : "(" LexSetRegExp EncodedType ")" { $$ = $3; }
+ : "(" LexSetRegExp TypedIdentifier ")" { $$ = $3; }
| { $$ = NULL; }
;
| "@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); }
: "@import" Module { $$ = CYNew CYImport($2); }
;
/* }}} */
+
+@begin ObjectiveC
/* Cycript (Objective-C): Boxed Expressions {{{ */
BoxableExpression
: NullLiteral { $$ = $1; }
/* }}} */
/* 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 {{{ */