Commit efefadc6 authored by adamk's avatar adamk Committed by Commit bot

Remove AstNode::PrettyPrint, --print-source, and --print-builtin-source

The PrettyPrinter may have been valuable once, but with all the desugaring
now done in the parser the output is far from readable, and for some nodes
it's next-to-impossible to recreate the source from the AST. --print-ast is a
much more sensible place to look for human-readable info on what the parser did.

Review-Url: https://codereview.chromium.org/1974623002
Cr-Commit-Position: refs/heads/master@{#37730}
parent aa912252
......@@ -41,10 +41,6 @@ void AstNode::Print(Isolate* isolate) {
}
void AstNode::PrettyPrint(Isolate* isolate) {
PrettyPrinter::PrintOut(isolate, this);
}
#endif // DEBUG
......
......@@ -197,7 +197,6 @@ class AstNode: public ZoneObject {
int position() const { return position_; }
#ifdef DEBUG
void PrettyPrint(Isolate* isolate);
void Print(Isolate* isolate);
#endif // DEBUG
......
This diff is collapsed.
......@@ -53,15 +53,15 @@ class CallPrinter : public AstVisitor {
#ifdef DEBUG
class PrettyPrinter: public AstVisitor {
// Prints the AST structure
class AstPrinter : public AstVisitor {
public:
explicit PrettyPrinter(Isolate* isolate);
virtual ~PrettyPrinter();
explicit AstPrinter(Isolate* isolate);
virtual ~AstPrinter();
// The following routines print a node into a string.
// The result string is alive as long as the PrettyPrinter is alive.
const char* Print(AstNode* node);
const char* PrintExpression(FunctionLiteral* program);
const char* PrintProgram(FunctionLiteral* program);
void PRINTF_FORMAT(2, 3) Print(const char* format, ...);
......@@ -75,48 +75,13 @@ class PrettyPrinter: public AstVisitor {
#undef DECLARE_VISIT
private:
Isolate* isolate_;
char* output_; // output string buffer
int size_; // output_ size
int pos_; // current printing position
friend class IndentedScope;
protected:
void Init();
const char* Output() const { return output_; }
virtual void PrintStatements(ZoneList<Statement*>* statements);
void PrintLabels(ZoneList<const AstRawString*>* labels);
virtual void PrintArguments(ZoneList<Expression*>* arguments);
void PrintLiteral(Handle<Object> value, bool quote);
void PrintLiteral(const AstRawString* value, bool quote);
void PrintParameters(Scope* scope);
void PrintDeclarations(ZoneList<Declaration*>* declarations);
void PrintFunctionLiteral(FunctionLiteral* function);
void PrintCaseClause(CaseClause* clause);
void PrintObjectLiteralProperty(ObjectLiteralProperty* property);
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
};
// Prints the AST structure
class AstPrinter: public PrettyPrinter {
public:
explicit AstPrinter(Isolate* isolate);
virtual ~AstPrinter();
const char* PrintProgram(FunctionLiteral* program);
// Print a node to stdout.
static void PrintOut(Isolate* isolate, AstNode* node);
// Individual nodes
#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT
private:
friend class IndentedScope;
void PrintLiteral(Handle<Object> value, bool quote);
void PrintIndented(const char* txt);
void PrintIndentedVisit(const char* s, AstNode* node);
......@@ -136,6 +101,12 @@ class AstPrinter: public PrettyPrinter {
void inc_indent() { indent_++; }
void dec_indent() { indent_--; }
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
Isolate* isolate_;
char* output_; // output string buffer
int size_; // output_ size
int pos_; // current printing position
int indent_;
};
......
......@@ -84,32 +84,24 @@ Comment::~Comment() {
void CodeGenerator::MakeCodePrologue(CompilationInfo* info, const char* kind) {
bool print_source = false;
bool print_ast = false;
const char* ftype;
if (info->isolate()->bootstrapper()->IsActive()) {
print_source = FLAG_print_builtin_source;
print_ast = FLAG_print_builtin_ast;
ftype = "builtin";
} else {
print_source = FLAG_print_source;
print_ast = FLAG_print_ast;
ftype = "user-defined";
}
if (FLAG_trace_codegen || print_source || print_ast) {
if (FLAG_trace_codegen || print_ast) {
base::SmartArrayPointer<char> name = info->GetDebugName();
PrintF("[generating %s code for %s function: %s]\n", kind, ftype,
name.get());
}
#ifdef DEBUG
if (info->parse_info() && print_source) {
PrintF("--- Source from AST ---\n%s\n",
PrettyPrinter(info->isolate()).PrintProgram(info->literal()));
}
if (info->parse_info() && print_ast) {
PrintF("--- AST ---\n%s\n",
AstPrinter(info->isolate()).PrintProgram(info->literal()));
......
......@@ -236,13 +236,6 @@ bool CompilationInfo::ExpectsJSReceiverAsReceiver() {
return is_sloppy(parse_info()->language_mode()) && !parse_info()->is_native();
}
#if DEBUG
void CompilationInfo::PrintAstForTesting() {
PrintF("--- Source from AST ---\n%s\n",
PrettyPrinter(isolate()).PrintProgram(literal()));
}
#endif
// ----------------------------------------------------------------------------
// Implementation of CompilationJob
......
......@@ -397,10 +397,6 @@ class CompilationInfo final {
osr_expr_stack_height_ = height;
}
#if DEBUG
void PrintAstForTesting();
#endif
bool has_simple_parameters();
struct InlinedFunctionHolder {
......
......@@ -967,9 +967,6 @@ DEFINE_BOOL(enable_slow_asserts, false,
#endif
// codegen-ia32.cc / codegen-arm.cc / macro-assembler-*.cc
DEFINE_BOOL(print_source, false, "pretty print source code")
DEFINE_BOOL(print_builtin_source, false,
"pretty print source code for builtins")
DEFINE_BOOL(print_ast, false, "print source AST")
DEFINE_BOOL(print_builtin_ast, false, "print source AST for builtins")
DEFINE_BOOL(trap_on_abort, false, "replace aborts by breakpoints")
......
......@@ -138,7 +138,7 @@ bool Interpreter::MakeBytecode(CompilationInfo* info) {
TimerEventScope<TimerEventCompileIgnition> timer(info->isolate());
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileIgnition");
if (FLAG_print_bytecode || FLAG_print_source || FLAG_print_ast) {
if (FLAG_print_bytecode || FLAG_print_ast) {
OFStream os(stdout);
base::SmartArrayPointer<char> name = info->GetDebugName();
os << "[generating bytecode for function: " << info->GetDebugName().get()
......@@ -147,14 +147,6 @@ bool Interpreter::MakeBytecode(CompilationInfo* info) {
}
#ifdef DEBUG
if (info->parse_info() && FLAG_print_source) {
OFStream os(stdout);
os << "--- Source from AST ---" << std::endl
<< PrettyPrinter(info->isolate()).PrintProgram(info->literal())
<< std::endl
<< std::flush;
}
if (info->parse_info() && FLAG_print_ast) {
OFStream os(stdout);
os << "--- AST ---" << std::endl
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment