blob: 66b4dd46c46fa23d577edb1ef2197ceafcf7d225 [file] [log] [blame]
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00001// Copyright 2012 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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.org659ceec2012-01-26 07:37:54 +000031#include "v8.h"
32
33#include "assembler.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000034#include "factory.h"
yangguo@chromium.org659ceec2012-01-26 07:37:54 +000035#include "isolate.h"
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +000036#include "jsregexp.h"
yangguo@chromium.org659ceec2012-01-26 07:37:54 +000037#include "list-inl.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000038#include "runtime.h"
ricow@chromium.orgddd545c2011-08-24 12:02:41 +000039#include "small-pointer-list.h"
yangguo@chromium.org304cc332012-07-24 07:59:48 +000040#include "smart-pointers.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000041#include "token.h"
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +000042#include "utils.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000043#include "variables.h"
erik.corry@gmail.combbceb572012-03-09 10:52:05 +000044#include "interface.h"
yangguo@chromium.org659ceec2012-01-26 07:37:54 +000045#include "zone-inl.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000046
kasperl@chromium.org71affb52009-05-26 05:44:31 +000047namespace v8 {
48namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000049
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.org78d1ad42012-02-09 13:53:47 +000063#define DECLARATION_NODE_LIST(V) \
64 V(VariableDeclaration) \
ulan@chromium.org812308e2012-02-29 15:58:45 +000065 V(FunctionDeclaration) \
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +000066 V(ModuleDeclaration) \
ulan@chromium.org812308e2012-02-29 15:58:45 +000067 V(ImportDeclaration) \
68 V(ExportDeclaration) \
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +000069
70#define MODULE_NODE_LIST(V) \
71 V(ModuleLiteral) \
72 V(ModuleVariable) \
73 V(ModulePath) \
74 V(ModuleUrl)
75
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +000076#define STATEMENT_NODE_LIST(V) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000077 V(Block) \
ulan@chromium.org8e8d8822012-11-23 14:36:46 +000078 V(ModuleStatement) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000079 V(ExpressionStatement) \
80 V(EmptyStatement) \
81 V(IfStatement) \
82 V(ContinueStatement) \
83 V(BreakStatement) \
84 V(ReturnStatement) \
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +000085 V(WithStatement) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000086 V(SwitchStatement) \
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +000087 V(DoWhileStatement) \
88 V(WhileStatement) \
89 V(ForStatement) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000090 V(ForInStatement) \
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +000091 V(TryCatchStatement) \
92 V(TryFinallyStatement) \
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +000093 V(DebuggerStatement)
94
95#define EXPRESSION_NODE_LIST(V) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000096 V(FunctionLiteral) \
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +000097 V(SharedFunctionInfoLiteral) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000098 V(Conditional) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000099 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.org0b6db592009-07-30 14:48:31 +0000116#define AST_NODE_LIST(V) \
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000117 DECLARATION_NODE_LIST(V) \
118 MODULE_NODE_LIST(V) \
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000119 STATEMENT_NODE_LIST(V) \
120 EXPRESSION_NODE_LIST(V)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000121
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000122// Forward declarations
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000123class AstConstructionVisitor;
124template<class> class AstNodeFactory;
yangguo@chromium.org659ceec2012-01-26 07:37:54 +0000125class AstVisitor;
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000126class Declaration;
127class Module;
yangguo@chromium.org659ceec2012-01-26 07:37:54 +0000128class BreakableStatement;
129class Expression;
130class IterationStatement;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000131class MaterializedLiteral;
yangguo@chromium.org659ceec2012-01-26 07:37:54 +0000132class Statement;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000133class TargetCollector;
134class TypeFeedbackOracle;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000135
yangguo@chromium.org659ceec2012-01-26 07:37:54 +0000136class RegExpAlternative;
137class RegExpAssertion;
138class RegExpAtom;
139class RegExpBackReference;
140class RegExpCapture;
141class RegExpCharacterClass;
142class RegExpCompiler;
143class RegExpDisjunction;
144class RegExpEmpty;
145class RegExpLookahead;
146class RegExpQuantifier;
147class RegExpText;
148
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000149#define DEF_FORWARD_DECLARATION(type) class type;
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000150AST_NODE_LIST(DEF_FORWARD_DECLARATION)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000151#undef DEF_FORWARD_DECLARATION
152
153
154// Typedef only introduced to avoid unreadable code.
155// Please do appreciate the required space in "> >".
156typedef ZoneList<Handle<String> > ZoneStringList;
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000157typedef ZoneList<Handle<Object> > ZoneObjectList;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000158
159
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000160#define DECLARE_NODE_TYPE(type) \
161 virtual void Accept(AstVisitor* v); \
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000162 virtual AstNode::Type node_type() const { return AstNode::k##type; } \
163 template<class> friend class AstNodeFactory;
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000164
165
166enum AstPropertiesFlag {
167 kDontInline,
168 kDontOptimize,
169 kDontSelfOptimize,
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000170 kDontSoftInline,
171 kDontCache
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000172};
173
174
175class 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.org0b6db592009-07-30 14:48:31 +0000191class AstNode: public ZoneObject {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000192 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000193#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.hansen43d26ec2008-07-03 15:10:15 +0000199
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +0000200 void* operator new(size_t size, Zone* zone) {
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +0000201 return zone->New(static_cast<int>(size));
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000202 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000203
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000204 AstNode() { }
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +0000205
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000206 virtual ~AstNode() { }
207
208 virtual void Accept(AstVisitor* v) = 0;
yangguo@chromium.org304cc332012-07-24 07:59:48 +0000209 virtual Type node_type() const = 0;
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000210
211 // Type testing & conversion functions overridden by concrete subclasses.
212#define DECLARE_NODE_FUNCTIONS(type) \
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000213 bool Is##type() { return node_type() == AstNode::k##type; } \
214 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; }
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000215 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
216#undef DECLARE_NODE_FUNCTIONS
217
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000218 virtual TargetCollector* AsTargetCollector() { return NULL; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000219 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
220 virtual IterationStatement* AsIterationStatement() { return NULL; }
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000221 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000222
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000223 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000224 static int GetNextId(Isolate* isolate) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +0000225 return ReserveIdRange(isolate, 1);
226 }
227
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000228 static int ReserveIdRange(Isolate* isolate, int n) {
229 int tmp = isolate->ast_node_id();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000230 isolate->set_ast_node_id(tmp + n);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000231 return tmp;
232 }
233
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000234 // 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.org84bcc552011-07-18 09:50:57 +0000240 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.org4d3fe4e2011-03-10 10:14:28 +0000245 friend class CaseClause; // Generates AST IDs.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000246};
247
248
249class Statement: public AstNode {
250 public:
251 Statement() : statement_pos_(RelocInfo::kNoPosition) {}
252
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000253 bool IsEmpty() { return AsEmptyStatement() != NULL; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000254
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.orgddd545c2011-08-24 12:02:41 +0000263class SmallMapList {
264 public:
265 SmallMapList() {}
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000266 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {}
ricow@chromium.orgddd545c2011-08-24 12:02:41 +0000267
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000268 void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); }
ricow@chromium.orgddd545c2011-08-24 12:02:41 +0000269 void Clear() { list_.Clear(); }
jkummerow@chromium.org1456e702012-03-30 08:38:13 +0000270 void Sort() { list_.Sort(); }
ricow@chromium.orgddd545c2011-08-24 12:02:41 +0000271
272 bool is_empty() const { return list_.is_empty(); }
273 int length() const { return list_.length(); }
274
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000275 void Add(Handle<Map> handle, Zone* zone) {
276 list_.Add(handle.location(), zone);
ricow@chromium.orgddd545c2011-08-24 12:02:41 +0000277 }
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.org0b6db592009-07-30 14:48:31 +0000294class Expression: public AstNode {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000295 public:
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000296 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.org44bc7082011-04-11 12:33:05 +0000308 virtual int position() const {
309 UNREACHABLE();
310 return 0;
311 }
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000312
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000313 virtual bool IsValidLeftHandSide() { return false; }
314
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000315 // Helpers for ToBoolean conversion.
316 virtual bool ToBooleanIsTrue() { return false; }
317 virtual bool ToBooleanIsFalse() { return false; }
318
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000319 // 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.org65fae842010-08-25 15:26:24 +0000324 // 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.orgd236f4d2010-09-01 06:52:08 +0000328 // True iff the expression is a literal represented as a smi.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000329 bool IsSmiLiteral();
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000330
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000331 // True iff the expression is a string literal.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000332 bool IsStringLiteral();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000333
334 // True iff the expression is the null literal.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000335 bool IsNullLiteral();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000336
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000337 // Type feedback information for assignments and properties.
338 virtual bool IsMonomorphic() {
339 UNREACHABLE();
340 return false;
341 }
ricow@chromium.orgddd545c2011-08-24 12:02:41 +0000342 virtual SmallMapList* GetReceiverTypes() {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000343 UNREACHABLE();
344 return NULL;
345 }
ricow@chromium.orgddd545c2011-08-24 12:02:41 +0000346 Handle<Map> GetMonomorphicReceiverType() {
347 ASSERT(IsMonomorphic());
348 SmallMapList* types = GetReceiverTypes();
349 ASSERT(types != NULL && types->length() == 1);
350 return types->at(0);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000351 }
352
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000353 BailoutId id() const { return id_; }
354 TypeFeedbackId test_id() const { return test_id_; }
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000355
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000356 protected:
357 explicit Expression(Isolate* isolate)
358 : id_(GetNextId(isolate)),
359 test_id_(GetNextId(isolate)) {}
360
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000361 private:
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000362 const BailoutId id_;
363 const TypeFeedbackId test_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000364};
365
366
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000367class 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.org44bc7082011-04-11 12:33:05 +0000382 Label* break_target() { return &break_target_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000383
384 // Testers.
385 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; }
386
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000387 BailoutId EntryId() const { return entry_id_; }
388 BailoutId ExitId() const { return exit_id_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000389
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000390 protected:
danno@chromium.orgc612e022011-11-10 11:38:15 +0000391 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.hansen43d26ec2008-07-03 15:10:15 +0000399
400 private:
401 ZoneStringList* labels_;
402 Type type_;
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000403 Label break_target_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000404 const BailoutId entry_id_;
405 const BailoutId exit_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000406};
407
408
409class Block: public BreakableStatement {
410 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000411 DECLARE_NODE_TYPE(Block)
412
rossberg@chromium.org400388e2012-06-06 09:29:22 +0000413 void AddStatement(Statement* statement, Zone* zone) {
414 statements_.Add(statement, zone);
415 }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000416
417 ZoneList<Statement*>* statements() { return &statements_; }
418 bool is_initializer_block() const { return is_initializer_block_; }
419
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000420 Scope* scope() const { return scope_; }
421 void set_scope(Scope* scope) { scope_ = scope; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000422
423 protected:
danno@chromium.orgc612e022011-11-10 11:38:15 +0000424 Block(Isolate* isolate,
425 ZoneStringList* labels,
426 int capacity,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000427 bool is_initializer_block,
428 Zone* zone)
danno@chromium.orgc612e022011-11-10 11:38:15 +0000429 : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY),
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000430 statements_(capacity, zone),
danno@chromium.orgc612e022011-11-10 11:38:15 +0000431 is_initializer_block_(is_initializer_block),
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000432 scope_(NULL) {
danno@chromium.orgc612e022011-11-10 11:38:15 +0000433 }
434
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000435 private:
436 ZoneList<Statement*> statements_;
437 bool is_initializer_block_;
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000438 Scope* scope_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000439};
440
441
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000442class Declaration: public AstNode {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000443 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000444 VariableProxy* proxy() const { return proxy_; }
445 VariableMode mode() const { return mode_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000446 Scope* scope() const { return scope_; }
ulan@chromium.org812308e2012-02-29 15:58:45 +0000447 virtual InitializationFlag initialization() const = 0;
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000448 virtual bool IsInlineable() const;
449
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000450 protected:
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000451 Declaration(VariableProxy* proxy,
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000452 VariableMode mode,
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000453 Scope* scope)
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000454 : proxy_(proxy),
455 mode_(mode),
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000456 scope_(scope) {
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000457 ASSERT(IsDeclaredVariableMode(mode));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000458 }
459
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000460 private:
461 VariableProxy* proxy_;
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000462 VariableMode mode_;
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000463
464 // Nested scope from which the declaration originated.
465 Scope* scope_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000466};
467
468
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000469class VariableDeclaration: public Declaration {
470 public:
471 DECLARE_NODE_TYPE(VariableDeclaration)
472
ulan@chromium.org812308e2012-02-29 15:58:45 +0000473 virtual InitializationFlag initialization() const {
474 return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
475 }
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000476
477 protected:
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000478 VariableDeclaration(VariableProxy* proxy,
479 VariableMode mode,
ulan@chromium.org812308e2012-02-29 15:58:45 +0000480 Scope* scope)
481 : Declaration(proxy, mode, scope) {
482 }
483};
484
485
486class 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.org812308e2012-02-29 15:58:45 +0000497 FunctionDeclaration(VariableProxy* proxy,
498 VariableMode mode,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000499 FunctionLiteral* fun,
500 Scope* scope)
501 : Declaration(proxy, mode, scope),
502 fun_(fun) {
ulan@chromium.org812308e2012-02-29 15:58:45 +0000503 // At the moment there are no "const functions" in JavaScript...
504 ASSERT(mode == VAR || mode == LET);
505 ASSERT(fun != NULL);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000506 }
507
508 private:
509 FunctionLiteral* fun_;
510};
511
512
513class ModuleDeclaration: public Declaration {
514 public:
515 DECLARE_NODE_TYPE(ModuleDeclaration)
516
517 Module* module() const { return module_; }
ulan@chromium.org812308e2012-02-29 15:58:45 +0000518 virtual InitializationFlag initialization() const {
519 return kCreatedInitialized;
520 }
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000521
522 protected:
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000523 ModuleDeclaration(VariableProxy* proxy,
524 Module* module,
525 Scope* scope)
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000526 : Declaration(proxy, MODULE, scope),
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000527 module_(module) {
528 }
529
530 private:
531 Module* module_;
532};
533
534
ulan@chromium.org812308e2012-02-29 15:58:45 +0000535class 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.org812308e2012-02-29 15:58:45 +0000545 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
557class 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.org81cac2b2012-07-10 11:28:27 +0000566 ExportDeclaration(VariableProxy* proxy, Scope* scope)
567 : Declaration(proxy, LET, scope) {}
ulan@chromium.org812308e2012-02-29 15:58:45 +0000568};
569
570
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000571class Module: public AstNode {
erik.corry@gmail.combbceb572012-03-09 10:52:05 +0000572 public:
573 Interface* interface() const { return interface_; }
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000574 Block* body() const { return body_; }
erik.corry@gmail.combbceb572012-03-09 10:52:05 +0000575
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000576 protected:
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000577 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.combbceb572012-03-09 10:52:05 +0000583
584 private:
585 Interface* interface_;
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000586 Block* body_;
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000587};
588
589
590class ModuleLiteral: public Module {
591 public:
592 DECLARE_NODE_TYPE(ModuleLiteral)
593
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000594 protected:
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000595 ModuleLiteral(Block* body, Interface* interface) : Module(interface, body) {}
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000596};
597
598
599class ModuleVariable: public Module {
600 public:
601 DECLARE_NODE_TYPE(ModuleVariable)
602
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000603 VariableProxy* proxy() const { return proxy_; }
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000604
605 protected:
erik.corry@gmail.combbceb572012-03-09 10:52:05 +0000606 inline explicit ModuleVariable(VariableProxy* proxy);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000607
608 private:
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000609 VariableProxy* proxy_;
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000610};
611
612
613class 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.org7028c052012-06-13 11:51:58 +0000621 ModulePath(Module* module, Handle<String> name, Zone* zone)
622 : Module(zone),
623 module_(module),
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000624 name_(name) {
625 }
626
627 private:
628 Module* module_;
629 Handle<String> name_;
630};
631
632
633class ModuleUrl: public Module {
634 public:
635 DECLARE_NODE_TYPE(ModuleUrl)
636
637 Handle<String> url() const { return url_; }
638
639 protected:
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000640 ModuleUrl(Handle<String> url, Zone* zone)
641 : Module(zone), url_(url) {
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +0000642 }
643
644 private:
645 Handle<String> url_;
646};
647
648
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000649class 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.hansen43d26ec2008-07-03 15:10:15 +0000668class 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.org471f2f12012-08-10 14:46:33 +0000675 BailoutId OsrEntryId() const { return osr_entry_id_; }
676 virtual BailoutId ContinueId() const = 0;
677 virtual BailoutId StackCheckId() const = 0;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000678
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000679 // Code generation
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000680 Label* continue_target() { return &continue_target_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000681
682 protected:
danno@chromium.orgc612e022011-11-10 11:38:15 +0000683 IterationStatement(Isolate* isolate, ZoneStringList* labels)
684 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS),
685 body_(NULL),
686 osr_entry_id_(GetNextId(isolate)) {
687 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000688
689 void Initialize(Statement* body) {
690 body_ = body;
691 }
692
693 private:
694 Statement* body_;
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000695 Label continue_target_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000696 const BailoutId osr_entry_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000697};
698
699
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000700class DoWhileStatement: public IterationStatement {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000701 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000702 DECLARE_NODE_TYPE(DoWhileStatement)
703
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000704 void Initialize(Expression* cond, Statement* body) {
705 IterationStatement::Initialize(body);
706 cond_ = cond;
707 }
708
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000709 Expression* cond() const { return cond_; }
710
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000711 // 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.org471f2f12012-08-10 14:46:33 +0000716 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.orga5551262010-12-07 12:49:48 +0000719
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000720 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000721 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.orga9aa5fa2011-04-13 08:46:07 +0000728
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000729 private:
730 Expression* cond_;
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000731 int condition_position_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000732 const BailoutId continue_id_;
733 const BailoutId back_edge_id_;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000734};
735
736
737class WhileStatement: public IterationStatement {
738 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000739 DECLARE_NODE_TYPE(WhileStatement)
740
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000741 void Initialize(Expression* cond, Statement* body) {
742 IterationStatement::Initialize(body);
743 cond_ = cond;
744 }
745
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000746 Expression* cond() const { return cond_; }
747 bool may_have_function_literal() const {
748 return may_have_function_literal_;
749 }
ricow@chromium.org65fae842010-08-25 15:26:24 +0000750 void set_may_have_function_literal(bool value) {
751 may_have_function_literal_ = value;
752 }
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000753
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000754 virtual BailoutId ContinueId() const { return EntryId(); }
755 virtual BailoutId StackCheckId() const { return body_id_; }
756 BailoutId BodyId() const { return body_id_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000757
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000758 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000759 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.com9d58c2b2009-10-16 11:48:38 +0000766 private:
767 Expression* cond_;
768 // True if there is a function literal subexpression in the condition.
769 bool may_have_function_literal_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000770 const BailoutId body_id_;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000771};
772
773
774class ForStatement: public IterationStatement {
775 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000776 DECLARE_NODE_TYPE(ForStatement)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000777
778 void Initialize(Statement* init,
779 Expression* cond,
780 Statement* next,
781 Statement* body) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000782 IterationStatement::Initialize(body);
783 init_ = init;
784 cond_ = cond;
785 next_ = next;
786 }
787
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000788 Statement* init() const { return init_; }
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000789 Expression* cond() const { return cond_; }
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000790 Statement* next() const { return next_; }
ricow@chromium.org65fae842010-08-25 15:26:24 +0000791
kasperl@chromium.orgf5aa8372009-03-24 14:47:14 +0000792 bool may_have_function_literal() const {
793 return may_have_function_literal_;
794 }
ricow@chromium.org65fae842010-08-25 15:26:24 +0000795 void set_may_have_function_literal(bool value) {
796 may_have_function_literal_ = value;
797 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000798
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000799 virtual BailoutId ContinueId() const { return continue_id_; }
800 virtual BailoutId StackCheckId() const { return body_id_; }
801 BailoutId BodyId() const { return body_id_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000802
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000803 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.orgb1df11d2012-02-08 10:26:21 +0000806
807 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000808 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.orgf8372902010-03-15 10:26:20 +0000818
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000819 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000820 Statement* init_;
821 Expression* cond_;
822 Statement* next_;
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000823 // True if there is a function literal subexpression in the condition.
kasperl@chromium.orgf5aa8372009-03-24 14:47:14 +0000824 bool may_have_function_literal_;
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000825 Variable* loop_variable_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000826 const BailoutId continue_id_;
827 const BailoutId body_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000828};
829
830
831class ForInStatement: public IterationStatement {
832 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000833 DECLARE_NODE_TYPE(ForInStatement)
834
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000835 void Initialize(Expression* each, Expression* enumerable, Statement* body) {
836 IterationStatement::Initialize(body);
837 each_ = each;
838 enumerable_ = enumerable;
839 }
840
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000841 Expression* each() const { return each_; }
842 Expression* enumerable() const { return enumerable_; }
843
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000844 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.orga5551262010-12-07 12:49:48 +0000850
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000851 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000852 ForInStatement(Isolate* isolate, ZoneStringList* labels)
853 : IterationStatement(isolate, labels),
854 each_(NULL),
855 enumerable_(NULL),
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +0000856 body_id_(GetNextId(isolate)),
857 prepare_id_(GetNextId(isolate)) {
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000858 }
859
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000860 private:
861 Expression* each_;
862 Expression* enumerable_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000863 const BailoutId body_id_;
864 const BailoutId prepare_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000865};
866
867
868class ExpressionStatement: public Statement {
869 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000870 DECLARE_NODE_TYPE(ExpressionStatement)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000871
872 void set_expression(Expression* e) { expression_ = e; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000873 Expression* expression() const { return expression_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000874
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000875 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000876 explicit ExpressionStatement(Expression* expression)
877 : expression_(expression) { }
878
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000879 private:
880 Expression* expression_;
881};
882
883
884class ContinueStatement: public Statement {
885 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000886 DECLARE_NODE_TYPE(ContinueStatement)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000887
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000888 IterationStatement* target() const { return target_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000889
890 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000891 explicit ContinueStatement(IterationStatement* target)
892 : target_(target) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000893
894 private:
895 IterationStatement* target_;
896};
897
898
899class BreakStatement: public Statement {
900 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000901 DECLARE_NODE_TYPE(BreakStatement)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000902
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000903 BreakableStatement* target() const { return target_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000904
905 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000906 explicit BreakStatement(BreakableStatement* target)
907 : target_(target) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000908
909 private:
910 BreakableStatement* target_;
911};
912
913
914class ReturnStatement: public Statement {
915 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000916 DECLARE_NODE_TYPE(ReturnStatement)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000917
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000918 Expression* expression() const { return expression_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000919
920 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000921 explicit ReturnStatement(Expression* expression)
922 : expression_(expression) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000923
924 private:
925 Expression* expression_;
926};
927
928
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000929class WithStatement: public Statement {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000930 public:
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000931 DECLARE_NODE_TYPE(WithStatement)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000932
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000933 Expression* expression() const { return expression_; }
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000934 Statement* statement() const { return statement_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000935
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000936 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +0000937 WithStatement(Expression* expression, Statement* statement)
938 : expression_(expression),
939 statement_(statement) { }
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000940
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000941 private:
942 Expression* expression_;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000943 Statement* statement_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000944};
945
946
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000947class CaseClause: public ZoneObject {
948 public:
rossberg@chromium.org717967f2011-07-20 13:44:42 +0000949 CaseClause(Isolate* isolate,
950 Expression* label,
951 ZoneList<Statement*>* statements,
952 int pos);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000953
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000954 bool is_default() const { return label_ == NULL; }
955 Expression* label() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000956 CHECK(!is_default());
957 return label_;
958 }
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000959 Label* body_target() { return &body_target_; }
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000960 ZoneList<Statement*>* statements() const { return statements_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000961
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000962 int position() const { return position_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000963 void set_position(int pos) { position_ = pos; }
964
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000965 BailoutId EntryId() const { return entry_id_; }
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000966
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000967 // Type feedback information.
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000968 TypeFeedbackId CompareId() { return compare_id_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000969 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
970 bool IsSmiCompare() { return compare_type_ == SMI_ONLY; }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000971 bool IsNameCompare() { return compare_type_ == NAME_ONLY; }
erikcorry0ad885c2011-11-21 13:51:57 +0000972 bool IsStringCompare() { return compare_type_ == STRING_ONLY; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000973 bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; }
974
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000975 private:
976 Expression* label_;
karlklose@chromium.org44bc7082011-04-11 12:33:05 +0000977 Label body_target_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000978 ZoneList<Statement*>* statements_;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000979 int position_;
erikcorry0ad885c2011-11-21 13:51:57 +0000980 enum CompareTypeFeedback {
981 NONE,
982 SMI_ONLY,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000983 NAME_ONLY,
erikcorry0ad885c2011-11-21 13:51:57 +0000984 STRING_ONLY,
985 OBJECT_ONLY
986 };
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000987 CompareTypeFeedback compare_type_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000988 const TypeFeedbackId compare_id_;
989 const BailoutId entry_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000990};
991
992
993class SwitchStatement: public BreakableStatement {
994 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +0000995 DECLARE_NODE_TYPE(SwitchStatement)
996
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000997 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
998 tag_ = tag;
999 cases_ = cases;
1000 }
1001
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001002 Expression* tag() const { return tag_; }
1003 ZoneList<CaseClause*>* cases() const { return cases_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001004
1005 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001006 SwitchStatement(Isolate* isolate, ZoneStringList* labels)
1007 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS),
1008 tag_(NULL),
1009 cases_(NULL) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001010
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.
1022class IfStatement: public Statement {
1023 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001024 DECLARE_NODE_TYPE(IfStatement)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001025
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.org5f0c45f2010-12-17 08:51:21 +00001032
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001033 BailoutId IfId() const { return if_id_; }
1034 BailoutId ThenId() const { return then_id_; }
1035 BailoutId ElseId() const { return else_id_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001036
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001037 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001038 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.hansen43d26ec2008-07-03 15:10:15 +00001050 private:
1051 Expression* condition_;
1052 Statement* then_statement_;
1053 Statement* else_statement_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001054 const BailoutId if_id_;
1055 const BailoutId then_id_;
1056 const BailoutId else_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001057};
1058
1059
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001060// NOTE: TargetCollectors are represented as nodes to fit in the target
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001061// stack in the compiler; this should probably be reworked.
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001062class TargetCollector: public AstNode {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001063 public:
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001064 explicit TargetCollector(Zone* zone) : targets_(0, zone) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001065
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001066 // 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.org7028c052012-06-13 11:51:58 +00001069 void AddTarget(Label* target, Zone* zone);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001070
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001071 // Virtual behaviour. TargetCollectors are never part of the AST.
ager@chromium.orga74f0da2008-12-03 16:05:52 +00001072 virtual void Accept(AstVisitor* v) { UNREACHABLE(); }
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001073 virtual Type node_type() const { return kInvalid; }
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001074 virtual TargetCollector* AsTargetCollector() { return this; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001075
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001076 ZoneList<Label*>* targets() { return &targets_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001077
1078 private:
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001079 ZoneList<Label*> targets_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001080};
1081
1082
1083class TryStatement: public Statement {
1084 public:
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001085 void set_escaping_targets(ZoneList<Label*>* targets) {
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001086 escaping_targets_ = targets;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001087 }
1088
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001089 int index() const { return index_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001090 Block* try_block() const { return try_block_; }
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001091 ZoneList<Label*>* escaping_targets() const { return escaping_targets_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001092
1093 protected:
1094 TryStatement(int index, Block* try_block)
1095 : index_(index),
1096 try_block_(try_block),
1097 escaping_targets_(NULL) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001098
1099 private:
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001100 // Unique (per-function) index of this handler. This is not an AST ID.
1101 int index_;
1102
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001103 Block* try_block_;
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001104 ZoneList<Label*>* escaping_targets_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001105};
1106
1107
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001108class TryCatchStatement: public TryStatement {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001109 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001110 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.org04e4f1e2011-11-14 13:36:17 +00001117 TryCatchStatement(int index,
1118 Block* try_block,
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001119 Scope* scope,
1120 Variable* variable,
1121 Block* catch_block)
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001122 : TryStatement(index, try_block),
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001123 scope_(scope),
1124 variable_(variable),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001125 catch_block_(catch_block) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001126 }
1127
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001128 private:
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001129 Scope* scope_;
1130 Variable* variable_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001131 Block* catch_block_;
1132};
1133
1134
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001135class TryFinallyStatement: public TryStatement {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001136 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001137 DECLARE_NODE_TYPE(TryFinallyStatement)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001138
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001139 Block* finally_block() const { return finally_block_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001140
1141 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001142 TryFinallyStatement(int index, Block* try_block, Block* finally_block)
1143 : TryStatement(index, try_block),
1144 finally_block_(finally_block) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001145
1146 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001147 Block* finally_block_;
1148};
1149
1150
1151class DebuggerStatement: public Statement {
1152 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001153 DECLARE_NODE_TYPE(DebuggerStatement)
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001154
1155 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001156 DebuggerStatement() {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001157};
1158
1159
1160class EmptyStatement: public Statement {
1161 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001162 DECLARE_NODE_TYPE(EmptyStatement)
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001163
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001164 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001165 EmptyStatement() {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001166};
1167
1168
1169class Literal: public Expression {
1170 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001171 DECLARE_NODE_TYPE(Literal)
1172
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00001173 virtual bool IsPropertyName() {
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001174 if (handle_->IsInternalizedString()) {
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00001175 uint32_t ignored;
1176 return !String::cast(*handle_)->AsArrayIndex(&ignored);
1177 }
1178 return false;
1179 }
1180
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001181 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.hansen43d26ec2008-07-03 15:10:15 +00001189 // Identity testers.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001190 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.hansen43d26ec2008-07-03 15:10:15 +00001198 bool IsFalse() const {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001199 ASSERT(!handle_.is_null());
1200 return handle_->IsFalse();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001201 }
1202
1203 Handle<Object> handle() const { return handle_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001204
erik.corry@gmail.combbceb572012-03-09 10:52:05 +00001205 // 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.org471f2f12012-08-10 14:46:33 +00001215 TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); }
1216
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001217 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001218 Literal(Isolate* isolate, Handle<Object> handle)
1219 : Expression(isolate),
1220 handle_(handle) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001221
1222 private:
erik.corry@gmail.combbceb572012-03-09 10:52:05 +00001223 Handle<String> ToString();
1224
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001225 Handle<Object> handle_;
1226};
1227
1228
1229// Base class for literals that needs space in the corresponding JSFunction.
1230class MaterializedLiteral: public Expression {
1231 public:
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001232 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1233
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001234 int literal_index() { return literal_index_; }
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001235
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.orgb1df11d2012-02-08 10:26:21 +00001241
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.orgbb29dc92009-03-24 13:25:23 +00001251
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001252 private:
1253 int literal_index_;
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001254 bool is_simple_;
1255 int depth_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001256};
1257
1258
1259// An object literal has a boilerplate object that is used
1260// for minimizing the work when constructing it at runtime.
1261class 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.hansen43d26ec2008-07-03 15:10:15 +00001268 enum Kind {
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001269 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.hansen43d26ec2008-07-03 15:10:15 +00001274 };
1275
ulan@chromium.org812308e2012-02-29 15:58:45 +00001276 Property(Literal* key, Expression* value, Isolate* isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001277
1278 Literal* key() { return key_; }
1279 Expression* value() { return value_; }
1280 Kind kind() { return kind_; }
1281
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001282 // 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.org3811b432009-10-28 14:53:37 +00001287 bool IsCompileTimeValue();
1288
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00001289 void set_emit_store(bool emit_store);
1290 bool emit_store();
1291
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001292 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.hansen43d26ec2008-07-03 15:10:15 +00001298 private:
1299 Literal* key_;
1300 Expression* value_;
1301 Kind kind_;
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00001302 bool emit_store_;
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +00001303 Handle<Map> receiver_type_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001304 };
1305
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001306 DECLARE_NODE_TYPE(ObjectLiteral)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001307
1308 Handle<FixedArray> constant_properties() const {
1309 return constant_properties_;
1310 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001311 ZoneList<Property*>* properties() const { return properties_; }
1312
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001313 bool fast_elements() const { return fast_elements_; }
1314
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001315 bool has_function() { return has_function_; }
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00001316
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.org7028c052012-06-13 11:51:58 +00001320 void CalculateEmitStore(Zone* zone);
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00001321
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001322 enum Flags {
1323 kNoFlags = 0,
1324 kFastElements = 1,
1325 kHasFunction = 1 << 1
1326 };
1327
rossberg@chromium.org2c067b12012-03-19 11:01:52 +00001328 struct Accessors: public ZoneObject {
1329 Accessors() : getter(NULL), setter(NULL) { }
1330 Expression* getter;
1331 Expression* setter;
1332 };
1333
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001334 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001335 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.hansen43d26ec2008-07-03 15:10:15 +00001349 private:
1350 Handle<FixedArray> constant_properties_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001351 ZoneList<Property*>* properties_;
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001352 bool fast_elements_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001353 bool has_function_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001354};
1355
1356
1357// Node for capturing a regexp literal.
1358class RegExpLiteral: public MaterializedLiteral {
1359 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001360 DECLARE_NODE_TYPE(RegExpLiteral)
1361
1362 Handle<String> pattern() const { return pattern_; }
1363 Handle<String> flags() const { return flags_; }
1364
1365 protected:
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001366 RegExpLiteral(Isolate* isolate,
1367 Handle<String> pattern,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001368 Handle<String> flags,
1369 int literal_index)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001370 : MaterializedLiteral(isolate, literal_index, false, 1),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001371 pattern_(pattern),
1372 flags_(flags) {}
1373
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001374 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.com37abdec2009-01-06 14:43:28 +00001380// for minimizing the work when constructing it at runtime.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001381class ArrayLiteral: public MaterializedLiteral {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001382 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001383 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.org471f2f12012-08-10 14:46:33 +00001389 BailoutId GetIdForElement(int i) {
1390 return BailoutId(first_element_id_.ToInt() + i);
1391 }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001392
1393 protected:
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001394 ArrayLiteral(Isolate* isolate,
1395 Handle<FixedArray> constant_elements,
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001396 ZoneList<Expression*>* values,
1397 int literal_index,
1398 bool is_simple,
1399 int depth)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001400 : MaterializedLiteral(isolate, literal_index, is_simple, depth),
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00001401 constant_elements_(constant_elements),
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001402 values_(values),
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001403 first_element_id_(ReserveIdRange(isolate, values->length())) {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001404
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001405 private:
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00001406 Handle<FixedArray> constant_elements_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001407 ZoneList<Expression*>* values_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001408 const BailoutId first_element_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001409};
1410
1411
1412class VariableProxy: public Expression {
1413 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001414 DECLARE_NODE_TYPE(VariableProxy)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001415
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001416 virtual bool IsValidLeftHandSide() {
1417 return var_ == NULL ? true : var_->IsValidLeftHandSide();
1418 }
ager@chromium.org3e875802009-06-29 08:26:34 +00001419
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001420 bool IsVariable(Handle<String> n) {
1421 return !is_this() && name().is_identical_to(n);
1422 }
1423
jkummerow@chromium.org486075a2011-09-07 12:44:28 +00001424 bool IsArguments() { return var_ != NULL && var_->is_arguments(); }
ager@chromium.org3e875802009-06-29 08:26:34 +00001425
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001426 bool IsLValue() {
1427 return is_lvalue_;
1428 }
1429
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001430 Handle<String> name() const { return name_; }
1431 Variable* var() const { return var_; }
1432 bool is_this() const { return is_this_; }
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001433 int position() const { return position_; }
erik.corry@gmail.combbceb572012-03-09 10:52:05 +00001434 Interface* interface() const { return interface_; }
1435
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001436
ricow@chromium.org65fae842010-08-25 15:26:24 +00001437 void MarkAsTrivial() { is_trivial_ = true; }
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001438 void MarkAsLValue() { is_lvalue_ = true; }
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001439
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001440 // Bind this proxy to the variable var. Interfaces must match.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001441 void BindTo(Variable* var);
1442
1443 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001444 VariableProxy(Isolate* isolate, Variable* var);
1445
1446 VariableProxy(Isolate* isolate,
1447 Handle<String> name,
1448 bool is_this,
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00001449 Interface* interface,
1450 int position);
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001451
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001452 Handle<String> name_;
1453 Variable* var_; // resolved variable, or NULL
1454 bool is_this_;
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001455 bool is_trivial_;
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001456 // True if this variable proxy is being used in an assignment
1457 // or with a increment/decrement operator.
1458 bool is_lvalue_;
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001459 int position_;
erik.corry@gmail.combbceb572012-03-09 10:52:05 +00001460 Interface* interface_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001461};
1462
1463
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001464class Property: public Expression {
1465 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001466 DECLARE_NODE_TYPE(Property)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001467
1468 virtual bool IsValidLeftHandSide() { return true; }
1469
1470 Expression* obj() const { return obj_; }
1471 Expression* key() const { return key_; }
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001472 virtual int position() const { return pos_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001473
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001474 BailoutId LoadId() const { return load_id_; }
ulan@chromium.orgea52b5f2012-07-30 13:05:33 +00001475
ager@chromium.org378b34e2011-01-28 08:04:38 +00001476 bool IsStringLength() const { return is_string_length_; }
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001477 bool IsStringAccess() const { return is_string_access_; }
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00001478 bool IsFunctionPrototype() const { return is_function_prototype_; }
1479
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001480 // Type feedback information.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001481 void RecordTypeFeedback(TypeFeedbackOracle* oracle, Zone* zone);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001482 virtual bool IsMonomorphic() { return is_monomorphic_; }
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001483 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001484 bool IsArrayLength() { return is_array_length_; }
jkummerow@chromium.org531dfe82012-03-20 13:01:16 +00001485 bool IsUninitialized() { return is_uninitialized_; }
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001486 TypeFeedbackId PropertyFeedbackId() { return reuse(id()); }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001487
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001488 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001489 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.org471f2f12012-08-10 14:46:33 +00001497 load_id_(GetNextId(isolate)),
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001498 is_monomorphic_(false),
jkummerow@chromium.org531dfe82012-03-20 13:01:16 +00001499 is_uninitialized_(false),
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001500 is_array_length_(false),
1501 is_string_length_(false),
1502 is_string_access_(false),
1503 is_function_prototype_(false) { }
1504
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001505 private:
1506 Expression* obj_;
1507 Expression* key_;
1508 int pos_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001509 const BailoutId load_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001510
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001511 SmallMapList receiver_types_;
ager@chromium.org378b34e2011-01-28 08:04:38 +00001512 bool is_monomorphic_ : 1;
jkummerow@chromium.org531dfe82012-03-20 13:01:16 +00001513 bool is_uninitialized_ : 1;
ager@chromium.org378b34e2011-01-28 08:04:38 +00001514 bool is_array_length_ : 1;
1515 bool is_string_length_ : 1;
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00001516 bool is_string_access_ : 1;
ager@chromium.org378b34e2011-01-28 08:04:38 +00001517 bool is_function_prototype_ : 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001518};
1519
1520
1521class Call: public Expression {
1522 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001523 DECLARE_NODE_TYPE(Call)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001524
1525 Expression* expression() const { return expression_; }
1526 ZoneList<Expression*>* arguments() const { return arguments_; }
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001527 virtual int position() const { return pos_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001528
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001529 // Type feedback information.
1530 TypeFeedbackId CallFeedbackId() const { return reuse(id()); }
1531 void RecordTypeFeedback(TypeFeedbackOracle* oracle, CallKind call_kind);
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001532 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001533 virtual bool IsMonomorphic() { return is_monomorphic_; }
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001534 CheckType check_type() const { return check_type_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001535 Handle<JSFunction> target() { return target_; }
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00001536
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.orga5551262010-12-07 12:49:48 +00001540 Handle<JSObject> holder() { return holder_; }
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00001541
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001542 Handle<JSGlobalPropertyCell> cell() { return cell_; }
1543
1544 bool ComputeTarget(Handle<Map> type, Handle<String> name);
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001545 bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupResult* lookup);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001546
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001547 BailoutId ReturnId() const { return return_id_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001548
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001549#ifdef DEBUG
1550 // Used to assert that the FullCodeGenerator records the return site.
1551 bool return_is_recorded_;
1552#endif
1553
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001554 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001555 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.hansen43d26ec2008-07-03 15:10:15 +00001567 private:
1568 Expression* expression_;
1569 ZoneList<Expression*>* arguments_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001570 int pos_;
1571
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001572 bool is_monomorphic_;
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00001573 CheckType check_type_;
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001574 SmallMapList receiver_types_;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001575 Handle<JSFunction> target_;
1576 Handle<JSObject> holder_;
1577 Handle<JSGlobalPropertyCell> cell_;
1578
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001579 const BailoutId return_id_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001580};
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001581
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001582
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001583class CallNew: public Expression {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001584 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001585 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.org471f2f12012-08-10 14:46:33 +00001591 // Type feedback information.
1592 TypeFeedbackId CallNewFeedbackId() const { return reuse(id()); }
ulan@chromium.org967e2702012-02-28 09:49:15 +00001593 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1594 virtual bool IsMonomorphic() { return is_monomorphic_; }
1595 Handle<JSFunction> target() { return target_; }
1596
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001597 BailoutId ReturnId() const { return return_id_; }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001598 ElementsKind elements_kind() const { return elements_kind_; }
ulan@chromium.org967e2702012-02-28 09:49:15 +00001599
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001600 protected:
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001601 CallNew(Isolate* isolate,
1602 Expression* expression,
1603 ZoneList<Expression*>* arguments,
1604 int pos)
1605 : Expression(isolate),
1606 expression_(expression),
1607 arguments_(arguments),
ulan@chromium.org967e2702012-02-28 09:49:15 +00001608 pos_(pos),
1609 is_monomorphic_(false),
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001610 return_id_(GetNextId(isolate)),
1611 elements_kind_(GetInitialFastElementsKind()) { }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00001612
ager@chromium.orga74f0da2008-12-03 16:05:52 +00001613 private:
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001614 Expression* expression_;
1615 ZoneList<Expression*>* arguments_;
1616 int pos_;
ulan@chromium.org967e2702012-02-28 09:49:15 +00001617
1618 bool is_monomorphic_;
1619 Handle<JSFunction> target_;
1620
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001621 const BailoutId return_id_;
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +00001622 ElementsKind elements_kind_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001623};
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").
1630class CallRuntime: public Expression {
1631 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001632 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.org471f2f12012-08-10 14:46:33 +00001639 TypeFeedbackId CallRuntimeFeedbackId() const { return reuse(id()); }
1640
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001641 protected:
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001642 CallRuntime(Isolate* isolate,
1643 Handle<String> name,
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001644 const Runtime::Function* function,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001645 ZoneList<Expression*>* arguments)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001646 : Expression(isolate),
1647 name_(name),
1648 function_(function),
1649 arguments_(arguments) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001650
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001651 private:
1652 Handle<String> name_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001653 const Runtime::Function* function_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001654 ZoneList<Expression*>* arguments_;
1655};
1656
1657
1658class UnaryOperation: public Expression {
1659 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001660 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.org471f2f12012-08-10 14:46:33 +00001668 BailoutId MaterializeTrueId() { return materialize_true_id_; }
1669 BailoutId MaterializeFalseId() { return materialize_false_id_; }
1670
1671 TypeFeedbackId UnaryOperationFeedbackId() const { return reuse(id()); }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001672
1673 protected:
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001674 UnaryOperation(Isolate* isolate,
1675 Token::Value op,
1676 Expression* expression,
1677 int pos)
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001678 : Expression(isolate),
1679 op_(op),
1680 expression_(expression),
1681 pos_(pos),
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001682 materialize_true_id_(GetNextId(isolate)),
1683 materialize_false_id_(GetNextId(isolate)) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001684 ASSERT(Token::IsUnaryOp(op));
1685 }
1686
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001687 private:
1688 Token::Value op_;
1689 Expression* expression_;
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00001690 int pos_;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001691
1692 // For unary not (Token::NOT), the AST ids where true and false will
1693 // actually be materialized, respectively.
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001694 const BailoutId materialize_true_id_;
1695 const BailoutId materialize_false_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001696};
1697
1698
1699class BinaryOperation: public Expression {
1700 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001701 DECLARE_NODE_TYPE(BinaryOperation)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001702
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001703 virtual bool ResultOverwriteAllowed();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001704
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001705 Token::Value op() const { return op_; }
1706 Expression* left() const { return left_; }
1707 Expression* right() const { return right_; }
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001708 virtual int position() const { return pos_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001709
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001710 BailoutId RightId() const { return right_id_; }
1711
1712 TypeFeedbackId BinaryOperationFeedbackId() const { return reuse(id()); }
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001713
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001714 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001715 BinaryOperation(Isolate* isolate,
1716 Token::Value op,
1717 Expression* left,
1718 Expression* right,
1719 int pos)
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001720 : Expression(isolate),
1721 op_(op),
1722 left_(left),
1723 right_(right),
1724 pos_(pos),
1725 right_id_(GetNextId(isolate)) {
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001726 ASSERT(Token::IsBinaryOp(op));
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001727 }
1728
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001729 private:
1730 Token::Value op_;
1731 Expression* left_;
1732 Expression* right_;
ricow@chromium.org65fae842010-08-25 15:26:24 +00001733 int pos_;
yangguo@chromium.org304cc332012-07-24 07:59:48 +00001734 // The short-circuit logical operations need an AST ID for their
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001735 // right-hand subexpression.
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001736 const BailoutId right_id_;
ricow@chromium.org65fae842010-08-25 15:26:24 +00001737};
1738
1739
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001740class CountOperation: public Expression {
1741 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001742 DECLARE_NODE_TYPE(CountOperation)
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001743
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001744 bool is_prefix() const { return is_prefix_; }
1745 bool is_postfix() const { return !is_prefix_; }
ricow@chromium.org65fae842010-08-25 15:26:24 +00001746
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001747 Token::Value op() const { return op_; }
kasperl@chromium.org74e4e5e2010-01-25 10:15:52 +00001748 Token::Value binary_op() {
ricow@chromium.org65fae842010-08-25 15:26:24 +00001749 return (op() == Token::INC) ? Token::ADD : Token::SUB;
kasperl@chromium.org74e4e5e2010-01-25 10:15:52 +00001750 }
ricow@chromium.org65fae842010-08-25 15:26:24 +00001751
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001752 Expression* expression() const { return expression_; }
1753 virtual int position() const { return pos_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001754
1755 virtual void MarkAsStatement() { is_prefix_ = true; }
1756
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001757 void RecordTypeFeedback(TypeFeedbackOracle* oracle, Zone* znoe);
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001758 virtual bool IsMonomorphic() { return is_monomorphic_; }
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001759 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001760
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001761 BailoutId AssignmentId() const { return assignment_id_; }
1762
1763 TypeFeedbackId CountBinOpFeedbackId() const { return count_id_; }
1764 TypeFeedbackId CountStoreFeedbackId() const { return reuse(id()); }
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001765
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001766 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001767 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.hansen43d26ec2008-07-03 15:10:15 +00001780 private:
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001781 Token::Value op_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001782 bool is_prefix_;
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001783 bool is_monomorphic_;
1784 Expression* expression_;
ricow@chromium.org65fae842010-08-25 15:26:24 +00001785 int pos_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001786 const BailoutId assignment_id_;
1787 const TypeFeedbackId count_id_;
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001788 SmallMapList receiver_types_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001789};
1790
1791
1792class CompareOperation: public Expression {
1793 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001794 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.org471f2f12012-08-10 14:46:33 +00001802 TypeFeedbackId CompareOperationFeedbackId() const { return reuse(id()); }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001803
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.org717967f2011-07-20 13:44:42 +00001810 CompareOperation(Isolate* isolate,
1811 Token::Value op,
ricow@chromium.org65fae842010-08-25 15:26:24 +00001812 Expression* left,
1813 Expression* right,
1814 int pos)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001815 : Expression(isolate),
1816 op_(op),
1817 left_(left),
1818 right_(right),
yangguo@chromium.orgfb377212012-11-16 14:43:43 +00001819 pos_(pos) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001820 ASSERT(Token::IsCompareOp(op));
1821 }
1822
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001823 private:
1824 Token::Value op_;
1825 Expression* left_;
1826 Expression* right_;
ricow@chromium.org65fae842010-08-25 15:26:24 +00001827 int pos_;
1828};
1829
1830
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001831class Conditional: public Expression {
1832 public:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001833 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.org471f2f12012-08-10 14:46:33 +00001842 BailoutId ThenId() const { return then_id_; }
1843 BailoutId ElseId() const { return else_id_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001844
1845 protected:
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001846 Conditional(Isolate* isolate,
1847 Expression* condition,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001848 Expression* then_expression,
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001849 Expression* else_expression,
1850 int then_expression_position,
1851 int else_expression_position)
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001852 : Expression(isolate),
1853 condition_(condition),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001854 then_expression_(then_expression),
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001855 else_expression_(else_expression),
1856 then_expression_position_(then_expression_position),
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001857 else_expression_position_(else_expression_position),
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001858 then_id_(GetNextId(isolate)),
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001859 else_id_(GetNextId(isolate)) { }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001860
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001861 private:
1862 Expression* condition_;
1863 Expression* then_expression_;
1864 Expression* else_expression_;
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001865 int then_expression_position_;
1866 int else_expression_position_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001867 const BailoutId then_id_;
1868 const BailoutId else_id_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001869};
1870
1871
1872class Assignment: public Expression {
1873 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001874 DECLARE_NODE_TYPE(Assignment)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001875
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001876 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
1877
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001878 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.org44bc7082011-04-11 12:33:05 +00001883 virtual int position() const { return pos_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001884 BinaryOperation* binary_operation() const { return binary_operation_; }
1885
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +00001886 // This check relies on the definition order of token in token.h.
1887 bool is_compound() const { return op() > Token::ASSIGN; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001888
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001889 BailoutId AssignmentId() const { return assignment_id_; }
1890
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001891 // Type feedback information.
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001892 TypeFeedbackId AssignmentFeedbackId() { return reuse(id()); }
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001893 void RecordTypeFeedback(TypeFeedbackOracle* oracle, Zone* zone);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001894 virtual bool IsMonomorphic() { return is_monomorphic_; }
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001895 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001896
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001897 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001898 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.orgb1df11d2012-02-08 10:26:21 +00001910 }
1911 }
1912
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001913 private:
1914 Token::Value op_;
1915 Expression* target_;
1916 Expression* value_;
1917 int pos_;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001918 BinaryOperation* binary_operation_;
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001919 const BailoutId assignment_id_;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001920
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001921 bool is_monomorphic_;
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00001922 SmallMapList receiver_types_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001923};
1924
1925
1926class Throw: public Expression {
1927 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001928 DECLARE_NODE_TYPE(Throw)
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001929
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001930 Expression* exception() const { return exception_; }
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001931 virtual int position() const { return pos_; }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001932
1933 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00001934 Throw(Isolate* isolate, Expression* exception, int pos)
1935 : Expression(isolate), exception_(exception), pos_(pos) {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001936
1937 private:
1938 Expression* exception_;
1939 int pos_;
1940};
1941
1942
1943class FunctionLiteral: public Expression {
1944 public:
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00001945 enum Type {
1946 ANONYMOUS_EXPRESSION,
1947 NAMED_EXPRESSION,
1948 DECLARATION
1949 };
1950
yangguo@chromium.org56454712012-02-16 15:33:53 +00001951 enum ParameterFlag {
1952 kNoDuplicateParameters = 0,
1953 kHasDuplicateParameters = 1
1954 };
1955
1956 enum IsFunctionFlag {
1957 kGlobalOrEval,
1958 kIsFunction
1959 };
1960
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00001961 enum IsParenthesizedFlag {
1962 kIsParenthesized,
1963 kNotParenthesized
1964 };
1965
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00001966 DECLARE_NODE_TYPE(FunctionLiteral)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001967
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001968 Handle<String> name() const { return name_; }
1969 Scope* scope() const { return scope_; }
1970 ZoneList<Statement*>* body() const { return body_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001971 void set_function_token_position(int pos) { function_token_position_ = pos; }
1972 int function_token_position() const { return function_token_position_; }
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001973 int start_position() const;
1974 int end_position() const;
yangguo@chromium.org56454712012-02-16 15:33:53 +00001975 int SourceSize() const { return end_position() - start_position(); }
danno@chromium.orgc612e022011-11-10 11:38:15 +00001976 bool is_expression() const { return IsExpression::decode(bitfield_); }
1977 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00001978 bool is_classic_mode() const { return language_mode() == CLASSIC_MODE; }
1979 LanguageMode language_mode() const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001980
1981 int materialized_literal_count() { return materialized_literal_count_; }
1982 int expected_property_count() { return expected_property_count_; }
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001983 int handler_count() { return handler_count_; }
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00001984 bool has_only_simple_this_property_assignments() {
danno@chromium.orgc612e022011-11-10 11:38:15 +00001985 return HasOnlySimpleThisPropertyAssignments::decode(bitfield_);
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00001986 }
1987 Handle<FixedArray> this_property_assignments() {
1988 return this_property_assignments_;
1989 }
danno@chromium.orgc612e022011-11-10 11:38:15 +00001990 int parameter_count() { return parameter_count_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001991
1992 bool AllowsLazyCompilation();
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00001993 bool AllowsLazyCompilationWithoutContext();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001994
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00001995 Handle<String> debug_name() const {
1996 if (name_->length() > 0) return name_;
1997 return inferred_name();
1998 }
1999
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00002000 Handle<String> inferred_name() const { return inferred_name_; }
kasperl@chromium.orgd1e3e722009-04-14 13:38:25 +00002001 void set_inferred_name(Handle<String> inferred_name) {
2002 inferred_name_ = inferred_name;
2003 }
2004
danno@chromium.orgc612e022011-11-10 11:38:15 +00002005 bool pretenure() { return Pretenure::decode(bitfield_); }
2006 void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
vegorov@chromium.org21b5e952010-11-23 10:24:40 +00002007
danno@chromium.orgc612e022011-11-10 11:38:15 +00002008 bool has_duplicate_parameters() {
2009 return HasDuplicateParameters::decode(bitfield_);
2010 }
whesse@chromium.org7b260152011-06-20 15:33:18 +00002011
yangguo@chromium.org56454712012-02-16 15:33:53 +00002012 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
2013
verwaest@chromium.orgde64f722012-08-16 15:44:54 +00002014 // 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.org471f2f12012-08-10 14:46:33 +00002019 bool is_parenthesized() {
2020 return IsParenthesized::decode(bitfield_) == kIsParenthesized;
2021 }
verwaest@chromium.orgde64f722012-08-16 15:44:54 +00002022 void set_parenthesized() {
2023 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
2024 }
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00002025
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002026 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.orgb1df11d2012-02-08 10:26:21 +00002033 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.org56454712012-02-16 15:33:53 +00002044 ParameterFlag has_duplicate_parameters,
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00002045 IsFunctionFlag is_function,
2046 IsParenthesizedFlag is_parenthesized)
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002047 : 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.org56454712012-02-16 15:33:53 +00002064 HasDuplicateParameters::encode(has_duplicate_parameters) |
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00002065 IsFunction::encode(is_function) |
2066 IsParenthesized::encode(is_parenthesized);
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002067 }
2068
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002069 private:
2070 Handle<String> name_;
2071 Scope* scope_;
2072 ZoneList<Statement*>* body_;
danno@chromium.orgc612e022011-11-10 11:38:15 +00002073 Handle<FixedArray> this_property_assignments_;
2074 Handle<String> inferred_name_;
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002075 AstProperties ast_properties_;
danno@chromium.orgc612e022011-11-10 11:38:15 +00002076
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002077 int materialized_literal_count_;
2078 int expected_property_count_;
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00002079 int handler_count_;
danno@chromium.orgc612e022011-11-10 11:38:15 +00002080 int parameter_count_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002081 int function_token_position_;
danno@chromium.orgc612e022011-11-10 11:38:15 +00002082
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.org56454712012-02-16 15:33:53 +00002088 class HasDuplicateParameters: public BitField<ParameterFlag, 4, 1> {};
2089 class IsFunction: public BitField<IsFunctionFlag, 5, 1> {};
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00002090 class IsParenthesized: public BitField<IsParenthesizedFlag, 6, 1> {};
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002091};
2092
2093
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00002094class SharedFunctionInfoLiteral: public Expression {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002095 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00002096 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral)
2097
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00002098 Handle<SharedFunctionInfo> shared_function_info() const {
2099 return shared_function_info_;
2100 }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002101
2102 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002103 SharedFunctionInfoLiteral(
2104 Isolate* isolate,
2105 Handle<SharedFunctionInfo> shared_function_info)
2106 : Expression(isolate),
2107 shared_function_info_(shared_function_info) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002108
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002109 private:
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00002110 Handle<SharedFunctionInfo> shared_function_info_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002111};
2112
2113
2114class ThisFunction: public Expression {
2115 public:
kmillikin@chromium.orgf05f2912010-09-30 10:07:24 +00002116 DECLARE_NODE_TYPE(ThisFunction)
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002117
2118 protected:
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002119 explicit ThisFunction(Isolate* isolate): Expression(isolate) {}
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002120};
2121
ulan@chromium.org65a89c22012-02-14 11:46:07 +00002122#undef DECLARE_NODE_TYPE
2123
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002124
2125// ----------------------------------------------------------------------------
2126// Regular expressions
2127
2128
ager@chromium.org32912102009-01-16 10:38:43 +00002129class 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.orga74f0da2008-12-03 16:05:52 +00002139class RegExpTree: public ZoneObject {
2140 public:
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002141 static const int kInfinity = kMaxInt;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002142 virtual ~RegExpTree() { }
2143 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
2144 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
ager@chromium.org8bb60582008-12-11 12:02:20 +00002145 RegExpNode* on_success) = 0;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002146 virtual bool IsTextElement() { return false; }
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00002147 virtual bool IsAnchoredAtStart() { return false; }
2148 virtual bool IsAnchoredAtEnd() { return false; }
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002149 virtual int min_match() = 0;
2150 virtual int max_match() = 0;
ager@chromium.org32912102009-01-16 10:38:43 +00002151 // Returns the interval of registers used for captures within this
2152 // expression.
2153 virtual Interval CaptureRegisters() { return Interval::Empty(); }
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002154 virtual void AppendToText(RegExpText* text, Zone* zone);
2155 SmartArrayPointer<const char> ToString(Zone* zone);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002156#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
2164class RegExpDisjunction: public RegExpTree {
2165 public:
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002166 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002167 virtual void* Accept(RegExpVisitor* visitor, void* data);
2168 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
ager@chromium.org8bb60582008-12-11 12:02:20 +00002169 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002170 virtual RegExpDisjunction* AsDisjunction();
ager@chromium.org32912102009-01-16 10:38:43 +00002171 virtual Interval CaptureRegisters();
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002172 virtual bool IsDisjunction();
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00002173 virtual bool IsAnchoredAtStart();
2174 virtual bool IsAnchoredAtEnd();
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002175 virtual int min_match() { return min_match_; }
2176 virtual int max_match() { return max_match_; }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002177 ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
2178 private:
2179 ZoneList<RegExpTree*>* alternatives_;
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002180 int min_match_;
2181 int max_match_;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002182};
2183
2184
2185class RegExpAlternative: public RegExpTree {
2186 public:
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002187 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002188 virtual void* Accept(RegExpVisitor* visitor, void* data);
2189 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
ager@chromium.org8bb60582008-12-11 12:02:20 +00002190 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002191 virtual RegExpAlternative* AsAlternative();
ager@chromium.org32912102009-01-16 10:38:43 +00002192 virtual Interval CaptureRegisters();
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002193 virtual bool IsAlternative();
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00002194 virtual bool IsAnchoredAtStart();
2195 virtual bool IsAnchoredAtEnd();
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002196 virtual int min_match() { return min_match_; }
2197 virtual int max_match() { return max_match_; }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002198 ZoneList<RegExpTree*>* nodes() { return nodes_; }
2199 private:
2200 ZoneList<RegExpTree*>* nodes_;
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002201 int min_match_;
2202 int max_match_;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002203};
2204
2205
2206class 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.org8bb60582008-12-11 12:02:20 +00002219 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002220 virtual RegExpAssertion* AsAssertion();
2221 virtual bool IsAssertion();
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00002222 virtual bool IsAnchoredAtStart();
2223 virtual bool IsAnchoredAtEnd();
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002224 virtual int min_match() { return 0; }
2225 virtual int max_match() { return 0; }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002226 Type type() { return type_; }
2227 private:
2228 Type type_;
2229};
2230
2231
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002232class 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.org7028c052012-06-13 11:51:58 +00002240 ZoneList<CharacterRange>* ranges(Zone* zone);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002241 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.org0c20e672010-01-14 15:28:53 +00002246 void Canonicalize();
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002247 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.orga74f0da2008-12-03 16:05:52 +00002255class RegExpCharacterClass: public RegExpTree {
2256 public:
2257 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002258 : set_(ranges),
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002259 is_negated_(is_negated) { }
2260 explicit RegExpCharacterClass(uc16 type)
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002261 : set_(type),
2262 is_negated_(false) { }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002263 virtual void* Accept(RegExpVisitor* visitor, void* data);
2264 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
ager@chromium.org8bb60582008-12-11 12:02:20 +00002265 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002266 virtual RegExpCharacterClass* AsCharacterClass();
2267 virtual bool IsCharacterClass();
2268 virtual bool IsTextElement() { return true; }
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002269 virtual int min_match() { return 1; }
2270 virtual int max_match() { return 1; }
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002271 virtual void AppendToText(RegExpText* text, Zone* zone);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002272 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.org7028c052012-06-13 11:51:58 +00002275 bool is_standard(Zone* zone);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002276 // 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.orgddb913d2009-01-27 10:01:48 +00002285 // . : non-unicode non-newline
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002286 // * : All characters
2287 uc16 standard_type() { return set_.standard_set_type(); }
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002288 ZoneList<CharacterRange>* ranges(Zone* zone) { return set_.ranges(zone); }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002289 bool is_negated() { return is_negated_; }
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00002290
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002291 private:
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002292 CharacterSet set_;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002293 bool is_negated_;
2294};
2295
2296
2297class 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.org8bb60582008-12-11 12:02:20 +00002302 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002303 virtual RegExpAtom* AsAtom();
2304 virtual bool IsAtom();
2305 virtual bool IsTextElement() { return true; }
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002306 virtual int min_match() { return data_.length(); }
2307 virtual int max_match() { return data_.length(); }
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002308 virtual void AppendToText(RegExpText* text, Zone* zone);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002309 Vector<const uc16> data() { return data_; }
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002310 int length() { return data_.length(); }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002311 private:
2312 Vector<const uc16> data_;
2313};
2314
2315
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002316class RegExpText: public RegExpTree {
2317 public:
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002318 explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002319 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.org7028c052012-06-13 11:51:58 +00002327 virtual void AppendToText(RegExpText* text, Zone* zone);
2328 void AddElement(TextElement elm, Zone* zone) {
2329 elements_.Add(elm, zone);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002330 length_ += elm.length();
kmillikin@chromium.org3cdd9e12010-09-06 11:39:48 +00002331 }
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002332 ZoneList<TextElement>* elements() { return &elements_; }
2333 private:
2334 ZoneList<TextElement> elements_;
2335 int length_;
2336};
2337
2338
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002339class RegExpQuantifier: public RegExpTree {
2340 public:
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002341 enum Type { GREEDY, NON_GREEDY, POSSESSIVE };
2342 RegExpQuantifier(int min, int max, Type type, RegExpTree* body)
2343 : body_(body),
2344 min_(min),
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002345 max_(max),
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002346 min_match_(min * body->min_match()),
2347 type_(type) {
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002348 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.orga74f0da2008-12-03 16:05:52 +00002354 virtual void* Accept(RegExpVisitor* visitor, void* data);
2355 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
ager@chromium.org8bb60582008-12-11 12:02:20 +00002356 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002357 static RegExpNode* ToNode(int min,
2358 int max,
2359 bool is_greedy,
2360 RegExpTree* body,
2361 RegExpCompiler* compiler,
iposva@chromium.org245aa852009-02-10 00:49:54 +00002362 RegExpNode* on_success,
2363 bool not_at_start = false);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002364 virtual RegExpQuantifier* AsQuantifier();
ager@chromium.org32912102009-01-16 10:38:43 +00002365 virtual Interval CaptureRegisters();
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002366 virtual bool IsQuantifier();
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002367 virtual int min_match() { return min_match_; }
2368 virtual int max_match() { return max_match_; }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002369 int min() { return min_; }
2370 int max() { return max_; }
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002371 bool is_possessive() { return type_ == POSSESSIVE; }
2372 bool is_non_greedy() { return type_ == NON_GREEDY; }
2373 bool is_greedy() { return type_ == GREEDY; }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002374 RegExpTree* body() { return body_; }
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00002375
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002376 private:
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002377 RegExpTree* body_;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002378 int min_;
2379 int max_;
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002380 int min_match_;
2381 int max_match_;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002382 Type type_;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002383};
2384
2385
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002386class RegExpCapture: public RegExpTree {
2387 public:
2388 explicit RegExpCapture(RegExpTree* body, int index)
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002389 : body_(body), index_(index) { }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002390 virtual void* Accept(RegExpVisitor* visitor, void* data);
2391 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
ager@chromium.org8bb60582008-12-11 12:02:20 +00002392 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002393 static RegExpNode* ToNode(RegExpTree* body,
2394 int index,
2395 RegExpCompiler* compiler,
ager@chromium.org8bb60582008-12-11 12:02:20 +00002396 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002397 virtual RegExpCapture* AsCapture();
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00002398 virtual bool IsAnchoredAtStart();
2399 virtual bool IsAnchoredAtEnd();
ager@chromium.org32912102009-01-16 10:38:43 +00002400 virtual Interval CaptureRegisters();
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002401 virtual bool IsCapture();
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002402 virtual int min_match() { return body_->min_match(); }
2403 virtual int max_match() { return body_->max_match(); }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002404 RegExpTree* body() { return body_; }
2405 int index() { return index_; }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002406 static int StartRegister(int index) { return index * 2; }
2407 static int EndRegister(int index) { return index * 2 + 1; }
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00002408
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002409 private:
2410 RegExpTree* body_;
2411 int index_;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002412};
2413
2414
2415class RegExpLookahead: public RegExpTree {
2416 public:
ager@chromium.orgddb913d2009-01-27 10:01:48 +00002417 RegExpLookahead(RegExpTree* body,
2418 bool is_positive,
2419 int capture_count,
2420 int capture_from)
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002421 : body_(body),
ager@chromium.orgddb913d2009-01-27 10:01:48 +00002422 is_positive_(is_positive),
2423 capture_count_(capture_count),
2424 capture_from_(capture_from) { }
2425
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002426 virtual void* Accept(RegExpVisitor* visitor, void* data);
2427 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
ager@chromium.org8bb60582008-12-11 12:02:20 +00002428 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002429 virtual RegExpLookahead* AsLookahead();
ager@chromium.org32912102009-01-16 10:38:43 +00002430 virtual Interval CaptureRegisters();
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002431 virtual bool IsLookahead();
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00002432 virtual bool IsAnchoredAtStart();
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002433 virtual int min_match() { return 0; }
2434 virtual int max_match() { return 0; }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002435 RegExpTree* body() { return body_; }
2436 bool is_positive() { return is_positive_; }
ager@chromium.orgddb913d2009-01-27 10:01:48 +00002437 int capture_count() { return capture_count_; }
2438 int capture_from() { return capture_from_; }
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00002439
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002440 private:
2441 RegExpTree* body_;
2442 bool is_positive_;
ager@chromium.orgddb913d2009-01-27 10:01:48 +00002443 int capture_count_;
2444 int capture_from_;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002445};
2446
2447
2448class 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.org8bb60582008-12-11 12:02:20 +00002454 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002455 virtual RegExpBackReference* AsBackReference();
2456 virtual bool IsBackReference();
ager@chromium.org32912102009-01-16 10:38:43 +00002457 virtual int min_match() { return 0; }
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002458 virtual int max_match() { return capture_->max_match(); }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002459 int index() { return capture_->index(); }
2460 RegExpCapture* capture() { return capture_; }
2461 private:
2462 RegExpCapture* capture_;
2463};
2464
2465
2466class RegExpEmpty: public RegExpTree {
2467 public:
2468 RegExpEmpty() { }
2469 virtual void* Accept(RegExpVisitor* visitor, void* data);
2470 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
ager@chromium.org8bb60582008-12-11 12:02:20 +00002471 RegExpNode* on_success);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002472 virtual RegExpEmpty* AsEmpty();
2473 virtual bool IsEmpty();
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +00002474 virtual int min_match() { return 0; }
2475 virtual int max_match() { return 0; }
erikcorry0ad885c2011-11-21 13:51:57 +00002476 static RegExpEmpty* GetInstance() {
2477 static RegExpEmpty* instance = ::new RegExpEmpty();
2478 return instance;
2479 }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002480};
2481
2482
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002483// ----------------------------------------------------------------------------
erik.corry@gmail.combbceb572012-03-09 10:52:05 +00002484// Out-of-line inline constructors (to side-step cyclic dependencies).
2485
2486inline ModuleVariable::ModuleVariable(VariableProxy* proxy)
2487 : Module(proxy->interface()),
2488 proxy_(proxy) {
2489}
2490
2491
2492// ----------------------------------------------------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002493// Basic visitor
2494// - leaf node visitors are abstract.
2495
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002496class AstVisitor BASE_EMBEDDED {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002497 public:
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +00002498 AstVisitor() {}
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002499 virtual ~AstVisitor() { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002500
lrn@chromium.org25156de2010-04-06 13:10:27 +00002501 // Stack overflow check and dynamic dispatch.
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +00002502 virtual void Visit(AstNode* node) = 0;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002503
lrn@chromium.org25156de2010-04-06 13:10:27 +00002504 // Iteration left-to-right.
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002505 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002506 virtual void VisitStatements(ZoneList<Statement*>* statements);
2507 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
2508
kasperl@chromium.orga5551262010-12-07 12:49:48 +00002509 // Individual AST nodes.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002510#define DEF_VISIT(type) \
2511 virtual void Visit##type(type* node) = 0;
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00002512 AST_NODE_LIST(DEF_VISIT)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002513#undef DEF_VISIT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002514};
2515
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002516
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +00002517#define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
2518public: \
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 \
2534private: \
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.orgb1df11d2012-02-08 10:26:21 +00002545// ----------------------------------------------------------------------------
2546// Construction time visitor.
2547
2548class 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
2570class 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
2584template<class Visitor>
2585class AstNodeFactory BASE_EMBEDDED {
2586 public:
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00002587 AstNodeFactory(Isolate* isolate, Zone* zone)
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002588 : isolate_(isolate),
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00002589 zone_(zone) { }
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002590
2591 Visitor* visitor() { return &visitor_; }
2592
2593#define VISIT_AND_RETURN(NodeType, node) \
2594 visitor_.Visit##NodeType((node)); \
2595 return node;
2596
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00002597 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
2598 VariableMode mode,
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00002599 Scope* scope) {
2600 VariableDeclaration* decl =
ulan@chromium.org812308e2012-02-29 15:58:45 +00002601 new(zone_) VariableDeclaration(proxy, mode, scope);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00002602 VISIT_AND_RETURN(VariableDeclaration, decl)
2603 }
2604
ulan@chromium.org812308e2012-02-29 15:58:45 +00002605 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.org78d1ad42012-02-09 13:53:47 +00002614 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.org812308e2012-02-29 15:58:45 +00002622 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.combbceb572012-03-09 10:52:05 +00002637 ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface) {
2638 ModuleLiteral* module = new(zone_) ModuleLiteral(body, interface);
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00002639 VISIT_AND_RETURN(ModuleLiteral, module)
2640 }
2641
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002642 ModuleVariable* NewModuleVariable(VariableProxy* proxy) {
2643 ModuleVariable* module = new(zone_) ModuleVariable(proxy);
2644 VISIT_AND_RETURN(ModuleVariable, module)
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00002645 }
2646
2647 ModulePath* NewModulePath(Module* origin, Handle<String> name) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002648 ModulePath* module = new(zone_) ModulePath(origin, name, zone_);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002649 VISIT_AND_RETURN(ModulePath, module)
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00002650 }
2651
2652 ModuleUrl* NewModuleUrl(Handle<String> url) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002653 ModuleUrl* module = new(zone_) ModuleUrl(url, zone_);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002654 VISIT_AND_RETURN(ModuleUrl, module)
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00002655 }
2656
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002657 Block* NewBlock(ZoneStringList* labels,
2658 int capacity,
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00002659 bool is_initializer_block) {
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002660 Block* block = new(zone_) Block(
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00002661 isolate_, labels, capacity, is_initializer_block, zone_);
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002662 VISIT_AND_RETURN(Block, block)
2663 }
2664
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002665#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.org8e8d8822012-11-23 14:36:46 +00002677 ModuleStatement* NewModuleStatement(VariableProxy* proxy, Block* body) {
2678 ModuleStatement* stmt = new(zone_) ModuleStatement(proxy, body);
2679 VISIT_AND_RETURN(ModuleStatement, stmt)
2680 }
2681
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002682 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.org28583c92012-07-16 11:31:55 +00002799 Interface* interface = Interface::NewValue(),
2800 int position = RelocInfo::kNoPosition) {
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002801 VariableProxy* proxy =
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00002802 new(zone_) VariableProxy(isolate_, name, is_this, interface, position);
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002803 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.org56454712012-02-16 15:33:53 +00002904 FunctionLiteral::ParameterFlag has_duplicate_parameters,
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002905 FunctionLiteral::Type type,
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +00002906 FunctionLiteral::IsFunctionFlag is_function,
2907 FunctionLiteral::IsParenthesizedFlag is_parenthesized) {
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002908 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.org471f2f12012-08-10 14:46:33 +00002912 parameter_count, type, has_duplicate_parameters, is_function,
2913 is_parenthesized);
yangguo@chromium.org56454712012-02-16 15:33:53 +00002914 // Top-level literal doesn't count for the AST's properties.
2915 if (is_function == FunctionLiteral::kIsFunction) {
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00002916 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.hansen43d26ec2008-07-03 15:10:15 +00002942} } // namespace v8::internal
2943
2944#endif // V8_AST_H_