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