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

Unified Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 1196433002: Create and test source mapping for invocations. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update comments. Created 5 years, 6 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: pkg/compiler/lib/src/ssa/builder.dart
diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart
index bfa55fe0d41a79d2524d69c94d912ac61d91abea..57761e3942f8ecc62e5bd2c99910d56223663f8d 100644
--- a/pkg/compiler/lib/src/ssa/builder.dart
+++ b/pkg/compiler/lib/src/ssa/builder.dart
@@ -10,7 +10,7 @@ class SsaFunctionCompiler implements FunctionCompiler {
SsaOptimizerTask optimizer;
SsaFunctionCompiler(JavaScriptBackend backend,
- SourceInformationFactory sourceInformationFactory)
+ SourceInformationStrategy sourceInformationFactory)
: generator = new SsaCodeGeneratorTask(backend, sourceInformationFactory),
builder = new SsaBuilderTask(backend, sourceInformationFactory),
optimizer = new SsaOptimizerTask(backend);
@@ -97,7 +97,7 @@ class SyntheticLocal extends Local {
class SsaBuilderTask extends CompilerTask {
final CodeEmitterTask emitter;
final JavaScriptBackend backend;
- final SourceInformationFactory sourceInformationFactory;
+ final SourceInformationStrategy sourceInformationFactory;
String get name => 'SSA builder';
@@ -480,7 +480,8 @@ class LocalsHandler {
* boxed or stored in a closure then the method generates code to retrieve
* the value.
*/
- HInstruction readLocal(Local local) {
+ HInstruction readLocal(Local local,
+ {SourceInformation sourceInformation}) {
if (isAccessedDirectly(local)) {
if (directLocals[local] == null) {
if (local is TypeVariableElement) {
@@ -500,7 +501,7 @@ class LocalsHandler {
: builder.getTypeOfCapturedVariable(redirect);
HInstruction fieldGet = new HFieldGet(redirect, receiver, type);
builder.add(fieldGet);
- return fieldGet;
+ return fieldGet..sourceInformation = sourceInformation;
} else if (isBoxed(local)) {
BoxFieldElement redirect = redirectionMapping[local];
// In the function that declares the captured variable the box is
@@ -512,14 +513,14 @@ class LocalsHandler {
HInstruction lookup = new HFieldGet(
redirect, box, builder.getTypeOfCapturedVariable(redirect));
builder.add(lookup);
- return lookup;
+ return lookup..sourceInformation = sourceInformation;
} else {
assert(isUsedInTryOrGenerator(local));
HLocalValue localValue = getLocal(local);
HInstruction instruction = new HLocalGet(
local, localValue, builder.backend.dynamicType);
builder.add(instruction);
- return instruction;
+ return instruction..sourceInformation = sourceInformation;
}
}
@@ -531,7 +532,8 @@ class LocalsHandler {
return res;
}
- HLocalValue getLocal(Local local) {
+ HLocalValue getLocal(Local local,
+ {SourceInformation sourceInformation}) {
// If the element is a parameter, we already have a
// HParameterValue for it. We cannot create another one because
// it could then have another name than the real parameter. And
@@ -541,7 +543,8 @@ class LocalsHandler {
return builder.activationVariables.putIfAbsent(local, () {
JavaScriptBackend backend = builder.backend;
- HLocalValue localValue = new HLocalValue(local, backend.nonNullType);
+ HLocalValue localValue = new HLocalValue(local, backend.nonNullType)
+ ..sourceInformation = sourceInformation;
builder.graph.entry.addAtExit(localValue);
return localValue;
});
@@ -557,7 +560,8 @@ class LocalsHandler {
* Sets the [element] to [value]. If the element is boxed or stored in a
* closure then the method generates code to set the value.
*/
- void updateLocal(Local local, HInstruction value) {
+ void updateLocal(Local local, HInstruction value,
+ {SourceInformation sourceInformation}) {
assert(!isStoredInClosureField(local));
if (isAccessedDirectly(local)) {
directLocals[local] = value;
@@ -568,11 +572,13 @@ class LocalsHandler {
// Inside the closure the box is stored in a closure-field and cannot
// be accessed directly.
HInstruction box = readLocal(redirect.box);
- builder.add(new HFieldSet(redirect, box, value));
+ builder.add(new HFieldSet(redirect, box, value)
+ ..sourceInformation = sourceInformation);
} else {
assert(isUsedInTryOrGenerator(local));
HLocalValue localValue = getLocal(local);
- builder.add(new HLocalSet(local, localValue, value));
+ builder.add(new HLocalSet(local, localValue, value)
+ ..sourceInformation = sourceInformation);
}
}
@@ -1113,7 +1119,7 @@ class SsaBuilder extends NewResolvedVisitor {
SsaBuilder(JavaScriptBackend backend,
CodegenWorkItem work,
this.nativeEmitter,
- SourceInformationFactory sourceInformationFactory)
+ SourceInformationStrategy sourceInformationFactory)
: this.compiler = backend.compiler,
this.backend = backend,
this.constantSystem = backend.constantSystem,
@@ -1123,7 +1129,8 @@ class SsaBuilder extends NewResolvedVisitor {
localsHandler = new LocalsHandler(this, work.element, null);
sourceElementStack.add(work.element);
sourceInformationBuilder =
- sourceInformationFactory.forContext(work.element.implementation);
+ sourceInformationFactory.createBuilderForContext(
+ work.element.implementation);
}
CodegenRegistry get registry => work.registry;
@@ -1612,17 +1619,19 @@ class SsaBuilder extends NewResolvedVisitor {
if (!backend.operatorEqHandlesNullArgument(functionElement)) {
handleIf(
function,
- () {
+ visitCondition: () {
HParameterValue parameter = parameters.values.first;
push(new HIdentity(
parameter, graph.addConstantNull(compiler), null,
backend.boolType));
},
- () {
+ visitThen: () {
+ // TODO(johnniwinther): Add source information.
closeAndGotoExit(new HReturn(
- graph.addConstantBool(false, compiler)));
+ graph.addConstantBool(false, compiler),
+ null));
},
- null);
+ visitElse: null);
}
}
function.body.accept(this);
@@ -1646,14 +1655,16 @@ class SsaBuilder extends NewResolvedVisitor {
HGraph buildLazyInitializer(VariableElement variable) {
inLazyInitializerExpression = true;
- ast.Node node = variable.node;
+ ast.VariableDefinitions node = variable.node;
openFunction(variable, node);
assert(invariant(variable, variable.initializer != null,
message: "Non-constant variable $variable has no initializer."));
visit(variable.initializer);
HInstruction value = pop();
value = potentiallyCheckOrTrustType(value, variable.type);
- closeAndGotoExit(new HReturn(value));
+ ast.SendSet sendSet = node.definitions.nodes.head;
+ closeAndGotoExit(new HReturn(value,
+ sourceInformationBuilder.buildReturn(sendSet.assignmentOperator)));
return closeFunction();
}
@@ -2155,6 +2166,10 @@ class SsaBuilder extends NewResolvedVisitor {
ssaType,
constructorArguments,
instantiatedTypes);
+ if (function != null) {
+ newObject.sourceInformation =
+ sourceInformationBuilder.buildGeneric(function);
+ }
add(newObject);
} else {
// Bulk assign to the initialized fields.
@@ -2308,7 +2323,8 @@ class SsaBuilder extends NewResolvedVisitor {
}
}
if (inliningStack.isEmpty) {
- closeAndGotoExit(new HReturn(newObject));
+ closeAndGotoExit(new HReturn(newObject,
+ sourceInformationBuilder.buildImplicitReturn(functionElement)));
return closeFunction();
} else {
localsHandler.updateLocal(returnLocal, newObject);
@@ -2609,7 +2625,8 @@ class SsaBuilder extends NewResolvedVisitor {
if (throwExpression != null && inliningStack.isEmpty) {
visitThrowExpression(throwExpression.expression);
handleInTryStatement();
- closeAndGotoExit(new HThrow(pop()));
+ closeAndGotoExit(
+ new HThrow(pop(), sourceInformationBuilder.buildThrow(node)));
} else {
visit(node.expression);
pop();
@@ -3104,7 +3121,8 @@ class SsaBuilder extends NewResolvedVisitor {
TypeMask type =
new TypeMask.nonNullExact(compiler.functionClass, compiler.world);
- push(new HForeignNew(closureClassElement, type, capturedVariables));
+ push(new HForeignNew(closureClassElement, type, capturedVariables)
+ ..sourceInformation = sourceInformationBuilder.buildGeneric(node));
Element methodElement = nestedClosureData.closureElement;
if (compiler.backend.methodNeedsRti(methodElement)) {
@@ -3131,16 +3149,23 @@ class SsaBuilder extends NewResolvedVisitor {
visitIf(ast.If node) {
assert(isReachable);
- handleIf(node,
- () => visit(node.condition),
- () => visit(node.thenPart),
- node.elsePart != null ? () => visit(node.elsePart) : null);
+ handleIf(
+ node,
+ visitCondition: () => visit(node.condition),
+ visitThen: () => visit(node.thenPart),
+ visitElse: node.elsePart != null ? () => visit(node.elsePart) : null,
+ sourceInformation: sourceInformationBuilder.buildIf(node));
}
void handleIf(ast.Node diagnosticNode,
- void visitCondition(), void visitThen(), void visitElse()) {
+ {void visitCondition(),
+ void visitThen(),
+ void visitElse(),
+ SourceInformation sourceInformation}) {
SsaBranchBuilder branchBuilder = new SsaBranchBuilder(this, diagnosticNode);
- branchBuilder.handleIf(visitCondition, visitThen, visitElse);
+ branchBuilder.handleIf(
+ visitCondition, visitThen, visitElse,
+ sourceInformation: sourceInformation);
}
@override
@@ -3171,8 +3196,10 @@ class SsaBuilder extends NewResolvedVisitor {
void visitNot(ast.Send node, ast.Node expression, _) {
assert(node.argumentsNode is ast.Prefix);
visit(expression);
- HNot not = new HNot(popBoolified(), backend.boolType);
- pushWithPosition(not, node);
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildGeneric(node);
+ push(new HNot(popBoolified(), backend.boolType)
+ ..sourceInformation = sourceInformation);
}
@override
@@ -3193,7 +3220,8 @@ class SsaBuilder extends NewResolvedVisitor {
}
}
- pushInvokeDynamic(node, elements.getSelector(node), [operand]);
+ pushInvokeDynamic(node, elements.getSelector(node), [operand],
+ sourceInformation: sourceInformationBuilder.buildGeneric(node));
}
@override
@@ -3226,7 +3254,8 @@ class SsaBuilder extends NewResolvedVisitor {
visitAndPop(right),
elements.getSelector(node),
node,
- location: node.selector);
+ sourceInformation:
+ sourceInformationBuilder.buildGeneric(node.selector));
}
/// TODO(johnniwinther): Merge [visitBinarySend] with [handleBinary] and
@@ -3235,8 +3264,9 @@ class SsaBuilder extends NewResolvedVisitor {
HInstruction right,
Selector selector,
ast.Send send,
- {ast.Node location}) {
- pushInvokeDynamic(send, selector, [left, right], location: location);
+ {SourceInformation sourceInformation}) {
+ pushInvokeDynamic(send, selector, [left, right],
+ sourceInformation: sourceInformation);
}
HInstruction generateInstanceSendReceiver(ast.Send send) {
@@ -3258,12 +3288,14 @@ class SsaBuilder extends NewResolvedVisitor {
* Returns a set of interceptor classes that contain the given
* [selector].
*/
- void generateInstanceGetterWithCompiledReceiver(ast.Send send,
- Selector selector,
- HInstruction receiver) {
+ void generateInstanceGetterWithCompiledReceiver(
+ ast.Send send,
+ Selector selector,
+ HInstruction receiver) {
assert(Elements.isInstanceSend(send, elements));
assert(selector.isGetter);
- pushInvokeDynamic(send, selector, [receiver]);
+ pushInvokeDynamic(send, selector, [receiver],
+ sourceInformation: sourceInformationBuilder.buildGet(send));
}
/// Inserts a call to checkDeferredIsLoaded for [prefixElement].
@@ -3290,15 +3322,20 @@ class SsaBuilder extends NewResolvedVisitor {
}
void handleInvalidStaticGet(ast.Send node, Element element) {
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildGet(node);
generateThrowNoSuchMethod(
node,
noSuchMethodTargetSymbolString(element, 'get'),
- argumentNodes: const Link<ast.Node>());
+ argumentNodes: const Link<ast.Node>(),
+ sourceInformation: sourceInformation);
}
/// Generate read access of an unresolved static or top level entity.
void generateStaticUnresolvedGet(ast.Send node, Element element) {
if (element is ErroneousElement) {
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildGet(node);
// An erroneous element indicates an unresolved static getter.
handleInvalidStaticGet(node, element);
} else {
@@ -3314,7 +3351,8 @@ class SsaBuilder extends NewResolvedVisitor {
void generateStaticConstGet(
ast.Send node,
FieldElement field,
- ConstantExpression constant) {
+ ConstantExpression constant,
+ SourceInformation sourceInformation) {
ConstantValue value = backend.constants.getConstantValue(constant);
HConstant instruction;
// Constants that are referred via a deferred prefix should be referred
@@ -3322,9 +3360,11 @@ class SsaBuilder extends NewResolvedVisitor {
PrefixElement prefix = compiler.deferredLoadTask
.deferredPrefixElement(node, elements);
if (prefix != null) {
- instruction = graph.addDeferredConstant(value, prefix, compiler);
+ instruction =
+ graph.addDeferredConstant(value, prefix, sourceInformation, compiler);
} else {
- instruction = graph.addConstant(value, compiler);
+ instruction = graph.addConstant(
+ value, compiler, sourceInformation: sourceInformation);
}
stack.add(instruction);
// The inferrer may have found a better type than the constant
@@ -3346,34 +3386,41 @@ class SsaBuilder extends NewResolvedVisitor {
ConstantExpression constant =
backend.constants.getConstantForVariable(field);
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildGet(node);
if (constant != null) {
if (!field.isAssignable) {
// A static final or const. Get its constant value and inline it if
// the value can be compiled eagerly.
- generateStaticConstGet(node, field, constant);
+ generateStaticConstGet(node, field, constant, sourceInformation);
} else {
// TODO(5346): Try to avoid the need for calling [declaration] before
// creating an [HStatic].
HInstruction instruction = new HStatic(
field.declaration,
- TypeMaskFactory.inferredTypeForElement(field, compiler));
+ TypeMaskFactory.inferredTypeForElement(field, compiler))
+ ..sourceInformation = sourceInformation;
push(instruction);
}
} else {
HInstruction instruction = new HLazyStatic(
field,
- TypeMaskFactory.inferredTypeForElement(field, compiler));
+ TypeMaskFactory.inferredTypeForElement(field, compiler))
+ ..sourceInformation = sourceInformation;
push(instruction);
}
}
/// Generate a getter invocation of the static or top level [getter].
void generateStaticGetterGet(ast.Send node, MethodElement getter) {
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildGet(node);
if (getter.isDeferredLoaderGetter) {
- generateDeferredLoaderGet(node, getter);
+ generateDeferredLoaderGet(node, getter, sourceInformation);
} else {
generateIsDeferredLoadedCheckOfSend(node);
- pushInvokeStatic(node, getter, <HInstruction>[]);
+ pushInvokeStatic(node, getter, <HInstruction>[],
+ sourceInformation: sourceInformation);
}
}
@@ -3389,14 +3436,22 @@ class SsaBuilder extends NewResolvedVisitor {
generateIsDeferredLoadedCheckOfSend(node);
// TODO(5346): Try to avoid the need for calling [declaration] before
// creating an [HStatic].
- push(new HStatic(function.declaration, backend.nonNullType));
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildGet(node);
+ push(new HStatic(function.declaration, backend.nonNullType)
+ ..sourceInformation = sourceInformation);
// TODO(ahe): This should be registered in codegen.
registry.registerGetOfStaticFunction(function.declaration);
}
/// Read a local variable, function or parameter.
- void handleLocalGet(LocalElement local) {
- stack.add(localsHandler.readLocal(local));
+ void buildLocalGet(LocalElement local, SourceInformation sourceInformation) {
+ stack.add(localsHandler.readLocal(
+ local, sourceInformation: sourceInformation));
+ }
+
+ void handleLocalGet(ast.Send node, LocalElement local) {
+ buildLocalGet(local, sourceInformationBuilder.buildGet(node));
}
@override
@@ -3440,17 +3495,17 @@ class SsaBuilder extends NewResolvedVisitor {
@override
void visitLocalVariableGet(ast.Send node, LocalVariableElement variable, _) {
- handleLocalGet(variable);
+ handleLocalGet(node, variable);
}
@override
void visitParameterGet(ast.Send node, ParameterElement parameter, _) {
- handleLocalGet(parameter);
+ handleLocalGet(node, parameter);
}
@override
void visitLocalFunctionGet(ast.Send node, LocalFunctionElement function, _) {
- handleLocalGet(function);
+ handleLocalGet(node, function);
}
@override
@@ -3524,7 +3579,8 @@ class SsaBuilder extends NewResolvedVisitor {
location = send;
}
assert(selector.isSetter);
- pushInvokeDynamic(location, selector, [receiver, value]);
+ pushInvokeDynamic(location, selector, [receiver, value],
+ sourceInformation: sourceInformationBuilder.buildAssignment(location));
pop();
stack.add(value);
}
@@ -3574,7 +3630,9 @@ class SsaBuilder extends NewResolvedVisitor {
stack.add(checkedOrTrusted);
}
- localsHandler.updateLocal(local, checkedOrTrusted);
+ localsHandler.updateLocal(local, checkedOrTrusted,
+ sourceInformation:
+ sourceInformationBuilder.buildAssignment(location));
}
}
@@ -3781,12 +3839,15 @@ class SsaBuilder extends NewResolvedVisitor {
void _generateDynamicSend(ast.Send node, HInstruction receiver) {
Selector selector = elements.getSelector(node);
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildCall(node, node.selector);
List<HInstruction> inputs = <HInstruction>[];
inputs.add(receiver);
addDynamicSendArgumentsToList(node, inputs);
- pushInvokeDynamic(node, selector, inputs);
+ pushInvokeDynamic(node, selector, inputs,
+ sourceInformation: sourceInformation);
if (selector.isSetter || selector.isIndexSet) {
pop();
stack.add(inputs.last);
@@ -3838,7 +3899,10 @@ class SsaBuilder extends NewResolvedVisitor {
ast.NodeList arguments,
Selector selector,
_) {
- generateCallInvoke(node, visitAndPop(expression));
+ generateCallInvoke(
+ node,
+ visitAndPop(expression),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
@override
@@ -3847,7 +3911,10 @@ class SsaBuilder extends NewResolvedVisitor {
ast.NodeList arguments,
CallStructure callStructure,
_) {
- generateCallInvoke(node, localsHandler.readThis());
+ generateCallInvoke(
+ node,
+ localsHandler.readThis(),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
@override
@@ -3857,7 +3924,10 @@ class SsaBuilder extends NewResolvedVisitor {
ast.NodeList arguments,
CallStructure callStructure,
_) {
- generateCallInvoke(node, localsHandler.readLocal(parameter));
+ generateCallInvoke(
+ node,
+ localsHandler.readLocal(parameter),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
@override
@@ -3867,7 +3937,10 @@ class SsaBuilder extends NewResolvedVisitor {
ast.NodeList arguments,
CallStructure callStructure,
_) {
- generateCallInvoke(node, localsHandler.readLocal(variable));
+ generateCallInvoke(
+ node,
+ localsHandler.readLocal(variable),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
@override
@@ -3877,7 +3950,10 @@ class SsaBuilder extends NewResolvedVisitor {
ast.NodeList arguments,
CallStructure callStructure,
_) {
- generateCallInvoke(node, localsHandler.readLocal(function));
+ generateCallInvoke(
+ node,
+ localsHandler.readLocal(function),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
@override
@@ -3887,7 +3963,8 @@ class SsaBuilder extends NewResolvedVisitor {
ast.NodeList arguments,
CallStructure callStructure,
_) {
- generateCallInvoke(node, localsHandler.readLocal(function));
+ generateCallInvoke(node, localsHandler.readLocal(function),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
void handleForeignJs(ast.Send node) {
@@ -3907,17 +3984,21 @@ class SsaBuilder extends NewResolvedVisitor {
TypeMask ssaType =
TypeMaskFactory.fromNativeBehavior(nativeBehavior, compiler);
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildCall(node, node.argumentsNode);
if (nativeBehavior.codeTemplate.isExpression) {
push(new HForeignCode(
nativeBehavior.codeTemplate, ssaType, inputs,
effects: nativeBehavior.sideEffects,
- nativeBehavior: nativeBehavior));
+ nativeBehavior: nativeBehavior)
+ ..sourceInformation = sourceInformation);
} else {
push(new HForeignCode(
nativeBehavior.codeTemplate, ssaType, inputs,
isStatement: true,
effects: nativeBehavior.sideEffects,
- nativeBehavior: nativeBehavior));
+ nativeBehavior: nativeBehavior)
+ ..sourceInformation = sourceInformation);
}
}
@@ -4267,7 +4348,9 @@ class SsaBuilder extends NewResolvedVisitor {
}
}
- generateDeferredLoaderGet(ast.Send node, FunctionElement deferredLoader) {
+ generateDeferredLoaderGet(ast.Send node,
+ FunctionElement deferredLoader,
+ SourceInformation sourceInformation) {
// Until now we only handle these as getters.
invariant(node, deferredLoader.isDeferredLoaderGetter);
Element loadFunction = compiler.loadLibraryFunction;
@@ -4277,7 +4360,8 @@ class SsaBuilder extends NewResolvedVisitor {
var inputs = [graph.addConstantString(
new ast.DartString.literal(loadId), compiler)];
push(new HInvokeStatic(loadFunction, inputs, backend.nonNullType,
- targetCanThrow: false));
+ targetCanThrow: false)
+ ..sourceInformation = sourceInformation);
}
generateSuperNoSuchMethodSend(ast.Send node,
@@ -4328,14 +4412,16 @@ class SsaBuilder extends NewResolvedVisitor {
graph.addConstant(kindConstant, compiler),
argumentsInstruction,
argumentNamesInstruction],
- typeMask: backend.dynamicType);
+ typeMask: backend.dynamicType);
var inputs = <HInstruction>[pop()];
push(buildInvokeSuper(compiler.noSuchMethodSelector, element, inputs));
}
/// Generate a call to a super method or constructor.
- void generateSuperInvoke(ast.Send node, FunctionElement function) {
+ void generateSuperInvoke(ast.Send node,
+ FunctionElement function,
+ SourceInformation sourceInformation) {
// TODO(5347): Try to avoid the need for calling [implementation] before
// calling [makeStaticArgumentList].
Selector selector = elements.getSelector(node);
@@ -4346,29 +4432,37 @@ class SsaBuilder extends NewResolvedVisitor {
makeStaticArgumentList(selector.callStructure,
node.arguments,
function.implementation);
- push(buildInvokeSuper(selector, function, inputs));
+ push(buildInvokeSuper(selector, function, inputs, sourceInformation));
}
/// Access the value from the super [element].
void handleSuperGet(ast.Send node, Element element) {
Selector selector = elements.getSelector(node);
- push(buildInvokeSuper(selector, element, const <HInstruction>[]));
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildGet(node);
+ push(buildInvokeSuper(
+ selector, element, const <HInstruction>[], sourceInformation));
}
/// Invoke .call on the value retrieved from the super [element].
void handleSuperCallInvoke(ast.Send node, Element element) {
Selector selector = elements.getSelector(node);
- HInstruction target =
- buildInvokeSuper(selector, element, const <HInstruction>[]);
+ HInstruction target = buildInvokeSuper(
+ selector, element, const <HInstruction>[],
+ sourceInformationBuilder.buildGet(node));
add(target);
- generateCallInvoke(node, target);
+ generateCallInvoke(
+ node,
+ target,
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
/// Invoke super [method].
void handleSuperMethodInvoke(
ast.Send node,
MethodElement method) {
- generateSuperInvoke(node, method);
+ generateSuperInvoke(node, method,
+ sourceInformationBuilder.buildCall(node, node.selector));
}
/// Access an unresolved super property.
@@ -4387,7 +4481,8 @@ class SsaBuilder extends NewResolvedVisitor {
Selector selector = elements.getSelector(node);
Element element = elements[node];
if (selector.applies(element, compiler.world)) {
- generateSuperInvoke(node, element);
+ generateSuperInvoke(node, element,
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
} else {
generateWrongArgumentCountError(node, element, node.arguments);
}
@@ -4577,8 +4672,10 @@ class SsaBuilder extends NewResolvedVisitor {
* extract the type argument by the index of the variable in the list of type
* variables for that class.
*/
- HInstruction readTypeVariable(ClassElement cls,
- TypeVariableElement variable) {
+ HInstruction readTypeVariable(
+ ClassElement cls,
+ TypeVariableElement variable,
+ {SourceInformation sourceInformation}) {
assert(sourceElement.isInstanceMember);
HInstruction target = localsHandler.readThis();
@@ -4596,11 +4693,15 @@ class SsaBuilder extends NewResolvedVisitor {
pushInvokeStatic(null,
backend.getGetRuntimeTypeArgument(),
[target, substitutionName, index],
- typeMask: backend.dynamicType);
+ typeMask: backend.dynamicType,
+ sourceInformation: sourceInformation);
} else {
- pushInvokeStatic(null, backend.getGetTypeArgumentByIndex(),
+ pushInvokeStatic(
+ null,
+ backend.getGetTypeArgumentByIndex(),
[target, index],
- typeMask: backend.dynamicType);
+ typeMask: backend.dynamicType,
+ sourceInformation: sourceInformation);
}
return pop();
}
@@ -4616,7 +4717,10 @@ class SsaBuilder extends NewResolvedVisitor {
/**
* Helper to create an instruction that gets the value of a type variable.
*/
- HInstruction addTypeVariableReference(TypeVariableType type) {
+ HInstruction addTypeVariableReference(
+ TypeVariableType type,
+ {SourceInformation sourceInformation}) {
+
assert(assertTypeInContext(type));
Element member = sourceElement;
bool isClosure = member.enclosingElement.isClosure;
@@ -4634,14 +4738,18 @@ class SsaBuilder extends NewResolvedVisitor {
// The type variable is used from a closure in a factory constructor.
// The value of the type argument is stored as a local on the closure
// itself.
- return localsHandler.readLocal(typeVariableLocal);
+ return localsHandler.readLocal(
+ typeVariableLocal, sourceInformation: sourceInformation);
} else if (member.isFunction ||
member.isGetter ||
member.isSetter ||
isInConstructorContext) {
// The type variable is stored on the "enclosing object" and needs to be
// accessed using the this-reference in the closure.
- return readTypeVariable(member.enclosingClass, type.element);
+ return readTypeVariable(
+ member.enclosingClass,
+ type.element,
+ sourceInformation: sourceInformation);
} else {
assert(member.isField);
// The type variable is stored in a parameter of the method.
@@ -4655,11 +4763,14 @@ class SsaBuilder extends NewResolvedVisitor {
// always return true when seeing one.
(member.isField && !isBuildingFor(member))) {
// The type variable is stored in a parameter of the method.
- return localsHandler.readLocal(typeVariableLocal);
+ return localsHandler.readLocal(
+ typeVariableLocal, sourceInformation: sourceInformation);
} else if (member.isInstanceMember) {
// The type variable is stored on the object.
- return readTypeVariable(member.enclosingClass,
- type.element);
+ return readTypeVariable(
+ member.enclosingClass,
+ type.element,
+ sourceInformation: sourceInformation);
} else {
compiler.internalError(type.element,
'Unexpected type variable in static context.');
@@ -4667,7 +4778,10 @@ class SsaBuilder extends NewResolvedVisitor {
}
}
- HInstruction analyzeTypeArgument(DartType argument) {
+ HInstruction analyzeTypeArgument(
+ DartType argument,
+ {SourceInformation sourceInformation}) {
+
assert(assertTypeInContext(argument));
if (argument.treatAsDynamic) {
// Represent [dynamic] as [null].
@@ -4675,7 +4789,8 @@ class SsaBuilder extends NewResolvedVisitor {
}
if (argument.isTypeVariable) {
- return addTypeVariableReference(argument);
+ return addTypeVariableReference(
+ argument, sourceInformation: sourceInformation);
}
List<HInstruction> inputs = <HInstruction>[];
@@ -4710,7 +4825,8 @@ class SsaBuilder extends NewResolvedVisitor {
void copyRuntimeTypeInfo(HInstruction source, HInstruction target) {
Element copyHelper = backend.getCopyTypeArguments();
- pushInvokeStatic(null, copyHelper, [source, target]);
+ pushInvokeStatic(null, copyHelper, [source, target],
+ sourceInformation: target.sourceInformation);
pop();
}
@@ -4730,7 +4846,8 @@ class SsaBuilder extends NewResolvedVisitor {
null,
typeInfoSetterElement,
<HInstruction>[newObject, typeInfo],
- typeMask: backend.dynamicType);
+ typeMask: backend.dynamicType,
+ sourceInformation: newObject.sourceInformation);
// The new object will now be referenced through the
// `setRuntimeTypeInfo` call. We therefore set the type of that
@@ -4885,6 +5002,8 @@ class SsaBuilder extends NewResolvedVisitor {
push(buildLiteralList(<HInstruction>[]));
stack.last.instructionType = elementType;
} else {
+ SourceInformation sourceInformation =
+ sourceInformationBuilder.buildNew(send);
ClassElement cls = constructor.enclosingClass;
if (cls.isAbstract && constructor.isGenerativeConstructor) {
generateAbstractClassInstantiationError(send, cls.name);
@@ -4894,7 +5013,9 @@ class SsaBuilder extends NewResolvedVisitor {
addInlinedInstantiation(expectedType);
pushInvokeStatic(node, constructor, inputs,
- typeMask: elementType, instanceType: expectedType);
+ typeMask: elementType,
+ instanceType: expectedType,
+ sourceInformation: sourceInformation);
removeInlinedInstantiation(expectedType);
}
HInstruction newInstance = stack.last;
@@ -4928,12 +5049,14 @@ class SsaBuilder extends NewResolvedVisitor {
}
void potentiallyAddTypeArguments(List<HInstruction> inputs, ClassElement cls,
- InterfaceType expectedType) {
+ InterfaceType expectedType,
+ {SourceInformation sourceInformation}) {
if (!backend.classNeedsRti(cls)) return;
assert(expectedType.typeArguments.isEmpty ||
cls.typeVariables.length == expectedType.typeArguments.length);
expectedType.typeArguments.forEach((DartType argument) {
- inputs.add(analyzeTypeArgument(argument));
+ inputs.add(analyzeTypeArgument(
+ argument, sourceInformation: sourceInformation));
});
}
@@ -5026,7 +5149,9 @@ class SsaBuilder extends NewResolvedVisitor {
new HIdentity(inputs[0], inputs[1], null, backend.boolType), node);
return;
} else {
- pushInvokeStatic(node, function, inputs);
+ pushInvokeStatic(node, function, inputs,
+ sourceInformation: sourceInformationBuilder.buildCall(
+ node, node.selector));
}
}
@@ -5045,7 +5170,10 @@ class SsaBuilder extends NewResolvedVisitor {
CallStructure callStructure,
_) {
generateStaticFieldGet(node, field);
- generateCallInvoke(node, pop());
+ generateCallInvoke(
+ node,
+ pop(),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
@override
@@ -5076,7 +5204,10 @@ class SsaBuilder extends NewResolvedVisitor {
CallStructure callStructure,
_) {
generateStaticGetterGet(node, getter);
- generateCallInvoke(node, pop());
+ generateCallInvoke(
+ node,
+ pop(),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
@override
@@ -5087,7 +5218,10 @@ class SsaBuilder extends NewResolvedVisitor {
CallStructure callStructure,
_) {
generateStaticFieldGet(node, field);
- generateCallInvoke(node, pop());
+ generateCallInvoke(
+ node,
+ pop(),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
@override
@@ -5122,7 +5256,10 @@ class SsaBuilder extends NewResolvedVisitor {
CallStructure callStructure,
_) {
generateStaticGetterGet(node, getter);
- generateCallInvoke(node, pop());
+ generateCallInvoke(
+ node,
+ pop(),
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
@override
@@ -5284,7 +5421,8 @@ class SsaBuilder extends NewResolvedVisitor {
void generateTypeVariableLiteral(ast.Send node,
TypeVariableType typeVariable) {
DartType type = localsHandler.substInContext(typeVariable);
- HInstruction value = analyzeTypeArgument(type);
+ HInstruction value = analyzeTypeArgument(type,
+ sourceInformation: sourceInformationBuilder.buildGet(node));
pushInvokeStatic(node,
backend.getRuntimeTypeToString(),
[value],
@@ -5301,17 +5439,20 @@ class SsaBuilder extends NewResolvedVisitor {
// reference instead of creating a NoSuchMethodError to avoid pulling it
// in if it is not used (e.g., in a try/catch).
HInstruction target = pop();
- generateCallInvoke(node, target);
+ generateCallInvoke(node, target,
+ sourceInformationBuilder.buildCall(node, node.argumentsNode));
}
/// Generate a '.call' invocation on [target].
- void generateCallInvoke(ast.Send node, HInstruction target) {
+ void generateCallInvoke(ast.Send node,
+ HInstruction target,
+ SourceInformation sourceInformation) {
Selector selector = elements.getSelector(node);
List<HInstruction> inputs = <HInstruction>[target];
addDynamicSendArgumentsToList(node, inputs);
Selector closureSelector = new Selector.callClosureFrom(selector);
- pushWithPosition(
- new HInvokeClosure(closureSelector, inputs, backend.dynamicType), node);
+ push(new HInvokeClosure(closureSelector, inputs, backend.dynamicType)
+ ..sourceInformation = sourceInformation);
}
visitGetterSend(ast.Send node) {
@@ -5346,7 +5487,8 @@ class SsaBuilder extends NewResolvedVisitor {
String methodName,
{Link<ast.Node> argumentNodes,
List<HInstruction> argumentValues,
- List<String> existingArguments}) {
+ List<String> existingArguments,
+ SourceInformation sourceInformation}) {
Element helper = backend.getThrowNoSuchMethod();
ConstantValue receiverConstant =
constantSystem.createString(new ast.DartString.empty());
@@ -5379,7 +5521,8 @@ class SsaBuilder extends NewResolvedVisitor {
}
pushInvokeStatic(diagnosticNode,
helper,
- [receiver, name, arguments, existingNamesList]);
+ [receiver, name, arguments, existingNamesList],
+ sourceInformation: sourceInformation);
}
/**
@@ -5441,8 +5584,7 @@ class SsaBuilder extends NewResolvedVisitor {
void pushInvokeDynamic(ast.Node node,
Selector selector,
List<HInstruction> arguments,
- {ast.Node location}) {
- if (location == null) location = node;
+ {SourceInformation sourceInformation}) {
// We prefer to not inline certain operations on indexables,
// because the constant folder will handle them better and turn
@@ -5500,17 +5642,17 @@ class SsaBuilder extends NewResolvedVisitor {
inputs.addAll(arguments);
TypeMask type = TypeMaskFactory.inferredTypeForSelector(selector, compiler);
if (selector.isGetter) {
- pushWithPosition(
- new HInvokeDynamicGetter(selector, null, inputs, type),
- location);
+ push(
+ new HInvokeDynamicGetter(selector, null, inputs, type)
+ ..sourceInformation = sourceInformation);
} else if (selector.isSetter) {
- pushWithPosition(
- new HInvokeDynamicSetter(selector, null, inputs, type),
- location);
+ push(
+ new HInvokeDynamicSetter(selector, null, inputs, type)
+ ..sourceInformation = sourceInformation);
} else {
- pushWithPosition(
- new HInvokeDynamicMethod(selector, inputs, type, isIntercepted),
- location);
+ push(
+ new HInvokeDynamicMethod(selector, inputs, type, isIntercepted)
+ ..sourceInformation = sourceInformation);
}
}
@@ -5518,7 +5660,9 @@ class SsaBuilder extends NewResolvedVisitor {
Element element,
List<HInstruction> arguments,
{TypeMask typeMask,
- InterfaceType instanceType}) {
+ InterfaceType instanceType,
+ SourceInformation sourceInformation}) {
+ // TODO(johnniwinther): Use [sourceInformation] instead of [location].
if (tryInlineMethod(element, null, arguments, location,
instanceType: instanceType)) {
return;
@@ -5533,7 +5677,8 @@ class SsaBuilder extends NewResolvedVisitor {
// creating an [HInvokeStatic].
HInvokeStatic instruction = new HInvokeStatic(
element.declaration, arguments, typeMask,
- targetCanThrow: targetCanThrow);
+ targetCanThrow: targetCanThrow)
+ ..sourceInformation = sourceInformation;
if (!currentInlinedInstantiations.isEmpty) {
instruction.instantiatedTypes = new List<DartType>.from(
currentInlinedInstantiations);
@@ -5548,7 +5693,8 @@ class SsaBuilder extends NewResolvedVisitor {
HInstruction buildInvokeSuper(Selector selector,
Element element,
- List<HInstruction> arguments) {
+ List<HInstruction> arguments,
+ [SourceInformation sourceInformation]) {
HInstruction receiver = localsHandler.readThis();
// TODO(5346): Try to avoid the need for calling [declaration] before
// creating an [HStatic].
@@ -5573,6 +5719,7 @@ class SsaBuilder extends NewResolvedVisitor {
selector,
inputs,
type,
+ sourceInformation,
isSetter: selector.isSetter || selector.isIndexSet);
instruction.sideEffects = compiler.world.getSideEffectsOfSelector(selector);
return instruction;
@@ -5589,10 +5736,13 @@ class SsaBuilder extends NewResolvedVisitor {
assert(arguments.tail.isEmpty);
rhs = pop();
}
- visitBinarySend(receiver, rhs,
- elements.getOperatorSelectorInComplexSendSet(node),
- node,
- location: node.assignmentOperator);
+ visitBinarySend(
+ receiver,
+ rhs,
+ elements.getOperatorSelectorInComplexSendSet(node),
+ node,
+ sourceInformation:
+ sourceInformationBuilder.buildGeneric(node.assignmentOperator));
}
void handleSuperSendSet(ast.SendSet node) {
@@ -6045,7 +6195,7 @@ class SsaBuilder extends NewResolvedVisitor {
} else if (getter.isFunction) {
generateStaticFunctionGet(node, getter);
} else if (getter.isLocal) {
- handleLocalGet(getter);
+ handleLocalGet(node, getter);
} else {
internalError(node, "Unexpected getter: $getter");
}
@@ -6176,7 +6326,10 @@ class SsaBuilder extends NewResolvedVisitor {
'rethrowableException should not be null.');
}
handleInTryStatement();
- closeAndGotoExit(new HThrow(exception, isRethrow: true));
+ closeAndGotoExit(
+ new HThrow(exception,
+ sourceInformationBuilder.buildThrow(node),
+ isRethrow: true));
}
visitRedirectingFactoryBody(ast.RedirectingFactoryBody node) {
@@ -6273,7 +6426,8 @@ class SsaBuilder extends NewResolvedVisitor {
visitThrowExpression(node.expression);
if (isReachable) {
handleInTryStatement();
- push(new HThrowExpression(pop()));
+ push(new HThrowExpression(
+ pop(), sourceInformationBuilder.buildThrow(node)));
isReachable = false;
}
}
@@ -7037,7 +7191,10 @@ class SsaBuilder extends NewResolvedVisitor {
[localsHandler.readLocal(switchTarget)],
nativeBehavior: native.NativeBehavior.PURE));
}
- handleIf(node, buildCondition, buildLoop, () => {});
+ handleIf(node,
+ visitCondition: buildCondition,
+ visitThen: buildLoop,
+ visitElse: () => {});
}
}
@@ -7100,7 +7257,7 @@ class SsaBuilder extends NewResolvedVisitor {
if (caseIterator.hasNext) {
pushInvokeStatic(switchCase, getFallThroughErrorElement, []);
HInstruction error = pop();
- closeAndGotoExit(new HThrow(error));
+ closeAndGotoExit(new HThrow(error, error.sourceInformation));
} else if (!isDefaultCase(switchCase)) {
// If there is no default, we will add one later to avoid
// the critical edge. So we generate a break statement to make
@@ -7376,17 +7533,24 @@ class SsaBuilder extends NewResolvedVisitor {
void visitElse() {
if (link.isEmpty) {
- closeAndGotoExit(new HThrow(exception, isRethrow: true));
+ closeAndGotoExit(
+ new HThrow(exception,
+ exception.sourceInformation,
+ isRethrow: true));
} else {
ast.CatchBlock newBlock = link.head;
handleIf(node,
- () { pushCondition(newBlock); },
- visitThen, visitElse);
+ visitCondition: () { pushCondition(newBlock); },
+ visitThen: visitThen,
+ visitElse: visitElse);
}
}
ast.CatchBlock firstBlock = link.head;
- handleIf(node, () { pushCondition(firstBlock); }, visitThen, visitElse);
+ handleIf(node,
+ visitCondition: () { pushCondition(firstBlock); },
+ visitThen: visitThen,
+ visitElse: visitElse);
if (!isAborted()) endCatchBlock = close(new HGoto());
rethrowableException = oldRethrowableException;
@@ -7517,7 +7681,8 @@ class SsaBuilder extends NewResolvedVisitor {
void emitReturn(HInstruction value, ast.Node node) {
if (inliningStack.isEmpty) {
- closeAndGotoExit(attachPosition(new HReturn(value), node));
+ closeAndGotoExit(new HReturn(value,
+ sourceInformationBuilder.buildReturn(node)));
} else {
localsHandler.updateLocal(returnLocal, value);
}
@@ -7802,13 +7967,14 @@ class SsaBranchBuilder {
void buildCondition(void visitCondition(),
SsaBranch conditionBranch,
SsaBranch thenBranch,
- SsaBranch elseBranch) {
+ SsaBranch elseBranch,
+ SourceInformation sourceInformation) {
startBranch(conditionBranch);
visitCondition();
checkNotAborted();
assert(identical(builder.current, builder.lastOpenedBlock));
HInstruction conditionValue = builder.popBoolified();
- HIf branch = new HIf(conditionValue);
+ HIf branch = new HIf(conditionValue)..sourceInformation = sourceInformation;
HBasicBlock conditionExitBlock = builder.current;
builder.close(branch);
conditionBranch.exitLocals = builder.localsHandler;
@@ -7869,7 +8035,10 @@ class SsaBranchBuilder {
return null;
}
- handleIf(void visitCondition(), void visitThen(), void visitElse()) {
+ handleIf(void visitCondition(),
+ void visitThen(),
+ void visitElse(),
+ {SourceInformation sourceInformation}) {
if (visitElse == null) {
// Make sure to have an else part to avoid a critical edge. A
// critical edge is an edge that connects a block with multiple
@@ -7879,12 +8048,17 @@ class SsaBranchBuilder {
visitElse = () {};
}
- _handleDiamondBranch(visitCondition, visitThen, visitElse, false);
+ _handleDiamondBranch(
+ visitCondition, visitThen, visitElse, isExpression: false,
+ sourceInformation: sourceInformation);
}
- handleConditional(void visitCondition(), void visitThen(), void visitElse()) {
+ handleConditional(void visitCondition(),
+ void visitThen(),
+ void visitElse()) {
assert(visitElse != null);
- _handleDiamondBranch(visitCondition, visitThen, visitElse, true);
+ _handleDiamondBranch(
+ visitCondition, visitThen, visitElse, isExpression: true);
}
handleIfNull(void left(), void right()) {
@@ -7979,7 +8153,8 @@ class SsaBranchBuilder {
void _handleDiamondBranch(void visitCondition(),
void visitThen(),
void visitElse(),
- bool isExpression) {
+ {bool isExpression,
+ SourceInformation sourceInformation}) {
SsaBranch conditionBranch = new SsaBranch(this);
SsaBranch thenBranch = new SsaBranch(this);
SsaBranch elseBranch = new SsaBranch(this);
@@ -7988,7 +8163,8 @@ class SsaBranchBuilder {
conditionBranch.startLocals = builder.localsHandler;
builder.goto(builder.current, conditionBranch.block);
- buildCondition(visitCondition, conditionBranch, thenBranch, elseBranch);
+ buildCondition(visitCondition, conditionBranch, thenBranch, elseBranch,
+ sourceInformation);
HInstruction thenValue =
buildBranch(thenBranch, visitThen, joinBranch, isExpression);
HInstruction elseValue =

Powered by Google App Engine
This is Rietveld 408576698