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