X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/7b87d2051f4c0c29515b30b1202a23a52e2d5f9e..20c32d79db6c7cb83737ef0142fd75d7ec35c81c:/Syntax.hpp diff --git a/Syntax.hpp b/Syntax.hpp index 7bc5bbe..4b25b30 100644 --- a/Syntax.hpp +++ b/Syntax.hpp @@ -1,5 +1,5 @@ -/* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2015 Jay Freeman (saurik) +/* Cycript - The Truly Universal Scripting Language + * Copyright (C) 2009-2016 Jay Freeman (saurik) */ /* GNU Affero General Public License, Version 3 {{{ */ @@ -33,6 +33,25 @@ #include "Location.hpp" #include "Options.hpp" #include "Pooling.hpp" +#include "String.hpp" + +double CYCastDouble(const char *value, size_t size); +double CYCastDouble(const char *value); +double CYCastDouble(CYUTF8String value); + +void CYNumerify(std::ostringstream &str, double value); + +enum CYStringifyMode { + CYStringifyModeLegacy, + CYStringifyModeCycript, + CYStringifyModeNative, +}; + +void CYStringify(std::ostringstream &str, const char *data, size_t size, CYStringifyMode mode); + +// XXX: this really should not be here ... :/ +void *CYPoolFile(CYPool &pool, const char *path, size_t *psize); +CYUTF8String CYPoolFileUTF8String(CYPool &pool, const char *path); struct CYContext; @@ -108,6 +127,8 @@ struct CYOutput { struct CYExpression; struct CYAssignment; +struct CYIdentifier; +struct CYNumber; struct CYPropertyName { virtual bool Computed() const { @@ -118,6 +139,14 @@ struct CYPropertyName { return false; } + virtual CYIdentifier *Identifier() { + return NULL; + } + + virtual CYNumber *Number(CYContext &context) { + return NULL; + } + virtual CYExpression *PropertyName(CYContext &context) = 0; virtual void PropertyName(CYOutput &out) const = 0; }; @@ -138,6 +167,7 @@ enum CYFlags { CYNoRightHand = (1 << 5), CYNoDangle = (1 << 6), CYNoInteger = (1 << 7), + CYNoColon = (1 << 8), CYNoBFC = (CYNoBrace | CYNoFunction | CYNoClass), }; @@ -258,6 +288,10 @@ struct CYIdentifier : { } + CYIdentifier *Identifier() override { + return this; + } + virtual const char *Word() const; CYIdentifier *Replace(CYContext &context, CYIdentifierKind); }; @@ -522,6 +556,10 @@ struct CYTarget : return false; } + virtual bool IsNew() const { + return false; + } + virtual CYStatement *Initialize(CYContext &context, CYExpression *value); virtual CYTarget *Replace(CYContext &context) = 0; @@ -577,17 +615,17 @@ struct CYParenthetical : void Output(CYOutput &out, CYFlags flags) const; }; -struct CYDeclaration; +struct CYBinding; struct CYFunctionParameter : CYNext, CYThing { - CYDeclaration *initialiser_; + CYBinding *binding_; - CYFunctionParameter(CYDeclaration *initialiser, CYFunctionParameter *next = NULL) : + CYFunctionParameter(CYBinding *binding, CYFunctionParameter *next = NULL) : CYNext(next), - initialiser_(initialiser) + binding_(binding) { } @@ -604,11 +642,6 @@ struct CYComprehension : { } - CYComprehension *Modify(CYComprehension *next) { - next_ = next; - return this; - } - virtual CYFunctionParameter *Parameter(CYContext &context) const = 0; CYFunctionParameter *Parameters(CYContext &context) const; virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; @@ -618,13 +651,13 @@ struct CYComprehension : struct CYForInComprehension : CYComprehension { - CYDeclaration *declaration_; - CYExpression *set_; + CYBinding *binding_; + CYExpression *iterable_; - CYForInComprehension(CYDeclaration *declaration, CYExpression *set, CYComprehension *next = NULL) : + CYForInComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) : CYComprehension(next), - declaration_(declaration), - set_(set) + binding_(binding), + iterable_(iterable) { } @@ -636,13 +669,13 @@ struct CYForInComprehension : struct CYForOfComprehension : CYComprehension { - CYDeclaration *declaration_; - CYExpression *set_; + CYBinding *binding_; + CYExpression *iterable_; - CYForOfComprehension(CYDeclaration *declaration, CYExpression *set, CYComprehension *next = NULL) : + CYForOfComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) : CYComprehension(next), - declaration_(declaration), - set_(set) + binding_(binding), + iterable_(iterable) { } @@ -768,6 +801,7 @@ struct CYString : return value_; } + virtual CYIdentifier *Identifier() const; virtual const char *Word() const; virtual CYNumber *Number(CYContext &context); @@ -812,6 +846,8 @@ struct CYTemplate : CYPrecedence(0) + virtual CYString *String(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -896,6 +932,12 @@ struct CYThis : struct CYBoolean : CYTrivial { + CYPrecedence(4) + + virtual bool RightHand() const { + return true; + } + virtual bool Value() const = 0; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -949,6 +991,22 @@ struct CYVariable : virtual CYFunctionParameter *Parameter() const; }; +struct CYSymbol : + CYTarget +{ + const char *name_; + + CYSymbol(const char *name) : + name_(name) + { + } + + CYPrecedence(0) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYPrefix : CYExpression { @@ -1062,11 +1120,11 @@ struct CYClause : CYThing, CYNext { - CYExpression *case_; + CYExpression *value_; CYStatement *code_; - CYClause(CYExpression *_case, CYStatement *code) : - case_(_case), + CYClause(CYExpression *value, CYStatement *code) : + value_(value), code_(code) { } @@ -1076,21 +1134,26 @@ struct CYClause : }; struct CYElement : + CYNext, CYThing { + CYElement(CYElement *next) : + CYNext(next) + { + } + virtual bool Elision() const = 0; virtual void Replace(CYContext &context) = 0; }; struct CYElementValue : - CYNext, CYElement { CYExpression *value_; - CYElementValue(CYExpression *value, CYElement *next) : - CYNext(next), + CYElementValue(CYExpression *value, CYElement *next = NULL) : + CYElement(next), value_(value) { } @@ -1108,7 +1171,8 @@ struct CYElementSpread : { CYExpression *value_; - CYElementSpread(CYExpression *value) : + CYElementSpread(CYExpression *value, CYElement *next = NULL) : + CYElement(next), value_(value) { } @@ -1135,13 +1199,13 @@ struct CYArray : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYDeclaration { +struct CYBinding { CYIdentifier *identifier_; - CYExpression *initialiser_; + CYExpression *initializer_; - CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) : + CYBinding(CYIdentifier *identifier, CYExpression *initializer = NULL) : identifier_(identifier), - initialiser_(initialiser) + initializer_(initializer) { } @@ -1155,11 +1219,11 @@ struct CYForLexical : CYForInInitializer { bool constant_; - CYDeclaration *declaration_; + CYBinding *binding_; - CYForLexical(bool constant, CYDeclaration *declaration) : + CYForLexical(bool constant, CYBinding *binding) : constant_(constant), - declaration_(declaration) + binding_(binding) { } @@ -1172,10 +1236,10 @@ struct CYForLexical : struct CYForVariable : CYForInInitializer { - CYDeclaration *declaration_; + CYBinding *binding_; - CYForVariable(CYDeclaration *declaration) : - declaration_(declaration) + CYForVariable(CYBinding *binding) : + binding_(binding) { } @@ -1185,15 +1249,15 @@ struct CYForVariable : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYDeclarations : - CYNext, +struct CYBindings : + CYNext, CYThing { - CYDeclaration *declaration_; + CYBinding *binding_; - CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) : - CYNext(next), - declaration_(declaration) + CYBindings(CYBinding *binding, CYBindings *next = NULL) : + CYNext(next), + binding_(binding) { } @@ -1209,10 +1273,10 @@ struct CYDeclarations : struct CYVar : CYForInitializer { - CYDeclarations *declarations_; + CYBindings *bindings_; - CYVar(CYDeclarations *declarations) : - declarations_(declarations) + CYVar(CYBindings *bindings) : + bindings_(bindings) { } @@ -1222,15 +1286,15 @@ struct CYVar : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYLet : +struct CYLexical : CYForInitializer { bool constant_; - CYDeclarations *declarations_; + CYBindings *bindings_; - CYLet(bool constant, CYDeclarations *declarations) : + CYLexical(bool constant, CYBindings *bindings) : constant_(constant), - declarations_(declarations) + bindings_(bindings) { } @@ -1241,7 +1305,7 @@ struct CYLet : }; struct CYBuilder { - CYList declarations_; + CYList bindings_; CYList statements_; operator bool() const { @@ -1291,13 +1355,13 @@ struct CYPropertyValue : struct CYFor : CYStatement { - CYForInitializer *initialiser_; + CYForInitializer *initializer_; CYExpression *test_; CYExpression *increment_; CYStatement *code_; - CYFor(CYForInitializer *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) : - initialiser_(initialiser), + CYFor(CYForInitializer *initializer, CYExpression *test, CYExpression *increment, CYStatement *code) : + initializer_(initializer), test_(test), increment_(increment), code_(code) @@ -1313,13 +1377,13 @@ struct CYFor : struct CYForIn : CYStatement { - CYForInInitializer *initialiser_; - CYExpression *set_; + CYForInInitializer *initializer_; + CYExpression *iterable_; CYStatement *code_; - CYForIn(CYForInInitializer *initialiser, CYExpression *set, CYStatement *code) : - initialiser_(initialiser), - set_(set), + CYForIn(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) : + initializer_(initializer), + iterable_(iterable), code_(code) { } @@ -1333,13 +1397,13 @@ struct CYForIn : struct CYForInitialized : CYStatement { - CYDeclaration *declaration_; - CYExpression *set_; + CYBinding *binding_; + CYExpression *iterable_; CYStatement *code_; - CYForInitialized(CYDeclaration *declaration, CYExpression *set, CYStatement *code) : - declaration_(declaration), - set_(set), + CYForInitialized(CYBinding *binding, CYExpression *iterable, CYStatement *code) : + binding_(binding), + iterable_(iterable), code_(code) { } @@ -1353,13 +1417,13 @@ struct CYForInitialized : struct CYForOf : CYStatement { - CYForInInitializer *initialiser_; - CYExpression *set_; + CYForInInitializer *initializer_; + CYExpression *iterable_; CYStatement *code_; - CYForOf(CYForInInitializer *initialiser, CYExpression *set, CYStatement *code) : - initialiser_(initialiser), - set_(set), + CYForOf(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) : + initializer_(initializer), + iterable_(iterable), code_(code) { } @@ -1380,6 +1444,8 @@ struct CYObject : { } + CYTarget *Replace(CYContext &context, CYTarget *seed); + virtual CYTarget *Replace(CYContext &context); void Output(CYOutput &out, CYFlags flags) const; }; @@ -1415,6 +1481,20 @@ struct CYDirectMember : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYAttemptMember : + CYMember +{ + CYAttemptMember(CYExpression *object, CYExpression *property) : + CYMember(object, property) + { + } + + CYPrecedence(1) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYIndirectMember : CYMember { @@ -1429,6 +1509,34 @@ struct CYIndirectMember : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYResolveMember : + CYMember +{ + CYResolveMember(CYExpression *object, CYExpression *property) : + CYMember(object, property) + { + } + + CYPrecedence(1) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYSubscriptMember : + CYMember +{ + CYSubscriptMember(CYExpression *object, CYExpression *property) : + CYMember(object, property) + { + } + + CYPrecedence(1) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + namespace cy { namespace Syntax { @@ -1448,6 +1556,9 @@ struct New : return arguments_ == NULL ? 2 : 1; } + virtual bool IsNew() const { + return true; + } virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; @@ -1501,26 +1612,55 @@ struct CYEval : struct CYRubyProc; -struct CYRubyBlock : +struct CYBraced : CYTarget { - CYExpression *call_; - CYRubyProc *proc_; + CYTarget *lhs_; - CYRubyBlock(CYExpression *call, CYRubyProc *proc) : - call_(call), - proc_(proc) + CYBraced(CYTarget *lhs = NULL) : + lhs_(lhs) { } CYPrecedence(1) + void SetLeft(CYTarget *lhs) { + lhs_ = lhs; + } +}; + +struct CYRubyBlock : + CYBraced +{ + CYRubyProc *proc_; + + CYRubyBlock(CYTarget *lhs, CYRubyProc *proc) : + CYBraced(lhs), + proc_(proc) + { + } + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; virtual CYTarget *AddArgument(CYContext &context, CYExpression *value); }; +struct CYExtend : + CYBraced +{ + CYObject object_; + + CYExtend(CYTarget *lhs, CYProperty *properties = NULL) : + CYBraced(lhs), + object_(properties) + { + } + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYIf : CYStatement { @@ -1950,42 +2090,91 @@ struct CYTypeError : virtual void Output(CYOutput &out) const; }; -struct CYTypeVoid : +enum CYTypeSigning { + CYTypeNeutral, + CYTypeSigned, + CYTypeUnsigned, +}; + +struct CYTypeCharacter : CYTypeSpecifier { - CYTypeVoid() { + CYTypeSigning signing_; + + CYTypeCharacter(CYTypeSigning signing) : + signing_(signing) + { } virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; -struct CYTypeVariable : +struct CYTypeInt128 : CYTypeSpecifier { - CYIdentifier *name_; + CYTypeSigning signing_; - CYTypeVariable(CYIdentifier *name) : - name_(name) + CYTypeInt128(CYTypeSigning signing) : + signing_(signing) { } - CYTypeVariable(const char *name) : - name_(new($pool) CYIdentifier(name)) + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out) const; +}; + +struct CYTypeIntegral : + CYTypeSpecifier +{ + CYTypeSigning signing_; + int length_; + + CYTypeIntegral(CYTypeSigning signing, int length = 1) : + signing_(signing), + length_(length) { } + CYTypeIntegral *Long() { + if (length_ != 1 && length_ != 2) + return NULL; + ++length_; + return this; + } + + CYTypeIntegral *Short() { + if (length_ != 1) + return NULL; + --length_; + return this; + } + + CYTypeIntegral *Signed() { + if (signing_ != CYTypeNeutral) + return NULL; + signing_ = CYTypeSigned; + return this; + } + + CYTypeIntegral *Unsigned() { + if (signing_ != CYTypeNeutral) + return NULL; + signing_ = CYTypeUnsigned; + return this; + } + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; -struct CYTypeUnsigned : +struct CYTypeFloating : CYTypeSpecifier { - CYTypeSpecifier *specifier_; + int length_; - CYTypeUnsigned(CYTypeSpecifier *specifier) : - specifier_(specifier) + CYTypeFloating(int length) : + length_(length) { } @@ -1993,27 +2182,30 @@ struct CYTypeUnsigned : virtual void Output(CYOutput &out) const; }; -struct CYTypeSigned : +struct CYTypeVoid : CYTypeSpecifier { - CYTypeSpecifier *specifier_; - - CYTypeSigned(CYTypeSpecifier *specifier) : - specifier_(specifier) - { + CYTypeVoid() { } virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; -struct CYTypeLong : +enum CYTypeReferenceKind { + CYTypeReferenceStruct, + CYTypeReferenceEnum, +}; + +struct CYTypeReference : CYTypeSpecifier { - CYTypeSpecifier *specifier_; + CYTypeReferenceKind kind_; + CYIdentifier *name_; - CYTypeLong(CYTypeSpecifier *specifier) : - specifier_(specifier) + CYTypeReference(CYTypeReferenceKind kind, CYIdentifier *name) : + kind_(kind), + name_(name) { } @@ -2021,13 +2213,18 @@ struct CYTypeLong : virtual void Output(CYOutput &out) const; }; -struct CYTypeShort : +struct CYTypeVariable : CYTypeSpecifier { - CYTypeSpecifier *specifier_; + CYIdentifier *name_; - CYTypeShort(CYTypeSpecifier *specifier) : - specifier_(specifier) + CYTypeVariable(CYIdentifier *name) : + name_(name) + { + } + + CYTypeVariable(const char *name) : + name_(new($pool) CYIdentifier(name)) { } @@ -2050,8 +2247,8 @@ struct CYTypeModifier : virtual CYTarget *Replace_(CYContext &context, CYTarget *type) = 0; CYTarget *Replace(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0; - void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const; + virtual void Output(CYOutput &out, CYPropertyName *name) const = 0; + void Output(CYOutput &out, int precedence, CYPropertyName *name, bool space) const; virtual CYTypeFunctionWith *Function() { return NULL; } }; @@ -2070,7 +2267,7 @@ struct CYTypeArrayOf : CYPrecedence(1) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; struct CYTypeConstant : @@ -2084,7 +2281,7 @@ struct CYTypeConstant : CYPrecedence(0) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; struct CYTypePointerTo : @@ -2098,7 +2295,7 @@ struct CYTypePointerTo : CYPrecedence(0) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; struct CYTypeVolatile : @@ -2112,50 +2309,63 @@ struct CYTypeVolatile : CYPrecedence(0) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; -struct CYTypedIdentifier : - CYNext, +struct CYType : CYThing { - CYLocation location_; - CYIdentifier *identifier_; CYTypeSpecifier *specifier_; CYTypeModifier *modifier_; - CYTypedIdentifier(const CYLocation &location, CYIdentifier *identifier = NULL) : - location_(location), - identifier_(identifier), - specifier_(NULL), - modifier_(NULL) - { - } - - CYTypedIdentifier(CYTypeSpecifier *specifier, CYTypeModifier *modifier = NULL) : - identifier_(NULL), + CYType(CYTypeSpecifier *specifier = NULL, CYTypeModifier *modifier = NULL) : specifier_(specifier), modifier_(modifier) { } - inline CYTypedIdentifier *Modify(CYTypeModifier *modifier) { + inline CYType *Modify(CYTypeModifier *modifier) { CYSetLast(modifier_) = modifier; return this; } + void Output(CYOutput &out, CYPropertyName *name) const; + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; CYTypeFunctionWith *Function(); }; +struct CYTypedLocation : + CYType +{ + CYLocation location_; + + CYTypedLocation(const CYLocation &location) : + location_(location) + { + } +}; + +struct CYTypedName : + CYTypedLocation +{ + CYPropertyName *name_; + + CYTypedName(const CYLocation &location, CYPropertyName *name = NULL) : + CYTypedLocation(location), + name_(name) + { + } +}; + struct CYEncodedType : CYTarget { - CYTypedIdentifier *typed_; + CYType *typed_; - CYEncodedType(CYTypedIdentifier *typed) : + CYEncodedType(CYType *typed) : typed_(typed) { } @@ -2170,11 +2380,13 @@ struct CYTypedParameter : CYNext, CYThing { - CYTypedIdentifier *typed_; + CYType *type_; + CYIdentifier *name_; - CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) : + CYTypedParameter(CYType *type, CYIdentifier *name, CYTypedParameter *next = NULL) : CYNext(next), - typed_(typed) + type_(type), + name_(name) { } @@ -2185,14 +2397,25 @@ struct CYTypedParameter : virtual void Output(CYOutput &out) const; }; +struct CYTypedFormal { + bool variadic_; + CYTypedParameter *parameters_; + + CYTypedFormal(bool variadic) : + variadic_(variadic), + parameters_(NULL) + { + } +}; + struct CYLambda : CYTarget { - CYTypedIdentifier *typed_; + CYType *typed_; CYTypedParameter *parameters_; CYStatement *code_; - CYLambda(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *code) : + CYLambda(CYType *typed, CYTypedParameter *parameters, CYStatement *code) : typed_(typed), parameters_(parameters), code_(code) @@ -2237,15 +2460,70 @@ struct CYImport : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYExternal : +struct CYImportSpecifier : + CYNext +{ + CYWord *name_; + CYIdentifier *binding_; + + CYImportSpecifier(CYWord *name, CYIdentifier *binding) : + name_(name), + binding_(binding) + { + } + + CYStatement *Replace(CYContext &context, CYIdentifier *module); +}; + +struct CYImportDeclaration : CYStatement +{ + CYImportSpecifier *specifiers_; + CYString *module_; + + CYImportDeclaration(CYImportSpecifier *specifiers, CYString *module) : + specifiers_(specifiers), + module_(module) + { + } + + CYCompact(None) + + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYExternalExpression : + CYTarget { CYString *abi_; - CYTypedIdentifier *typed_; + CYType *type_; + CYPropertyName *name_; - CYExternal(CYString *abi, CYTypedIdentifier *typed) : + CYExternalExpression(CYString *abi, CYType *type, CYPropertyName *name) : abi_(abi), - typed_(typed) + type_(type), + name_(name) + { + } + + CYPrecedence(0) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYExternalDefinition : + CYStatement +{ + CYString *abi_; + CYType *type_; + CYIdentifier *name_; + + CYExternalDefinition(CYString *abi, CYType *type, CYIdentifier *name) : + abi_(abi), + type_(type), + name_(name) { } @@ -2255,13 +2533,31 @@ struct CYExternal : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYTypeExpression : + CYTarget +{ + CYType *typed_; + + CYTypeExpression(CYType *typed) : + typed_(typed) + { + } + + CYPrecedence(0) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYTypeDefinition : CYStatement { - CYTypedIdentifier *typed_; + CYType *type_; + CYIdentifier *name_; - CYTypeDefinition(CYTypedIdentifier *typed) : - typed_(typed) + CYTypeDefinition(CYType *type, CYIdentifier *name) : + type_(type), + name_(name) { } @@ -2285,16 +2581,18 @@ struct CYTypeBlockWith : CYPrecedence(0) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; struct CYTypeFunctionWith : CYTypeModifier { + bool variadic_; CYTypedParameter *parameters_; - CYTypeFunctionWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) : + CYTypeFunctionWith(bool variadic, CYTypedParameter *parameters, CYTypeModifier *next = NULL) : CYTypeModifier(next), + variadic_(variadic), parameters_(parameters) { } @@ -2302,11 +2600,105 @@ struct CYTypeFunctionWith : CYPrecedence(1) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; virtual CYTypeFunctionWith *Function() { return this; } }; +struct CYTypeStructField : + CYNext +{ + CYType *type_; + CYPropertyName *name_; + + CYTypeStructField(CYType *type, CYPropertyName *name, CYTypeStructField *next = NULL) : + CYNext(next), + type_(type), + name_(name) + { + } +}; + +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_; + CYStructTail *tail_; + + CYTypeStruct(CYIdentifier *name, CYStructTail *tail) : + name_(name), + tail_(tail) + { + } + + virtual CYTarget *Replace(CYContext &context); + 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; +}; + +struct CYEnumConstant : + CYNext +{ + CYIdentifier *name_; + CYNumber *value_; + + CYEnumConstant(CYIdentifier *name, CYNumber *value, CYEnumConstant *next = NULL) : + CYNext(next), + name_(name), + value_(value) + { + } +}; + +struct CYTypeEnum : + CYTypeSpecifier +{ + CYIdentifier *name_; + CYTypeSpecifier *specifier_; + CYEnumConstant *constants_; + + CYTypeEnum(CYIdentifier *name, CYTypeSpecifier *specifier, CYEnumConstant *constants) : + name_(name), + specifier_(specifier), + constants_(constants) + { + } + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out) const; +}; + namespace cy { namespace Syntax {