1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
10 #include "src/assembler.h"
11 #include "src/ast-value-factory.h"
12 #include "src/bailout-reason.h"
13 #include "src/factory.h"
14 #include "src/isolate.h"
15 #include "src/jsregexp.h"
16 #include "src/list-inl.h"
17 #include "src/modules.h"
18 #include "src/runtime/runtime.h"
19 #include "src/small-pointer-list.h"
20 #include "src/smart-pointers.h"
21 #include "src/token.h"
22 #include "src/types.h"
23 #include "src/utils.h"
24 #include "src/variables.h"
29 // The abstract syntax tree is an intermediate, light-weight
30 // representation of the parsed JavaScript code suitable for
31 // compilation to native code.
33 // Nodes are allocated in a separate zone, which allows faster
34 // allocation and constant-time deallocation of the entire syntax
38 // ----------------------------------------------------------------------------
39 // Nodes of the abstract syntax tree. Only concrete classes are
42 #define DECLARATION_NODE_LIST(V) \
43 V(VariableDeclaration) \
44 V(FunctionDeclaration) \
45 V(ModuleDeclaration) \
46 V(ImportDeclaration) \
49 #define MODULE_NODE_LIST(V) \
54 #define STATEMENT_NODE_LIST(V) \
57 V(ExpressionStatement) \
60 V(ContinueStatement) \
70 V(TryCatchStatement) \
71 V(TryFinallyStatement) \
74 #define EXPRESSION_NODE_LIST(V) \
77 V(NativeFunctionLiteral) \
99 #define AST_NODE_LIST(V) \
100 DECLARATION_NODE_LIST(V) \
101 MODULE_NODE_LIST(V) \
102 STATEMENT_NODE_LIST(V) \
103 EXPRESSION_NODE_LIST(V)
105 // Forward declarations
106 class AstNodeFactory;
110 class BreakableStatement;
112 class IterationStatement;
113 class MaterializedLiteral;
115 class TypeFeedbackOracle;
117 class RegExpAlternative;
118 class RegExpAssertion;
120 class RegExpBackReference;
122 class RegExpCharacterClass;
123 class RegExpCompiler;
124 class RegExpDisjunction;
126 class RegExpLookahead;
127 class RegExpQuantifier;
130 #define DEF_FORWARD_DECLARATION(type) class type;
131 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
132 #undef DEF_FORWARD_DECLARATION
135 // Typedef only introduced to avoid unreadable code.
136 // Please do appreciate the required space in "> >".
137 typedef ZoneList<Handle<String> > ZoneStringList;
138 typedef ZoneList<Handle<Object> > ZoneObjectList;
141 #define DECLARE_NODE_TYPE(type) \
142 void Accept(AstVisitor* v) OVERRIDE; \
143 AstNode::NodeType node_type() const FINAL { return AstNode::k##type; } \
144 friend class AstNodeFactory;
147 enum AstPropertiesFlag {
154 class FeedbackVectorRequirements {
156 FeedbackVectorRequirements(int slots, int ic_slots)
157 : slots_(slots), ic_slots_(ic_slots) {}
159 int slots() const { return slots_; }
160 int ic_slots() const { return ic_slots_; }
168 class AstProperties FINAL BASE_EMBEDDED {
170 class Flags : public EnumSet<AstPropertiesFlag, int> {};
172 AstProperties() : node_count_(0) {}
174 Flags* flags() { return &flags_; }
175 int node_count() { return node_count_; }
176 void add_node_count(int count) { node_count_ += count; }
178 int slots() const { return spec_.slots(); }
179 void increase_slots(int count) { spec_.increase_slots(count); }
181 int ic_slots() const { return spec_.ic_slots(); }
182 void increase_ic_slots(int count) { spec_.increase_ic_slots(count); }
183 void SetKind(int ic_slot, Code::Kind kind) { spec_.SetKind(ic_slot, kind); }
184 const FeedbackVectorSpec& get_spec() const { return spec_; }
189 FeedbackVectorSpec spec_;
193 class AstNode: public ZoneObject {
195 #define DECLARE_TYPE_ENUM(type) k##type,
197 AST_NODE_LIST(DECLARE_TYPE_ENUM)
200 #undef DECLARE_TYPE_ENUM
202 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
204 explicit AstNode(int position): position_(position) {}
205 virtual ~AstNode() {}
207 virtual void Accept(AstVisitor* v) = 0;
208 virtual NodeType node_type() const = 0;
209 int position() const { return position_; }
211 // Type testing & conversion functions overridden by concrete subclasses.
212 #define DECLARE_NODE_FUNCTIONS(type) \
213 bool Is##type() const { return node_type() == AstNode::k##type; } \
215 return Is##type() ? reinterpret_cast<type*>(this) : NULL; \
217 const type* As##type() const { \
218 return Is##type() ? reinterpret_cast<const type*>(this) : NULL; \
220 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
221 #undef DECLARE_NODE_FUNCTIONS
223 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
224 virtual IterationStatement* AsIterationStatement() { return NULL; }
225 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
227 // The interface for feedback slots, with default no-op implementations for
228 // node types which don't actually have this. Note that this is conceptually
229 // not really nice, but multiple inheritance would introduce yet another
230 // vtable entry per node, something we don't want for space reasons.
231 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
233 return FeedbackVectorRequirements(0, 0);
235 virtual void SetFirstFeedbackSlot(FeedbackVectorSlot slot) { UNREACHABLE(); }
236 virtual void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) {
239 // Each ICSlot stores a kind of IC which the participating node should know.
240 virtual Code::Kind FeedbackICSlotKind(int index) {
242 return Code::NUMBER_OF_KINDS;
246 // Hidden to prevent accidental usage. It would have to load the
247 // current zone from the TLS.
248 void* operator new(size_t size);
250 friend class CaseClause; // Generates AST IDs.
256 class Statement : public AstNode {
258 explicit Statement(Zone* zone, int position) : AstNode(position) {}
260 bool IsEmpty() { return AsEmptyStatement() != NULL; }
261 virtual bool IsJump() const { return false; }
265 class SmallMapList FINAL {
268 SmallMapList(int capacity, Zone* zone) : list_(capacity, zone) {}
270 void Reserve(int capacity, Zone* zone) { list_.Reserve(capacity, zone); }
271 void Clear() { list_.Clear(); }
272 void Sort() { list_.Sort(); }
274 bool is_empty() const { return list_.is_empty(); }
275 int length() const { return list_.length(); }
277 void AddMapIfMissing(Handle<Map> map, Zone* zone) {
278 if (!Map::TryUpdate(map).ToHandle(&map)) return;
279 for (int i = 0; i < length(); ++i) {
280 if (at(i).is_identical_to(map)) return;
285 void FilterForPossibleTransitions(Map* root_map) {
286 for (int i = list_.length() - 1; i >= 0; i--) {
287 if (at(i)->FindRootMap() != root_map) {
288 list_.RemoveElement(list_.at(i));
293 void Add(Handle<Map> handle, Zone* zone) {
294 list_.Add(handle.location(), zone);
297 Handle<Map> at(int i) const {
298 return Handle<Map>(list_.at(i));
301 Handle<Map> first() const { return at(0); }
302 Handle<Map> last() const { return at(length() - 1); }
305 // The list stores pointers to Map*, that is Map**, so it's GC safe.
306 SmallPointerList<Map*> list_;
308 DISALLOW_COPY_AND_ASSIGN(SmallMapList);
312 class Expression : public AstNode {
315 // Not assigned a context yet, or else will not be visited during
318 // Evaluated for its side effects.
320 // Evaluated for its value (and side effects).
322 // Evaluated for control flow (and side effects).
326 virtual bool IsValidReferenceExpression() const { return false; }
328 // Helpers for ToBoolean conversion.
329 virtual bool ToBooleanIsTrue() const { return false; }
330 virtual bool ToBooleanIsFalse() const { return false; }
332 // Symbols that cannot be parsed as array indices are considered property
333 // names. We do not treat symbols that can be array indexes as property
334 // names because [] for string objects is handled only by keyed ICs.
335 virtual bool IsPropertyName() const { return false; }
337 // True iff the expression is a literal represented as a smi.
338 bool IsSmiLiteral() const;
340 // True iff the expression is a string literal.
341 bool IsStringLiteral() const;
343 // True iff the expression is the null literal.
344 bool IsNullLiteral() const;
346 // True if we can prove that the expression is the undefined literal.
347 bool IsUndefinedLiteral(Isolate* isolate) const;
349 // Expression type bounds
350 Bounds bounds() const { return bounds_; }
351 void set_bounds(Bounds bounds) { bounds_ = bounds; }
353 // Whether the expression is parenthesized
354 bool is_parenthesized() const {
355 return IsParenthesizedField::decode(bit_field_);
357 bool is_multi_parenthesized() const {
358 return IsMultiParenthesizedField::decode(bit_field_);
360 void increase_parenthesization_level() {
362 IsMultiParenthesizedField::update(bit_field_, is_parenthesized());
363 bit_field_ = IsParenthesizedField::update(bit_field_, true);
366 // Type feedback information for assignments and properties.
367 virtual bool IsMonomorphic() {
371 virtual SmallMapList* GetReceiverTypes() {
375 virtual KeyedAccessStoreMode GetStoreMode() const {
377 return STANDARD_STORE;
379 virtual IcCheckType GetKeyType() const {
384 // TODO(rossberg): this should move to its own AST node eventually.
385 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
386 byte to_boolean_types() const {
387 return ToBooleanTypesField::decode(bit_field_);
390 void set_base_id(int id) { base_id_ = id; }
391 static int num_ids() { return parent_num_ids() + 2; }
392 BailoutId id() const { return BailoutId(local_id(0)); }
393 TypeFeedbackId test_id() const { return TypeFeedbackId(local_id(1)); }
396 Expression(Zone* zone, int pos)
398 base_id_(BailoutId::None().ToInt()),
399 bounds_(Bounds::Unbounded(zone)),
401 static int parent_num_ids() { return 0; }
402 void set_to_boolean_types(byte types) {
403 bit_field_ = ToBooleanTypesField::update(bit_field_, types);
406 int base_id() const {
407 DCHECK(!BailoutId(base_id_).IsNone());
412 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
416 class ToBooleanTypesField : public BitField16<byte, 0, 8> {};
417 class IsParenthesizedField : public BitField16<bool, 8, 1> {};
418 class IsMultiParenthesizedField : public BitField16<bool, 9, 1> {};
420 // Ends with 16-bit field; deriving classes in turn begin with
421 // 16-bit fields for optimum packing efficiency.
425 class BreakableStatement : public Statement {
428 TARGET_FOR_ANONYMOUS,
429 TARGET_FOR_NAMED_ONLY
432 // The labels associated with this statement. May be NULL;
433 // if it is != NULL, guaranteed to contain at least one entry.
434 ZoneList<const AstRawString*>* labels() const { return labels_; }
436 // Type testing & conversion.
437 BreakableStatement* AsBreakableStatement() FINAL { return this; }
440 Label* break_target() { return &break_target_; }
443 bool is_target_for_anonymous() const {
444 return breakable_type_ == TARGET_FOR_ANONYMOUS;
447 void set_base_id(int id) { base_id_ = id; }
448 static int num_ids() { return parent_num_ids() + 2; }
449 BailoutId EntryId() const { return BailoutId(local_id(0)); }
450 BailoutId ExitId() const { return BailoutId(local_id(1)); }
453 BreakableStatement(Zone* zone, ZoneList<const AstRawString*>* labels,
454 BreakableType breakable_type, int position)
455 : Statement(zone, position),
457 breakable_type_(breakable_type),
458 base_id_(BailoutId::None().ToInt()) {
459 DCHECK(labels == NULL || labels->length() > 0);
461 static int parent_num_ids() { return 0; }
463 int base_id() const {
464 DCHECK(!BailoutId(base_id_).IsNone());
469 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
471 ZoneList<const AstRawString*>* labels_;
472 BreakableType breakable_type_;
478 class Block FINAL : public BreakableStatement {
480 DECLARE_NODE_TYPE(Block)
482 void AddStatement(Statement* statement, Zone* zone) {
483 statements_.Add(statement, zone);
486 ZoneList<Statement*>* statements() { return &statements_; }
487 bool is_initializer_block() const { return is_initializer_block_; }
489 static int num_ids() { return parent_num_ids() + 1; }
490 BailoutId DeclsId() const { return BailoutId(local_id(0)); }
492 bool IsJump() const OVERRIDE {
493 return !statements_.is_empty() && statements_.last()->IsJump()
494 && labels() == NULL; // Good enough as an approximation...
497 Scope* scope() const { return scope_; }
498 void set_scope(Scope* scope) { scope_ = scope; }
501 Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
502 bool is_initializer_block, int pos)
503 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos),
504 statements_(capacity, zone),
505 is_initializer_block_(is_initializer_block),
507 static int parent_num_ids() { return BreakableStatement::num_ids(); }
510 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
512 ZoneList<Statement*> statements_;
513 bool is_initializer_block_;
518 class Declaration : public AstNode {
520 VariableProxy* proxy() const { return proxy_; }
521 VariableMode mode() const { return mode_; }
522 Scope* scope() const { return scope_; }
523 virtual InitializationFlag initialization() const = 0;
524 virtual bool IsInlineable() const;
527 Declaration(Zone* zone, VariableProxy* proxy, VariableMode mode, Scope* scope,
529 : AstNode(pos), mode_(mode), proxy_(proxy), scope_(scope) {
530 DCHECK(IsDeclaredVariableMode(mode));
535 VariableProxy* proxy_;
537 // Nested scope from which the declaration originated.
542 class VariableDeclaration FINAL : public Declaration {
544 DECLARE_NODE_TYPE(VariableDeclaration)
546 InitializationFlag initialization() const OVERRIDE {
547 return mode() == VAR ? kCreatedInitialized : kNeedsInitialization;
551 VariableDeclaration(Zone* zone,
552 VariableProxy* proxy,
556 : Declaration(zone, proxy, mode, scope, pos) {
561 class FunctionDeclaration FINAL : public Declaration {
563 DECLARE_NODE_TYPE(FunctionDeclaration)
565 FunctionLiteral* fun() const { return fun_; }
566 InitializationFlag initialization() const OVERRIDE {
567 return kCreatedInitialized;
569 bool IsInlineable() const OVERRIDE;
572 FunctionDeclaration(Zone* zone,
573 VariableProxy* proxy,
575 FunctionLiteral* fun,
578 : Declaration(zone, proxy, mode, scope, pos),
580 DCHECK(mode == VAR || mode == LET || mode == CONST);
585 FunctionLiteral* fun_;
589 class ModuleDeclaration FINAL : public Declaration {
591 DECLARE_NODE_TYPE(ModuleDeclaration)
593 Module* module() const { return module_; }
594 InitializationFlag initialization() const OVERRIDE {
595 return kCreatedInitialized;
599 ModuleDeclaration(Zone* zone, VariableProxy* proxy, Module* module,
600 Scope* scope, int pos)
601 : Declaration(zone, proxy, CONST, scope, pos), module_(module) {}
608 class ImportDeclaration FINAL : public Declaration {
610 DECLARE_NODE_TYPE(ImportDeclaration)
612 Module* module() const { return module_; }
613 InitializationFlag initialization() const OVERRIDE {
614 return kCreatedInitialized;
618 ImportDeclaration(Zone* zone,
619 VariableProxy* proxy,
623 : Declaration(zone, proxy, LET, scope, pos),
632 class ExportDeclaration FINAL : public Declaration {
634 DECLARE_NODE_TYPE(ExportDeclaration)
636 InitializationFlag initialization() const OVERRIDE {
637 return kCreatedInitialized;
641 ExportDeclaration(Zone* zone, VariableProxy* proxy, Scope* scope, int pos)
642 : Declaration(zone, proxy, LET, scope, pos) {}
646 class Module : public AstNode {
648 ModuleDescriptor* descriptor() const { return descriptor_; }
649 Block* body() const { return body_; }
652 Module(Zone* zone, int pos)
653 : AstNode(pos), descriptor_(ModuleDescriptor::New(zone)), body_(NULL) {}
654 Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL)
655 : AstNode(pos), descriptor_(descriptor), body_(body) {}
658 ModuleDescriptor* descriptor_;
663 class ModuleLiteral FINAL : public Module {
665 DECLARE_NODE_TYPE(ModuleLiteral)
668 ModuleLiteral(Zone* zone, Block* body, ModuleDescriptor* descriptor, int pos)
669 : Module(zone, descriptor, pos, body) {}
673 class ModulePath FINAL : public Module {
675 DECLARE_NODE_TYPE(ModulePath)
677 Module* module() const { return module_; }
678 Handle<String> name() const { return name_->string(); }
681 ModulePath(Zone* zone, Module* module, const AstRawString* name, int pos)
682 : Module(zone, pos), module_(module), name_(name) {}
686 const AstRawString* name_;
690 class ModuleUrl FINAL : public Module {
692 DECLARE_NODE_TYPE(ModuleUrl)
694 Handle<String> url() const { return url_; }
697 ModuleUrl(Zone* zone, Handle<String> url, int pos)
698 : Module(zone, pos), url_(url) {
706 class ModuleStatement FINAL : public Statement {
708 DECLARE_NODE_TYPE(ModuleStatement)
710 Block* body() const { return body_; }
713 ModuleStatement(Zone* zone, Block* body, int pos)
714 : Statement(zone, pos), body_(body) {}
721 class IterationStatement : public BreakableStatement {
723 // Type testing & conversion.
724 IterationStatement* AsIterationStatement() FINAL { return this; }
726 Statement* body() const { return body_; }
728 static int num_ids() { return parent_num_ids() + 1; }
729 BailoutId OsrEntryId() const { return BailoutId(local_id(0)); }
730 virtual BailoutId ContinueId() const = 0;
731 virtual BailoutId StackCheckId() const = 0;
734 Label* continue_target() { return &continue_target_; }
737 IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
738 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
740 static int parent_num_ids() { return BreakableStatement::num_ids(); }
741 void Initialize(Statement* body) { body_ = body; }
744 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
747 Label continue_target_;
751 class DoWhileStatement FINAL : public IterationStatement {
753 DECLARE_NODE_TYPE(DoWhileStatement)
755 void Initialize(Expression* cond, Statement* body) {
756 IterationStatement::Initialize(body);
760 Expression* cond() const { return cond_; }
762 static int num_ids() { return parent_num_ids() + 2; }
763 BailoutId ContinueId() const OVERRIDE { return BailoutId(local_id(0)); }
764 BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); }
765 BailoutId BackEdgeId() const { return BailoutId(local_id(1)); }
768 DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
769 : IterationStatement(zone, labels, pos), cond_(NULL) {}
770 static int parent_num_ids() { return IterationStatement::num_ids(); }
773 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
779 class WhileStatement FINAL : public IterationStatement {
781 DECLARE_NODE_TYPE(WhileStatement)
783 void Initialize(Expression* cond, Statement* body) {
784 IterationStatement::Initialize(body);
788 Expression* cond() const { return cond_; }
790 static int num_ids() { return parent_num_ids() + 1; }
791 BailoutId ContinueId() const OVERRIDE { return EntryId(); }
792 BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
793 BailoutId BodyId() const { return BailoutId(local_id(0)); }
796 WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
797 : IterationStatement(zone, labels, pos), cond_(NULL) {}
798 static int parent_num_ids() { return IterationStatement::num_ids(); }
801 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
807 class ForStatement FINAL : public IterationStatement {
809 DECLARE_NODE_TYPE(ForStatement)
811 void Initialize(Statement* init,
815 IterationStatement::Initialize(body);
821 Statement* init() const { return init_; }
822 Expression* cond() const { return cond_; }
823 Statement* next() const { return next_; }
825 static int num_ids() { return parent_num_ids() + 2; }
826 BailoutId ContinueId() const OVERRIDE { return BailoutId(local_id(0)); }
827 BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
828 BailoutId BodyId() const { return BailoutId(local_id(1)); }
831 ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
832 : IterationStatement(zone, labels, pos),
836 static int parent_num_ids() { return IterationStatement::num_ids(); }
839 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
847 class ForEachStatement : public IterationStatement {
850 ENUMERATE, // for (each in subject) body;
851 ITERATE // for (each of subject) body;
854 void Initialize(Expression* each, Expression* subject, Statement* body) {
855 IterationStatement::Initialize(body);
860 Expression* each() const { return each_; }
861 Expression* subject() const { return subject_; }
864 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
865 : IterationStatement(zone, labels, pos), each_(NULL), subject_(NULL) {}
869 Expression* subject_;
873 class ForInStatement FINAL : public ForEachStatement {
875 DECLARE_NODE_TYPE(ForInStatement)
877 Expression* enumerable() const {
881 // Type feedback information.
882 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
883 Isolate* isolate) OVERRIDE {
884 return FeedbackVectorRequirements(1, 0);
886 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
887 for_in_feedback_slot_ = slot;
890 FeedbackVectorSlot ForInFeedbackSlot() {
891 DCHECK(!for_in_feedback_slot_.IsInvalid());
892 return for_in_feedback_slot_;
895 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
896 ForInType for_in_type() const { return for_in_type_; }
897 void set_for_in_type(ForInType type) { for_in_type_ = type; }
899 static int num_ids() { return parent_num_ids() + 5; }
900 BailoutId BodyId() const { return BailoutId(local_id(0)); }
901 BailoutId PrepareId() const { return BailoutId(local_id(1)); }
902 BailoutId EnumId() const { return BailoutId(local_id(2)); }
903 BailoutId ToObjectId() const { return BailoutId(local_id(3)); }
904 BailoutId AssignmentId() const { return BailoutId(local_id(4)); }
905 BailoutId ContinueId() const OVERRIDE { return EntryId(); }
906 BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
909 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
910 : ForEachStatement(zone, labels, pos),
911 for_in_type_(SLOW_FOR_IN),
912 for_in_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
913 static int parent_num_ids() { return ForEachStatement::num_ids(); }
916 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
918 ForInType for_in_type_;
919 FeedbackVectorSlot for_in_feedback_slot_;
923 class ForOfStatement FINAL : public ForEachStatement {
925 DECLARE_NODE_TYPE(ForOfStatement)
927 void Initialize(Expression* each,
930 Expression* assign_iterator,
931 Expression* next_result,
932 Expression* result_done,
933 Expression* assign_each) {
934 ForEachStatement::Initialize(each, subject, body);
935 assign_iterator_ = assign_iterator;
936 next_result_ = next_result;
937 result_done_ = result_done;
938 assign_each_ = assign_each;
941 Expression* iterable() const {
945 // iterator = subject[Symbol.iterator]()
946 Expression* assign_iterator() const {
947 return assign_iterator_;
950 // result = iterator.next() // with type check
951 Expression* next_result() const {
956 Expression* result_done() const {
960 // each = result.value
961 Expression* assign_each() const {
965 BailoutId ContinueId() const OVERRIDE { return EntryId(); }
966 BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); }
968 static int num_ids() { return parent_num_ids() + 1; }
969 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); }
972 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
973 : ForEachStatement(zone, labels, pos),
974 assign_iterator_(NULL),
977 assign_each_(NULL) {}
978 static int parent_num_ids() { return ForEachStatement::num_ids(); }
981 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
983 Expression* assign_iterator_;
984 Expression* next_result_;
985 Expression* result_done_;
986 Expression* assign_each_;
990 class ExpressionStatement FINAL : public Statement {
992 DECLARE_NODE_TYPE(ExpressionStatement)
994 void set_expression(Expression* e) { expression_ = e; }
995 Expression* expression() const { return expression_; }
996 bool IsJump() const OVERRIDE { return expression_->IsThrow(); }
999 ExpressionStatement(Zone* zone, Expression* expression, int pos)
1000 : Statement(zone, pos), expression_(expression) { }
1003 Expression* expression_;
1007 class JumpStatement : public Statement {
1009 bool IsJump() const FINAL { return true; }
1012 explicit JumpStatement(Zone* zone, int pos) : Statement(zone, pos) {}
1016 class ContinueStatement FINAL : public JumpStatement {
1018 DECLARE_NODE_TYPE(ContinueStatement)
1020 IterationStatement* target() const { return target_; }
1023 explicit ContinueStatement(Zone* zone, IterationStatement* target, int pos)
1024 : JumpStatement(zone, pos), target_(target) { }
1027 IterationStatement* target_;
1031 class BreakStatement FINAL : public JumpStatement {
1033 DECLARE_NODE_TYPE(BreakStatement)
1035 BreakableStatement* target() const { return target_; }
1038 explicit BreakStatement(Zone* zone, BreakableStatement* target, int pos)
1039 : JumpStatement(zone, pos), target_(target) { }
1042 BreakableStatement* target_;
1046 class ReturnStatement FINAL : public JumpStatement {
1048 DECLARE_NODE_TYPE(ReturnStatement)
1050 Expression* expression() const { return expression_; }
1053 explicit ReturnStatement(Zone* zone, Expression* expression, int pos)
1054 : JumpStatement(zone, pos), expression_(expression) { }
1057 Expression* expression_;
1061 class WithStatement FINAL : public Statement {
1063 DECLARE_NODE_TYPE(WithStatement)
1065 Scope* scope() { return scope_; }
1066 Expression* expression() const { return expression_; }
1067 Statement* statement() const { return statement_; }
1069 void set_base_id(int id) { base_id_ = id; }
1070 static int num_ids() { return parent_num_ids() + 1; }
1071 BailoutId EntryId() const { return BailoutId(local_id(0)); }
1074 WithStatement(Zone* zone, Scope* scope, Expression* expression,
1075 Statement* statement, int pos)
1076 : Statement(zone, pos),
1078 expression_(expression),
1079 statement_(statement),
1080 base_id_(BailoutId::None().ToInt()) {}
1081 static int parent_num_ids() { return 0; }
1083 int base_id() const {
1084 DCHECK(!BailoutId(base_id_).IsNone());
1089 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1092 Expression* expression_;
1093 Statement* statement_;
1098 class CaseClause FINAL : public Expression {
1100 DECLARE_NODE_TYPE(CaseClause)
1102 bool is_default() const { return label_ == NULL; }
1103 Expression* label() const {
1104 CHECK(!is_default());
1107 Label* body_target() { return &body_target_; }
1108 ZoneList<Statement*>* statements() const { return statements_; }
1110 static int num_ids() { return parent_num_ids() + 2; }
1111 BailoutId EntryId() const { return BailoutId(local_id(0)); }
1112 TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); }
1114 Type* compare_type() { return compare_type_; }
1115 void set_compare_type(Type* type) { compare_type_ = type; }
1118 static int parent_num_ids() { return Expression::num_ids(); }
1121 CaseClause(Zone* zone, Expression* label, ZoneList<Statement*>* statements,
1123 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1127 ZoneList<Statement*>* statements_;
1128 Type* compare_type_;
1132 class SwitchStatement FINAL : public BreakableStatement {
1134 DECLARE_NODE_TYPE(SwitchStatement)
1136 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
1141 Expression* tag() const { return tag_; }
1142 ZoneList<CaseClause*>* cases() const { return cases_; }
1145 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
1146 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
1152 ZoneList<CaseClause*>* cases_;
1156 // If-statements always have non-null references to their then- and
1157 // else-parts. When parsing if-statements with no explicit else-part,
1158 // the parser implicitly creates an empty statement. Use the
1159 // HasThenStatement() and HasElseStatement() functions to check if a
1160 // given if-statement has a then- or an else-part containing code.
1161 class IfStatement FINAL : public Statement {
1163 DECLARE_NODE_TYPE(IfStatement)
1165 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
1166 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
1168 Expression* condition() const { return condition_; }
1169 Statement* then_statement() const { return then_statement_; }
1170 Statement* else_statement() const { return else_statement_; }
1172 bool IsJump() const OVERRIDE {
1173 return HasThenStatement() && then_statement()->IsJump()
1174 && HasElseStatement() && else_statement()->IsJump();
1177 void set_base_id(int id) { base_id_ = id; }
1178 static int num_ids() { return parent_num_ids() + 3; }
1179 BailoutId IfId() const { return BailoutId(local_id(0)); }
1180 BailoutId ThenId() const { return BailoutId(local_id(1)); }
1181 BailoutId ElseId() const { return BailoutId(local_id(2)); }
1184 IfStatement(Zone* zone, Expression* condition, Statement* then_statement,
1185 Statement* else_statement, int pos)
1186 : Statement(zone, pos),
1187 condition_(condition),
1188 then_statement_(then_statement),
1189 else_statement_(else_statement),
1190 base_id_(BailoutId::None().ToInt()) {}
1191 static int parent_num_ids() { return 0; }
1193 int base_id() const {
1194 DCHECK(!BailoutId(base_id_).IsNone());
1199 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1201 Expression* condition_;
1202 Statement* then_statement_;
1203 Statement* else_statement_;
1208 class TryStatement : public Statement {
1210 int index() const { return index_; }
1211 Block* try_block() const { return try_block_; }
1214 TryStatement(Zone* zone, int index, Block* try_block, int pos)
1215 : Statement(zone, pos), index_(index), try_block_(try_block) {}
1218 // Unique (per-function) index of this handler. This is not an AST ID.
1225 class TryCatchStatement FINAL : public TryStatement {
1227 DECLARE_NODE_TYPE(TryCatchStatement)
1229 Scope* scope() { return scope_; }
1230 Variable* variable() { return variable_; }
1231 Block* catch_block() const { return catch_block_; }
1234 TryCatchStatement(Zone* zone,
1241 : TryStatement(zone, index, try_block, pos),
1243 variable_(variable),
1244 catch_block_(catch_block) {
1249 Variable* variable_;
1250 Block* catch_block_;
1254 class TryFinallyStatement FINAL : public TryStatement {
1256 DECLARE_NODE_TYPE(TryFinallyStatement)
1258 Block* finally_block() const { return finally_block_; }
1261 TryFinallyStatement(
1262 Zone* zone, int index, Block* try_block, Block* finally_block, int pos)
1263 : TryStatement(zone, index, try_block, pos),
1264 finally_block_(finally_block) { }
1267 Block* finally_block_;
1271 class DebuggerStatement FINAL : public Statement {
1273 DECLARE_NODE_TYPE(DebuggerStatement)
1275 void set_base_id(int id) { base_id_ = id; }
1276 static int num_ids() { return parent_num_ids() + 1; }
1277 BailoutId DebugBreakId() const { return BailoutId(local_id(0)); }
1280 explicit DebuggerStatement(Zone* zone, int pos)
1281 : Statement(zone, pos), base_id_(BailoutId::None().ToInt()) {}
1282 static int parent_num_ids() { return 0; }
1284 int base_id() const {
1285 DCHECK(!BailoutId(base_id_).IsNone());
1290 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1296 class EmptyStatement FINAL : public Statement {
1298 DECLARE_NODE_TYPE(EmptyStatement)
1301 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {}
1305 class Literal FINAL : public Expression {
1307 DECLARE_NODE_TYPE(Literal)
1309 bool IsPropertyName() const OVERRIDE { return value_->IsPropertyName(); }
1311 Handle<String> AsPropertyName() {
1312 DCHECK(IsPropertyName());
1313 return Handle<String>::cast(value());
1316 const AstRawString* AsRawPropertyName() {
1317 DCHECK(IsPropertyName());
1318 return value_->AsString();
1321 bool ToBooleanIsTrue() const OVERRIDE { return value()->BooleanValue(); }
1322 bool ToBooleanIsFalse() const OVERRIDE { return !value()->BooleanValue(); }
1324 Handle<Object> value() const { return value_->value(); }
1325 const AstValue* raw_value() const { return value_; }
1327 // Support for using Literal as a HashMap key. NOTE: Currently, this works
1328 // only for string and number literals!
1330 static bool Match(void* literal1, void* literal2);
1332 static int num_ids() { return parent_num_ids() + 1; }
1333 TypeFeedbackId LiteralFeedbackId() const {
1334 return TypeFeedbackId(local_id(0));
1338 Literal(Zone* zone, const AstValue* value, int position)
1339 : Expression(zone, position), value_(value) {}
1340 static int parent_num_ids() { return Expression::num_ids(); }
1343 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1345 const AstValue* value_;
1349 // Base class for literals that needs space in the corresponding JSFunction.
1350 class MaterializedLiteral : public Expression {
1352 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1354 int literal_index() { return literal_index_; }
1357 // only callable after initialization.
1358 DCHECK(depth_ >= 1);
1363 MaterializedLiteral(Zone* zone, int literal_index, int pos)
1364 : Expression(zone, pos),
1365 literal_index_(literal_index),
1369 // A materialized literal is simple if the values consist of only
1370 // constants and simple object and array literals.
1371 bool is_simple() const { return is_simple_; }
1372 void set_is_simple(bool is_simple) { is_simple_ = is_simple; }
1373 friend class CompileTimeValue;
1375 void set_depth(int depth) {
1380 // Populate the constant properties/elements fixed array.
1381 void BuildConstants(Isolate* isolate);
1382 friend class ArrayLiteral;
1383 friend class ObjectLiteral;
1385 // If the expression is a literal, return the literal value;
1386 // if the expression is a materialized literal and is simple return a
1387 // compile time value as encoded by CompileTimeValue::GetValue().
1388 // Otherwise, return undefined literal as the placeholder
1389 // in the object literal boilerplate.
1390 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate);
1399 // Property is used for passing information
1400 // about an object literal's properties from the parser
1401 // to the code generator.
1402 class ObjectLiteralProperty FINAL : public ZoneObject {
1405 CONSTANT, // Property with constant value (compile time).
1406 COMPUTED, // Property with computed value (execution time).
1407 MATERIALIZED_LITERAL, // Property value is a materialized literal.
1408 GETTER, SETTER, // Property is an accessor function.
1409 PROTOTYPE // Property is __proto__.
1412 Expression* key() { return key_; }
1413 Expression* value() { return value_; }
1414 Kind kind() { return kind_; }
1416 // Type feedback information.
1417 bool IsMonomorphic() { return !receiver_type_.is_null(); }
1418 Handle<Map> GetReceiverType() { return receiver_type_; }
1420 bool IsCompileTimeValue();
1422 void set_emit_store(bool emit_store);
1425 bool is_static() const { return is_static_; }
1426 bool is_computed_name() const { return is_computed_name_; }
1428 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; }
1431 friend class AstNodeFactory;
1433 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind,
1434 bool is_static, bool is_computed_name);
1435 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key,
1436 Expression* value, bool is_static,
1437 bool is_computed_name);
1445 bool is_computed_name_;
1446 Handle<Map> receiver_type_;
1450 // An object literal has a boilerplate object that is used
1451 // for minimizing the work when constructing it at runtime.
1452 class ObjectLiteral FINAL : public MaterializedLiteral {
1454 typedef ObjectLiteralProperty Property;
1456 DECLARE_NODE_TYPE(ObjectLiteral)
1458 Handle<FixedArray> constant_properties() const {
1459 return constant_properties_;
1461 ZoneList<Property*>* properties() const { return properties_; }
1462 bool fast_elements() const { return fast_elements_; }
1463 bool may_store_doubles() const { return may_store_doubles_; }
1464 bool has_function() const { return has_function_; }
1466 // Decide if a property should be in the object boilerplate.
1467 static bool IsBoilerplateProperty(Property* property);
1469 // Populate the constant properties fixed array.
1470 void BuildConstantProperties(Isolate* isolate);
1472 // Mark all computed expressions that are bound to a key that
1473 // is shadowed by a later occurrence of the same key. For the
1474 // marked expressions, no store code is emitted.
1475 void CalculateEmitStore(Zone* zone);
1477 // Assemble bitfield of flags for the CreateObjectLiteral helper.
1478 int ComputeFlags() const {
1479 int flags = fast_elements() ? kFastElements : kNoFlags;
1480 flags |= has_function() ? kHasFunction : kNoFlags;
1487 kHasFunction = 1 << 1
1490 struct Accessors: public ZoneObject {
1491 Accessors() : getter(NULL), setter(NULL) {}
1496 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1498 // Return an AST id for a property that is used in simulate instructions.
1499 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); }
1501 // Unlike other AST nodes, this number of bailout IDs allocated for an
1502 // ObjectLiteral can vary, so num_ids() is not a static method.
1503 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); }
1506 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index,
1507 int boilerplate_properties, bool has_function, int pos)
1508 : MaterializedLiteral(zone, literal_index, pos),
1509 properties_(properties),
1510 boilerplate_properties_(boilerplate_properties),
1511 fast_elements_(false),
1512 may_store_doubles_(false),
1513 has_function_(has_function) {}
1514 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1517 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1518 Handle<FixedArray> constant_properties_;
1519 ZoneList<Property*>* properties_;
1520 int boilerplate_properties_;
1521 bool fast_elements_;
1522 bool may_store_doubles_;
1527 // Node for capturing a regexp literal.
1528 class RegExpLiteral FINAL : public MaterializedLiteral {
1530 DECLARE_NODE_TYPE(RegExpLiteral)
1532 Handle<String> pattern() const { return pattern_->string(); }
1533 Handle<String> flags() const { return flags_->string(); }
1536 RegExpLiteral(Zone* zone, const AstRawString* pattern,
1537 const AstRawString* flags, int literal_index, int pos)
1538 : MaterializedLiteral(zone, literal_index, pos),
1545 const AstRawString* pattern_;
1546 const AstRawString* flags_;
1550 // An array literal has a literals object that is used
1551 // for minimizing the work when constructing it at runtime.
1552 class ArrayLiteral FINAL : public MaterializedLiteral {
1554 DECLARE_NODE_TYPE(ArrayLiteral)
1556 Handle<FixedArray> constant_elements() const { return constant_elements_; }
1557 ZoneList<Expression*>* values() const { return values_; }
1559 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); }
1561 // Return an AST id for an element that is used in simulate instructions.
1562 BailoutId GetIdForElement(int i) { return BailoutId(local_id(i + 1)); }
1564 // Unlike other AST nodes, this number of bailout IDs allocated for an
1565 // ArrayLiteral can vary, so num_ids() is not a static method.
1566 int num_ids() const { return parent_num_ids() + 1 + values()->length(); }
1568 // Populate the constant elements fixed array.
1569 void BuildConstantElements(Isolate* isolate);
1571 // Assemble bitfield of flags for the CreateArrayLiteral helper.
1572 int ComputeFlags() const {
1573 int flags = depth() == 1 ? kShallowElements : kNoFlags;
1574 flags |= ArrayLiteral::kDisableMementos;
1580 kShallowElements = 1,
1581 kDisableMementos = 1 << 1
1585 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, int literal_index,
1587 : MaterializedLiteral(zone, literal_index, pos), values_(values) {}
1588 static int parent_num_ids() { return MaterializedLiteral::num_ids(); }
1591 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1593 Handle<FixedArray> constant_elements_;
1594 ZoneList<Expression*>* values_;
1598 class VariableProxy FINAL : public Expression {
1600 DECLARE_NODE_TYPE(VariableProxy)
1602 bool IsValidReferenceExpression() const OVERRIDE {
1603 return !is_resolved() || var()->IsValidReference();
1606 bool IsArguments() const { return is_resolved() && var()->is_arguments(); }
1608 Handle<String> name() const { return raw_name()->string(); }
1609 const AstRawString* raw_name() const {
1610 return is_resolved() ? var_->raw_name() : raw_name_;
1613 Variable* var() const {
1614 DCHECK(is_resolved());
1617 void set_var(Variable* v) {
1618 DCHECK(!is_resolved());
1623 bool is_this() const { return IsThisField::decode(bit_field_); }
1625 bool is_assigned() const { return IsAssignedField::decode(bit_field_); }
1626 void set_is_assigned() {
1627 bit_field_ = IsAssignedField::update(bit_field_, true);
1630 bool is_resolved() const { return IsResolvedField::decode(bit_field_); }
1631 void set_is_resolved() {
1632 bit_field_ = IsResolvedField::update(bit_field_, true);
1635 int end_position() const { return end_position_; }
1637 // Bind this proxy to the variable var.
1638 void BindTo(Variable* var);
1640 bool UsesVariableFeedbackSlot() const {
1641 return FLAG_vector_ics && (var()->IsUnallocated() || var()->IsLookupSlot());
1644 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1645 Isolate* isolate) OVERRIDE {
1646 return FeedbackVectorRequirements(0, UsesVariableFeedbackSlot() ? 1 : 0);
1649 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
1650 variable_feedback_slot_ = slot;
1652 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; }
1653 FeedbackVectorICSlot VariableFeedbackSlot() {
1654 DCHECK(!UsesVariableFeedbackSlot() || !variable_feedback_slot_.IsInvalid());
1655 return variable_feedback_slot_;
1659 VariableProxy(Zone* zone, Variable* var, int start_position,
1662 VariableProxy(Zone* zone, const AstRawString* name, bool is_this,
1663 int start_position, int end_position);
1665 class IsThisField : public BitField8<bool, 0, 1> {};
1666 class IsAssignedField : public BitField8<bool, 1, 1> {};
1667 class IsResolvedField : public BitField8<bool, 2, 1> {};
1669 // Start with 16-bit (or smaller) field, which should get packed together
1670 // with Expression's trailing 16-bit field.
1672 FeedbackVectorICSlot variable_feedback_slot_;
1674 const AstRawString* raw_name_; // if !is_resolved_
1675 Variable* var_; // if is_resolved_
1677 // Position is stored in the AstNode superclass, but VariableProxy needs to
1678 // know its end position too (for error messages). It cannot be inferred from
1679 // the variable name length because it can contain escapes.
1684 class Property FINAL : public Expression {
1686 DECLARE_NODE_TYPE(Property)
1688 bool IsValidReferenceExpression() const OVERRIDE { return true; }
1690 Expression* obj() const { return obj_; }
1691 Expression* key() const { return key_; }
1693 static int num_ids() { return parent_num_ids() + 2; }
1694 BailoutId LoadId() const { return BailoutId(local_id(0)); }
1695 TypeFeedbackId PropertyFeedbackId() { return TypeFeedbackId(local_id(1)); }
1697 bool IsStringAccess() const {
1698 return IsStringAccessField::decode(bit_field_);
1701 // Type feedback information.
1702 bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; }
1703 SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; }
1704 KeyedAccessStoreMode GetStoreMode() const OVERRIDE { return STANDARD_STORE; }
1705 IcCheckType GetKeyType() const OVERRIDE {
1706 return KeyTypeField::decode(bit_field_);
1708 bool IsUninitialized() const {
1709 return !is_for_call() && HasNoTypeInformation();
1711 bool HasNoTypeInformation() const {
1712 return IsUninitializedField::decode(bit_field_);
1714 void set_is_uninitialized(bool b) {
1715 bit_field_ = IsUninitializedField::update(bit_field_, b);
1717 void set_is_string_access(bool b) {
1718 bit_field_ = IsStringAccessField::update(bit_field_, b);
1720 void set_key_type(IcCheckType key_type) {
1721 bit_field_ = KeyTypeField::update(bit_field_, key_type);
1723 void mark_for_call() {
1724 bit_field_ = IsForCallField::update(bit_field_, true);
1726 bool is_for_call() const { return IsForCallField::decode(bit_field_); }
1728 bool IsSuperAccess() {
1729 return obj()->IsSuperReference();
1732 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1733 Isolate* isolate) OVERRIDE {
1734 return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0);
1736 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
1737 property_feedback_slot_ = slot;
1739 Code::Kind FeedbackICSlotKind(int index) OVERRIDE {
1740 return key()->IsPropertyName() ? Code::LOAD_IC : Code::KEYED_LOAD_IC;
1743 FeedbackVectorICSlot PropertyFeedbackSlot() const {
1744 DCHECK(!FLAG_vector_ics || !property_feedback_slot_.IsInvalid());
1745 return property_feedback_slot_;
1749 Property(Zone* zone, Expression* obj, Expression* key, int pos)
1750 : Expression(zone, pos),
1751 bit_field_(IsForCallField::encode(false) |
1752 IsUninitializedField::encode(false) |
1753 IsStringAccessField::encode(false)),
1754 property_feedback_slot_(FeedbackVectorICSlot::Invalid()),
1757 static int parent_num_ids() { return Expression::num_ids(); }
1760 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1762 class IsForCallField : public BitField8<bool, 0, 1> {};
1763 class IsUninitializedField : public BitField8<bool, 1, 1> {};
1764 class IsStringAccessField : public BitField8<bool, 2, 1> {};
1765 class KeyTypeField : public BitField8<IcCheckType, 3, 1> {};
1767 FeedbackVectorICSlot property_feedback_slot_;
1770 SmallMapList receiver_types_;
1774 class Call FINAL : public Expression {
1776 DECLARE_NODE_TYPE(Call)
1778 Expression* expression() const { return expression_; }
1779 ZoneList<Expression*>* arguments() const { return arguments_; }
1781 // Type feedback information.
1782 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1783 Isolate* isolate) OVERRIDE;
1784 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
1785 ic_slot_or_slot_ = slot.ToInt();
1787 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
1788 ic_slot_or_slot_ = slot.ToInt();
1790 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::CALL_IC; }
1792 FeedbackVectorSlot CallFeedbackSlot() const {
1793 DCHECK(ic_slot_or_slot_ != FeedbackVectorSlot::Invalid().ToInt());
1794 return FeedbackVectorSlot(ic_slot_or_slot_);
1797 FeedbackVectorICSlot CallFeedbackICSlot() const {
1798 DCHECK(ic_slot_or_slot_ != FeedbackVectorICSlot::Invalid().ToInt());
1799 return FeedbackVectorICSlot(ic_slot_or_slot_);
1802 SmallMapList* GetReceiverTypes() OVERRIDE {
1803 if (expression()->IsProperty()) {
1804 return expression()->AsProperty()->GetReceiverTypes();
1809 bool IsMonomorphic() OVERRIDE {
1810 if (expression()->IsProperty()) {
1811 return expression()->AsProperty()->IsMonomorphic();
1813 return !target_.is_null();
1816 bool global_call() const {
1817 VariableProxy* proxy = expression_->AsVariableProxy();
1818 return proxy != NULL && proxy->var()->IsUnallocated();
1821 bool known_global_function() const {
1822 return global_call() && !target_.is_null();
1825 Handle<JSFunction> target() { return target_; }
1827 Handle<Cell> cell() { return cell_; }
1829 Handle<AllocationSite> allocation_site() { return allocation_site_; }
1831 void set_target(Handle<JSFunction> target) { target_ = target; }
1832 void set_allocation_site(Handle<AllocationSite> site) {
1833 allocation_site_ = site;
1835 bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupIterator* it);
1837 static int num_ids() { return parent_num_ids() + 2; }
1838 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1839 BailoutId EvalOrLookupId() const { return BailoutId(local_id(1)); }
1841 bool is_uninitialized() const {
1842 return IsUninitializedField::decode(bit_field_);
1844 void set_is_uninitialized(bool b) {
1845 bit_field_ = IsUninitializedField::update(bit_field_, b);
1857 // Helpers to determine how to handle the call.
1858 CallType GetCallType(Isolate* isolate) const;
1859 bool IsUsingCallFeedbackSlot(Isolate* isolate) const;
1860 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const;
1863 // Used to assert that the FullCodeGenerator records the return site.
1864 bool return_is_recorded_;
1868 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1870 : Expression(zone, pos),
1871 ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()),
1872 expression_(expression),
1873 arguments_(arguments),
1874 bit_field_(IsUninitializedField::encode(false)) {
1875 if (expression->IsProperty()) {
1876 expression->AsProperty()->mark_for_call();
1879 static int parent_num_ids() { return Expression::num_ids(); }
1882 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1884 // We store this as an integer because we don't know if we have a slot or
1885 // an ic slot until scoping time.
1886 int ic_slot_or_slot_;
1887 Expression* expression_;
1888 ZoneList<Expression*>* arguments_;
1889 Handle<JSFunction> target_;
1891 Handle<AllocationSite> allocation_site_;
1892 class IsUninitializedField : public BitField8<bool, 0, 1> {};
1897 class CallNew FINAL : public Expression {
1899 DECLARE_NODE_TYPE(CallNew)
1901 Expression* expression() const { return expression_; }
1902 ZoneList<Expression*>* arguments() const { return arguments_; }
1904 // Type feedback information.
1905 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1906 Isolate* isolate) OVERRIDE {
1907 return FeedbackVectorRequirements(FLAG_pretenuring_call_new ? 2 : 1, 0);
1909 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
1910 callnew_feedback_slot_ = slot;
1913 FeedbackVectorSlot CallNewFeedbackSlot() {
1914 DCHECK(!callnew_feedback_slot_.IsInvalid());
1915 return callnew_feedback_slot_;
1917 FeedbackVectorSlot AllocationSiteFeedbackSlot() {
1918 DCHECK(FLAG_pretenuring_call_new);
1919 return CallNewFeedbackSlot().next();
1922 bool IsMonomorphic() OVERRIDE { return is_monomorphic_; }
1923 Handle<JSFunction> target() const { return target_; }
1924 Handle<AllocationSite> allocation_site() const {
1925 return allocation_site_;
1928 static int num_ids() { return parent_num_ids() + 1; }
1929 static int feedback_slots() { return 1; }
1930 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1932 void set_allocation_site(Handle<AllocationSite> site) {
1933 allocation_site_ = site;
1935 void set_is_monomorphic(bool monomorphic) { is_monomorphic_ = monomorphic; }
1936 void set_target(Handle<JSFunction> target) { target_ = target; }
1939 CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1941 : Expression(zone, pos),
1942 expression_(expression),
1943 arguments_(arguments),
1944 is_monomorphic_(false),
1945 callnew_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
1947 static int parent_num_ids() { return Expression::num_ids(); }
1950 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1952 Expression* expression_;
1953 ZoneList<Expression*>* arguments_;
1954 bool is_monomorphic_;
1955 Handle<JSFunction> target_;
1956 Handle<AllocationSite> allocation_site_;
1957 FeedbackVectorSlot callnew_feedback_slot_;
1961 // The CallRuntime class does not represent any official JavaScript
1962 // language construct. Instead it is used to call a C or JS function
1963 // with a set of arguments. This is used from the builtins that are
1964 // implemented in JavaScript (see "v8natives.js").
1965 class CallRuntime FINAL : public Expression {
1967 DECLARE_NODE_TYPE(CallRuntime)
1969 Handle<String> name() const { return raw_name_->string(); }
1970 const AstRawString* raw_name() const { return raw_name_; }
1971 const Runtime::Function* function() const { return function_; }
1972 ZoneList<Expression*>* arguments() const { return arguments_; }
1973 bool is_jsruntime() const { return function_ == NULL; }
1975 // Type feedback information.
1976 bool HasCallRuntimeFeedbackSlot() const {
1977 return FLAG_vector_ics && is_jsruntime();
1979 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1980 Isolate* isolate) OVERRIDE {
1981 return FeedbackVectorRequirements(0, HasCallRuntimeFeedbackSlot() ? 1 : 0);
1983 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
1984 callruntime_feedback_slot_ = slot;
1986 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; }
1988 FeedbackVectorICSlot CallRuntimeFeedbackSlot() {
1989 DCHECK(!HasCallRuntimeFeedbackSlot() ||
1990 !callruntime_feedback_slot_.IsInvalid());
1991 return callruntime_feedback_slot_;
1994 static int num_ids() { return parent_num_ids() + 1; }
1995 TypeFeedbackId CallRuntimeFeedbackId() const {
1996 return TypeFeedbackId(local_id(0));
2000 CallRuntime(Zone* zone, const AstRawString* name,
2001 const Runtime::Function* function,
2002 ZoneList<Expression*>* arguments, int pos)
2003 : Expression(zone, pos),
2005 function_(function),
2006 arguments_(arguments),
2007 callruntime_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
2008 static int parent_num_ids() { return Expression::num_ids(); }
2011 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2013 const AstRawString* raw_name_;
2014 const Runtime::Function* function_;
2015 ZoneList<Expression*>* arguments_;
2016 FeedbackVectorICSlot callruntime_feedback_slot_;
2020 class UnaryOperation FINAL : public Expression {
2022 DECLARE_NODE_TYPE(UnaryOperation)
2024 Token::Value op() const { return op_; }
2025 Expression* expression() const { return expression_; }
2027 // For unary not (Token::NOT), the AST ids where true and false will
2028 // actually be materialized, respectively.
2029 static int num_ids() { return parent_num_ids() + 2; }
2030 BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); }
2031 BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); }
2033 virtual void RecordToBooleanTypeFeedback(
2034 TypeFeedbackOracle* oracle) OVERRIDE;
2037 UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos)
2038 : Expression(zone, pos), op_(op), expression_(expression) {
2039 DCHECK(Token::IsUnaryOp(op));
2041 static int parent_num_ids() { return Expression::num_ids(); }
2044 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2047 Expression* expression_;
2051 class BinaryOperation FINAL : public Expression {
2053 DECLARE_NODE_TYPE(BinaryOperation)
2055 Token::Value op() const { return static_cast<Token::Value>(op_); }
2056 Expression* left() const { return left_; }
2057 Expression* right() const { return right_; }
2058 Handle<AllocationSite> allocation_site() const { return allocation_site_; }
2059 void set_allocation_site(Handle<AllocationSite> allocation_site) {
2060 allocation_site_ = allocation_site;
2063 // The short-circuit logical operations need an AST ID for their
2064 // right-hand subexpression.
2065 static int num_ids() { return parent_num_ids() + 2; }
2066 BailoutId RightId() const { return BailoutId(local_id(0)); }
2068 TypeFeedbackId BinaryOperationFeedbackId() const {
2069 return TypeFeedbackId(local_id(1));
2071 Maybe<int> fixed_right_arg() const {
2072 return has_fixed_right_arg_ ? Maybe<int>(fixed_right_arg_value_)
2075 void set_fixed_right_arg(Maybe<int> arg) {
2076 has_fixed_right_arg_ = arg.has_value;
2077 if (arg.has_value) fixed_right_arg_value_ = arg.value;
2080 virtual void RecordToBooleanTypeFeedback(
2081 TypeFeedbackOracle* oracle) OVERRIDE;
2084 BinaryOperation(Zone* zone, Token::Value op, Expression* left,
2085 Expression* right, int pos)
2086 : Expression(zone, pos),
2087 op_(static_cast<byte>(op)),
2088 has_fixed_right_arg_(false),
2089 fixed_right_arg_value_(0),
2092 DCHECK(Token::IsBinaryOp(op));
2094 static int parent_num_ids() { return Expression::num_ids(); }
2097 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2099 const byte op_; // actually Token::Value
2100 // TODO(rossberg): the fixed arg should probably be represented as a Constant
2101 // type for the RHS. Currenty it's actually a Maybe<int>
2102 bool has_fixed_right_arg_;
2103 int fixed_right_arg_value_;
2106 Handle<AllocationSite> allocation_site_;
2110 class CountOperation FINAL : public Expression {
2112 DECLARE_NODE_TYPE(CountOperation)
2114 bool is_prefix() const { return IsPrefixField::decode(bit_field_); }
2115 bool is_postfix() const { return !is_prefix(); }
2117 Token::Value op() const { return TokenField::decode(bit_field_); }
2118 Token::Value binary_op() {
2119 return (op() == Token::INC) ? Token::ADD : Token::SUB;
2122 Expression* expression() const { return expression_; }
2124 bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; }
2125 SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; }
2126 IcCheckType GetKeyType() const OVERRIDE {
2127 return KeyTypeField::decode(bit_field_);
2129 KeyedAccessStoreMode GetStoreMode() const OVERRIDE {
2130 return StoreModeField::decode(bit_field_);
2132 Type* type() const { return type_; }
2133 void set_key_type(IcCheckType type) {
2134 bit_field_ = KeyTypeField::update(bit_field_, type);
2136 void set_store_mode(KeyedAccessStoreMode mode) {
2137 bit_field_ = StoreModeField::update(bit_field_, mode);
2139 void set_type(Type* type) { type_ = type; }
2141 static int num_ids() { return parent_num_ids() + 4; }
2142 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2143 BailoutId ToNumberId() const { return BailoutId(local_id(1)); }
2144 TypeFeedbackId CountBinOpFeedbackId() const {
2145 return TypeFeedbackId(local_id(2));
2147 TypeFeedbackId CountStoreFeedbackId() const {
2148 return TypeFeedbackId(local_id(3));
2152 CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr,
2154 : Expression(zone, pos),
2155 bit_field_(IsPrefixField::encode(is_prefix) |
2156 KeyTypeField::encode(ELEMENT) |
2157 StoreModeField::encode(STANDARD_STORE) |
2158 TokenField::encode(op)),
2160 expression_(expr) {}
2161 static int parent_num_ids() { return Expression::num_ids(); }
2164 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2166 class IsPrefixField : public BitField16<bool, 0, 1> {};
2167 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2168 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2169 class TokenField : public BitField16<Token::Value, 6, 8> {};
2171 // Starts with 16-bit field, which should get packed together with
2172 // Expression's trailing 16-bit field.
2173 uint16_t bit_field_;
2175 Expression* expression_;
2176 SmallMapList receiver_types_;
2180 class CompareOperation FINAL : public Expression {
2182 DECLARE_NODE_TYPE(CompareOperation)
2184 Token::Value op() const { return op_; }
2185 Expression* left() const { return left_; }
2186 Expression* right() const { return right_; }
2188 // Type feedback information.
2189 static int num_ids() { return parent_num_ids() + 1; }
2190 TypeFeedbackId CompareOperationFeedbackId() const {
2191 return TypeFeedbackId(local_id(0));
2193 Type* combined_type() const { return combined_type_; }
2194 void set_combined_type(Type* type) { combined_type_ = type; }
2196 // Match special cases.
2197 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
2198 bool IsLiteralCompareUndefined(Expression** expr, Isolate* isolate);
2199 bool IsLiteralCompareNull(Expression** expr);
2202 CompareOperation(Zone* zone, Token::Value op, Expression* left,
2203 Expression* right, int pos)
2204 : Expression(zone, pos),
2208 combined_type_(Type::None(zone)) {
2209 DCHECK(Token::IsCompareOp(op));
2211 static int parent_num_ids() { return Expression::num_ids(); }
2214 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2220 Type* combined_type_;
2224 class Conditional FINAL : public Expression {
2226 DECLARE_NODE_TYPE(Conditional)
2228 Expression* condition() const { return condition_; }
2229 Expression* then_expression() const { return then_expression_; }
2230 Expression* else_expression() const { return else_expression_; }
2232 static int num_ids() { return parent_num_ids() + 2; }
2233 BailoutId ThenId() const { return BailoutId(local_id(0)); }
2234 BailoutId ElseId() const { return BailoutId(local_id(1)); }
2237 Conditional(Zone* zone, Expression* condition, Expression* then_expression,
2238 Expression* else_expression, int position)
2239 : Expression(zone, position),
2240 condition_(condition),
2241 then_expression_(then_expression),
2242 else_expression_(else_expression) {}
2243 static int parent_num_ids() { return Expression::num_ids(); }
2246 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2248 Expression* condition_;
2249 Expression* then_expression_;
2250 Expression* else_expression_;
2254 class Assignment FINAL : public Expression {
2256 DECLARE_NODE_TYPE(Assignment)
2258 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
2260 Token::Value binary_op() const;
2262 Token::Value op() const { return TokenField::decode(bit_field_); }
2263 Expression* target() const { return target_; }
2264 Expression* value() const { return value_; }
2265 BinaryOperation* binary_operation() const { return binary_operation_; }
2267 // This check relies on the definition order of token in token.h.
2268 bool is_compound() const { return op() > Token::ASSIGN; }
2270 static int num_ids() { return parent_num_ids() + 2; }
2271 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2273 // Type feedback information.
2274 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); }
2275 bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; }
2276 bool IsUninitialized() const {
2277 return IsUninitializedField::decode(bit_field_);
2279 bool HasNoTypeInformation() {
2280 return IsUninitializedField::decode(bit_field_);
2282 SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; }
2283 IcCheckType GetKeyType() const OVERRIDE {
2284 return KeyTypeField::decode(bit_field_);
2286 KeyedAccessStoreMode GetStoreMode() const OVERRIDE {
2287 return StoreModeField::decode(bit_field_);
2289 void set_is_uninitialized(bool b) {
2290 bit_field_ = IsUninitializedField::update(bit_field_, b);
2292 void set_key_type(IcCheckType key_type) {
2293 bit_field_ = KeyTypeField::update(bit_field_, key_type);
2295 void set_store_mode(KeyedAccessStoreMode mode) {
2296 bit_field_ = StoreModeField::update(bit_field_, mode);
2300 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value,
2302 static int parent_num_ids() { return Expression::num_ids(); }
2305 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2307 class IsUninitializedField : public BitField16<bool, 0, 1> {};
2308 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2309 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2310 class TokenField : public BitField16<Token::Value, 6, 8> {};
2312 // Starts with 16-bit field, which should get packed together with
2313 // Expression's trailing 16-bit field.
2314 uint16_t bit_field_;
2315 Expression* target_;
2317 BinaryOperation* binary_operation_;
2318 SmallMapList receiver_types_;
2322 class Yield FINAL : public Expression {
2324 DECLARE_NODE_TYPE(Yield)
2327 kInitial, // The initial yield that returns the unboxed generator object.
2328 kSuspend, // A normal yield: { value: EXPRESSION, done: false }
2329 kDelegating, // A yield*.
2330 kFinal // A return: { value: EXPRESSION, done: true }
2333 Expression* generator_object() const { return generator_object_; }
2334 Expression* expression() const { return expression_; }
2335 Kind yield_kind() const { return yield_kind_; }
2337 // Delegating yield surrounds the "yield" in a "try/catch". This index
2338 // locates the catch handler in the handler table, and is equivalent to
2339 // TryCatchStatement::index().
2341 DCHECK_EQ(kDelegating, yield_kind());
2344 void set_index(int index) {
2345 DCHECK_EQ(kDelegating, yield_kind());
2349 // Type feedback information.
2350 bool HasFeedbackSlots() const {
2351 return FLAG_vector_ics && (yield_kind() == kDelegating);
2353 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2354 Isolate* isolate) OVERRIDE {
2355 return FeedbackVectorRequirements(0, HasFeedbackSlots() ? 3 : 0);
2357 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
2358 yield_first_feedback_slot_ = slot;
2360 Code::Kind FeedbackICSlotKind(int index) OVERRIDE {
2361 return index == 0 ? Code::KEYED_LOAD_IC : Code::LOAD_IC;
2364 FeedbackVectorICSlot KeyedLoadFeedbackSlot() {
2365 DCHECK(!HasFeedbackSlots() || !yield_first_feedback_slot_.IsInvalid());
2366 return yield_first_feedback_slot_;
2369 FeedbackVectorICSlot DoneFeedbackSlot() {
2370 return KeyedLoadFeedbackSlot().next();
2373 FeedbackVectorICSlot ValueFeedbackSlot() { return DoneFeedbackSlot().next(); }
2376 Yield(Zone* zone, Expression* generator_object, Expression* expression,
2377 Kind yield_kind, int pos)
2378 : Expression(zone, pos),
2379 generator_object_(generator_object),
2380 expression_(expression),
2381 yield_kind_(yield_kind),
2383 yield_first_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
2386 Expression* generator_object_;
2387 Expression* expression_;
2390 FeedbackVectorICSlot yield_first_feedback_slot_;
2394 class Throw FINAL : public Expression {
2396 DECLARE_NODE_TYPE(Throw)
2398 Expression* exception() const { return exception_; }
2401 Throw(Zone* zone, Expression* exception, int pos)
2402 : Expression(zone, pos), exception_(exception) {}
2405 Expression* exception_;
2409 class FunctionLiteral FINAL : public Expression {
2412 ANONYMOUS_EXPRESSION,
2417 enum ParameterFlag {
2418 kNoDuplicateParameters = 0,
2419 kHasDuplicateParameters = 1
2422 enum IsFunctionFlag {
2427 enum IsParenthesizedFlag {
2432 enum ArityRestriction {
2438 DECLARE_NODE_TYPE(FunctionLiteral)
2440 Handle<String> name() const { return raw_name_->string(); }
2441 const AstRawString* raw_name() const { return raw_name_; }
2442 Scope* scope() const { return scope_; }
2443 ZoneList<Statement*>* body() const { return body_; }
2444 void set_function_token_position(int pos) { function_token_position_ = pos; }
2445 int function_token_position() const { return function_token_position_; }
2446 int start_position() const;
2447 int end_position() const;
2448 int SourceSize() const { return end_position() - start_position(); }
2449 bool is_expression() const { return IsExpression::decode(bitfield_); }
2450 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
2451 LanguageMode language_mode() const;
2452 bool uses_super_property() const;
2454 static bool NeedsHomeObject(Expression* literal) {
2455 return literal != NULL && literal->IsFunctionLiteral() &&
2456 literal->AsFunctionLiteral()->uses_super_property();
2459 int materialized_literal_count() { return materialized_literal_count_; }
2460 int expected_property_count() { return expected_property_count_; }
2461 int handler_count() { return handler_count_; }
2462 int parameter_count() { return parameter_count_; }
2464 bool AllowsLazyCompilation();
2465 bool AllowsLazyCompilationWithoutContext();
2467 void InitializeSharedInfo(Handle<Code> code);
2469 Handle<String> debug_name() const {
2470 if (raw_name_ != NULL && !raw_name_->IsEmpty()) {
2471 return raw_name_->string();
2473 return inferred_name();
2476 Handle<String> inferred_name() const {
2477 if (!inferred_name_.is_null()) {
2478 DCHECK(raw_inferred_name_ == NULL);
2479 return inferred_name_;
2481 if (raw_inferred_name_ != NULL) {
2482 return raw_inferred_name_->string();
2485 return Handle<String>();
2488 // Only one of {set_inferred_name, set_raw_inferred_name} should be called.
2489 void set_inferred_name(Handle<String> inferred_name) {
2490 DCHECK(!inferred_name.is_null());
2491 inferred_name_ = inferred_name;
2492 DCHECK(raw_inferred_name_== NULL || raw_inferred_name_->IsEmpty());
2493 raw_inferred_name_ = NULL;
2496 void set_raw_inferred_name(const AstString* raw_inferred_name) {
2497 DCHECK(raw_inferred_name != NULL);
2498 raw_inferred_name_ = raw_inferred_name;
2499 DCHECK(inferred_name_.is_null());
2500 inferred_name_ = Handle<String>();
2503 // shared_info may be null if it's not cached in full code.
2504 Handle<SharedFunctionInfo> shared_info() { return shared_info_; }
2506 bool pretenure() { return Pretenure::decode(bitfield_); }
2507 void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
2509 bool has_duplicate_parameters() {
2510 return HasDuplicateParameters::decode(bitfield_);
2513 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
2515 // This is used as a heuristic on when to eagerly compile a function
2516 // literal. We consider the following constructs as hints that the
2517 // function will be called immediately:
2518 // - (function() { ... })();
2519 // - var x = function() { ... }();
2520 bool is_parenthesized() {
2521 return IsParenthesized::decode(bitfield_) == kIsParenthesized;
2523 void set_parenthesized() {
2524 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
2527 FunctionKind kind() { return FunctionKindBits::decode(bitfield_); }
2529 int ast_node_count() { return ast_properties_.node_count(); }
2530 AstProperties::Flags* flags() { return ast_properties_.flags(); }
2531 void set_ast_properties(AstProperties* ast_properties) {
2532 ast_properties_ = *ast_properties;
2534 const FeedbackVectorSpec& feedback_vector_spec() const {
2535 return ast_properties_.get_spec();
2537 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2538 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2539 void set_dont_optimize_reason(BailoutReason reason) {
2540 dont_optimize_reason_ = reason;
2544 FunctionLiteral(Zone* zone, const AstRawString* name,
2545 AstValueFactory* ast_value_factory, Scope* scope,
2546 ZoneList<Statement*>* body, int materialized_literal_count,
2547 int expected_property_count, int handler_count,
2548 int parameter_count, FunctionType function_type,
2549 ParameterFlag has_duplicate_parameters,
2550 IsFunctionFlag is_function,
2551 IsParenthesizedFlag is_parenthesized, FunctionKind kind,
2553 : Expression(zone, position),
2557 raw_inferred_name_(ast_value_factory->empty_string()),
2558 dont_optimize_reason_(kNoReason),
2559 materialized_literal_count_(materialized_literal_count),
2560 expected_property_count_(expected_property_count),
2561 handler_count_(handler_count),
2562 parameter_count_(parameter_count),
2563 function_token_position_(RelocInfo::kNoPosition) {
2564 bitfield_ = IsExpression::encode(function_type != DECLARATION) |
2565 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
2566 Pretenure::encode(false) |
2567 HasDuplicateParameters::encode(has_duplicate_parameters) |
2568 IsFunction::encode(is_function) |
2569 IsParenthesized::encode(is_parenthesized) |
2570 FunctionKindBits::encode(kind);
2571 DCHECK(IsValidFunctionKind(kind));
2575 const AstRawString* raw_name_;
2576 Handle<String> name_;
2577 Handle<SharedFunctionInfo> shared_info_;
2579 ZoneList<Statement*>* body_;
2580 const AstString* raw_inferred_name_;
2581 Handle<String> inferred_name_;
2582 AstProperties ast_properties_;
2583 BailoutReason dont_optimize_reason_;
2585 int materialized_literal_count_;
2586 int expected_property_count_;
2588 int parameter_count_;
2589 int function_token_position_;
2592 class IsExpression : public BitField<bool, 0, 1> {};
2593 class IsAnonymous : public BitField<bool, 1, 1> {};
2594 class Pretenure : public BitField<bool, 2, 1> {};
2595 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
2596 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
2597 class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {};
2598 class FunctionKindBits : public BitField<FunctionKind, 6, 7> {};
2602 class ClassLiteral FINAL : public Expression {
2604 typedef ObjectLiteralProperty Property;
2606 DECLARE_NODE_TYPE(ClassLiteral)
2608 Handle<String> name() const { return raw_name_->string(); }
2609 const AstRawString* raw_name() const { return raw_name_; }
2610 Scope* scope() const { return scope_; }
2611 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; }
2612 Expression* extends() const { return extends_; }
2613 FunctionLiteral* constructor() const { return constructor_; }
2614 ZoneList<Property*>* properties() const { return properties_; }
2615 int start_position() const { return position(); }
2616 int end_position() const { return end_position_; }
2618 BailoutId EntryId() const { return BailoutId(local_id(0)); }
2619 BailoutId DeclsId() const { return BailoutId(local_id(1)); }
2620 BailoutId ExitId() { return BailoutId(local_id(2)); }
2622 // Return an AST id for a property that is used in simulate instructions.
2623 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 3)); }
2625 // Unlike other AST nodes, this number of bailout IDs allocated for an
2626 // ClassLiteral can vary, so num_ids() is not a static method.
2627 int num_ids() const { return parent_num_ids() + 3 + properties()->length(); }
2630 ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope,
2631 VariableProxy* class_variable_proxy, Expression* extends,
2632 FunctionLiteral* constructor, ZoneList<Property*>* properties,
2633 int start_position, int end_position)
2634 : Expression(zone, start_position),
2637 class_variable_proxy_(class_variable_proxy),
2639 constructor_(constructor),
2640 properties_(properties),
2641 end_position_(end_position) {}
2642 static int parent_num_ids() { return Expression::num_ids(); }
2645 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2647 const AstRawString* raw_name_;
2649 VariableProxy* class_variable_proxy_;
2650 Expression* extends_;
2651 FunctionLiteral* constructor_;
2652 ZoneList<Property*>* properties_;
2657 class NativeFunctionLiteral FINAL : public Expression {
2659 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2661 Handle<String> name() const { return name_->string(); }
2662 v8::Extension* extension() const { return extension_; }
2665 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2666 v8::Extension* extension, int pos)
2667 : Expression(zone, pos), name_(name), extension_(extension) {}
2670 const AstRawString* name_;
2671 v8::Extension* extension_;
2675 class ThisFunction FINAL : public Expression {
2677 DECLARE_NODE_TYPE(ThisFunction)
2680 ThisFunction(Zone* zone, int pos) : Expression(zone, pos) {}
2684 class SuperReference FINAL : public Expression {
2686 DECLARE_NODE_TYPE(SuperReference)
2688 VariableProxy* this_var() const { return this_var_; }
2690 static int num_ids() { return parent_num_ids() + 1; }
2691 TypeFeedbackId HomeObjectFeedbackId() { return TypeFeedbackId(local_id(0)); }
2693 // Type feedback information.
2694 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2695 Isolate* isolate) OVERRIDE {
2696 return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0);
2698 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
2699 homeobject_feedback_slot_ = slot;
2701 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; }
2703 FeedbackVectorICSlot HomeObjectFeedbackSlot() {
2704 DCHECK(!FLAG_vector_ics || !homeobject_feedback_slot_.IsInvalid());
2705 return homeobject_feedback_slot_;
2709 SuperReference(Zone* zone, VariableProxy* this_var, int pos)
2710 : Expression(zone, pos),
2711 this_var_(this_var),
2712 homeobject_feedback_slot_(FeedbackVectorICSlot::Invalid()) {
2713 DCHECK(this_var->is_this());
2715 static int parent_num_ids() { return Expression::num_ids(); }
2718 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2720 VariableProxy* this_var_;
2721 FeedbackVectorICSlot homeobject_feedback_slot_;
2725 #undef DECLARE_NODE_TYPE
2728 // ----------------------------------------------------------------------------
2729 // Regular expressions
2732 class RegExpVisitor BASE_EMBEDDED {
2734 virtual ~RegExpVisitor() { }
2735 #define MAKE_CASE(Name) \
2736 virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
2737 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
2742 class RegExpTree : public ZoneObject {
2744 static const int kInfinity = kMaxInt;
2745 virtual ~RegExpTree() {}
2746 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
2747 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2748 RegExpNode* on_success) = 0;
2749 virtual bool IsTextElement() { return false; }
2750 virtual bool IsAnchoredAtStart() { return false; }
2751 virtual bool IsAnchoredAtEnd() { return false; }
2752 virtual int min_match() = 0;
2753 virtual int max_match() = 0;
2754 // Returns the interval of registers used for captures within this
2756 virtual Interval CaptureRegisters() { return Interval::Empty(); }
2757 virtual void AppendToText(RegExpText* text, Zone* zone);
2758 std::ostream& Print(std::ostream& os, Zone* zone); // NOLINT
2759 #define MAKE_ASTYPE(Name) \
2760 virtual RegExp##Name* As##Name(); \
2761 virtual bool Is##Name();
2762 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
2767 class RegExpDisjunction FINAL : public RegExpTree {
2769 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
2770 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2771 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2772 RegExpNode* on_success) OVERRIDE;
2773 RegExpDisjunction* AsDisjunction() OVERRIDE;
2774 Interval CaptureRegisters() OVERRIDE;
2775 bool IsDisjunction() OVERRIDE;
2776 bool IsAnchoredAtStart() OVERRIDE;
2777 bool IsAnchoredAtEnd() OVERRIDE;
2778 int min_match() OVERRIDE { return min_match_; }
2779 int max_match() OVERRIDE { return max_match_; }
2780 ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
2782 ZoneList<RegExpTree*>* alternatives_;
2788 class RegExpAlternative FINAL : public RegExpTree {
2790 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
2791 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2792 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2793 RegExpNode* on_success) OVERRIDE;
2794 RegExpAlternative* AsAlternative() OVERRIDE;
2795 Interval CaptureRegisters() OVERRIDE;
2796 bool IsAlternative() OVERRIDE;
2797 bool IsAnchoredAtStart() OVERRIDE;
2798 bool IsAnchoredAtEnd() OVERRIDE;
2799 int min_match() OVERRIDE { return min_match_; }
2800 int max_match() OVERRIDE { return max_match_; }
2801 ZoneList<RegExpTree*>* nodes() { return nodes_; }
2803 ZoneList<RegExpTree*>* nodes_;
2809 class RegExpAssertion FINAL : public RegExpTree {
2811 enum AssertionType {
2819 explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { }
2820 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2821 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2822 RegExpNode* on_success) OVERRIDE;
2823 RegExpAssertion* AsAssertion() OVERRIDE;
2824 bool IsAssertion() OVERRIDE;
2825 bool IsAnchoredAtStart() OVERRIDE;
2826 bool IsAnchoredAtEnd() OVERRIDE;
2827 int min_match() OVERRIDE { return 0; }
2828 int max_match() OVERRIDE { return 0; }
2829 AssertionType assertion_type() { return assertion_type_; }
2831 AssertionType assertion_type_;
2835 class CharacterSet FINAL BASE_EMBEDDED {
2837 explicit CharacterSet(uc16 standard_set_type)
2839 standard_set_type_(standard_set_type) {}
2840 explicit CharacterSet(ZoneList<CharacterRange>* ranges)
2842 standard_set_type_(0) {}
2843 ZoneList<CharacterRange>* ranges(Zone* zone);
2844 uc16 standard_set_type() { return standard_set_type_; }
2845 void set_standard_set_type(uc16 special_set_type) {
2846 standard_set_type_ = special_set_type;
2848 bool is_standard() { return standard_set_type_ != 0; }
2849 void Canonicalize();
2851 ZoneList<CharacterRange>* ranges_;
2852 // If non-zero, the value represents a standard set (e.g., all whitespace
2853 // characters) without having to expand the ranges.
2854 uc16 standard_set_type_;
2858 class RegExpCharacterClass FINAL : public RegExpTree {
2860 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
2862 is_negated_(is_negated) { }
2863 explicit RegExpCharacterClass(uc16 type)
2865 is_negated_(false) { }
2866 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2867 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2868 RegExpNode* on_success) OVERRIDE;
2869 RegExpCharacterClass* AsCharacterClass() OVERRIDE;
2870 bool IsCharacterClass() OVERRIDE;
2871 bool IsTextElement() OVERRIDE { return true; }
2872 int min_match() OVERRIDE { return 1; }
2873 int max_match() OVERRIDE { return 1; }
2874 void AppendToText(RegExpText* text, Zone* zone) OVERRIDE;
2875 CharacterSet character_set() { return set_; }
2876 // TODO(lrn): Remove need for complex version if is_standard that
2877 // recognizes a mangled standard set and just do { return set_.is_special(); }
2878 bool is_standard(Zone* zone);
2879 // Returns a value representing the standard character set if is_standard()
2881 // Currently used values are:
2882 // s : unicode whitespace
2883 // S : unicode non-whitespace
2884 // w : ASCII word character (digit, letter, underscore)
2885 // W : non-ASCII word character
2887 // D : non-ASCII digit
2888 // . : non-unicode non-newline
2889 // * : All characters
2890 uc16 standard_type() { return set_.standard_set_type(); }
2891 ZoneList<CharacterRange>* ranges(Zone* zone) { return set_.ranges(zone); }
2892 bool is_negated() { return is_negated_; }
2900 class RegExpAtom FINAL : public RegExpTree {
2902 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
2903 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2904 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2905 RegExpNode* on_success) OVERRIDE;
2906 RegExpAtom* AsAtom() OVERRIDE;
2907 bool IsAtom() OVERRIDE;
2908 bool IsTextElement() OVERRIDE { return true; }
2909 int min_match() OVERRIDE { return data_.length(); }
2910 int max_match() OVERRIDE { return data_.length(); }
2911 void AppendToText(RegExpText* text, Zone* zone) OVERRIDE;
2912 Vector<const uc16> data() { return data_; }
2913 int length() { return data_.length(); }
2915 Vector<const uc16> data_;
2919 class RegExpText FINAL : public RegExpTree {
2921 explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
2922 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2923 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2924 RegExpNode* on_success) OVERRIDE;
2925 RegExpText* AsText() OVERRIDE;
2926 bool IsText() OVERRIDE;
2927 bool IsTextElement() OVERRIDE { return true; }
2928 int min_match() OVERRIDE { return length_; }
2929 int max_match() OVERRIDE { return length_; }
2930 void AppendToText(RegExpText* text, Zone* zone) OVERRIDE;
2931 void AddElement(TextElement elm, Zone* zone) {
2932 elements_.Add(elm, zone);
2933 length_ += elm.length();
2935 ZoneList<TextElement>* elements() { return &elements_; }
2937 ZoneList<TextElement> elements_;
2942 class RegExpQuantifier FINAL : public RegExpTree {
2944 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE };
2945 RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body)
2949 min_match_(min * body->min_match()),
2950 quantifier_type_(type) {
2951 if (max > 0 && body->max_match() > kInfinity / max) {
2952 max_match_ = kInfinity;
2954 max_match_ = max * body->max_match();
2957 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2958 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2959 RegExpNode* on_success) OVERRIDE;
2960 static RegExpNode* ToNode(int min,
2964 RegExpCompiler* compiler,
2965 RegExpNode* on_success,
2966 bool not_at_start = false);
2967 RegExpQuantifier* AsQuantifier() OVERRIDE;
2968 Interval CaptureRegisters() OVERRIDE;
2969 bool IsQuantifier() OVERRIDE;
2970 int min_match() OVERRIDE { return min_match_; }
2971 int max_match() OVERRIDE { return max_match_; }
2972 int min() { return min_; }
2973 int max() { return max_; }
2974 bool is_possessive() { return quantifier_type_ == POSSESSIVE; }
2975 bool is_non_greedy() { return quantifier_type_ == NON_GREEDY; }
2976 bool is_greedy() { return quantifier_type_ == GREEDY; }
2977 RegExpTree* body() { return body_; }
2985 QuantifierType quantifier_type_;
2989 class RegExpCapture FINAL : public RegExpTree {
2991 explicit RegExpCapture(RegExpTree* body, int index)
2992 : body_(body), index_(index) { }
2993 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2994 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2995 RegExpNode* on_success) OVERRIDE;
2996 static RegExpNode* ToNode(RegExpTree* body,
2998 RegExpCompiler* compiler,
2999 RegExpNode* on_success);
3000 RegExpCapture* AsCapture() OVERRIDE;
3001 bool IsAnchoredAtStart() OVERRIDE;
3002 bool IsAnchoredAtEnd() OVERRIDE;
3003 Interval CaptureRegisters() OVERRIDE;
3004 bool IsCapture() OVERRIDE;
3005 int min_match() OVERRIDE { return body_->min_match(); }
3006 int max_match() OVERRIDE { return body_->max_match(); }
3007 RegExpTree* body() { return body_; }
3008 int index() { return index_; }
3009 static int StartRegister(int index) { return index * 2; }
3010 static int EndRegister(int index) { return index * 2 + 1; }
3018 class RegExpLookahead FINAL : public RegExpTree {
3020 RegExpLookahead(RegExpTree* body,
3025 is_positive_(is_positive),
3026 capture_count_(capture_count),
3027 capture_from_(capture_from) { }
3029 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3030 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3031 RegExpNode* on_success) OVERRIDE;
3032 RegExpLookahead* AsLookahead() OVERRIDE;
3033 Interval CaptureRegisters() OVERRIDE;
3034 bool IsLookahead() OVERRIDE;
3035 bool IsAnchoredAtStart() OVERRIDE;
3036 int min_match() OVERRIDE { return 0; }
3037 int max_match() OVERRIDE { return 0; }
3038 RegExpTree* body() { return body_; }
3039 bool is_positive() { return is_positive_; }
3040 int capture_count() { return capture_count_; }
3041 int capture_from() { return capture_from_; }
3051 class RegExpBackReference FINAL : public RegExpTree {
3053 explicit RegExpBackReference(RegExpCapture* capture)
3054 : capture_(capture) { }
3055 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3056 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3057 RegExpNode* on_success) OVERRIDE;
3058 RegExpBackReference* AsBackReference() OVERRIDE;
3059 bool IsBackReference() OVERRIDE;
3060 int min_match() OVERRIDE { return 0; }
3061 int max_match() OVERRIDE { return capture_->max_match(); }
3062 int index() { return capture_->index(); }
3063 RegExpCapture* capture() { return capture_; }
3065 RegExpCapture* capture_;
3069 class RegExpEmpty FINAL : public RegExpTree {
3072 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3073 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3074 RegExpNode* on_success) OVERRIDE;
3075 RegExpEmpty* AsEmpty() OVERRIDE;
3076 bool IsEmpty() OVERRIDE;
3077 int min_match() OVERRIDE { return 0; }
3078 int max_match() OVERRIDE { return 0; }
3082 // ----------------------------------------------------------------------------
3084 // - leaf node visitors are abstract.
3086 class AstVisitor BASE_EMBEDDED {
3089 virtual ~AstVisitor() {}
3091 // Stack overflow check and dynamic dispatch.
3092 virtual void Visit(AstNode* node) = 0;
3094 // Iteration left-to-right.
3095 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations);
3096 virtual void VisitStatements(ZoneList<Statement*>* statements);
3097 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
3099 // Individual AST nodes.
3100 #define DEF_VISIT(type) \
3101 virtual void Visit##type(type* node) = 0;
3102 AST_NODE_LIST(DEF_VISIT)
3107 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
3109 void Visit(AstNode* node) FINAL { \
3110 if (!CheckStackOverflow()) node->Accept(this); \
3113 void SetStackOverflow() { stack_overflow_ = true; } \
3114 void ClearStackOverflow() { stack_overflow_ = false; } \
3115 bool HasStackOverflow() const { return stack_overflow_; } \
3117 bool CheckStackOverflow() { \
3118 if (stack_overflow_) return true; \
3119 StackLimitCheck check(isolate_); \
3120 if (!check.HasOverflowed()) return false; \
3121 stack_overflow_ = true; \
3126 void InitializeAstVisitor(Isolate* isolate, Zone* zone) { \
3127 isolate_ = isolate; \
3129 stack_overflow_ = false; \
3131 Zone* zone() { return zone_; } \
3132 Isolate* isolate() { return isolate_; } \
3134 Isolate* isolate_; \
3136 bool stack_overflow_
3139 // ----------------------------------------------------------------------------
3142 class AstNodeFactory FINAL BASE_EMBEDDED {
3144 explicit AstNodeFactory(AstValueFactory* ast_value_factory)
3145 : zone_(ast_value_factory->zone()),
3146 ast_value_factory_(ast_value_factory) {}
3148 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
3152 return new (zone_) VariableDeclaration(zone_, proxy, mode, scope, pos);
3155 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
3157 FunctionLiteral* fun,
3160 return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
3163 ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy,
3167 return new (zone_) ModuleDeclaration(zone_, proxy, module, scope, pos);
3170 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
3174 return new (zone_) ImportDeclaration(zone_, proxy, module, scope, pos);
3177 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
3180 return new (zone_) ExportDeclaration(zone_, proxy, scope, pos);
3183 ModuleLiteral* NewModuleLiteral(Block* body, ModuleDescriptor* descriptor,
3185 return new (zone_) ModuleLiteral(zone_, body, descriptor, pos);
3188 ModulePath* NewModulePath(Module* origin, const AstRawString* name, int pos) {
3189 return new (zone_) ModulePath(zone_, origin, name, pos);
3192 ModuleUrl* NewModuleUrl(Handle<String> url, int pos) {
3193 return new (zone_) ModuleUrl(zone_, url, pos);
3196 Block* NewBlock(ZoneList<const AstRawString*>* labels,
3198 bool is_initializer_block,
3201 Block(zone_, labels, capacity, is_initializer_block, pos);
3204 #define STATEMENT_WITH_LABELS(NodeType) \
3205 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
3206 return new (zone_) NodeType(zone_, labels, pos); \
3208 STATEMENT_WITH_LABELS(DoWhileStatement)
3209 STATEMENT_WITH_LABELS(WhileStatement)
3210 STATEMENT_WITH_LABELS(ForStatement)
3211 STATEMENT_WITH_LABELS(SwitchStatement)
3212 #undef STATEMENT_WITH_LABELS
3214 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3215 ZoneList<const AstRawString*>* labels,
3217 switch (visit_mode) {
3218 case ForEachStatement::ENUMERATE: {
3219 return new (zone_) ForInStatement(zone_, labels, pos);
3221 case ForEachStatement::ITERATE: {
3222 return new (zone_) ForOfStatement(zone_, labels, pos);
3229 ModuleStatement* NewModuleStatement(Block* body, int pos) {
3230 return new (zone_) ModuleStatement(zone_, body, pos);
3233 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3234 return new (zone_) ExpressionStatement(zone_, expression, pos);
3237 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
3238 return new (zone_) ContinueStatement(zone_, target, pos);
3241 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
3242 return new (zone_) BreakStatement(zone_, target, pos);
3245 ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
3246 return new (zone_) ReturnStatement(zone_, expression, pos);
3249 WithStatement* NewWithStatement(Scope* scope,
3250 Expression* expression,
3251 Statement* statement,
3253 return new (zone_) WithStatement(zone_, scope, expression, statement, pos);
3256 IfStatement* NewIfStatement(Expression* condition,
3257 Statement* then_statement,
3258 Statement* else_statement,
3261 IfStatement(zone_, condition, then_statement, else_statement, pos);
3264 TryCatchStatement* NewTryCatchStatement(int index,
3270 return new (zone_) TryCatchStatement(zone_, index, try_block, scope,
3271 variable, catch_block, pos);
3274 TryFinallyStatement* NewTryFinallyStatement(int index,
3276 Block* finally_block,
3279 TryFinallyStatement(zone_, index, try_block, finally_block, pos);
3282 DebuggerStatement* NewDebuggerStatement(int pos) {
3283 return new (zone_) DebuggerStatement(zone_, pos);
3286 EmptyStatement* NewEmptyStatement(int pos) {
3287 return new(zone_) EmptyStatement(zone_, pos);
3290 CaseClause* NewCaseClause(
3291 Expression* label, ZoneList<Statement*>* statements, int pos) {
3292 return new (zone_) CaseClause(zone_, label, statements, pos);
3295 Literal* NewStringLiteral(const AstRawString* string, int pos) {
3297 Literal(zone_, ast_value_factory_->NewString(string), pos);
3300 // A JavaScript symbol (ECMA-262 edition 6).
3301 Literal* NewSymbolLiteral(const char* name, int pos) {
3302 return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3305 Literal* NewNumberLiteral(double number, int pos) {
3307 Literal(zone_, ast_value_factory_->NewNumber(number), pos);
3310 Literal* NewSmiLiteral(int number, int pos) {
3311 return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3314 Literal* NewBooleanLiteral(bool b, int pos) {
3315 return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3318 Literal* NewNullLiteral(int pos) {
3319 return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3322 Literal* NewUndefinedLiteral(int pos) {
3323 return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3326 Literal* NewTheHoleLiteral(int pos) {
3327 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3330 ObjectLiteral* NewObjectLiteral(
3331 ZoneList<ObjectLiteral::Property*>* properties,
3333 int boilerplate_properties,
3336 return new (zone_) ObjectLiteral(zone_, properties, literal_index,
3337 boilerplate_properties, has_function, pos);
3340 ObjectLiteral::Property* NewObjectLiteralProperty(
3341 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3342 bool is_static, bool is_computed_name) {
3344 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name);
3347 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
3350 bool is_computed_name) {
3351 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
3352 is_static, is_computed_name);
3355 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3356 const AstRawString* flags,
3359 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos);
3362 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3365 return new (zone_) ArrayLiteral(zone_, values, literal_index, pos);
3368 VariableProxy* NewVariableProxy(Variable* var,
3369 int start_position = RelocInfo::kNoPosition,
3370 int end_position = RelocInfo::kNoPosition) {
3371 return new (zone_) VariableProxy(zone_, var, start_position, end_position);
3374 VariableProxy* NewVariableProxy(const AstRawString* name, bool is_this,
3375 int start_position = RelocInfo::kNoPosition,
3376 int end_position = RelocInfo::kNoPosition) {
3378 VariableProxy(zone_, name, is_this, start_position, end_position);
3381 Property* NewProperty(Expression* obj, Expression* key, int pos) {
3382 return new (zone_) Property(zone_, obj, key, pos);
3385 Call* NewCall(Expression* expression,
3386 ZoneList<Expression*>* arguments,
3388 return new (zone_) Call(zone_, expression, arguments, pos);
3391 CallNew* NewCallNew(Expression* expression,
3392 ZoneList<Expression*>* arguments,
3394 return new (zone_) CallNew(zone_, expression, arguments, pos);
3397 CallRuntime* NewCallRuntime(const AstRawString* name,
3398 const Runtime::Function* function,
3399 ZoneList<Expression*>* arguments,
3401 return new (zone_) CallRuntime(zone_, name, function, arguments, pos);
3404 UnaryOperation* NewUnaryOperation(Token::Value op,
3405 Expression* expression,
3407 return new (zone_) UnaryOperation(zone_, op, expression, pos);
3410 BinaryOperation* NewBinaryOperation(Token::Value op,
3414 return new (zone_) BinaryOperation(zone_, op, left, right, pos);
3417 CountOperation* NewCountOperation(Token::Value op,
3421 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos);
3424 CompareOperation* NewCompareOperation(Token::Value op,
3428 return new (zone_) CompareOperation(zone_, op, left, right, pos);
3431 Conditional* NewConditional(Expression* condition,
3432 Expression* then_expression,
3433 Expression* else_expression,
3435 return new (zone_) Conditional(zone_, condition, then_expression,
3436 else_expression, position);
3439 Assignment* NewAssignment(Token::Value op,
3443 DCHECK(Token::IsAssignmentOp(op));
3444 Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos);
3445 if (assign->is_compound()) {
3446 DCHECK(Token::IsAssignmentOp(op));
3447 assign->binary_operation_ =
3448 NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3453 Yield* NewYield(Expression *generator_object,
3454 Expression* expression,
3455 Yield::Kind yield_kind,
3457 if (!expression) expression = NewUndefinedLiteral(pos);
3459 Yield(zone_, generator_object, expression, yield_kind, pos);
3462 Throw* NewThrow(Expression* exception, int pos) {
3463 return new (zone_) Throw(zone_, exception, pos);
3466 FunctionLiteral* NewFunctionLiteral(
3467 const AstRawString* name, AstValueFactory* ast_value_factory,
3468 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3469 int expected_property_count, int handler_count, int parameter_count,
3470 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3471 FunctionLiteral::FunctionType function_type,
3472 FunctionLiteral::IsFunctionFlag is_function,
3473 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind,
3475 return new (zone_) FunctionLiteral(
3476 zone_, name, ast_value_factory, scope, body, materialized_literal_count,
3477 expected_property_count, handler_count, parameter_count, function_type,
3478 has_duplicate_parameters, is_function, is_parenthesized, kind,
3482 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope,
3483 VariableProxy* proxy, Expression* extends,
3484 FunctionLiteral* constructor,
3485 ZoneList<ObjectLiteral::Property*>* properties,
3486 int start_position, int end_position) {
3488 ClassLiteral(zone_, name, scope, proxy, extends, constructor,
3489 properties, start_position, end_position);
3492 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3493 v8::Extension* extension,
3495 return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3498 ThisFunction* NewThisFunction(int pos) {
3499 return new (zone_) ThisFunction(zone_, pos);
3502 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) {
3503 return new (zone_) SuperReference(zone_, this_var, pos);
3508 AstValueFactory* ast_value_factory_;
3512 } } // namespace v8::internal