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