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 // At the moment there are no "const functions" in JavaScript...
581 DCHECK(mode == VAR || mode == LET);
586 FunctionLiteral* fun_;
590 class ModuleDeclaration FINAL : public Declaration {
592 DECLARE_NODE_TYPE(ModuleDeclaration)
594 Module* module() const { return module_; }
595 InitializationFlag initialization() const OVERRIDE {
596 return kCreatedInitialized;
600 ModuleDeclaration(Zone* zone, VariableProxy* proxy, Module* module,
601 Scope* scope, int pos)
602 : Declaration(zone, proxy, CONST, scope, pos), module_(module) {}
609 class ImportDeclaration FINAL : public Declaration {
611 DECLARE_NODE_TYPE(ImportDeclaration)
613 Module* module() const { return module_; }
614 InitializationFlag initialization() const OVERRIDE {
615 return kCreatedInitialized;
619 ImportDeclaration(Zone* zone,
620 VariableProxy* proxy,
624 : Declaration(zone, proxy, LET, scope, pos),
633 class ExportDeclaration FINAL : public Declaration {
635 DECLARE_NODE_TYPE(ExportDeclaration)
637 InitializationFlag initialization() const OVERRIDE {
638 return kCreatedInitialized;
642 ExportDeclaration(Zone* zone, VariableProxy* proxy, Scope* scope, int pos)
643 : Declaration(zone, proxy, LET, scope, pos) {}
647 class Module : public AstNode {
649 ModuleDescriptor* descriptor() const { return descriptor_; }
650 Block* body() const { return body_; }
653 Module(Zone* zone, int pos)
654 : AstNode(pos), descriptor_(ModuleDescriptor::New(zone)), body_(NULL) {}
655 Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL)
656 : AstNode(pos), descriptor_(descriptor), body_(body) {}
659 ModuleDescriptor* descriptor_;
664 class ModuleLiteral FINAL : public Module {
666 DECLARE_NODE_TYPE(ModuleLiteral)
669 ModuleLiteral(Zone* zone, Block* body, ModuleDescriptor* descriptor, int pos)
670 : Module(zone, descriptor, pos, body) {}
674 class ModulePath FINAL : public Module {
676 DECLARE_NODE_TYPE(ModulePath)
678 Module* module() const { return module_; }
679 Handle<String> name() const { return name_->string(); }
682 ModulePath(Zone* zone, Module* module, const AstRawString* name, int pos)
683 : Module(zone, pos), module_(module), name_(name) {}
687 const AstRawString* name_;
691 class ModuleUrl FINAL : public Module {
693 DECLARE_NODE_TYPE(ModuleUrl)
695 Handle<String> url() const { return url_; }
698 ModuleUrl(Zone* zone, Handle<String> url, int pos)
699 : Module(zone, pos), url_(url) {
707 class ModuleStatement FINAL : public Statement {
709 DECLARE_NODE_TYPE(ModuleStatement)
711 Block* body() const { return body_; }
714 ModuleStatement(Zone* zone, Block* body, int pos)
715 : Statement(zone, pos), body_(body) {}
722 class IterationStatement : public BreakableStatement {
724 // Type testing & conversion.
725 IterationStatement* AsIterationStatement() FINAL { return this; }
727 Statement* body() const { return body_; }
729 static int num_ids() { return parent_num_ids() + 1; }
730 BailoutId OsrEntryId() const { return BailoutId(local_id(0)); }
731 virtual BailoutId ContinueId() const = 0;
732 virtual BailoutId StackCheckId() const = 0;
735 Label* continue_target() { return &continue_target_; }
738 IterationStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
739 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
741 static int parent_num_ids() { return BreakableStatement::num_ids(); }
742 void Initialize(Statement* body) { body_ = body; }
745 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
748 Label continue_target_;
752 class DoWhileStatement FINAL : public IterationStatement {
754 DECLARE_NODE_TYPE(DoWhileStatement)
756 void Initialize(Expression* cond, Statement* body) {
757 IterationStatement::Initialize(body);
761 Expression* cond() const { return cond_; }
763 static int num_ids() { return parent_num_ids() + 2; }
764 BailoutId ContinueId() const OVERRIDE { return BailoutId(local_id(0)); }
765 BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); }
766 BailoutId BackEdgeId() const { return BailoutId(local_id(1)); }
769 DoWhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
770 : IterationStatement(zone, labels, pos), cond_(NULL) {}
771 static int parent_num_ids() { return IterationStatement::num_ids(); }
774 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
780 class WhileStatement FINAL : public IterationStatement {
782 DECLARE_NODE_TYPE(WhileStatement)
784 void Initialize(Expression* cond, Statement* body) {
785 IterationStatement::Initialize(body);
789 Expression* cond() const { return cond_; }
791 static int num_ids() { return parent_num_ids() + 1; }
792 BailoutId ContinueId() const OVERRIDE { return EntryId(); }
793 BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
794 BailoutId BodyId() const { return BailoutId(local_id(0)); }
797 WhileStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
798 : IterationStatement(zone, labels, pos), cond_(NULL) {}
799 static int parent_num_ids() { return IterationStatement::num_ids(); }
802 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
808 class ForStatement FINAL : public IterationStatement {
810 DECLARE_NODE_TYPE(ForStatement)
812 void Initialize(Statement* init,
816 IterationStatement::Initialize(body);
822 Statement* init() const { return init_; }
823 Expression* cond() const { return cond_; }
824 Statement* next() const { return next_; }
826 static int num_ids() { return parent_num_ids() + 2; }
827 BailoutId ContinueId() const OVERRIDE { return BailoutId(local_id(0)); }
828 BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
829 BailoutId BodyId() const { return BailoutId(local_id(1)); }
832 ForStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
833 : IterationStatement(zone, labels, pos),
837 static int parent_num_ids() { return IterationStatement::num_ids(); }
840 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
848 class ForEachStatement : public IterationStatement {
851 ENUMERATE, // for (each in subject) body;
852 ITERATE // for (each of subject) body;
855 void Initialize(Expression* each, Expression* subject, Statement* body) {
856 IterationStatement::Initialize(body);
861 Expression* each() const { return each_; }
862 Expression* subject() const { return subject_; }
865 ForEachStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
866 : IterationStatement(zone, labels, pos), each_(NULL), subject_(NULL) {}
870 Expression* subject_;
874 class ForInStatement FINAL : public ForEachStatement {
876 DECLARE_NODE_TYPE(ForInStatement)
878 Expression* enumerable() const {
882 // Type feedback information.
883 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
884 Isolate* isolate) OVERRIDE {
885 return FeedbackVectorRequirements(1, 0);
887 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
888 for_in_feedback_slot_ = slot;
891 FeedbackVectorSlot ForInFeedbackSlot() {
892 DCHECK(!for_in_feedback_slot_.IsInvalid());
893 return for_in_feedback_slot_;
896 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
897 ForInType for_in_type() const { return for_in_type_; }
898 void set_for_in_type(ForInType type) { for_in_type_ = type; }
900 static int num_ids() { return parent_num_ids() + 5; }
901 BailoutId BodyId() const { return BailoutId(local_id(0)); }
902 BailoutId PrepareId() const { return BailoutId(local_id(1)); }
903 BailoutId EnumId() const { return BailoutId(local_id(2)); }
904 BailoutId ToObjectId() const { return BailoutId(local_id(3)); }
905 BailoutId AssignmentId() const { return BailoutId(local_id(4)); }
906 BailoutId ContinueId() const OVERRIDE { return EntryId(); }
907 BailoutId StackCheckId() const OVERRIDE { return BodyId(); }
910 ForInStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
911 : ForEachStatement(zone, labels, pos),
912 for_in_type_(SLOW_FOR_IN),
913 for_in_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
914 static int parent_num_ids() { return ForEachStatement::num_ids(); }
917 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
919 ForInType for_in_type_;
920 FeedbackVectorSlot for_in_feedback_slot_;
924 class ForOfStatement FINAL : public ForEachStatement {
926 DECLARE_NODE_TYPE(ForOfStatement)
928 void Initialize(Expression* each,
931 Expression* assign_iterator,
932 Expression* next_result,
933 Expression* result_done,
934 Expression* assign_each) {
935 ForEachStatement::Initialize(each, subject, body);
936 assign_iterator_ = assign_iterator;
937 next_result_ = next_result;
938 result_done_ = result_done;
939 assign_each_ = assign_each;
942 Expression* iterable() const {
946 // var iterator = subject[Symbol.iterator]();
947 Expression* assign_iterator() const {
948 return assign_iterator_;
951 // var result = iterator.next();
952 Expression* next_result() const {
957 Expression* result_done() const {
961 // each = result.value
962 Expression* assign_each() const {
966 BailoutId ContinueId() const OVERRIDE { return EntryId(); }
967 BailoutId StackCheckId() const OVERRIDE { return BackEdgeId(); }
969 static int num_ids() { return parent_num_ids() + 1; }
970 BailoutId BackEdgeId() const { return BailoutId(local_id(0)); }
973 ForOfStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
974 : ForEachStatement(zone, labels, pos),
975 assign_iterator_(NULL),
978 assign_each_(NULL) {}
979 static int parent_num_ids() { return ForEachStatement::num_ids(); }
982 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
984 Expression* assign_iterator_;
985 Expression* next_result_;
986 Expression* result_done_;
987 Expression* assign_each_;
991 class ExpressionStatement FINAL : public Statement {
993 DECLARE_NODE_TYPE(ExpressionStatement)
995 void set_expression(Expression* e) { expression_ = e; }
996 Expression* expression() const { return expression_; }
997 bool IsJump() const OVERRIDE { return expression_->IsThrow(); }
1000 ExpressionStatement(Zone* zone, Expression* expression, int pos)
1001 : Statement(zone, pos), expression_(expression) { }
1004 Expression* expression_;
1008 class JumpStatement : public Statement {
1010 bool IsJump() const FINAL { return true; }
1013 explicit JumpStatement(Zone* zone, int pos) : Statement(zone, pos) {}
1017 class ContinueStatement FINAL : public JumpStatement {
1019 DECLARE_NODE_TYPE(ContinueStatement)
1021 IterationStatement* target() const { return target_; }
1024 explicit ContinueStatement(Zone* zone, IterationStatement* target, int pos)
1025 : JumpStatement(zone, pos), target_(target) { }
1028 IterationStatement* target_;
1032 class BreakStatement FINAL : public JumpStatement {
1034 DECLARE_NODE_TYPE(BreakStatement)
1036 BreakableStatement* target() const { return target_; }
1039 explicit BreakStatement(Zone* zone, BreakableStatement* target, int pos)
1040 : JumpStatement(zone, pos), target_(target) { }
1043 BreakableStatement* target_;
1047 class ReturnStatement FINAL : public JumpStatement {
1049 DECLARE_NODE_TYPE(ReturnStatement)
1051 Expression* expression() const { return expression_; }
1054 explicit ReturnStatement(Zone* zone, Expression* expression, int pos)
1055 : JumpStatement(zone, pos), expression_(expression) { }
1058 Expression* expression_;
1062 class WithStatement FINAL : public Statement {
1064 DECLARE_NODE_TYPE(WithStatement)
1066 Scope* scope() { return scope_; }
1067 Expression* expression() const { return expression_; }
1068 Statement* statement() const { return statement_; }
1070 void set_base_id(int id) { base_id_ = id; }
1071 static int num_ids() { return parent_num_ids() + 1; }
1072 BailoutId EntryId() const { return BailoutId(local_id(0)); }
1075 WithStatement(Zone* zone, Scope* scope, Expression* expression,
1076 Statement* statement, int pos)
1077 : Statement(zone, pos),
1079 expression_(expression),
1080 statement_(statement),
1081 base_id_(BailoutId::None().ToInt()) {}
1082 static int parent_num_ids() { return 0; }
1084 int base_id() const {
1085 DCHECK(!BailoutId(base_id_).IsNone());
1090 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1093 Expression* expression_;
1094 Statement* statement_;
1099 class CaseClause FINAL : public Expression {
1101 DECLARE_NODE_TYPE(CaseClause)
1103 bool is_default() const { return label_ == NULL; }
1104 Expression* label() const {
1105 CHECK(!is_default());
1108 Label* body_target() { return &body_target_; }
1109 ZoneList<Statement*>* statements() const { return statements_; }
1111 static int num_ids() { return parent_num_ids() + 2; }
1112 BailoutId EntryId() const { return BailoutId(local_id(0)); }
1113 TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); }
1115 Type* compare_type() { return compare_type_; }
1116 void set_compare_type(Type* type) { compare_type_ = type; }
1119 static int parent_num_ids() { return Expression::num_ids(); }
1122 CaseClause(Zone* zone, Expression* label, ZoneList<Statement*>* statements,
1124 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1128 ZoneList<Statement*>* statements_;
1129 Type* compare_type_;
1133 class SwitchStatement FINAL : public BreakableStatement {
1135 DECLARE_NODE_TYPE(SwitchStatement)
1137 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
1142 Expression* tag() const { return tag_; }
1143 ZoneList<CaseClause*>* cases() const { return cases_; }
1146 SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels, int pos)
1147 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
1153 ZoneList<CaseClause*>* cases_;
1157 // If-statements always have non-null references to their then- and
1158 // else-parts. When parsing if-statements with no explicit else-part,
1159 // the parser implicitly creates an empty statement. Use the
1160 // HasThenStatement() and HasElseStatement() functions to check if a
1161 // given if-statement has a then- or an else-part containing code.
1162 class IfStatement FINAL : public Statement {
1164 DECLARE_NODE_TYPE(IfStatement)
1166 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
1167 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
1169 Expression* condition() const { return condition_; }
1170 Statement* then_statement() const { return then_statement_; }
1171 Statement* else_statement() const { return else_statement_; }
1173 bool IsJump() const OVERRIDE {
1174 return HasThenStatement() && then_statement()->IsJump()
1175 && HasElseStatement() && else_statement()->IsJump();
1178 void set_base_id(int id) { base_id_ = id; }
1179 static int num_ids() { return parent_num_ids() + 3; }
1180 BailoutId IfId() const { return BailoutId(local_id(0)); }
1181 BailoutId ThenId() const { return BailoutId(local_id(1)); }
1182 BailoutId ElseId() const { return BailoutId(local_id(2)); }
1185 IfStatement(Zone* zone, Expression* condition, Statement* then_statement,
1186 Statement* else_statement, int pos)
1187 : Statement(zone, pos),
1188 condition_(condition),
1189 then_statement_(then_statement),
1190 else_statement_(else_statement),
1191 base_id_(BailoutId::None().ToInt()) {}
1192 static int parent_num_ids() { return 0; }
1194 int base_id() const {
1195 DCHECK(!BailoutId(base_id_).IsNone());
1200 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1202 Expression* condition_;
1203 Statement* then_statement_;
1204 Statement* else_statement_;
1209 class TryStatement : public Statement {
1211 int index() const { return index_; }
1212 Block* try_block() const { return try_block_; }
1215 TryStatement(Zone* zone, int index, Block* try_block, int pos)
1216 : Statement(zone, pos), index_(index), try_block_(try_block) {}
1219 // Unique (per-function) index of this handler. This is not an AST ID.
1226 class TryCatchStatement FINAL : public TryStatement {
1228 DECLARE_NODE_TYPE(TryCatchStatement)
1230 Scope* scope() { return scope_; }
1231 Variable* variable() { return variable_; }
1232 Block* catch_block() const { return catch_block_; }
1235 TryCatchStatement(Zone* zone,
1242 : TryStatement(zone, index, try_block, pos),
1244 variable_(variable),
1245 catch_block_(catch_block) {
1250 Variable* variable_;
1251 Block* catch_block_;
1255 class TryFinallyStatement FINAL : public TryStatement {
1257 DECLARE_NODE_TYPE(TryFinallyStatement)
1259 Block* finally_block() const { return finally_block_; }
1262 TryFinallyStatement(
1263 Zone* zone, int index, Block* try_block, Block* finally_block, int pos)
1264 : TryStatement(zone, index, try_block, pos),
1265 finally_block_(finally_block) { }
1268 Block* finally_block_;
1272 class DebuggerStatement FINAL : public Statement {
1274 DECLARE_NODE_TYPE(DebuggerStatement)
1276 void set_base_id(int id) { base_id_ = id; }
1277 static int num_ids() { return parent_num_ids() + 1; }
1278 BailoutId DebugBreakId() const { return BailoutId(local_id(0)); }
1281 explicit DebuggerStatement(Zone* zone, int pos)
1282 : Statement(zone, pos), base_id_(BailoutId::None().ToInt()) {}
1283 static int parent_num_ids() { return 0; }
1285 int base_id() const {
1286 DCHECK(!BailoutId(base_id_).IsNone());
1291 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1297 class EmptyStatement FINAL : public Statement {
1299 DECLARE_NODE_TYPE(EmptyStatement)
1302 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {}
1306 class Literal FINAL : public Expression {
1308 DECLARE_NODE_TYPE(Literal)
1310 bool IsPropertyName() const OVERRIDE { return value_->IsPropertyName(); }
1312 Handle<String> AsPropertyName() {
1313 DCHECK(IsPropertyName());
1314 return Handle<String>::cast(value());
1317 const AstRawString* AsRawPropertyName() {
1318 DCHECK(IsPropertyName());
1319 return value_->AsString();
1322 bool ToBooleanIsTrue() const OVERRIDE { return value()->BooleanValue(); }
1323 bool ToBooleanIsFalse() const OVERRIDE { return !value()->BooleanValue(); }
1325 Handle<Object> value() const { return value_->value(); }
1326 const AstValue* raw_value() const { return value_; }
1328 // Support for using Literal as a HashMap key. NOTE: Currently, this works
1329 // only for string and number literals!
1331 static bool Match(void* literal1, void* literal2);
1333 static int num_ids() { return parent_num_ids() + 1; }
1334 TypeFeedbackId LiteralFeedbackId() const {
1335 return TypeFeedbackId(local_id(0));
1339 Literal(Zone* zone, const AstValue* value, int position)
1340 : Expression(zone, position), value_(value) {}
1341 static int parent_num_ids() { return Expression::num_ids(); }
1344 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1346 const AstValue* value_;
1350 // Base class for literals that needs space in the corresponding JSFunction.
1351 class MaterializedLiteral : public Expression {
1353 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1355 int literal_index() { return literal_index_; }
1358 // only callable after initialization.
1359 DCHECK(depth_ >= 1);
1364 MaterializedLiteral(Zone* zone, int literal_index, int pos)
1365 : Expression(zone, pos),
1366 literal_index_(literal_index),
1370 // A materialized literal is simple if the values consist of only
1371 // constants and simple object and array literals.
1372 bool is_simple() const { return is_simple_; }
1373 void set_is_simple(bool is_simple) { is_simple_ = is_simple; }
1374 friend class CompileTimeValue;
1376 void set_depth(int depth) {
1381 // Populate the constant properties/elements fixed array.
1382 void BuildConstants(Isolate* isolate);
1383 friend class ArrayLiteral;
1384 friend class ObjectLiteral;
1386 // If the expression is a literal, return the literal value;
1387 // if the expression is a materialized literal and is simple return a
1388 // compile time value as encoded by CompileTimeValue::GetValue().
1389 // Otherwise, return undefined literal as the placeholder
1390 // in the object literal boilerplate.
1391 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate);
1400 // Property is used for passing information
1401 // about an object literal's properties from the parser
1402 // to the code generator.
1403 class ObjectLiteralProperty FINAL : public ZoneObject {
1406 CONSTANT, // Property with constant value (compile time).
1407 COMPUTED, // Property with computed value (execution time).
1408 MATERIALIZED_LITERAL, // Property value is a materialized literal.
1409 GETTER, SETTER, // Property is an accessor function.
1410 PROTOTYPE // Property is __proto__.
1413 Expression* key() { return key_; }
1414 Expression* value() { return value_; }
1415 Kind kind() { return kind_; }
1417 // Type feedback information.
1418 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1419 bool IsMonomorphic() { return !receiver_type_.is_null(); }
1420 Handle<Map> GetReceiverType() { return receiver_type_; }
1422 bool IsCompileTimeValue();
1424 void set_emit_store(bool emit_store);
1427 bool is_static() const { return is_static_; }
1428 bool is_computed_name() const { return is_computed_name_; }
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 // Bind this proxy to the variable var.
1636 void BindTo(Variable* var);
1638 bool UsesVariableFeedbackSlot() const {
1639 return FLAG_vector_ics && (var()->IsUnallocated() || var()->IsLookupSlot());
1642 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1643 Isolate* isolate) OVERRIDE {
1644 return FeedbackVectorRequirements(0, UsesVariableFeedbackSlot() ? 1 : 0);
1647 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
1648 variable_feedback_slot_ = slot;
1650 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; }
1651 FeedbackVectorICSlot VariableFeedbackSlot() {
1652 DCHECK(!UsesVariableFeedbackSlot() || !variable_feedback_slot_.IsInvalid());
1653 return variable_feedback_slot_;
1657 VariableProxy(Zone* zone, Variable* var, int position);
1659 VariableProxy(Zone* zone, const AstRawString* name, bool is_this,
1662 class IsThisField : public BitField8<bool, 0, 1> {};
1663 class IsAssignedField : public BitField8<bool, 1, 1> {};
1664 class IsResolvedField : public BitField8<bool, 2, 1> {};
1666 // Start with 16-bit (or smaller) field, which should get packed together
1667 // with Expression's trailing 16-bit field.
1669 FeedbackVectorICSlot variable_feedback_slot_;
1671 const AstRawString* raw_name_; // if !is_resolved_
1672 Variable* var_; // if is_resolved_
1677 class Property FINAL : public Expression {
1679 DECLARE_NODE_TYPE(Property)
1681 bool IsValidReferenceExpression() const OVERRIDE { return true; }
1683 Expression* obj() const { return obj_; }
1684 Expression* key() const { return key_; }
1686 static int num_ids() { return parent_num_ids() + 2; }
1687 BailoutId LoadId() const { return BailoutId(local_id(0)); }
1688 TypeFeedbackId PropertyFeedbackId() { return TypeFeedbackId(local_id(1)); }
1690 bool IsStringAccess() const {
1691 return IsStringAccessField::decode(bit_field_);
1694 // Type feedback information.
1695 bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; }
1696 SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; }
1697 KeyedAccessStoreMode GetStoreMode() const OVERRIDE { return STANDARD_STORE; }
1698 IcCheckType GetKeyType() const OVERRIDE {
1699 return KeyTypeField::decode(bit_field_);
1701 bool IsUninitialized() const {
1702 return !is_for_call() && HasNoTypeInformation();
1704 bool HasNoTypeInformation() const {
1705 return IsUninitializedField::decode(bit_field_);
1707 void set_is_uninitialized(bool b) {
1708 bit_field_ = IsUninitializedField::update(bit_field_, b);
1710 void set_is_string_access(bool b) {
1711 bit_field_ = IsStringAccessField::update(bit_field_, b);
1713 void set_key_type(IcCheckType key_type) {
1714 bit_field_ = KeyTypeField::update(bit_field_, key_type);
1716 void mark_for_call() {
1717 bit_field_ = IsForCallField::update(bit_field_, true);
1719 bool is_for_call() const { return IsForCallField::decode(bit_field_); }
1721 bool IsSuperAccess() {
1722 return obj()->IsSuperReference();
1725 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1726 Isolate* isolate) OVERRIDE {
1727 return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0);
1729 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
1730 property_feedback_slot_ = slot;
1732 Code::Kind FeedbackICSlotKind(int index) OVERRIDE {
1733 return key()->IsPropertyName() ? Code::LOAD_IC : Code::KEYED_LOAD_IC;
1736 FeedbackVectorICSlot PropertyFeedbackSlot() const {
1737 DCHECK(!FLAG_vector_ics || !property_feedback_slot_.IsInvalid());
1738 return property_feedback_slot_;
1742 Property(Zone* zone, Expression* obj, Expression* key, int pos)
1743 : Expression(zone, pos),
1744 bit_field_(IsForCallField::encode(false) |
1745 IsUninitializedField::encode(false) |
1746 IsStringAccessField::encode(false)),
1747 property_feedback_slot_(FeedbackVectorICSlot::Invalid()),
1750 static int parent_num_ids() { return Expression::num_ids(); }
1753 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1755 class IsForCallField : public BitField8<bool, 0, 1> {};
1756 class IsUninitializedField : public BitField8<bool, 1, 1> {};
1757 class IsStringAccessField : public BitField8<bool, 2, 1> {};
1758 class KeyTypeField : public BitField8<IcCheckType, 3, 1> {};
1760 FeedbackVectorICSlot property_feedback_slot_;
1763 SmallMapList receiver_types_;
1767 class Call FINAL : public Expression {
1769 DECLARE_NODE_TYPE(Call)
1771 Expression* expression() const { return expression_; }
1772 ZoneList<Expression*>* arguments() const { return arguments_; }
1774 // Type feedback information.
1775 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1776 Isolate* isolate) OVERRIDE;
1777 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
1778 ic_slot_or_slot_ = slot.ToInt();
1780 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
1781 ic_slot_or_slot_ = slot.ToInt();
1783 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::CALL_IC; }
1785 FeedbackVectorSlot CallFeedbackSlot() const {
1786 DCHECK(ic_slot_or_slot_ != FeedbackVectorSlot::Invalid().ToInt());
1787 return FeedbackVectorSlot(ic_slot_or_slot_);
1790 FeedbackVectorICSlot CallFeedbackICSlot() const {
1791 DCHECK(ic_slot_or_slot_ != FeedbackVectorICSlot::Invalid().ToInt());
1792 return FeedbackVectorICSlot(ic_slot_or_slot_);
1795 SmallMapList* GetReceiverTypes() OVERRIDE {
1796 if (expression()->IsProperty()) {
1797 return expression()->AsProperty()->GetReceiverTypes();
1802 bool IsMonomorphic() OVERRIDE {
1803 if (expression()->IsProperty()) {
1804 return expression()->AsProperty()->IsMonomorphic();
1806 return !target_.is_null();
1809 bool global_call() const {
1810 VariableProxy* proxy = expression_->AsVariableProxy();
1811 return proxy != NULL && proxy->var()->IsUnallocated();
1814 bool known_global_function() const {
1815 return global_call() && !target_.is_null();
1818 Handle<JSFunction> target() { return target_; }
1820 Handle<Cell> cell() { return cell_; }
1822 Handle<AllocationSite> allocation_site() { return allocation_site_; }
1824 void set_target(Handle<JSFunction> target) { target_ = target; }
1825 void set_allocation_site(Handle<AllocationSite> site) {
1826 allocation_site_ = site;
1828 bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupIterator* it);
1830 static int num_ids() { return parent_num_ids() + 2; }
1831 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1832 BailoutId EvalOrLookupId() const { return BailoutId(local_id(1)); }
1834 bool is_uninitialized() const {
1835 return IsUninitializedField::decode(bit_field_);
1837 void set_is_uninitialized(bool b) {
1838 bit_field_ = IsUninitializedField::update(bit_field_, b);
1850 // Helpers to determine how to handle the call.
1851 CallType GetCallType(Isolate* isolate) const;
1852 bool IsUsingCallFeedbackSlot(Isolate* isolate) const;
1853 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const;
1856 // Used to assert that the FullCodeGenerator records the return site.
1857 bool return_is_recorded_;
1861 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1863 : Expression(zone, pos),
1864 ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()),
1865 expression_(expression),
1866 arguments_(arguments),
1867 bit_field_(IsUninitializedField::encode(false)) {
1868 if (expression->IsProperty()) {
1869 expression->AsProperty()->mark_for_call();
1872 static int parent_num_ids() { return Expression::num_ids(); }
1875 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1877 // We store this as an integer because we don't know if we have a slot or
1878 // an ic slot until scoping time.
1879 int ic_slot_or_slot_;
1880 Expression* expression_;
1881 ZoneList<Expression*>* arguments_;
1882 Handle<JSFunction> target_;
1884 Handle<AllocationSite> allocation_site_;
1885 class IsUninitializedField : public BitField8<bool, 0, 1> {};
1890 class CallNew FINAL : public Expression {
1892 DECLARE_NODE_TYPE(CallNew)
1894 Expression* expression() const { return expression_; }
1895 ZoneList<Expression*>* arguments() const { return arguments_; }
1897 // Type feedback information.
1898 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1899 Isolate* isolate) OVERRIDE {
1900 return FeedbackVectorRequirements(FLAG_pretenuring_call_new ? 2 : 1, 0);
1902 void SetFirstFeedbackSlot(FeedbackVectorSlot slot) OVERRIDE {
1903 callnew_feedback_slot_ = slot;
1906 FeedbackVectorSlot CallNewFeedbackSlot() {
1907 DCHECK(!callnew_feedback_slot_.IsInvalid());
1908 return callnew_feedback_slot_;
1910 FeedbackVectorSlot AllocationSiteFeedbackSlot() {
1911 DCHECK(FLAG_pretenuring_call_new);
1912 return CallNewFeedbackSlot().next();
1915 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1916 bool IsMonomorphic() OVERRIDE { return is_monomorphic_; }
1917 Handle<JSFunction> target() const { return target_; }
1918 Handle<AllocationSite> allocation_site() const {
1919 return allocation_site_;
1922 static int num_ids() { return parent_num_ids() + 1; }
1923 static int feedback_slots() { return 1; }
1924 BailoutId ReturnId() const { return BailoutId(local_id(0)); }
1927 CallNew(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments,
1929 : Expression(zone, pos),
1930 expression_(expression),
1931 arguments_(arguments),
1932 is_monomorphic_(false),
1933 callnew_feedback_slot_(FeedbackVectorSlot::Invalid()) {}
1935 static int parent_num_ids() { return Expression::num_ids(); }
1938 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1940 Expression* expression_;
1941 ZoneList<Expression*>* arguments_;
1942 bool is_monomorphic_;
1943 Handle<JSFunction> target_;
1944 Handle<AllocationSite> allocation_site_;
1945 FeedbackVectorSlot callnew_feedback_slot_;
1949 // The CallRuntime class does not represent any official JavaScript
1950 // language construct. Instead it is used to call a C or JS function
1951 // with a set of arguments. This is used from the builtins that are
1952 // implemented in JavaScript (see "v8natives.js").
1953 class CallRuntime FINAL : public Expression {
1955 DECLARE_NODE_TYPE(CallRuntime)
1957 Handle<String> name() const { return raw_name_->string(); }
1958 const AstRawString* raw_name() const { return raw_name_; }
1959 const Runtime::Function* function() const { return function_; }
1960 ZoneList<Expression*>* arguments() const { return arguments_; }
1961 bool is_jsruntime() const { return function_ == NULL; }
1963 // Type feedback information.
1964 bool HasCallRuntimeFeedbackSlot() const {
1965 return FLAG_vector_ics && is_jsruntime();
1967 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
1968 Isolate* isolate) OVERRIDE {
1969 return FeedbackVectorRequirements(0, HasCallRuntimeFeedbackSlot() ? 1 : 0);
1971 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
1972 callruntime_feedback_slot_ = slot;
1974 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; }
1976 FeedbackVectorICSlot CallRuntimeFeedbackSlot() {
1977 DCHECK(!HasCallRuntimeFeedbackSlot() ||
1978 !callruntime_feedback_slot_.IsInvalid());
1979 return callruntime_feedback_slot_;
1982 static int num_ids() { return parent_num_ids() + 1; }
1983 TypeFeedbackId CallRuntimeFeedbackId() const {
1984 return TypeFeedbackId(local_id(0));
1988 CallRuntime(Zone* zone, const AstRawString* name,
1989 const Runtime::Function* function,
1990 ZoneList<Expression*>* arguments, int pos)
1991 : Expression(zone, pos),
1993 function_(function),
1994 arguments_(arguments),
1995 callruntime_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
1996 static int parent_num_ids() { return Expression::num_ids(); }
1999 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2001 const AstRawString* raw_name_;
2002 const Runtime::Function* function_;
2003 ZoneList<Expression*>* arguments_;
2004 FeedbackVectorICSlot callruntime_feedback_slot_;
2008 class UnaryOperation FINAL : public Expression {
2010 DECLARE_NODE_TYPE(UnaryOperation)
2012 Token::Value op() const { return op_; }
2013 Expression* expression() const { return expression_; }
2015 // For unary not (Token::NOT), the AST ids where true and false will
2016 // actually be materialized, respectively.
2017 static int num_ids() { return parent_num_ids() + 2; }
2018 BailoutId MaterializeTrueId() const { return BailoutId(local_id(0)); }
2019 BailoutId MaterializeFalseId() const { return BailoutId(local_id(1)); }
2021 virtual void RecordToBooleanTypeFeedback(
2022 TypeFeedbackOracle* oracle) OVERRIDE;
2025 UnaryOperation(Zone* zone, Token::Value op, Expression* expression, int pos)
2026 : Expression(zone, pos), op_(op), expression_(expression) {
2027 DCHECK(Token::IsUnaryOp(op));
2029 static int parent_num_ids() { return Expression::num_ids(); }
2032 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2035 Expression* expression_;
2039 class BinaryOperation FINAL : public Expression {
2041 DECLARE_NODE_TYPE(BinaryOperation)
2043 Token::Value op() const { return static_cast<Token::Value>(op_); }
2044 Expression* left() const { return left_; }
2045 Expression* right() const { return right_; }
2046 Handle<AllocationSite> allocation_site() const { return allocation_site_; }
2047 void set_allocation_site(Handle<AllocationSite> allocation_site) {
2048 allocation_site_ = allocation_site;
2051 // The short-circuit logical operations need an AST ID for their
2052 // right-hand subexpression.
2053 static int num_ids() { return parent_num_ids() + 2; }
2054 BailoutId RightId() const { return BailoutId(local_id(0)); }
2056 TypeFeedbackId BinaryOperationFeedbackId() const {
2057 return TypeFeedbackId(local_id(1));
2059 Maybe<int> fixed_right_arg() const {
2060 return has_fixed_right_arg_ ? Maybe<int>(fixed_right_arg_value_)
2063 void set_fixed_right_arg(Maybe<int> arg) {
2064 has_fixed_right_arg_ = arg.has_value;
2065 if (arg.has_value) fixed_right_arg_value_ = arg.value;
2068 virtual void RecordToBooleanTypeFeedback(
2069 TypeFeedbackOracle* oracle) OVERRIDE;
2072 BinaryOperation(Zone* zone, Token::Value op, Expression* left,
2073 Expression* right, int pos)
2074 : Expression(zone, pos),
2075 op_(static_cast<byte>(op)),
2076 has_fixed_right_arg_(false),
2077 fixed_right_arg_value_(0),
2080 DCHECK(Token::IsBinaryOp(op));
2082 static int parent_num_ids() { return Expression::num_ids(); }
2085 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2087 const byte op_; // actually Token::Value
2088 // TODO(rossberg): the fixed arg should probably be represented as a Constant
2089 // type for the RHS. Currenty it's actually a Maybe<int>
2090 bool has_fixed_right_arg_;
2091 int fixed_right_arg_value_;
2094 Handle<AllocationSite> allocation_site_;
2098 class CountOperation FINAL : public Expression {
2100 DECLARE_NODE_TYPE(CountOperation)
2102 bool is_prefix() const { return IsPrefixField::decode(bit_field_); }
2103 bool is_postfix() const { return !is_prefix(); }
2105 Token::Value op() const { return TokenField::decode(bit_field_); }
2106 Token::Value binary_op() {
2107 return (op() == Token::INC) ? Token::ADD : Token::SUB;
2110 Expression* expression() const { return expression_; }
2112 bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; }
2113 SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; }
2114 IcCheckType GetKeyType() const OVERRIDE {
2115 return KeyTypeField::decode(bit_field_);
2117 KeyedAccessStoreMode GetStoreMode() const OVERRIDE {
2118 return StoreModeField::decode(bit_field_);
2120 Type* type() const { return type_; }
2121 void set_key_type(IcCheckType type) {
2122 bit_field_ = KeyTypeField::update(bit_field_, type);
2124 void set_store_mode(KeyedAccessStoreMode mode) {
2125 bit_field_ = StoreModeField::update(bit_field_, mode);
2127 void set_type(Type* type) { type_ = type; }
2129 static int num_ids() { return parent_num_ids() + 4; }
2130 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2131 BailoutId ToNumberId() const { return BailoutId(local_id(1)); }
2132 TypeFeedbackId CountBinOpFeedbackId() const {
2133 return TypeFeedbackId(local_id(2));
2135 TypeFeedbackId CountStoreFeedbackId() const {
2136 return TypeFeedbackId(local_id(3));
2140 CountOperation(Zone* zone, Token::Value op, bool is_prefix, Expression* expr,
2142 : Expression(zone, pos),
2143 bit_field_(IsPrefixField::encode(is_prefix) |
2144 KeyTypeField::encode(ELEMENT) |
2145 StoreModeField::encode(STANDARD_STORE) |
2146 TokenField::encode(op)),
2148 expression_(expr) {}
2149 static int parent_num_ids() { return Expression::num_ids(); }
2152 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2154 class IsPrefixField : public BitField16<bool, 0, 1> {};
2155 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2156 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2157 class TokenField : public BitField16<Token::Value, 6, 8> {};
2159 // Starts with 16-bit field, which should get packed together with
2160 // Expression's trailing 16-bit field.
2161 uint16_t bit_field_;
2163 Expression* expression_;
2164 SmallMapList receiver_types_;
2168 class CompareOperation FINAL : public Expression {
2170 DECLARE_NODE_TYPE(CompareOperation)
2172 Token::Value op() const { return op_; }
2173 Expression* left() const { return left_; }
2174 Expression* right() const { return right_; }
2176 // Type feedback information.
2177 static int num_ids() { return parent_num_ids() + 1; }
2178 TypeFeedbackId CompareOperationFeedbackId() const {
2179 return TypeFeedbackId(local_id(0));
2181 Type* combined_type() const { return combined_type_; }
2182 void set_combined_type(Type* type) { combined_type_ = type; }
2184 // Match special cases.
2185 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check);
2186 bool IsLiteralCompareUndefined(Expression** expr, Isolate* isolate);
2187 bool IsLiteralCompareNull(Expression** expr);
2190 CompareOperation(Zone* zone, Token::Value op, Expression* left,
2191 Expression* right, int pos)
2192 : Expression(zone, pos),
2196 combined_type_(Type::None(zone)) {
2197 DCHECK(Token::IsCompareOp(op));
2199 static int parent_num_ids() { return Expression::num_ids(); }
2202 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2208 Type* combined_type_;
2212 class Conditional FINAL : public Expression {
2214 DECLARE_NODE_TYPE(Conditional)
2216 Expression* condition() const { return condition_; }
2217 Expression* then_expression() const { return then_expression_; }
2218 Expression* else_expression() const { return else_expression_; }
2220 static int num_ids() { return parent_num_ids() + 2; }
2221 BailoutId ThenId() const { return BailoutId(local_id(0)); }
2222 BailoutId ElseId() const { return BailoutId(local_id(1)); }
2225 Conditional(Zone* zone, Expression* condition, Expression* then_expression,
2226 Expression* else_expression, int position)
2227 : Expression(zone, position),
2228 condition_(condition),
2229 then_expression_(then_expression),
2230 else_expression_(else_expression) {}
2231 static int parent_num_ids() { return Expression::num_ids(); }
2234 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2236 Expression* condition_;
2237 Expression* then_expression_;
2238 Expression* else_expression_;
2242 class Assignment FINAL : public Expression {
2244 DECLARE_NODE_TYPE(Assignment)
2246 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
2248 Token::Value binary_op() const;
2250 Token::Value op() const { return TokenField::decode(bit_field_); }
2251 Expression* target() const { return target_; }
2252 Expression* value() const { return value_; }
2253 BinaryOperation* binary_operation() const { return binary_operation_; }
2255 // This check relies on the definition order of token in token.h.
2256 bool is_compound() const { return op() > Token::ASSIGN; }
2258 static int num_ids() { return parent_num_ids() + 2; }
2259 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2261 // Type feedback information.
2262 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); }
2263 bool IsMonomorphic() OVERRIDE { return receiver_types_.length() == 1; }
2264 bool IsUninitialized() const {
2265 return IsUninitializedField::decode(bit_field_);
2267 bool HasNoTypeInformation() {
2268 return IsUninitializedField::decode(bit_field_);
2270 SmallMapList* GetReceiverTypes() OVERRIDE { return &receiver_types_; }
2271 IcCheckType GetKeyType() const OVERRIDE {
2272 return KeyTypeField::decode(bit_field_);
2274 KeyedAccessStoreMode GetStoreMode() const OVERRIDE {
2275 return StoreModeField::decode(bit_field_);
2277 void set_is_uninitialized(bool b) {
2278 bit_field_ = IsUninitializedField::update(bit_field_, b);
2280 void set_key_type(IcCheckType key_type) {
2281 bit_field_ = KeyTypeField::update(bit_field_, key_type);
2283 void set_store_mode(KeyedAccessStoreMode mode) {
2284 bit_field_ = StoreModeField::update(bit_field_, mode);
2288 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value,
2290 static int parent_num_ids() { return Expression::num_ids(); }
2293 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2295 class IsUninitializedField : public BitField16<bool, 0, 1> {};
2296 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
2297 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 4> {};
2298 class TokenField : public BitField16<Token::Value, 6, 8> {};
2300 // Starts with 16-bit field, which should get packed together with
2301 // Expression's trailing 16-bit field.
2302 uint16_t bit_field_;
2303 Expression* target_;
2305 BinaryOperation* binary_operation_;
2306 SmallMapList receiver_types_;
2310 class Yield FINAL : public Expression {
2312 DECLARE_NODE_TYPE(Yield)
2315 kInitial, // The initial yield that returns the unboxed generator object.
2316 kSuspend, // A normal yield: { value: EXPRESSION, done: false }
2317 kDelegating, // A yield*.
2318 kFinal // A return: { value: EXPRESSION, done: true }
2321 Expression* generator_object() const { return generator_object_; }
2322 Expression* expression() const { return expression_; }
2323 Kind yield_kind() const { return yield_kind_; }
2325 // Delegating yield surrounds the "yield" in a "try/catch". This index
2326 // locates the catch handler in the handler table, and is equivalent to
2327 // TryCatchStatement::index().
2329 DCHECK_EQ(kDelegating, yield_kind());
2332 void set_index(int index) {
2333 DCHECK_EQ(kDelegating, yield_kind());
2337 // Type feedback information.
2338 bool HasFeedbackSlots() const {
2339 return FLAG_vector_ics && (yield_kind() == kDelegating);
2341 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2342 Isolate* isolate) OVERRIDE {
2343 return FeedbackVectorRequirements(0, HasFeedbackSlots() ? 3 : 0);
2345 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
2346 yield_first_feedback_slot_ = slot;
2348 Code::Kind FeedbackICSlotKind(int index) OVERRIDE {
2349 return index == 0 ? Code::KEYED_LOAD_IC : Code::LOAD_IC;
2352 FeedbackVectorICSlot KeyedLoadFeedbackSlot() {
2353 DCHECK(!HasFeedbackSlots() || !yield_first_feedback_slot_.IsInvalid());
2354 return yield_first_feedback_slot_;
2357 FeedbackVectorICSlot DoneFeedbackSlot() {
2358 return KeyedLoadFeedbackSlot().next();
2361 FeedbackVectorICSlot ValueFeedbackSlot() { return DoneFeedbackSlot().next(); }
2364 Yield(Zone* zone, Expression* generator_object, Expression* expression,
2365 Kind yield_kind, int pos)
2366 : Expression(zone, pos),
2367 generator_object_(generator_object),
2368 expression_(expression),
2369 yield_kind_(yield_kind),
2371 yield_first_feedback_slot_(FeedbackVectorICSlot::Invalid()) {}
2374 Expression* generator_object_;
2375 Expression* expression_;
2378 FeedbackVectorICSlot yield_first_feedback_slot_;
2382 class Throw FINAL : public Expression {
2384 DECLARE_NODE_TYPE(Throw)
2386 Expression* exception() const { return exception_; }
2389 Throw(Zone* zone, Expression* exception, int pos)
2390 : Expression(zone, pos), exception_(exception) {}
2393 Expression* exception_;
2397 class FunctionLiteral FINAL : public Expression {
2400 ANONYMOUS_EXPRESSION,
2405 enum ParameterFlag {
2406 kNoDuplicateParameters = 0,
2407 kHasDuplicateParameters = 1
2410 enum IsFunctionFlag {
2415 enum IsParenthesizedFlag {
2420 enum ArityRestriction {
2426 DECLARE_NODE_TYPE(FunctionLiteral)
2428 Handle<String> name() const { return raw_name_->string(); }
2429 const AstRawString* raw_name() const { return raw_name_; }
2430 Scope* scope() const { return scope_; }
2431 ZoneList<Statement*>* body() const { return body_; }
2432 void set_function_token_position(int pos) { function_token_position_ = pos; }
2433 int function_token_position() const { return function_token_position_; }
2434 int start_position() const;
2435 int end_position() const;
2436 int SourceSize() const { return end_position() - start_position(); }
2437 bool is_expression() const { return IsExpression::decode(bitfield_); }
2438 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
2439 LanguageMode language_mode() const;
2440 bool uses_super_property() const;
2442 static bool NeedsHomeObject(Expression* literal) {
2443 return literal != NULL && literal->IsFunctionLiteral() &&
2444 literal->AsFunctionLiteral()->uses_super_property();
2447 int materialized_literal_count() { return materialized_literal_count_; }
2448 int expected_property_count() { return expected_property_count_; }
2449 int handler_count() { return handler_count_; }
2450 int parameter_count() { return parameter_count_; }
2452 bool AllowsLazyCompilation();
2453 bool AllowsLazyCompilationWithoutContext();
2455 void InitializeSharedInfo(Handle<Code> code);
2457 Handle<String> debug_name() const {
2458 if (raw_name_ != NULL && !raw_name_->IsEmpty()) {
2459 return raw_name_->string();
2461 return inferred_name();
2464 Handle<String> inferred_name() const {
2465 if (!inferred_name_.is_null()) {
2466 DCHECK(raw_inferred_name_ == NULL);
2467 return inferred_name_;
2469 if (raw_inferred_name_ != NULL) {
2470 return raw_inferred_name_->string();
2473 return Handle<String>();
2476 // Only one of {set_inferred_name, set_raw_inferred_name} should be called.
2477 void set_inferred_name(Handle<String> inferred_name) {
2478 DCHECK(!inferred_name.is_null());
2479 inferred_name_ = inferred_name;
2480 DCHECK(raw_inferred_name_== NULL || raw_inferred_name_->IsEmpty());
2481 raw_inferred_name_ = NULL;
2484 void set_raw_inferred_name(const AstString* raw_inferred_name) {
2485 DCHECK(raw_inferred_name != NULL);
2486 raw_inferred_name_ = raw_inferred_name;
2487 DCHECK(inferred_name_.is_null());
2488 inferred_name_ = Handle<String>();
2491 // shared_info may be null if it's not cached in full code.
2492 Handle<SharedFunctionInfo> shared_info() { return shared_info_; }
2494 bool pretenure() { return Pretenure::decode(bitfield_); }
2495 void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
2497 bool has_duplicate_parameters() {
2498 return HasDuplicateParameters::decode(bitfield_);
2501 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }
2503 // This is used as a heuristic on when to eagerly compile a function
2504 // literal. We consider the following constructs as hints that the
2505 // function will be called immediately:
2506 // - (function() { ... })();
2507 // - var x = function() { ... }();
2508 bool is_parenthesized() {
2509 return IsParenthesized::decode(bitfield_) == kIsParenthesized;
2511 void set_parenthesized() {
2512 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
2515 FunctionKind kind() { return FunctionKindBits::decode(bitfield_); }
2517 int ast_node_count() { return ast_properties_.node_count(); }
2518 AstProperties::Flags* flags() { return ast_properties_.flags(); }
2519 void set_ast_properties(AstProperties* ast_properties) {
2520 ast_properties_ = *ast_properties;
2522 const FeedbackVectorSpec& feedback_vector_spec() const {
2523 return ast_properties_.get_spec();
2525 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2526 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2527 void set_dont_optimize_reason(BailoutReason reason) {
2528 dont_optimize_reason_ = reason;
2532 FunctionLiteral(Zone* zone, const AstRawString* name,
2533 AstValueFactory* ast_value_factory, Scope* scope,
2534 ZoneList<Statement*>* body, int materialized_literal_count,
2535 int expected_property_count, int handler_count,
2536 int parameter_count, FunctionType function_type,
2537 ParameterFlag has_duplicate_parameters,
2538 IsFunctionFlag is_function,
2539 IsParenthesizedFlag is_parenthesized, FunctionKind kind,
2541 : Expression(zone, position),
2545 raw_inferred_name_(ast_value_factory->empty_string()),
2546 dont_optimize_reason_(kNoReason),
2547 materialized_literal_count_(materialized_literal_count),
2548 expected_property_count_(expected_property_count),
2549 handler_count_(handler_count),
2550 parameter_count_(parameter_count),
2551 function_token_position_(RelocInfo::kNoPosition) {
2552 bitfield_ = IsExpression::encode(function_type != DECLARATION) |
2553 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
2554 Pretenure::encode(false) |
2555 HasDuplicateParameters::encode(has_duplicate_parameters) |
2556 IsFunction::encode(is_function) |
2557 IsParenthesized::encode(is_parenthesized) |
2558 FunctionKindBits::encode(kind);
2559 DCHECK(IsValidFunctionKind(kind));
2563 const AstRawString* raw_name_;
2564 Handle<String> name_;
2565 Handle<SharedFunctionInfo> shared_info_;
2567 ZoneList<Statement*>* body_;
2568 const AstString* raw_inferred_name_;
2569 Handle<String> inferred_name_;
2570 AstProperties ast_properties_;
2571 BailoutReason dont_optimize_reason_;
2573 int materialized_literal_count_;
2574 int expected_property_count_;
2576 int parameter_count_;
2577 int function_token_position_;
2580 class IsExpression : public BitField<bool, 0, 1> {};
2581 class IsAnonymous : public BitField<bool, 1, 1> {};
2582 class Pretenure : public BitField<bool, 2, 1> {};
2583 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
2584 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
2585 class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {};
2586 class FunctionKindBits : public BitField<FunctionKind, 6, 7> {};
2590 class ClassLiteral FINAL : public Expression {
2592 typedef ObjectLiteralProperty Property;
2594 DECLARE_NODE_TYPE(ClassLiteral)
2596 Handle<String> name() const { return raw_name_->string(); }
2597 const AstRawString* raw_name() const { return raw_name_; }
2598 Scope* scope() const { return scope_; }
2599 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; }
2600 Expression* extends() const { return extends_; }
2601 FunctionLiteral* constructor() const { return constructor_; }
2602 ZoneList<Property*>* properties() const { return properties_; }
2603 int start_position() const { return position(); }
2604 int end_position() const { return end_position_; }
2606 BailoutId EntryId() const { return BailoutId(local_id(0)); }
2607 BailoutId DeclsId() const { return BailoutId(local_id(1)); }
2608 BailoutId ExitId() { return BailoutId(local_id(2)); }
2610 // Return an AST id for a property that is used in simulate instructions.
2611 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 3)); }
2613 // Unlike other AST nodes, this number of bailout IDs allocated for an
2614 // ClassLiteral can vary, so num_ids() is not a static method.
2615 int num_ids() const { return parent_num_ids() + 3 + properties()->length(); }
2618 ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope,
2619 VariableProxy* class_variable_proxy, Expression* extends,
2620 FunctionLiteral* constructor, ZoneList<Property*>* properties,
2621 int start_position, int end_position)
2622 : Expression(zone, start_position),
2625 class_variable_proxy_(class_variable_proxy),
2627 constructor_(constructor),
2628 properties_(properties),
2629 end_position_(end_position) {}
2630 static int parent_num_ids() { return Expression::num_ids(); }
2633 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2635 const AstRawString* raw_name_;
2637 VariableProxy* class_variable_proxy_;
2638 Expression* extends_;
2639 FunctionLiteral* constructor_;
2640 ZoneList<Property*>* properties_;
2645 class NativeFunctionLiteral FINAL : public Expression {
2647 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2649 Handle<String> name() const { return name_->string(); }
2650 v8::Extension* extension() const { return extension_; }
2653 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2654 v8::Extension* extension, int pos)
2655 : Expression(zone, pos), name_(name), extension_(extension) {}
2658 const AstRawString* name_;
2659 v8::Extension* extension_;
2663 class ThisFunction FINAL : public Expression {
2665 DECLARE_NODE_TYPE(ThisFunction)
2668 ThisFunction(Zone* zone, int pos) : Expression(zone, pos) {}
2672 class SuperReference FINAL : public Expression {
2674 DECLARE_NODE_TYPE(SuperReference)
2676 VariableProxy* this_var() const { return this_var_; }
2678 static int num_ids() { return parent_num_ids() + 1; }
2679 TypeFeedbackId HomeObjectFeedbackId() { return TypeFeedbackId(local_id(0)); }
2681 // Type feedback information.
2682 virtual FeedbackVectorRequirements ComputeFeedbackRequirements(
2683 Isolate* isolate) OVERRIDE {
2684 return FeedbackVectorRequirements(0, FLAG_vector_ics ? 1 : 0);
2686 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE {
2687 homeobject_feedback_slot_ = slot;
2689 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; }
2691 FeedbackVectorICSlot HomeObjectFeedbackSlot() {
2692 DCHECK(!FLAG_vector_ics || !homeobject_feedback_slot_.IsInvalid());
2693 return homeobject_feedback_slot_;
2697 SuperReference(Zone* zone, VariableProxy* this_var, int pos)
2698 : Expression(zone, pos),
2699 this_var_(this_var),
2700 homeobject_feedback_slot_(FeedbackVectorICSlot::Invalid()) {
2701 DCHECK(this_var->is_this());
2703 static int parent_num_ids() { return Expression::num_ids(); }
2706 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2708 VariableProxy* this_var_;
2709 FeedbackVectorICSlot homeobject_feedback_slot_;
2713 #undef DECLARE_NODE_TYPE
2716 // ----------------------------------------------------------------------------
2717 // Regular expressions
2720 class RegExpVisitor BASE_EMBEDDED {
2722 virtual ~RegExpVisitor() { }
2723 #define MAKE_CASE(Name) \
2724 virtual void* Visit##Name(RegExp##Name*, void* data) = 0;
2725 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE)
2730 class RegExpTree : public ZoneObject {
2732 static const int kInfinity = kMaxInt;
2733 virtual ~RegExpTree() {}
2734 virtual void* Accept(RegExpVisitor* visitor, void* data) = 0;
2735 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2736 RegExpNode* on_success) = 0;
2737 virtual bool IsTextElement() { return false; }
2738 virtual bool IsAnchoredAtStart() { return false; }
2739 virtual bool IsAnchoredAtEnd() { return false; }
2740 virtual int min_match() = 0;
2741 virtual int max_match() = 0;
2742 // Returns the interval of registers used for captures within this
2744 virtual Interval CaptureRegisters() { return Interval::Empty(); }
2745 virtual void AppendToText(RegExpText* text, Zone* zone);
2746 std::ostream& Print(std::ostream& os, Zone* zone); // NOLINT
2747 #define MAKE_ASTYPE(Name) \
2748 virtual RegExp##Name* As##Name(); \
2749 virtual bool Is##Name();
2750 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_ASTYPE)
2755 class RegExpDisjunction FINAL : public RegExpTree {
2757 explicit RegExpDisjunction(ZoneList<RegExpTree*>* alternatives);
2758 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2759 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2760 RegExpNode* on_success) OVERRIDE;
2761 RegExpDisjunction* AsDisjunction() OVERRIDE;
2762 Interval CaptureRegisters() OVERRIDE;
2763 bool IsDisjunction() OVERRIDE;
2764 bool IsAnchoredAtStart() OVERRIDE;
2765 bool IsAnchoredAtEnd() OVERRIDE;
2766 int min_match() OVERRIDE { return min_match_; }
2767 int max_match() OVERRIDE { return max_match_; }
2768 ZoneList<RegExpTree*>* alternatives() { return alternatives_; }
2770 ZoneList<RegExpTree*>* alternatives_;
2776 class RegExpAlternative FINAL : public RegExpTree {
2778 explicit RegExpAlternative(ZoneList<RegExpTree*>* nodes);
2779 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2780 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2781 RegExpNode* on_success) OVERRIDE;
2782 RegExpAlternative* AsAlternative() OVERRIDE;
2783 Interval CaptureRegisters() OVERRIDE;
2784 bool IsAlternative() OVERRIDE;
2785 bool IsAnchoredAtStart() OVERRIDE;
2786 bool IsAnchoredAtEnd() OVERRIDE;
2787 int min_match() OVERRIDE { return min_match_; }
2788 int max_match() OVERRIDE { return max_match_; }
2789 ZoneList<RegExpTree*>* nodes() { return nodes_; }
2791 ZoneList<RegExpTree*>* nodes_;
2797 class RegExpAssertion FINAL : public RegExpTree {
2799 enum AssertionType {
2807 explicit RegExpAssertion(AssertionType type) : assertion_type_(type) { }
2808 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2809 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2810 RegExpNode* on_success) OVERRIDE;
2811 RegExpAssertion* AsAssertion() OVERRIDE;
2812 bool IsAssertion() OVERRIDE;
2813 bool IsAnchoredAtStart() OVERRIDE;
2814 bool IsAnchoredAtEnd() OVERRIDE;
2815 int min_match() OVERRIDE { return 0; }
2816 int max_match() OVERRIDE { return 0; }
2817 AssertionType assertion_type() { return assertion_type_; }
2819 AssertionType assertion_type_;
2823 class CharacterSet FINAL BASE_EMBEDDED {
2825 explicit CharacterSet(uc16 standard_set_type)
2827 standard_set_type_(standard_set_type) {}
2828 explicit CharacterSet(ZoneList<CharacterRange>* ranges)
2830 standard_set_type_(0) {}
2831 ZoneList<CharacterRange>* ranges(Zone* zone);
2832 uc16 standard_set_type() { return standard_set_type_; }
2833 void set_standard_set_type(uc16 special_set_type) {
2834 standard_set_type_ = special_set_type;
2836 bool is_standard() { return standard_set_type_ != 0; }
2837 void Canonicalize();
2839 ZoneList<CharacterRange>* ranges_;
2840 // If non-zero, the value represents a standard set (e.g., all whitespace
2841 // characters) without having to expand the ranges.
2842 uc16 standard_set_type_;
2846 class RegExpCharacterClass FINAL : public RegExpTree {
2848 RegExpCharacterClass(ZoneList<CharacterRange>* ranges, bool is_negated)
2850 is_negated_(is_negated) { }
2851 explicit RegExpCharacterClass(uc16 type)
2853 is_negated_(false) { }
2854 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2855 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2856 RegExpNode* on_success) OVERRIDE;
2857 RegExpCharacterClass* AsCharacterClass() OVERRIDE;
2858 bool IsCharacterClass() OVERRIDE;
2859 bool IsTextElement() OVERRIDE { return true; }
2860 int min_match() OVERRIDE { return 1; }
2861 int max_match() OVERRIDE { return 1; }
2862 void AppendToText(RegExpText* text, Zone* zone) OVERRIDE;
2863 CharacterSet character_set() { return set_; }
2864 // TODO(lrn): Remove need for complex version if is_standard that
2865 // recognizes a mangled standard set and just do { return set_.is_special(); }
2866 bool is_standard(Zone* zone);
2867 // Returns a value representing the standard character set if is_standard()
2869 // Currently used values are:
2870 // s : unicode whitespace
2871 // S : unicode non-whitespace
2872 // w : ASCII word character (digit, letter, underscore)
2873 // W : non-ASCII word character
2875 // D : non-ASCII digit
2876 // . : non-unicode non-newline
2877 // * : All characters
2878 uc16 standard_type() { return set_.standard_set_type(); }
2879 ZoneList<CharacterRange>* ranges(Zone* zone) { return set_.ranges(zone); }
2880 bool is_negated() { return is_negated_; }
2888 class RegExpAtom FINAL : public RegExpTree {
2890 explicit RegExpAtom(Vector<const uc16> data) : data_(data) { }
2891 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2892 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2893 RegExpNode* on_success) OVERRIDE;
2894 RegExpAtom* AsAtom() OVERRIDE;
2895 bool IsAtom() OVERRIDE;
2896 bool IsTextElement() OVERRIDE { return true; }
2897 int min_match() OVERRIDE { return data_.length(); }
2898 int max_match() OVERRIDE { return data_.length(); }
2899 void AppendToText(RegExpText* text, Zone* zone) OVERRIDE;
2900 Vector<const uc16> data() { return data_; }
2901 int length() { return data_.length(); }
2903 Vector<const uc16> data_;
2907 class RegExpText FINAL : public RegExpTree {
2909 explicit RegExpText(Zone* zone) : elements_(2, zone), length_(0) {}
2910 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2911 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2912 RegExpNode* on_success) OVERRIDE;
2913 RegExpText* AsText() OVERRIDE;
2914 bool IsText() OVERRIDE;
2915 bool IsTextElement() OVERRIDE { return true; }
2916 int min_match() OVERRIDE { return length_; }
2917 int max_match() OVERRIDE { return length_; }
2918 void AppendToText(RegExpText* text, Zone* zone) OVERRIDE;
2919 void AddElement(TextElement elm, Zone* zone) {
2920 elements_.Add(elm, zone);
2921 length_ += elm.length();
2923 ZoneList<TextElement>* elements() { return &elements_; }
2925 ZoneList<TextElement> elements_;
2930 class RegExpQuantifier FINAL : public RegExpTree {
2932 enum QuantifierType { GREEDY, NON_GREEDY, POSSESSIVE };
2933 RegExpQuantifier(int min, int max, QuantifierType type, RegExpTree* body)
2937 min_match_(min * body->min_match()),
2938 quantifier_type_(type) {
2939 if (max > 0 && body->max_match() > kInfinity / max) {
2940 max_match_ = kInfinity;
2942 max_match_ = max * body->max_match();
2945 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2946 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2947 RegExpNode* on_success) OVERRIDE;
2948 static RegExpNode* ToNode(int min,
2952 RegExpCompiler* compiler,
2953 RegExpNode* on_success,
2954 bool not_at_start = false);
2955 RegExpQuantifier* AsQuantifier() OVERRIDE;
2956 Interval CaptureRegisters() OVERRIDE;
2957 bool IsQuantifier() OVERRIDE;
2958 int min_match() OVERRIDE { return min_match_; }
2959 int max_match() OVERRIDE { return max_match_; }
2960 int min() { return min_; }
2961 int max() { return max_; }
2962 bool is_possessive() { return quantifier_type_ == POSSESSIVE; }
2963 bool is_non_greedy() { return quantifier_type_ == NON_GREEDY; }
2964 bool is_greedy() { return quantifier_type_ == GREEDY; }
2965 RegExpTree* body() { return body_; }
2973 QuantifierType quantifier_type_;
2977 class RegExpCapture FINAL : public RegExpTree {
2979 explicit RegExpCapture(RegExpTree* body, int index)
2980 : body_(body), index_(index) { }
2981 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
2982 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
2983 RegExpNode* on_success) OVERRIDE;
2984 static RegExpNode* ToNode(RegExpTree* body,
2986 RegExpCompiler* compiler,
2987 RegExpNode* on_success);
2988 RegExpCapture* AsCapture() OVERRIDE;
2989 bool IsAnchoredAtStart() OVERRIDE;
2990 bool IsAnchoredAtEnd() OVERRIDE;
2991 Interval CaptureRegisters() OVERRIDE;
2992 bool IsCapture() OVERRIDE;
2993 int min_match() OVERRIDE { return body_->min_match(); }
2994 int max_match() OVERRIDE { return body_->max_match(); }
2995 RegExpTree* body() { return body_; }
2996 int index() { return index_; }
2997 static int StartRegister(int index) { return index * 2; }
2998 static int EndRegister(int index) { return index * 2 + 1; }
3006 class RegExpLookahead FINAL : public RegExpTree {
3008 RegExpLookahead(RegExpTree* body,
3013 is_positive_(is_positive),
3014 capture_count_(capture_count),
3015 capture_from_(capture_from) { }
3017 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3018 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3019 RegExpNode* on_success) OVERRIDE;
3020 RegExpLookahead* AsLookahead() OVERRIDE;
3021 Interval CaptureRegisters() OVERRIDE;
3022 bool IsLookahead() OVERRIDE;
3023 bool IsAnchoredAtStart() OVERRIDE;
3024 int min_match() OVERRIDE { return 0; }
3025 int max_match() OVERRIDE { return 0; }
3026 RegExpTree* body() { return body_; }
3027 bool is_positive() { return is_positive_; }
3028 int capture_count() { return capture_count_; }
3029 int capture_from() { return capture_from_; }
3039 class RegExpBackReference FINAL : public RegExpTree {
3041 explicit RegExpBackReference(RegExpCapture* capture)
3042 : capture_(capture) { }
3043 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3044 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3045 RegExpNode* on_success) OVERRIDE;
3046 RegExpBackReference* AsBackReference() OVERRIDE;
3047 bool IsBackReference() OVERRIDE;
3048 int min_match() OVERRIDE { return 0; }
3049 int max_match() OVERRIDE { return capture_->max_match(); }
3050 int index() { return capture_->index(); }
3051 RegExpCapture* capture() { return capture_; }
3053 RegExpCapture* capture_;
3057 class RegExpEmpty FINAL : public RegExpTree {
3060 void* Accept(RegExpVisitor* visitor, void* data) OVERRIDE;
3061 virtual RegExpNode* ToNode(RegExpCompiler* compiler,
3062 RegExpNode* on_success) OVERRIDE;
3063 RegExpEmpty* AsEmpty() OVERRIDE;
3064 bool IsEmpty() OVERRIDE;
3065 int min_match() OVERRIDE { return 0; }
3066 int max_match() OVERRIDE { return 0; }
3070 // ----------------------------------------------------------------------------
3072 // - leaf node visitors are abstract.
3074 class AstVisitor BASE_EMBEDDED {
3077 virtual ~AstVisitor() {}
3079 // Stack overflow check and dynamic dispatch.
3080 virtual void Visit(AstNode* node) = 0;
3082 // Iteration left-to-right.
3083 virtual void VisitDeclarations(ZoneList<Declaration*>* declarations);
3084 virtual void VisitStatements(ZoneList<Statement*>* statements);
3085 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
3087 // Individual AST nodes.
3088 #define DEF_VISIT(type) \
3089 virtual void Visit##type(type* node) = 0;
3090 AST_NODE_LIST(DEF_VISIT)
3095 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
3097 void Visit(AstNode* node) FINAL { \
3098 if (!CheckStackOverflow()) node->Accept(this); \
3101 void SetStackOverflow() { stack_overflow_ = true; } \
3102 void ClearStackOverflow() { stack_overflow_ = false; } \
3103 bool HasStackOverflow() const { return stack_overflow_; } \
3105 bool CheckStackOverflow() { \
3106 if (stack_overflow_) return true; \
3107 StackLimitCheck check(isolate_); \
3108 if (!check.HasOverflowed()) return false; \
3109 stack_overflow_ = true; \
3114 void InitializeAstVisitor(Isolate* isolate, Zone* zone) { \
3115 isolate_ = isolate; \
3117 stack_overflow_ = false; \
3119 Zone* zone() { return zone_; } \
3120 Isolate* isolate() { return isolate_; } \
3122 Isolate* isolate_; \
3124 bool stack_overflow_
3127 // ----------------------------------------------------------------------------
3130 class AstNodeFactory FINAL BASE_EMBEDDED {
3132 explicit AstNodeFactory(AstValueFactory* ast_value_factory)
3133 : zone_(ast_value_factory->zone()),
3134 ast_value_factory_(ast_value_factory) {}
3136 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
3140 return new (zone_) VariableDeclaration(zone_, proxy, mode, scope, pos);
3143 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
3145 FunctionLiteral* fun,
3148 return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
3151 ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy,
3155 return new (zone_) ModuleDeclaration(zone_, proxy, module, scope, pos);
3158 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
3162 return new (zone_) ImportDeclaration(zone_, proxy, module, scope, pos);
3165 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
3168 return new (zone_) ExportDeclaration(zone_, proxy, scope, pos);
3171 ModuleLiteral* NewModuleLiteral(Block* body, ModuleDescriptor* descriptor,
3173 return new (zone_) ModuleLiteral(zone_, body, descriptor, pos);
3176 ModulePath* NewModulePath(Module* origin, const AstRawString* name, int pos) {
3177 return new (zone_) ModulePath(zone_, origin, name, pos);
3180 ModuleUrl* NewModuleUrl(Handle<String> url, int pos) {
3181 return new (zone_) ModuleUrl(zone_, url, pos);
3184 Block* NewBlock(ZoneList<const AstRawString*>* labels,
3186 bool is_initializer_block,
3189 Block(zone_, labels, capacity, is_initializer_block, pos);
3192 #define STATEMENT_WITH_LABELS(NodeType) \
3193 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
3194 return new (zone_) NodeType(zone_, labels, pos); \
3196 STATEMENT_WITH_LABELS(DoWhileStatement)
3197 STATEMENT_WITH_LABELS(WhileStatement)
3198 STATEMENT_WITH_LABELS(ForStatement)
3199 STATEMENT_WITH_LABELS(SwitchStatement)
3200 #undef STATEMENT_WITH_LABELS
3202 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3203 ZoneList<const AstRawString*>* labels,
3205 switch (visit_mode) {
3206 case ForEachStatement::ENUMERATE: {
3207 return new (zone_) ForInStatement(zone_, labels, pos);
3209 case ForEachStatement::ITERATE: {
3210 return new (zone_) ForOfStatement(zone_, labels, pos);
3217 ModuleStatement* NewModuleStatement(Block* body, int pos) {
3218 return new (zone_) ModuleStatement(zone_, body, pos);
3221 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3222 return new (zone_) ExpressionStatement(zone_, expression, pos);
3225 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
3226 return new (zone_) ContinueStatement(zone_, target, pos);
3229 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
3230 return new (zone_) BreakStatement(zone_, target, pos);
3233 ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
3234 return new (zone_) ReturnStatement(zone_, expression, pos);
3237 WithStatement* NewWithStatement(Scope* scope,
3238 Expression* expression,
3239 Statement* statement,
3241 return new (zone_) WithStatement(zone_, scope, expression, statement, pos);
3244 IfStatement* NewIfStatement(Expression* condition,
3245 Statement* then_statement,
3246 Statement* else_statement,
3249 IfStatement(zone_, condition, then_statement, else_statement, pos);
3252 TryCatchStatement* NewTryCatchStatement(int index,
3258 return new (zone_) TryCatchStatement(zone_, index, try_block, scope,
3259 variable, catch_block, pos);
3262 TryFinallyStatement* NewTryFinallyStatement(int index,
3264 Block* finally_block,
3267 TryFinallyStatement(zone_, index, try_block, finally_block, pos);
3270 DebuggerStatement* NewDebuggerStatement(int pos) {
3271 return new (zone_) DebuggerStatement(zone_, pos);
3274 EmptyStatement* NewEmptyStatement(int pos) {
3275 return new(zone_) EmptyStatement(zone_, pos);
3278 CaseClause* NewCaseClause(
3279 Expression* label, ZoneList<Statement*>* statements, int pos) {
3280 return new (zone_) CaseClause(zone_, label, statements, pos);
3283 Literal* NewStringLiteral(const AstRawString* string, int pos) {
3285 Literal(zone_, ast_value_factory_->NewString(string), pos);
3288 // A JavaScript symbol (ECMA-262 edition 6).
3289 Literal* NewSymbolLiteral(const char* name, int pos) {
3290 return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3293 Literal* NewNumberLiteral(double number, int pos) {
3295 Literal(zone_, ast_value_factory_->NewNumber(number), pos);
3298 Literal* NewSmiLiteral(int number, int pos) {
3299 return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3302 Literal* NewBooleanLiteral(bool b, int pos) {
3303 return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3306 Literal* NewNullLiteral(int pos) {
3307 return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3310 Literal* NewUndefinedLiteral(int pos) {
3311 return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3314 Literal* NewTheHoleLiteral(int pos) {
3315 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3318 ObjectLiteral* NewObjectLiteral(
3319 ZoneList<ObjectLiteral::Property*>* properties,
3321 int boilerplate_properties,
3324 return new (zone_) ObjectLiteral(zone_, properties, literal_index,
3325 boilerplate_properties, has_function, pos);
3328 ObjectLiteral::Property* NewObjectLiteralProperty(
3329 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3330 bool is_static, bool is_computed_name) {
3332 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name);
3335 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
3338 bool is_computed_name) {
3339 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
3340 is_static, is_computed_name);
3343 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3344 const AstRawString* flags,
3347 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos);
3350 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3353 return new (zone_) ArrayLiteral(zone_, values, literal_index, pos);
3356 VariableProxy* NewVariableProxy(Variable* var,
3357 int pos = RelocInfo::kNoPosition) {
3358 return new (zone_) VariableProxy(zone_, var, pos);
3361 VariableProxy* NewVariableProxy(const AstRawString* name,
3363 int position = RelocInfo::kNoPosition) {
3364 return new (zone_) VariableProxy(zone_, name, is_this, position);
3367 Property* NewProperty(Expression* obj, Expression* key, int pos) {
3368 return new (zone_) Property(zone_, obj, key, pos);
3371 Call* NewCall(Expression* expression,
3372 ZoneList<Expression*>* arguments,
3374 return new (zone_) Call(zone_, expression, arguments, pos);
3377 CallNew* NewCallNew(Expression* expression,
3378 ZoneList<Expression*>* arguments,
3380 return new (zone_) CallNew(zone_, expression, arguments, pos);
3383 CallRuntime* NewCallRuntime(const AstRawString* name,
3384 const Runtime::Function* function,
3385 ZoneList<Expression*>* arguments,
3387 return new (zone_) CallRuntime(zone_, name, function, arguments, pos);
3390 UnaryOperation* NewUnaryOperation(Token::Value op,
3391 Expression* expression,
3393 return new (zone_) UnaryOperation(zone_, op, expression, pos);
3396 BinaryOperation* NewBinaryOperation(Token::Value op,
3400 return new (zone_) BinaryOperation(zone_, op, left, right, pos);
3403 CountOperation* NewCountOperation(Token::Value op,
3407 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos);
3410 CompareOperation* NewCompareOperation(Token::Value op,
3414 return new (zone_) CompareOperation(zone_, op, left, right, pos);
3417 Conditional* NewConditional(Expression* condition,
3418 Expression* then_expression,
3419 Expression* else_expression,
3421 return new (zone_) Conditional(zone_, condition, then_expression,
3422 else_expression, position);
3425 Assignment* NewAssignment(Token::Value op,
3429 DCHECK(Token::IsAssignmentOp(op));
3430 Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos);
3431 if (assign->is_compound()) {
3432 DCHECK(Token::IsAssignmentOp(op));
3433 assign->binary_operation_ =
3434 NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3439 Yield* NewYield(Expression *generator_object,
3440 Expression* expression,
3441 Yield::Kind yield_kind,
3443 if (!expression) expression = NewUndefinedLiteral(pos);
3445 Yield(zone_, generator_object, expression, yield_kind, pos);
3448 Throw* NewThrow(Expression* exception, int pos) {
3449 return new (zone_) Throw(zone_, exception, pos);
3452 FunctionLiteral* NewFunctionLiteral(
3453 const AstRawString* name, AstValueFactory* ast_value_factory,
3454 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3455 int expected_property_count, int handler_count, int parameter_count,
3456 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3457 FunctionLiteral::FunctionType function_type,
3458 FunctionLiteral::IsFunctionFlag is_function,
3459 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind,
3461 return new (zone_) FunctionLiteral(
3462 zone_, name, ast_value_factory, scope, body, materialized_literal_count,
3463 expected_property_count, handler_count, parameter_count, function_type,
3464 has_duplicate_parameters, is_function, is_parenthesized, kind,
3468 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope,
3469 VariableProxy* proxy, Expression* extends,
3470 FunctionLiteral* constructor,
3471 ZoneList<ObjectLiteral::Property*>* properties,
3472 int start_position, int end_position) {
3474 ClassLiteral(zone_, name, scope, proxy, extends, constructor,
3475 properties, start_position, end_position);
3478 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3479 v8::Extension* extension,
3481 return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3484 ThisFunction* NewThisFunction(int pos) {
3485 return new (zone_) ThisFunction(zone_, pos);
3488 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) {
3489 return new (zone_) SuperReference(zone_, this_var, pos);
3494 AstValueFactory* ast_value_factory_;
3498 } } // namespace v8::internal