Index: pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart |
diff --git a/pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart |
index 4b47e8c38351cc96584d70dae93d94e98bb379ba..0edf49ffcc62184d2b1f386dfec538aef98c3455 100644 |
--- a/pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart |
+++ b/pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart |
@@ -6,7 +6,7 @@ library dart2js.js_emitter.parameter_stub_generator; |
import '../closure.dart' show ClosureClassElement; |
import '../common.dart'; |
-import '../compiler.dart' show Compiler; |
+import '../common_elements.dart'; |
import '../constants/values.dart'; |
import '../elements/elements.dart' |
show |
@@ -17,11 +17,15 @@ import '../elements/elements.dart' |
ParameterElement; |
import '../js/js.dart' as jsAst; |
import '../js/js.dart' show js; |
-import '../js_backend/js_backend.dart' |
- show JavaScriptBackend, JavaScriptConstantCompiler, Namer; |
+import '../js_backend/constant_handler_javascript.dart' |
+ show JavaScriptConstantCompiler; |
+import '../js_backend/namer.dart' show Namer; |
+import '../js_backend/native_data.dart'; |
+import '../js_backend/interceptor_data.dart'; |
import '../universe/call_structure.dart' show CallStructure; |
import '../universe/selector.dart' show Selector; |
-import '../universe/world_builder.dart' show SelectorConstraints; |
+import '../universe/world_builder.dart' |
+ show CodegenWorldBuilder, SelectorConstraints; |
import '../world.dart' show ClosedWorld; |
import 'model.dart'; |
@@ -31,20 +35,29 @@ import 'code_emitter_task.dart' show CodeEmitterTask, Emitter; |
class ParameterStubGenerator { |
static final Set<Selector> emptySelectorSet = new Set<Selector>(); |
- final Namer namer; |
- final Compiler compiler; |
- final JavaScriptBackend backend; |
- final ClosedWorld closedWorld; |
+ final CommonElements _commonElements; |
+ final CodeEmitterTask _emitterTask; |
+ final JavaScriptConstantCompiler _constants; |
+ final Namer _namer; |
+ final NativeData _nativeData; |
+ final InterceptorData _interceptorData; |
+ final CodegenWorldBuilder _codegenWorldBuilder; |
+ final ClosedWorld _closedWorld; |
ParameterStubGenerator( |
- this.compiler, this.namer, this.backend, this.closedWorld); |
+ this._commonElements, |
+ this._emitterTask, |
+ this._constants, |
+ this._namer, |
+ this._nativeData, |
+ this._interceptorData, |
+ this._codegenWorldBuilder, |
+ this._closedWorld); |
- Emitter get emitter => backend.emitter.emitter; |
- CodeEmitterTask get emitterTask => backend.emitter; |
- DiagnosticReporter get reporter => compiler.reporter; |
+ Emitter get _emitter => _emitterTask.emitter; |
bool needsSuperGetter(FunctionElement element) => |
- compiler.codegenWorldBuilder.methodsNeedingSuperGetter.contains(element); |
+ _codegenWorldBuilder.methodsNeedingSuperGetter.contains(element); |
/** |
* Generates stubs to handle invocation of methods with optional |
@@ -78,11 +91,9 @@ class ParameterStubGenerator { |
// directly. |
return null; |
} |
- JavaScriptConstantCompiler handler = backend.constants; |
List<String> names = callStructure.getOrderedNamedArguments(); |
- bool isInterceptedMethod = |
- backend.interceptorData.isInterceptedMethod(member); |
+ bool isInterceptedMethod = _interceptorData.isInterceptedMethod(member); |
// If the method is intercepted, we need to also pass the actual receiver. |
int extraArgumentCount = isInterceptedMethod ? 1 : 0; |
@@ -110,7 +121,7 @@ class ParameterStubGenerator { |
int indexOfLastOptionalArgumentInParameters = optionalParameterStart - 1; |
parameters.orderedForEachParameter((ParameterElement element) { |
- String jsName = backend.namer.safeVariableName(element.name); |
+ String jsName = _namer.safeVariableName(element.name); |
assert(jsName != receiverArgumentName); |
if (count < optionalParameterStart) { |
parametersBuffer[count] = new jsAst.Parameter(jsName); |
@@ -125,17 +136,17 @@ class ParameterStubGenerator { |
parametersBuffer[optionalParameterStart + index] = |
new jsAst.Parameter(jsName); |
} else { |
- ConstantValue value = handler.getConstantValue(element.constant); |
+ ConstantValue value = _constants.getConstantValue(element.constant); |
if (value == null) { |
argumentsBuffer[count] = |
- emitter.constantReference(new NullConstantValue()); |
+ _emitter.constantReference(new NullConstantValue()); |
} else { |
if (!value.isNull) { |
// If the value is the null constant, we should not pass it |
// down to the native method. |
indexOfLastOptionalArgumentInParameters = count; |
} |
- argumentsBuffer[count] = emitter.constantReference(value); |
+ argumentsBuffer[count] = _emitter.constantReference(value); |
} |
} |
} |
@@ -143,42 +154,41 @@ class ParameterStubGenerator { |
}); |
var body; // List or jsAst.Statement. |
- if (backend.nativeData.hasFixedBackendName(member)) { |
- body = emitterTask.nativeEmitter.generateParameterStubStatements( |
+ if (_nativeData.hasFixedBackendName(member)) { |
+ body = _emitterTask.nativeEmitter.generateParameterStubStatements( |
member, |
isInterceptedMethod, |
- namer.invocationName(selector), |
+ _namer.invocationName(selector), |
parametersBuffer, |
argumentsBuffer, |
indexOfLastOptionalArgumentInParameters); |
} else if (member.isInstanceMember) { |
if (needsSuperGetter(member)) { |
ClassElement superClass = member.enclosingClass; |
- jsAst.Name methodName = namer.instanceMethodName(member); |
+ jsAst.Name methodName = _namer.instanceMethodName(member); |
// When redirecting, we must ensure that we don't end up in a subclass. |
// We thus can't just invoke `this.foo$1.call(filledInArguments)`. |
// Instead we need to call the statically resolved target. |
// `<class>.prototype.bar$1.call(this, argument0, ...)`. |
body = js.statement('return #.#.call(this, #);', [ |
- backend.emitter |
- .prototypeAccess(superClass, hasBeenInstantiated: true), |
+ _emitterTask.prototypeAccess(superClass, hasBeenInstantiated: true), |
methodName, |
argumentsBuffer |
]); |
} else { |
body = js.statement('return this.#(#);', |
- [namer.instanceMethodName(member), argumentsBuffer]); |
+ [_namer.instanceMethodName(member), argumentsBuffer]); |
} |
} else { |
body = js.statement('return #(#)', |
- [emitter.staticFunctionAccess(member), argumentsBuffer]); |
+ [_emitter.staticFunctionAccess(member), argumentsBuffer]); |
} |
jsAst.Fun function = js('function(#) { #; }', [parametersBuffer, body]); |
- jsAst.Name name = member.isStatic ? null : namer.invocationName(selector); |
+ jsAst.Name name = member.isStatic ? null : _namer.invocationName(selector); |
jsAst.Name callName = |
- (callSelector != null) ? namer.invocationName(callSelector) : null; |
+ (callSelector != null) ? _namer.invocationName(callSelector) : null; |
return new ParameterStubMethod(name, callName, function); |
} |
@@ -217,11 +227,13 @@ class ParameterStubGenerator { |
{bool canTearOff: true}) { |
if (member.enclosingElement.isClosure) { |
ClosureClassElement cls = member.enclosingElement; |
- if (cls.supertype.element == backend.commonElements.boundClosureClass) { |
- reporter.internalError(cls.methodElement, 'Bound closure1.'); |
+ if (cls.supertype.element == _commonElements.boundClosureClass) { |
+ throw new SpannableAssertionFailure( |
+ cls.methodElement, 'Bound closure1.'); |
} |
if (cls.methodElement.isInstanceMember) { |
- reporter.internalError(cls.methodElement, 'Bound closure2.'); |
+ throw new SpannableAssertionFailure( |
+ cls.methodElement, 'Bound closure2.'); |
} |
} |
@@ -239,12 +251,12 @@ class ParameterStubGenerator { |
// Only instance members (not static methods) need stubs. |
if (member.isInstanceMember) { |
- selectors = compiler.codegenWorldBuilder.invocationsByName(member.name); |
+ selectors = _codegenWorldBuilder.invocationsByName(member.name); |
} |
if (canTearOff) { |
- String call = namer.closureInvocationSelectorName; |
- callSelectors = compiler.codegenWorldBuilder.invocationsByName(call); |
+ String call = _namer.closureInvocationSelectorName; |
+ callSelectors = _codegenWorldBuilder.invocationsByName(call); |
} |
assert(emptySelectorSet.isEmpty); |
@@ -294,7 +306,7 @@ class ParameterStubGenerator { |
for (Selector selector in selectors.keys) { |
if (renamedCallSelectors.contains(selector)) continue; |
if (!selector.appliesUnnamed(member)) continue; |
- if (!selectors[selector].applies(member, selector, closedWorld)) { |
+ if (!selectors[selector].applies(member, selector, _closedWorld)) { |
continue; |
} |