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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 1785633002: Make source information mandatory for building send-like node in CPS (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 years, 9 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart
index 3bc70321fb707feb5c236a1101884785f5a19782..d4cf770cf14bf945a3434ab2a5bf8d38f4fd94ae 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart
@@ -695,7 +695,7 @@ class IrBuilder {
assert(!element.isInstanceMember);
assert(isOpen);
if (program.isJsInterop(element)) {
- return buildInvokeJsInteropMember(element, arguments);
+ return buildInvokeJsInteropMember(element, arguments, sourceInformation);
}
return addPrimitive(
new ir.InvokeStatic(element, selector, arguments, sourceInformation));
@@ -726,21 +726,24 @@ class IrBuilder {
CallStructure callStructure,
TypeMask mask,
List<ir.Definition> arguments,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
Selector selector = callStructure.callSelector;
return _buildInvokeDynamic(
target, selector, mask, arguments, sourceInformation);
}
- ir.Primitive buildStaticNoSuchMethod(Selector selector,
- List<ir.Primitive> arguments) {
+ ir.Primitive buildStaticNoSuchMethod(
+ Selector selector,
+ List<ir.Primitive> arguments,
+ SourceInformation sourceInformation) {
ir.Primitive receiver = buildStringConstant('');
ir.Primitive name = buildStringConstant(selector.name);
ir.Primitive argumentList = buildListLiteral(null, arguments);
ir.Primitive expectedArgumentNames = buildNullConstant();
return buildStaticFunctionInvocation(
program.throwNoSuchMethod,
- <ir.Primitive>[receiver, name, argumentList, expectedArgumentNames]);
+ <ir.Primitive>[receiver, name, argumentList, expectedArgumentNames],
+ sourceInformation);
}
/// Create a [ir.Constant] from [value] and add it to the CPS term.
@@ -874,7 +877,7 @@ class IrBuilder {
MethodElement method,
CallStructure callStructure,
List<ir.Primitive> arguments,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
// TODO(johnniwinther): This shouldn't be necessary.
SelectorKind kind = Elements.isOperatorName(method.name)
? SelectorKind.OPERATOR : SelectorKind.CALL;
@@ -886,7 +889,7 @@ class IrBuilder {
/// Create a read access of the [method] on the super class, i.e. a
/// closurization of [method].
ir.Primitive buildSuperMethodGet(MethodElement method,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
// TODO(johnniwinther): This should have its own ir node.
return _buildInvokeSuper(
method,
@@ -910,7 +913,7 @@ class IrBuilder {
/// [value].
ir.Primitive buildSuperSetterSet(MethodElement setter,
ir.Primitive value,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
// TODO(johnniwinther): This should have its own ir node.
_buildInvokeSuper(
setter,
@@ -924,7 +927,7 @@ class IrBuilder {
/// the provided [index].
ir.Primitive buildSuperIndex(MethodElement method,
ir.Primitive index,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
return _buildInvokeSuper(
method, new Selector.index(), <ir.Primitive>[index],
sourceInformation);
@@ -935,7 +938,7 @@ class IrBuilder {
ir.Primitive buildSuperIndexSet(MethodElement method,
ir.Primitive index,
ir.Primitive value,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
_buildInvokeSuper(method, new Selector.indexSet(),
<ir.Primitive>[index, value], sourceInformation);
return value;
@@ -948,7 +951,7 @@ class IrBuilder {
Selector selector,
TypeMask mask,
List<ir.Primitive> arguments,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
return _buildInvokeDynamic(
receiver, selector, mask, arguments, sourceInformation);
}
@@ -964,7 +967,7 @@ class IrBuilder {
if (field != null) {
// If the world says this resolves to a unique field, then it MUST be
// treated as a field access, since the getter might not be emitted.
- return buildFieldGet(receiver, field);
+ return buildFieldGet(receiver, field, sourceInformation);
} else {
return _buildInvokeDynamic(
receiver, selector, mask, const <ir.Primitive>[], sourceInformation);
@@ -977,13 +980,13 @@ class IrBuilder {
Selector selector,
TypeMask mask,
ir.Primitive value,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
assert(selector.isSetter);
FieldElement field = program.locateSingleField(selector, mask);
if (field != null) {
// If the world says this resolves to a unique field, then it MUST be
// treated as a field access, since the setter might not be emitted.
- buildFieldSet(receiver, field, value);
+ buildFieldSet(receiver, field, value, sourceInformation);
} else {
_buildInvokeDynamic(receiver, selector, mask, <ir.Primitive>[value],
sourceInformation);
@@ -997,7 +1000,7 @@ class IrBuilder {
TypeMask mask,
ir.Primitive index,
ir.Primitive value,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
_buildInvokeDynamic(
receiver, new Selector.indexSet(), mask, <ir.Primitive>[index, value],
sourceInformation);
@@ -1015,7 +1018,7 @@ class IrBuilder {
// TODO(johnniwinther): Maybe this should have its own ir node.
return buildCallInvocation(
buildLocalGet(function), callStructure, arguments,
- sourceInformation: sourceInformation);
+ sourceInformation);
}
/// Create a static invocation of [function].
@@ -1024,7 +1027,7 @@ class IrBuilder {
ir.Primitive buildStaticFunctionInvocation(
MethodElement function,
List<ir.Primitive> arguments,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
Selector selector = new Selector.call(
function.memberName, new CallStructure(arguments.length));
return buildInvokeStatic(function, selector, arguments, sourceInformation);
@@ -1041,7 +1044,7 @@ class IrBuilder {
/// Create a write access to the static [field] with the [value].
ir.Primitive buildStaticFieldSet(FieldElement field,
ir.Primitive value,
- [SourceInformation sourceInformation]) {
+ SourceInformation sourceInformation) {
addPrimitive(new ir.SetStatic(field, value, sourceInformation));
return value;
}
@@ -1049,7 +1052,7 @@ class IrBuilder {
/// Create a setter invocation of the static [setter] with the [value].
ir.Primitive buildStaticSetterSet(MethodElement setter,
ir.Primitive value,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
Selector selector = new Selector.setter(setter.memberName);
buildInvokeStatic(
setter, selector, <ir.Primitive>[value], sourceInformation);
@@ -1062,14 +1065,15 @@ class IrBuilder {
ir.Primitive buildErroneousInvocation(
Element element,
Selector selector,
- List<ir.Primitive> arguments) {
+ List<ir.Primitive> arguments,
+ SourceInformation sourceInformation) {
// TODO(johnniwinther): This should have its own ir node.
- return buildInvokeStatic(element, selector, arguments, null);
+ return buildInvokeStatic(element, selector, arguments, sourceInformation);
}
/// Concatenate string values. The arguments must be strings.
ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments,
- {SourceInformation sourceInformation}) {
+ SourceInformation sourceInformation) {
assert(isOpen);
return addPrimitive(new ir.ApplyBuiltinOperator(
ir.BuiltinOperator.StringConcatenate,
@@ -1084,9 +1088,9 @@ class IrBuilder {
ir.Primitive functionExpression,
CallStructure callStructure,
List<ir.Definition> arguments,
- {SourceInformation sourceInformation}) {
- return _buildInvokeCall(functionExpression, callStructure, null, arguments,
- sourceInformation: sourceInformation);
+ SourceInformation sourceInformation) {
+ return _buildInvokeCall(
+ functionExpression, callStructure, null, arguments, sourceInformation);
}
/// Creates an if-then-else statement with the provided [condition] where the
@@ -1337,9 +1341,13 @@ class IrBuilder {
Element variableElement,
Selector variableSelector,
TypeMask variableMask,
+ SourceInformation variableSetSourceInformation,
TypeMask currentMask,
+ SourceInformation currentSourceInformation,
TypeMask iteratorMask,
+ SourceInformation iteratorSourceInformation,
TypeMask moveNextMask,
+ SourceInformation moveNextSourceInformation,
SubbuildFunction buildBody,
JumpTarget target,
ClosureScope closureScope}) {
@@ -1400,10 +1408,14 @@ class IrBuilder {
iterator,
Selectors.current,
currentMask,
- emptyArguments));
+ emptyArguments,
+ sourceInformation: currentSourceInformation));
// TODO(johnniwinther): Extract this as a provided strategy.
if (Elements.isLocal(variableElement)) {
- bodyBuilder.buildLocalVariableSet(variableElement, currentValue);
+ bodyBuilder.buildLocalVariableSet(
+ variableElement,
+ currentValue,
+ variableSetSourceInformation);
} else if (Elements.isError(variableElement) ||
Elements.isMalformed(variableElement)) {
Selector selector = new Selector.setter(
@@ -1412,22 +1424,27 @@ class IrBuilder {
// Note the comparison below. It can be the case that an element isError
// and isMalformed.
if (Elements.isError(variableElement)) {
- bodyBuilder.buildStaticNoSuchMethod(selector, value);
+ bodyBuilder.buildStaticNoSuchMethod(selector, value,
+ variableSetSourceInformation);
} else {
- bodyBuilder.buildErroneousInvocation(variableElement, selector, value);
+ bodyBuilder.buildErroneousInvocation(
+ variableElement, selector, value, variableSetSourceInformation);
}
} else if (Elements.isStaticOrTopLevel(variableElement)) {
if (variableElement.isField) {
bodyBuilder.addPrimitive(
- new ir.SetStatic(variableElement, currentValue));
+ new ir.SetStatic(
+ variableElement, currentValue, variableSetSourceInformation));
} else {
- bodyBuilder.buildStaticSetterSet(variableElement, currentValue);
+ bodyBuilder.buildStaticSetterSet(
+ variableElement, currentValue, variableSetSourceInformation);
}
} else {
ir.Primitive receiver = bodyBuilder.buildThis();
assert(receiver != null);
bodyBuilder.buildDynamicSet(
- receiver, variableSelector, variableMask, currentValue);
+ receiver, variableSelector, variableMask, currentValue,
+ variableSetSourceInformation);
}
// Translate the body in the hole in the delimited term above, and add
@@ -1857,6 +1874,7 @@ class IrBuilder {
ir.Primitive typeMatches =
checkBuilder.buildTypeOperator(exceptionParameter,
clause.type,
+ clause.sourceInformation,
isTypeTest: true);
checkBuilder.add(new ir.LetCont.two(thenContinuation, elseContinuation,
new ir.Branch.strict(typeMatches,
@@ -2009,8 +2027,10 @@ class IrBuilder {
/// Generate the body for a native function [function] that is annotated with
/// an implementation in JavaScript (provided as string in [javaScriptCode]).
- void buildNativeFunctionBody(FunctionElement function,
- String javaScriptCode) {
+ void buildNativeFunctionBody(
+ FunctionElement function,
+ String javaScriptCode,
+ SourceInformation sourceInformation) {
NativeBehavior behavior = new NativeBehavior();
behavior.sideEffects.setAllSideEffects();
// Generate a [ForeignCode] statement from the given native code.
@@ -2018,7 +2038,8 @@ class IrBuilder {
js.js.statementTemplateYielding(
new js.LiteralStatement(javaScriptCode)),
<ir.Primitive>[],
- behavior);
+ behavior,
+ sourceInformation);
}
/// Generate the body for a native function that redirects to a native
@@ -2029,7 +2050,7 @@ class IrBuilder {
/// be the JavaScript implementation of a function, getter, or setter.
void buildRedirectingNativeFunctionBody(FunctionElement function,
String name,
- SourceInformation source) {
+ SourceInformation sourceInformation) {
List<ir.Primitive> arguments = <ir.Primitive>[];
NativeBehavior behavior = new NativeBehavior();
behavior.sideEffects.setAllSideEffects();
@@ -2050,7 +2071,8 @@ class IrBuilder {
// typedef(s).
ir.Constant arity = buildIntegerConstant(type.computeArity());
input = buildStaticFunctionInvocation(
- program.closureConverter, <ir.Primitive>[input, arity]);
+ program.closureConverter, <ir.Primitive>[input, arity],
+ sourceInformation);
}
arguments.add(input);
argumentTemplates.add('#');
@@ -2070,16 +2092,19 @@ class IrBuilder {
js.js.uncachedExpressionTemplate(code),
arguments,
behavior,
+ sourceInformation,
type: program.getTypeMaskForNativeFunction(function));
- buildReturn(value: value, sourceInformation: source);
+ buildReturn(value: value, sourceInformation: sourceInformation);
}
static _isNotNull(ir.Primitive value) =>
!(value is ir.Constant && value.value.isNull);
/// Builds a call to a resolved js-interop element.
- ir.Primitive buildInvokeJsInteropMember(FunctionElement element,
- List<ir.Primitive> arguments) {
+ ir.Primitive buildInvokeJsInteropMember(
+ FunctionElement element,
+ List<ir.Primitive> arguments,
+ SourceInformation sourceInformation) {
program.addNativeMethod(element);
String target = program.getJsInteropTargetPath(element);
// Strip off trailing arguments that were not specified.
@@ -2119,14 +2144,17 @@ class IrBuilder {
var args = new List.filled(inputs.length, '#').join(',');
code = element.isConstructor ? "new $target($args)" : "$target($args)";
}
- return buildForeignCode(js.js.parseForeignJS(code), inputs, behavior);
+ return buildForeignCode(js.js.parseForeignJS(code),
+ inputs, behavior, sourceInformation);
// TODO(sigmund): should we record the source-information here?
}
/// Builds an object literal that results from invoking a factory constructor
/// of a js-interop anonymous type.
- ir.Primitive buildJsInteropObjectLiteral(ConstructorElement constructor,
- List<ir.Primitive> arguments, {SourceInformation source}) {
+ ir.Primitive buildJsInteropObjectLiteral(
+ ConstructorElement constructor,
+ List<ir.Primitive> arguments,
+ SourceInformation sourceInformation) {
assert(program.isJsInteropAnonymous(constructor));
program.addNativeMethod(constructor);
FunctionSignature params = constructor.functionSignature;
@@ -2150,8 +2178,8 @@ class IrBuilder {
behavior.typesReturned.add(constructor.enclosingClass.thisType);
}
- // TODO(sigmund): should we record the source-information here?
- return buildForeignCode(code, filteredArguments, behavior);
+ return buildForeignCode(
+ code, filteredArguments, behavior, sourceInformation);
}
/// Create a blocks of [statements] by applying [build] to all reachable
@@ -2503,16 +2531,23 @@ class IrBuilder {
}
/// Create a read access of [local] function, variable, or parameter.
- ir.Primitive buildLocalGet(LocalElement local) {
+ // TODO(johnniwinther): Make [sourceInformation] mandatory.
+ ir.Primitive buildLocalGet(
+ LocalElement local,
+ {SourceInformation sourceInformation}) {
assert(isOpen);
ClosureLocation location = state.boxedVariables[local];
if (location != null) {
- ir.Primitive result = new ir.GetField(environment.lookup(location.box),
- location.field);
+ ir.Primitive result = new ir.GetField(
+ environment.lookup(location.box),
+ location.field,
+ sourceInformation: sourceInformation);
result.useElementAsHint(local);
return addPrimitive(result);
} else if (isInMutableVariable(local)) {
- return addPrimitive(new ir.GetMutable(getMutableVariable(local)));
+ return addPrimitive(
+ new ir.GetMutable(
+ getMutableVariable(local), sourceInformation: sourceInformation));
} else {
return environment.lookup(local);
}
@@ -2520,17 +2555,23 @@ class IrBuilder {
/// Create a write access to [local] variable or parameter with the provided
/// [value].
- ir.Primitive buildLocalVariableSet(LocalElement local, ir.Primitive value) {
+ ir.Primitive buildLocalVariableSet(
+ LocalElement local,
+ ir.Primitive value,
+ SourceInformation sourceInformation) {
assert(isOpen);
ClosureLocation location = state.boxedVariables[local];
if (location != null) {
addPrimitive(new ir.SetField(
environment.lookup(location.box),
location.field,
- value));
+ value,
+ sourceInformation: sourceInformation));
} else if (isInMutableVariable(local)) {
addPrimitive(new ir.SetMutable(
- getMutableVariable(local), value));
+ getMutableVariable(local),
+ value,
+ sourceInformation: sourceInformation));
} else {
value.useElementAsHint(local);
environment.update(local, value);
@@ -2589,23 +2630,38 @@ class IrBuilder {
return state.thisParameter;
}
- ir.Primitive buildFieldGet(ir.Primitive receiver, FieldElement target) {
+ ir.Primitive buildFieldGet(
+ ir.Primitive receiver,
+ FieldElement target,
+ SourceInformation sourceInformation) {
return addPrimitive(new ir.GetField(receiver, target,
+ sourceInformation: sourceInformation,
isFinal: program.fieldNeverChanges(target)));
}
void buildFieldSet(ir.Primitive receiver,
FieldElement target,
- ir.Primitive value) {
- addPrimitive(new ir.SetField(receiver, target, value));
+ ir.Primitive value,
+ SourceInformation sourceInformation) {
+ addPrimitive(new ir.SetField(
+ receiver, target, value, sourceInformation: sourceInformation));
}
- ir.Primitive buildSuperFieldGet(FieldElement target) {
- return addPrimitive(new ir.GetField(buildThis(), target));
+ ir.Primitive buildSuperFieldGet(
+ FieldElement target,
+ SourceInformation sourceInformation) {
+ return addPrimitive(
+ new ir.GetField(
+ buildThis(), target, sourceInformation: sourceInformation));
}
- ir.Primitive buildSuperFieldSet(FieldElement target, ir.Primitive value) {
- addPrimitive(new ir.SetField(buildThis(), target, value));
+ ir.Primitive buildSuperFieldSet(
+ FieldElement target,
+ ir.Primitive value,
+ SourceInformation sourceInformation) {
+ addPrimitive(
+ new ir.SetField(
+ buildThis(), target, value, sourceInformation: sourceInformation));
return value;
}
@@ -2642,10 +2698,10 @@ class IrBuilder {
ClassElement cls = element.enclosingClass;
if (program.isJsInterop(element)) {
if (program.isJsInteropAnonymous(element)) {
- return buildJsInteropObjectLiteral(element, arguments,
- source: sourceInformation);
+ return buildJsInteropObjectLiteral(
+ element, arguments, sourceInformation);
}
- return buildInvokeJsInteropMember(element, arguments);
+ return buildInvokeJsInteropMember(element, arguments, sourceInformation);
}
if (program.requiresRuntimeTypesFor(cls)) {
InterfaceType interface = type;
@@ -2731,6 +2787,7 @@ class IrBuilder {
ir.Primitive buildForeignCode(js.Template codeTemplate,
List<ir.Primitive> arguments,
NativeBehavior behavior,
+ SourceInformation sourceInformation,
{Element dependency,
TypeMask type}) {
assert(behavior != null);
@@ -2749,6 +2806,7 @@ class IrBuilder {
type,
arguments,
behavior,
+ sourceInformation,
dependency: dependency));
if (!codeTemplate.isExpression) {
// Close the term if this is a "throw" expression or native body.
@@ -2761,6 +2819,7 @@ class IrBuilder {
/// Creates a type test or type cast of [value] against [type].
ir.Primitive buildTypeOperator(ir.Primitive value,
DartType type,
+ SourceInformation sourceInformation,
{bool isTypeTest}) {
assert(isOpen);
assert(isTypeTest != null);
@@ -2772,7 +2831,8 @@ class IrBuilder {
ir.Primitive message = buildStringConstant(element.message);
return buildStaticFunctionInvocation(
program.throwTypeErrorHelper,
- <ir.Primitive>[message]);
+ <ir.Primitive>[message],
+ sourceInformation);
}
List<ir.Primitive> typeArguments = const <ir.Primitive>[];
@@ -2933,11 +2993,13 @@ class CatchClauseInfo {
final LocalVariableElement exceptionVariable;
final LocalVariableElement stackTraceVariable;
final SubbuildFunction buildCatchBlock;
+ final SourceInformation sourceInformation;
CatchClauseInfo({this.type,
this.exceptionVariable,
this.stackTraceVariable,
- this.buildCatchBlock});
+ this.buildCatchBlock,
+ this.sourceInformation});
}
class SwitchCaseInfo {
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698