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