Revert "[Ast] Teach Ast Printer to print raw literal values."
This reverts commit c60934e9e4
.
Reason for revert: breaks nosnap build
Original change's description:
> [Ast] Teach Ast Printer to print raw literal values.
>
> Converts the ast prettyprinter to printing literals from the raw values
> rather than internalized on-heap strings. This enables ast printing before
> internalizing, and means we can avoid use of the isolate in the interpreter's
> off-thread phase.
>
> Also removes --print-builtin-ast and relies on just --print-ast to print
> everything.
>
> Finally, converts FunctionLiteral's debug_name function to return a
> char[] which is created from the raw name literal where it exists, rather
> than relying on the value having been internalized.
>
> BUG=v8:5203
>
> Change-Id: I0e358d6acc9ae4516ed49e7a763e208fea5fcf66
> Reviewed-on: https://chromium-review.googlesource.com/749261
> Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
> Reviewed-by: Adam Klein <adamk@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#49119}
TBR=rmcilroy@chromium.org,adamk@chromium.org
Change-Id: Ic9d511f5107666a2f6a2bf59d8e93643c32d4d2b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:5203
Reviewed-on: https://chromium-review.googlesource.com/753627
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49120}
This commit is contained in:
parent
c60934e9e4
commit
5dc02ef2b8
@ -168,20 +168,6 @@ void AstConsString::Internalize(Isolate* isolate) {
|
|||||||
set_string(tmp);
|
set_string(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::forward_list<const AstRawString*> AstConsString::ToRawStrings() const {
|
|
||||||
std::forward_list<const AstRawString*> result;
|
|
||||||
if (IsEmpty()) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.emplace_front(segment_.string);
|
|
||||||
for (AstConsString::Segment* current = segment_.next; current != nullptr;
|
|
||||||
current = current->next) {
|
|
||||||
result.emplace_front(current->string);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
AstStringConstants::AstStringConstants(Isolate* isolate, uint32_t hash_seed)
|
AstStringConstants::AstStringConstants(Isolate* isolate, uint32_t hash_seed)
|
||||||
: zone_(isolate->allocator(), ZONE_NAME),
|
: zone_(isolate->allocator(), ZONE_NAME),
|
||||||
string_table_(AstRawString::Compare),
|
string_table_(AstRawString::Compare),
|
||||||
|
@ -28,8 +28,6 @@
|
|||||||
#ifndef V8_AST_AST_VALUE_FACTORY_H_
|
#ifndef V8_AST_AST_VALUE_FACTORY_H_
|
||||||
#define V8_AST_AST_VALUE_FACTORY_H_
|
#define V8_AST_AST_VALUE_FACTORY_H_
|
||||||
|
|
||||||
#include <forward_list>
|
|
||||||
|
|
||||||
#include "src/base/hashmap.h"
|
#include "src/base/hashmap.h"
|
||||||
#include "src/conversions.h"
|
#include "src/conversions.h"
|
||||||
#include "src/factory.h"
|
#include "src/factory.h"
|
||||||
@ -153,8 +151,6 @@ class AstConsString final : public ZoneObject {
|
|||||||
return Handle<String>(string_);
|
return Handle<String>(string_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::forward_list<const AstRawString*> ToRawStrings() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class AstValueFactory;
|
friend class AstValueFactory;
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "src/ast/ast.h"
|
#include "src/ast/ast.h"
|
||||||
|
|
||||||
#include <cmath> // For isfinite.
|
#include <cmath> // For isfinite.
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "src/ast/compile-time-value.h"
|
#include "src/ast/compile-time-value.h"
|
||||||
#include "src/ast/prettyprinter.h"
|
#include "src/ast/prettyprinter.h"
|
||||||
@ -249,34 +248,6 @@ bool FunctionLiteral::NeedsHomeObject(Expression* expr) {
|
|||||||
return expr->AsFunctionLiteral()->scope()->NeedsHomeObject();
|
return expr->AsFunctionLiteral()->scope()->NeedsHomeObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<char[]> FunctionLiteral::GetDebugName() const {
|
|
||||||
const AstConsString* cons_string;
|
|
||||||
if (raw_name_ != nullptr && !raw_name_->IsEmpty()) {
|
|
||||||
cons_string = raw_name_;
|
|
||||||
} else if (raw_inferred_name_ != nullptr && !raw_inferred_name_->IsEmpty()) {
|
|
||||||
cons_string = raw_inferred_name_;
|
|
||||||
} else if (!inferred_name_.is_null()) {
|
|
||||||
AllowHandleDereference allow_deref;
|
|
||||||
return inferred_name_->ToCString();
|
|
||||||
} else {
|
|
||||||
return std::unique_ptr<char[]>(new char{'\0'});
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(rmcilroy): Deal with two-character strings.
|
|
||||||
std::vector<char> result_vec;
|
|
||||||
std::forward_list<const AstRawString*> strings = cons_string->ToRawStrings();
|
|
||||||
for (const AstRawString* string : strings) {
|
|
||||||
if (!string->is_one_byte()) break;
|
|
||||||
for (int i = 0; i < string->length(); i++) {
|
|
||||||
result_vec.push_back(string->raw_data()[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::unique_ptr<char[]> result(new char[result_vec.size() + 1]);
|
|
||||||
memcpy(result.get(), result_vec.data(), result_vec.size());
|
|
||||||
result[result_vec.size()] = '\0';
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value,
|
ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value,
|
||||||
Kind kind, bool is_computed_name)
|
Kind kind, bool is_computed_name)
|
||||||
: LiteralProperty(key, value, is_computed_name),
|
: LiteralProperty(key, value, is_computed_name),
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
#ifndef V8_AST_AST_H_
|
#ifndef V8_AST_AST_H_
|
||||||
#define V8_AST_AST_H_
|
#define V8_AST_AST_H_
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "src/ast/ast-value-factory.h"
|
#include "src/ast/ast-value-factory.h"
|
||||||
#include "src/ast/modules.h"
|
#include "src/ast/modules.h"
|
||||||
#include "src/ast/variables.h"
|
#include "src/ast/variables.h"
|
||||||
@ -2268,8 +2266,12 @@ class FunctionLiteral final : public Expression {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns either name or inferred name as a cstring.
|
Handle<String> debug_name() const {
|
||||||
std::unique_ptr<char[]> GetDebugName() const;
|
if (raw_name_ != nullptr && !raw_name_->IsEmpty()) {
|
||||||
|
return raw_name_->string();
|
||||||
|
}
|
||||||
|
return inferred_name();
|
||||||
|
}
|
||||||
|
|
||||||
Handle<String> inferred_name() const {
|
Handle<String> inferred_name() const {
|
||||||
if (!inferred_name_.is_null()) {
|
if (!inferred_name_.is_null()) {
|
||||||
@ -2290,8 +2292,6 @@ class FunctionLiteral final : public Expression {
|
|||||||
raw_inferred_name_ = nullptr;
|
raw_inferred_name_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AstConsString* raw_inferred_name() { return raw_inferred_name_; }
|
|
||||||
|
|
||||||
void set_raw_inferred_name(const AstConsString* raw_inferred_name) {
|
void set_raw_inferred_name(const AstConsString* raw_inferred_name) {
|
||||||
DCHECK_NOT_NULL(raw_inferred_name);
|
DCHECK_NOT_NULL(raw_inferred_name);
|
||||||
raw_inferred_name_ = raw_inferred_name;
|
raw_inferred_name_ = raw_inferred_name;
|
||||||
@ -2524,7 +2524,6 @@ class ClassLiteral final : public Expression {
|
|||||||
class NativeFunctionLiteral final : public Expression {
|
class NativeFunctionLiteral final : public Expression {
|
||||||
public:
|
public:
|
||||||
Handle<String> name() const { return name_->string(); }
|
Handle<String> name() const { return name_->string(); }
|
||||||
const AstRawString* raw_name() const { return name_; }
|
|
||||||
v8::Extension* extension() const { return extension_; }
|
v8::Extension* extension() const { return extension_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -562,66 +562,64 @@ void AstPrinter::PrintLabels(ZoneList<const AstRawString*>* labels) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AstPrinter::PrintLiteral(Literal* literal, bool quote) {
|
void AstPrinter::PrintLiteral(MaybeHandle<Object> maybe_value, bool quote) {
|
||||||
switch (literal->type()) {
|
Handle<Object> value;
|
||||||
case Literal::kString:
|
if (!maybe_value.ToHandle(&value)) {
|
||||||
PrintLiteral(literal->AsRawString(), quote);
|
Print("<nil>");
|
||||||
break;
|
return;
|
||||||
case Literal::kSymbol:
|
|
||||||
const char* symbol;
|
|
||||||
switch (literal->AsSymbol()) {
|
|
||||||
case AstSymbol::kHomeObjectSymbol:
|
|
||||||
symbol = "HomeObjectSymbol";
|
|
||||||
}
|
}
|
||||||
Print("%s", symbol);
|
Object* object = *value;
|
||||||
break;
|
if (object->IsString()) {
|
||||||
case Literal::kSmi:
|
String* string = String::cast(object);
|
||||||
Print("%d", Smi::ToInt(literal->AsSmiLiteral()));
|
if (quote) Print("\"");
|
||||||
break;
|
for (int i = 0; i < string->length(); i++) {
|
||||||
case Literal::kHeapNumber:
|
Print("%c", string->Get(i));
|
||||||
Print("%g", literal->AsNumber());
|
}
|
||||||
break;
|
if (quote) Print("\"");
|
||||||
case Literal::kBigInt:
|
} else if (object->IsNull(isolate_)) {
|
||||||
Print("%sn", literal->AsBigInt().c_str());
|
|
||||||
break;
|
|
||||||
case Literal::kNull:
|
|
||||||
Print("null");
|
Print("null");
|
||||||
break;
|
} else if (object->IsTrue(isolate_)) {
|
||||||
case Literal::kUndefined:
|
|
||||||
Print("undefined");
|
|
||||||
break;
|
|
||||||
case Literal::kTheHole:
|
|
||||||
Print("the hole");
|
|
||||||
break;
|
|
||||||
case Literal::kBoolean:
|
|
||||||
if (literal->ToBooleanIsTrue()) {
|
|
||||||
Print("true");
|
Print("true");
|
||||||
} else {
|
} else if (object->IsFalse(isolate_)) {
|
||||||
Print("false");
|
Print("false");
|
||||||
|
} else if (object->IsUndefined(isolate_)) {
|
||||||
|
Print("undefined");
|
||||||
|
} else if (object->IsNumber()) {
|
||||||
|
Print("%g", object->Number());
|
||||||
|
} else if (object->IsJSObject()) {
|
||||||
|
// regular expression
|
||||||
|
if (object->IsJSFunction()) {
|
||||||
|
Print("JS-Function");
|
||||||
|
} else if (object->IsJSArray()) {
|
||||||
|
Print("JS-array[%u]", Smi::ToInt(JSArray::cast(object)->length()));
|
||||||
|
} else if (object->IsJSObject()) {
|
||||||
|
Print("JS-Object");
|
||||||
|
} else {
|
||||||
|
Print("?UNKNOWN?");
|
||||||
}
|
}
|
||||||
break;
|
} else if (object->IsFixedArray()) {
|
||||||
|
Print("FixedArray");
|
||||||
|
} else if (object->IsSymbol()) {
|
||||||
|
// Symbols can only occur as literals if they were inserted by the parser.
|
||||||
|
Symbol* symbol = Symbol::cast(object);
|
||||||
|
if (symbol->name()->IsString()) {
|
||||||
|
int length = 0;
|
||||||
|
String* string = String::cast(symbol->name());
|
||||||
|
std::unique_ptr<char[]> desc = string->ToCString(
|
||||||
|
ALLOW_NULLS, FAST_STRING_TRAVERSAL, 0, string->length(), &length);
|
||||||
|
Print("Symbol(%*s)", length, desc.get());
|
||||||
|
} else {
|
||||||
|
Print("Symbol()");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Print("<unknown literal %p>", static_cast<void*>(object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AstPrinter::PrintLiteral(const AstRawString* value, bool quote) {
|
void AstPrinter::PrintLiteral(const AstRawString* value, bool quote) {
|
||||||
if (quote) Print("\"");
|
PrintLiteral(value->string(), quote);
|
||||||
const char* format = value->is_one_byte() ? "%c" : "%lc";
|
|
||||||
const int increment = value->is_one_byte() ? 1 : 2;
|
|
||||||
const unsigned char* raw_bytes = value->raw_data();
|
|
||||||
for (int i = 0; i < value->length(); i += increment) {
|
|
||||||
Print(format, raw_bytes[i]);
|
|
||||||
}
|
|
||||||
if (quote) Print("\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AstPrinter::PrintLiteral(const AstConsString* value, bool quote) {
|
|
||||||
if (quote) Print("\"");
|
|
||||||
std::forward_list<const AstRawString*> strings = value->ToRawStrings();
|
|
||||||
for (const AstRawString* string : strings) {
|
|
||||||
PrintLiteral(string, false);
|
|
||||||
}
|
|
||||||
if (quote) Print("\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -652,9 +650,9 @@ class IndentedScope BASE_EMBEDDED {
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
AstPrinter::AstPrinter(uintptr_t stack_limit)
|
AstPrinter::AstPrinter(Isolate* isolate)
|
||||||
: output_(nullptr), size_(0), pos_(0), indent_(0) {
|
: isolate_(isolate), output_(nullptr), size_(0), pos_(0), indent_(0) {
|
||||||
InitializeAstVisitor(stack_limit);
|
InitializeAstVisitor(isolate);
|
||||||
}
|
}
|
||||||
|
|
||||||
AstPrinter::~AstPrinter() {
|
AstPrinter::~AstPrinter() {
|
||||||
@ -670,32 +668,19 @@ void AstPrinter::PrintIndented(const char* txt) {
|
|||||||
Print("%s", txt);
|
Print("%s", txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AstPrinter::PrintLiteralIndented(const char* info, Literal* literal,
|
void AstPrinter::PrintLiteralIndented(const char* info,
|
||||||
|
MaybeHandle<Object> maybe_value,
|
||||||
bool quote) {
|
bool quote) {
|
||||||
PrintIndented(info);
|
PrintIndented(info);
|
||||||
Print(" ");
|
Print(" ");
|
||||||
PrintLiteral(literal, quote);
|
PrintLiteral(maybe_value, quote);
|
||||||
Print("\n");
|
Print("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AstPrinter::PrintLiteralIndented(const char* info,
|
|
||||||
const AstRawString* value, bool quote) {
|
|
||||||
PrintIndented(info);
|
|
||||||
Print(" ");
|
|
||||||
PrintLiteral(value, quote);
|
|
||||||
Print("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void AstPrinter::PrintLiteralIndented(const char* info,
|
void AstPrinter::PrintLiteralWithModeIndented(const char* info,
|
||||||
const AstConsString* value, bool quote) {
|
Variable* var,
|
||||||
PrintIndented(info);
|
Handle<Object> value) {
|
||||||
Print(" ");
|
|
||||||
PrintLiteral(value, quote);
|
|
||||||
Print("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void AstPrinter::PrintLiteralWithModeIndented(const char* info, Variable* var,
|
|
||||||
const AstRawString* value) {
|
|
||||||
if (var == nullptr) {
|
if (var == nullptr) {
|
||||||
PrintLiteralIndented(info, value, true);
|
PrintLiteralIndented(info, value, true);
|
||||||
} else {
|
} else {
|
||||||
@ -730,10 +715,8 @@ const char* AstPrinter::PrintProgram(FunctionLiteral* program) {
|
|||||||
Print(" %d\n", program->kind());
|
Print(" %d\n", program->kind());
|
||||||
PrintIndented("SUSPEND COUNT");
|
PrintIndented("SUSPEND COUNT");
|
||||||
Print(" %d\n", program->suspend_count());
|
Print(" %d\n", program->suspend_count());
|
||||||
PrintLiteralIndented("NAME", program->raw_name(), true);
|
PrintLiteralIndented("NAME", program->name(), true);
|
||||||
if (program->raw_inferred_name()) {
|
PrintLiteralIndented("INFERRED NAME", program->inferred_name(), true);
|
||||||
PrintLiteralIndented("INFERRED NAME", program->raw_inferred_name(), true);
|
|
||||||
}
|
|
||||||
PrintParameters(program->scope());
|
PrintParameters(program->scope());
|
||||||
PrintDeclarations(program->scope()->declarations());
|
PrintDeclarations(program->scope()->declarations());
|
||||||
PrintStatements(program->body());
|
PrintStatements(program->body());
|
||||||
@ -743,7 +726,7 @@ const char* AstPrinter::PrintProgram(FunctionLiteral* program) {
|
|||||||
|
|
||||||
|
|
||||||
void AstPrinter::PrintOut(Isolate* isolate, AstNode* node) {
|
void AstPrinter::PrintOut(Isolate* isolate, AstNode* node) {
|
||||||
AstPrinter printer(isolate->stack_guard()->real_climit());
|
AstPrinter printer(isolate);
|
||||||
printer.Init();
|
printer.Init();
|
||||||
printer.Visit(node);
|
printer.Visit(node);
|
||||||
PrintF("%s", printer.output_);
|
PrintF("%s", printer.output_);
|
||||||
@ -761,7 +744,7 @@ void AstPrinter::PrintParameters(DeclarationScope* scope) {
|
|||||||
IndentedScope indent(this, "PARAMS");
|
IndentedScope indent(this, "PARAMS");
|
||||||
for (int i = 0; i < scope->num_parameters(); i++) {
|
for (int i = 0; i < scope->num_parameters(); i++) {
|
||||||
PrintLiteralWithModeIndented("VAR", scope->parameter(i),
|
PrintLiteralWithModeIndented("VAR", scope->parameter(i),
|
||||||
scope->parameter(i)->raw_name());
|
scope->parameter(i)->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -792,16 +775,16 @@ void AstPrinter::VisitBlock(Block* node) {
|
|||||||
// TODO(svenpanne) Start with IndentedScope.
|
// TODO(svenpanne) Start with IndentedScope.
|
||||||
void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) {
|
void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) {
|
||||||
PrintLiteralWithModeIndented("VARIABLE", node->proxy()->var(),
|
PrintLiteralWithModeIndented("VARIABLE", node->proxy()->var(),
|
||||||
node->proxy()->raw_name());
|
node->proxy()->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO(svenpanne) Start with IndentedScope.
|
// TODO(svenpanne) Start with IndentedScope.
|
||||||
void AstPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) {
|
void AstPrinter::VisitFunctionDeclaration(FunctionDeclaration* node) {
|
||||||
PrintIndented("FUNCTION ");
|
PrintIndented("FUNCTION ");
|
||||||
PrintLiteral(node->proxy()->raw_name(), true);
|
PrintLiteral(node->proxy()->name(), true);
|
||||||
Print(" = function ");
|
Print(" = function ");
|
||||||
PrintLiteral(node->fun()->raw_name(), false);
|
PrintLiteral(node->fun()->name(), false);
|
||||||
Print("\n");
|
Print("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -954,7 +937,7 @@ void AstPrinter::VisitTryCatchStatement(TryCatchStatement* node) {
|
|||||||
}
|
}
|
||||||
Print(" %s\n", prediction);
|
Print(" %s\n", prediction);
|
||||||
PrintLiteralWithModeIndented("CATCHVAR", node->scope()->catch_variable(),
|
PrintLiteralWithModeIndented("CATCHVAR", node->scope()->catch_variable(),
|
||||||
node->scope()->catch_variable()->raw_name());
|
node->scope()->catch_variable()->name());
|
||||||
PrintIndentedVisit("CATCH", node->catch_block());
|
PrintIndentedVisit("CATCH", node->catch_block());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -971,8 +954,8 @@ void AstPrinter::VisitDebuggerStatement(DebuggerStatement* node) {
|
|||||||
|
|
||||||
void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
|
void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
|
||||||
IndentedScope indent(this, "FUNC LITERAL", node->position());
|
IndentedScope indent(this, "FUNC LITERAL", node->position());
|
||||||
PrintLiteralIndented("NAME", node->raw_name(), false);
|
PrintLiteralIndented("NAME", node->name(), false);
|
||||||
PrintLiteralIndented("INFERRED NAME", node->raw_inferred_name(), false);
|
PrintLiteralIndented("INFERRED NAME", node->inferred_name(), false);
|
||||||
PrintParameters(node->scope());
|
PrintParameters(node->scope());
|
||||||
// We don't want to see the function literal in this case: it
|
// We don't want to see the function literal in this case: it
|
||||||
// will be printed via PrintProgram when the code for it is
|
// will be printed via PrintProgram when the code for it is
|
||||||
@ -983,7 +966,7 @@ void AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
|
|||||||
|
|
||||||
void AstPrinter::VisitClassLiteral(ClassLiteral* node) {
|
void AstPrinter::VisitClassLiteral(ClassLiteral* node) {
|
||||||
IndentedScope indent(this, "CLASS LITERAL", node->position());
|
IndentedScope indent(this, "CLASS LITERAL", node->position());
|
||||||
PrintLiteralIndented("NAME", node->constructor()->raw_name(), false);
|
PrintLiteralIndented("NAME", node->constructor()->name(), false);
|
||||||
if (node->extends() != nullptr) {
|
if (node->extends() != nullptr) {
|
||||||
PrintIndentedVisit("EXTENDS", node->extends());
|
PrintIndentedVisit("EXTENDS", node->extends());
|
||||||
}
|
}
|
||||||
@ -1027,7 +1010,7 @@ void AstPrinter::PrintClassProperties(
|
|||||||
|
|
||||||
void AstPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {
|
void AstPrinter::VisitNativeFunctionLiteral(NativeFunctionLiteral* node) {
|
||||||
IndentedScope indent(this, "NATIVE FUNC LITERAL", node->position());
|
IndentedScope indent(this, "NATIVE FUNC LITERAL", node->position());
|
||||||
PrintLiteralIndented("NAME", node->raw_name(), false);
|
PrintLiteralIndented("NAME", node->name(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1046,13 +1029,15 @@ void AstPrinter::VisitConditional(Conditional* node) {
|
|||||||
|
|
||||||
|
|
||||||
void AstPrinter::VisitLiteral(Literal* node) {
|
void AstPrinter::VisitLiteral(Literal* node) {
|
||||||
PrintLiteralIndented("LITERAL", node, true);
|
// TODO(adamk): Teach Literal how to print its values without
|
||||||
|
// allocating on the heap.
|
||||||
|
PrintLiteralIndented("LITERAL", node->BuildValue(isolate_), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AstPrinter::VisitRegExpLiteral(RegExpLiteral* node) {
|
void AstPrinter::VisitRegExpLiteral(RegExpLiteral* node) {
|
||||||
IndentedScope indent(this, "REGEXP LITERAL", node->position());
|
IndentedScope indent(this, "REGEXP LITERAL", node->position());
|
||||||
PrintLiteralIndented("PATTERN", node->raw_pattern(), false);
|
PrintLiteralIndented("PATTERN", node->pattern(), false);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
EmbeddedVector<char, 128> buf;
|
EmbeddedVector<char, 128> buf;
|
||||||
if (node->flags() & RegExp::kGlobal) buf[i++] = 'g';
|
if (node->flags() & RegExp::kGlobal) buf[i++] = 'g';
|
||||||
@ -1126,7 +1111,7 @@ void AstPrinter::VisitVariableProxy(VariableProxy* node) {
|
|||||||
|
|
||||||
if (!node->is_resolved()) {
|
if (!node->is_resolved()) {
|
||||||
SNPrintF(buf + pos, " unresolved");
|
SNPrintF(buf + pos, " unresolved");
|
||||||
PrintLiteralWithModeIndented(buf.start(), nullptr, node->raw_name());
|
PrintLiteralWithModeIndented(buf.start(), nullptr, node->name());
|
||||||
} else {
|
} else {
|
||||||
Variable* var = node->var();
|
Variable* var = node->var();
|
||||||
switch (var->location()) {
|
switch (var->location()) {
|
||||||
@ -1149,7 +1134,7 @@ void AstPrinter::VisitVariableProxy(VariableProxy* node) {
|
|||||||
SNPrintF(buf + pos, " module");
|
SNPrintF(buf + pos, " module");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PrintLiteralWithModeIndented(buf.start(), var, node->raw_name());
|
PrintLiteralWithModeIndented(buf.start(), var, node->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1197,13 +1182,13 @@ void AstPrinter::VisitProperty(Property* node) {
|
|||||||
IndentedScope indent(this, buf.start(), node->position());
|
IndentedScope indent(this, buf.start(), node->position());
|
||||||
|
|
||||||
Visit(node->obj());
|
Visit(node->obj());
|
||||||
LhsKind property_kind = Property::GetAssignType(node);
|
Literal* literal = node->key()->AsLiteral();
|
||||||
if (property_kind == NAMED_PROPERTY ||
|
if (literal != nullptr &&
|
||||||
property_kind == NAMED_SUPER_PROPERTY) {
|
literal->BuildValue(isolate_)->IsInternalizedString()) {
|
||||||
PrintLiteralIndented("NAME", node->key()->AsLiteral(), false);
|
// TODO(adamk): Teach Literal how to print its values without
|
||||||
|
// allocating on the heap.
|
||||||
|
PrintLiteralIndented("NAME", literal->BuildValue(isolate_), false);
|
||||||
} else {
|
} else {
|
||||||
DCHECK(property_kind == KEYED_PROPERTY ||
|
|
||||||
property_kind == KEYED_SUPER_PROPERTY);
|
|
||||||
PrintIndentedVisit("KEY", node->key());
|
PrintIndentedVisit("KEY", node->key());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ class CallPrinter final : public AstVisitor<CallPrinter> {
|
|||||||
|
|
||||||
class AstPrinter final : public AstVisitor<AstPrinter> {
|
class AstPrinter final : public AstVisitor<AstPrinter> {
|
||||||
public:
|
public:
|
||||||
explicit AstPrinter(uintptr_t stack_limit);
|
explicit AstPrinter(Isolate* isolate);
|
||||||
~AstPrinter();
|
~AstPrinter();
|
||||||
|
|
||||||
// The following routines print a node into a string.
|
// The following routines print a node into a string.
|
||||||
@ -89,8 +89,7 @@ class AstPrinter final : public AstVisitor<AstPrinter> {
|
|||||||
|
|
||||||
void PrintLabels(ZoneList<const AstRawString*>* labels);
|
void PrintLabels(ZoneList<const AstRawString*>* labels);
|
||||||
void PrintLiteral(const AstRawString* value, bool quote);
|
void PrintLiteral(const AstRawString* value, bool quote);
|
||||||
void PrintLiteral(const AstConsString* value, bool quote);
|
void PrintLiteral(MaybeHandle<Object> maybe_value, bool quote);
|
||||||
void PrintLiteral(Literal* literal, bool quote);
|
|
||||||
void PrintIndented(const char* txt);
|
void PrintIndented(const char* txt);
|
||||||
void PrintIndentedVisit(const char* s, AstNode* node);
|
void PrintIndentedVisit(const char* s, AstNode* node);
|
||||||
|
|
||||||
@ -99,13 +98,11 @@ class AstPrinter final : public AstVisitor<AstPrinter> {
|
|||||||
void PrintParameters(DeclarationScope* scope);
|
void PrintParameters(DeclarationScope* scope);
|
||||||
void PrintArguments(ZoneList<Expression*>* arguments);
|
void PrintArguments(ZoneList<Expression*>* arguments);
|
||||||
void PrintCaseClause(CaseClause* clause);
|
void PrintCaseClause(CaseClause* clause);
|
||||||
void PrintLiteralIndented(const char* info, Literal* literal, bool quote);
|
void PrintLiteralIndented(const char* info, MaybeHandle<Object> maybe_value,
|
||||||
void PrintLiteralIndented(const char* info, const AstRawString* value,
|
|
||||||
bool quote);
|
bool quote);
|
||||||
void PrintLiteralIndented(const char* info, const AstConsString* value,
|
void PrintLiteralWithModeIndented(const char* info,
|
||||||
bool quote);
|
Variable* var,
|
||||||
void PrintLiteralWithModeIndented(const char* info, Variable* var,
|
Handle<Object> value);
|
||||||
const AstRawString* value);
|
|
||||||
void PrintLabelsIndented(ZoneList<const AstRawString*>* labels);
|
void PrintLabelsIndented(ZoneList<const AstRawString*>* labels);
|
||||||
void PrintObjectProperties(ZoneList<ObjectLiteral::Property*>* properties);
|
void PrintObjectProperties(ZoneList<ObjectLiteral::Property*>* properties);
|
||||||
void PrintClassProperties(ZoneList<ClassLiteral::Property*>* properties);
|
void PrintClassProperties(ZoneList<ClassLiteral::Property*>* properties);
|
||||||
@ -115,6 +112,7 @@ class AstPrinter final : public AstVisitor<AstPrinter> {
|
|||||||
|
|
||||||
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
|
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
|
||||||
|
|
||||||
|
Isolate* isolate_;
|
||||||
char* output_; // output string buffer
|
char* output_; // output string buffer
|
||||||
int size_; // output_ size
|
int size_; // output_ size
|
||||||
int pos_; // current printing position
|
int pos_; // current printing position
|
||||||
|
@ -130,7 +130,8 @@ bool CompilationInfo::has_simple_parameters() {
|
|||||||
|
|
||||||
std::unique_ptr<char[]> CompilationInfo::GetDebugName() const {
|
std::unique_ptr<char[]> CompilationInfo::GetDebugName() const {
|
||||||
if (literal()) {
|
if (literal()) {
|
||||||
return literal()->GetDebugName();
|
AllowHandleDereference allow_deref;
|
||||||
|
return literal()->debug_name()->ToCString();
|
||||||
}
|
}
|
||||||
if (!shared_info().is_null()) {
|
if (!shared_info().is_null()) {
|
||||||
return shared_info()->DebugName()->ToCString();
|
return shared_info()->DebugName()->ToCString();
|
||||||
|
@ -1028,6 +1028,7 @@ DEFINE_BOOL(enable_slow_asserts, false,
|
|||||||
|
|
||||||
// codegen-ia32.cc / codegen-arm.cc / macro-assembler-*.cc
|
// codegen-ia32.cc / codegen-arm.cc / macro-assembler-*.cc
|
||||||
DEFINE_BOOL(print_ast, false, "print source AST")
|
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")
|
DEFINE_BOOL(trap_on_abort, false, "replace aborts by breakpoints")
|
||||||
|
|
||||||
// compiler.cc
|
// compiler.cc
|
||||||
|
@ -137,7 +137,20 @@ void Interpreter::IterateDispatchTable(RootVisitor* v) {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void MaybePrintAst(ParseInfo* parse_info, CompilationInfo* compilation_info) {
|
void MaybePrintAst(ParseInfo* parse_info, CompilationInfo* compilation_info) {
|
||||||
if (!FLAG_print_ast) return;
|
Isolate* isolate = compilation_info->isolate();
|
||||||
|
bool print_ast = isolate->bootstrapper()->IsActive() ? FLAG_print_builtin_ast
|
||||||
|
: FLAG_print_ast;
|
||||||
|
if (!print_ast) return;
|
||||||
|
|
||||||
|
// Requires internalizing the AST, so make sure we are on the main thread and
|
||||||
|
// allow handle dereference and allocations.
|
||||||
|
// TODO(rmcilroy): Make ast-printer print ast raw strings instead of
|
||||||
|
// internalized strings to avoid internalizing here.
|
||||||
|
DCHECK(ThreadId::Current().Equals(isolate->thread_id()));
|
||||||
|
AllowHandleDereference allow_deref;
|
||||||
|
AllowHandleAllocation allow_handles;
|
||||||
|
AllowHeapAllocation allow_gc;
|
||||||
|
parse_info->ast_value_factory()->Internalize(isolate);
|
||||||
|
|
||||||
OFStream os(stdout);
|
OFStream os(stdout);
|
||||||
std::unique_ptr<char[]> name = compilation_info->GetDebugName();
|
std::unique_ptr<char[]> name = compilation_info->GetDebugName();
|
||||||
@ -145,8 +158,7 @@ void MaybePrintAst(ParseInfo* parse_info, CompilationInfo* compilation_info) {
|
|||||||
<< compilation_info->GetDebugName().get() << "]" << std::endl;
|
<< compilation_info->GetDebugName().get() << "]" << std::endl;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
os << "--- AST ---" << std::endl
|
os << "--- AST ---" << std::endl
|
||||||
<< AstPrinter(parse_info->stack_limit())
|
<< AstPrinter(isolate).PrintProgram(compilation_info->literal())
|
||||||
.PrintProgram(compilation_info->literal())
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
}
|
}
|
||||||
|
@ -778,7 +778,7 @@ FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info,
|
|||||||
double ms = timer.Elapsed().InMillisecondsF();
|
double ms = timer.Elapsed().InMillisecondsF();
|
||||||
// We need to make sure that the debug-name is available.
|
// We need to make sure that the debug-name is available.
|
||||||
ast_value_factory()->Internalize(isolate);
|
ast_value_factory()->Internalize(isolate);
|
||||||
std::unique_ptr<char[]> name_chars = result->GetDebugName();
|
std::unique_ptr<char[]> name_chars = result->debug_name()->ToCString();
|
||||||
PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms);
|
PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user