Chromium Code Reviews| Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder_visitor.dart |
| diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_visitor.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_visitor.dart |
| index 492f1170833e9b4ae229a06f4d029581b42209d9..f4a17fedee73b5736f601ce629f62d704d535231 100644 |
| --- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_visitor.dart |
| +++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_visitor.dart |
| @@ -24,8 +24,10 @@ part of dart2js.ir_builder; |
| class IrBuilderTask extends CompilerTask { |
| final Map<Element, ir.ExecutableDefinition> nodes = |
| <Element, ir.ExecutableDefinition>{}; |
| + final bool generateSourceMap; |
| - IrBuilderTask(Compiler compiler) : super(compiler); |
| + IrBuilderTask(Compiler compiler, {this.generateSourceMap: true}) |
| + : super(compiler); |
| String get name => 'IR builder'; |
| @@ -37,27 +39,33 @@ class IrBuilderTask extends CompilerTask { |
| ir.ExecutableDefinition buildNode(AstElement element) { |
| if (!canBuild(element)) return null; |
| + |
| TreeElements elementsMapping = element.resolvedAst.elements; |
| element = element.implementation; |
| return compiler.withCurrentElement(element, () { |
| - SourceFile sourceFile = elementSourceFile(element); |
| + SourceInformationBuilder sourceInformationBuilder = generateSourceMap |
| + ? new PositionSourceInformationBuilder(element) |
| + : const SourceInformationBuilder(); |
| + |
| IrBuilderVisitor builder = |
| compiler.backend is JavaScriptBackend |
| - ? new JsIrBuilderVisitor(elementsMapping, compiler, sourceFile) |
| - : new DartIrBuilderVisitor(elementsMapping, compiler, sourceFile); |
| - return builder.buildExecutable(element); |
| + ? new JsIrBuilderVisitor( |
| + elementsMapping, compiler, sourceInformationBuilder) |
| + : new DartIrBuilderVisitor( |
| + elementsMapping, compiler, sourceInformationBuilder); |
| + ir.ExecutableDefinition definition = |
| + builder.buildExecutable(element); |
| + if (definition != null) { |
| + nodes[element] = definition; |
| + } |
| + return definition; |
| }); |
| } |
| void buildNodes() { |
| measure(() { |
| Set<Element> resolved = compiler.enqueuer.resolution.resolvedElements; |
| - resolved.forEach((AstElement element) { |
| - ir.ExecutableDefinition definition = buildNode(element); |
| - if (definition != null) { |
| - nodes[element] = definition; |
| - } |
| - }); |
| + resolved.forEach(buildNode); |
| }); |
| } |
| @@ -115,7 +123,7 @@ class _GetterElements { |
| abstract class IrBuilderVisitor extends ResolvedVisitor<ir.Primitive> |
| with IrBuilderMixin<ast.Node> { |
| final Compiler compiler; |
| - final SourceFile sourceFile; |
| + final SourceInformationBuilder sourceInformationBuilder; |
| // In SSA terms, join-point continuation parameters are the phis and the |
| // continuation invocation arguments are the corresponding phi inputs. To |
| @@ -136,7 +144,9 @@ abstract class IrBuilderVisitor extends ResolvedVisitor<ir.Primitive> |
| // arguments, and what the arguments are. |
| /// Construct a top-level visitor. |
| - IrBuilderVisitor(TreeElements elements, this.compiler, this.sourceFile) |
| + IrBuilderVisitor(TreeElements elements, |
| + this.compiler, |
| + this.sourceInformationBuilder) |
| : super(elements); |
| /** |
| @@ -653,7 +663,8 @@ abstract class IrBuilderVisitor extends ResolvedVisitor<ir.Primitive> |
| // so the vm can fail at runtime. |
| assert(selector.kind == SelectorKind.GETTER || |
| selector.kind == SelectorKind.SETTER); |
| - result = irBuilder.buildStaticGet(element, selector); |
| + result = irBuilder.buildStaticGet(element, selector, |
| + sourceInformation: sourceInformationBuilder.buildGet(node)); |
| } else if (Elements.isStaticOrTopLevelFunction(element)) { |
| // Convert a top-level or static function to a function object. |
| result = translateConstant(node); |
| @@ -752,7 +763,8 @@ abstract class IrBuilderVisitor extends ResolvedVisitor<ir.Primitive> |
| assert(element is FunctionElement); |
| List<ir.Primitive> arguments = node.arguments.mapToList(visit); |
| arguments = normalizeStaticArguments(selector, element, arguments); |
| - return irBuilder.buildStaticInvocation(element, selector, arguments); |
| + return irBuilder.buildStaticInvocation(element, selector, arguments, |
| + sourceInformation: sourceInformationBuilder.buildCall(node)); |
| } |
| } |
| @@ -1078,9 +1090,9 @@ class DartIrBuilderVisitor extends IrBuilderVisitor { |
| DartIrBuilder get irBuilder => super.irBuilder; |
| DartIrBuilderVisitor(TreeElements elements, |
| - Compiler compiler, |
| - SourceFile sourceFile) |
| - : super(elements, compiler, sourceFile); |
| + Compiler compiler, |
| + SourceInformationBuilder sourceInformationBuilder) |
| + : super(elements, compiler, sourceInformationBuilder); |
| DartIrBuilder makeIRBuilder(ast.Node node, ExecutableElement element) { |
| DartCapturedVariables closures = new DartCapturedVariables(elements); |
| @@ -1205,8 +1217,8 @@ class JsIrBuilderVisitor extends IrBuilderVisitor { |
| JsIrBuilderVisitor(TreeElements elements, |
| Compiler compiler, |
| - SourceFile sourceFile) |
| - : super(elements, compiler, sourceFile); |
| + SourceInformationBuilder sourceInformationBuilder) |
| + : super(elements, compiler, sourceInformationBuilder); |
| /// Builds the IR for creating an instance of the closure class corresponding |
| /// to the given nested function. |
| @@ -1317,7 +1329,7 @@ class JsIrBuilderVisitor extends IrBuilderVisitor { |
| JsIrBuilderVisitor visitor = new JsIrBuilderVisitor( |
| context.resolvedAst.elements, |
| compiler, |
| - elementSourceFile(context)); |
| + sourceInformationBuilder.forContext(context)); |
| return visitor.withBuilder(irBuilder, () => visitor.visit(expression)); |
| } |
| @@ -1329,7 +1341,7 @@ class JsIrBuilderVisitor extends IrBuilderVisitor { |
| JsIrBuilderVisitor visitor = new JsIrBuilderVisitor( |
| context.resolvedAst.elements, |
| compiler, |
| - elementSourceFile(context)); |
| + sourceInformationBuilder.forContext(context)); |
| return visitor.withBuilder(irBuilder, () => visitor.translateConstant(exp)); |
| } |
| @@ -1711,6 +1723,45 @@ class JsIrBuilderVisitor extends IrBuilderVisitor { |
| } |
| return result; |
| } |
| +} |
| + |
| +/// Interface for generating [SourceInformation] for the CPS. |
| +class SourceInformationBuilder { |
| + const SourceInformationBuilder(); |
| + |
| + /// Create a [SourceInformationBuilder] for [element]. |
| + SourceInformationBuilder forContext(AstElement element) => this; |
| + |
| + /// Generate [SourceInformation] for the read access in [node]. |
| + SourceInformation buildGet(ast.Node node) => null; |
|
floitsch
2015/02/24 19:58:12
The "build" reads redundant at the use-sites, but
|
| + /// Generate [SourceInformation] for the invocation in [node]. |
| + SourceInformation buildCall(ast.Node node) => null; |
| } |
| +/// [SourceInformationBuilder] that generates [PositionSourceInformation]. |
| +class PositionSourceInformationBuilder implements SourceInformationBuilder { |
| + final SourceFile sourceFile; |
| + final String name; |
| + |
| + PositionSourceInformationBuilder(AstElement element) |
| + : sourceFile = element.compilationUnit.script.file, |
| + name = element.name; |
| + |
| + @override |
| + SourceInformation buildGet(ast.Node node) { |
| + return new PositionSourceInformation( |
| + new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); |
| + } |
| + |
| + @override |
| + SourceInformation buildCall(ast.Node node) { |
| + return new PositionSourceInformation( |
| + new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); |
| + } |
| + |
| + @override |
| + SourceInformationBuilder forContext(AstElement element) { |
|
floitsch
2015/02/24 19:58:12
I'm not sure I like this. Is this just to avoid ha
Johnni Winther
2015/02/26 10:21:34
It is made to handle the choice of strategy at one
|
| + return new PositionSourceInformationBuilder(element); |
| + } |
| +} |