Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: runtime/vm/kernel_to_il.cc

Issue 2628693004: TokenPositions on more nodes when running from Kernel (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/kernel_to_il.cc
diff --git a/runtime/vm/kernel_to_il.cc b/runtime/vm/kernel_to_il.cc
index dae30a4a5ac324e08803d83b84ba10b22d76e41f..c5fc1d16eb5b9f31b15f66d3958b3c449b84017c 100644
--- a/runtime/vm/kernel_to_il.cc
+++ b/runtime/vm/kernel_to_il.cc
@@ -58,21 +58,24 @@ static void DiscoverEnclosingElements(Zone* zone,
}
-void ScopeBuilder::EnterScope(TreeNode* node) {
+void ScopeBuilder::EnterScope(TreeNode* node, TokenPosition start_position) {
scope_ = new (Z) LocalScope(scope_, depth_.function_, depth_.loop_);
+ scope_->set_begin_token_pos(start_position);
result_->scopes.Insert(node, scope_);
}
-void ScopeBuilder::ExitScope() {
+void ScopeBuilder::ExitScope(TokenPosition end_position) {
+ scope_->set_end_token_pos(end_position);
scope_ = scope_->parent();
}
LocalVariable* ScopeBuilder::MakeVariable(const dart::String& name,
- const AbstractType& type) {
- return new (Z) LocalVariable(TokenPosition::kNoSource,
- TokenPosition::kNoSource, name, type);
+ const AbstractType& type,
+ TokenPosition declaration_pos,
+ TokenPosition token_pos) {
+ return new (Z) LocalVariable(declaration_pos, token_pos, name, type);
}
@@ -91,7 +94,8 @@ void ScopeBuilder::AddParameters(FunctionNode* function, intptr_t pos) {
void ScopeBuilder::AddParameter(VariableDeclaration* declaration,
intptr_t pos) {
LocalVariable* variable = MakeVariable(H.DartSymbol(declaration->name()),
- T.TranslateVariableType(declaration));
+ T.TranslateVariableType(declaration),
+ declaration->position());
if (declaration->IsFinal()) {
variable->set_is_final();
}
@@ -237,7 +241,8 @@ void ScopeBuilder::AddVariable(VariableDeclaration* declaration) {
? GenerateName(":var", name_index_++)
: H.DartSymbol(declaration->name());
LocalVariable* variable =
- MakeVariable(name, T.TranslateVariableType(declaration));
+ MakeVariable(name, T.TranslateVariableType(declaration),
+ declaration->position(), declaration->end_position());
if (declaration->IsFinal()) {
variable->set_is_final();
}
@@ -287,6 +292,8 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() {
ContextScope::Handle(Z, function.context_scope()));
}
current_function_scope_ = scope_ = new (Z) LocalScope(enclosing_scope, 0, 0);
+ scope_->set_begin_token_pos(function.token_pos());
+ scope_->set_end_token_pos(function.end_token_pos());
LocalVariable* context_var = parsed_function->current_context_var();
context_var->set_is_forced_stack();
@@ -335,9 +342,9 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() {
for (intptr_t i = 0; i < klass->fields().length(); i++) {
Field* field = klass->fields()[i];
if (!field->IsStatic() && (field->initializer() != NULL)) {
- EnterScope(field);
+ EnterScope(field, field->position());
field->initializer()->AcceptExpressionVisitor(this);
- ExitScope();
+ ExitScope(field->end_position());
}
}
}
@@ -455,7 +462,7 @@ void ScopeBuilder::HandleLocalFunction(TreeNode* parent,
FunctionNode* saved_function_node = current_function_node_;
ScopeBuilder::DepthState saved_depth_state = depth_;
depth_ = DepthState(depth_.function_ + 1);
- EnterScope(parent);
+ EnterScope(parent, function->position());
current_function_scope_ = scope_;
current_function_node_ = function;
if (depth_.function_ == 1) {
@@ -464,7 +471,7 @@ void ScopeBuilder::HandleLocalFunction(TreeNode* parent,
}
AddParameters(function);
VisitFunctionNode(function);
- ExitScope();
+ ExitScope(function->end_position());
depth_ = saved_depth_state;
current_function_scope_ = saved_function_scope;
current_function_node_ = saved_function_node;
@@ -499,16 +506,16 @@ void ScopeBuilder::VisitFunctionExpression(FunctionExpression* node) {
void ScopeBuilder::VisitLet(Let* node) {
- EnterScope(node);
+ EnterScope(node, node->position());
node->VisitChildren(this);
- ExitScope();
+ ExitScope(node->end_position());
}
void ScopeBuilder::VisitBlock(Block* node) {
- EnterScope(node);
+ EnterScope(node, node->position());
node->VisitChildren(this);
- ExitScope();
+ ExitScope(node->end_position());
}
@@ -539,7 +546,7 @@ void ScopeBuilder::VisitDoStatement(DoStatement* node) {
void ScopeBuilder::VisitForStatement(ForStatement* node) {
- EnterScope(node);
+ EnterScope(node, node->position());
List<VariableDeclaration>& variables = node->variables();
for (intptr_t i = 0; i < variables.length(); ++i) {
VisitVariableDeclaration(variables[i]);
@@ -554,7 +561,7 @@ void ScopeBuilder::VisitForStatement(ForStatement* node) {
updates[i]->AcceptExpressionVisitor(this);
}
--depth_.loop_;
- ExitScope();
+ ExitScope(node->end_position());
}
@@ -563,10 +570,10 @@ void ScopeBuilder::VisitForInStatement(ForInStatement* node) {
++depth_.for_in_;
AddIteratorVariable();
++depth_.loop_;
- EnterScope(node);
+ EnterScope(node, node->position());
VisitVariableDeclaration(node->variable());
node->body()->AcceptStatementVisitor(this);
- ExitScope();
+ ExitScope(node->end_position());
--depth_.loop_;
--depth_.for_in_;
}
@@ -612,7 +619,7 @@ void ScopeBuilder::VisitTryCatch(TryCatch* node) {
List<Catch>& catches = node->catches();
for (intptr_t i = 0; i < catches.length(); ++i) {
Catch* ketch = catches[i];
- EnterScope(ketch);
+ EnterScope(ketch, ketch->position());
if (ketch->exception() != NULL) {
VisitVariableDeclaration(ketch->exception());
}
@@ -620,7 +627,7 @@ void ScopeBuilder::VisitTryCatch(TryCatch* node) {
VisitVariableDeclaration(ketch->stack_trace());
}
ketch->body()->AcceptStatementVisitor(this);
- ExitScope();
+ ExitScope(ketch->end_position());
}
--depth_.catch_;
}
@@ -2467,7 +2474,7 @@ Fragment FlowGraphBuilder::PushArgument() {
}
-Fragment FlowGraphBuilder::Return() {
+Fragment FlowGraphBuilder::Return(TokenPosition position) {
Value* value = Pop();
ASSERT(stack_ == NULL);
ReturnInstr* return_instr =
@@ -2582,7 +2589,8 @@ Fragment FlowGraphBuilder::StoreInstanceField(
}
-Fragment FlowGraphBuilder::StoreLocal(LocalVariable* variable) {
+Fragment FlowGraphBuilder::StoreLocal(LocalVariable* variable,
+ TokenPosition position) {
Fragment instructions;
if (variable->is_captured()) {
LocalVariable* value = MakeTemporary();
@@ -2591,8 +2599,9 @@ Fragment FlowGraphBuilder::StoreLocal(LocalVariable* variable) {
instructions +=
StoreInstanceField(Context::variable_offset(variable->index()));
} else {
+ Value* value = Pop();
StoreLocalInstr* store =
- new (Z) StoreLocalInstr(*variable, Pop(), TokenPosition::kNoSource);
+ new (Z) StoreLocalInstr(*variable, value, position);
instructions <<= store;
Push(store);
}
@@ -2606,10 +2615,10 @@ Fragment FlowGraphBuilder::StoreStaticField(const dart::Field& field) {
}
-Fragment FlowGraphBuilder::StringInterpolate() {
+Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) {
Value* array = Pop();
StringInterpolateInstr* interpolate =
- new (Z) StringInterpolateInstr(array, TokenPosition::kNoSource);
+ new (Z) StringInterpolateInstr(array, position);
Push(interpolate);
return Fragment(interpolate);
}
@@ -3017,7 +3026,7 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfFunction(FunctionNode* function,
// false.
Fragment null_fragment(null_entry);
null_fragment += Constant(Bool::False());
- null_fragment += Return();
+ null_fragment += Return(dart_function.end_token_pos());
body = Fragment(body.entry, non_null_entry);
}
@@ -3029,7 +3038,7 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfFunction(FunctionNode* function,
}
if (body.is_open()) {
body += NullConstant();
- body += Return();
+ body += Return(dart_function.end_token_pos());
}
// If functions body contains any yield points build switch statement that
@@ -3102,6 +3111,7 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfFunction(FunctionNode* function,
context_depth_ = current_context_depth;
}
+
normal_entry->LinkTo(body.entry);
// When compiling for OSR, use a depth first search to prune instructions
@@ -3456,7 +3466,7 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfImplicitClosureFunction(
argument_names);
// Return the result.
- body += Return();
+ body += Return(kernel_function->end_position());
return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1);
}
@@ -4215,7 +4225,8 @@ void FlowGraphBuilder::VisitVariableGet(VariableGet* node) {
void FlowGraphBuilder::VisitVariableSet(VariableSet* node) {
Fragment instructions = TranslateExpression(node->expression());
- instructions += StoreLocal(LookupVariable(node->variable()));
+ instructions +=
+ StoreLocal(LookupVariable(node->variable()), node->position());
fragment_ = instructions;
}
@@ -4626,7 +4637,7 @@ void FlowGraphBuilder::VisitIsExpression(IsExpression* node) {
instructions += PushArgument(); // Negate?.
instructions +=
- InstanceCall(TokenPosition::kNoSource,
+ InstanceCall(node->position(),
dart::Library::PrivateCoreLibName(Symbols::_instanceOf()),
Token::kIS, 4);
}
@@ -4772,7 +4783,7 @@ void FlowGraphBuilder::VisitStringConcatenation(StringConcatenation* node) {
instructions += Drop();
}
- instructions += StringInterpolate();
+ instructions += StringInterpolate(node->position());
fragment_ = instructions;
}
@@ -4969,10 +4980,10 @@ void FlowGraphBuilder::VisitReturnStatement(ReturnStatement* node) {
instructions += TranslateFinallyFinalizers(NULL, -1);
if (instructions.is_open()) {
instructions += LoadLocal(scopes_->finally_return_variable);
- instructions += Return();
+ instructions += Return(node->position());
}
} else {
- instructions += Return();
+ instructions += Return(node->position());
}
} else {
Pop();
@@ -5005,7 +5016,7 @@ void FlowGraphBuilder::VisitVariableDeclaration(VariableDeclaration* node) {
instructions += TranslateExpression(initializer);
}
}
- instructions += StoreLocal(variable);
+ instructions += StoreLocal(variable, variable->token_pos());
instructions += Drop();
fragment_ = instructions;
}
@@ -5783,9 +5794,19 @@ Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node,
for (intptr_t i = 0; i < scopes_->function_scopes.length(); ++i) {
if (scopes_->function_scopes[i].function != node) continue;
+ TokenPosition position = node->position();
Kevin Millikin (Google) 2017/01/12 13:43:04 Is there any reason not to just continue numbering
jensj 2017/01/13 10:14:44 Numbering them 0, 1, 2 etc is rather weird at it i
+ if (parent->IsFunctionDeclaration()) {
+ position = FunctionDeclaration::Cast(parent)->position();
+ }
+ if (!position.IsReal()) {
+ // Positions has to be unique in regards to the parent.
+ // A non-real at this point is probably -1, we cannot blindly use that
+ // as others might use it too. Create a new dummy non-real TokenPosition.
+ position = TokenPosition(i).ToSynthetic();
+ }
+
// NOTE: This is not TokenPosition in the general sense!
- function = I->LookupClosureFunction(parsed_function_->function(),
- TokenPosition(i));
+ function = I->LookupClosureFunction(parsed_function_->function(), position);
if (function.IsNull()) {
const dart::String* name;
if (parent->IsFunctionExpression()) {
@@ -5797,8 +5818,9 @@ Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node,
}
// NOTE: This is not TokenPosition in the general sense!
function = Function::NewClosureFunction(
- *name, parsed_function_->function(), TokenPosition(i));
- function.set_is_debuggable(false);
+ *name, parsed_function_->function(), position);
+ function.set_is_debuggable(node->debuggable());
+ function.set_end_token_pos(node->end_position());
LocalScope* scope = scopes_->function_scopes[i].scope;
const ContextScope& context_scope =
ContextScope::Handle(Z, scope->PreserveOuterScope(context_depth_));

Powered by Google App Engine
This is Rietveld 408576698