X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/e56c24995a0c0ffaed5b6769a2bead83ced2de03..a06663061c35a475ef947bf228512f8df92e36f0:/Syntax.hpp diff --git a/Syntax.hpp b/Syntax.hpp index fa27dd4..a3dad90 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 {{{ */ @@ -40,7 +40,14 @@ double CYCastDouble(const char *value); double CYCastDouble(CYUTF8String value); void CYNumerify(std::ostringstream &str, double value); -void CYStringify(std::ostringstream &str, const char *data, size_t size, bool c = false); + +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); @@ -120,6 +127,8 @@ struct CYOutput { struct CYExpression; struct CYAssignment; +struct CYIdentifier; +struct CYNumber; struct CYPropertyName { virtual bool Computed() const { @@ -130,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; }; @@ -271,6 +288,10 @@ struct CYIdentifier : { } + CYIdentifier *Identifier() override { + return this; + } + virtual const char *Word() const; CYIdentifier *Replace(CYContext &context, CYIdentifierKind); }; @@ -780,6 +801,7 @@ struct CYString : return value_; } + virtual CYIdentifier *Identifier() const; virtual const char *Word() const; virtual CYNumber *Number(CYContext &context); @@ -824,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; }; @@ -2072,6 +2096,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 { @@ -2126,12 +2164,19 @@ struct CYTypeVoid : virtual void Output(CYOutput &out) const; }; +enum CYTypeReferenceKind { + CYTypeReferenceStruct, + CYTypeReferenceEnum, +}; + struct CYTypeReference : CYTypeSpecifier { + CYTypeReferenceKind kind_; CYIdentifier *name_; - CYTypeReference(CYIdentifier *name) : + CYTypeReference(CYTypeReferenceKind kind, CYIdentifier *name) : + kind_(kind), name_(name) { } @@ -2174,8 +2219,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; } }; @@ -2194,7 +2239,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 : @@ -2208,7 +2253,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 : @@ -2222,7 +2267,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 : @@ -2236,50 +2281,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) { } @@ -2294,11 +2352,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) { } @@ -2323,11 +2383,11 @@ struct CYTypedFormal { 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) @@ -2405,15 +2465,37 @@ struct CYImportDeclaration : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYExternal : +struct CYExternalExpression : + CYTarget +{ + CYString *abi_; + CYType *type_; + CYPropertyName *name_; + + CYExternalExpression(CYString *abi, CYType *type, CYPropertyName *name) : + abi_(abi), + type_(type), + name_(name) + { + } + + CYPrecedence(0) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYExternalDefinition : CYStatement { CYString *abi_; - CYTypedIdentifier *typed_; + CYType *type_; + CYIdentifier *name_; - CYExternal(CYString *abi, CYTypedIdentifier *typed) : + CYExternalDefinition(CYString *abi, CYType *type, CYIdentifier *name) : abi_(abi), - typed_(typed) + type_(type), + name_(name) { } @@ -2426,9 +2508,9 @@ struct CYExternal : struct CYTypeExpression : CYTarget { - CYTypedIdentifier *typed_; + CYType *typed_; - CYTypeExpression(CYTypedIdentifier *typed) : + CYTypeExpression(CYType *typed) : typed_(typed) { } @@ -2442,10 +2524,12 @@ struct CYTypeExpression : struct CYTypeDefinition : CYStatement { - CYTypedIdentifier *typed_; + CYType *type_; + CYIdentifier *name_; - CYTypeDefinition(CYTypedIdentifier *typed) : - typed_(typed) + CYTypeDefinition(CYType *type, CYIdentifier *name) : + type_(type), + name_(name) { } @@ -2469,7 +2553,7 @@ 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 : @@ -2488,7 +2572,7 @@ 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; } }; @@ -2496,11 +2580,13 @@ struct CYTypeFunctionWith : struct CYTypeStructField : CYNext { - CYTypedIdentifier *typed_; + CYType *type_; + CYPropertyName *name_; - CYTypeStructField(CYTypedIdentifier *typed, CYTypeStructField *next = NULL) : + CYTypeStructField(CYType *type, CYPropertyName *name, CYTypeStructField *next = NULL) : CYNext(next), - typed_(typed) + type_(type), + name_(name) { } }; @@ -2553,6 +2639,38 @@ struct CYStructDefinition : 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 {