return value;
}
+void CYStructDefinition::Output(CYOutput &out, CYFlags flags) const {
+ out << "struct" << ' ' << *name_ << *tail_;
+}
+
+void CYStructTail::Output(CYOutput &out) const {
+ out << ' ' << '{' << '\n';
+ ++out.indent_;
+ CYForEach (field, fields_) {
+ out << '\t' << *field->typed_;
+ out.Terminate();
+ out << '\n';
+ }
+ --out.indent_;
+ out << '}';
+}
+
void CYSuperAccess::Output(CYOutput &out, CYFlags flags) const {
out << "super";
if (const char *word = property_->Word())
}
void CYTypeStruct::Output(CYOutput &out) const {
- out << "struct" << ' ';
+ out << "struct";
if (name_ != NULL)
- out << *name_ << ' ';
- out << '{' << '\n';
- ++out.indent_;
- CYForEach (field, fields_) {
- out << '\t' << *field->typed_;
- out.Terminate();
- out << '\n';
- }
- --out.indent_;
- out << '}';
+ out << ' ' << *name_;
+ else
+ out << *tail_;
}
void CYTypeUnsigned::Output(CYOutput &out) const {
out << "unsigned" << specifier_;
}
+void CYTypeReference::Output(CYOutput &out) const {
+ out << "struct" << ' ' << *name_;
+}
+
void CYTypeVariable::Output(CYOutput &out) const {
out << *name_;
}
%type <typedIdentifier_> SuffixedType
%type <typedIdentifier_> SuffixedTypeOpt
%type <typedIdentifier_> TypeSignifier
+%type <typedIdentifier_> TypeSignifierNone
%type <typedIdentifier_> TypeSignifierOpt
%type <modifier_> TypeQualifierLeft
%type <modifier_> TypeQualifierLeftOpt
%type <typedIdentifier_> TypeQualifierRight
%type <typedIdentifier_> TypeQualifierRightOpt
+%type <typedIdentifier_> TypedIdentifierDefinition
+%type <typedIdentifier_> TypedIdentifierEncoding
+%type <typedIdentifier_> TypedIdentifierField
%type <typedIdentifier_> TypedIdentifierMaybe
%type <typedIdentifier_> TypedIdentifierNo
%type <typedIdentifier_> TypedIdentifierYes
| "volatile" { $$ = CYNew CYIdentifier("volatile"); }
@begin C
| "signed" { $$ = CYNew CYIdentifier("signed"); }
- | "struct" { $$ = CYNew CYIdentifier("struct"); }
| "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
@end
@begin ObjectiveC
| "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
;
+TypeSignifierNone
+ : { $$ = CYNew CYTypedIdentifier(@$); }
+ ;
+
TypeSignifierOpt
: TypeSignifier[pass] { $$ = $pass; }
- | { $$ = CYNew CYTypedIdentifier(@$); }
+ | TypeSignifierNone[pass] { $$ = $pass; }
;
SuffixedType
;
StructFieldListOpt
- : TypedIdentifierMaybe[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
+ : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
| { $$ = NULL; }
;
| "char" { $$ = CYNew CYTypeVariable("char"); }
| "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
| "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
- | "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYTypeStruct($name, $fields); }
+ | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
;
TypedIdentifierMaybe
- : TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
- | TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
| "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
+ | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
;
TypedIdentifierYes
: TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
;
+TypedIdentifierField
+ : TypedIdentifierYes[pass] { $$ = $pass; }
+ | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ ;
+
+TypedIdentifierEncoding
+ : TypedIdentifierNo[pass] { $$ = $pass; }
+ | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ ;
+
+TypedIdentifierDefinition
+ : TypedIdentifierYes[pass] { $$ = $pass; }
+ | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
+ ;
+
PrimaryExpression
- : "@encode" "(" TypedIdentifierMaybe[typed] ")" { $$ = CYNew CYEncodedType($typed); }
+ : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
;
/* }}} */
@end
;
ImplementationFieldListOpt
- : TypedIdentifierMaybe[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
+ : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
| { $$ = NULL; }
;
;
PrimaryExpression
- : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierMaybe[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
+ : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
+ ;
+/* }}} */
+/* Cycript (C): Structure Definitions {{{ */
+IdentifierNoOf
+ : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
+ ;
+
+Statement__
+ : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
+ ;
+
+PrimaryExpression
+ : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
;
/* }}} */
/* Cycript (C): Type Definitions {{{ */
;
TypeDefinition
- : "typedef" NewLineNot TypedIdentifierYes[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
+ : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
;
Statement__
;
PrimaryExpression
- : "(" LexOf "typedef" NewLineOpt TypedIdentifierNo[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
+ : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
;
/* }}} */
/* Cycript (C): extern "C" {{{ */
;
ExternCStatement
- : TypedIdentifierYes[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
+ : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
| TypeDefinition[pass] { $$ = $pass; }
;
: "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
;
/* }}} */
-
@end
@begin E4X
return this;
}
+CYStatement *CYStructDefinition::Replace(CYContext &context) {
+ CYTarget *target(tail_->Replace(context));
+ if (name_ != NULL)
+ target = $C1($M(target, $S("withName")), $S(name_->Word()));
+ return $ CYLexical(false, $B1($B($I($pool.strcat(name_->Word(), "$cy", NULL)), target)));
+}
+
+CYTarget *CYStructTail::Replace(CYContext &context) {
+ CYList<CYElementValue> types;
+ CYList<CYElementValue> names;
+
+ CYForEach (field, fields_) {
+ CYTypedIdentifier *typed(field->typed_);
+ types->*$ CYElementValue(typed->Replace(context));
+
+ CYExpression *name;
+ if (typed->identifier_ == NULL)
+ name = NULL;
+ else
+ name = $S(typed->identifier_->Word());
+ names->*$ CYElementValue(name);
+ }
+
+ return $N2($V("Type"), $ CYArray(types), $ CYArray(names));
+}
+
CYTarget *CYSuperAccess::Replace(CYContext &context) {
return $C1($M($M($M($V(context.super_), $S("prototype")), property_), $S("bind")), $ CYThis());
}
return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("pointerTo"))));
}
+CYTarget *CYTypeReference::Replace(CYContext &context) {
+ return $V($pool.strcat(name_->Word(), "$cy", NULL));
+}
+
CYTarget *CYTypeShort::Replace(CYContext &context) {
return $ CYCall($ CYDirectMember(specifier_->Replace(context), $ CYString("short")));
}
}
CYTarget *CYTypeStruct::Replace(CYContext &context) {
- CYList<CYElementValue> types;
- CYList<CYElementValue> names;
-
- CYForEach (field, fields_) {
- CYTypedIdentifier *typed(field->typed_);
- types->*$ CYElementValue(typed->Replace(context));
-
- CYExpression *name;
- if (typed->identifier_ == NULL)
- name = NULL;
- else
- name = $S(typed->identifier_->Word());
- names->*$ CYElementValue(name);
- }
-
- CYTarget *target($N2($V("Type"), $ CYArray(types), $ CYArray(names)));
+ CYTarget *target(tail_->Replace(context));
if (name_ != NULL)
target = $C1($M(target, $S("withName")), $S(name_->Word()));
return target;
virtual void Output(CYOutput &out) const;
};
+struct CYTypeReference :
+ CYTypeSpecifier
+{
+ CYIdentifier *name_;
+
+ CYTypeReference(CYIdentifier *name) :
+ name_(name)
+ {
+ }
+
+ virtual CYTarget *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
struct CYTypeVariable :
CYTypeSpecifier
{
}
};
+struct CYStructTail :
+ CYThing
+{
+ CYTypeStructField *fields_;
+
+ CYStructTail(CYTypeStructField *fields) :
+ fields_(fields)
+ {
+ }
+
+ CYTarget *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
struct CYTypeStruct :
CYTypeSpecifier
{
CYIdentifier *name_;
- CYTypeStructField *fields_;
+ CYStructTail *tail_;
- CYTypeStruct(CYIdentifier *name, CYTypeStructField *fields) :
+ CYTypeStruct(CYIdentifier *name, CYStructTail *tail) :
name_(name),
- fields_(fields)
+ tail_(tail)
{
}
virtual void Output(CYOutput &out) const;
};
+struct CYStructDefinition :
+ CYStatement
+{
+ CYIdentifier *name_;
+ CYStructTail *tail_;
+
+ CYStructDefinition(CYIdentifier *name, CYStructTail *tail) :
+ name_(name),
+ tail_(tail)
+ {
+ }
+
+ CYCompact(None)
+
+ virtual CYStatement *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
namespace cy {
namespace Syntax {