X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/a196a97ab164eed3f08ce1fb944c11486e99e320..20ac42262940be749bcb41139c42bb01878c6c02:/Syntax.hpp diff --git a/Syntax.hpp b/Syntax.hpp index d278729..f11c2f2 100644 --- a/Syntax.hpp +++ b/Syntax.hpp @@ -28,8 +28,6 @@ #include #include #include -#include -#include #include "List.hpp" #include "Location.hpp" @@ -78,15 +76,15 @@ struct CYOutput { _assert(out_.sputc(value) != EOF); recent_ = indent_; if (value == '\n') - position_.lines(1); + position_.Lines(1); else - position_.columns(1); + position_.Columns(1); } _finline void operator ()(const char *data, std::streamsize size) { _assert(out_.sputn(data, size) == size); recent_ = indent_; - position_.columns(size); + position_.Columns(size); } _finline void operator ()(const char *data) { @@ -201,6 +199,13 @@ struct CYStatement : typedef CYList CYStatements; +struct CYForInitializer : + CYStatement +{ + virtual CYForInitializer *Replace(CYContext &context) = 0; + virtual void Output(CYOutput &out, CYFlags flags) const = 0; +}; + struct CYWord : CYThing, CYPropertyName @@ -212,10 +217,6 @@ struct CYWord : { } - void Set(const char *value) { - word_ = value; - } - virtual bool Constructor() const { return strcmp(word_, "constructor") == 0; } @@ -232,24 +233,33 @@ _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) { return lhs << rhs.Word(); } +enum CYIdentifierKind { + CYIdentifierArgument, + CYIdentifierCatch, + CYIdentifierGlobal, + CYIdentifierLexical, + CYIdentifierMagic, + CYIdentifierOther, + CYIdentifierVariable, +}; + struct CYIdentifier : CYNext, CYWord { - CYIdentifier *replace_; + CYLocation location_; size_t offset_; size_t usage_; CYIdentifier(const char *word) : CYWord(word), - replace_(NULL), offset_(0), usage_(0) { } virtual const char *Word() const; - CYIdentifier *Replace(CYContext &context); + CYIdentifier *Replace(CYContext &context, CYIdentifierKind); }; struct CYLabel : @@ -286,38 +296,43 @@ struct CYIdentifierValueLess : } }; -enum CYIdentifierFlags { - CYIdentifierArgument, - CYIdentifierVariable, - CYIdentifierOther, - CYIdentifierMagic, - CYIdentifierCatch, -}; - -typedef std::set CYCStringSet; -typedef std::set CYIdentifierValueSet; -typedef std::map CYIdentifierAddressFlagsMap; - -struct CYIdentifierUsage { +struct CYIdentifierFlags : + CYNext +{ CYIdentifier *identifier_; - size_t usage_; -}; + CYIdentifierKind kind_; + unsigned count_; + unsigned offset_; -typedef std::vector CYIdentifierUsageVector; + CYIdentifierFlags(CYIdentifier *identifier, CYIdentifierKind kind, CYIdentifierFlags *next = NULL) : + CYNext(next), + identifier_(identifier), + kind_(kind), + count_(0), + offset_(0) + { + } +}; struct CYScope { bool transparent_; CYScope *parent_; + bool damaged_; + CYIdentifierFlags *shadow_; - CYIdentifierAddressFlagsMap internal_; - CYIdentifierValueSet identifiers_; + CYIdentifierFlags *internal_; CYScope(bool transparent, CYContext &context); - void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags); - virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier); - void Merge(CYContext &context, CYIdentifier *identifier); + CYIdentifierFlags *Lookup(CYContext &context, const char *word); + CYIdentifierFlags *Lookup(CYContext &context, CYIdentifier *identifier); + + CYIdentifierFlags *Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierKind kind); + void Merge(CYContext &context, const CYIdentifierFlags *flags); + void Close(CYContext &context, CYStatement *&statements); + void Close(CYContext &context); + void Damage(); }; struct CYScript : @@ -344,12 +359,12 @@ struct CYContext { CYThisScope *this_; CYIdentifier *super_; - CYIdentifierUsageVector rename_; - CYNonLocal *nonlocal_; CYNonLocal *nextlocal_; unsigned unique_; + std::vector replace_; + CYContext(CYOptions &options) : options_(options), scope_(NULL), @@ -444,18 +459,13 @@ struct CYBlock : virtual CYStatement *Return(); }; -struct CYForInitializer { - virtual CYExpression *Replace(CYContext &context) = 0; - virtual void Output(CYOutput &out, CYFlags flags) const = 0; -}; +struct CYTarget; +struct CYVar; struct CYForInInitializer { - virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; - virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value) = 0; - - virtual CYExpression *Replace(CYContext &context) = 0; - virtual CYAssignment *Assignment(CYContext &context) = 0; + virtual CYStatement *Initialize(CYContext &context, CYExpression *value) = 0; + virtual CYTarget *Replace(CYContext &context) = 0; virtual void Output(CYOutput &out, CYFlags flags) const = 0; }; @@ -465,8 +475,6 @@ struct CYNumber; struct CYString; struct CYExpression : - CYForInitializer, - CYForInInitializer, CYThing { virtual int Precedence() const = 0; @@ -475,17 +483,17 @@ struct CYExpression : return true; } - virtual void ForIn(CYOutput &out, CYFlags flags) const; - virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value); + virtual bool Eval() const { + return false; + } - virtual CYExpression *AddArgument(CYContext &context, CYExpression *value); + virtual CYTarget *AddArgument(CYContext &context, CYExpression *value); virtual void Output(CYOutput &out) const; virtual void Output(CYOutput &out, CYFlags flags) const = 0; void Output(CYOutput &out, int precedence, CYFlags flags) const; virtual CYExpression *Replace(CYContext &context) = 0; - virtual CYAssignment *Assignment(CYContext &context); virtual CYExpression *Primitive(CYContext &context) { return NULL; @@ -506,6 +514,20 @@ struct CYExpression : } }; +struct CYTarget : + CYExpression, + CYForInInitializer +{ + virtual bool RightHand() const { + return false; + } + + virtual CYStatement *Initialize(CYContext &context, CYExpression *value); + + virtual CYTarget *Replace(CYContext &context) = 0; + using CYExpression::Output; +}; + #define CYAlphabetic(value) \ virtual bool Alphabetic() const { \ return value; \ @@ -517,11 +539,6 @@ struct CYExpression : return Precedence_; \ } -#define CYRightHand(value) \ - virtual bool RightHand() const { \ - return value; \ - } - struct CYCompound : CYExpression { @@ -545,7 +562,7 @@ struct CYCompound : }; struct CYParenthetical : - CYExpression + CYTarget { CYExpression *expression_; @@ -556,7 +573,7 @@ struct CYParenthetical : CYPrecedence(0) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); void Output(CYOutput &out, CYFlags flags) const; }; @@ -566,9 +583,9 @@ struct CYFunctionParameter : CYNext, CYThing { - CYForInInitializer *initialiser_; + CYDeclaration *initialiser_; - CYFunctionParameter(CYForInInitializer *initialiser, CYFunctionParameter *next = NULL) : + CYFunctionParameter(CYDeclaration *initialiser, CYFunctionParameter *next = NULL) : CYNext(next), initialiser_(initialiser) { @@ -651,7 +668,7 @@ struct CYIfComprehension : }; struct CYArrayComprehension : - CYExpression + CYTarget { CYExpression *expression_; CYComprehension *comprehensions_; @@ -664,15 +681,16 @@ struct CYArrayComprehension : CYPrecedence(0) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYLiteral : - CYExpression + CYTarget { + CYLocation location_; + CYPrecedence(0) - CYRightHand(false) virtual CYExpression *Primitive(CYContext &context) { return this; @@ -682,14 +700,13 @@ struct CYLiteral : struct CYTrivial : CYLiteral { - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); }; struct CYMagic : - CYExpression + CYTarget { CYPrecedence(0) - CYRightHand(false) }; struct CYRange { @@ -782,7 +799,7 @@ struct CYSpan : }; struct CYTemplate : - CYExpression + CYTarget { CYString *string_; CYSpan *spans_; @@ -794,9 +811,8 @@ struct CYTemplate : } CYPrecedence(0) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -873,13 +889,19 @@ struct CYNull : struct CYThis : CYMagic { - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYBoolean : CYTrivial { + CYPrecedence(4) + + virtual bool RightHand() const { + return true; + } + virtual bool Value() const = 0; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -907,7 +929,7 @@ struct CYTrue : }; struct CYVariable : - CYExpression + CYTarget { CYIdentifier *name_; @@ -922,9 +944,12 @@ struct CYVariable : } CYPrecedence(0) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + virtual bool Eval() const { + return strcmp(name_->Word(), "eval") == 0; + } + + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; virtual CYFunctionParameter *Parameter() const; @@ -993,17 +1018,17 @@ struct CYPostfix : struct CYAssignment : CYExpression { - CYExpression *lhs_; + CYTarget *lhs_; CYExpression *rhs_; - CYAssignment(CYExpression *lhs, CYExpression *rhs) : + CYAssignment(CYTarget *lhs, CYExpression *rhs) : lhs_(lhs), rhs_(rhs) { } - void SetLeft(CYExpression *lhs) { - lhs_ = lhs; + void SetRight(CYExpression *rhs) { + rhs_ = rhs; } virtual const char *Operator() const = 0; @@ -1112,13 +1137,11 @@ struct CYArray : { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYDeclaration : - CYForInInitializer -{ +struct CYDeclaration { CYIdentifier *identifier_; CYExpression *initialiser_; @@ -1128,14 +1151,43 @@ struct CYDeclaration : { } - virtual void ForIn(CYOutput &out, CYFlags flags) const; - virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value); + CYTarget *Target(CYContext &context); - virtual CYExpression *Replace(CYContext &context); + virtual CYAssignment *Replace(CYContext &context, CYIdentifierKind kind); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; - virtual CYAssignment *Assignment(CYContext &context); - CYVariable *Variable(CYContext &context); +struct CYForLexical : + CYForInInitializer +{ + bool constant_; + CYDeclaration *declaration_; + + CYForLexical(bool constant, CYDeclaration *declaration) : + constant_(constant), + declaration_(declaration) + { + } + + virtual CYStatement *Initialize(CYContext &context, CYExpression *value); + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYForVariable : + CYForInInitializer +{ + CYDeclaration *declaration_; + CYForVariable(CYDeclaration *declaration) : + declaration_(declaration) + { + } + + virtual CYStatement *Initialize(CYContext &context, CYExpression *value); + + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1151,9 +1203,8 @@ struct CYDeclarations : { } - void Replace(CYContext &context); + CYExpression *Replace(CYContext &context, CYIdentifierKind kind); - CYExpression *Expression(CYContext &context); CYArgument *Argument(CYContext &context); CYFunctionParameter *Parameter(CYContext &context); @@ -1161,22 +1212,8 @@ struct CYDeclarations : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYForDeclarations : - CYForInitializer -{ - CYDeclarations *declarations_; - - CYForDeclarations(CYDeclarations *declarations) : - declarations_(declarations) - { - } - - virtual CYExpression *Replace(CYContext &context); - virtual void Output(CYOutput &out, CYFlags flags) const; -}; - struct CYVar : - CYStatement + CYForInitializer { CYDeclarations *declarations_; @@ -1187,25 +1224,25 @@ struct CYVar : CYCompact(None) - virtual CYStatement *Replace(CYContext &context); + virtual CYForInitializer *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYLetStatement : - CYStatement +struct CYLet : + CYForInitializer { + bool constant_; CYDeclarations *declarations_; - CYStatement *code_; - CYLetStatement(CYDeclarations *declarations, CYStatement *code) : - declarations_(declarations), - code_(code) + CYLet(bool constant, CYDeclarations *declarations) : + constant_(constant), + declarations_(declarations) { } - CYCompact(Long) + CYCompact(None) - virtual CYStatement *Replace(CYContext &context); + virtual CYForInitializer *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1230,6 +1267,8 @@ struct CYProperty : { } + virtual bool Update() const; + CYProperty *ReplaceAll(CYContext &context, CYBuilder &builder, CYExpression *self, bool update); void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, bool protect); @@ -1297,6 +1336,26 @@ struct CYForIn : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYForInitialized : + CYStatement +{ + CYDeclaration *declaration_; + CYExpression *set_; + CYStatement *code_; + + CYForInitialized(CYDeclaration *declaration, CYExpression *set, CYStatement *code) : + declaration_(declaration), + set_(set), + code_(code) + { + } + + CYCompact(Long) + + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYForOf : CYStatement { @@ -1327,12 +1386,12 @@ struct CYObject : { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); void Output(CYOutput &out, CYFlags flags) const; }; struct CYMember : - CYExpression + CYTarget { CYExpression *object_; CYExpression *property_; @@ -1357,9 +1416,8 @@ struct CYDirectMember : } CYPrecedence(1) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1372,9 +1430,8 @@ struct CYIndirectMember : } CYPrecedence(1) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1382,7 +1439,7 @@ namespace cy { namespace Syntax { struct New : - CYExpression + CYTarget { CYExpression *constructor_; CYArgument *arguments_; @@ -1397,41 +1454,61 @@ struct New : return arguments_ == NULL ? 2 : 1; } - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; - virtual CYExpression *AddArgument(CYContext &context, CYExpression *value); + virtual CYTarget *AddArgument(CYContext &context, CYExpression *value); }; } } -struct CYCall : - CYExpression +struct CYApply : + CYTarget { - CYExpression *function_; CYArgument *arguments_; - CYCall(CYExpression *function, CYArgument *arguments = NULL) : - function_(function), + CYApply(CYArgument *arguments = NULL) : arguments_(arguments) { } CYPrecedence(1) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *AddArgument(CYContext &context, CYExpression *value); +}; + +struct CYCall : + CYApply +{ + CYExpression *function_; + + CYCall(CYExpression *function, CYArgument *arguments = NULL) : + CYApply(arguments), + function_(function) + { + } + virtual void Output(CYOutput &out, CYFlags flags) const; + virtual CYTarget *Replace(CYContext &context); +}; - virtual CYExpression *AddArgument(CYContext &context, CYExpression *value); +struct CYEval : + CYApply +{ + CYEval(CYArgument *arguments) : + CYApply(arguments) + { + } + + virtual void Output(CYOutput &out, CYFlags flags) const; + virtual CYTarget *Replace(CYContext &context); }; struct CYRubyProc; struct CYRubyBlock : - CYExpression + CYTarget { CYExpression *call_; CYRubyProc *proc_; @@ -1443,12 +1520,11 @@ struct CYRubyBlock : } CYPrecedence(1) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; - virtual CYExpression *AddArgument(CYContext &context, CYExpression *value); + virtual CYTarget *AddArgument(CYContext &context, CYExpression *value); }; struct CYIf : @@ -1533,7 +1609,7 @@ struct CYFunction { struct CYFunctionExpression : CYFunction, - CYExpression + CYTarget { CYIdentifier *name_; @@ -1544,9 +1620,8 @@ struct CYFunctionExpression : } CYPrecedence(0) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + CYTarget *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1560,15 +1635,14 @@ struct CYFatArrow : } CYPrecedence(0) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + CYExpression *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYRubyProc : CYFunction, - CYExpression + CYTarget { CYRubyProc(CYFunctionParameter *parameters, CYStatement *code) : CYFunction(parameters, code) @@ -1576,9 +1650,8 @@ struct CYRubyProc : } CYPrecedence(0) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + CYTarget *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1596,7 +1669,7 @@ struct CYFunctionStatement : CYCompact(None) - virtual CYStatement *Replace(CYContext &context); + CYStatement *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1650,6 +1723,8 @@ struct CYPropertyMethod : { } + bool Update() const override; + virtual CYFunctionExpression *Constructor(); virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect); @@ -1675,7 +1750,7 @@ struct CYClassTail : }; struct CYClassExpression : - CYExpression + CYTarget { CYIdentifier *name_; CYClassTail *tail_; @@ -1687,9 +1762,8 @@ struct CYClassExpression : } CYPrecedence(0) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + CYTarget *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1707,12 +1781,12 @@ struct CYClassStatement : CYCompact(Long) - virtual CYStatement *Replace(CYContext &context); + CYStatement *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYSuperCall : - CYExpression + CYTarget { CYArgument *arguments_; @@ -1722,14 +1796,13 @@ struct CYSuperCall : } CYPrecedence(2) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + CYTarget *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYSuperAccess : - CYExpression + CYTarget { CYExpression *property_; @@ -1739,14 +1812,13 @@ struct CYSuperAccess : } CYPrecedence(1) - CYRightHand(false) - virtual CYExpression *Replace(CYContext &context); + CYTarget *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYExpress : - CYStatement + CYForInitializer { CYExpression *expression_; @@ -1759,7 +1831,7 @@ struct CYExpress : CYCompact(None) - virtual CYStatement *Replace(CYContext &context); + CYForInitializer *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; virtual CYStatement *Return(); @@ -1777,7 +1849,7 @@ struct CYContinue : CYCompact(Short) - virtual CYStatement *Replace(CYContext &context); + CYStatement *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1793,7 +1865,7 @@ struct CYBreak : CYCompact(Short) - virtual CYStatement *Replace(CYContext &context); + CYStatement *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1809,7 +1881,7 @@ struct CYReturn : CYCompact(None) - virtual CYStatement *Replace(CYContext &context); + CYStatement *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1825,7 +1897,7 @@ struct CYYieldGenerator : CYPrecedence(0) - virtual CYExpression *Replace(CYContext &context); + CYExpression *Replace(CYContext &context) override; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1846,11 +1918,11 @@ struct CYYieldValue : }; struct CYEmpty : - CYStatement + CYForInitializer { CYCompact(Short) - virtual CYStatement *Replace(CYContext &context); + virtual CYForInitializer *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1871,7 +1943,7 @@ struct CYFinally : struct CYTypeSpecifier : CYThing { - virtual CYExpression *Replace(CYContext &context) = 0; + virtual CYTarget *Replace(CYContext &context) = 0; }; struct CYTypeError : @@ -1880,7 +1952,7 @@ struct CYTypeError : CYTypeError() { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; @@ -1890,7 +1962,7 @@ struct CYTypeVoid : CYTypeVoid() { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; @@ -1909,7 +1981,7 @@ struct CYTypeVariable : { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; @@ -1923,7 +1995,7 @@ struct CYTypeUnsigned : { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; @@ -1937,7 +2009,7 @@ struct CYTypeSigned : { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; @@ -1951,7 +2023,7 @@ struct CYTypeLong : { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; @@ -1965,7 +2037,7 @@ struct CYTypeShort : { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; @@ -1981,8 +2053,8 @@ struct CYTypeModifier : virtual int Precedence() const = 0; - virtual CYExpression *Replace_(CYContext &context, CYExpression *type) = 0; - CYExpression *Replace(CYContext &context, CYExpression *type); + 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; @@ -2003,7 +2075,7 @@ struct CYTypeArrayOf : CYPrecedence(1) - virtual CYExpression *Replace_(CYContext &context, CYExpression *type); + virtual CYTarget *Replace_(CYContext &context, CYTarget *type); virtual void Output(CYOutput &out, CYIdentifier *identifier) const; }; @@ -2017,7 +2089,7 @@ struct CYTypeConstant : CYPrecedence(0) - virtual CYExpression *Replace_(CYContext &context, CYExpression *type); + virtual CYTarget *Replace_(CYContext &context, CYTarget *type); virtual void Output(CYOutput &out, CYIdentifier *identifier) const; }; @@ -2031,7 +2103,7 @@ struct CYTypePointerTo : CYPrecedence(0) - virtual CYExpression *Replace_(CYContext &context, CYExpression *type); + virtual CYTarget *Replace_(CYContext &context, CYTarget *type); virtual void Output(CYOutput &out, CYIdentifier *identifier) const; }; @@ -2045,7 +2117,7 @@ struct CYTypeVolatile : CYPrecedence(0) - virtual CYExpression *Replace_(CYContext &context, CYExpression *type); + virtual CYTarget *Replace_(CYContext &context, CYTarget *type); virtual void Output(CYOutput &out, CYIdentifier *identifier) const; }; @@ -2078,14 +2150,14 @@ struct CYTypedIdentifier : return this; } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; CYTypeFunctionWith *Function(); }; struct CYEncodedType : - CYExpression + CYTarget { CYTypedIdentifier *typed_; @@ -2096,7 +2168,7 @@ struct CYEncodedType : CYPrecedence(1) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -2120,7 +2192,7 @@ struct CYTypedParameter : }; struct CYLambda : - CYExpression + CYTarget { CYTypedIdentifier *typed_; CYTypedParameter *parameters_; @@ -2135,7 +2207,7 @@ struct CYLambda : CYPrecedence(1) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -2218,7 +2290,7 @@ struct CYTypeBlockWith : CYPrecedence(0) - virtual CYExpression *Replace_(CYContext &context, CYExpression *type); + virtual CYTarget *Replace_(CYContext &context, CYTarget *type); virtual void Output(CYOutput &out, CYIdentifier *identifier) const; }; @@ -2235,7 +2307,7 @@ struct CYTypeFunctionWith : CYPrecedence(1) - virtual CYExpression *Replace_(CYContext &context, CYExpression *type); + virtual CYTarget *Replace_(CYContext &context, CYTarget *type); virtual void Output(CYOutput &out, CYIdentifier *identifier) const; virtual CYTypeFunctionWith *Function() { return this; } @@ -2385,20 +2457,20 @@ struct CYAddressOf : }; struct CYIndirect : - CYPrefix + CYTarget { + CYExpression *rhs_; + CYIndirect(CYExpression *rhs) : - CYPrefix(rhs) + rhs_(rhs) { } - virtual const char *Operator() const { - return "*"; - } - - CYAlphabetic(false) + // XXX: this should be checked + CYPrecedence(2) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; }; #define CYReplace \ @@ -2455,7 +2527,7 @@ struct CYIndirect : struct CY ## name ## Assign : \ CYAssignment \ { args \ - CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \ + CY ## name ## Assign(CYTarget *lhs, CYExpression *rhs) : \ CYAssignment(lhs, rhs) \ { \ } \