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 40ed4ccd2ffd8b9e48af788ef03b2e50e4984a38..bcf70e244520b49af7084ecfaf1cee6dcd485032 100644 |
--- a/pkg/compiler/lib/src/ssa/builder.dart |
+++ b/pkg/compiler/lib/src/ssa/builder.dart |
@@ -60,10 +60,12 @@ class SsaBuilderTask extends CompilerTask { |
backend = backend, |
super(backend.compiler); |
+ DiagnosticReporter get reporter => compiler.reporter; |
+ |
HGraph build(CodegenWorkItem work) { |
return measure(() { |
Element element = work.element.implementation; |
- return compiler.withCurrentElement(element, () { |
+ return reporter.withCurrentElement(element, () { |
HInstruction.idCounter = 0; |
SsaBuilder builder = |
new SsaBuilder( |
@@ -86,7 +88,7 @@ class SsaBuilderTask extends CompilerTask { |
graph = builder.buildLazyInitializer(element); |
} |
} else { |
- compiler.internalError(element, 'Unexpected element kind $kind.'); |
+ reporter.internalError(element, 'Unexpected element kind $kind.'); |
} |
assert(graph.isValid()); |
if (!identical(kind, ElementKind.FIELD)) { |
@@ -439,10 +441,10 @@ class LocalsHandler { |
if (isAccessedDirectly(local)) { |
if (directLocals[local] == null) { |
if (local is TypeVariableElement) { |
- builder.compiler.internalError(builder.compiler.currentElement, |
+ builder.reporter.internalError(builder.compiler.currentElement, |
"Runtime type information not available for $local."); |
} else { |
- builder.compiler.internalError(local, |
+ builder.reporter.internalError(local, |
"Cannot find value $local."); |
} |
} |
@@ -792,17 +794,17 @@ abstract class JumpHandler { |
// used as the target of a break, and therefore doesn't need a break |
// handler associated with it. |
class NullJumpHandler implements JumpHandler { |
- final Compiler compiler; |
+ final DiagnosticReporter reporter; |
- NullJumpHandler(this.compiler); |
+ NullJumpHandler(this.reporter); |
void generateBreak([LabelDefinition label]) { |
- compiler.internalError(CURRENT_ELEMENT_SPANNABLE, |
+ reporter.internalError(CURRENT_ELEMENT_SPANNABLE, |
'NullJumpHandler.generateBreak should not be called.'); |
} |
void generateContinue([LabelDefinition label]) { |
- compiler.internalError(CURRENT_ELEMENT_SPANNABLE, |
+ reporter.internalError(CURRENT_ELEMENT_SPANNABLE, |
'NullJumpHandler.generateContinue should not be called.'); |
} |
@@ -1105,6 +1107,9 @@ class SsaBuilder extends ast.Visitor |
work.element.implementation); |
} |
+ |
+ DiagnosticReporter get reporter => compiler.reporter; |
+ |
// TODO(johnniwinther): Avoid the need for this. |
Resolution get resolution => compiler.resolution; |
@@ -1496,7 +1501,7 @@ class SsaBuilder extends ast.Visitor |
inlinedFrom(Element element, f()) { |
assert(element is FunctionElement || element is VariableElement); |
- return compiler.withCurrentElement(element, () { |
+ return reporter.withCurrentElement(element, () { |
// The [sourceElementStack] contains declaration elements. |
SourceInformationBuilder oldSourceInformationBuilder = |
sourceInformationBuilder; |
@@ -1868,7 +1873,7 @@ class SsaBuilder extends ast.Visitor |
Map<Element, HInstruction> fieldValues, |
FunctionElement caller) { |
callee = callee.implementation; |
- compiler.withCurrentElement(callee, () { |
+ reporter.withCurrentElement(callee, () { |
constructors.add(callee); |
ClassElement enclosingClass = callee.enclosingClass; |
if (backend.classNeedsRti(enclosingClass)) { |
@@ -1983,7 +1988,7 @@ class SsaBuilder extends ast.Visitor |
// forwarding constructor in a mixin application did not match the |
// constructor (which, for example, may happen when the libraries are |
// not compatible for private names, see issue 20394). |
- compiler.internalError(constructor, |
+ reporter.internalError(constructor, |
'forwarding constructor call does not match'); |
} |
inlineSuperOrRedirect( |
@@ -2045,7 +2050,7 @@ class SsaBuilder extends ast.Visitor |
// TODO(johnniwinther): Should we find injected constructors as well? |
FunctionElement target = superClass.lookupDefaultConstructor(); |
if (target == null) { |
- compiler.internalError(superClass, |
+ reporter.internalError(superClass, |
"No default constructor available."); |
} |
List<HInstruction> arguments = |
@@ -2075,7 +2080,7 @@ class SsaBuilder extends ast.Visitor |
classElement.forEachInstanceField( |
(ClassElement enclosingClass, VariableElement member) { |
if (compiler.elementHasCompileTimeError(member)) return; |
- compiler.withCurrentElement(member, () { |
+ reporter.withCurrentElement(member, () { |
TreeElements definitions = member.treeElements; |
ast.Node node = member.node; |
ast.Expression initializer = member.initializer; |
@@ -2663,19 +2668,19 @@ class SsaBuilder extends ast.Visitor |
if (!isReachable) { |
// The block has been aborted by a return or a throw. |
if (!stack.isEmpty) { |
- compiler.internalError(node, 'Non-empty instruction stack.'); |
+ reporter.internalError(node, 'Non-empty instruction stack.'); |
} |
return; |
} |
} |
assert(!current.isClosed()); |
if (!stack.isEmpty) { |
- compiler.internalError(node, 'Non-empty instruction stack.'); |
+ reporter.internalError(node, 'Non-empty instruction stack.'); |
} |
} |
visitClassNode(ast.ClassNode node) { |
- compiler.internalError(node, |
+ reporter.internalError(node, |
'SsaBuilder.visitClassNode should not be called.'); |
} |
@@ -3215,7 +3220,7 @@ class SsaBuilder extends ast.Visitor |
if (node.isThis()) { |
visitThisGet(node); |
} else { |
- compiler.internalError(node, |
+ reporter.internalError(node, |
"SsaFromAstMixin.visitIdentifier on non-this."); |
} |
} |
@@ -4078,7 +4083,7 @@ class SsaBuilder extends ast.Visitor |
// argument, which is the foreign code. |
if (link.isEmpty || link.tail.isEmpty) { |
// We should not get here because the call should be compiled to NSM. |
- compiler.internalError(node.argumentsNode, |
+ reporter.internalError(node.argumentsNode, |
'At least two arguments expected.'); |
} |
native.NativeBehavior nativeBehavior = |
@@ -4088,7 +4093,7 @@ class SsaBuilder extends ast.Visitor |
addGenericSendArgumentsToList(link.tail.tail, inputs); |
if (nativeBehavior.codeTemplate.positionalArgumentCount != inputs.length) { |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
node, MessageKind.GENERIC, |
{'text': |
'Mismatch between number of placeholders' |
@@ -4122,14 +4127,14 @@ class SsaBuilder extends ast.Visitor |
List<HInstruction> inputs = <HInstruction>[]; |
addGenericSendArgumentsToList(node.arguments, inputs); |
if (inputs.length != 2) { |
- compiler.internalError(node.argumentsNode, 'Two arguments expected.'); |
+ reporter.internalError(node.argumentsNode, 'Two arguments expected.'); |
} |
push(new HStringConcat(inputs[0], inputs[1], node, backend.stringType)); |
} |
void handleForeignJsCurrentIsolateContext(ast.Send node) { |
if (!node.arguments.isEmpty) { |
- compiler.internalError(node, |
+ reporter.internalError(node, |
'Too many arguments to JS_CURRENT_ISOLATE_CONTEXT.'); |
} |
@@ -4146,7 +4151,7 @@ class SsaBuilder extends ast.Visitor |
// Leg's isolate. |
Element element = backend.isolateHelperLibrary.find('_currentIsolate'); |
if (element == null) { |
- compiler.internalError(node, |
+ reporter.internalError(node, |
'Isolate library and compiler mismatch.'); |
} |
pushInvokeStatic(null, element, [], typeMask: backend.dynamicType); |
@@ -4158,7 +4163,7 @@ class SsaBuilder extends ast.Visitor |
ast.Node argument; |
switch (arguments.length) { |
case 0: |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
node, MessageKind.GENERIC, |
{'text': 'Error: Expected one argument to JS_GET_FLAG.'}); |
return; |
@@ -4167,7 +4172,7 @@ class SsaBuilder extends ast.Visitor |
break; |
default: |
for (int i = 1; i < arguments.length; i++) { |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
arguments[i], MessageKind.GENERIC, |
{'text': 'Error: Extra argument to JS_GET_FLAG.'}); |
} |
@@ -4175,7 +4180,7 @@ class SsaBuilder extends ast.Visitor |
} |
ast.LiteralString string = argument.asLiteralString(); |
if (string == null) { |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
argument, MessageKind.GENERIC, |
{'text': 'Error: Expected a literal string.'}); |
} |
@@ -4189,7 +4194,7 @@ class SsaBuilder extends ast.Visitor |
value = compiler.useContentSecurityPolicy; |
break; |
default: |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
node, MessageKind.GENERIC, |
{'text': 'Error: Unknown internal flag "$name".'}); |
} |
@@ -4201,7 +4206,7 @@ class SsaBuilder extends ast.Visitor |
ast.Node argument; |
switch (arguments.length) { |
case 0: |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
node, MessageKind.GENERIC, |
{'text': 'Error: Expected one argument to JS_GET_NAME.'}); |
return; |
@@ -4210,7 +4215,7 @@ class SsaBuilder extends ast.Visitor |
break; |
default: |
for (int i = 1; i < arguments.length; i++) { |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
arguments[i], MessageKind.GENERIC, |
{'text': 'Error: Extra argument to JS_GET_NAME.'}); |
} |
@@ -4220,7 +4225,7 @@ class SsaBuilder extends ast.Visitor |
if (element == null || |
element is! FieldElement || |
element.enclosingClass != backend.jsGetNameEnum) { |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
argument, MessageKind.GENERIC, |
{'text': 'Error: Expected a JsGetName enum value.'}); |
} |
@@ -4236,7 +4241,7 @@ class SsaBuilder extends ast.Visitor |
List<ast.Node> arguments = node.arguments.toList(); |
ast.Node argument; |
if (arguments.length < 2) { |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
node, MessageKind.GENERIC, |
{'text': 'Error: Expected at least two arguments to JS_BUILTIN.'}); |
} |
@@ -4245,7 +4250,7 @@ class SsaBuilder extends ast.Visitor |
if (builtinElement == null || |
(builtinElement is! FieldElement) || |
builtinElement.enclosingClass != backend.jsBuiltinEnum) { |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
argument, MessageKind.GENERIC, |
{'text': 'Error: Expected a JsBuiltin enum value.'}); |
} |
@@ -4279,7 +4284,7 @@ class SsaBuilder extends ast.Visitor |
switch (arguments.length) { |
case 0: |
case 1: |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
node, MessageKind.GENERIC, |
{'text': 'Error: Expected two arguments to JS_EMBEDDED_GLOBAL.'}); |
return; |
@@ -4290,7 +4295,7 @@ class SsaBuilder extends ast.Visitor |
break; |
default: |
for (int i = 2; i < arguments.length; i++) { |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
arguments[i], MessageKind.GENERIC, |
{'text': 'Error: Extra argument to JS_EMBEDDED_GLOBAL.'}); |
} |
@@ -4299,7 +4304,7 @@ class SsaBuilder extends ast.Visitor |
visit(globalNameNode); |
HInstruction globalNameHNode = pop(); |
if (!globalNameHNode.isConstantString()) { |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
arguments[1], MessageKind.GENERIC, |
{'text': 'Error: Expected String as second argument ' |
'to JS_EMBEDDED_GLOBAL.'}); |
@@ -4336,7 +4341,7 @@ class SsaBuilder extends ast.Visitor |
} |
} |
} |
- compiler.reportErrorMessage( |
+ reporter.reportErrorMessage( |
node, |
MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT); |
stack.add(graph.addConstantNull(compiler)); |
@@ -4355,7 +4360,7 @@ class SsaBuilder extends ast.Visitor |
// Call a helper method from the isolate library. |
Element element = backend.isolateHelperLibrary.find('_callInIsolate'); |
if (element == null) { |
- compiler.internalError(node, |
+ reporter.internalError(node, |
'Isolate library and compiler mismatch.'); |
} |
List<HInstruction> inputs = <HInstruction>[]; |
@@ -4366,13 +4371,13 @@ class SsaBuilder extends ast.Visitor |
FunctionSignature handleForeignRawFunctionRef(ast.Send node, String name) { |
if (node.arguments.isEmpty || !node.arguments.tail.isEmpty) { |
- compiler.internalError(node.argumentsNode, |
+ reporter.internalError(node.argumentsNode, |
'"$name" requires exactly one argument.'); |
} |
ast.Node closure = node.arguments.head; |
Element element = elements[closure]; |
if (!Elements.isStaticOrTopLevelFunction(element)) { |
- compiler.internalError(closure, |
+ reporter.internalError(closure, |
'"$name" requires a static or top-level method.'); |
} |
FunctionElement function = element; |
@@ -4382,7 +4387,7 @@ class SsaBuilder extends ast.Visitor |
FunctionElement implementation = function.implementation; |
FunctionSignature params = implementation.functionSignature; |
if (params.optionalParameterCount != 0) { |
- compiler.internalError(closure, |
+ reporter.internalError(closure, |
'"$name" does not handle closure with optional parameters.'); |
} |
@@ -4405,7 +4410,7 @@ class SsaBuilder extends ast.Visitor |
void handleForeignJsSetStaticState(ast.Send node) { |
if (node.arguments.isEmpty || !node.arguments.tail.isEmpty) { |
- compiler.internalError(node.argumentsNode, |
+ reporter.internalError(node.argumentsNode, |
'Exactly one argument required.'); |
} |
visit(node.arguments.head); |
@@ -4422,7 +4427,7 @@ class SsaBuilder extends ast.Visitor |
void handleForeignJsGetStaticState(ast.Send node) { |
if (!node.arguments.isEmpty) { |
- compiler.internalError(node.argumentsNode, 'Too many arguments.'); |
+ reporter.internalError(node.argumentsNode, 'Too many arguments.'); |
} |
push(new HForeignCode(js.js.parseForeignJS(backend.namer.staticStateHolder), |
backend.dynamicType, |
@@ -4460,7 +4465,7 @@ class SsaBuilder extends ast.Visitor |
} else if (name == 'JS_STRING_CONCAT') { |
handleJsStringConcat(node); |
} else { |
- compiler.internalError(node, "Unknown foreign: ${element}"); |
+ reporter.internalError(node, "Unknown foreign: ${element}"); |
} |
} |
@@ -4887,7 +4892,7 @@ class SsaBuilder extends ast.Visitor |
type.element, |
sourceInformation: sourceInformation); |
} else { |
- compiler.internalError(type.element, |
+ reporter.internalError(type.element, |
'Unexpected type variable in static context.'); |
return null; |
} |
@@ -5574,7 +5579,7 @@ class SsaBuilder extends ast.Visitor |
// TODO(antonm): migrate rest of SsaFromAstMixin to internalError. |
internalError(Spannable node, String reason) { |
- compiler.internalError(node, reason); |
+ reporter.internalError(node, reason); |
} |
void generateError(ast.Node node, String message, Element helper) { |
@@ -6894,7 +6899,7 @@ class SsaBuilder extends ast.Visitor |
visitNodeList(ast.NodeList node) { |
for (Link<ast.Node> link = node.nodes; !link.isEmpty; link = link.tail) { |
if (isAborted()) { |
- compiler.reportHintMessage( |
+ reporter.reportHintMessage( |
link.head, |
MessageKind.GENERIC, |
{'text': 'dead code'}); |
@@ -6910,7 +6915,7 @@ class SsaBuilder extends ast.Visitor |
visitOperator(ast.Operator node) { |
// Operators are intercepted in their surrounding Send nodes. |
- compiler.internalError(node, |
+ reporter.internalError(node, |
'SsaBuilder.visitOperator should not be called.'); |
} |
@@ -6937,7 +6942,7 @@ class SsaBuilder extends ast.Visitor |
HInstruction exception = rethrowableException; |
if (exception == null) { |
exception = graph.addConstantNull(compiler); |
- compiler.internalError(node, |
+ reporter.internalError(node, |
'rethrowableException should not be null.'); |
} |
handleInTryStatement(); |
@@ -7062,7 +7067,7 @@ class SsaBuilder extends ast.Visitor |
} |
visitTypeAnnotation(ast.TypeAnnotation node) { |
- compiler.internalError(node, |
+ reporter.internalError(node, |
'Visiting type annotation in SSA builder.'); |
} |
@@ -7138,7 +7143,7 @@ class SsaBuilder extends ast.Visitor |
visitStringInterpolationPart(ast.StringInterpolationPart node) { |
// The parts are iterated in visitStringInterpolation. |
- compiler.internalError(node, |
+ reporter.internalError(node, |
'SsaBuilder.visitStringInterpolation should not be called.'); |
} |
@@ -7193,7 +7198,7 @@ class SsaBuilder extends ast.Visitor |
JumpTarget element = elements.getTargetDefinition(node); |
if (element == null || !identical(element.statement, node)) { |
// No breaks or continues to this node. |
- return new NullJumpHandler(compiler); |
+ return new NullJumpHandler(reporter); |
} |
if (isLoopJump && node is ast.SwitchStatement) { |
// Create a special jump handler for loops created for switch statements |
@@ -7460,7 +7465,7 @@ class SsaBuilder extends ast.Visitor |
} |
visitLabel(ast.Label node) { |
- compiler.internalError(node, 'SsaFromAstMixin.visitLabel.'); |
+ reporter.internalError(node, 'SsaFromAstMixin.visitLabel.'); |
} |
visitLabeledStatement(ast.LabeledStatement node) { |
@@ -7790,7 +7795,7 @@ class SsaBuilder extends ast.Visitor |
// is not the generated switch statement but instead the loop generated |
// in the call to [handleLoop] below. |
handleSwitch(node, |
- new NullJumpHandler(compiler), |
+ new NullJumpHandler(reporter), |
buildExpression, node.cases, getConstants, |
(_) => false, // No case is default. |
buildSwitchCase); |
@@ -7957,11 +7962,11 @@ class SsaBuilder extends ast.Visitor |
} |
visitSwitchCase(ast.SwitchCase node) { |
- compiler.internalError(node, 'SsaFromAstMixin.visitSwitchCase.'); |
+ reporter.internalError(node, 'SsaFromAstMixin.visitSwitchCase.'); |
} |
visitCaseMatch(ast.CaseMatch node) { |
- compiler.internalError(node, 'SsaFromAstMixin.visitCaseMatch.'); |
+ reporter.internalError(node, 'SsaFromAstMixin.visitCaseMatch.'); |
} |
/// Calls [buildTry] inside a synthetic try block with [buildFinally] in the |
@@ -8112,7 +8117,7 @@ class SsaBuilder extends ast.Visitor |
if (catchBlock.onKeyword != null) { |
DartType type = elements.getType(catchBlock.type); |
if (type == null) { |
- compiler.internalError(catchBlock.type, 'On with no type.'); |
+ reporter.internalError(catchBlock.type, 'On with no type.'); |
} |
HInstruction condition = |
buildIsNode(catchBlock.type, type, unwrappedException); |
@@ -8130,7 +8135,7 @@ class SsaBuilder extends ast.Visitor |
// condition. |
DartType type = elements.getType(declaration.type); |
if (type == null) { |
- compiler.internalError(catchBlock, 'Catch with unresolved type.'); |
+ reporter.internalError(catchBlock, 'Catch with unresolved type.'); |
} |
condition = buildIsNode(declaration.type, type, unwrappedException); |
push(condition); |
@@ -8269,7 +8274,7 @@ class SsaBuilder extends ast.Visitor |
} |
visitTypeVariable(ast.TypeVariable node) { |
- compiler.internalError(node, 'SsaFromAstMixin.visitTypeVariable.'); |
+ reporter.internalError(node, 'SsaFromAstMixin.visitTypeVariable.'); |
} |
/** |
@@ -8406,7 +8411,7 @@ class StringBuilderVisitor extends ast.Visitor { |
} |
visitNode(ast.Node node) { |
- builder.compiler.internalError(node, 'Unexpected node.'); |
+ builder.reporter.internalError(node, 'Unexpected node.'); |
} |
void visitExpression(ast.Node node) { |