X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/3fe283c53edc2a98d0164d893a4a667245da8e78..511f56b025a791a6f62910bdd2fe01caaaf917c2:/Parser.hpp diff --git a/Parser.hpp b/Parser.hpp index d9530df..63270a1 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -1,21 +1,21 @@ /* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2013 Jay Freeman (saurik) + * Copyright (C) 2009-2014 Jay Freeman (saurik) */ -/* GNU General Public License, Version 3 {{{ */ +/* GNU Affero General Public License, Version 3 {{{ */ /* - * Cycript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * Cycript is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Cycript. If not, see . + * GNU Affero General Public License for more details. + + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . **/ /* }}} */ @@ -460,27 +460,6 @@ struct CYBlock : virtual void Output(CYOutput &out, CYFlags flags) const; }; -class CYStream : - public std::istream -{ - private: - class CYBuffer : - public std::streambuf - { - public: - CYBuffer(const char *start, const char *end) { - setg(const_cast(start), const_cast(start), const_cast(end)); - } - } buffer_; - - public: - CYStream(const char *start, const char *end) : - std::istream(&buffer_), - buffer_(start, end) - { - } -}; - struct CYForInitialiser { virtual ~CYForInitialiser() { } @@ -506,7 +485,6 @@ struct CYNumber; struct CYString; struct CYExpression : - CYNext, CYForInitialiser, CYForInInitialiser, CYClassName, @@ -534,7 +512,7 @@ struct CYExpression : virtual CYAssignment *Assignment(CYContext &context); virtual CYExpression *Primitive(CYContext &context) { - return this; + return NULL; } virtual CYNumber *Number(CYContext &context) { @@ -569,16 +547,16 @@ struct CYExpression : struct CYCompound : CYExpression { - CYExpression *expressions_; + CYExpression *expression_; + CYExpression *next_; - CYCompound(CYExpression *expressions = NULL) : - expressions_(expressions) + CYCompound(CYExpression *expression, CYExpression *next = NULL) : + expression_(expression), + next_(next) { - } - - void AddPrev(CYExpression *expression) { - CYSetLast(expression) = expressions_; - expressions_ = expression; + if (expression_ == NULL) + throw; + _assert(expression_ != NULL); } CYPrecedence(17) @@ -716,6 +694,10 @@ struct CYLiteral : { CYPrecedence(0) CYRightHand(false) + + virtual CYExpression *Primitive(CYContext &context) { + return this; + } }; struct CYTrivial : @@ -1535,7 +1517,7 @@ struct CYExpress : CYExpress(CYExpression *expression) : expression_(expression) { - if (expression == NULL) + if (expression_ == NULL) throw; } @@ -1612,6 +1594,16 @@ struct CYTypeSpecifier : virtual CYExpression *Replace(CYContext &context) = 0; }; +struct CYTypeError : + CYTypeSpecifier +{ + CYTypeError() { + } + + virtual CYExpression *Replace(CYContext &context); + virtual void Output(CYOutput &out) const; +}; + struct CYTypeVoid : CYTypeSpecifier { @@ -1859,6 +1851,52 @@ struct CYLambda : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYModule : + CYNext, + CYThing +{ + CYWord *part_; + + CYModule(CYWord *part, CYModule *next = NULL) : + CYNext(next), + part_(part) + { + } + + CYString *Replace(CYContext &context, const char *separator) const; + void Output(CYOutput &out) const; +}; + +struct CYImport : + CYStatement +{ + CYModule *module_; + + CYImport(CYModule *module) : + module_(module) + { + } + + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYExternal : + CYStatement +{ + CYString *abi_; + CYTypedIdentifier *typed_; + + CYExternal(CYString *abi, CYTypedIdentifier *typed) : + abi_(abi), + typed_(typed) + { + } + + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYTypeDefinition : CYStatement {