X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/0559abf83c4cc9bbd896b69dfaae1e8422521479..b0e6429c745211a7fa3036f22a74e85ae227af2b:/Syntax.hpp diff --git a/Syntax.hpp b/Syntax.hpp index 5599f7e..f16b877 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 {{{ */ @@ -150,6 +150,7 @@ enum CYFlags { CYNoRightHand = (1 << 5), CYNoDangle = (1 << 6), CYNoInteger = (1 << 7), + CYNoColon = (1 << 8), CYNoBFC = (CYNoBrace | CYNoFunction | CYNoClass), }; @@ -534,6 +535,10 @@ struct CYTarget : return false; } + virtual bool IsNew() const { + return false; + } + virtual CYStatement *Initialize(CYContext &context, CYExpression *value); virtual CYTarget *Replace(CYContext &context) = 0; @@ -962,6 +967,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 { @@ -1089,21 +1110,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 = NULL) : - CYNext(next), + CYElement(next), value_(value) { } @@ -1121,7 +1147,8 @@ struct CYElementSpread : { CYExpression *value_; - CYElementSpread(CYExpression *value) : + CYElementSpread(CYExpression *value, CYElement *next = NULL) : + CYElement(next), value_(value) { } @@ -1393,6 +1420,8 @@ struct CYObject : { } + CYTarget *Replace(CYContext &context, CYTarget *seed); + virtual CYTarget *Replace(CYContext &context); void Output(CYOutput &out, CYFlags flags) const; }; @@ -1442,6 +1471,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 { @@ -1461,6 +1518,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; @@ -1514,26 +1574,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 { @@ -1983,6 +2072,20 @@ struct CYTypeCharacter : virtual void Output(CYOutput &out) const; }; +struct CYTypeInt128 : + CYTypeSpecifier +{ + CYTypeSigning signing_; + + CYTypeInt128(CYTypeSigning signing) : + signing_(signing) + { + } + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out) const; +}; + struct CYTypeIntegral : CYTypeSpecifier { @@ -2086,7 +2189,7 @@ struct CYTypeModifier : CYTarget *Replace(CYContext &context, CYTarget *type); virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0; - void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const; + void Output(CYOutput &out, int precedence, CYIdentifier *identifier, bool space) const; virtual CYTypeFunctionWith *Function() { return NULL; } }; @@ -2207,7 +2310,7 @@ struct CYTypedParameter : { CYTypedIdentifier *typed_; - CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) : + CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next = NULL) : CYNext(next), typed_(typed) { @@ -2220,6 +2323,17 @@ struct CYTypedParameter : virtual void Output(CYOutput &out) const; }; +struct CYTypedFormal { + bool variadic_; + CYTypedParameter *parameters_; + + CYTypedFormal(bool variadic) : + variadic_(variadic), + parameters_(NULL) + { + } +}; + struct CYLambda : CYTarget { @@ -2305,13 +2419,31 @@ struct CYImportDeclaration : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYExternal : +struct CYExternalExpression : + CYTarget +{ + CYString *abi_; + CYTypedIdentifier *typed_; + + CYExternalExpression(CYString *abi, CYTypedIdentifier *typed) : + abi_(abi), + typed_(typed) + { + } + + CYPrecedence(0) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYExternalDefinition : CYStatement { CYString *abi_; CYTypedIdentifier *typed_; - CYExternal(CYString *abi, CYTypedIdentifier *typed) : + CYExternalDefinition(CYString *abi, CYTypedIdentifier *typed) : abi_(abi), typed_(typed) { @@ -2375,10 +2507,12 @@ struct CYTypeBlockWith : 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) { }