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