mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
Add source information to variable declarations in CPS.
This adds a source mapping to variable declarations in the beginning of a JS function, that points to the start of the corresponding Dart method: foo: function() { var a, b; ^ maps to foo() { ^ R=sigmund@google.com Review URL: https://codereview.chromium.org/1772703002 .
This commit is contained in:
parent
528f6c01a7
commit
7b7cfb66ab
6 changed files with 33 additions and 12 deletions
|
@ -855,14 +855,16 @@ class IrBuilder {
|
|||
/// 1. Call [buildFunctionHeader].
|
||||
/// 2. Call `buildXXX` methods to build the body.
|
||||
/// 3. Call [makeFunctionDefinition] to finish.
|
||||
ir.FunctionDefinition makeFunctionDefinition() {
|
||||
ir.FunctionDefinition makeFunctionDefinition(
|
||||
SourceInformation sourceInformation) {
|
||||
_ensureReturn();
|
||||
return new ir.FunctionDefinition(
|
||||
state.currentElement,
|
||||
state.thisParameter,
|
||||
state.functionParameters,
|
||||
state.returnContinuation,
|
||||
root);
|
||||
root,
|
||||
sourceInformation: sourceInformation);
|
||||
}
|
||||
|
||||
/// Create a invocation of the [method] on the super class where the call
|
||||
|
|
|
@ -487,7 +487,8 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
|
|||
sourceInformation:
|
||||
sourceInformationBuilder.buildImplicitReturn(constructor));
|
||||
|
||||
return irBuilder.makeFunctionDefinition();
|
||||
return irBuilder.makeFunctionDefinition(
|
||||
sourceInformationBuilder.buildVariableDeclaration());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -738,7 +739,8 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
|
|||
irBuilder.buildConstructorBodyHeader(getConstructorBodyParameters(body),
|
||||
getClosureScopeForNode(node));
|
||||
visit(node.body);
|
||||
return irBuilder.makeFunctionDefinition();
|
||||
return irBuilder.makeFunctionDefinition(
|
||||
sourceInformationBuilder.buildVariableDeclaration());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -781,7 +783,8 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
|
|||
value: initialValue,
|
||||
sourceInformation:
|
||||
sourceInformationBuilder.buildReturn(sendSet.assignmentOperator));
|
||||
return irBuilder.makeFunctionDefinition();
|
||||
return irBuilder.makeFunctionDefinition(
|
||||
sourceInformationBuilder.buildVariableDeclaration());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -952,7 +955,8 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
|
|||
} else {
|
||||
visit(node.body);
|
||||
}
|
||||
return irBuilder.makeFunctionDefinition();
|
||||
return irBuilder.makeFunctionDefinition(
|
||||
sourceInformationBuilder.buildVariableDeclaration());
|
||||
}
|
||||
|
||||
/// Builds the IR for creating an instance of the closure class corresponding
|
||||
|
|
|
@ -421,10 +421,17 @@ class FunctionDefinition extends InteriorNode {
|
|||
final Parameter receiverParameter;
|
||||
final List<Parameter> parameters;
|
||||
final Continuation returnContinuation;
|
||||
final SourceInformation sourceInformation;
|
||||
Expression body;
|
||||
|
||||
FunctionDefinition(this.element, this.receiverParameter, this.parameters,
|
||||
this.returnContinuation, this.body, {this.interceptorParameter});
|
||||
FunctionDefinition(
|
||||
this.element,
|
||||
this.receiverParameter,
|
||||
this.parameters,
|
||||
this.returnContinuation,
|
||||
this.body,
|
||||
{this.interceptorParameter,
|
||||
this.sourceInformation});
|
||||
|
||||
accept(BlockVisitor visitor) => visitor.visitFunctionDefinition(this);
|
||||
|
||||
|
@ -3040,7 +3047,8 @@ class CopyingVisitor extends TrampolineRecursiveVisitor {
|
|||
visit(node.body);
|
||||
FunctionDefinition copy = new FunctionDefinition(
|
||||
node.element, thisParameter, parameters, returnContinuation, _first,
|
||||
interceptorParameter: interceptorParameter);
|
||||
interceptorParameter: interceptorParameter,
|
||||
sourceInformation: node.sourceInformation);
|
||||
_first = _current = null;
|
||||
return copy;
|
||||
}
|
||||
|
|
|
@ -184,7 +184,8 @@ class CodeGenerator extends tree_ir.StatementVisitor
|
|||
if (jsVariables.length > 0) {
|
||||
// Would be nice to avoid inserting at the beginning of list.
|
||||
accumulator.insert(0, new js.ExpressionStatement(
|
||||
new js.VariableDeclarationList(jsVariables)));
|
||||
new js.VariableDeclarationList(jsVariables)
|
||||
.withSourceInformation(function.sourceInformation)));
|
||||
}
|
||||
return new js.Fun(parameters, new js.Block(accumulator));
|
||||
}
|
||||
|
|
|
@ -136,7 +136,8 @@ class Builder implements cps_ir.Visitor/*<NodeCallback|Node>*/ {
|
|||
returnContinuation = node.returnContinuation;
|
||||
phiTempVar = new Variable(node.element, null);
|
||||
Statement body = translateExpression(node.body);
|
||||
return new FunctionDefinition(node.element, parameters, body);
|
||||
return new FunctionDefinition(node.element, parameters, body,
|
||||
sourceInformation: node.sourceInformation);
|
||||
}
|
||||
|
||||
/// Returns a list of variables corresponding to the arguments to a method
|
||||
|
|
|
@ -654,10 +654,15 @@ class Unreachable extends Statement {
|
|||
class FunctionDefinition extends Node {
|
||||
final ExecutableElement element;
|
||||
final List<Variable> parameters;
|
||||
final SourceInformation sourceInformation;
|
||||
Statement body;
|
||||
|
||||
/// Creates a function definition and updates `writeCount` for [parameters].
|
||||
FunctionDefinition(this.element, this.parameters, this.body) {
|
||||
FunctionDefinition(
|
||||
this.element,
|
||||
this.parameters,
|
||||
this.body,
|
||||
{this.sourceInformation}) {
|
||||
for (Variable param in parameters) {
|
||||
param.writeCount++; // Being a parameter counts as a write.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue