38 InitializeAstVisitor(isolate);
69 Print(
"(intermediate value)");
93void CallPrinter::VisitBlock(
Block* node) {
98void CallPrinter::VisitVariableDeclaration(VariableDeclaration* node) {}
101void CallPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) {}
104void CallPrinter::VisitExpressionStatement(ExpressionStatement* node) {
105 Find(node->expression());
109void CallPrinter::VisitEmptyStatement(EmptyStatement* node) {}
112void CallPrinter::VisitSloppyBlockFunctionStatement(
113 SloppyBlockFunctionStatement* node) {
114 Find(node->statement());
118void CallPrinter::VisitIfStatement(IfStatement* node) {
119 Find(node->condition());
120 Find(node->then_statement());
121 if (node->HasElseStatement()) {
122 Find(node->else_statement());
127void CallPrinter::VisitContinueStatement(ContinueStatement* node) {}
130void CallPrinter::VisitBreakStatement(BreakStatement* node) {}
133void CallPrinter::VisitReturnStatement(ReturnStatement* node) {
134 Find(node->expression());
138void CallPrinter::VisitWithStatement(WithStatement* node) {
139 Find(node->expression());
140 Find(node->statement());
144void CallPrinter::VisitSwitchStatement(SwitchStatement* node) {
146 for (CaseClause* clause : *node->cases()) {
147 if (!clause->is_default())
Find(clause->label());
153void CallPrinter::VisitDoWhileStatement(DoWhileStatement* node) {
159void CallPrinter::VisitWhileStatement(WhileStatement* node) {
165void CallPrinter::VisitForStatement(ForStatement* node) {
166 if (node->init() !=
nullptr) {
169 if (node->cond() !=
nullptr)
Find(node->cond());
170 if (node->next() !=
nullptr)
Find(node->next());
175void CallPrinter::VisitForInStatement(ForInStatement* node) {
177 Find(node->subject());
182void CallPrinter::VisitForOfStatement(ForOfStatement* node) {
186 bool was_found =
false;
187 if (node->subject()->position() ==
position_) {
195 Find(node->subject(),
true);
205void CallPrinter::VisitTryCatchStatement(TryCatchStatement* node) {
206 Find(node->try_block());
207 Find(node->catch_block());
211void CallPrinter::VisitTryFinallyStatement(TryFinallyStatement* node) {
212 Find(node->try_block());
213 Find(node->finally_block());
217void CallPrinter::VisitDebuggerStatement(DebuggerStatement* node) {}
220void CallPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
228void CallPrinter::VisitClassLiteral(ClassLiteral* node) {
229 if (node->extends())
Find(node->extends());
230 for (
int i = 0;
i < node->public_members()->
length();
i++) {
231 Find(node->public_members()->at(
i)->value());
233 for (
int i = 0;
i < node->private_members()->
length();
i++) {
234 Find(node->private_members()->at(
i)->value());
238void CallPrinter::VisitInitializeClassMembersStatement(
239 InitializeClassMembersStatement* node) {
240 for (
int i = 0;
i < node->fields()->
length();
i++) {
241 Find(node->fields()->at(
i)->value());
245void CallPrinter::VisitInitializeClassStaticElementsStatement(
246 InitializeClassStaticElementsStatement* node) {
247 for (
int i = 0;
i < node->elements()->
length();
i++) {
250 Find(element->property()->value());
252 Find(element->static_block());
257void CallPrinter::VisitAutoAccessorGetterBody(AutoAccessorGetterBody* node) {}
259void CallPrinter::VisitAutoAccessorSetterBody(AutoAccessorSetterBody* node) {}
261void CallPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {}
263void CallPrinter::VisitConditionalChain(ConditionalChain* node) {
264 for (
size_t i = 0;
i < node->conditional_chain_length(); ++
i) {
265 Find(node->condition_at(
i));
266 Find(node->then_expression_at(
i));
268 Find(node->else_expression());
271void CallPrinter::VisitConditional(Conditional* node) {
272 Find(node->condition());
273 Find(node->then_expression());
274 Find(node->else_expression());
278void CallPrinter::VisitLiteral(Literal* node) {
285void CallPrinter::VisitRegExpLiteral(RegExpLiteral* node) {
289#define V(Lower, Camel, LowerCamel, Char, Bit) \
290 if (node->flags() & RegExp::k##Camel) Print(Char);
296void CallPrinter::VisitObjectLiteral(ObjectLiteral* node) {
299 Find(node->properties()->at(
i)->value());
305void CallPrinter::VisitArrayLiteral(ArrayLiteral* node) {
309 Expression* subexpr = node->values()->at(
i);
310 Spread* spread = subexpr->AsSpread();
311 if (spread !=
nullptr && !
found_ &&
312 position_ == spread->expression()->position()) {
315 Find(spread->expression(),
true);
325void CallPrinter::VisitVariableProxy(VariableProxy* node) {
335void CallPrinter::VisitAssignment(Assignment* node) {
336 bool was_found =
false;
337 if (node->target()->IsObjectLiteral()) {
338 ObjectLiteral* target = node->target()->AsObjectLiteral();
344 for (ObjectLiteralProperty* prop : *target->properties()) {
345 if (prop->value()->position() ==
position_) {
357 Find(node->target(),
true);
360 Find(node->target());
361 if (node->target()->IsArrayLiteral()) {
363 if (node->value()->position() ==
position_) {
368 Find(node->value(),
true);
373 Find(node->value(),
true);
382void CallPrinter::VisitCompoundAssignment(CompoundAssignment* node) {
383 VisitAssignment(node);
386void CallPrinter::VisitYield(Yield* node) {
Find(node->expression()); }
388void CallPrinter::VisitYieldStar(YieldStar* node) {
397 Find(node->expression());
400void CallPrinter::VisitAwait(Await* node) {
Find(node->expression()); }
402void CallPrinter::VisitThrow(Throw* node) {
Find(node->exception()); }
404void CallPrinter::VisitOptionalChain(OptionalChain* node) {
405 Find(node->expression());
408void CallPrinter::VisitProperty(Property* node) {
409 Expression*
key = node->key();
413 Find(node->obj(),
true);
414 if (node->is_optional_chain_link()) {
422 Find(node->obj(),
true);
423 if (node->is_optional_chain_link()) {
432void CallPrinter::VisitCall(Call* node) {
433 bool was_found =
false;
436 !node->arguments()->is_empty()) {
437 if (
const Spread* spread = node->arguments()->last()->AsSpread()) {
455 if (!
is_user_js_ && node->expression()->IsVariableProxy()) {
461 Find(node->expression(),
true);
471void CallPrinter::VisitCallNew(CallNew* node) {
472 bool was_found =
false;
475 !node->arguments()->is_empty()) {
476 if (
const Spread* spread = node->arguments()->last()->AsSpread()) {
493 if (!
is_user_js_ && node->expression()->IsVariableProxy()) {
508void CallPrinter::VisitCallRuntime(CallRuntime* node) {
512void CallPrinter::VisitSuperCallForwardArgs(SuperCallForwardArgs* node) {
513 Find(node->expression(),
true);
514 Print(
"(...forwarded args...)");
517void CallPrinter::VisitUnaryOperation(UnaryOperation* node) {
520 op == Token::kDelete || op == Token::kTypeOf || op == Token::kVoid;
523 if (needsSpace)
Print(
" ");
524 Find(node->expression(),
true);
529void CallPrinter::VisitCountOperation(CountOperation* node) {
532 Find(node->expression(),
true);
538void CallPrinter::VisitBinaryOperation(BinaryOperation* node) {
540 Find(node->left(),
true);
544 Find(node->right(),
true);
548void CallPrinter::VisitNaryOperation(NaryOperation* node) {
550 Find(node->first(),
true);
551 for (
size_t i = 0;
i < node->subsequent_length(); ++
i) {
555 Find(node->subsequent(
i),
true);
560void CallPrinter::VisitCompareOperation(CompareOperation* node) {
562 Find(node->left(),
true);
566 Find(node->right(),
true);
571void CallPrinter::VisitSpread(Spread* node) {
573 Find(node->expression(),
true);
577void CallPrinter::VisitEmptyParentheses(EmptyParentheses* node) {
581void CallPrinter::VisitGetTemplateObject(GetTemplateObject* node) {}
583void CallPrinter::VisitTemplateLiteral(TemplateLiteral* node) {
584 for (Expression* substitution : *node->substitutions()) {
585 Find(substitution,
true);
589void CallPrinter::VisitImportCallExpression(ImportCallExpression* node) {
595 Find(node->specifier(),
true);
596 if (node->import_options()) {
598 Find(node->import_options(),
true);
603void CallPrinter::VisitThisExpression(ThisExpression* node) {
Print(
"this"); }
605void CallPrinter::VisitSuperPropertyReference(SuperPropertyReference* node) {}
608void CallPrinter::VisitSuperCallReference(SuperCallReference* node) {
614 if (statements ==
nullptr)
return;
615 for (
int i = 0;
i < statements->
length();
i++) {
622 for (
int i = 0;
i < arguments->
length();
i++) {
623 Find(arguments->at(
i));
628 if (IsString(*value)) {
629 if (quote)
Print(
"\"");
631 if (quote)
Print(
"\"");
634 }
else if (IsTrue(*value,
isolate_)) {
636 }
else if (IsFalse(*value,
isolate_)) {
638 }
else if (IsUndefined(*value,
isolate_)) {
642 }
else if (IsSymbol(*value)) {
658const char* AstPrinter::Print(
AstNode* node) {
664void AstPrinter::Init() {
667 const int initial_size = 256;
669 size_ = initial_size;
675void AstPrinter::Print(
const char* format, ...) {
678 va_start(arguments, format);
689 const int slack = 32;
700void AstPrinter::PrintLiteral(Literal*
literal,
bool quote) {
703 PrintLiteral(
literal->AsRawString(), quote);
706 PrintLiteral(
literal->AsConsString(), quote);
736void AstPrinter::PrintLiteral(
const AstRawString* value,
bool quote) {
737 if (quote)
Print(
"\"");
738 if (value !=
nullptr) {
739 const char* format = value->is_one_byte() ?
"%c" :
"%lc";
740 const int increment = value->is_one_byte() ? 1 : 2;
741 const unsigned char* raw_bytes = value->raw_data();
743 Print(format, raw_bytes[
i]);
746 if (quote)
Print(
"\"");
749void AstPrinter::PrintLiteral(
const AstConsString* value,
bool quote) {
750 if (quote)
Print(
"\"");
751 if (value !=
nullptr) {
752 std::forward_list<const AstRawString*> strings = value->ToRawStrings();
753 for (
const AstRawString*
string : strings) {
754 PrintLiteral(
string,
false);
757 if (quote)
Print(
"\"");
764 IndentedScope(AstPrinter* printer,
const char* txt)
765 : ast_printer_(printer) {
766 ast_printer_->PrintIndented(txt);
767 ast_printer_->Print(
"\n");
768 ast_printer_->inc_indent();
771 IndentedScope(AstPrinter* printer,
const char* txt,
int pos)
772 : ast_printer_(printer) {
773 ast_printer_->PrintIndented(txt);
774 ast_printer_->Print(
" at %d\n",
pos);
775 ast_printer_->inc_indent();
778 virtual ~IndentedScope() {
779 ast_printer_->dec_indent();
783 AstPrinter* ast_printer_;
788AstPrinter::AstPrinter(uintptr_t stack_limit)
790 InitializeAstVisitor(stack_limit);
793AstPrinter::~AstPrinter() {
799void AstPrinter::PrintIndented(
const char* txt) {
800 for (
int i = 0;
i < indent_;
i++) {
806void AstPrinter::PrintLiteralIndented(
const char* info, Literal*
literal,
814void AstPrinter::PrintLiteralIndented(
const char* info,
815 const AstRawString* value,
bool quote) {
818 PrintLiteral(value, quote);
822void AstPrinter::PrintLiteralIndented(
const char* info,
823 const AstConsString* value,
bool quote) {
826 PrintLiteral(value, quote);
830void AstPrinter::PrintLiteralWithModeIndented(
const char* info,
Variable* var,
831 const AstRawString* value) {
832 if (var ==
nullptr) {
833 PrintLiteralIndented(info, value,
true);
835 base::EmbeddedVector<char, 256> buf;
837 SNPrintF(buf,
"%s (%p) (mode = %s, assigned = %s", info,
838 reinterpret_cast<void*
>(var), VariableMode2String(var->mode()),
841 PrintLiteralIndented(buf.begin(), value,
true);
845void AstPrinter::PrintIndentedVisit(
const char* s, AstNode* node) {
846 if (node !=
nullptr) {
847 IndentedScope indent(
this, s, node->position());
853const char* AstPrinter::PrintProgram(FunctionLiteral* program) {
855 { IndentedScope indent(
this,
"FUNC", program->position());
856 PrintIndented(
"KIND");
857 Print(
" %d\n",
static_cast<uint32_t
>(program->kind()));
858 PrintIndented(
"LITERAL ID");
859 Print(
" %d\n", program->function_literal_id());
860 PrintIndented(
"SUSPEND COUNT");
861 Print(
" %d\n", program->suspend_count());
862 PrintLiteralIndented(
"NAME", program->raw_name(),
true);
863 if (program->raw_inferred_name()) {
864 PrintLiteralIndented(
"INFERRED NAME", program->raw_inferred_name(),
true);
866 if (program->requires_instance_members_initializer()) {
867 Print(
" REQUIRES INSTANCE FIELDS INITIALIZER\n");
869 if (program->class_scope_has_private_brand()) {
870 Print(
" CLASS SCOPE HAS PRIVATE BRAND\n");
872 if (program->has_static_private_methods_or_accessors()) {
873 Print(
" HAS STATIC PRIVATE METHODS\n");
875 PrintParameters(program->scope());
876 PrintDeclarations(program->scope()->declarations());
877 PrintStatements(program->body());
883void AstPrinter::PrintOut(Isolate* isolate, AstNode* node) {
884 AstPrinter printer(isolate ? isolate->stack_guard()->real_climit() : 0);
887 PrintF(
"%s", printer.output_);
891 if (!declarations->is_empty()) {
892 IndentedScope indent(
this,
"DECLS");
893 for (Declaration* decl : *declarations) Visit(decl);
897void AstPrinter::PrintParameters(DeclarationScope* scope) {
898 if (scope->num_parameters() > 0) {
899 IndentedScope indent(
this,
"PARAMS");
900 for (
int i = 0;
i < scope->num_parameters();
i++) {
901 PrintLiteralWithModeIndented(
"VAR", scope->parameter(
i),
902 scope->parameter(
i)->raw_name());
908 for (
int i = 0;
i < statements->
length();
i++) {
909 Visit(statements->at(
i));
914 for (
int i = 0;
i < arguments->
length();
i++) {
915 Visit(arguments->at(
i));
920void AstPrinter::VisitBlock(Block* node) {
921 const char* block_txt =
922 node->ignore_completion_value() ?
"BLOCK NOCOMPLETIONS" :
"BLOCK";
923 IndentedScope indent(
this, block_txt, node->position());
924 PrintStatements(node->statements());
929void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) {
930 PrintLiteralWithModeIndented(
"VARIABLE", node->var(),
931 node->var()->raw_name());
936void AstPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) {
937 PrintIndented(
"FUNCTION ");
938 PrintLiteral(node->var()->raw_name(),
true);
939 Print(
" = function ");
940 PrintLiteral(node->fun()->raw_name(),
false);
945void AstPrinter::VisitExpressionStatement(ExpressionStatement* node) {
946 IndentedScope indent(
this,
"EXPRESSION STATEMENT", node->position());
947 Visit(node->expression());
951void AstPrinter::VisitEmptyStatement(EmptyStatement* node) {
952 IndentedScope indent(
this,
"EMPTY", node->position());
956void AstPrinter::VisitSloppyBlockFunctionStatement(
957 SloppyBlockFunctionStatement* node) {
958 Visit(node->statement());
962void AstPrinter::VisitIfStatement(IfStatement* node) {
963 IndentedScope indent(
this,
"IF", node->position());
964 PrintIndentedVisit(
"CONDITION", node->condition());
965 PrintIndentedVisit(
"THEN", node->then_statement());
966 if (node->HasElseStatement()) {
967 PrintIndentedVisit(
"ELSE", node->else_statement());
972void AstPrinter::VisitContinueStatement(ContinueStatement* node) {
973 IndentedScope indent(
this,
"CONTINUE", node->position());
977void AstPrinter::VisitBreakStatement(BreakStatement* node) {
978 IndentedScope indent(
this,
"BREAK", node->position());
982void AstPrinter::VisitReturnStatement(ReturnStatement* node) {
983 IndentedScope indent(
this,
"RETURN", node->position());
984 Visit(node->expression());
988void AstPrinter::VisitWithStatement(WithStatement* node) {
989 IndentedScope indent(
this,
"WITH", node->position());
990 PrintIndentedVisit(
"OBJECT", node->expression());
991 PrintIndentedVisit(
"BODY", node->statement());
995void AstPrinter::VisitSwitchStatement(SwitchStatement* node) {
996 IndentedScope switch_indent(
this,
"SWITCH", node->position());
997 PrintIndentedVisit(
"TAG", node->tag());
998 for (CaseClause* clause : *node->cases()) {
999 if (clause->is_default()) {
1000 IndentedScope indent(
this,
"DEFAULT");
1001 PrintStatements(clause->statements());
1003 IndentedScope indent(
this,
"CASE");
1004 Visit(clause->label());
1005 PrintStatements(clause->statements());
1011void AstPrinter::VisitDoWhileStatement(DoWhileStatement* node) {
1012 IndentedScope indent(
this,
"DO", node->position());
1013 PrintIndentedVisit(
"BODY", node->body());
1014 PrintIndentedVisit(
"COND", node->cond());
1018void AstPrinter::VisitWhileStatement(WhileStatement* node) {
1019 IndentedScope indent(
this,
"WHILE", node->position());
1020 PrintIndentedVisit(
"COND", node->cond());
1021 PrintIndentedVisit(
"BODY", node->body());
1025void AstPrinter::VisitForStatement(ForStatement* node) {
1026 IndentedScope indent(
this,
"FOR", node->position());
1027 if (node->init()) PrintIndentedVisit(
"INIT", node->init());
1028 if (node->cond()) PrintIndentedVisit(
"COND", node->cond());
1029 PrintIndentedVisit(
"BODY", node->body());
1030 if (node->next()) PrintIndentedVisit(
"NEXT", node->next());
1034void AstPrinter::VisitForInStatement(ForInStatement* node) {
1035 IndentedScope indent(
this,
"FOR IN", node->position());
1036 PrintIndentedVisit(
"FOR", node->each());
1037 PrintIndentedVisit(
"IN", node->subject());
1038 PrintIndentedVisit(
"BODY", node->body());
1042void AstPrinter::VisitForOfStatement(ForOfStatement* node) {
1043 IndentedScope indent(
this,
"FOR OF", node->position());
1044 const char* for_type;
1045 switch (node->type()) {
1050 for_type =
"FOR AWAIT";
1053 PrintIndentedVisit(for_type, node->each());
1054 PrintIndentedVisit(
"OF", node->subject());
1055 PrintIndentedVisit(
"BODY", node->body());
1059void AstPrinter::VisitTryCatchStatement(TryCatchStatement* node) {
1060 IndentedScope indent(
this,
"TRY CATCH", node->position());
1061 PrintIndentedVisit(
"TRY", node->try_block());
1062 PrintIndented(
"CATCH PREDICTION");
1063 const char* prediction =
"";
1066 prediction =
"UNCAUGHT";
1069 prediction =
"CAUGHT";
1072 prediction =
"ASYNC_AWAIT";
1075 prediction =
"UNCAUGHT_ASYNC_AWAIT";
1082 Print(
" %s\n", prediction);
1083 if (node->scope()) {
1084 PrintLiteralWithModeIndented(
"CATCHVAR", node->scope()->catch_variable(),
1085 node->scope()->catch_variable()->raw_name());
1087 PrintIndentedVisit(
"CATCH", node->catch_block());
1090void AstPrinter::VisitTryFinallyStatement(TryFinallyStatement* node) {
1091 IndentedScope indent(
this,
"TRY FINALLY", node->position());
1092 PrintIndentedVisit(
"TRY", node->try_block());
1093 PrintIndentedVisit(
"FINALLY", node->finally_block());
1096void AstPrinter::VisitDebuggerStatement(DebuggerStatement* node) {
1097 IndentedScope indent(
this,
"DEBUGGER", node->position());
1101void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
1102 IndentedScope indent(
this,
"FUNC LITERAL", node->position());
1103 PrintIndented(
"LITERAL ID");
1104 Print(
" %d\n", node->function_literal_id());
1105 PrintLiteralIndented(
"NAME", node->raw_name(),
false);
1106 PrintLiteralIndented(
"INFERRED NAME", node->raw_inferred_name(),
false);
1115void AstPrinter::VisitClassLiteral(ClassLiteral* node) {
1116 IndentedScope indent(
this,
"CLASS LITERAL", node->position());
1117 PrintLiteralIndented(
"NAME", node->constructor()->raw_name(),
false);
1118 if (node->extends() !=
nullptr) {
1119 PrintIndentedVisit(
"EXTENDS", node->extends());
1121 Scope* outer = node->constructor()->scope()->outer_scope();
1122 if (outer->is_class_scope()) {
1123 Variable* brand = outer->AsClassScope()->brand();
1124 if (brand !=
nullptr) {
1125 PrintLiteralWithModeIndented(
"BRAND", brand, brand->raw_name());
1128 if (node->static_initializer() !=
nullptr) {
1129 PrintIndentedVisit(
"STATIC INITIALIZER", node->static_initializer());
1131 if (node->instance_members_initializer_function() !=
nullptr) {
1132 PrintIndentedVisit(
"INSTANCE MEMBERS INITIALIZER",
1133 node->instance_members_initializer_function());
1135 PrintClassProperties(node->private_members());
1136 PrintClassProperties(node->public_members());
1139void AstPrinter::VisitInitializeClassMembersStatement(
1140 InitializeClassMembersStatement* node) {
1141 IndentedScope indent(
this,
"INITIALIZE CLASS MEMBERS", node->position());
1142 PrintClassProperties(node->fields());
1145void AstPrinter::VisitInitializeClassStaticElementsStatement(
1146 InitializeClassStaticElementsStatement* node) {
1147 IndentedScope indent(
this,
"INITIALIZE CLASS STATIC ELEMENTS",
1149 PrintClassStaticElements(node->elements());
1152void AstPrinter::VisitAutoAccessorGetterBody(AutoAccessorGetterBody* node) {
1153 IndentedScope indent(
this,
"AUTO ACCESSOR GETTER BODY", node->position());
1154 PrintIndentedVisit(
"AUTO ACCESSOR STORAGE PRIVATE NAME", node->name_proxy());
1157void AstPrinter::VisitAutoAccessorSetterBody(AutoAccessorSetterBody* node) {
1158 IndentedScope indent(
this,
"AUTO ACCESSOR SETTER BODY", node->position());
1159 PrintIndentedVisit(
"AUTO ACCESSOR STORAGE PRIVATE NAME", node->name_proxy());
1163 const char* prop_kind =
nullptr;
1164 switch (property->kind()) {
1166 prop_kind =
"METHOD";
1169 prop_kind =
"GETTER";
1172 prop_kind =
"SETTER";
1175 prop_kind =
"FIELD";
1178 prop_kind =
"AUTO ACCESSOR";
1181 base::EmbeddedVector<char, 128> buf;
1182 SNPrintF(buf,
"PROPERTY%s%s - %s", property->is_static() ?
" - STATIC" :
"",
1183 property->is_private() ?
" - PRIVATE" :
" - PUBLIC", prop_kind);
1184 IndentedScope prop(
this, buf.begin());
1185 PrintIndentedVisit(
"KEY", property->key());
1186 PrintIndentedVisit(
"VALUE", property->value());
1189void AstPrinter::PrintClassProperties(
1191 for (
int i = 0;
i < properties->
length();
i++) {
1192 PrintClassProperty(properties->at(
i));
1196void AstPrinter::PrintClassStaticElements(
1198 for (
int i = 0;
i < static_elements->
length();
i++) {
1200 switch (element->kind()) {
1202 PrintClassProperty(element->property());
1205 PrintIndentedVisit(
"STATIC BLOCK", element->static_block());
1211void AstPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {
1212 IndentedScope indent(
this,
"NATIVE FUNC LITERAL", node->position());
1213 PrintLiteralIndented(
"NAME", node->raw_name(),
false);
1216void AstPrinter::VisitConditionalChain(ConditionalChain* node) {
1217 IndentedScope indent(
this,
"CONDITIONAL_CHAIN", node->position());
1218 PrintIndentedVisit(
"CONDITION", node->condition_at(0));
1219 PrintIndentedVisit(
"THEN", node->then_expression_at(0));
1220 for (
size_t i = 1;
i < node->conditional_chain_length(); ++
i) {
1221 IndentedScope inner_indent(
this,
"ELSE IF", node->condition_position_at(
i));
1222 PrintIndentedVisit(
"CONDITION", node->condition_at(
i));
1223 PrintIndentedVisit(
"THEN", node->then_expression_at(
i));
1225 PrintIndentedVisit(
"ELSE", node->else_expression());
1228void AstPrinter::VisitConditional(Conditional* node) {
1229 IndentedScope indent(
this,
"CONDITIONAL", node->position());
1230 PrintIndentedVisit(
"CONDITION", node->condition());
1231 PrintIndentedVisit(
"THEN", node->then_expression());
1232 PrintIndentedVisit(
"ELSE", node->else_expression());
1236void AstPrinter::VisitLiteral(Literal* node) {
1237 PrintLiteralIndented(
"LITERAL", node,
true);
1241void AstPrinter::VisitRegExpLiteral(RegExpLiteral* node) {
1242 IndentedScope indent(
this,
"REGEXP LITERAL", node->position());
1243 PrintLiteralIndented(
"PATTERN", node->raw_pattern(),
false);
1245 base::EmbeddedVector<char, 128> buf;
1246#define V(Lower, Camel, LowerCamel, Char, Bit) \
1247 if (node->flags() & RegExp::k##Camel) buf[i++] = Char;
1251 PrintIndented(
"FLAGS ");
1252 Print(
"%s", buf.begin());
1257void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) {
1258 IndentedScope indent(
this,
"OBJ LITERAL", node->position());
1259 PrintObjectProperties(node->properties());
1262void AstPrinter::PrintObjectProperties(
1264 for (
int i = 0;
i < properties->
length();
i++) {
1266 const char* prop_kind =
nullptr;
1267 switch (property->kind()) {
1269 prop_kind =
"CONSTANT";
1272 prop_kind =
"COMPUTED";
1275 prop_kind =
"MATERIALIZED_LITERAL";
1278 prop_kind =
"PROTOTYPE";
1281 prop_kind =
"GETTER";
1284 prop_kind =
"SETTER";
1287 prop_kind =
"SPREAD";
1290 base::EmbeddedVector<char, 128> buf;
1291 SNPrintF(buf,
"PROPERTY - %s", prop_kind);
1292 IndentedScope prop(
this, buf.begin());
1293 PrintIndentedVisit(
"KEY", properties->at(
i)->key());
1294 PrintIndentedVisit(
"VALUE", properties->at(
i)->value());
1299void AstPrinter::VisitArrayLiteral(ArrayLiteral* node) {
1300 IndentedScope array_indent(
this,
"ARRAY LITERAL", node->position());
1301 if (node->values()->length() > 0) {
1302 IndentedScope indent(
this,
"VALUES", node->position());
1304 Visit(node->values()->at(
i));
1310void AstPrinter::VisitVariableProxy(VariableProxy* node) {
1311 base::EmbeddedVector<char, 128> buf;
1314 if (!node->is_resolved()) {
1316 PrintLiteralWithModeIndented(buf.begin(),
nullptr, node->raw_name());
1319 switch (var->location()) {
1324 SNPrintF(buf +
pos,
" parameter[%d]", var->index());
1330 SNPrintF(buf +
pos,
" context[%d]", var->index());
1339 SNPrintF(buf +
pos,
" repl global[%d]", var->index());
1342 PrintLiteralWithModeIndented(buf.begin(), var, node->raw_name());
1347void AstPrinter::VisitAssignment(Assignment* node) {
1348 IndentedScope indent(
this,
Token::Name(node->op()), node->position());
1349 Visit(node->target());
1350 Visit(node->value());
1353void AstPrinter::VisitCompoundAssignment(CompoundAssignment* node) {
1354 VisitAssignment(node);
1357void AstPrinter::VisitYield(Yield* node) {
1358 base::EmbeddedVector<char, 128> buf;
1360 IndentedScope indent(
this, buf.begin(), node->position());
1361 Visit(node->expression());
1364void AstPrinter::VisitYieldStar(YieldStar* node) {
1365 base::EmbeddedVector<char, 128> buf;
1367 IndentedScope indent(
this, buf.begin(), node->position());
1368 Visit(node->expression());
1371void AstPrinter::VisitAwait(Await* node) {
1372 base::EmbeddedVector<char, 128> buf;
1374 IndentedScope indent(
this, buf.begin(), node->position());
1375 Visit(node->expression());
1378void AstPrinter::VisitThrow(Throw* node) {
1379 IndentedScope indent(
this,
"THROW", node->position());
1380 Visit(node->exception());
1383void AstPrinter::VisitOptionalChain(OptionalChain* node) {
1384 IndentedScope indent(
this,
"OPTIONAL_CHAIN", node->position());
1385 Visit(node->expression());
1388void AstPrinter::VisitProperty(Property* node) {
1389 base::EmbeddedVector<char, 128> buf;
1391 IndentedScope indent(
this, buf.begin(), node->position());
1398 PrintLiteralIndented(
"NAME", node->key()->AsLiteral(),
false);
1402 PrintIndentedVisit(
"PRIVATE_METHOD", node->key());
1406 PrintIndentedVisit(
"PRIVATE_GETTER_ONLY", node->key());
1410 PrintIndentedVisit(
"PRIVATE_SETTER_ONLY", node->key());
1414 PrintIndentedVisit(
"PRIVATE_GETTER_AND_SETTER", node->key());
1419 PrintIndentedVisit(
"KEY", node->key());
1423 PrintIndentedVisit(
"PRIVATE_DEBUG_DYNAMIC", node->key());
1431void AstPrinter::VisitCall(Call* node) {
1432 base::EmbeddedVector<char, 128> buf;
1434 IndentedScope indent(
this, buf.begin());
1436 Visit(node->expression());
1437 PrintArguments(node->arguments());
1441void AstPrinter::VisitCallNew(CallNew* node) {
1442 IndentedScope indent(
this,
"CALL NEW", node->position());
1443 Visit(node->expression());
1444 PrintArguments(node->arguments());
1448void AstPrinter::VisitCallRuntime(CallRuntime* node) {
1449 base::EmbeddedVector<char, 128> buf;
1450 SNPrintF(buf,
"CALL RUNTIME %s", node->function()->name);
1451 IndentedScope indent(
this, buf.begin(), node->position());
1452 PrintArguments(node->arguments());
1456void AstPrinter::VisitUnaryOperation(UnaryOperation* node) {
1457 IndentedScope indent(
this,
Token::Name(node->op()), node->position());
1458 Visit(node->expression());
1462void AstPrinter::VisitCountOperation(CountOperation* node) {
1463 base::EmbeddedVector<char, 128> buf;
1464 SNPrintF(buf,
"%s %s", (node->is_prefix() ?
"PRE" :
"POST"),
1466 IndentedScope indent(
this, buf.begin(), node->position());
1467 Visit(node->expression());
1471void AstPrinter::VisitBinaryOperation(BinaryOperation* node) {
1472 IndentedScope indent(
this,
Token::Name(node->op()), node->position());
1473 Visit(node->left());
1474 Visit(node->right());
1477void AstPrinter::VisitNaryOperation(NaryOperation* node) {
1478 IndentedScope indent(
this,
Token::Name(node->op()), node->position());
1479 Visit(node->first());
1480 for (
size_t i = 0;
i < node->subsequent_length(); ++
i) {
1481 Visit(node->subsequent(
i));
1485void AstPrinter::VisitCompareOperation(CompareOperation* node) {
1486 IndentedScope indent(
this,
Token::Name(node->op()), node->position());
1487 Visit(node->left());
1488 Visit(node->right());
1492void AstPrinter::VisitSpread(Spread* node) {
1493 IndentedScope indent(
this,
"SPREAD", node->position());
1494 Visit(node->expression());
1497void AstPrinter::VisitEmptyParentheses(EmptyParentheses* node) {
1498 IndentedScope indent(
this,
"()", node->position());
1501void AstPrinter::VisitGetTemplateObject(GetTemplateObject* node) {
1502 IndentedScope indent(
this,
"GET-TEMPLATE-OBJECT", node->position());
1505void AstPrinter::VisitTemplateLiteral(TemplateLiteral* node) {
1506 IndentedScope indent(
this,
"TEMPLATE-LITERAL", node->position());
1507 const AstRawString*
string = node->string_parts()->first();
1508 if (!string->IsEmpty()) PrintLiteralIndented(
"SPAN",
string,
true);
1509 for (
int i = 0;
i < node->substitutions()->
length();) {
1510 PrintIndentedVisit(
"EXPR", node->substitutions()->at(
i++));
1511 if (i < node->string_parts()->
length()) {
1512 string = node->string_parts()->at(
i);
1513 if (!string->IsEmpty()) PrintLiteralIndented(
"SPAN",
string,
true);
1518void AstPrinter::VisitImportCallExpression(ImportCallExpression* node) {
1519 IndentedScope indent(
this,
"IMPORT-CALL", node->position());
1520 PrintIndented(
"PHASE");
1521 Print(
" %d\n",
static_cast<uint32_t
>(node->phase()));
1522 Visit(node->specifier());
1523 if (node->import_options()) {
1524 Visit(node->import_options());
1528void AstPrinter::VisitThisExpression(ThisExpression* node) {
1529 IndentedScope indent(
this,
"THIS-EXPRESSION", node->position());
1532void AstPrinter::VisitSuperPropertyReference(SuperPropertyReference* node) {
1533 IndentedScope indent(
this,
"SUPER-PROPERTY-REFERENCE", node->position());
1536void AstPrinter::VisitSuperCallReference(SuperCallReference* node) {
1537 IndentedScope indent(
this,
"SUPER-CALL-REFERENCE", node->position());
1540void AstPrinter::VisitSuperCallForwardArgs(SuperCallForwardArgs* node) {
1541 IndentedScope indent(
this,
"SUPER FORWARD-VARARGS", node->position());
1542 Visit(node->expression());
void Visit(AstNode *node)
Assignment * destructuring_assignment_
SpreadErrorInArgsHint error_in_spread_args_
IncrementalStringBuilder builder_
void FindArguments(const ZonePtrList< Expression > *arguments)
void PrintLiteral(DirectHandle< Object > value, bool quote)
ObjectLiteralProperty * destructuring_prop_
ErrorHint GetErrorHint() const
FunctionKind function_kind_
CallPrinter(Isolate *isolate, bool is_user_js, SpreadErrorInArgsHint error_in_spread_args=SpreadErrorInArgsHint::kNoErrorInArgs)
void Find(AstNode *node, bool print=false)
DirectHandle< String > Print(FunctionLiteral *program, int position)
bool is_async_iterator_error_
void FindStatements(const ZonePtrList< Statement > *statements)
ClassLiteralProperty Property
ClassLiteralStaticElement StaticElement
base::ThreadedList< Declaration > List
bool ToBooleanIsTrue() const
V8_WARN_UNUSED_RESULT Handle< String > NumberToString(DirectHandle< Object > number, NumberCacheMode mode=NumberCacheMode::kBoth)
V8_INLINE void AppendCString(const SrcChar *s)
MaybeDirectHandle< String > Finish()
V8_INLINE void AppendCharacter(uint8_t c)
V8_INLINE void AppendString(std::string_view str)
v8::internal::Factory * factory()
ObjectLiteralProperty Property
static AssignType GetAssignType(Property *property)
static constexpr int ToInt(const Tagged< Object > object)
static const char * Name(Value token)
static const char * String(Value token)
V8_INLINE int length() const
Comparator::Output * output_
FunctionLiteral * literal
int SNPrintF(Vector< char > str, const char *format,...)
int VSNPrintF(Vector< char > str, const char *format, va_list args)
V8_INLINE constexpr bool IsInternalizedString(InstanceType instance_type)
SnapshotTable< OpIndex, VariableData >::Key Variable
void DeleteArray(T *array)
bool IsNumber(Tagged< Object > obj)
void PrintF(const char *format,...)
@ PRIVATE_GETTER_AND_SETTER
bool IsAsyncFunction(FunctionKind kind)
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
void Print(Tagged< Object > obj)
void MemCopy(void *dest, const void *src, size_t size)
ZoneList< T * > ZonePtrList
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset IsNull(value)||IsJSProxy(value)||IsWasmObject(value)||(IsJSObject(value) &&(HeapLayout
T * NewArray(size_t size)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
#define DCHECK_EQ(v1, v2)