| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Generate code using the cps-based IR pipeline. | 5 /// Generate code using the cps-based IR pipeline. |
| 6 library code_generator_task; | 6 library code_generator_task; |
| 7 | 7 |
| 8 import 'glue.dart'; | 8 import 'glue.dart'; |
| 9 import 'codegen.dart'; | 9 import 'codegen.dart'; |
| 10 import 'unsugar.dart'; | 10 import 'unsugar.dart'; |
| 11 | 11 |
| 12 import '../js_backend.dart'; | 12 import '../js_backend.dart'; |
| 13 import '../../dart2jslib.dart'; | 13 import '../../dart2jslib.dart'; |
| 14 import '../../io/source_file.dart'; | |
| 15 import '../../cps_ir/cps_ir_nodes.dart' as cps; | 14 import '../../cps_ir/cps_ir_nodes.dart' as cps; |
| 16 import '../../cps_ir/cps_ir_builder.dart'; | 15 import '../../cps_ir/cps_ir_builder.dart'; |
| 17 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; | 16 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; |
| 18 import '../../tree/tree.dart' as ast; | |
| 19 import '../../types/types.dart' show TypeMask, UnionTypeMask, FlatTypeMask, | 17 import '../../types/types.dart' show TypeMask, UnionTypeMask, FlatTypeMask, |
| 20 ForwardingTypeMask; | 18 ForwardingTypeMask; |
| 21 import '../../scanner/scannerlib.dart' as scanner; | |
| 22 import '../../elements/elements.dart'; | 19 import '../../elements/elements.dart'; |
| 23 import '../../js/js.dart' as js; | 20 import '../../js/js.dart' as js; |
| 24 import '../../io/source_map_builder.dart'; | 21 import '../../io/source_information.dart' show StartEndSourceInformation; |
| 25 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; | 22 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; |
| 26 import '../../dart_backend/backend_ast_emitter.dart' as backend_ast_emitter; | 23 import '../../dart_backend/backend_ast_emitter.dart' as backend_ast_emitter; |
| 27 import '../../cps_ir/optimizers.dart'; | 24 import '../../cps_ir/optimizers.dart'; |
| 28 import '../../tracer.dart'; | 25 import '../../tracer.dart'; |
| 29 import '../../js_backend/codegen/codegen.dart'; | 26 import '../../js_backend/codegen/codegen.dart'; |
| 30 import '../../ssa/ssa.dart' as ssa; | 27 import '../../ssa/ssa.dart' as ssa; |
| 31 import '../../tree_ir/optimization/optimization.dart'; | 28 import '../../tree_ir/optimization/optimization.dart'; |
| 32 import '../../cps_ir/cps_ir_nodes_sexpr.dart'; | 29 import '../../cps_ir/cps_ir_nodes_sexpr.dart'; |
| 33 import 'js_tree_builder.dart'; | 30 import 'js_tree_builder.dart'; |
| 34 | 31 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 197 |
| 201 return attachPosition(codeGen.buildFunction(definition), work.element); | 198 return attachPosition(codeGen.buildFunction(definition), work.element); |
| 202 } | 199 } |
| 203 | 200 |
| 204 Iterable<CompilerTask> get tasks { | 201 Iterable<CompilerTask> get tasks { |
| 205 // TODO(sigurdm): Make a better list of tasks. | 202 // TODO(sigurdm): Make a better list of tasks. |
| 206 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); | 203 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); |
| 207 } | 204 } |
| 208 | 205 |
| 209 js.Node attachPosition(js.Node node, AstElement element) { | 206 js.Node attachPosition(js.Node node, AstElement element) { |
| 210 // TODO(sra): Attaching positions might be cleaner if the source position | 207 return node.withSourceInformation( |
| 211 // was on a wrapping node. | 208 StartEndSourceInformation.computeSourceInformation(element)); |
| 212 SourceFile sourceFile = sourceFileOfElement(element); | |
| 213 String name = element.name; | |
| 214 AstElement implementation = element.implementation; | |
| 215 ast.Node expression = implementation.node; | |
| 216 scanner.Token beginToken; | |
| 217 scanner.Token endToken; | |
| 218 if (expression == null) { | |
| 219 // Synthesized node. Use the enclosing element for the location. | |
| 220 beginToken = endToken = element.position; | |
| 221 } else { | |
| 222 beginToken = expression.getBeginToken(); | |
| 223 endToken = expression.getEndToken(); | |
| 224 } | |
| 225 // TODO(podivilov): find the right sourceFile here and remove offset | |
| 226 // checks below. | |
| 227 var sourcePosition, endSourcePosition; | |
| 228 if (beginToken.charOffset < sourceFile.length) { | |
| 229 sourcePosition = | |
| 230 new TokenSourceFileLocation(sourceFile, beginToken, name); | |
| 231 } | |
| 232 if (endToken.charOffset < sourceFile.length) { | |
| 233 endSourcePosition = | |
| 234 new TokenSourceFileLocation(sourceFile, endToken, name); | |
| 235 } | |
| 236 return node.withPosition(sourcePosition, endSourcePosition); | |
| 237 } | |
| 238 | |
| 239 SourceFile sourceFileOfElement(Element element) { | |
| 240 return element.implementation.compilationUnit.script.file; | |
| 241 } | 209 } |
| 242 } | 210 } |
| OLD | NEW |