X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/fa389b0ff91fdcf932a5ea1c6d5d34edea583d03..d15b59f5d4f43d12719c5ce37518246058b405c6:/Parser.hpp diff --git a/Parser.hpp b/Parser.hpp index ec50ef9..2dc89ce 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -1,4 +1,4 @@ -/* Cycript - Remove Execution Server and Disassembler +/* Cycript - Error.hppution Server and Disassembler * Copyright (C) 2009 Jay Freeman (saurik) */ @@ -280,6 +280,10 @@ struct CYBlock : { } + operator CYStatement *() const { + return statements_; + } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out) const; @@ -306,8 +310,9 @@ class CYDriver { bool strict_; enum Condition { - RegExStart, - RegExRest + RegExpCondition, + XMLContentCondition, + XMLTagCondition, }; std::string filename_; @@ -331,8 +336,12 @@ class CYDriver { CYDriver(const std::string &filename); ~CYDriver(); + Condition GetCondition(); void SetCondition(Condition condition); + void PushCondition(Condition condition); + void PopCondition(); + void Warning(const cy::location &location, const char *message); }; @@ -343,10 +352,12 @@ struct CYForInitialiser { struct CYForInInitialiser { virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; virtual const char *ForEachIn() const = 0; - virtual void ForEachIn(CYOutput &out) const = 0; virtual CYExpression *ForEachIn(CYContext &out) = 0; }; +struct CYNumber; +struct CYString; + struct CYExpression : CYNext, CYForInitialiser, @@ -364,7 +375,6 @@ struct CYExpression : virtual void ForIn(CYOutput &out, CYFlags flags) const; virtual const char *ForEachIn() const; - virtual void ForEachIn(CYOutput &out) const; virtual CYExpression *ForEachIn(CYContext &out); virtual void Output(CYOutput &out) const; @@ -378,6 +388,18 @@ struct CYExpression : virtual CYExpression *Replace(CYContext &context) = 0; + virtual CYExpression *Primitive(CYContext &context) { + return this; + } + + virtual CYNumber *Number(CYContext &context) { + return NULL; + } + + virtual CYString *String(CYContext &context) { + return NULL; + } + virtual const char *Word() const { return NULL; } @@ -441,17 +463,12 @@ struct CYComprehension : CYNext, CYThing { - void Output(CYOutput &out) const; virtual const char *Name() const = 0; - virtual void Begin_(CYOutput &out) const = 0; - - virtual void End_(CYOutput &out) const { - } - virtual CYFunctionParameter *Parameter(CYContext &context) const = 0; CYFunctionParameter *Parameters(CYContext &context) const; virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; + virtual void Output(CYOutput &out) const = 0; }; struct CYForInComprehension : @@ -470,10 +487,9 @@ struct CYForInComprehension : return name_->Value(); } - virtual void Begin_(CYOutput &out) const; - virtual CYFunctionParameter *Parameter(CYContext &context) const; virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; + virtual void Output(CYOutput &out) const; }; struct CYForEachInComprehension : @@ -492,11 +508,9 @@ struct CYForEachInComprehension : return name_->Value(); } - virtual void Begin_(CYOutput &out) const; - virtual void End_(CYOutput &out) const; - virtual CYFunctionParameter *Parameter(CYContext &context) const; virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; + virtual void Output(CYOutput &out) const; }; struct CYIfComprehension : @@ -513,10 +527,9 @@ struct CYIfComprehension : return NULL; } - virtual void Begin_(CYOutput &out) const; - virtual CYFunctionParameter *Parameter(CYContext &context) const; virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; + virtual void Output(CYOutput &out) const; }; struct CYArrayComprehension : @@ -618,6 +631,10 @@ struct CYString : virtual const char *Word() const; + virtual CYNumber *Number(CYContext &context); + virtual CYString *String(CYContext &context); + + virtual CYString *Concat(CYContext &out, CYString *rhs) const; virtual void Output(CYOutput &out, CYFlags flags) const; virtual void PropertyName(CYOutput &out) const; }; @@ -637,6 +654,9 @@ struct CYNumber : return value_; } + virtual CYNumber *Number(CYContext &context); + virtual CYString *String(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; virtual void PropertyName(CYOutput &out) const; }; @@ -667,6 +687,9 @@ struct CYNull : { } + virtual CYNumber *Number(CYContext &context); + virtual CYString *String(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -702,6 +725,9 @@ struct CYFalse : virtual bool Value() const { return false; } + + virtual CYNumber *Number(CYContext &context); + virtual CYString *String(CYContext &context); }; struct CYTrue : @@ -716,6 +742,9 @@ struct CYTrue : virtual bool Value() const { return true; } + + virtual CYNumber *Number(CYContext &context); + virtual CYString *String(CYContext &context); }; struct CYVariable : @@ -915,7 +944,6 @@ struct CYDeclaration : virtual void ForIn(CYOutput &out, CYFlags flags) const; virtual const char *ForEachIn() const; - virtual void ForEachIn(CYOutput &out) const; virtual CYExpression *ForEachIn(CYContext &out); void Replace(CYContext &context); @@ -930,7 +958,7 @@ struct CYDeclarations : { CYDeclaration *declaration_; - CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) : + CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) : CYNext(next), declaration_(declaration) { @@ -1062,22 +1090,6 @@ struct CYObject : void Output(CYOutput &out, CYFlags flags) const; }; -struct CYCatch : - CYThing -{ - CYIdentifier *name_; - CYBlock code_; - - CYCatch(CYIdentifier *name, CYStatement *statements) : - name_(name), - code_(statements) - { - } - - void Replace(CYContext &context); - virtual void Output(CYOutput &out) const; -}; - struct CYMember : CYExpression { @@ -1340,14 +1352,33 @@ struct CYFinally : virtual void Output(CYOutput &out) const; }; -struct CYTry : +namespace cy { +namespace Syntax { + +struct Catch : + CYThing +{ + CYIdentifier *name_; + CYBlock code_; + + Catch(CYIdentifier *name, CYStatement *statements) : + name_(name), + code_(statements) + { + } + + void Replace(CYContext &context); + virtual void Output(CYOutput &out) const; +}; + +struct Try : CYStatement { CYBlock code_; - CYCatch *catch_; + Catch *catch_; CYFinally *finally_; - CYTry(CYStatement *statements, CYCatch *_catch, CYFinally *finally) : + Try(CYStatement *statements, Catch *_catch, CYFinally *finally) : code_(statements), catch_(_catch), finally_(finally) @@ -1358,12 +1389,12 @@ struct CYTry : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYThrow : +struct Throw : CYStatement { CYExpression *value_; - CYThrow(CYExpression *value) : + Throw(CYExpression *value) : value_(value) { } @@ -1372,6 +1403,8 @@ struct CYThrow : virtual void Output(CYOutput &out, CYFlags flags) const; }; +} } + struct CYWith : CYStatement { @@ -1450,7 +1483,7 @@ struct CYIndirect : } virtual const char *Operator() const { - return "*"; + return "^"; } CYAlphabetic(false) @@ -1458,10 +1491,13 @@ struct CYIndirect : virtual CYExpression *Replace(CYContext &context); }; -#define CYPostfix_(op, name) \ +#define CYReplace \ + virtual CYExpression *Replace(CYContext &context); + +#define CYPostfix_(op, name, args...) \ struct CY ## name : \ CYPostfix \ - { \ + { args \ CY ## name(CYExpression *lhs) : \ CYPostfix(lhs) \ { \ @@ -1472,10 +1508,10 @@ struct CYIndirect : } \ }; -#define CYPrefix_(alphabetic, op, name) \ +#define CYPrefix_(alphabetic, op, name, args...) \ struct CY ## name : \ CYPrefix \ - { \ + { args \ CY ## name(CYExpression *rhs) : \ CYPrefix(rhs) \ { \ @@ -1488,10 +1524,10 @@ struct CYIndirect : } \ }; -#define CYInfix_(alphabetic, precedence, op, name) \ +#define CYInfix_(alphabetic, precedence, op, name, args...) \ struct CY ## name : \ CYInfix \ - { \ + { args \ CY ## name(CYExpression *lhs, CYExpression *rhs) : \ CYInfix(lhs, rhs) \ { \ @@ -1505,10 +1541,10 @@ struct CYIndirect : } \ }; -#define CYAssignment_(op, name) \ +#define CYAssignment_(op, name, args...) \ struct CY ## name ## Assign : \ CYAssignment \ - { \ + { args \ CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \ CYAssignment(lhs, rhs) \ { \ @@ -1535,7 +1571,7 @@ CYPrefix_(false, "!", LogicalNot) CYInfix_(false, 5, "*", Multiply) CYInfix_(false, 5, "/", Divide) CYInfix_(false, 5, "%", Modulus) -CYInfix_(false, 6, "+", Add) +CYInfix_(false, 6, "+", Add, CYReplace) CYInfix_(false, 6, "-", Subtract) CYInfix_(false, 7, "<<", ShiftLeft) CYInfix_(false, 7, ">>", ShiftRightSigned)