OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dart2js.ir_builder_task; | 5 library dart2js.ir_builder_task; |
6 | 6 |
7 import '../closure.dart' as closurelib; | 7 import '../closure.dart' as closurelib; |
8 import '../closure.dart' hide ClosureScope; | 8 import '../closure.dart' hide ClosureScope; |
9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 | 50 |
51 String get name => 'IR builder'; | 51 String get name => 'IR builder'; |
52 | 52 |
53 bool hasIr(Element element) => nodes.containsKey(element.implementation); | 53 bool hasIr(Element element) => nodes.containsKey(element.implementation); |
54 | 54 |
55 ir.ExecutableDefinition getIr(ExecutableElement element) { | 55 ir.ExecutableDefinition getIr(ExecutableElement element) { |
56 return nodes[element.implementation]; | 56 return nodes[element.implementation]; |
57 } | 57 } |
58 | 58 |
59 ir.ExecutableDefinition buildNode(AstElement element) { | 59 ir.ExecutableDefinition buildNode(AstElement element) { |
60 return measure(() => _buildNode(element)); | |
61 } | |
62 | |
63 ir.ExecutableDefinition _buildNode(AstElement element) { | |
60 if (!canBuild(element)) return null; | 64 if (!canBuild(element)) return null; |
61 | 65 |
62 TreeElements elementsMapping = element.resolvedAst.elements; | 66 TreeElements elementsMapping = element.resolvedAst.elements; |
63 element = element.implementation; | 67 element = element.implementation; |
64 return compiler.withCurrentElement(element, () { | 68 return compiler.withCurrentElement(element, () { |
65 SourceInformationBuilder sourceInformationBuilder = generateSourceMap | 69 SourceInformationBuilder sourceInformationBuilder = generateSourceMap |
66 ? new PositionSourceInformationBuilder(element) | 70 ? new PositionSourceInformationBuilder(element) |
67 : const SourceInformationBuilder(); | 71 : const SourceInformationBuilder(); |
68 | 72 |
69 IrBuilderVisitor builder = | 73 IrBuilderVisitor builder = |
70 compiler.backend is JavaScriptBackend | 74 compiler.backend is JavaScriptBackend |
71 ? new JsIrBuilderVisitor( | 75 ? new JsIrBuilderVisitor( |
72 elementsMapping, compiler, sourceInformationBuilder) | 76 elementsMapping, compiler, sourceInformationBuilder) |
73 : new DartIrBuilderVisitor( | 77 : new DartIrBuilderVisitor( |
74 elementsMapping, compiler, sourceInformationBuilder); | 78 elementsMapping, compiler, sourceInformationBuilder); |
75 ir.ExecutableDefinition definition = | 79 ir.ExecutableDefinition definition = |
76 builder.buildExecutable(element); | 80 builder.buildExecutable(element); |
77 if (definition != null) { | 81 if (definition != null) { |
78 nodes[element] = definition; | 82 nodes[element] = definition; |
79 } | 83 } |
80 return definition; | 84 return definition; |
81 }); | 85 }); |
82 } | 86 } |
83 | 87 |
84 void buildNodes() { | 88 void buildNodes() { |
85 measure(() { | 89 measure(() { |
86 Set<Element> resolved = compiler.enqueuer.resolution.resolvedElements; | 90 Set<Element> resolved = compiler.enqueuer.resolution.resolvedElements; |
87 resolved.forEach(buildNode); | 91 resolved.forEach(_buildNode); |
88 }); | 92 }); |
89 } | 93 } |
90 | 94 |
91 bool canBuild(Element element) { | 95 bool canBuild(Element element) { |
92 if (element is TypedefElement) return false; | 96 if (element is TypedefElement) return false; |
93 if (element is FunctionElement) { | 97 if (element is FunctionElement) { |
94 // TODO(sigurdm): Support native functions for dart2js. | 98 // TODO(sigurdm): Support native functions for dart2js. |
95 assert(invariant(element, !element.isNative)); | 99 assert(invariant(element, !element.isNative)); |
96 | 100 |
97 if (element is ConstructorElement) { | 101 if (element is ConstructorElement) { |
(...skipping 2363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2461 | 2465 |
2462 return withBuilder(builder, () { | 2466 return withBuilder(builder, () { |
2463 irBuilder.buildConstructorBodyHeader(getConstructorBodyParameters(body), | 2467 irBuilder.buildConstructorBodyHeader(getConstructorBodyParameters(body), |
2464 getClosureScopeForNode(node)); | 2468 getClosureScopeForNode(node)); |
2465 visit(node.body); | 2469 visit(node.body); |
2466 return irBuilder.makeFunctionDefinition([]); | 2470 return irBuilder.makeFunctionDefinition([]); |
2467 }); | 2471 }); |
2468 } | 2472 } |
2469 | 2473 |
2470 ir.FunctionDefinition buildFunction(FunctionElement element) { | 2474 ir.FunctionDefinition buildFunction(FunctionElement element) { |
2475 Selector selector = new Selector.fromElement(element); | |
Kevin Millikin (Google)
2015/03/26 15:14:16
Inadvertent change? selector is only used in the
| |
2476 //if (glue.isInterceptedSelector(selector)) { | |
2471 assert(invariant(element, element.isImplementation)); | 2477 assert(invariant(element, element.isImplementation)); |
2472 ast.FunctionExpression node = element.node; | 2478 ast.FunctionExpression node = element.node; |
2473 | 2479 |
2474 assert(!element.isSynthesized); | 2480 assert(!element.isSynthesized); |
2475 assert(node != null); | 2481 assert(node != null); |
2476 assert(elements[node] != null); | 2482 assert(elements[node] != null); |
2477 | 2483 |
2478 closureMap = compiler.closureToClassMapper.computeClosureToClassMapping( | 2484 closureMap = compiler.closureToClassMapper.computeClosureToClassMapping( |
2479 element, | 2485 element, |
2480 node, | 2486 node, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2603 SourceInformation buildCall(ast.Node node) { | 2609 SourceInformation buildCall(ast.Node node) { |
2604 return new PositionSourceInformation( | 2610 return new PositionSourceInformation( |
2605 new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); | 2611 new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); |
2606 } | 2612 } |
2607 | 2613 |
2608 @override | 2614 @override |
2609 SourceInformationBuilder forContext(AstElement element) { | 2615 SourceInformationBuilder forContext(AstElement element) { |
2610 return new PositionSourceInformationBuilder(element); | 2616 return new PositionSourceInformationBuilder(element); |
2611 } | 2617 } |
2612 } | 2618 } |
OLD | NEW |