CYThis *this_;
CYTrue *true_;
CYTypeModifier *type_;
- CYTypedIdentifier *typed_;
+ CYTypedIdentifier *typedIdentifier_;
+ CYTypedParameter *typedParameter_;
CYWord *word_;
@begin ObjectiveC
%type <messageParameter_> MessageParameterListOpt
%type <bool_> MessageScope
%type <type_> ModifiedType
-%type <typed_> PrefixedType
+%type <typedIdentifier_> PrefixedType
+%type <type_> QualifiedType
%type <argument_> SelectorCall_
%type <argument_> SelectorCall
%type <selector_> SelectorExpression_
%type <selector_> SelectorExpressionOpt
%type <argument_> SelectorList
%type <word_> SelectorWordOpt
-%type <typed_> SuffixedType
+%type <typedIdentifier_> SuffixedType
%type <expression_> TypeOpt
-%type <typed_> TypedIdentifier
+%type <typedIdentifier_> TypedIdentifier
+%type <typedParameter_> TypedParameterList_
+%type <typedParameter_> TypedParameterList
+%type <typedParameter_> TypedParameterListOpt
%type <argument_> VariadicCall
@end
/* Cycript (Objective-C): Type Encoding {{{ */
SuffixedType
: IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); }
- | "(" PrefixedType ")" { $$ = $2; }
+ | "(" LexPushInOff PrefixedType LexPopIn ")" { $$ = $3; }
| SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3->Value()); $$ = $1; }
;
| "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; }
;
-ModifiedType
+QualifiedType
: Variable { $$ = CYNew CYTypeVariable($1); }
- | "const" ModifiedType { $$ = CYNew CYTypeConstant($2); }
+ | "const" QualifiedType { $$ = CYNew CYTypeConstant($2); }
+ ;
+
+ModifiedType
+ : QualifiedType { $$ = $1; }
+ | QualifiedType "*" { $$ = CYNew CYTypePointerTo($1); }
+ | QualifiedType "const" { $$ = CYNew CYTypeConstant($1); }
;
TypedIdentifier
- : ModifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;}
+ : QualifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;}
;
EncodedType
;
TypeOpt
- : "(" EncodedType ")" { $$ = $2; }
+ : "(" LexSetRegExp EncodedType ")" { $$ = $3; }
| "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); }
| { $$ = NULL; }
;
: "@" BoxableExpression { $$ = CYNew CYBox($2); }
;
/* }}} */
+/* Cycript (Objective-C): Block Expressions {{{ */
+TypedParameterList_
+ : "," TypedParameterList { $$ = $2; }
+ | { $$ = NULL; }
+ ;
+
+TypedParameterList
+ : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
+ ;
+
+TypedParameterListOpt
+ : TypedParameterList { $$ = $1; }
+ | { $$ = NULL; }
+ ;
+
+PrimaryExpression
+ : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYObjCBlock($2, $5, $10); }
+ ;
+/* }}} */
@end
@begin C
return $C1($M($V("Instance"), $S("box")), value_);
}
+CYExpression *CYObjCBlock::Replace(CYContext &context) {
+ return $N2($V("Functor"), $ CYFunctionExpression(NULL, parameters_->Parameters(context), statements_), parameters_->TypeSignature(context, type_->Replace(context)));
+}
+
CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL)
return $ CYBlock($$->*
next_->Replace(context)->*
CYExpression *CYSendSuper::Replace(CYContext &context) {
return $ CYSendDirect($V("$cyr"), arguments_);
}
+
+CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL)
+ return $ CYFunctionParameter($ CYDeclaration(typed_->identifier_), next_->Parameters(context));
+}
+
+CYExpression *CYTypedParameter::TypeSignature(CYContext &context, CYExpression *prefix) { $T(prefix)
+ return next_->TypeSignature(context, $ CYAdd(prefix, typed_->type_->Replace(context)));
+}
}
};
+struct CYTypedParameter :
+ CYNext<CYTypedParameter>
+{
+ CYTypedIdentifier *typed_;
+
+ CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) :
+ CYNext<CYTypedParameter>(next),
+ typed_(typed)
+ {
+ }
+
+ CYFunctionParameter *Parameters(CYContext &context);
+ CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
+};
+
+struct CYObjCBlock :
+ CYExpression
+{
+ CYTypeModifier *type_;
+ CYTypedParameter *parameters_;
+ CYStatement *statements_;
+
+ CYObjCBlock(CYTypeModifier *type, CYTypedParameter *parameters, CYStatement *statements) :
+ type_(type),
+ parameters_(parameters),
+ statements_(statements)
+ {
+ }
+
+ CYPrecedence(1)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYEncodedType :
CYExpression
{