10 #include "src/ast/ast-value-factory.h" 11 #include "src/ast/modules.h" 12 #include "src/ast/variables.h" 13 #include "src/bailout-reason.h" 14 #include "src/globals.h" 15 #include "src/heap/factory.h" 16 #include "src/isolate.h" 17 #include "src/label.h" 18 #include "src/objects/literal-objects.h" 19 #include "src/objects/smi.h" 20 #include "src/parsing/token.h" 21 #include "src/runtime/runtime.h" 39 #define DECLARATION_NODE_LIST(V) \ 40 V(VariableDeclaration) \ 41 V(FunctionDeclaration) 43 #define ITERATION_NODE_LIST(V) \ 50 #define BREAKABLE_NODE_LIST(V) \ 54 #define STATEMENT_NODE_LIST(V) \ 55 ITERATION_NODE_LIST(V) \ 56 BREAKABLE_NODE_LIST(V) \ 57 V(ExpressionStatement) \ 59 V(SloppyBlockFunctionStatement) \ 61 V(ContinueStatement) \ 65 V(TryCatchStatement) \ 66 V(TryFinallyStatement) \ 67 V(DebuggerStatement) \ 68 V(InitializeClassMembersStatement) 70 #define LITERAL_NODE_LIST(V) \ 75 #define EXPRESSION_NODE_LIST(V) \ 76 LITERAL_NODE_LIST(V) \ 86 V(CompoundAssignment) \ 93 V(GetTemplateObject) \ 94 V(ImportCallExpression) \ 96 V(NativeFunctionLiteral) \ 99 V(RewritableExpression) \ 101 V(StoreInArrayLiteral) \ 102 V(SuperCallReference) \ 103 V(SuperPropertyReference) \ 112 #define FAILURE_NODE_LIST(V) V(FailureExpression) 114 #define AST_NODE_LIST(V) \ 115 DECLARATION_NODE_LIST(V) \ 116 STATEMENT_NODE_LIST(V) \ 117 EXPRESSION_NODE_LIST(V) 121 class AstNodeFactory;
123 class BreakableStatement;
125 class IterationStatement;
126 class MaterializedLiteral;
127 class NestedVariableDeclaration;
128 class ProducedPreParsedScopeData;
131 #define DEF_FORWARD_DECLARATION(type) class type; 132 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
133 FAILURE_NODE_LIST(DEF_FORWARD_DECLARATION)
134 #undef DEF_FORWARD_DECLARATION 138 #define DECLARE_TYPE_ENUM(type) k##type, 139 enum NodeType : uint8_t {
140 AST_NODE_LIST(DECLARE_TYPE_ENUM)
141 FAILURE_NODE_LIST(DECLARE_TYPE_ENUM)
143 #undef DECLARE_TYPE_ENUM 145 void*
operator new(
size_t size,
Zone* zone) {
return zone->New(size); }
147 NodeType node_type()
const {
return NodeTypeField::decode(bit_field_); }
148 int position()
const {
return position_; }
156 #define DECLARE_NODE_FUNCTIONS(type) \ 157 V8_INLINE bool Is##type() const; \ 158 V8_INLINE type* As##type(); \ 159 V8_INLINE const type* As##type() const; 160 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
161 FAILURE_NODE_LIST(DECLARE_NODE_FUNCTIONS)
162 #undef DECLARE_NODE_FUNCTIONS 171 void*
operator new(
size_t size);
174 class NodeTypeField :
public BitField<NodeType, 0, 6> {};
178 static const uint8_t kNextBitFieldIndex = NodeTypeField::kNext;
181 : position_(position), bit_field_(NodeTypeField::encode(
type)) {}
192 static const uint8_t kNextBitFieldIndex = AstNode::kNextBitFieldIndex;
211 bool IsValidReferenceExpression()
const;
214 bool ToBooleanIsTrue()
const;
215 bool ToBooleanIsFalse()
const;
220 bool IsPropertyName()
const;
224 bool IsAnonymousFunctionDefinition()
const;
227 bool IsConciseMethodDefinition()
const;
230 bool IsAccessorFunctionDefinition()
const;
233 bool IsSmiLiteral()
const;
236 bool IsNumberLiteral()
const;
239 bool IsStringLiteral()
const;
242 bool IsNullLiteral()
const;
245 bool IsTheHoleLiteral()
const;
249 bool IsUndefinedLiteral()
const;
251 bool IsCompileTimeValue();
254 STATIC_ASSERT(kObjectLiteral + 1 == kArrayLiteral);
255 return IsInRange(node_type(), kObjectLiteral, kArrayLiteral);
258 bool is_parenthesized()
const {
259 return IsParenthesizedField::decode(bit_field_);
262 void mark_parenthesized() {
263 bit_field_ = IsParenthesizedField::update(bit_field_,
true);
267 class IsParenthesizedField
268 :
public BitField<bool, AstNode::kNextBitFieldIndex, 1> {};
272 DCHECK(!is_parenthesized());
275 static const uint8_t kNextBitFieldIndex = IsParenthesizedField::kNext;
304 TARGET_FOR_ANONYMOUS,
305 TARGET_FOR_NAMED_ONLY
318 bool is_target_for_anonymous()
const {
319 return BreakableTypeField::decode(bit_field_) == TARGET_FOR_ANONYMOUS;
323 class BreakableTypeField
324 :
public BitField<BreakableType, Statement::kNextBitFieldIndex, 1> {};
329 bit_field_ |= BreakableTypeField::encode(breakable_type);
332 static const uint8_t kNextBitFieldIndex = BreakableTypeField::kNext;
338 bool ignore_completion_value()
const {
339 return IgnoreCompletionField::decode(bit_field_);
344 bool IsJump()
const {
345 return !statements_.is_empty() && statements_.last()->IsJump() &&
349 Scope* scope()
const {
return scope_; }
350 void set_scope(
Scope* scope) { scope_ = scope; }
354 DCHECK_EQ(0, statements_.length());
355 statements.CopyTo(&statements_, zone);
364 class IgnoreCompletionField
365 :
public BitField<bool, BreakableStatement::kNextBitFieldIndex, 1> {};
367 :
public BitField<bool, IgnoreCompletionField::kNext, 1> {};
371 bool ignore_completion_value)
373 statements_(capacity, zone),
375 bit_field_ |= IgnoreCompletionField::encode(ignore_completion_value) |
376 IsLabeledField::encode(labels !=
nullptr);
380 :
Block(
nullptr, labels, 0, ignore_completion_value) {}
389 int capacity,
bool ignore_completion_value)
390 :
Block(zone, labels, capacity, ignore_completion_value),
392 DCHECK_NOT_NULL(labels);
393 DCHECK_GT(labels->length(), 0);
397 bool ignore_completion_value)
398 :
LabeledBlock(
nullptr, labels, 0, ignore_completion_value) {}
404 if (IsLabeledField::decode(bit_field_)) {
412 Block* block() {
return block_; }
419 :
Expression(pos, kDoExpression), block_(block), result_(result) {
420 DCHECK_NOT_NULL(block_);
421 DCHECK_NOT_NULL(result_);
437 :
AstNode(pos,
type), proxy_(proxy), next_(
nullptr) {}
456 :
public BitField<bool, Declaration::kNextBitFieldIndex, 1> {};
461 bit_field_ = IsNestedField::update(bit_field_, is_nested);
464 static const uint8_t kNextBitFieldIndex = IsNestedField::kNext;
472 Scope* scope()
const {
return scope_; }
485 return IsNestedField::decode(bit_field_)
493 bool declares_sloppy_block_function()
const {
494 return DeclaresSloppyBlockFunction::decode(bit_field_);
500 class DeclaresSloppyBlockFunction
501 :
public BitField<bool, Declaration::kNextBitFieldIndex, 1> {};
504 bool declares_sloppy_block_function,
int pos)
505 :
Declaration(proxy, pos, kFunctionDeclaration), fun_(fun) {
506 bit_field_ = DeclaresSloppyBlockFunction::update(
507 bit_field_, declares_sloppy_block_function);
512 static const uint8_t kNextBitFieldIndex = DeclaresSloppyBlockFunction::kNext;
518 Statement* body()
const {
return body_; }
519 void set_body(
Statement* s) { body_ = s; }
539 own_labels_(own_labels),
541 void Initialize(
Statement* body) { body_ = body; }
543 static const uint8_t kNextBitFieldIndex =
544 BreakableStatement::kNextBitFieldIndex;
556 IterationStatement::Initialize(body);
577 IterationStatement::Initialize(body);
599 IterationStatement::Initialize(body);
605 Statement* init()
const {
return init_; }
607 Statement* next()
const {
return next_; }
632 using IterationStatement::Initialize;
634 static const char* VisitModeString(VisitMode mode) {
635 return mode == ITERATE ?
"for-of" :
"for-in";
649 ForEachStatement::Initialize(body);
659 Expression* subject()
const {
return subject_; }
661 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
662 ForInType for_in_type()
const {
return ForInTypeField::decode(bit_field_); }
672 bit_field_ = ForInTypeField::update(bit_field_, SLOW_FOR_IN);
679 :
public BitField<ForInType, ForEachStatement::kNextBitFieldIndex, 1> {};
689 ForEachStatement::Initialize(body);
690 iterator_ = iterator;
691 assign_iterator_ = assign_iterator;
692 assign_next_ = assign_next;
693 next_result_ = next_result;
694 result_done_ = result_done;
695 assign_each_ = assign_each;
704 return assign_iterator_;
708 Expression* assign_next()
const {
return assign_next_; }
725 void set_assign_iterator(
Expression* e) { assign_iterator_ = e; }
726 void set_assign_next(
Expression* e) { assign_next_ = e; }
727 void set_next_result(
Expression* e) { next_result_ = e; }
728 void set_result_done(
Expression* e) { result_done_ = e; }
729 void set_assign_each(
Expression* e) { assign_each_ = e; }
738 assign_iterator_(
nullptr),
739 next_result_(
nullptr),
740 result_done_(
nullptr),
741 assign_each_(
nullptr) {}
754 void set_expression(
Expression* e) { expression_ = e; }
755 Expression* expression()
const {
return expression_; }
756 bool IsJump()
const {
return expression_->IsThrow(); }
762 :
Statement(pos, kExpressionStatement), expression_(expression) {}
770 bool IsJump()
const {
return true; }
807 enum Type { kNormal, kAsyncReturn };
808 Expression* expression()
const {
return expression_; }
810 Type
type()
const {
return TypeField::decode(bit_field_); }
811 bool is_async_return()
const {
return type() == kAsyncReturn; }
813 int end_position()
const {
return end_position_; }
820 expression_(expression),
821 end_position_(end_position) {
822 bit_field_ |= TypeField::encode(
type);
829 :
public BitField<Type, JumpStatement::kNextBitFieldIndex, 1> {};
835 Scope* scope() {
return scope_; }
836 Expression* expression()
const {
return expression_; }
837 Statement* statement()
const {
return statement_; }
838 void set_statement(
Statement* s) { statement_ = s; }
847 expression_(expression),
848 statement_(statement) {}
857 bool is_default()
const {
return label_ ==
nullptr; }
859 DCHECK(!is_default());
907 bool HasThenStatement()
const {
return !then_statement_->IsEmptyStatement(); }
908 bool HasElseStatement()
const {
return !else_statement_->IsEmptyStatement(); }
910 Expression* condition()
const {
return condition_; }
911 Statement* then_statement()
const {
return then_statement_; }
912 Statement* else_statement()
const {
return else_statement_; }
914 void set_then_statement(
Statement* s) { then_statement_ = s; }
915 void set_else_statement(
Statement* s) { else_statement_ = s; }
917 bool IsJump()
const {
918 return HasThenStatement() && then_statement()->IsJump()
919 && HasElseStatement() && else_statement()->IsJump();
928 condition_(condition),
929 then_statement_(then_statement),
930 else_statement_(else_statement) {}
940 Block* try_block()
const {
return try_block_; }
941 void set_try_block(
Block* b) { try_block_ = b; }
954 Scope* scope() {
return scope_; }
955 Block* catch_block()
const {
return catch_block_; }
956 void set_catch_block(
Block* b) { catch_block_ = b; }
974 inline HandlerTable::CatchPrediction GetCatchPrediction(
975 HandlerTable::CatchPrediction outer_catch_prediction)
const {
976 if (catch_prediction_ == HandlerTable::UNCAUGHT) {
977 return outer_catch_prediction;
979 return catch_prediction_;
1000 inline bool ShouldClearPendingException(
1001 HandlerTable::CatchPrediction outer_catch_prediction)
const {
1002 return catch_prediction_ != HandlerTable::UNCAUGHT ||
1003 outer_catch_prediction != HandlerTable::UNCAUGHT;
1010 HandlerTable::CatchPrediction catch_prediction,
int pos)
1013 catch_block_(catch_block),
1014 catch_prediction_(catch_prediction) {}
1017 Block* catch_block_;
1018 HandlerTable::CatchPrediction catch_prediction_;
1024 Block* finally_block()
const {
return finally_block_; }
1025 void set_finally_block(
Block* b) { finally_block_ = b; }
1032 finally_block_(finally_block) {}
1034 Block* finally_block_;
1059 Statement* statement()
const {
return statement_; }
1060 void set_statement(
Statement* statement) { statement_ = statement; }
1066 :
Statement(kNoSourcePosition, kSloppyBlockFunctionStatement),
1067 statement_(statement) {}
1087 Type
type()
const {
return TypeField::decode(bit_field_); }
1091 bool IsPropertyName()
const;
1098 bool AsArrayIndex(
uint32_t* index)
const;
1101 DCHECK(IsPropertyName());
1105 Smi AsSmiLiteral()
const {
1106 DCHECK_EQ(kSmi,
type());
1107 return Smi::FromInt(smi_);
1111 bool IsNumber()
const {
return type() == kHeapNumber ||
type() == kSmi; }
1112 double AsNumber()
const {
1125 DCHECK_EQ(
type(), kBigInt);
1129 bool IsString()
const {
return type() == kString; }
1131 DCHECK_EQ(
type(), kString);
1135 AstSymbol AsSymbol() {
1136 DCHECK_EQ(
type(), kSymbol);
1140 V8_EXPORT_PRIVATE
bool ToBooleanIsTrue()
const;
1141 bool ToBooleanIsFalse()
const {
return !ToBooleanIsTrue(); }
1143 bool ToUint32(
uint32_t* value)
const;
1152 static bool Match(
void* literal1,
void* literal2);
1157 class TypeField :
public BitField<Type, Expression::kNextBitFieldIndex, 4> {};
1160 bit_field_ = TypeField::update(bit_field_, kSmi);
1163 Literal(
double number,
int position)
1164 :
Expression(position, kLiteral), number_(number) {
1165 bit_field_ = TypeField::update(bit_field_, kHeapNumber);
1169 :
Expression(position, kLiteral), bigint_(bigint) {
1170 bit_field_ = TypeField::update(bit_field_, kBigInt);
1174 :
Expression(position, kLiteral), string_(
string) {
1175 bit_field_ = TypeField::update(bit_field_, kString);
1178 Literal(AstSymbol symbol,
int position)
1179 :
Expression(position, kLiteral), symbol_(symbol) {
1180 bit_field_ = TypeField::update(bit_field_, kSymbol);
1183 Literal(
bool boolean,
int position)
1184 :
Expression(position, kLiteral), boolean_(
boolean) {
1185 bit_field_ = TypeField::update(bit_field_, kBoolean);
1189 DCHECK(
type == kNull ||
type == kUndefined ||
type == kTheHole);
1190 bit_field_ = TypeField::update(bit_field_,
type);
1208 bool IsSimple()
const;
1213 friend class CompileTimeValue;
1218 int InitDepthAndFlags();
1220 bool NeedsInitialAllocationSite();
1223 void BuildConstants(
Isolate* isolate);
1237 const AstRawString* raw_pattern()
const {
return pattern_; }
1238 int flags()
const {
return flags_; }
1246 pattern_(pattern) {}
1259 kDisableMementos = 1 << 1,
1260 kNeedsInitialAllocationSite = 1 << 2,
1263 bool is_initialized()
const {
return 0 < depth_; }
1265 DCHECK(is_initialized());
1269 bool is_shallow()
const {
return depth() == 1; }
1270 bool needs_initial_allocation_site()
const {
1271 return NeedsInitialAllocationSiteField::decode(bit_field_);
1274 int ComputeFlags(
bool disable_mementos =
false)
const {
1275 int flags = kNoFlags;
1276 if (is_shallow()) flags |= kIsShallow;
1277 if (disable_mementos) flags |= kDisableMementos;
1278 if (needs_initial_allocation_site()) flags |= kNeedsInitialAllocationSite;
1284 bool is_simple()
const {
return IsSimpleField::decode(bit_field_); }
1288 class NeedsInitialAllocationSiteField
1289 :
public BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1> {};
1291 :
public BitField<bool, NeedsInitialAllocationSiteField::kNext, 1> {};
1297 bit_field_ |= NeedsInitialAllocationSiteField::encode(
false) |
1298 IsSimpleField::encode(
false);
1301 void set_is_simple(
bool is_simple) {
1302 bit_field_ = IsSimpleField::update(bit_field_, is_simple);
1305 void set_depth(
int depth) {
1306 DCHECK(!is_initialized());
1310 void set_needs_initial_allocation_site(
bool required) {
1311 bit_field_ = NeedsInitialAllocationSiteField::update(bit_field_, required);
1314 static const uint8_t kNextBitFieldIndex = IsSimpleField::kNext;
1320 Expression* key()
const {
return key_and_is_computed_name_.GetPointer(); }
1323 bool is_computed_name()
const {
1324 return key_and_is_computed_name_.GetPayload();
1326 bool NeedsSetFunctionName()
const;
1330 : key_and_is_computed_name_(key, is_computed_name), value_(value) {}
1341 enum Kind : uint8_t {
1344 MATERIALIZED_LITERAL,
1351 Kind kind()
const {
return kind_; }
1353 bool IsCompileTimeValue()
const;
1355 void set_emit_store(
bool emit_store);
1356 bool emit_store()
const;
1358 bool IsNullPrototype()
const {
1359 return IsPrototype() && value()->IsNullLiteral();
1361 bool IsPrototype()
const {
return kind() == PROTOTYPE; }
1367 bool is_computed_name);
1383 DCHECK(!boilerplate_description_.is_null());
1384 return boilerplate_description_;
1386 int properties_count()
const {
return boilerplate_properties_; }
1388 bool has_elements()
const {
return HasElementsField::decode(bit_field_); }
1389 bool has_rest_property()
const {
1390 return HasRestPropertyField::decode(bit_field_);
1392 bool fast_elements()
const {
return FastElementsField::decode(bit_field_); }
1393 bool has_null_prototype()
const {
1394 return HasNullPrototypeField::decode(bit_field_);
1397 bool is_empty()
const {
1398 DCHECK(is_initialized());
1399 return !has_elements() && properties_count() == 0 &&
1400 properties()->length() == 0;
1403 bool IsEmptyObjectLiteral()
const {
1404 return is_empty() && !has_null_prototype();
1408 int InitDepthAndFlags();
1413 if (boilerplate_description_.is_null()) {
1414 BuildBoilerplateDescription(isolate);
1416 return boilerplate_description();
1420 void BuildBoilerplateDescription(
Isolate* isolate);
1425 void CalculateEmitStore(
Zone* zone);
1428 bool IsFastCloningSupported()
const;
1431 int ComputeFlags(
bool disable_mementos =
false)
const {
1432 int flags = AggregateLiteral::ComputeFlags(disable_mementos);
1433 if (fast_elements()) flags |= kFastElements;
1434 if (has_null_prototype()) flags |= kHasNullPrototype;
1438 int EncodeLiteralType() {
1439 int flags = kNoFlags;
1440 if (fast_elements()) flags |= kFastElements;
1441 if (has_null_prototype()) flags |= kHasNullPrototype;
1446 kFastElements = 1 << 3,
1447 kHasNullPrototype = 1 << 4,
1450 static_cast<int>(AggregateLiteral::kNeedsInitialAllocationSite) <
1451 static_cast<int>(kFastElements));
1454 Accessors() : getter(
nullptr), setter(
nullptr) {}
1463 uint32_t boilerplate_properties,
int pos,
1464 bool has_rest_property)
1466 boilerplate_properties_(boilerplate_properties),
1467 properties_(0, nullptr) {
1468 bit_field_ |= HasElementsField::encode(
false) |
1469 HasRestPropertyField::encode(has_rest_property) |
1470 FastElementsField::encode(
false) |
1471 HasNullPrototypeField::encode(
false);
1472 properties.CopyTo(&properties_, zone);
1475 void InitFlagsForPendingNullPrototype(
int i);
1477 void set_has_elements(
bool has_elements) {
1478 bit_field_ = HasElementsField::update(bit_field_, has_elements);
1480 void set_fast_elements(
bool fast_elements) {
1481 bit_field_ = FastElementsField::update(bit_field_, fast_elements);
1483 void set_has_null_protoype(
bool has_null_prototype) {
1484 bit_field_ = HasNullPrototypeField::update(bit_field_, has_null_prototype);
1488 Handle<ObjectBoilerplateDescription> boilerplate_description_;
1489 ZoneList<Property*> properties_;
1491 class HasElementsField
1492 :
public BitField<bool, AggregateLiteral::kNextBitFieldIndex, 1> {};
1493 class HasRestPropertyField
1494 :
public BitField<bool, HasElementsField::kNext, 1> {};
1495 class FastElementsField
1496 :
public BitField<bool, HasRestPropertyField::kNext, 1> {};
1497 class HasNullPrototypeField
1498 :
public BitField<bool, FastElementsField::kNext, 1> {};
1505 bool (*)(void*, void*),
1506 ZoneAllocationPolicy> {
1514 Iterator lookup(
Literal* literal) {
1516 if (it->second ==
nullptr) {
1532 return boilerplate_description_;
1537 int first_spread_index()
const {
return first_spread_index_; }
1540 int InitDepthAndFlags();
1545 if (boilerplate_description_.is_null()) {
1546 BuildBoilerplateDescription(isolate);
1548 return boilerplate_description();
1552 void BuildBoilerplateDescription(
Isolate* isolate);
1555 bool IsFastCloningSupported()
const;
1558 int ComputeFlags(
bool disable_mementos =
false)
const {
1559 return AggregateLiteral::ComputeFlags(disable_mementos);
1566 int first_spread_index,
int pos)
1568 first_spread_index_(first_spread_index),
1569 values_(0,
nullptr) {
1570 values.CopyTo(&values_, zone);
1573 int first_spread_index_;
1578 enum class HoleCheckMode { kRequired, kElided };
1582 bool IsValidReferenceExpression()
const {
1583 return !is_this() && !is_new_target();
1588 return is_resolved() ? var_->raw_name() : raw_name_;
1592 DCHECK(is_resolved());
1596 DCHECK(!is_resolved());
1601 bool is_this()
const {
return IsThisField::decode(bit_field_); }
1603 bool is_assigned()
const {
return IsAssignedField::decode(bit_field_); }
1604 void set_is_assigned() {
1605 bit_field_ = IsAssignedField::update(bit_field_,
true);
1606 if (is_resolved()) {
1607 var()->set_maybe_assigned();
1611 bool is_resolved()
const {
return IsResolvedField::decode(bit_field_); }
1612 void set_is_resolved() {
1613 bit_field_ = IsResolvedField::update(bit_field_,
true);
1616 bool is_new_target()
const {
return IsNewTargetField::decode(bit_field_); }
1617 void set_is_new_target() {
1618 bit_field_ = IsNewTargetField::update(bit_field_,
true);
1621 HoleCheckMode hole_check_mode()
const {
1622 HoleCheckMode mode = HoleCheckModeField::decode(bit_field_);
1623 DCHECK_IMPLIES(mode == HoleCheckMode::kRequired,
1624 var()->binding_needs_init() ||
1625 var()->local_if_not_shadowed()->binding_needs_init());
1628 void set_needs_hole_check() {
1630 HoleCheckModeField::update(bit_field_, HoleCheckMode::kRequired);
1633 bool is_private_name()
const {
return IsPrivateName::decode(bit_field_); }
1634 void set_is_private_name() {
1635 bit_field_ = IsPrivateName::update(bit_field_,
true);
1641 V8_INLINE
VariableProxy* next_unresolved() {
return next_unresolved_; }
1642 V8_INLINE
bool is_removed_from_unresolved()
const {
1643 return IsRemovedFromUnresolvedField::decode(bit_field_);
1646 void mark_removed_from_unresolved() {
1647 bit_field_ = IsRemovedFromUnresolvedField::update(bit_field_,
true);
1654 return t->pre_parser_expr_next();
1666 while (*n !=
nullptr && (*n)->is_removed_from_unresolved()) {
1684 :
Expression(start_position, kVariableProxy),
1686 next_unresolved_(nullptr),
1687 pre_parser_expr_next_(nullptr) {
1688 bit_field_ |= IsThisField::encode(variable_kind == THIS_VARIABLE) |
1689 IsAssignedField::encode(
false) |
1690 IsResolvedField::encode(
false) |
1691 IsRemovedFromUnresolvedField::encode(
false) |
1692 HoleCheckModeField::encode(HoleCheckMode::kElided) |
1693 IsPrivateName::encode(
false);
1698 class IsThisField :
public BitField<bool, Expression::kNextBitFieldIndex, 1> {
1700 class IsAssignedField :
public BitField<bool, IsThisField::kNext, 1> {};
1701 class IsResolvedField :
public BitField<bool, IsAssignedField::kNext, 1> {};
1702 class IsRemovedFromUnresolvedField
1703 :
public BitField<bool, IsResolvedField::kNext, 1> {};
1704 class IsNewTargetField
1705 :
public BitField<bool, IsRemovedFromUnresolvedField::kNext, 1> {};
1706 class HoleCheckModeField
1707 :
public BitField<HoleCheckMode, IsNewTargetField::kNext, 1> {};
1708 class IsPrivateName :
public BitField<bool, HoleCheckModeField::kNext, 1> {};
1711 const AstRawString* raw_name_;
1715 V8_INLINE VariableProxy** next() {
return &next_unresolved_; }
1716 VariableProxy* next_unresolved_;
1718 VariableProxy** pre_parser_expr_next() {
return &pre_parser_expr_next_; }
1719 VariableProxy* pre_parser_expr_next_;
1721 friend base::ThreadedListTraits<VariableProxy>;
1730 NAMED_SUPER_PROPERTY,
1731 KEYED_SUPER_PROPERTY
1736 bool IsValidReferenceExpression()
const {
return true; }
1741 bool IsSuperAccess() {
return obj()->IsSuperPropertyReference(); }
1744 static LhsKind GetAssignType(
Property* property) {
1745 if (property ==
nullptr)
return VARIABLE;
1746 bool super_access =
property->IsSuperAccess();
1747 return (property->key()->IsPropertyName())
1748 ? (super_access ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY)
1749 : (super_access ? KEYED_SUPER_PROPERTY : KEYED_PROPERTY);
1756 :
Expression(pos, kProperty), obj_(obj), key_(key) {
1777 :
Expression(pos, kResolvedProperty), object_(obj), property_(property) {}
1785 Expression* expression()
const {
return expression_; }
1788 bool is_possibly_eval()
const {
1789 return IsPossiblyEvalField::decode(bit_field_);
1792 bool is_tagged_template()
const {
1793 return IsTaggedTemplateField::decode(bit_field_);
1796 bool only_last_arg_is_spread() {
1797 return !arguments_.is_empty() && arguments_.last()->IsSpread();
1803 NAMED_PROPERTY_CALL,
1804 KEYED_PROPERTY_CALL,
1805 NAMED_SUPER_PROPERTY_CALL,
1806 KEYED_SUPER_PROPERTY_CALL,
1808 RESOLVED_PROPERTY_CALL,
1818 CallType GetCallType()
const;
1820 enum class TaggedTemplateTag { kTrue };
1827 PossiblyEval possibly_eval)
1829 expression_(expression),
1830 arguments_(0,
nullptr) {
1832 IsPossiblyEvalField::encode(possibly_eval == IS_POSSIBLY_EVAL) |
1833 IsTaggedTemplateField::encode(
false);
1834 arguments.CopyTo(&arguments_, zone);
1839 TaggedTemplateTag tag)
1841 expression_(expression),
1842 arguments_(0,
nullptr) {
1843 bit_field_ |= IsPossiblyEvalField::encode(
false) |
1844 IsTaggedTemplateField::encode(
true);
1845 arguments.CopyTo(&arguments_, zone);
1848 class IsPossiblyEvalField
1849 :
public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
1850 class IsTaggedTemplateField
1851 :
public BitField<bool, IsPossiblyEvalField::kNext, 1> {};
1860 Expression* expression()
const {
return expression_; }
1863 bool only_last_arg_is_spread() {
1864 return !arguments_.is_empty() && arguments_.last()->IsSpread();
1873 expression_(expression),
1874 arguments_(0,
nullptr) {
1875 arguments.CopyTo(&arguments_, zone);
1889 bool is_jsruntime()
const {
return function_ ==
nullptr; }
1891 int context_index()
const {
1892 DCHECK(is_jsruntime());
1893 return context_index_;
1896 DCHECK(!is_jsruntime());
1900 const char* debug_name();
1908 function_(
function),
1909 arguments_(0,
nullptr) {
1910 arguments.CopyTo(&arguments_, zone);
1915 context_index_(context_index),
1917 arguments_(0,
nullptr) {
1918 arguments.CopyTo(&arguments_, zone);
1929 Token::Value op()
const {
return OperatorField::decode(bit_field_); }
1930 Expression* expression()
const {
return expression_; }
1936 :
Expression(pos, kUnaryOperation), expression_(expression) {
1937 bit_field_ |= OperatorField::encode(op);
1938 DCHECK(Token::IsUnaryOp(op));
1944 :
public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
1950 Token::Value op()
const {
return OperatorField::decode(bit_field_); }
1956 bool IsSmiLiteralOperation(
Expression** subexpr,
Smi* literal);
1962 :
Expression(pos, kBinaryOperation), left_(left), right_(right) {
1963 bit_field_ |= OperatorField::encode(op);
1964 DCHECK(Token::IsBinaryOp(op));
1971 :
public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
1976 Token::Value op()
const {
return OperatorField::decode(bit_field_); }
1979 return subsequent_[index].expression;
1982 size_t subsequent_length()
const {
return subsequent_.size(); }
1983 int subsequent_op_position(
size_t index)
const {
1984 return subsequent_[index].op_position;
1987 void AddSubsequent(
Expression* expr,
int pos) {
1988 subsequent_.emplace_back(expr, pos);
1995 size_t initial_subsequent_size)
1996 :
Expression(first->position(), kNaryOperation),
1999 bit_field_ |= OperatorField::encode(op);
2000 DCHECK(Token::IsBinaryOp(op));
2001 DCHECK_NE(op, Token::EXP);
2002 subsequent_.reserve(initial_subsequent_size);
2022 struct NaryOperationEntry {
2026 : expression(e), op_position(pos) {}
2031 :
public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
2036 bool is_prefix()
const {
return IsPrefixField::decode(bit_field_); }
2037 bool is_postfix()
const {
return !is_prefix(); }
2039 Token::Value op()
const {
return TokenField::decode(bit_field_); }
2041 Expression* expression()
const {
return expression_; }
2047 :
Expression(pos, kCountOperation), expression_(expr) {
2048 bit_field_ |= IsPrefixField::encode(is_prefix) | TokenField::encode(op);
2052 :
public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
2053 class TokenField :
public BitField<Token::Value, IsPrefixField::kNext, 7> {};
2061 Token::Value op()
const {
return OperatorField::decode(bit_field_); }
2067 bool IsLiteralCompareUndefined(
Expression** expr);
2068 bool IsLiteralCompareNull(
Expression** expr);
2075 :
Expression(pos, kCompareOperation), left_(left), right_(right) {
2076 bit_field_ |= OperatorField::encode(op);
2077 DCHECK(Token::IsCompareOp(op));
2084 :
public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
2090 Expression* expression()
const {
return expression_; }
2092 int expression_position()
const {
return expr_pos_; }
2099 expr_pos_(expr_pos),
2100 expression_(expression) {}
2120 :
Expression(position, kStoreInArrayLiteral),
2132 Expression* condition()
const {
return condition_; }
2133 Expression* then_expression()
const {
return then_expression_; }
2134 Expression* else_expression()
const {
return else_expression_; }
2142 condition_(condition),
2143 then_expression_(then_expression),
2144 else_expression_(else_expression) {}
2153 Token::Value op()
const {
return TokenField::decode(bit_field_); }
2154 Expression* target()
const {
return target_; }
2160 LookupHoistingMode lookup_hoisting_mode()
const {
2161 return static_cast<LookupHoistingMode
>(
2162 LookupHoistingModeField::decode(bit_field_));
2164 void set_lookup_hoisting_mode(LookupHoistingMode mode) {
2166 LookupHoistingModeField::update(bit_field_, static_cast<bool>(mode));
2177 :
public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
2178 class LookupHoistingModeField :
public BitField<bool, TokenField::kNext, 1> {
2187 BinaryOperation* binary_operation()
const {
return binary_operation_; }
2194 :
Assignment(kCompoundAssignment, op, target, value, pos),
2195 binary_operation_(binary_operation) {}
2217 Expression* expression()
const {
return expr_; }
2218 bool is_rewritten()
const {
return IsRewrittenField::decode(bit_field_); }
2219 void set_rewritten() {
2220 bit_field_ = IsRewrittenField::update(bit_field_,
true);
2224 DCHECK(!is_rewritten());
2225 DCHECK_NOT_NULL(new_expression);
2226 DCHECK(!new_expression->IsRewritableExpression());
2227 expr_ = new_expression;
2231 Scope* scope()
const {
return scope_; }
2232 void set_scope(
Scope* scope) { scope_ = scope; }
2238 :
Expression(expression->position(), kRewritableExpression),
2241 bit_field_ |= IsRewrittenField::encode(
false);
2242 DCHECK(!expression->IsRewritableExpression());
2248 class IsRewrittenField
2249 :
public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
2268 enum OnAbruptResume { kOnExceptionThrow, kNoControl };
2270 Expression* expression()
const {
return expression_; }
2271 OnAbruptResume on_abrupt_resume()
const {
2272 return OnAbruptResumeField::decode(bit_field_);
2282 OnAbruptResume on_abrupt_resume)
2283 :
Expression(pos, node_type), expression_(expression) {
2284 bit_field_ |= OnAbruptResumeField::encode(on_abrupt_resume);
2289 class OnAbruptResumeField
2290 :
public BitField<OnAbruptResume, Expression::kNextBitFieldIndex, 1> {};
2296 Yield(
Expression* expression,
int pos, OnAbruptResume on_abrupt_resume)
2297 :
Suspend(kYield, expression, pos, on_abrupt_resume) {}
2304 :
Suspend(kYieldStar, expression, pos,
2305 Suspend::OnAbruptResume::kNoControl) {}
2313 :
Suspend(kAwait, expression, pos, Suspend::kOnExceptionThrow) {}
2318 Expression* exception()
const {
return exception_; }
2324 :
Expression(pos, kThrow), exception_(exception) {}
2333 kAnonymousExpression,
2340 enum IdType { kIdTypeInvalid = -1, kIdTypeTopLevel = 0 };
2342 enum ParameterFlag : uint8_t {
2343 kNoDuplicateParameters,
2344 kHasDuplicateParameters
2346 enum EagerCompileHint : uint8_t { kShouldEagerCompile, kShouldLazyCompile };
2354 bool has_shared_name()
const {
return raw_name_ !=
nullptr; }
2356 void set_raw_name(
const AstConsString* name) { raw_name_ = name; }
2359 void set_function_token_position(
int pos) { function_token_position_ = pos; }
2360 int function_token_position()
const {
return function_token_position_; }
2361 int start_position()
const;
2362 int end_position()
const;
2363 bool is_declaration()
const {
return function_type() == kDeclaration; }
2364 bool is_named_expression()
const {
2365 return function_type() == kNamedExpression;
2367 bool is_anonymous_expression()
const {
2368 return function_type() == kAnonymousExpression;
2371 void mark_as_iife() { bit_field_ = IIFEBit::update(bit_field_,
true); }
2372 bool is_iife()
const {
return IIFEBit::decode(bit_field_); }
2373 bool is_toplevel()
const {
2374 return function_literal_id() == FunctionLiteral::kIdTypeTopLevel;
2376 bool is_wrapped()
const {
return function_type() == kWrapped; }
2377 LanguageMode language_mode()
const;
2379 static bool NeedsHomeObject(
Expression* expr);
2381 int expected_property_count() {
2383 DCHECK(ShouldEagerCompile());
2384 return expected_property_count_;
2386 int parameter_count() {
return parameter_count_; }
2387 int function_length() {
return function_length_; }
2389 bool AllowsLazyCompilation();
2392 if (suspend_count() > 0) {
2393 DCHECK(IsResumableFunction(kind()));
2400 std::unique_ptr<char[]> GetDebugName()
const;
2403 if (!inferred_name_.is_null()) {
2404 DCHECK_NULL(raw_inferred_name_);
2405 return inferred_name_;
2407 if (raw_inferred_name_ !=
nullptr) {
2408 return raw_inferred_name_->string();
2412 const AstConsString* raw_inferred_name() {
return raw_inferred_name_; }
2416 void set_raw_inferred_name(
const AstConsString* raw_inferred_name);
2418 bool pretenure()
const {
return Pretenure::decode(bit_field_); }
2419 void set_pretenure() { bit_field_ = Pretenure::update(bit_field_,
true); }
2421 bool has_duplicate_parameters()
const {
2423 DCHECK(ShouldEagerCompile());
2424 return HasDuplicateParameters::decode(bit_field_);
2432 bool ShouldEagerCompile()
const;
2433 V8_EXPORT_PRIVATE
void SetShouldEagerCompile();
2435 FunctionType function_type()
const {
2436 return FunctionTypeBits::decode(bit_field_);
2438 FunctionKind kind()
const;
2440 bool dont_optimize() {
2441 return dont_optimize_reason() != BailoutReason::kNoReason;
2443 BailoutReason dont_optimize_reason() {
2444 return DontOptimizeReasonField::decode(bit_field_);
2446 void set_dont_optimize_reason(BailoutReason reason) {
2447 bit_field_ = DontOptimizeReasonField::update(bit_field_, reason);
2450 bool IsAnonymousFunctionDefinition()
const {
2451 return is_anonymous_expression();
2454 int suspend_count() {
return suspend_count_; }
2455 void set_suspend_count(
int suspend_count) { suspend_count_ = suspend_count; }
2457 int return_position() {
2460 end_position() - (HasBracesField::decode(bit_field_) ? 1 : 0));
2463 int function_literal_id()
const {
return function_literal_id_; }
2464 void set_function_literal_id(
int function_literal_id) {
2465 function_literal_id_ = function_literal_id;
2468 void set_requires_instance_members_initializer(
bool value) {
2469 bit_field_ = RequiresInstanceMembersInitializer::update(bit_field_, value);
2471 bool requires_instance_members_initializer()
const {
2472 return RequiresInstanceMembersInitializer::decode(bit_field_);
2476 return produced_preparsed_scope_data_;
2485 int expected_property_count,
int parameter_count,
int function_length,
2486 FunctionType function_type, ParameterFlag has_duplicate_parameters,
2487 EagerCompileHint eager_compile_hint,
int position,
bool has_braces,
2488 int function_literal_id,
2491 expected_property_count_(expected_property_count),
2492 parameter_count_(parameter_count),
2493 function_length_(function_length),
2494 function_token_position_(kNoSourcePosition),
2496 function_literal_id_(function_literal_id),
2497 raw_name_(name ? ast_value_factory->NewConsString(name) :
nullptr),
2500 raw_inferred_name_(ast_value_factory->empty_cons_string()),
2501 produced_preparsed_scope_data_(produced_preparsed_scope_data) {
2502 bit_field_ |= FunctionTypeBits::encode(function_type) |
2503 Pretenure::encode(
false) |
2504 HasDuplicateParameters::encode(has_duplicate_parameters ==
2505 kHasDuplicateParameters) |
2506 DontOptimizeReasonField::encode(BailoutReason::kNoReason) |
2507 RequiresInstanceMembersInitializer::encode(
false) |
2508 HasBracesField::encode(has_braces) | IIFEBit::encode(
false);
2509 if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile();
2510 body.CopyTo(&body_, zone);
2513 class FunctionTypeBits
2514 :
public BitField<FunctionType, Expression::kNextBitFieldIndex, 3> {};
2515 class Pretenure :
public BitField<bool, FunctionTypeBits::kNext, 1> {};
2516 class HasDuplicateParameters :
public BitField<bool, Pretenure::kNext, 1> {};
2517 class DontOptimizeReasonField
2518 :
public BitField<BailoutReason, HasDuplicateParameters::kNext, 8> {};
2519 class RequiresInstanceMembersInitializer
2520 :
public BitField<bool, DontOptimizeReasonField::kNext, 1> {};
2521 class HasBracesField
2522 :
public BitField<bool, RequiresInstanceMembersInitializer::kNext, 1> {};
2523 class IIFEBit :
public BitField<bool, HasBracesField::kNext, 1> {};
2525 int expected_property_count_;
2526 int parameter_count_;
2527 int function_length_;
2528 int function_token_position_;
2530 int function_literal_id_;
2544 enum Kind : uint8_t { METHOD, GETTER, SETTER, FIELD };
2546 Kind kind()
const {
return kind_; }
2548 bool is_static()
const {
return is_static_; }
2550 bool is_private()
const {
return is_private_; }
2552 void set_computed_name_var(
Variable* var) {
2553 DCHECK_EQ(FIELD, kind());
2554 DCHECK(!is_private());
2555 private_or_computed_name_var_ = var;
2558 Variable* computed_name_var()
const {
2559 DCHECK_EQ(FIELD, kind());
2560 DCHECK(!is_private());
2561 return private_or_computed_name_var_;
2564 void set_private_name_var(
Variable* var) {
2565 DCHECK_EQ(FIELD, kind());
2566 DCHECK(is_private());
2567 private_or_computed_name_var_ = var;
2569 Variable* private_name_var()
const {
2570 DCHECK_EQ(FIELD, kind());
2571 DCHECK(is_private());
2572 return private_or_computed_name_var_;
2579 bool is_static,
bool is_computed_name,
bool is_private);
2584 Variable* private_or_computed_name_var_;
2597 :
Statement(pos, kInitializeClassMembersStatement), fields_(fields) {}
2606 Scope* scope()
const {
return scope_; }
2607 Variable* class_variable()
const {
return class_variable_; }
2608 Expression* extends()
const {
return extends_; }
2611 int start_position()
const {
return position(); }
2612 int end_position()
const {
return end_position_; }
2613 bool has_name_static_property()
const {
2614 return HasNameStaticProperty::decode(bit_field_);
2616 bool has_static_computed_names()
const {
2617 return HasStaticComputedNames::decode(bit_field_);
2620 bool is_anonymous_expression()
const {
2621 return IsAnonymousExpression::decode(bit_field_);
2623 bool IsAnonymousFunctionDefinition()
const {
2624 return is_anonymous_expression();
2628 return static_fields_initializer_;
2632 return instance_members_initializer_function_;
2642 int start_position,
int end_position,
2643 bool has_name_static_property,
bool has_static_computed_names,
2646 end_position_(end_position),
2648 class_variable_(class_variable),
2650 constructor_(constructor),
2651 properties_(properties),
2652 static_fields_initializer_(static_fields_initializer),
2653 instance_members_initializer_function_(
2654 instance_members_initializer_function) {
2655 bit_field_ |= HasNameStaticProperty::encode(has_name_static_property) |
2656 HasStaticComputedNames::encode(has_static_computed_names) |
2657 IsAnonymousExpression::encode(is_anonymous);
2668 class HasNameStaticProperty
2669 :
public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
2670 class HasStaticComputedNames
2671 :
public BitField<bool, HasNameStaticProperty::kNext, 1> {};
2672 class IsAnonymousExpression
2673 :
public BitField<bool, HasStaticComputedNames::kNext, 1> {};
2681 v8::Extension* extension()
const {
return extension_; }
2690 extension_(extension) {}
2693 v8::Extension* extension_;
2707 Expression* home_object()
const {
return home_object_; }
2715 this_var_(this_var),
2716 home_object_(home_object) {
2717 DCHECK(this_var->is_this());
2718 DCHECK(home_object->IsProperty());
2729 VariableProxy* new_target_var()
const {
return new_target_var_; }
2730 VariableProxy* this_function_var()
const {
return this_function_var_; }
2738 this_var_(this_var),
2739 new_target_var_(new_target_var),
2740 this_function_var_(this_function_var) {
2741 DCHECK(this_var->is_this());
2742 DCHECK(new_target_var->raw_name()->IsOneByteEqualTo(
".new.target"));
2743 DCHECK(this_function_var->raw_name()->IsOneByteEqualTo(
".this_function"));
2755 Expression* argument()
const {
return argument_; }
2761 :
Expression(pos, kImportCallExpression), argument_(argument) {}
2773 mark_parenthesized();
2781 enum class IteratorType {
kNormal, kAsync };
2784 IteratorType hint()
const {
return hint_; }
2786 Expression* iterable()
const {
return iterable_; }
2788 Expression* iterable_for_call_printer()
const {
2789 return destructured_iterable_ !=
nullptr ? destructured_iterable_
2797 IteratorType hint,
int pos)
2800 iterable_(iterable),
2801 destructured_iterable_(destructured_iterable) {}
2806 iterable_(iterable),
2807 destructured_iterable_(
nullptr) {}
2823 return cooked_strings_;
2826 return raw_strings_;
2837 cooked_strings_(cooked_strings),
2838 raw_strings_(raw_strings) {}
2847 return string_parts_;
2850 return substitutions_;
2858 string_parts_(parts),
2859 substitutions_(substitutions) {}
2870 template <
class Sub
class>
2873 void Visit(
AstNode* node) { impl()->Visit(node); }
2876 for (
Declaration* decl : *declarations) Visit(decl);
2880 for (
int i = 0;
i < statements->length();
i++) {
2883 if (stmt->IsJump())
break;
2888 for (
int i = 0;
i < expressions->length();
i++) {
2894 if (expression !=
nullptr) Visit(expression);
2899 Subclass* impl() {
return static_cast<Subclass*
>(
this); }
2902 #define GENERATE_VISIT_CASE(NodeType) \ 2903 case AstNode::k##NodeType: \ 2904 return this->impl()->Visit##NodeType(static_cast<NodeType*>(node)); 2906 #define GENERATE_FAILURE_CASE(NodeType) \ 2907 case AstNode::k##NodeType: \ 2910 #define GENERATE_AST_VISITOR_SWITCH() \ 2911 switch (node->node_type()) { \ 2912 AST_NODE_LIST(GENERATE_VISIT_CASE) \ 2913 FAILURE_NODE_LIST(GENERATE_FAILURE_CASE) \ 2916 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ 2918 void VisitNoStackOverflowCheck(AstNode* node) { \ 2919 GENERATE_AST_VISITOR_SWITCH() \ 2922 void Visit(AstNode* node) { \ 2923 if (CheckStackOverflow()) return; \ 2924 VisitNoStackOverflowCheck(node); \ 2927 void SetStackOverflow() { stack_overflow_ = true; } \ 2928 void ClearStackOverflow() { stack_overflow_ = false; } \ 2929 bool HasStackOverflow() const { return stack_overflow_; } \ 2931 bool CheckStackOverflow() { \ 2932 if (stack_overflow_) return true; \ 2933 if (GetCurrentStackPosition() < stack_limit_) { \ 2934 stack_overflow_ = true; \ 2941 void InitializeAstVisitor(Isolate* isolate) { \ 2942 stack_limit_ = isolate->stack_guard()->real_climit(); \ 2943 stack_overflow_ = false; \ 2946 void InitializeAstVisitor(uintptr_t stack_limit) { \ 2947 stack_limit_ = stack_limit; \ 2948 stack_overflow_ = false; \ 2951 uintptr_t stack_limit_; \ 2952 bool stack_overflow_ 2954 #define DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW() \ 2956 void Visit(AstNode* node) { GENERATE_AST_VISITOR_SWITCH() } \ 2967 ast_value_factory_(ast_value_factory),
2971 AstValueFactory* ast_value_factory()
const {
return ast_value_factory_; }
2985 bool is_sloppy_block_function,
2991 Block* NewBlock(
int capacity,
bool ignore_completion_value) {
2992 return new (zone_)
Block(zone_,
nullptr, capacity, ignore_completion_value);
2995 Block* NewBlock(
bool ignore_completion_value,
2997 return labels !=
nullptr 2998 ?
new (zone_)
LabeledBlock(labels, ignore_completion_value)
2999 :
new (zone_)
Block(labels, ignore_completion_value);
3002 Block* NewBlock(
bool ignore_completion_value,
3004 Block* result = NewBlock(ignore_completion_value,
nullptr);
3005 result->InitializeStatements(statements, zone_);
3009 #define STATEMENT_WITH_LABELS(NodeType) \ 3010 NodeType* New##NodeType(ZonePtrList<const AstRawString>* labels, \ 3011 ZonePtrList<const AstRawString>* own_labels, \ 3013 return new (zone_) NodeType(labels, own_labels, pos); \ 3018 #undef STATEMENT_WITH_LABELS 3026 ForEachStatement::VisitMode visit_mode,
3029 switch (visit_mode) {
3030 case ForEachStatement::ENUMERATE: {
3033 case ForEachStatement::ITERATE: {
3059 int end_position = kNoSourcePosition) {
3060 return new (zone_)
ReturnStatement(expression, ReturnStatement::kNormal,
3065 Expression* expression,
int pos,
int end_position = kNoSourcePosition) {
3067 expression, ReturnStatement::kAsyncReturn, pos, end_position);
3074 return new (zone_)
WithStatement(scope, expression, statement, pos);
3080 IfStatement(condition, then_statement, else_statement, pos);
3084 Block* catch_block,
int pos) {
3086 HandlerTable::CAUGHT, pos);
3094 HandlerTable::UNCAUGHT, pos);
3102 HandlerTable::DESUGARING, pos);
3110 HandlerTable::ASYNC_AWAIT, pos);
3114 Block* finally_block,
int pos) {
3123 return empty_statement_;
3127 return failure_expression_;
3136 return new (zone_)
CaseClause(zone_, label, statements);
3140 DCHECK_NOT_NULL(
string);
3141 return new (zone_)
Literal(
string, pos);
3145 Literal* NewSymbolLiteral(AstSymbol symbol,
int pos) {
3146 return new (zone_)
Literal(symbol, pos);
3149 Literal* NewNumberLiteral(
double number,
int pos);
3151 Literal* NewSmiLiteral(
int number,
int pos) {
3152 return new (zone_)
Literal(number, pos);
3156 return new (zone_)
Literal(bigint, pos);
3159 Literal* NewBooleanLiteral(
bool b,
int pos) {
3160 return new (zone_)
Literal(b, pos);
3163 Literal* NewNullLiteral(
int pos) {
3164 return new (zone_)
Literal(Literal::kNull, pos);
3167 Literal* NewUndefinedLiteral(
int pos) {
3168 return new (zone_)
Literal(Literal::kUndefined, pos);
3171 Literal* NewTheHoleLiteral() {
3172 return new (zone_)
Literal(Literal::kTheHole, kNoSourcePosition);
3177 uint32_t boilerplate_properties,
int pos,
bool has_rest_property) {
3178 return new (zone_)
ObjectLiteral(zone_, properties, boilerplate_properties,
3179 pos, has_rest_property);
3184 bool is_computed_name) {
3191 bool is_computed_name) {
3203 return new (zone_)
ArrayLiteral(zone_, values, -1, pos);
3207 int first_spread_index,
int pos) {
3208 return new (zone_)
ArrayLiteral(zone_, values, first_spread_index, pos);
3212 int start_position = kNoSourcePosition) {
3217 VariableKind variable_kind,
3218 int start_position = kNoSourcePosition) {
3219 DCHECK_NOT_NULL(name);
3220 return new (zone_)
VariableProxy(name, variable_kind, start_position);
3229 return new (zone_)
Variable(variable);
3233 return new (zone_)
Property(obj, key, pos);
3238 int pos = kNoSourcePosition) {
3244 Call::PossiblyEval possibly_eval = Call::NOT_EVAL) {
3245 return new (zone_)
Call(zone_, expression, arguments, pos, possibly_eval);
3251 Call(zone_, expression, arguments, pos, Call::TaggedTemplateTag::kTrue);
3256 return new (zone_)
CallNew(zone_, expression, arguments, pos);
3259 CallRuntime* NewCallRuntime(Runtime::FunctionId
id,
3263 CallRuntime(zone_, Runtime::FunctionForId(
id), arguments, pos);
3269 return new (zone_)
CallRuntime(zone_,
function, arguments, pos);
3275 return new (zone_)
CallRuntime(zone_, context_index, arguments, pos);
3292 size_t initial_subsequent_size) {
3293 return new (zone_)
NaryOperation(zone_, op, first, initial_subsequent_size);
3311 return new (zone_)
Spread(expression, pos, expr_pos);
3325 Conditional(condition, then_expression, else_expression, position);
3330 DCHECK_NOT_NULL(expression);
3338 DCHECK(Token::IsAssignmentOp(op));
3340 if (op != Token::INIT && target->IsVariableProxy()) {
3341 target->AsVariableProxy()->set_is_assigned();
3344 if (op == Token::ASSIGN || op == Token::INIT) {
3346 Assignment(AstNode::kAssignment, op, target, value, pos);
3349 op, target, value, pos,
3350 NewBinaryOperation(Token::BinaryOpForAssignment(op), target, value,
3356 Suspend::OnAbruptResume on_abrupt_resume) {
3357 if (!expression) expression = NewUndefinedLiteral(pos);
3358 return new (zone_)
Yield(expression, pos, on_abrupt_resume);
3362 return new (zone_)
YieldStar(expression, pos);
3366 if (!expression) expression = NewUndefinedLiteral(pos);
3367 return new (zone_)
Await(expression, pos);
3371 return new (zone_)
Throw(exception, pos);
3377 int parameter_count,
int function_length,
3378 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3379 FunctionLiteral::FunctionType function_type,
3380 FunctionLiteral::EagerCompileHint eager_compile_hint,
int position,
3381 bool has_braces,
int function_literal_id,
3384 zone_, name, ast_value_factory_, scope, body, expected_property_count,
3385 parameter_count, function_length, function_type,
3386 has_duplicate_parameters, eager_compile_hint, position, has_braces,
3387 function_literal_id, produced_preparsed_scope_data);
3395 int expected_property_count,
int parameter_count) {
3397 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope,
3398 body, expected_property_count, parameter_count, parameter_count,
3399 FunctionLiteral::kAnonymousExpression,
3400 FunctionLiteral::kNoDuplicateParameters,
3401 FunctionLiteral::kShouldLazyCompile, 0,
false,
3402 FunctionLiteral::kIdTypeTopLevel);
3407 bool is_static,
bool is_computed_name,
bool is_private) {
3409 is_computed_name, is_private);
3418 int start_position,
int end_position,
bool has_name_static_property,
3419 bool has_static_computed_names,
bool is_anonymous) {
3421 scope, variable, extends, constructor, properties,
3422 static_fields_initializer, instance_members_initializer_function,
3423 start_position, end_position, has_name_static_property,
3424 has_static_computed_names, is_anonymous);
3428 v8::Extension* extension,
3462 IteratorType hint,
int pos) {
3463 return new (zone_)
GetIterator(iterable, destructured_iterable, hint, pos);
3468 return new (zone_)
GetIterator(iterable, hint, pos);
3492 Zone* zone()
const {
return zone_; }
3509 #define DECLARE_NODE_FUNCTIONS(type) \ 3510 bool AstNode::Is##type() const { \ 3511 NodeType mine = node_type(); \ 3512 if (mine == AstNode::kRewritableExpression && \ 3513 AstNode::k##type == AstNode::kAssignment) \ 3514 mine = reinterpret_cast<const RewritableExpression*>(this) \ 3517 return mine == AstNode::k##type; \ 3519 type* AstNode::As##type() { \ 3520 NodeType mine = node_type(); \ 3521 AstNode* result = this; \ 3522 if (mine == AstNode::kRewritableExpression && \ 3523 AstNode::k##type == AstNode::kAssignment) { \ 3525 reinterpret_cast<const RewritableExpression*>(this)->expression(); \ 3526 mine = result->node_type(); \ 3528 return mine == AstNode::k##type ? reinterpret_cast<type*>(result) \ 3531 const type* AstNode::As##type() const { \ 3532 NodeType mine = node_type(); \ 3533 const AstNode* result = this; \ 3534 if (mine == AstNode::kRewritableExpression && \ 3535 AstNode::k##type != AstNode::kRewritableExpression) { \ 3537 reinterpret_cast<const RewritableExpression*>(this)->expression(); \ 3538 mine = result->node_type(); \ 3540 return mine == AstNode::k##type ? reinterpret_cast<const type*>(result) \ 3543 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3544 FAILURE_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3545 #undef DECLARE_NODE_FUNCTIONS 3550 #endif // V8_AST_AST_H_