%type <expression_> Variable
@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 <typedIdentifier_> TypeSignifier
%type <modifier_> TypeQualifierLeft
%type <typedIdentifier_> TypeQualifierRight
%type <typedIdentifier_> TypedIdentifier
%type <messageParameter_> MessageParameterList
%type <messageParameter_> MessageParameterListOpt
%type <bool_> MessageScope
-%type <typedIdentifier_> ModifiedType
%type <argument_> SelectorCall_
%type <argument_> SelectorCall
%type <selector_> SelectorExpression_
@begin C
/* Cycript (C): Type Encoding {{{ */
-TypeParenthetical
- : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
- ;
-
TypeSignifier
- : IdentifierType { $$ = 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); }
+ : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
+ | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
;
SuffixedType
- : ArrayedType { $$ = $1; }
+ : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
| "(" 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; }
+ | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
+ | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
+ | TypeSignifier { $$ = $1; }
+ | { $$ = CYNew CYTypedIdentifier(@$); }
;
PrefixedType
;
/* }}} */
/* Cycript (Objective-C): Block Expressions {{{ */
-ModifiedType
- : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->specifier_ = $2; $$->modifier_ = $1; }
- | ModifiedType "*" { $$ = $1; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
- ;
-
PrimaryExpression
- : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); }
+ : "^" TypedIdentifier { if ($2->identifier_ != NULL) error($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else error($2->location_, "expected parameters"); }
;
/* }}} */
/* Cycript (Objective-C): Instance Literals {{{ */
/* }}} */
/* Cycript (C): Type Definitions {{{ */
Statement__
- : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) YYABORT; } Terminator { $$ = CYNew CYTypeDefinition($2); }
+ : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
;
/* }}} */
/* Cycript (C): extern "C" {{{ */
Statement__
- : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) YYABORT; } TypedIdentifier Terminator { $$ = CYNew CYExternal($2, $4); }
+ : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) YYABORT; } TypedIdentifier { if ($4->identifier_ == NULL) error($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
;
/* }}} */
#include <cstdlib>
#include "List.hpp"
+#include "Location.hpp"
#include "Pooling.hpp"
#include "Options.hpp"
virtual void Output(CYOutput &out) const;
};
+struct CYTypeFunctionWith;
+
struct CYTypeModifier :
CYNext<CYTypeModifier>
{
virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0;
void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const;
+
+ virtual CYTypeFunctionWith *Function() { return NULL; }
};
struct CYTypeArrayOf :
CYNext<CYTypedIdentifier>,
CYThing
{
+ CYLocation location_;
CYIdentifier *identifier_;
CYTypeSpecifier *specifier_;
CYTypeModifier *modifier_;
- CYTypedIdentifier(CYIdentifier *identifier = NULL) :
+ CYTypedIdentifier(const CYLocation &location, CYIdentifier *identifier = NULL) :
+ location_(location),
identifier_(identifier),
specifier_(NULL),
modifier_(NULL)
virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
+
+ CYTypeFunctionWith *Function();
};
struct CYEncodedType :
virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
+
+ virtual CYTypeFunctionWith *Function() { return this; }
};
namespace cy {