kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_AST_H_ |
| 29 | #define V8_AST_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "execution.h" |
| 33 | #include "factory.h" |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 34 | #include "jsregexp.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | #include "runtime.h" |
| 36 | #include "token.h" |
| 37 | #include "variables.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 39 | namespace v8 { |
| 40 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | |
| 42 | // The abstract syntax tree is an intermediate, light-weight |
| 43 | // representation of the parsed JavaScript code suitable for |
| 44 | // compilation to native code. |
| 45 | |
| 46 | // Nodes are allocated in a separate zone, which allows faster |
| 47 | // allocation and constant-time deallocation of the entire syntax |
| 48 | // tree. |
| 49 | |
| 50 | |
| 51 | // ---------------------------------------------------------------------------- |
| 52 | // Nodes of the abstract syntax tree. Only concrete classes are |
| 53 | // enumerated here. |
| 54 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 55 | #define STATEMENT_NODE_LIST(V) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 56 | V(Block) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | V(ExpressionStatement) \ |
| 58 | V(EmptyStatement) \ |
| 59 | V(IfStatement) \ |
| 60 | V(ContinueStatement) \ |
| 61 | V(BreakStatement) \ |
| 62 | V(ReturnStatement) \ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 63 | V(EnterWithContextStatement) \ |
| 64 | V(ExitContextStatement) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | V(SwitchStatement) \ |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 66 | V(DoWhileStatement) \ |
| 67 | V(WhileStatement) \ |
| 68 | V(ForStatement) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 69 | V(ForInStatement) \ |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 70 | V(TryCatchStatement) \ |
| 71 | V(TryFinallyStatement) \ |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 72 | V(DebuggerStatement) |
| 73 | |
| 74 | #define EXPRESSION_NODE_LIST(V) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 75 | V(FunctionLiteral) \ |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 76 | V(SharedFunctionInfoLiteral) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 77 | V(Conditional) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | V(VariableProxy) \ |
| 79 | V(Literal) \ |
| 80 | V(RegExpLiteral) \ |
| 81 | V(ObjectLiteral) \ |
| 82 | V(ArrayLiteral) \ |
| 83 | V(Assignment) \ |
| 84 | V(Throw) \ |
| 85 | V(Property) \ |
| 86 | V(Call) \ |
| 87 | V(CallNew) \ |
| 88 | V(CallRuntime) \ |
| 89 | V(UnaryOperation) \ |
| 90 | V(CountOperation) \ |
| 91 | V(BinaryOperation) \ |
| 92 | V(CompareOperation) \ |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 93 | V(CompareToNull) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | V(ThisFunction) |
| 95 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 96 | #define AST_NODE_LIST(V) \ |
| 97 | V(Declaration) \ |
| 98 | STATEMENT_NODE_LIST(V) \ |
| 99 | EXPRESSION_NODE_LIST(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 100 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 101 | // Forward declarations |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 102 | class BitVector; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 103 | class DefinitionInfo; |
| 104 | class MaterializedLiteral; |
| 105 | class TargetCollector; |
| 106 | class TypeFeedbackOracle; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 107 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 108 | #define DEF_FORWARD_DECLARATION(type) class type; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 109 | AST_NODE_LIST(DEF_FORWARD_DECLARATION) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | #undef DEF_FORWARD_DECLARATION |
| 111 | |
| 112 | |
| 113 | // Typedef only introduced to avoid unreadable code. |
| 114 | // Please do appreciate the required space in "> >". |
| 115 | typedef ZoneList<Handle<String> > ZoneStringList; |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 116 | typedef ZoneList<Handle<Object> > ZoneObjectList; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | |
| 118 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 119 | #define DECLARE_NODE_TYPE(type) \ |
| 120 | virtual void Accept(AstVisitor* v); \ |
| 121 | virtual AstNode::Type node_type() const { return AstNode::k##type; } \ |
| 122 | virtual type* As##type() { return this; } |
| 123 | |
| 124 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 125 | class AstNode: public ZoneObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | public: |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 127 | #define DECLARE_TYPE_ENUM(type) k##type, |
| 128 | enum Type { |
| 129 | AST_NODE_LIST(DECLARE_TYPE_ENUM) |
| 130 | kInvalid = -1 |
| 131 | }; |
| 132 | #undef DECLARE_TYPE_ENUM |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 134 | static const int kNoNumber = -1; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 135 | static const int kFunctionEntryId = 2; // Using 0 could disguise errors. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 136 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 137 | // Override ZoneObject's new to count allocated AST nodes. |
| 138 | void* operator new(size_t size, Zone* zone) { |
| 139 | Isolate* isolate = zone->isolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 140 | isolate->set_ast_node_count(isolate->ast_node_count() + 1); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 141 | return zone->New(static_cast<int>(size)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 142 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 143 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 144 | AstNode() {} |
| 145 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 146 | virtual ~AstNode() { } |
| 147 | |
| 148 | virtual void Accept(AstVisitor* v) = 0; |
| 149 | virtual Type node_type() const { return kInvalid; } |
| 150 | |
| 151 | // Type testing & conversion functions overridden by concrete subclasses. |
| 152 | #define DECLARE_NODE_FUNCTIONS(type) \ |
| 153 | virtual type* As##type() { return NULL; } |
| 154 | AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 155 | #undef DECLARE_NODE_FUNCTIONS |
| 156 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 157 | virtual Statement* AsStatement() { return NULL; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 158 | virtual Expression* AsExpression() { return NULL; } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 159 | virtual TargetCollector* AsTargetCollector() { return NULL; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 160 | virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
| 161 | virtual IterationStatement* AsIterationStatement() { return NULL; } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 162 | virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 163 | virtual Slot* AsSlot() { return NULL; } |
| 164 | |
| 165 | // True if the node is simple enough for us to inline calls containing it. |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 166 | virtual bool IsInlineable() const = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 167 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 168 | static int Count() { return Isolate::Current()->ast_node_count(); } |
| 169 | static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 170 | |
| 171 | protected: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 172 | static unsigned GetNextId(Isolate* isolate) { |
| 173 | return ReserveIdRange(isolate, 1); |
| 174 | } |
| 175 | |
| 176 | static unsigned ReserveIdRange(Isolate* isolate, int n) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 177 | unsigned tmp = isolate->ast_node_id(); |
| 178 | isolate->set_ast_node_id(tmp + n); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 179 | return tmp; |
| 180 | } |
| 181 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 182 | private: |
| 183 | // Hidden to prevent accidental usage. It would have to load the |
| 184 | // current zone from the TLS. |
| 185 | void* operator new(size_t size); |
| 186 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 187 | friend class CaseClause; // Generates AST IDs. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | |
| 191 | class Statement: public AstNode { |
| 192 | public: |
| 193 | Statement() : statement_pos_(RelocInfo::kNoPosition) {} |
| 194 | |
| 195 | virtual Statement* AsStatement() { return this; } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 196 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 197 | virtual Assignment* StatementAsSimpleAssignment() { return NULL; } |
| 198 | virtual CountOperation* StatementAsCountOperation() { return NULL; } |
| 199 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 200 | bool IsEmpty() { return AsEmptyStatement() != NULL; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 201 | |
| 202 | void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } |
| 203 | int statement_pos() const { return statement_pos_; } |
| 204 | |
| 205 | private: |
| 206 | int statement_pos_; |
| 207 | }; |
| 208 | |
| 209 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 210 | class Expression: public AstNode { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 211 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 212 | enum Context { |
| 213 | // Not assigned a context yet, or else will not be visited during |
| 214 | // code generation. |
| 215 | kUninitialized, |
| 216 | // Evaluated for its side effects. |
| 217 | kEffect, |
| 218 | // Evaluated for its value (and side effects). |
| 219 | kValue, |
| 220 | // Evaluated for control flow (and side effects). |
| 221 | kTest |
| 222 | }; |
| 223 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 224 | explicit Expression(Isolate* isolate) |
| 225 | : id_(GetNextId(isolate)), |
| 226 | test_id_(GetNextId(isolate)) {} |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 227 | |
| 228 | virtual int position() const { |
| 229 | UNREACHABLE(); |
| 230 | return 0; |
| 231 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 232 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | virtual Expression* AsExpression() { return this; } |
| 234 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 235 | virtual bool IsTrivial() { return false; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 236 | virtual bool IsValidLeftHandSide() { return false; } |
| 237 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 238 | // Helpers for ToBoolean conversion. |
| 239 | virtual bool ToBooleanIsTrue() { return false; } |
| 240 | virtual bool ToBooleanIsFalse() { return false; } |
| 241 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 242 | // Symbols that cannot be parsed as array indices are considered property |
| 243 | // names. We do not treat symbols that can be array indexes as property |
| 244 | // names because [] for string objects is handled only by keyed ICs. |
| 245 | virtual bool IsPropertyName() { return false; } |
| 246 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | // Mark the expression as being compiled as an expression |
| 248 | // statement. This is used to transform postfix increments to |
| 249 | // (faster) prefix increments. |
| 250 | virtual void MarkAsStatement() { /* do nothing */ } |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 251 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 252 | // True iff the result can be safely overwritten (to avoid allocation). |
| 253 | // False for operations that can return one of their operands. |
| 254 | virtual bool ResultOverwriteAllowed() { return false; } |
| 255 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 256 | // True iff the expression is a literal represented as a smi. |
| 257 | virtual bool IsSmiLiteral() { return false; } |
| 258 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 259 | // Type feedback information for assignments and properties. |
| 260 | virtual bool IsMonomorphic() { |
| 261 | UNREACHABLE(); |
| 262 | return false; |
| 263 | } |
| 264 | virtual bool IsArrayLength() { |
| 265 | UNREACHABLE(); |
| 266 | return false; |
| 267 | } |
| 268 | virtual ZoneMapList* GetReceiverTypes() { |
| 269 | UNREACHABLE(); |
| 270 | return NULL; |
| 271 | } |
| 272 | virtual Handle<Map> GetMonomorphicReceiverType() { |
| 273 | UNREACHABLE(); |
| 274 | return Handle<Map>(); |
| 275 | } |
| 276 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 277 | unsigned id() const { return id_; } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 278 | unsigned test_id() const { return test_id_; } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 279 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 280 | private: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 281 | unsigned id_; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 282 | unsigned test_id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | |
| 286 | /** |
| 287 | * A sentinel used during pre parsing that represents some expression |
| 288 | * that is a valid left hand side without having to actually build |
| 289 | * the expression. |
| 290 | */ |
| 291 | class ValidLeftHandSideSentinel: public Expression { |
| 292 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 293 | explicit ValidLeftHandSideSentinel(Isolate* isolate) : Expression(isolate) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 294 | virtual bool IsValidLeftHandSide() { return true; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 295 | virtual void Accept(AstVisitor* v) { UNREACHABLE(); } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 296 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | |
| 300 | class BreakableStatement: public Statement { |
| 301 | public: |
| 302 | enum Type { |
| 303 | TARGET_FOR_ANONYMOUS, |
| 304 | TARGET_FOR_NAMED_ONLY |
| 305 | }; |
| 306 | |
| 307 | // The labels associated with this statement. May be NULL; |
| 308 | // if it is != NULL, guaranteed to contain at least one entry. |
| 309 | ZoneStringList* labels() const { return labels_; } |
| 310 | |
| 311 | // Type testing & conversion. |
| 312 | virtual BreakableStatement* AsBreakableStatement() { return this; } |
| 313 | |
| 314 | // Code generation |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 315 | Label* break_target() { return &break_target_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | |
| 317 | // Testers. |
| 318 | bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } |
| 319 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 320 | // Bailout support. |
| 321 | int EntryId() const { return entry_id_; } |
| 322 | int ExitId() const { return exit_id_; } |
| 323 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 324 | protected: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 325 | BreakableStatement(Isolate* isolate, ZoneStringList* labels, Type type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 326 | |
| 327 | private: |
| 328 | ZoneStringList* labels_; |
| 329 | Type type_; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 330 | Label break_target_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 331 | int entry_id_; |
| 332 | int exit_id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | |
| 336 | class Block: public BreakableStatement { |
| 337 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 338 | inline Block(Isolate* isolate, |
| 339 | ZoneStringList* labels, |
| 340 | int capacity, |
| 341 | bool is_initializer_block); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 342 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 343 | DECLARE_NODE_TYPE(Block) |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 344 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 345 | virtual Assignment* StatementAsSimpleAssignment() { |
| 346 | if (statements_.length() != 1) return NULL; |
| 347 | return statements_[0]->StatementAsSimpleAssignment(); |
| 348 | } |
| 349 | |
| 350 | virtual CountOperation* StatementAsCountOperation() { |
| 351 | if (statements_.length() != 1) return NULL; |
| 352 | return statements_[0]->StatementAsCountOperation(); |
| 353 | } |
| 354 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 355 | virtual bool IsInlineable() const; |
| 356 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 357 | void AddStatement(Statement* statement) { statements_.Add(statement); } |
| 358 | |
| 359 | ZoneList<Statement*>* statements() { return &statements_; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 360 | bool is_initializer_block() const { return is_initializer_block_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 361 | |
| 362 | private: |
| 363 | ZoneList<Statement*> statements_; |
| 364 | bool is_initializer_block_; |
| 365 | }; |
| 366 | |
| 367 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 368 | class Declaration: public AstNode { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 369 | public: |
| 370 | Declaration(VariableProxy* proxy, Variable::Mode mode, FunctionLiteral* fun) |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 371 | : proxy_(proxy), |
| 372 | mode_(mode), |
| 373 | fun_(fun) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 374 | ASSERT(mode == Variable::VAR || mode == Variable::CONST); |
| 375 | // At the moment there are no "const functions"'s in JavaScript... |
| 376 | ASSERT(fun == NULL || mode == Variable::VAR); |
| 377 | } |
| 378 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 379 | DECLARE_NODE_TYPE(Declaration) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 380 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 381 | VariableProxy* proxy() const { return proxy_; } |
| 382 | Variable::Mode mode() const { return mode_; } |
| 383 | FunctionLiteral* fun() const { return fun_; } // may be NULL |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 384 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 385 | |
| 386 | private: |
| 387 | VariableProxy* proxy_; |
| 388 | Variable::Mode mode_; |
| 389 | FunctionLiteral* fun_; |
| 390 | }; |
| 391 | |
| 392 | |
| 393 | class IterationStatement: public BreakableStatement { |
| 394 | public: |
| 395 | // Type testing & conversion. |
| 396 | virtual IterationStatement* AsIterationStatement() { return this; } |
| 397 | |
| 398 | Statement* body() const { return body_; } |
| 399 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 400 | // Bailout support. |
| 401 | int OsrEntryId() const { return osr_entry_id_; } |
| 402 | virtual int ContinueId() const = 0; |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 403 | virtual int StackCheckId() const = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 404 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 405 | // Code generation |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 406 | Label* continue_target() { return &continue_target_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 407 | |
| 408 | protected: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 409 | inline IterationStatement(Isolate* isolate, ZoneStringList* labels); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 410 | |
| 411 | void Initialize(Statement* body) { |
| 412 | body_ = body; |
| 413 | } |
| 414 | |
| 415 | private: |
| 416 | Statement* body_; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 417 | Label continue_target_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 418 | int osr_entry_id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 419 | }; |
| 420 | |
| 421 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 422 | class DoWhileStatement: public IterationStatement { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 423 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 424 | inline DoWhileStatement(Isolate* isolate, ZoneStringList* labels); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 426 | DECLARE_NODE_TYPE(DoWhileStatement) |
| 427 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 428 | void Initialize(Expression* cond, Statement* body) { |
| 429 | IterationStatement::Initialize(body); |
| 430 | cond_ = cond; |
| 431 | } |
| 432 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 433 | Expression* cond() const { return cond_; } |
| 434 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 435 | // Position where condition expression starts. We need it to make |
| 436 | // the loop's condition a breakable location. |
| 437 | int condition_position() { return condition_position_; } |
| 438 | void set_condition_position(int pos) { condition_position_ = pos; } |
| 439 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 440 | // Bailout support. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 441 | virtual int ContinueId() const { return continue_id_; } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 442 | virtual int StackCheckId() const { return back_edge_id_; } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 443 | int BackEdgeId() const { return back_edge_id_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 444 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 445 | virtual bool IsInlineable() const; |
| 446 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 447 | private: |
| 448 | Expression* cond_; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 449 | int condition_position_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 450 | int continue_id_; |
| 451 | int back_edge_id_; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 452 | }; |
| 453 | |
| 454 | |
| 455 | class WhileStatement: public IterationStatement { |
| 456 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 457 | inline WhileStatement(Isolate* isolate, ZoneStringList* labels); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 458 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 459 | DECLARE_NODE_TYPE(WhileStatement) |
| 460 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 461 | void Initialize(Expression* cond, Statement* body) { |
| 462 | IterationStatement::Initialize(body); |
| 463 | cond_ = cond; |
| 464 | } |
| 465 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 466 | Expression* cond() const { return cond_; } |
| 467 | bool may_have_function_literal() const { |
| 468 | return may_have_function_literal_; |
| 469 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 470 | void set_may_have_function_literal(bool value) { |
| 471 | may_have_function_literal_ = value; |
| 472 | } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 473 | virtual bool IsInlineable() const; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 474 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 475 | // Bailout support. |
| 476 | virtual int ContinueId() const { return EntryId(); } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 477 | virtual int StackCheckId() const { return body_id_; } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 478 | int BodyId() const { return body_id_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 479 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 480 | private: |
| 481 | Expression* cond_; |
| 482 | // True if there is a function literal subexpression in the condition. |
| 483 | bool may_have_function_literal_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 484 | int body_id_; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 485 | }; |
| 486 | |
| 487 | |
| 488 | class ForStatement: public IterationStatement { |
| 489 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 490 | inline ForStatement(Isolate* isolate, ZoneStringList* labels); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 491 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 492 | DECLARE_NODE_TYPE(ForStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 493 | |
| 494 | void Initialize(Statement* init, |
| 495 | Expression* cond, |
| 496 | Statement* next, |
| 497 | Statement* body) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 498 | IterationStatement::Initialize(body); |
| 499 | init_ = init; |
| 500 | cond_ = cond; |
| 501 | next_ = next; |
| 502 | } |
| 503 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 504 | Statement* init() const { return init_; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 505 | Expression* cond() const { return cond_; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 506 | Statement* next() const { return next_; } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 507 | |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 508 | bool may_have_function_literal() const { |
| 509 | return may_have_function_literal_; |
| 510 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 511 | void set_may_have_function_literal(bool value) { |
| 512 | may_have_function_literal_ = value; |
| 513 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 514 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 515 | // Bailout support. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 516 | virtual int ContinueId() const { return continue_id_; } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 517 | virtual int StackCheckId() const { return body_id_; } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 518 | int BodyId() const { return body_id_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 519 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 520 | bool is_fast_smi_loop() { return loop_variable_ != NULL; } |
| 521 | Variable* loop_variable() { return loop_variable_; } |
| 522 | void set_loop_variable(Variable* var) { loop_variable_ = var; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 523 | virtual bool IsInlineable() const; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 524 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | Statement* init_; |
| 527 | Expression* cond_; |
| 528 | Statement* next_; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 529 | // True if there is a function literal subexpression in the condition. |
kasperl@chromium.org | f5aa837 | 2009-03-24 14:47:14 +0000 | [diff] [blame] | 530 | bool may_have_function_literal_; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 531 | Variable* loop_variable_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 532 | int continue_id_; |
| 533 | int body_id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 534 | }; |
| 535 | |
| 536 | |
| 537 | class ForInStatement: public IterationStatement { |
| 538 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 539 | inline ForInStatement(Isolate* isolate, ZoneStringList* labels); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 541 | DECLARE_NODE_TYPE(ForInStatement) |
| 542 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | void Initialize(Expression* each, Expression* enumerable, Statement* body) { |
| 544 | IterationStatement::Initialize(body); |
| 545 | each_ = each; |
| 546 | enumerable_ = enumerable; |
| 547 | } |
| 548 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 549 | Expression* each() const { return each_; } |
| 550 | Expression* enumerable() const { return enumerable_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 551 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 552 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 553 | // Bailout support. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 554 | int AssignmentId() const { return assignment_id_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 555 | virtual int ContinueId() const { return EntryId(); } |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 556 | virtual int StackCheckId() const { return EntryId(); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 557 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 558 | private: |
| 559 | Expression* each_; |
| 560 | Expression* enumerable_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 561 | int assignment_id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | }; |
| 563 | |
| 564 | |
| 565 | class ExpressionStatement: public Statement { |
| 566 | public: |
| 567 | explicit ExpressionStatement(Expression* expression) |
| 568 | : expression_(expression) { } |
| 569 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 570 | DECLARE_NODE_TYPE(ExpressionStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 571 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 572 | virtual bool IsInlineable() const; |
| 573 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 574 | virtual Assignment* StatementAsSimpleAssignment(); |
| 575 | virtual CountOperation* StatementAsCountOperation(); |
| 576 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 577 | void set_expression(Expression* e) { expression_ = e; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 578 | Expression* expression() const { return expression_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 579 | |
| 580 | private: |
| 581 | Expression* expression_; |
| 582 | }; |
| 583 | |
| 584 | |
| 585 | class ContinueStatement: public Statement { |
| 586 | public: |
| 587 | explicit ContinueStatement(IterationStatement* target) |
| 588 | : target_(target) { } |
| 589 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 590 | DECLARE_NODE_TYPE(ContinueStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 591 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 592 | IterationStatement* target() const { return target_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 593 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 594 | |
| 595 | private: |
| 596 | IterationStatement* target_; |
| 597 | }; |
| 598 | |
| 599 | |
| 600 | class BreakStatement: public Statement { |
| 601 | public: |
| 602 | explicit BreakStatement(BreakableStatement* target) |
| 603 | : target_(target) { } |
| 604 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 605 | DECLARE_NODE_TYPE(BreakStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 606 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 607 | BreakableStatement* target() const { return target_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 608 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 609 | |
| 610 | private: |
| 611 | BreakableStatement* target_; |
| 612 | }; |
| 613 | |
| 614 | |
| 615 | class ReturnStatement: public Statement { |
| 616 | public: |
| 617 | explicit ReturnStatement(Expression* expression) |
| 618 | : expression_(expression) { } |
| 619 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 620 | DECLARE_NODE_TYPE(ReturnStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 621 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 622 | Expression* expression() const { return expression_; } |
| 623 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 624 | |
| 625 | private: |
| 626 | Expression* expression_; |
| 627 | }; |
| 628 | |
| 629 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 630 | class EnterWithContextStatement: public Statement { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 631 | public: |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 632 | explicit EnterWithContextStatement(Expression* expression) |
| 633 | : expression_(expression) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 634 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 635 | DECLARE_NODE_TYPE(EnterWithContextStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 637 | Expression* expression() const { return expression_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 638 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 639 | virtual bool IsInlineable() const; |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 640 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 641 | private: |
| 642 | Expression* expression_; |
| 643 | }; |
| 644 | |
| 645 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 646 | class ExitContextStatement: public Statement { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 647 | public: |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 648 | virtual bool IsInlineable() const; |
| 649 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 650 | DECLARE_NODE_TYPE(ExitContextStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 651 | }; |
| 652 | |
| 653 | |
| 654 | class CaseClause: public ZoneObject { |
| 655 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 656 | CaseClause(Isolate* isolate, |
| 657 | Expression* label, |
| 658 | ZoneList<Statement*>* statements, |
| 659 | int pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 660 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 661 | bool is_default() const { return label_ == NULL; } |
| 662 | Expression* label() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 663 | CHECK(!is_default()); |
| 664 | return label_; |
| 665 | } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 666 | Label* body_target() { return &body_target_; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 667 | ZoneList<Statement*>* statements() const { return statements_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 668 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 669 | int position() const { return position_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 670 | void set_position(int pos) { position_ = pos; } |
| 671 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 672 | int EntryId() { return entry_id_; } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 673 | int CompareId() { return compare_id_; } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 674 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 675 | // Type feedback information. |
| 676 | void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| 677 | bool IsSmiCompare() { return compare_type_ == SMI_ONLY; } |
| 678 | bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; } |
| 679 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 680 | private: |
| 681 | Expression* label_; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 682 | Label body_target_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 683 | ZoneList<Statement*>* statements_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 684 | int position_; |
| 685 | enum CompareTypeFeedback { NONE, SMI_ONLY, OBJECT_ONLY }; |
| 686 | CompareTypeFeedback compare_type_; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 687 | int compare_id_; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 688 | int entry_id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 689 | }; |
| 690 | |
| 691 | |
| 692 | class SwitchStatement: public BreakableStatement { |
| 693 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 694 | inline SwitchStatement(Isolate* isolate, ZoneStringList* labels); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 695 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 696 | DECLARE_NODE_TYPE(SwitchStatement) |
| 697 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 698 | void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { |
| 699 | tag_ = tag; |
| 700 | cases_ = cases; |
| 701 | } |
| 702 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 703 | Expression* tag() const { return tag_; } |
| 704 | ZoneList<CaseClause*>* cases() const { return cases_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 705 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 706 | |
| 707 | private: |
| 708 | Expression* tag_; |
| 709 | ZoneList<CaseClause*>* cases_; |
| 710 | }; |
| 711 | |
| 712 | |
| 713 | // If-statements always have non-null references to their then- and |
| 714 | // else-parts. When parsing if-statements with no explicit else-part, |
| 715 | // the parser implicitly creates an empty statement. Use the |
| 716 | // HasThenStatement() and HasElseStatement() functions to check if a |
| 717 | // given if-statement has a then- or an else-part containing code. |
| 718 | class IfStatement: public Statement { |
| 719 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 720 | IfStatement(Isolate* isolate, |
| 721 | Expression* condition, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 722 | Statement* then_statement, |
| 723 | Statement* else_statement) |
| 724 | : condition_(condition), |
| 725 | then_statement_(then_statement), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 726 | else_statement_(else_statement), |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 727 | if_id_(GetNextId(isolate)), |
| 728 | then_id_(GetNextId(isolate)), |
| 729 | else_id_(GetNextId(isolate)) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 730 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 731 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 732 | DECLARE_NODE_TYPE(IfStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 733 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 734 | virtual bool IsInlineable() const; |
| 735 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 736 | bool HasThenStatement() const { return !then_statement()->IsEmpty(); } |
| 737 | bool HasElseStatement() const { return !else_statement()->IsEmpty(); } |
| 738 | |
| 739 | Expression* condition() const { return condition_; } |
| 740 | Statement* then_statement() const { return then_statement_; } |
| 741 | Statement* else_statement() const { return else_statement_; } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 742 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 743 | int IfId() const { return if_id_; } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 744 | int ThenId() const { return then_id_; } |
| 745 | int ElseId() const { return else_id_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 746 | |
| 747 | private: |
| 748 | Expression* condition_; |
| 749 | Statement* then_statement_; |
| 750 | Statement* else_statement_; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 751 | int if_id_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 752 | int then_id_; |
| 753 | int else_id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 754 | }; |
| 755 | |
| 756 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 757 | // NOTE: TargetCollectors are represented as nodes to fit in the target |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 758 | // stack in the compiler; this should probably be reworked. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 759 | class TargetCollector: public AstNode { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 760 | public: |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 761 | TargetCollector(): targets_(0) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 762 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 763 | // Adds a jump target to the collector. The collector stores a pointer not |
| 764 | // a copy of the target to make binding work, so make sure not to pass in |
| 765 | // references to something on the stack. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 766 | void AddTarget(Label* target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 767 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 768 | // Virtual behaviour. TargetCollectors are never part of the AST. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 769 | virtual void Accept(AstVisitor* v) { UNREACHABLE(); } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 770 | virtual TargetCollector* AsTargetCollector() { return this; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 771 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 772 | ZoneList<Label*>* targets() { return &targets_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 773 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 774 | |
| 775 | private: |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 776 | ZoneList<Label*> targets_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 777 | }; |
| 778 | |
| 779 | |
| 780 | class TryStatement: public Statement { |
| 781 | public: |
| 782 | explicit TryStatement(Block* try_block) |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 783 | : try_block_(try_block), escaping_targets_(NULL) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 784 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 785 | void set_escaping_targets(ZoneList<Label*>* targets) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 786 | escaping_targets_ = targets; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | Block* try_block() const { return try_block_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 790 | ZoneList<Label*>* escaping_targets() const { return escaping_targets_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 791 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 792 | |
| 793 | private: |
| 794 | Block* try_block_; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 795 | ZoneList<Label*>* escaping_targets_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 796 | }; |
| 797 | |
| 798 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 799 | class TryCatchStatement: public TryStatement { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 800 | public: |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 801 | TryCatchStatement(Block* try_block, |
| 802 | Scope* scope, |
| 803 | Variable* variable, |
| 804 | Block* catch_block) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 805 | : TryStatement(try_block), |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 806 | scope_(scope), |
| 807 | variable_(variable), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 808 | catch_block_(catch_block) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 809 | } |
| 810 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 811 | DECLARE_NODE_TYPE(TryCatchStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 812 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 813 | Scope* scope() { return scope_; } |
| 814 | Variable* variable() { return variable_; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 815 | Block* catch_block() const { return catch_block_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 816 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 817 | |
| 818 | private: |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 819 | Scope* scope_; |
| 820 | Variable* variable_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 821 | Block* catch_block_; |
| 822 | }; |
| 823 | |
| 824 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 825 | class TryFinallyStatement: public TryStatement { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 826 | public: |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 827 | TryFinallyStatement(Block* try_block, Block* finally_block) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 828 | : TryStatement(try_block), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 829 | finally_block_(finally_block) { } |
| 830 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 831 | DECLARE_NODE_TYPE(TryFinallyStatement) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 832 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 833 | Block* finally_block() const { return finally_block_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 834 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 835 | |
| 836 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 837 | Block* finally_block_; |
| 838 | }; |
| 839 | |
| 840 | |
| 841 | class DebuggerStatement: public Statement { |
| 842 | public: |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 843 | DECLARE_NODE_TYPE(DebuggerStatement) |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 844 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 845 | }; |
| 846 | |
| 847 | |
| 848 | class EmptyStatement: public Statement { |
| 849 | public: |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 850 | DECLARE_NODE_TYPE(EmptyStatement) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 851 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 852 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 853 | }; |
| 854 | |
| 855 | |
| 856 | class Literal: public Expression { |
| 857 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 858 | Literal(Isolate* isolate, Handle<Object> handle) |
| 859 | : Expression(isolate), handle_(handle) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 860 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 861 | DECLARE_NODE_TYPE(Literal) |
| 862 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 863 | virtual bool IsTrivial() { return true; } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 864 | virtual bool IsSmiLiteral() { return handle_->IsSmi(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 865 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 866 | // Check if this literal is identical to the other literal. |
| 867 | bool IsIdenticalTo(const Literal* other) const { |
| 868 | return handle_.is_identical_to(other->handle_); |
| 869 | } |
| 870 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 871 | virtual bool IsPropertyName() { |
| 872 | if (handle_->IsSymbol()) { |
| 873 | uint32_t ignored; |
| 874 | return !String::cast(*handle_)->AsArrayIndex(&ignored); |
| 875 | } |
| 876 | return false; |
| 877 | } |
| 878 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 879 | Handle<String> AsPropertyName() { |
| 880 | ASSERT(IsPropertyName()); |
| 881 | return Handle<String>::cast(handle_); |
| 882 | } |
| 883 | |
| 884 | virtual bool ToBooleanIsTrue() { return handle_->ToBoolean()->IsTrue(); } |
| 885 | virtual bool ToBooleanIsFalse() { return handle_->ToBoolean()->IsFalse(); } |
| 886 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 887 | // Identity testers. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 888 | bool IsNull() const { |
| 889 | ASSERT(!handle_.is_null()); |
| 890 | return handle_->IsNull(); |
| 891 | } |
| 892 | bool IsTrue() const { |
| 893 | ASSERT(!handle_.is_null()); |
| 894 | return handle_->IsTrue(); |
| 895 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 896 | bool IsFalse() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 897 | ASSERT(!handle_.is_null()); |
| 898 | return handle_->IsFalse(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | Handle<Object> handle() const { return handle_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 902 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 903 | |
| 904 | private: |
| 905 | Handle<Object> handle_; |
| 906 | }; |
| 907 | |
| 908 | |
| 909 | // Base class for literals that needs space in the corresponding JSFunction. |
| 910 | class MaterializedLiteral: public Expression { |
| 911 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 912 | MaterializedLiteral(Isolate* isolate, |
| 913 | int literal_index, |
| 914 | bool is_simple, |
| 915 | int depth) |
| 916 | : Expression(isolate), |
| 917 | literal_index_(literal_index), |
| 918 | is_simple_(is_simple), |
| 919 | depth_(depth) {} |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 920 | |
| 921 | virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } |
| 922 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 923 | int literal_index() { return literal_index_; } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 924 | |
| 925 | // A materialized literal is simple if the values consist of only |
| 926 | // constants and simple object and array literals. |
| 927 | bool is_simple() const { return is_simple_; } |
| 928 | |
| 929 | int depth() const { return depth_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 930 | virtual bool IsInlineable() const; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 931 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 932 | private: |
| 933 | int literal_index_; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 934 | bool is_simple_; |
| 935 | int depth_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 936 | }; |
| 937 | |
| 938 | |
| 939 | // An object literal has a boilerplate object that is used |
| 940 | // for minimizing the work when constructing it at runtime. |
| 941 | class ObjectLiteral: public MaterializedLiteral { |
| 942 | public: |
| 943 | // Property is used for passing information |
| 944 | // about an object literal's properties from the parser |
| 945 | // to the code generator. |
| 946 | class Property: public ZoneObject { |
| 947 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 948 | enum Kind { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 949 | CONSTANT, // Property with constant value (compile time). |
| 950 | COMPUTED, // Property with computed value (execution time). |
| 951 | MATERIALIZED_LITERAL, // Property value is a materialized literal. |
| 952 | GETTER, SETTER, // Property is an accessor function. |
| 953 | PROTOTYPE // Property is __proto__. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 954 | }; |
| 955 | |
| 956 | Property(Literal* key, Expression* value); |
| 957 | Property(bool is_getter, FunctionLiteral* value); |
| 958 | |
| 959 | Literal* key() { return key_; } |
| 960 | Expression* value() { return value_; } |
| 961 | Kind kind() { return kind_; } |
| 962 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 963 | bool IsCompileTimeValue(); |
| 964 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 965 | void set_emit_store(bool emit_store); |
| 966 | bool emit_store(); |
| 967 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 968 | private: |
| 969 | Literal* key_; |
| 970 | Expression* value_; |
| 971 | Kind kind_; |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 972 | bool emit_store_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 973 | }; |
| 974 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 975 | ObjectLiteral(Isolate* isolate, |
| 976 | Handle<FixedArray> constant_properties, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 977 | ZoneList<Property*>* properties, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 978 | int literal_index, |
| 979 | bool is_simple, |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 980 | bool fast_elements, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 981 | int depth, |
| 982 | bool has_function) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 983 | : MaterializedLiteral(isolate, literal_index, is_simple, depth), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 984 | constant_properties_(constant_properties), |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 985 | properties_(properties), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 986 | fast_elements_(fast_elements), |
| 987 | has_function_(has_function) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 988 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 989 | DECLARE_NODE_TYPE(ObjectLiteral) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | |
| 991 | Handle<FixedArray> constant_properties() const { |
| 992 | return constant_properties_; |
| 993 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 994 | ZoneList<Property*>* properties() const { return properties_; } |
| 995 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 996 | bool fast_elements() const { return fast_elements_; } |
| 997 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 998 | bool has_function() { return has_function_; } |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 999 | |
| 1000 | // Mark all computed expressions that are bound to a key that |
| 1001 | // is shadowed by a later occurrence of the same key. For the |
| 1002 | // marked expressions, no store code is emitted. |
| 1003 | void CalculateEmitStore(); |
| 1004 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1005 | enum Flags { |
| 1006 | kNoFlags = 0, |
| 1007 | kFastElements = 1, |
| 1008 | kHasFunction = 1 << 1 |
| 1009 | }; |
| 1010 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1011 | private: |
| 1012 | Handle<FixedArray> constant_properties_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1013 | ZoneList<Property*>* properties_; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1014 | bool fast_elements_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1015 | bool has_function_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1016 | }; |
| 1017 | |
| 1018 | |
| 1019 | // Node for capturing a regexp literal. |
| 1020 | class RegExpLiteral: public MaterializedLiteral { |
| 1021 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1022 | RegExpLiteral(Isolate* isolate, |
| 1023 | Handle<String> pattern, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1024 | Handle<String> flags, |
| 1025 | int literal_index) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1026 | : MaterializedLiteral(isolate, literal_index, false, 1), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1027 | pattern_(pattern), |
| 1028 | flags_(flags) {} |
| 1029 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1030 | DECLARE_NODE_TYPE(RegExpLiteral) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1031 | |
| 1032 | Handle<String> pattern() const { return pattern_; } |
| 1033 | Handle<String> flags() const { return flags_; } |
| 1034 | |
| 1035 | private: |
| 1036 | Handle<String> pattern_; |
| 1037 | Handle<String> flags_; |
| 1038 | }; |
| 1039 | |
| 1040 | // An array literal has a literals object that is used |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1041 | // for minimizing the work when constructing it at runtime. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1042 | class ArrayLiteral: public MaterializedLiteral { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1043 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1044 | ArrayLiteral(Isolate* isolate, |
| 1045 | Handle<FixedArray> constant_elements, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1046 | ZoneList<Expression*>* values, |
| 1047 | int literal_index, |
| 1048 | bool is_simple, |
| 1049 | int depth) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1050 | : MaterializedLiteral(isolate, literal_index, is_simple, depth), |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1051 | constant_elements_(constant_elements), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1052 | values_(values), |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1053 | first_element_id_(ReserveIdRange(isolate, values->length())) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1054 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1055 | DECLARE_NODE_TYPE(ArrayLiteral) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1057 | Handle<FixedArray> constant_elements() const { return constant_elements_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1058 | ZoneList<Expression*>* values() const { return values_; } |
| 1059 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1060 | // Return an AST id for an element that is used in simulate instructions. |
| 1061 | int GetIdForElement(int i) { return first_element_id_ + i; } |
| 1062 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1063 | private: |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1064 | Handle<FixedArray> constant_elements_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1065 | ZoneList<Expression*>* values_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1066 | int first_element_id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1067 | }; |
| 1068 | |
| 1069 | |
| 1070 | class VariableProxy: public Expression { |
| 1071 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1072 | VariableProxy(Isolate* isolate, Variable* var); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1073 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1074 | DECLARE_NODE_TYPE(VariableProxy) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1075 | |
| 1076 | // Type testing & conversion |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1077 | Variable* AsVariable() { return (this == NULL) ? NULL : var_; } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1078 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1079 | virtual bool IsValidLeftHandSide() { |
| 1080 | return var_ == NULL ? true : var_->IsValidLeftHandSide(); |
| 1081 | } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1082 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1083 | virtual bool IsTrivial() { |
| 1084 | // Reading from a mutable variable is a side effect, but the |
| 1085 | // variable for 'this' is immutable. |
| 1086 | return is_this_ || is_trivial_; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1089 | virtual bool IsInlineable() const; |
| 1090 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1091 | bool IsVariable(Handle<String> n) { |
| 1092 | return !is_this() && name().is_identical_to(n); |
| 1093 | } |
| 1094 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1095 | bool IsArguments() { |
| 1096 | Variable* variable = AsVariable(); |
| 1097 | return (variable == NULL) ? false : variable->is_arguments(); |
| 1098 | } |
| 1099 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1100 | Handle<String> name() const { return name_; } |
| 1101 | Variable* var() const { return var_; } |
| 1102 | bool is_this() const { return is_this_; } |
| 1103 | bool inside_with() const { return inside_with_; } |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1104 | int position() const { return position_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1105 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1106 | void MarkAsTrivial() { is_trivial_ = true; } |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1107 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1108 | // Bind this proxy to the variable var. |
| 1109 | void BindTo(Variable* var); |
| 1110 | |
| 1111 | protected: |
| 1112 | Handle<String> name_; |
| 1113 | Variable* var_; // resolved variable, or NULL |
| 1114 | bool is_this_; |
| 1115 | bool inside_with_; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1116 | bool is_trivial_; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1117 | int position_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1118 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1119 | VariableProxy(Isolate* isolate, |
| 1120 | Handle<String> name, |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1121 | bool is_this, |
| 1122 | bool inside_with, |
| 1123 | int position = RelocInfo::kNoPosition); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1124 | VariableProxy(Isolate* isolate, bool is_this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1125 | |
| 1126 | friend class Scope; |
| 1127 | }; |
| 1128 | |
| 1129 | |
| 1130 | class VariableProxySentinel: public VariableProxy { |
| 1131 | public: |
| 1132 | virtual bool IsValidLeftHandSide() { return !is_this(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1133 | |
| 1134 | private: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1135 | VariableProxySentinel(Isolate* isolate, bool is_this) |
| 1136 | : VariableProxy(isolate, is_this) { } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1137 | |
| 1138 | friend class AstSentinels; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1139 | }; |
| 1140 | |
| 1141 | |
| 1142 | class Slot: public Expression { |
| 1143 | public: |
| 1144 | enum Type { |
| 1145 | // A slot in the parameter section on the stack. index() is |
| 1146 | // the parameter index, counting left-to-right, starting at 0. |
| 1147 | PARAMETER, |
| 1148 | |
| 1149 | // A slot in the local section on the stack. index() is |
| 1150 | // the variable index in the stack frame, starting at 0. |
| 1151 | LOCAL, |
| 1152 | |
| 1153 | // An indexed slot in a heap context. index() is the |
| 1154 | // variable index in the context object on the heap, |
| 1155 | // starting at 0. var()->scope() is the corresponding |
| 1156 | // scope. |
| 1157 | CONTEXT, |
| 1158 | |
| 1159 | // A named slot in a heap context. var()->name() is the |
| 1160 | // variable name in the context object on the heap, |
| 1161 | // with lookup starting at the current context. index() |
| 1162 | // is invalid. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1163 | LOOKUP |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1164 | }; |
| 1165 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1166 | Slot(Isolate* isolate, Variable* var, Type type, int index) |
| 1167 | : Expression(isolate), var_(var), type_(type), index_(index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1168 | ASSERT(var != NULL); |
| 1169 | } |
| 1170 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1171 | virtual void Accept(AstVisitor* v); |
| 1172 | |
| 1173 | virtual Slot* AsSlot() { return this; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1174 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1175 | bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } |
| 1176 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1177 | // Accessors |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1178 | Variable* var() const { return var_; } |
| 1179 | Type type() const { return type_; } |
| 1180 | int index() const { return index_; } |
| 1181 | bool is_arguments() const { return var_->is_arguments(); } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1182 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1183 | |
| 1184 | private: |
| 1185 | Variable* var_; |
| 1186 | Type type_; |
| 1187 | int index_; |
| 1188 | }; |
| 1189 | |
| 1190 | |
| 1191 | class Property: public Expression { |
| 1192 | public: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1193 | // Synthetic properties are property lookups introduced by the system, |
| 1194 | // to objects that aren't visible to the user. Function calls to synthetic |
| 1195 | // properties should use the global object as receiver, not the base object |
| 1196 | // of the resolved Reference. |
| 1197 | enum Type { NORMAL, SYNTHETIC }; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1198 | Property(Isolate* isolate, |
| 1199 | Expression* obj, |
| 1200 | Expression* key, |
| 1201 | int pos, |
| 1202 | Type type = NORMAL) |
| 1203 | : Expression(isolate), |
| 1204 | obj_(obj), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1205 | key_(key), |
| 1206 | pos_(pos), |
| 1207 | type_(type), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1208 | receiver_types_(NULL), |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1209 | is_monomorphic_(false), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1210 | is_array_length_(false), |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1211 | is_string_length_(false), |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1212 | is_string_access_(false), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1213 | is_function_prototype_(false) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1214 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1215 | DECLARE_NODE_TYPE(Property) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1216 | |
| 1217 | virtual bool IsValidLeftHandSide() { return true; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1218 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1219 | |
| 1220 | Expression* obj() const { return obj_; } |
| 1221 | Expression* key() const { return key_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1222 | virtual int position() const { return pos_; } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1223 | bool is_synthetic() const { return type_ == SYNTHETIC; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1224 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1225 | bool IsStringLength() const { return is_string_length_; } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1226 | bool IsStringAccess() const { return is_string_access_; } |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1227 | bool IsFunctionPrototype() const { return is_function_prototype_; } |
| 1228 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1229 | // Type feedback information. |
| 1230 | void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| 1231 | virtual bool IsMonomorphic() { return is_monomorphic_; } |
| 1232 | virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; } |
| 1233 | virtual bool IsArrayLength() { return is_array_length_; } |
| 1234 | virtual Handle<Map> GetMonomorphicReceiverType() { |
| 1235 | return monomorphic_receiver_type_; |
| 1236 | } |
| 1237 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1238 | private: |
| 1239 | Expression* obj_; |
| 1240 | Expression* key_; |
| 1241 | int pos_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1242 | Type type_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1243 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1244 | ZoneMapList* receiver_types_; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1245 | bool is_monomorphic_ : 1; |
| 1246 | bool is_array_length_ : 1; |
| 1247 | bool is_string_length_ : 1; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1248 | bool is_string_access_ : 1; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1249 | bool is_function_prototype_ : 1; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1250 | Handle<Map> monomorphic_receiver_type_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1251 | }; |
| 1252 | |
| 1253 | |
| 1254 | class Call: public Expression { |
| 1255 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1256 | Call(Isolate* isolate, |
| 1257 | Expression* expression, |
| 1258 | ZoneList<Expression*>* arguments, |
| 1259 | int pos) |
| 1260 | : Expression(isolate), |
| 1261 | expression_(expression), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1262 | arguments_(arguments), |
| 1263 | pos_(pos), |
| 1264 | is_monomorphic_(false), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1265 | check_type_(RECEIVER_MAP_CHECK), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1266 | receiver_types_(NULL), |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1267 | return_id_(GetNextId(isolate)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1268 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1269 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1270 | DECLARE_NODE_TYPE(Call) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1271 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1272 | virtual bool IsInlineable() const; |
| 1273 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1274 | Expression* expression() const { return expression_; } |
| 1275 | ZoneList<Expression*>* arguments() const { return arguments_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1276 | virtual int position() const { return pos_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1277 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1278 | void RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 1279 | CallKind call_kind); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1280 | virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; } |
| 1281 | virtual bool IsMonomorphic() { return is_monomorphic_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1282 | CheckType check_type() const { return check_type_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1283 | Handle<JSFunction> target() { return target_; } |
| 1284 | Handle<JSObject> holder() { return holder_; } |
| 1285 | Handle<JSGlobalPropertyCell> cell() { return cell_; } |
| 1286 | |
| 1287 | bool ComputeTarget(Handle<Map> type, Handle<String> name); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1288 | bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupResult* lookup); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1289 | |
| 1290 | // Bailout support. |
| 1291 | int ReturnId() const { return return_id_; } |
| 1292 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1293 | #ifdef DEBUG |
| 1294 | // Used to assert that the FullCodeGenerator records the return site. |
| 1295 | bool return_is_recorded_; |
| 1296 | #endif |
| 1297 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1298 | private: |
| 1299 | Expression* expression_; |
| 1300 | ZoneList<Expression*>* arguments_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1301 | int pos_; |
| 1302 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1303 | bool is_monomorphic_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1304 | CheckType check_type_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1305 | ZoneMapList* receiver_types_; |
| 1306 | Handle<JSFunction> target_; |
| 1307 | Handle<JSObject> holder_; |
| 1308 | Handle<JSGlobalPropertyCell> cell_; |
| 1309 | |
| 1310 | int return_id_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1311 | }; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1312 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1313 | |
| 1314 | class AstSentinels { |
| 1315 | public: |
| 1316 | ~AstSentinels() { } |
| 1317 | |
| 1318 | // Returns a property singleton property access on 'this'. Used |
| 1319 | // during preparsing. |
| 1320 | Property* this_property() { return &this_property_; } |
| 1321 | VariableProxySentinel* this_proxy() { return &this_proxy_; } |
| 1322 | VariableProxySentinel* identifier_proxy() { return &identifier_proxy_; } |
| 1323 | ValidLeftHandSideSentinel* valid_left_hand_side_sentinel() { |
| 1324 | return &valid_left_hand_side_sentinel_; |
| 1325 | } |
| 1326 | Call* call_sentinel() { return &call_sentinel_; } |
| 1327 | EmptyStatement* empty_statement() { return &empty_statement_; } |
| 1328 | |
| 1329 | private: |
| 1330 | AstSentinels(); |
| 1331 | VariableProxySentinel this_proxy_; |
| 1332 | VariableProxySentinel identifier_proxy_; |
| 1333 | ValidLeftHandSideSentinel valid_left_hand_side_sentinel_; |
| 1334 | Property this_property_; |
| 1335 | Call call_sentinel_; |
| 1336 | EmptyStatement empty_statement_; |
| 1337 | |
| 1338 | friend class Isolate; |
| 1339 | |
| 1340 | DISALLOW_COPY_AND_ASSIGN(AstSentinels); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1341 | }; |
| 1342 | |
| 1343 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1344 | class CallNew: public Expression { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1345 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1346 | CallNew(Isolate* isolate, |
| 1347 | Expression* expression, |
| 1348 | ZoneList<Expression*>* arguments, |
| 1349 | int pos) |
| 1350 | : Expression(isolate), |
| 1351 | expression_(expression), |
| 1352 | arguments_(arguments), |
| 1353 | pos_(pos) { } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1354 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1355 | DECLARE_NODE_TYPE(CallNew) |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1356 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1357 | virtual bool IsInlineable() const; |
| 1358 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1359 | Expression* expression() const { return expression_; } |
| 1360 | ZoneList<Expression*>* arguments() const { return arguments_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1361 | virtual int position() const { return pos_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1362 | |
| 1363 | private: |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1364 | Expression* expression_; |
| 1365 | ZoneList<Expression*>* arguments_; |
| 1366 | int pos_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1367 | }; |
| 1368 | |
| 1369 | |
| 1370 | // The CallRuntime class does not represent any official JavaScript |
| 1371 | // language construct. Instead it is used to call a C or JS function |
| 1372 | // with a set of arguments. This is used from the builtins that are |
| 1373 | // implemented in JavaScript (see "v8natives.js"). |
| 1374 | class CallRuntime: public Expression { |
| 1375 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1376 | CallRuntime(Isolate* isolate, |
| 1377 | Handle<String> name, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1378 | const Runtime::Function* function, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1379 | ZoneList<Expression*>* arguments) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1380 | : Expression(isolate), |
| 1381 | name_(name), |
| 1382 | function_(function), |
| 1383 | arguments_(arguments) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1384 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1385 | DECLARE_NODE_TYPE(CallRuntime) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1386 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1387 | virtual bool IsInlineable() const; |
| 1388 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1389 | Handle<String> name() const { return name_; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1390 | const Runtime::Function* function() const { return function_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1391 | ZoneList<Expression*>* arguments() const { return arguments_; } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1392 | bool is_jsruntime() const { return function_ == NULL; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1393 | |
| 1394 | private: |
| 1395 | Handle<String> name_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1396 | const Runtime::Function* function_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1397 | ZoneList<Expression*>* arguments_; |
| 1398 | }; |
| 1399 | |
| 1400 | |
| 1401 | class UnaryOperation: public Expression { |
| 1402 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1403 | UnaryOperation(Isolate* isolate, |
| 1404 | Token::Value op, |
| 1405 | Expression* expression, |
| 1406 | int pos) |
| 1407 | : Expression(isolate), op_(op), expression_(expression), pos_(pos) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1408 | ASSERT(Token::IsUnaryOp(op)); |
| 1409 | } |
| 1410 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1411 | DECLARE_NODE_TYPE(UnaryOperation) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1412 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1413 | virtual bool IsInlineable() const; |
| 1414 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1415 | virtual bool ResultOverwriteAllowed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1416 | |
| 1417 | Token::Value op() const { return op_; } |
| 1418 | Expression* expression() const { return expression_; } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1419 | virtual int position() const { return pos_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1420 | |
| 1421 | private: |
| 1422 | Token::Value op_; |
| 1423 | Expression* expression_; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1424 | int pos_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1425 | }; |
| 1426 | |
| 1427 | |
| 1428 | class BinaryOperation: public Expression { |
| 1429 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1430 | BinaryOperation(Isolate* isolate, |
| 1431 | Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1432 | Expression* left, |
| 1433 | Expression* right, |
| 1434 | int pos) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1435 | : Expression(isolate), op_(op), left_(left), right_(right), pos_(pos) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1436 | ASSERT(Token::IsBinaryOp(op)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1437 | right_id_ = (op == Token::AND || op == Token::OR) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1438 | ? static_cast<int>(GetNextId(isolate)) |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1439 | : AstNode::kNoNumber; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1442 | DECLARE_NODE_TYPE(BinaryOperation) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1443 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1444 | virtual bool IsInlineable() const; |
| 1445 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1446 | virtual bool ResultOverwriteAllowed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1447 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1448 | Token::Value op() const { return op_; } |
| 1449 | Expression* left() const { return left_; } |
| 1450 | Expression* right() const { return right_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1451 | virtual int position() const { return pos_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1452 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1453 | // Bailout support. |
| 1454 | int RightId() const { return right_id_; } |
| 1455 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1456 | private: |
| 1457 | Token::Value op_; |
| 1458 | Expression* left_; |
| 1459 | Expression* right_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1460 | int pos_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1461 | // The short-circuit logical operations have an AST ID for their |
| 1462 | // right-hand subexpression. |
| 1463 | int right_id_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1464 | }; |
| 1465 | |
| 1466 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1467 | class CountOperation: public Expression { |
| 1468 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1469 | CountOperation(Isolate* isolate, |
| 1470 | Token::Value op, |
| 1471 | bool is_prefix, |
| 1472 | Expression* expr, |
| 1473 | int pos) |
| 1474 | : Expression(isolate), |
| 1475 | op_(op), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1476 | is_prefix_(is_prefix), |
| 1477 | expression_(expr), |
| 1478 | pos_(pos), |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1479 | assignment_id_(GetNextId(isolate)), |
| 1480 | count_id_(GetNextId(isolate)), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1481 | receiver_types_(NULL) { } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1482 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1483 | DECLARE_NODE_TYPE(CountOperation) |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1484 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1485 | bool is_prefix() const { return is_prefix_; } |
| 1486 | bool is_postfix() const { return !is_prefix_; } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1487 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1488 | Token::Value op() const { return op_; } |
kasperl@chromium.org | 74e4e5e | 2010-01-25 10:15:52 +0000 | [diff] [blame] | 1489 | Token::Value binary_op() { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1490 | return (op() == Token::INC) ? Token::ADD : Token::SUB; |
kasperl@chromium.org | 74e4e5e | 2010-01-25 10:15:52 +0000 | [diff] [blame] | 1491 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1492 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1493 | Expression* expression() const { return expression_; } |
| 1494 | virtual int position() const { return pos_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1495 | |
| 1496 | virtual void MarkAsStatement() { is_prefix_ = true; } |
| 1497 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1498 | virtual bool IsInlineable() const; |
| 1499 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1500 | void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| 1501 | virtual bool IsMonomorphic() { return is_monomorphic_; } |
| 1502 | virtual Handle<Map> GetMonomorphicReceiverType() { |
| 1503 | return monomorphic_receiver_type_; |
| 1504 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1505 | virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1506 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1507 | // Bailout support. |
| 1508 | int AssignmentId() const { return assignment_id_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1509 | int CountId() const { return count_id_; } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1510 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1511 | private: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1512 | Token::Value op_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1513 | bool is_prefix_; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1514 | bool is_monomorphic_; |
| 1515 | Expression* expression_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1516 | int pos_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1517 | int assignment_id_; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1518 | int count_id_; |
| 1519 | Handle<Map> monomorphic_receiver_type_; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1520 | ZoneMapList* receiver_types_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1521 | }; |
| 1522 | |
| 1523 | |
| 1524 | class CompareOperation: public Expression { |
| 1525 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1526 | CompareOperation(Isolate* isolate, |
| 1527 | Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1528 | Expression* left, |
| 1529 | Expression* right, |
| 1530 | int pos) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1531 | : Expression(isolate), |
| 1532 | op_(op), |
| 1533 | left_(left), |
| 1534 | right_(right), |
| 1535 | pos_(pos), |
| 1536 | compare_type_(NONE) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1537 | ASSERT(Token::IsCompareOp(op)); |
| 1538 | } |
| 1539 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1540 | DECLARE_NODE_TYPE(CompareOperation) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1541 | |
| 1542 | Token::Value op() const { return op_; } |
| 1543 | Expression* left() const { return left_; } |
| 1544 | Expression* right() const { return right_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1545 | virtual int position() const { return pos_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1546 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1547 | virtual bool IsInlineable() const; |
| 1548 | |
| 1549 | // Type feedback information. |
| 1550 | void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| 1551 | bool IsSmiCompare() { return compare_type_ == SMI_ONLY; } |
| 1552 | bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; } |
| 1553 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1554 | // Match special cases. |
| 1555 | bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check); |
| 1556 | bool IsLiteralCompareUndefined(Expression** expr); |
| 1557 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1558 | private: |
| 1559 | Token::Value op_; |
| 1560 | Expression* left_; |
| 1561 | Expression* right_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1562 | int pos_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1563 | |
| 1564 | enum CompareTypeFeedback { NONE, SMI_ONLY, OBJECT_ONLY }; |
| 1565 | CompareTypeFeedback compare_type_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1566 | }; |
| 1567 | |
| 1568 | |
| 1569 | class CompareToNull: public Expression { |
| 1570 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1571 | CompareToNull(Isolate* isolate, bool is_strict, Expression* expression) |
| 1572 | : Expression(isolate), is_strict_(is_strict), expression_(expression) { } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1573 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1574 | DECLARE_NODE_TYPE(CompareToNull) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1575 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1576 | virtual bool IsInlineable() const; |
| 1577 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1578 | bool is_strict() const { return is_strict_; } |
| 1579 | Token::Value op() const { return is_strict_ ? Token::EQ_STRICT : Token::EQ; } |
| 1580 | Expression* expression() const { return expression_; } |
| 1581 | |
| 1582 | private: |
| 1583 | bool is_strict_; |
| 1584 | Expression* expression_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1585 | }; |
| 1586 | |
| 1587 | |
| 1588 | class Conditional: public Expression { |
| 1589 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1590 | Conditional(Isolate* isolate, |
| 1591 | Expression* condition, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1592 | Expression* then_expression, |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1593 | Expression* else_expression, |
| 1594 | int then_expression_position, |
| 1595 | int else_expression_position) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1596 | : Expression(isolate), |
| 1597 | condition_(condition), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1598 | then_expression_(then_expression), |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1599 | else_expression_(else_expression), |
| 1600 | then_expression_position_(then_expression_position), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1601 | else_expression_position_(else_expression_position), |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1602 | then_id_(GetNextId(isolate)), |
| 1603 | else_id_(GetNextId(isolate)) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1604 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1605 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1606 | DECLARE_NODE_TYPE(Conditional) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1607 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1608 | virtual bool IsInlineable() const; |
| 1609 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1610 | Expression* condition() const { return condition_; } |
| 1611 | Expression* then_expression() const { return then_expression_; } |
| 1612 | Expression* else_expression() const { return else_expression_; } |
| 1613 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1614 | int then_expression_position() const { return then_expression_position_; } |
| 1615 | int else_expression_position() const { return else_expression_position_; } |
| 1616 | |
| 1617 | int ThenId() const { return then_id_; } |
| 1618 | int ElseId() const { return else_id_; } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1619 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1620 | private: |
| 1621 | Expression* condition_; |
| 1622 | Expression* then_expression_; |
| 1623 | Expression* else_expression_; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1624 | int then_expression_position_; |
| 1625 | int else_expression_position_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1626 | int then_id_; |
| 1627 | int else_id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1628 | }; |
| 1629 | |
| 1630 | |
| 1631 | class Assignment: public Expression { |
| 1632 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1633 | Assignment(Isolate* isolate, |
| 1634 | Token::Value op, |
| 1635 | Expression* target, |
| 1636 | Expression* value, |
| 1637 | int pos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1638 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1639 | DECLARE_NODE_TYPE(Assignment) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1640 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1641 | virtual bool IsInlineable() const; |
| 1642 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1643 | Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } |
| 1644 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | Token::Value binary_op() const; |
| 1646 | |
| 1647 | Token::Value op() const { return op_; } |
| 1648 | Expression* target() const { return target_; } |
| 1649 | Expression* value() const { return value_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1650 | virtual int position() const { return pos_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1651 | BinaryOperation* binary_operation() const { return binary_operation_; } |
| 1652 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1653 | // This check relies on the definition order of token in token.h. |
| 1654 | bool is_compound() const { return op() > Token::ASSIGN; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1655 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1656 | // An initialization block is a series of statments of the form |
| 1657 | // x.y.z.a = ...; x.y.z.b = ...; etc. The parser marks the beginning and |
| 1658 | // ending of these blocks to allow for optimizations of initialization |
| 1659 | // blocks. |
| 1660 | bool starts_initialization_block() { return block_start_; } |
| 1661 | bool ends_initialization_block() { return block_end_; } |
| 1662 | void mark_block_start() { block_start_ = true; } |
| 1663 | void mark_block_end() { block_end_ = true; } |
| 1664 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1665 | // Type feedback information. |
| 1666 | void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| 1667 | virtual bool IsMonomorphic() { return is_monomorphic_; } |
| 1668 | virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; } |
| 1669 | virtual Handle<Map> GetMonomorphicReceiverType() { |
| 1670 | return monomorphic_receiver_type_; |
| 1671 | } |
| 1672 | |
| 1673 | // Bailout support. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1674 | int CompoundLoadId() const { return compound_load_id_; } |
| 1675 | int AssignmentId() const { return assignment_id_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1676 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1677 | private: |
| 1678 | Token::Value op_; |
| 1679 | Expression* target_; |
| 1680 | Expression* value_; |
| 1681 | int pos_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1682 | BinaryOperation* binary_operation_; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1683 | int compound_load_id_; |
| 1684 | int assignment_id_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1685 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 1686 | bool block_start_; |
| 1687 | bool block_end_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1688 | |
| 1689 | bool is_monomorphic_; |
| 1690 | ZoneMapList* receiver_types_; |
| 1691 | Handle<Map> monomorphic_receiver_type_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1692 | }; |
| 1693 | |
| 1694 | |
| 1695 | class Throw: public Expression { |
| 1696 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1697 | Throw(Isolate* isolate, Expression* exception, int pos) |
| 1698 | : Expression(isolate), exception_(exception), pos_(pos) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1699 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1700 | DECLARE_NODE_TYPE(Throw) |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1701 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1702 | Expression* exception() const { return exception_; } |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1703 | virtual int position() const { return pos_; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1704 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1705 | |
| 1706 | private: |
| 1707 | Expression* exception_; |
| 1708 | int pos_; |
| 1709 | }; |
| 1710 | |
| 1711 | |
| 1712 | class FunctionLiteral: public Expression { |
| 1713 | public: |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 1714 | enum Type { |
| 1715 | ANONYMOUS_EXPRESSION, |
| 1716 | NAMED_EXPRESSION, |
| 1717 | DECLARATION |
| 1718 | }; |
| 1719 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1720 | FunctionLiteral(Isolate* isolate, |
| 1721 | Handle<String> name, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1722 | Scope* scope, |
| 1723 | ZoneList<Statement*>* body, |
| 1724 | int materialized_literal_count, |
| 1725 | int expected_property_count, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1726 | bool has_only_simple_this_property_assignments, |
| 1727 | Handle<FixedArray> this_property_assignments, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1728 | int num_parameters, |
| 1729 | int start_position, |
| 1730 | int end_position, |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 1731 | Type type, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1732 | bool has_duplicate_parameters) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1733 | : Expression(isolate), |
| 1734 | name_(name), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1735 | scope_(scope), |
| 1736 | body_(body), |
| 1737 | materialized_literal_count_(materialized_literal_count), |
| 1738 | expected_property_count_(expected_property_count), |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1739 | has_only_simple_this_property_assignments_( |
| 1740 | has_only_simple_this_property_assignments), |
| 1741 | this_property_assignments_(this_property_assignments), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1742 | num_parameters_(num_parameters), |
| 1743 | start_position_(start_position), |
| 1744 | end_position_(end_position), |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 1745 | function_token_position_(RelocInfo::kNoPosition), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1746 | inferred_name_(HEAP->empty_string()), |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 1747 | is_expression_(type != DECLARATION), |
| 1748 | is_anonymous_(type == ANONYMOUS_EXPRESSION), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1749 | pretenure_(false), |
| 1750 | has_duplicate_parameters_(has_duplicate_parameters) { |
| 1751 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1752 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1753 | DECLARE_NODE_TYPE(FunctionLiteral) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1754 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1755 | Handle<String> name() const { return name_; } |
| 1756 | Scope* scope() const { return scope_; } |
| 1757 | ZoneList<Statement*>* body() const { return body_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1758 | void set_function_token_position(int pos) { function_token_position_ = pos; } |
| 1759 | int function_token_position() const { return function_token_position_; } |
| 1760 | int start_position() const { return start_position_; } |
| 1761 | int end_position() const { return end_position_; } |
| 1762 | bool is_expression() const { return is_expression_; } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 1763 | bool is_anonymous() const { return is_anonymous_; } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1764 | bool strict_mode() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1765 | |
| 1766 | int materialized_literal_count() { return materialized_literal_count_; } |
| 1767 | int expected_property_count() { return expected_property_count_; } |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1768 | bool has_only_simple_this_property_assignments() { |
| 1769 | return has_only_simple_this_property_assignments_; |
| 1770 | } |
| 1771 | Handle<FixedArray> this_property_assignments() { |
| 1772 | return this_property_assignments_; |
| 1773 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1774 | int num_parameters() { return num_parameters_; } |
| 1775 | |
| 1776 | bool AllowsLazyCompilation(); |
| 1777 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1778 | Handle<String> debug_name() const { |
| 1779 | if (name_->length() > 0) return name_; |
| 1780 | return inferred_name(); |
| 1781 | } |
| 1782 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1783 | Handle<String> inferred_name() const { return inferred_name_; } |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 1784 | void set_inferred_name(Handle<String> inferred_name) { |
| 1785 | inferred_name_ = inferred_name; |
| 1786 | } |
| 1787 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1788 | bool pretenure() { return pretenure_; } |
| 1789 | void set_pretenure(bool value) { pretenure_ = value; } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1790 | virtual bool IsInlineable() const; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1791 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1792 | bool has_duplicate_parameters() { return has_duplicate_parameters_; } |
| 1793 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1794 | private: |
| 1795 | Handle<String> name_; |
| 1796 | Scope* scope_; |
| 1797 | ZoneList<Statement*>* body_; |
| 1798 | int materialized_literal_count_; |
| 1799 | int expected_property_count_; |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1800 | bool has_only_simple_this_property_assignments_; |
| 1801 | Handle<FixedArray> this_property_assignments_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1802 | int num_parameters_; |
| 1803 | int start_position_; |
| 1804 | int end_position_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1805 | int function_token_position_; |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 1806 | Handle<String> inferred_name_; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1807 | bool is_expression_; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 1808 | bool is_anonymous_; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1809 | bool pretenure_; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1810 | bool has_duplicate_parameters_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1811 | }; |
| 1812 | |
| 1813 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1814 | class SharedFunctionInfoLiteral: public Expression { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1815 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1816 | SharedFunctionInfoLiteral( |
| 1817 | Isolate* isolate, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1818 | Handle<SharedFunctionInfo> shared_function_info) |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1819 | : Expression(isolate), shared_function_info_(shared_function_info) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1820 | |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1821 | DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) |
| 1822 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1823 | Handle<SharedFunctionInfo> shared_function_info() const { |
| 1824 | return shared_function_info_; |
| 1825 | } |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1826 | virtual bool IsInlineable() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1827 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1828 | private: |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1829 | Handle<SharedFunctionInfo> shared_function_info_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1830 | }; |
| 1831 | |
| 1832 | |
| 1833 | class ThisFunction: public Expression { |
| 1834 | public: |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1835 | explicit ThisFunction(Isolate* isolate) : Expression(isolate) {} |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 1836 | DECLARE_NODE_TYPE(ThisFunction) |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1837 | virtual bool IsInlineable() const; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1838 | }; |
| 1839 | |
| 1840 | |
| 1841 | // ---------------------------------------------------------------------------- |
| 1842 | // Regular expressions |
| 1843 | |
| 1844 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1845 | class RegExpVisitor BASE_EMBEDDED { |
| 1846 | public: |
| 1847 | virtual ~RegExpVisitor() { } |
| 1848 | #define MAKE_CASE(Name) \ |
| 1849 | virtual void* Visit##Name(RegExp##Name*, void* data) = 0; |
| 1850 | FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) |
| 1851 | #undef MAKE_CASE |
| 1852 | }; |
| 1853 | |
| 1854 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1855 | class RegExpTree: public ZoneObject { |
| 1856 | public: |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1857 | static const int kInfinity = kMaxInt; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1858 | virtual ~RegExpTree() { } |
| 1859 | virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; |
| 1860 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1861 | RegExpNode* on_success) = 0; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1862 | virtual bool IsTextElement() { return false; } |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1863 | virtual bool IsAnchoredAtStart() { return false; } |
| 1864 | virtual bool IsAnchoredAtEnd() { return false; } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1865 | virtual int min_match() = 0; |
| 1866 | virtual int max_match() = 0; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1867 | // Returns the interval of registers used for captures within this |
| 1868 | // expression. |
| 1869 | virtual Interval CaptureRegisters() { return Interval::Empty(); } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1870 | virtual void AppendToText(RegExpText* text); |
| 1871 | SmartPointer<const char> ToString(); |
| 1872 | #define MAKE_ASTYPE(Name) \ |
| 1873 | virtual RegExp##Name* As##Name(); \ |
| 1874 | virtual bool Is##Name(); |
| 1875 | FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE) |
| 1876 | #undef MAKE_ASTYPE |
| 1877 | }; |
| 1878 | |
| 1879 | |
| 1880 | class RegExpDisjunction: public RegExpTree { |
| 1881 | public: |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1882 | explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1883 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1884 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1885 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1886 | virtual RegExpDisjunction* AsDisjunction(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1887 | virtual Interval CaptureRegisters(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1888 | virtual bool IsDisjunction(); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1889 | virtual bool IsAnchoredAtStart(); |
| 1890 | virtual bool IsAnchoredAtEnd(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1891 | virtual int min_match() { return min_match_; } |
| 1892 | virtual int max_match() { return max_match_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1893 | ZoneList<RegExpTree*>* alternatives() { return alternatives_; } |
| 1894 | private: |
| 1895 | ZoneList<RegExpTree*>* alternatives_; |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1896 | int min_match_; |
| 1897 | int max_match_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1898 | }; |
| 1899 | |
| 1900 | |
| 1901 | class RegExpAlternative: public RegExpTree { |
| 1902 | public: |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1903 | explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1904 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1905 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1906 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1907 | virtual RegExpAlternative* AsAlternative(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1908 | virtual Interval CaptureRegisters(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1909 | virtual bool IsAlternative(); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1910 | virtual bool IsAnchoredAtStart(); |
| 1911 | virtual bool IsAnchoredAtEnd(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1912 | virtual int min_match() { return min_match_; } |
| 1913 | virtual int max_match() { return max_match_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1914 | ZoneList<RegExpTree*>* nodes() { return nodes_; } |
| 1915 | private: |
| 1916 | ZoneList<RegExpTree*>* nodes_; |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1917 | int min_match_; |
| 1918 | int max_match_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1919 | }; |
| 1920 | |
| 1921 | |
| 1922 | class RegExpAssertion: public RegExpTree { |
| 1923 | public: |
| 1924 | enum Type { |
| 1925 | START_OF_LINE, |
| 1926 | START_OF_INPUT, |
| 1927 | END_OF_LINE, |
| 1928 | END_OF_INPUT, |
| 1929 | BOUNDARY, |
| 1930 | NON_BOUNDARY |
| 1931 | }; |
| 1932 | explicit RegExpAssertion(Type type) : type_(type) { } |
| 1933 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1934 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1935 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1936 | virtual RegExpAssertion* AsAssertion(); |
| 1937 | virtual bool IsAssertion(); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1938 | virtual bool IsAnchoredAtStart(); |
| 1939 | virtual bool IsAnchoredAtEnd(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1940 | virtual int min_match() { return 0; } |
| 1941 | virtual int max_match() { return 0; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1942 | Type type() { return type_; } |
| 1943 | private: |
| 1944 | Type type_; |
| 1945 | }; |
| 1946 | |
| 1947 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1948 | class CharacterSet BASE_EMBEDDED { |
| 1949 | public: |
| 1950 | explicit CharacterSet(uc16 standard_set_type) |
| 1951 | : ranges_(NULL), |
| 1952 | standard_set_type_(standard_set_type) {} |
| 1953 | explicit CharacterSet(ZoneList<CharacterRange>* ranges) |
| 1954 | : ranges_(ranges), |
| 1955 | standard_set_type_(0) {} |
| 1956 | ZoneList<CharacterRange>* ranges(); |
| 1957 | uc16 standard_set_type() { return standard_set_type_; } |
| 1958 | void set_standard_set_type(uc16 special_set_type) { |
| 1959 | standard_set_type_ = special_set_type; |
| 1960 | } |
| 1961 | bool is_standard() { return standard_set_type_ != 0; } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1962 | void Canonicalize(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1963 | private: |
| 1964 | ZoneList<CharacterRange>* ranges_; |
| 1965 | // If non-zero, the value represents a standard set (e.g., all whitespace |
| 1966 | // characters) without having to expand the ranges. |
| 1967 | uc16 standard_set_type_; |
| 1968 | }; |
| 1969 | |
| 1970 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1971 | class RegExpCharacterClass: public RegExpTree { |
| 1972 | public: |
| 1973 | RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated) |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1974 | : set_(ranges), |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1975 | is_negated_(is_negated) { } |
| 1976 | explicit RegExpCharacterClass(uc16 type) |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1977 | : set_(type), |
| 1978 | is_negated_(false) { } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1979 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 1980 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1981 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1982 | virtual RegExpCharacterClass* AsCharacterClass(); |
| 1983 | virtual bool IsCharacterClass(); |
| 1984 | virtual bool IsTextElement() { return true; } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1985 | virtual int min_match() { return 1; } |
| 1986 | virtual int max_match() { return 1; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1987 | virtual void AppendToText(RegExpText* text); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1988 | CharacterSet character_set() { return set_; } |
| 1989 | // TODO(lrn): Remove need for complex version if is_standard that |
| 1990 | // recognizes a mangled standard set and just do { return set_.is_special(); } |
| 1991 | bool is_standard(); |
| 1992 | // Returns a value representing the standard character set if is_standard() |
| 1993 | // returns true. |
| 1994 | // Currently used values are: |
| 1995 | // s : unicode whitespace |
| 1996 | // S : unicode non-whitespace |
| 1997 | // w : ASCII word character (digit, letter, underscore) |
| 1998 | // W : non-ASCII word character |
| 1999 | // d : ASCII digit |
| 2000 | // D : non-ASCII digit |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2001 | // . : non-unicode non-newline |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2002 | // * : All characters |
| 2003 | uc16 standard_type() { return set_.standard_set_type(); } |
| 2004 | ZoneList<CharacterRange>* ranges() { return set_.ranges(); } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2005 | bool is_negated() { return is_negated_; } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2006 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2007 | private: |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2008 | CharacterSet set_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2009 | bool is_negated_; |
| 2010 | }; |
| 2011 | |
| 2012 | |
| 2013 | class RegExpAtom: public RegExpTree { |
| 2014 | public: |
| 2015 | explicit RegExpAtom(Vector<const uc16> data) : data_(data) { } |
| 2016 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 2017 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2018 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2019 | virtual RegExpAtom* AsAtom(); |
| 2020 | virtual bool IsAtom(); |
| 2021 | virtual bool IsTextElement() { return true; } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2022 | virtual int min_match() { return data_.length(); } |
| 2023 | virtual int max_match() { return data_.length(); } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2024 | virtual void AppendToText(RegExpText* text); |
| 2025 | Vector<const uc16> data() { return data_; } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2026 | int length() { return data_.length(); } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2027 | private: |
| 2028 | Vector<const uc16> data_; |
| 2029 | }; |
| 2030 | |
| 2031 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2032 | class RegExpText: public RegExpTree { |
| 2033 | public: |
| 2034 | RegExpText() : elements_(2), length_(0) {} |
| 2035 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 2036 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
| 2037 | RegExpNode* on_success); |
| 2038 | virtual RegExpText* AsText(); |
| 2039 | virtual bool IsText(); |
| 2040 | virtual bool IsTextElement() { return true; } |
| 2041 | virtual int min_match() { return length_; } |
| 2042 | virtual int max_match() { return length_; } |
| 2043 | virtual void AppendToText(RegExpText* text); |
| 2044 | void AddElement(TextElement elm) { |
| 2045 | elements_.Add(elm); |
| 2046 | length_ += elm.length(); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 2047 | } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2048 | ZoneList<TextElement>* elements() { return &elements_; } |
| 2049 | private: |
| 2050 | ZoneList<TextElement> elements_; |
| 2051 | int length_; |
| 2052 | }; |
| 2053 | |
| 2054 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2055 | class RegExpQuantifier: public RegExpTree { |
| 2056 | public: |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2057 | enum Type { GREEDY, NON_GREEDY, POSSESSIVE }; |
| 2058 | RegExpQuantifier(int min, int max, Type type, RegExpTree* body) |
| 2059 | : body_(body), |
| 2060 | min_(min), |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2061 | max_(max), |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2062 | min_match_(min * body->min_match()), |
| 2063 | type_(type) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2064 | if (max > 0 && body->max_match() > kInfinity / max) { |
| 2065 | max_match_ = kInfinity; |
| 2066 | } else { |
| 2067 | max_match_ = max * body->max_match(); |
| 2068 | } |
| 2069 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2070 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 2071 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2072 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2073 | static RegExpNode* ToNode(int min, |
| 2074 | int max, |
| 2075 | bool is_greedy, |
| 2076 | RegExpTree* body, |
| 2077 | RegExpCompiler* compiler, |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2078 | RegExpNode* on_success, |
| 2079 | bool not_at_start = false); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2080 | virtual RegExpQuantifier* AsQuantifier(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2081 | virtual Interval CaptureRegisters(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2082 | virtual bool IsQuantifier(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2083 | virtual int min_match() { return min_match_; } |
| 2084 | virtual int max_match() { return max_match_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2085 | int min() { return min_; } |
| 2086 | int max() { return max_; } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2087 | bool is_possessive() { return type_ == POSSESSIVE; } |
| 2088 | bool is_non_greedy() { return type_ == NON_GREEDY; } |
| 2089 | bool is_greedy() { return type_ == GREEDY; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2090 | RegExpTree* body() { return body_; } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2091 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2092 | private: |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2093 | RegExpTree* body_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2094 | int min_; |
| 2095 | int max_; |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2096 | int min_match_; |
| 2097 | int max_match_; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2098 | Type type_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2099 | }; |
| 2100 | |
| 2101 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2102 | class RegExpCapture: public RegExpTree { |
| 2103 | public: |
| 2104 | explicit RegExpCapture(RegExpTree* body, int index) |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2105 | : body_(body), index_(index) { } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2106 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 2107 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2108 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2109 | static RegExpNode* ToNode(RegExpTree* body, |
| 2110 | int index, |
| 2111 | RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2112 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2113 | virtual RegExpCapture* AsCapture(); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 2114 | virtual bool IsAnchoredAtStart(); |
| 2115 | virtual bool IsAnchoredAtEnd(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2116 | virtual Interval CaptureRegisters(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2117 | virtual bool IsCapture(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2118 | virtual int min_match() { return body_->min_match(); } |
| 2119 | virtual int max_match() { return body_->max_match(); } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2120 | RegExpTree* body() { return body_; } |
| 2121 | int index() { return index_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2122 | static int StartRegister(int index) { return index * 2; } |
| 2123 | static int EndRegister(int index) { return index * 2 + 1; } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2124 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2125 | private: |
| 2126 | RegExpTree* body_; |
| 2127 | int index_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2128 | }; |
| 2129 | |
| 2130 | |
| 2131 | class RegExpLookahead: public RegExpTree { |
| 2132 | public: |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2133 | RegExpLookahead(RegExpTree* body, |
| 2134 | bool is_positive, |
| 2135 | int capture_count, |
| 2136 | int capture_from) |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2137 | : body_(body), |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2138 | is_positive_(is_positive), |
| 2139 | capture_count_(capture_count), |
| 2140 | capture_from_(capture_from) { } |
| 2141 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2142 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 2143 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2144 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2145 | virtual RegExpLookahead* AsLookahead(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2146 | virtual Interval CaptureRegisters(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2147 | virtual bool IsLookahead(); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 2148 | virtual bool IsAnchoredAtStart(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2149 | virtual int min_match() { return 0; } |
| 2150 | virtual int max_match() { return 0; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2151 | RegExpTree* body() { return body_; } |
| 2152 | bool is_positive() { return is_positive_; } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2153 | int capture_count() { return capture_count_; } |
| 2154 | int capture_from() { return capture_from_; } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2155 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2156 | private: |
| 2157 | RegExpTree* body_; |
| 2158 | bool is_positive_; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2159 | int capture_count_; |
| 2160 | int capture_from_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2161 | }; |
| 2162 | |
| 2163 | |
| 2164 | class RegExpBackReference: public RegExpTree { |
| 2165 | public: |
| 2166 | explicit RegExpBackReference(RegExpCapture* capture) |
| 2167 | : capture_(capture) { } |
| 2168 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 2169 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2170 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2171 | virtual RegExpBackReference* AsBackReference(); |
| 2172 | virtual bool IsBackReference(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2173 | virtual int min_match() { return 0; } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2174 | virtual int max_match() { return capture_->max_match(); } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2175 | int index() { return capture_->index(); } |
| 2176 | RegExpCapture* capture() { return capture_; } |
| 2177 | private: |
| 2178 | RegExpCapture* capture_; |
| 2179 | }; |
| 2180 | |
| 2181 | |
| 2182 | class RegExpEmpty: public RegExpTree { |
| 2183 | public: |
| 2184 | RegExpEmpty() { } |
| 2185 | virtual void* Accept(RegExpVisitor* visitor, void* data); |
| 2186 | virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2187 | RegExpNode* on_success); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2188 | virtual RegExpEmpty* AsEmpty(); |
| 2189 | virtual bool IsEmpty(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2190 | virtual int min_match() { return 0; } |
| 2191 | virtual int max_match() { return 0; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2192 | static RegExpEmpty* GetInstance() { return &kInstance; } |
| 2193 | private: |
| 2194 | static RegExpEmpty kInstance; |
| 2195 | }; |
| 2196 | |
| 2197 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2198 | // ---------------------------------------------------------------------------- |
| 2199 | // Basic visitor |
| 2200 | // - leaf node visitors are abstract. |
| 2201 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2202 | class AstVisitor BASE_EMBEDDED { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2203 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2204 | AstVisitor() : isolate_(Isolate::Current()), stack_overflow_(false) { } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2205 | virtual ~AstVisitor() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2206 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2207 | // Stack overflow check and dynamic dispatch. |
| 2208 | void Visit(AstNode* node) { if (!CheckStackOverflow()) node->Accept(this); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2209 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2210 | // Iteration left-to-right. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2211 | virtual void VisitDeclarations(ZoneList<Declaration*>* declarations); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2212 | virtual void VisitStatements(ZoneList<Statement*>* statements); |
| 2213 | virtual void VisitExpressions(ZoneList<Expression*>* expressions); |
| 2214 | |
| 2215 | // Stack overflow tracking support. |
| 2216 | bool HasStackOverflow() const { return stack_overflow_; } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2217 | bool CheckStackOverflow(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2218 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2219 | // If a stack-overflow exception is encountered when visiting a |
| 2220 | // node, calling SetStackOverflow will make sure that the visitor |
| 2221 | // bails out without visiting more nodes. |
| 2222 | void SetStackOverflow() { stack_overflow_ = true; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2223 | void ClearStackOverflow() { stack_overflow_ = false; } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2224 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2225 | // Nodes not appearing in the AST, including slots. |
| 2226 | virtual void VisitSlot(Slot* node) { UNREACHABLE(); } |
| 2227 | |
| 2228 | // Individual AST nodes. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2229 | #define DEF_VISIT(type) \ |
| 2230 | virtual void Visit##type(type* node) = 0; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2231 | AST_NODE_LIST(DEF_VISIT) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2232 | #undef DEF_VISIT |
| 2233 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2234 | protected: |
| 2235 | Isolate* isolate() { return isolate_; } |
| 2236 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2237 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2238 | Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2239 | bool stack_overflow_; |
| 2240 | }; |
| 2241 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2242 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2243 | } } // namespace v8::internal |
| 2244 | |
| 2245 | #endif // V8_AST_H_ |