Commit f3b5721c authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque][cleanup] Move method definitions from .h to .cc

This CL moves every method definition with >5 LoC from
declaration-visitor.h to declaration-visitor.cc.

R=tebbi@chromium.org

Bug: v8:7793
Change-Id: I61b5672c9662608fd33c3a23af6176cfa9791295
Reviewed-on: https://chromium-review.googlesource.com/1111709Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Simon Zünd <szuend@google.com>
Cr-Commit-Position: refs/heads/master@{#53962}
parent d7ea6030
......@@ -248,6 +248,94 @@ void DeclarationVisitor::Visit(ReturnStatement* stmt) {
}
}
void DeclarationVisitor::Visit(VarDeclarationStatement* stmt) {
std::string variable_name = stmt->name;
const Type* type = declarations()->GetType(stmt->type);
if (type->IsConstexpr()) {
ReportError("cannot declare variable with constexpr type");
}
declarations()->DeclareVariable(variable_name, type);
if (global_context_.verbose()) {
std::cout << "declared variable " << variable_name << " with type " << type
<< "\n";
}
if (stmt->initializer) {
Visit(*stmt->initializer);
if (global_context_.verbose()) {
std::cout << "variable has initialization expression at "
<< CurrentPositionAsString() << "\n";
}
}
}
void DeclarationVisitor::Visit(LogicalOrExpression* expr) {
{
Declarations::NodeScopeActivator scope(declarations(), expr->left);
declarations()->DeclareLabel(kFalseLabelName);
Visit(expr->left);
}
Visit(expr->right);
}
void DeclarationVisitor::Visit(LogicalAndExpression* expr) {
{
Declarations::NodeScopeActivator scope(declarations(), expr->left);
declarations()->DeclareLabel(kTrueLabelName);
Visit(expr->left);
}
Visit(expr->right);
}
void DeclarationVisitor::DeclareExpressionForBranch(Expression* node) {
Declarations::NodeScopeActivator scope(declarations(), node);
// Conditional expressions can either explicitly return a bit
// type, or they can be backed by macros that don't return but
// take a true and false label. By declaring the labels before
// visiting the conditional expression, those label-based
// macro conditionals will be able to find them through normal
// label lookups.
declarations()->DeclareLabel(kTrueLabelName);
declarations()->DeclareLabel(kFalseLabelName);
Visit(node);
}
void DeclarationVisitor::Visit(ConditionalExpression* expr) {
DeclareExpressionForBranch(expr->condition);
PushControlSplit();
Visit(expr->if_true);
Visit(expr->if_false);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(
expr, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void DeclarationVisitor::Visit(IfStatement* stmt) {
if (!stmt->is_constexpr) {
PushControlSplit();
}
DeclareExpressionForBranch(stmt->condition);
Visit(stmt->if_true);
if (stmt->if_false) Visit(*stmt->if_false);
if (!stmt->is_constexpr) {
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
}
void DeclarationVisitor::Visit(WhileStatement* stmt) {
Declarations::NodeScopeActivator scope(declarations(), stmt);
DeclareExpressionForBranch(stmt->condition);
PushControlSplit();
Visit(stmt->body);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void DeclarationVisitor::Visit(ForOfLoopStatement* stmt) {
// Scope for for iteration variable
Declarations::NodeScopeActivator scope(declarations(), stmt);
......@@ -263,6 +351,19 @@ void DeclarationVisitor::Visit(ForOfLoopStatement* stmt) {
changed_vars);
}
void DeclarationVisitor::Visit(ForLoopStatement* stmt) {
Declarations::NodeScopeActivator scope(declarations(), stmt);
if (stmt->var_declaration) Visit(*stmt->var_declaration);
PushControlSplit();
DeclareExpressionForBranch(stmt->test);
Visit(stmt->body);
Visit(stmt->action);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void DeclarationVisitor::Visit(TryLabelStatement* stmt) {
// Activate a new scope to declare handler labels, they should not be
// visible outside the label block.
......@@ -301,6 +402,55 @@ void DeclarationVisitor::Visit(TryLabelStatement* stmt) {
}
}
void DeclarationVisitor::GenerateHeader(std::string& file_name) {
std::stringstream new_contents_stream;
new_contents_stream
<< "#ifndef V8_BUILTINS_BUILTIN_DEFINITIONS_FROM_DSL_H_\n"
"#define V8_BUILTINS_BUILTIN_DEFINITIONS_FROM_DSL_H_\n"
"\n"
"#define BUILTIN_LIST_FROM_DSL(CPP, API, TFJ, TFC, TFS, TFH, ASM) "
"\\\n";
for (auto builtin : torque_builtins_) {
int firstParameterIndex = 1;
bool declareParameters = true;
if (builtin->IsStub()) {
new_contents_stream << "TFS(" << builtin->name();
} else {
new_contents_stream << "TFJ(" << builtin->name();
if (builtin->IsVarArgsJavaScript()) {
new_contents_stream
<< ", SharedFunctionInfo::kDontAdaptArgumentsSentinel";
declareParameters = false;
} else {
assert(builtin->IsFixedArgsJavaScript());
// FixedArg javascript builtins need to offer the parameter
// count.
assert(builtin->parameter_names().size() >= 2);
new_contents_stream << ", " << (builtin->parameter_names().size() - 2);
// And the receiver is explicitly declared.
new_contents_stream << ", kReceiver";
firstParameterIndex = 2;
}
}
if (declareParameters) {
int index = 0;
for (auto parameter : builtin->parameter_names()) {
if (index >= firstParameterIndex) {
new_contents_stream << ", k" << CamelifyString(parameter);
}
index++;
}
}
new_contents_stream << ") \\\n";
}
new_contents_stream
<< "\n"
"#endif // V8_BUILTINS_BUILTIN_DEFINITIONS_FROM_DSL_H_\n";
std::string new_contents(new_contents_stream.str());
ReplaceFileContentsIfDifferent(file_name, new_contents);
}
void DeclarationVisitor::Visit(IdentifierExpression* expr) {
if (expr->generic_arguments.size() != 0) {
TypeVector specialization_types;
......@@ -327,6 +477,70 @@ void DeclarationVisitor::Visit(CallExpression* expr) {
for (Expression* arg : expr->arguments) Visit(arg);
}
void DeclarationVisitor::Visit(TypeDeclaration* decl) {
std::string extends = decl->extends ? *decl->extends : std::string("");
std::string* extends_ptr = decl->extends ? &extends : nullptr;
std::string generates = decl->generates ? *decl->generates : std::string("");
declarations()->DeclareAbstractType(decl->name, generates, extends_ptr);
if (decl->constexpr_generates) {
std::string constexpr_name =
std::string(CONSTEXPR_TYPE_PREFIX) + decl->name;
declarations()->DeclareAbstractType(
constexpr_name, *decl->constexpr_generates, &(decl->name));
}
}
void DeclarationVisitor::MarkLocationModified(Expression* location) {
if (IdentifierExpression* id = IdentifierExpression::cast(location)) {
const Value* value = declarations()->LookupValue(id->name);
if (value->IsVariable()) {
const Variable* variable = Variable::cast(value);
bool was_live = MarkVariableModified(variable);
if (was_live && global_context_.verbose()) {
std::cout << *variable << " was modified in control split at "
<< PositionAsString(id->pos) << "\n";
}
}
}
}
bool DeclarationVisitor::MarkVariableModified(const Variable* variable) {
auto e = live_and_changed_variables_.rend();
auto c = live_and_changed_variables_.rbegin();
bool was_live_in_preceeding_split = false;
while (c != e) {
if (c->live.find(variable) != c->live.end()) {
c->changed.insert(variable);
was_live_in_preceeding_split = true;
}
c++;
}
return was_live_in_preceeding_split;
}
void DeclarationVisitor::DeclareSignature(const Signature& signature) {
auto type_iterator = signature.parameter_types.types.begin();
for (auto name : signature.parameter_names) {
const Type* t(*type_iterator++);
if (name.size() != 0) {
declarations()->DeclareParameter(name, GetParameterVariableFromName(name),
t);
}
}
for (auto& label : signature.labels) {
auto label_params = label.types;
Label* new_label = declarations()->DeclareLabel(label.name);
size_t i = 0;
for (auto var_type : label_params) {
std::string var_name = label.name + std::to_string(i++);
new_label->AddVariable(
declarations()->DeclareVariable(var_name, var_type));
}
}
}
void DeclarationVisitor::DeclareSpecializedTypes(const SpecializationKey& key) {
size_t i = 0;
Generic* generic = key.first;
......
......@@ -65,22 +65,7 @@ class DeclarationVisitor : public FileVisitor {
}
void Visit(ExpressionStatement* stmt) { Visit(stmt->expression); }
void Visit(TailCallStatement* stmt) { Visit(stmt->call); }
void Visit(TypeDeclaration* decl) {
std::string extends = decl->extends ? *decl->extends : std::string("");
std::string* extends_ptr = decl->extends ? &extends : nullptr;
std::string generates =
decl->generates ? *decl->generates : std::string("");
declarations()->DeclareAbstractType(decl->name, generates, extends_ptr);
if (decl->constexpr_generates) {
std::string constexpr_name =
std::string(CONSTEXPR_TYPE_PREFIX) + decl->name;
declarations()->DeclareAbstractType(
constexpr_name, *decl->constexpr_generates, &(decl->name));
}
}
void Visit(TypeDeclaration* decl);
void Visit(TypeAliasDeclaration* decl) {
const Type* type = declarations()->GetType(decl->type);
......@@ -121,99 +106,20 @@ class DeclarationVisitor : public FileVisitor {
if (do_check) DeclareExpressionForBranch(stmt->expression);
}
void Visit(VarDeclarationStatement* stmt) {
std::string variable_name = stmt->name;
const Type* type = declarations()->GetType(stmt->type);
if (type->IsConstexpr()) {
ReportError("cannot declare variable with constexpr type");
}
declarations()->DeclareVariable(variable_name, type);
if (global_context_.verbose()) {
std::cout << "declared variable " << variable_name << " with type "
<< type << "\n";
}
if (stmt->initializer) {
Visit(*stmt->initializer);
if (global_context_.verbose()) {
std::cout << "variable has initialization expression at "
<< CurrentPositionAsString() << "\n";
}
}
}
void Visit(VarDeclarationStatement* stmt);
void Visit(ConstDeclaration* decl) {
declarations()->DeclareConstant(
decl->name, declarations()->GetType(decl->type), decl->literal);
}
void Visit(LogicalOrExpression* expr) {
{
Declarations::NodeScopeActivator scope(declarations(), expr->left);
declarations()->DeclareLabel(kFalseLabelName);
Visit(expr->left);
}
Visit(expr->right);
}
void Visit(LogicalAndExpression* expr) {
{
Declarations::NodeScopeActivator scope(declarations(), expr->left);
declarations()->DeclareLabel(kTrueLabelName);
Visit(expr->left);
}
Visit(expr->right);
}
void DeclareExpressionForBranch(Expression* node) {
Declarations::NodeScopeActivator scope(declarations(), node);
// Conditional expressions can either explicitly return a bit
// type, or they can be backed by macros that don't return but
// take a true and false label. By declaring the labels before
// visiting the conditional expression, those label-based
// macro conditionals will be able to find them through normal
// label lookups.
declarations()->DeclareLabel(kTrueLabelName);
declarations()->DeclareLabel(kFalseLabelName);
Visit(node);
}
void Visit(ConditionalExpression* expr) {
DeclareExpressionForBranch(expr->condition);
PushControlSplit();
Visit(expr->if_true);
Visit(expr->if_false);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(
expr, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void Visit(IfStatement* stmt) {
if (!stmt->is_constexpr) {
PushControlSplit();
}
DeclareExpressionForBranch(stmt->condition);
Visit(stmt->if_true);
if (stmt->if_false) Visit(*stmt->if_false);
if (!stmt->is_constexpr) {
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
}
void Visit(WhileStatement* stmt) {
Declarations::NodeScopeActivator scope(declarations(), stmt);
DeclareExpressionForBranch(stmt->condition);
PushControlSplit();
Visit(stmt->body);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void Visit(LogicalOrExpression* expr);
void Visit(LogicalAndExpression* expr);
void DeclareExpressionForBranch(Expression* node);
void Visit(ConditionalExpression* expr);
void Visit(IfStatement* stmt);
void Visit(WhileStatement* stmt);
void Visit(ForOfLoopStatement* stmt);
void Visit(AssignmentExpression* expr) {
......@@ -225,19 +131,7 @@ class DeclarationVisitor : public FileVisitor {
void Visit(BreakStatement* stmt) {}
void Visit(ContinueStatement* stmt) {}
void Visit(GotoStatement* expr) {}
void Visit(ForLoopStatement* stmt) {
Declarations::NodeScopeActivator scope(declarations(), stmt);
if (stmt->var_declaration) Visit(*stmt->var_declaration);
PushControlSplit();
DeclareExpressionForBranch(stmt->test);
Visit(stmt->body);
Visit(stmt->action);
auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(
stmt, declarations()->GetCurrentSpecializationTypeNamesVector(),
changed_vars);
}
void Visit(ForLoopStatement* stmt);
void Visit(IncrementDecrementExpression* expr) {
MarkLocationModified(expr->location);
......@@ -245,56 +139,7 @@ class DeclarationVisitor : public FileVisitor {
}
void Visit(TryLabelStatement* stmt);
void GenerateHeader(std::string& file_name) {
std::stringstream new_contents_stream;
new_contents_stream
<< "#ifndef V8_BUILTINS_BUILTIN_DEFINITIONS_FROM_DSL_H_\n"
"#define V8_BUILTINS_BUILTIN_DEFINITIONS_FROM_DSL_H_\n"
"\n"
"#define BUILTIN_LIST_FROM_DSL(CPP, API, TFJ, TFC, TFS, TFH, ASM) "
"\\\n";
for (auto builtin : torque_builtins_) {
int firstParameterIndex = 1;
bool declareParameters = true;
if (builtin->IsStub()) {
new_contents_stream << "TFS(" << builtin->name();
} else {
new_contents_stream << "TFJ(" << builtin->name();
if (builtin->IsVarArgsJavaScript()) {
new_contents_stream
<< ", SharedFunctionInfo::kDontAdaptArgumentsSentinel";
declareParameters = false;
} else {
assert(builtin->IsFixedArgsJavaScript());
// FixedArg javascript builtins need to offer the parameter
// count.
assert(builtin->parameter_names().size() >= 2);
new_contents_stream << ", "
<< (builtin->parameter_names().size() - 2);
// And the receiver is explicitly declared.
new_contents_stream << ", kReceiver";
firstParameterIndex = 2;
}
}
if (declareParameters) {
int index = 0;
for (auto parameter : builtin->parameter_names()) {
if (index >= firstParameterIndex) {
new_contents_stream << ", k" << CamelifyString(parameter);
}
index++;
}
}
new_contents_stream << ") \\\n";
}
new_contents_stream
<< "\n"
"#endif // V8_BUILTINS_BUILTIN_DEFINITIONS_FROM_DSL_H_\n";
std::string new_contents(new_contents_stream.str());
ReplaceFileContentsIfDifferent(file_name, new_contents);
}
void GenerateHeader(std::string& file_name);
private:
struct LiveAndChanged {
......@@ -314,55 +159,9 @@ class DeclarationVisitor : public FileVisitor {
return result;
}
void MarkLocationModified(Expression* location) {
if (IdentifierExpression* id = IdentifierExpression::cast(location)) {
const Value* value = declarations()->LookupValue(id->name);
if (value->IsVariable()) {
const Variable* variable = Variable::cast(value);
bool was_live = MarkVariableModified(variable);
if (was_live && global_context_.verbose()) {
std::cout << *variable << " was modified in control split at "
<< PositionAsString(id->pos) << "\n";
}
}
}
}
bool MarkVariableModified(const Variable* variable) {
auto e = live_and_changed_variables_.rend();
auto c = live_and_changed_variables_.rbegin();
bool was_live_in_preceeding_split = false;
while (c != e) {
if (c->live.find(variable) != c->live.end()) {
c->changed.insert(variable);
was_live_in_preceeding_split = true;
}
c++;
}
return was_live_in_preceeding_split;
}
void DeclareSignature(const Signature& signature) {
auto type_iterator = signature.parameter_types.types.begin();
for (auto name : signature.parameter_names) {
const Type* t(*type_iterator++);
if (name.size() != 0) {
declarations()->DeclareParameter(name,
GetParameterVariableFromName(name), t);
}
}
for (auto& label : signature.labels) {
auto label_params = label.types;
Label* new_label = declarations()->DeclareLabel(label.name);
size_t i = 0;
for (auto var_type : label_params) {
std::string var_name = label.name + std::to_string(i++);
new_label->AddVariable(
declarations()->DeclareVariable(var_name, var_type));
}
}
}
void MarkLocationModified(Expression* location);
bool MarkVariableModified(const Variable* variable);
void DeclareSignature(const Signature& signature);
void DeclareSpecializedTypes(const SpecializationKey& key);
void Specialize(const SpecializationKey& key, CallableNode* callable,
......
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