| OLD | NEW |
| 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library fletchc.compiler; | 5 library fletchc.compiler; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:convert' show | 10 import 'dart:convert' show |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 SourceFileProvider; | 29 SourceFileProvider; |
| 30 | 30 |
| 31 import 'package:compiler/src/elements/elements.dart' show | 31 import 'package:compiler/src/elements/elements.dart' show |
| 32 ConstructorElement, | 32 ConstructorElement, |
| 33 ClassElement, | 33 ClassElement, |
| 34 FunctionElement; | 34 FunctionElement; |
| 35 | 35 |
| 36 import 'package:compiler/src/filenames.dart' show | 36 import 'package:compiler/src/filenames.dart' show |
| 37 appendSlash; | 37 appendSlash; |
| 38 | 38 |
| 39 import 'src/compiled_function.dart' show | 39 import 'src/fletch_function_builder.dart' show |
| 40 CompiledFunction; | 40 FletchFunctionBuilder; |
| 41 | 41 |
| 42 import 'src/debug_info.dart'; | 42 import 'src/debug_info.dart'; |
| 43 | 43 |
| 44 import 'src/fletch_native_descriptor.dart' show | 44 import 'src/fletch_native_descriptor.dart' show |
| 45 FletchNativeDescriptor; | 45 FletchNativeDescriptor; |
| 46 | 46 |
| 47 import 'src/fletch_backend.dart' show | 47 import 'src/fletch_backend.dart' show |
| 48 FletchBackend; | 48 FletchBackend; |
| 49 | 49 |
| 50 import 'src/compiled_class.dart' show | 50 import 'src/fletch_class_builder.dart' show |
| 51 CompiledClass; | 51 FletchClassBuilder; |
| 52 | 52 |
| 53 import 'package:compiler/src/apiimpl.dart' as apiimpl; | 53 import 'package:compiler/src/apiimpl.dart' as apiimpl; |
| 54 | 54 |
| 55 import 'src/fletch_compiler.dart' as implementation; | 55 import 'src/fletch_compiler.dart' as implementation; |
| 56 | 56 |
| 57 import 'bytecodes.dart' show | 57 import 'bytecodes.dart' show |
| 58 Bytecode; | 58 Bytecode; |
| 59 | 59 |
| 60 import 'src/fletch_selector.dart'; | 60 import 'src/fletch_selector.dart'; |
| 61 | 61 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 Map<String, FletchNativeDescriptor> natives = | 235 Map<String, FletchNativeDescriptor> natives = |
| 236 <String, FletchNativeDescriptor>{}; | 236 <String, FletchNativeDescriptor>{}; |
| 237 Map<String, String> names = <String, String>{}; | 237 Map<String, String> names = <String, String>{}; |
| 238 FletchNativeDescriptor.decode(data, natives, names); | 238 FletchNativeDescriptor.decode(data, natives, names); |
| 239 _compiler.context.nativeDescriptors = natives; | 239 _compiler.context.nativeDescriptors = natives; |
| 240 _compiler.context.setNames(names); | 240 _compiler.context.setNames(names); |
| 241 } | 241 } |
| 242 | 242 |
| 243 Uri get fletchVm => _compiler.fletchVm; | 243 Uri get fletchVm => _compiler.fletchVm; |
| 244 | 244 |
| 245 CompiledFunction lookupCompiledFunction(int methodId) { | 245 FletchFunctionBuilder lookupFletchFunctionBuilder(int methodId) { |
| 246 CompiledFunction function = _compiler.context.backend.functions[methodId]; | 246 FletchFunctionBuilder function = |
| 247 _compiler.context.backend.functions[methodId]; |
| 247 assert(function.methodId == methodId); | 248 assert(function.methodId == methodId); |
| 248 return function; | 249 return function; |
| 249 } | 250 } |
| 250 | 251 |
| 251 String lookupFunctionName(int methodId) { | 252 String lookupFunctionName(int methodId) { |
| 252 CompiledFunction function = lookupCompiledFunction(methodId); | 253 FletchFunctionBuilder function = lookupFletchFunctionBuilder(methodId); |
| 253 if (function == null) return ''; | 254 if (function == null) return ''; |
| 254 if (function.isConstructor) { | 255 if (function.isConstructor) { |
| 255 ConstructorElement constructor = function.element; | 256 ConstructorElement constructor = function.element; |
| 256 ClassElement enclosing = constructor.enclosingClass; | 257 ClassElement enclosing = constructor.enclosingClass; |
| 257 String name = (constructor.name == null || constructor.name.length == 0) | 258 String name = (constructor.name == null || constructor.name.length == 0) |
| 258 ? '' | 259 ? '' |
| 259 : '.${constructor.name}'; | 260 : '.${constructor.name}'; |
| 260 String postfix = function.isInitializerList ? ' initializer' : ''; | 261 String postfix = function.isInitializerList ? ' initializer' : ''; |
| 261 return '${enclosing.name}$name$postfix'; | 262 return '${enclosing.name}$name$postfix'; |
| 262 } | 263 } |
| 263 String functionName = function.name; | 264 String functionName = function.name; |
| 264 if (functionName == null) return ''; | 265 if (functionName == null) return ''; |
| 265 CompiledClass memberOf = function.memberOf; | 266 FletchClassBuilder memberOf = function.memberOf; |
| 266 if (memberOf == null) return functionName; | 267 if (memberOf == null) return functionName; |
| 267 if (memberOf.element == null) return functionName; | 268 if (memberOf.element == null) return functionName; |
| 268 if (functionName.isEmpty) return memberOf.element.name; | 269 if (functionName.isEmpty) return memberOf.element.name; |
| 269 return '${memberOf.element.name}.$functionName'; | 270 return '${memberOf.element.name}.$functionName'; |
| 270 } | 271 } |
| 271 | 272 |
| 272 CompiledClass lookupCompiledClass(int classId) { | 273 FletchClassBuilder lookupFletchClassBuilder(int classId) { |
| 273 CompiledClass klass = _compiler.context.backend.classes[classId]; | 274 FletchClassBuilder klass = _compiler.context.backend.classes[classId]; |
| 274 assert(klass.id == classId); | 275 assert(klass.id == classId); |
| 275 return klass; | 276 return klass; |
| 276 } | 277 } |
| 277 | 278 |
| 278 String lookupClassName(int classId) { | 279 String lookupClassName(int classId) { |
| 279 CompiledClass klass = lookupCompiledClass(classId); | 280 FletchClassBuilder klass = lookupFletchClassBuilder(classId); |
| 280 if (klass.element != null) return klass.element.name; | 281 if (klass.element != null) return klass.element.name; |
| 281 // TODO(ager): Provide better information for closures. | 282 // TODO(ager): Provide better information for closures. |
| 282 if (_compiler.context.backend.closureClasses.values.contains(klass)) { | 283 if (_compiler.context.backend.closureClasses.values.contains(klass)) { |
| 283 return 'closure'; | 284 return 'closure'; |
| 284 } | 285 } |
| 285 CompiledFunction function = | 286 FletchFunctionBuilder function = |
| 286 _compiler.context.backend.compiledFunctionFromTearoffClass(klass); | 287 _compiler.context.backend.functionBuilderFromTearoffClass(klass); |
| 287 if (function != null) return 'tearoff of ${function.name}'; | 288 if (function != null) return 'tearoff of ${function.name}'; |
| 288 return 'unknown'; | 289 return 'unknown'; |
| 289 } | 290 } |
| 290 | 291 |
| 291 String lookupFunctionNameBySelector(int selector) { | 292 String lookupFunctionNameBySelector(int selector) { |
| 292 int id = FletchSelector.decodeId(selector); | 293 int id = FletchSelector.decodeId(selector); |
| 293 return _compiler.context.symbols[id]; | 294 return _compiler.context.symbols[id]; |
| 294 } | 295 } |
| 295 | 296 |
| 296 List<Bytecode> lookupFunctionBytecodes(int methodId) { | 297 List<Bytecode> lookupFunctionBytecodes(int methodId) { |
| 297 return lookupCompiledFunction(methodId).builder.bytecodes; | 298 return lookupFletchFunctionBuilder(methodId).builder.bytecodes; |
| 298 } | 299 } |
| 299 | 300 |
| 300 Iterable<int> lookupFunctionIdsByName(String name) { | 301 Iterable<int> lookupFunctionIdsByName(String name) { |
| 301 return _compiler.context.backend.functions | 302 return _compiler.context.backend.functions |
| 302 .where((f) => f.name == name) | 303 .where((f) => f.name == name) |
| 303 .map((f) => f.methodId); | 304 .map((f) => f.methodId); |
| 304 } | 305 } |
| 305 | 306 |
| 306 int mainMethodId() { | 307 int mainMethodId() { |
| 307 FunctionElement mainFunctionElement = _compiler.mainFunction; | 308 FunctionElement mainFunctionElement = _compiler.mainFunction; |
| 308 CompiledFunction mainMethod = | 309 FletchFunctionBuilder mainMethod = |
| 309 _compiler.context.backend.compiledFunctions[mainFunctionElement]; | 310 _compiler.context.backend.functionBuilders[mainFunctionElement]; |
| 310 return mainMethod.methodId; | 311 return mainMethod.methodId; |
| 311 } | 312 } |
| 312 | 313 |
| 313 String astString(int methodId, int bytecodeIndex) { | 314 String astString(int methodId, int bytecodeIndex) { |
| 314 CompiledFunction function = lookupCompiledFunction(methodId); | 315 FletchFunctionBuilder function = lookupFletchFunctionBuilder(methodId); |
| 315 _compiler.context.backend.ensureDebugInfo(function); | 316 _compiler.context.backend.ensureDebugInfo(function); |
| 316 return function.debugInfo.astStringFor(bytecodeIndex); | 317 return function.debugInfo.astStringFor(bytecodeIndex); |
| 317 } | 318 } |
| 318 | 319 |
| 319 String fileAndLineString(int methodId, int bytecodeIndex) { | 320 String fileAndLineString(int methodId, int bytecodeIndex) { |
| 320 CompiledFunction function = lookupCompiledFunction(methodId); | 321 FletchFunctionBuilder function = lookupFletchFunctionBuilder(methodId); |
| 321 _compiler.context.backend.ensureDebugInfo(function); | 322 _compiler.context.backend.ensureDebugInfo(function); |
| 322 return function.debugInfo.fileAndLineStringFor(bytecodeIndex); | 323 return function.debugInfo.fileAndLineStringFor(bytecodeIndex); |
| 323 } | 324 } |
| 324 | 325 |
| 325 String sourceListString(int methodId, | 326 String sourceListString(int methodId, |
| 326 int bytecodeIndex, | 327 int bytecodeIndex, |
| 327 {int contextLines : 5}) { | 328 {int contextLines : 5}) { |
| 328 CompiledFunction function = lookupCompiledFunction(methodId); | 329 FletchFunctionBuilder function = lookupFletchFunctionBuilder(methodId); |
| 329 _compiler.context.backend.ensureDebugInfo(function); | 330 _compiler.context.backend.ensureDebugInfo(function); |
| 330 return function.debugInfo.sourceListStringFor(bytecodeIndex, contextLines); | 331 return function.debugInfo.sourceListStringFor(bytecodeIndex, contextLines); |
| 331 } | 332 } |
| 332 | 333 |
| 333 SourceLocation sourceLocation(int methodId, int bytecodeIndex) { | 334 SourceLocation sourceLocation(int methodId, int bytecodeIndex) { |
| 334 CompiledFunction function = lookupCompiledFunction(methodId); | 335 FletchFunctionBuilder function = lookupFletchFunctionBuilder(methodId); |
| 335 _compiler.context.backend.ensureDebugInfo(function); | 336 _compiler.context.backend.ensureDebugInfo(function); |
| 336 return function.debugInfo.sourceLocationFor(bytecodeIndex); | 337 return function.debugInfo.sourceLocationFor(bytecodeIndex); |
| 337 } | 338 } |
| 338 | 339 |
| 339 ScopeInfo scopeInfo(int methodId, int bytecodeIndex) { | 340 ScopeInfo scopeInfo(int methodId, int bytecodeIndex) { |
| 340 CompiledFunction function = lookupCompiledFunction(methodId); | 341 FletchFunctionBuilder function = lookupFletchFunctionBuilder(methodId); |
| 341 _compiler.context.backend.ensureDebugInfo(function); | 342 _compiler.context.backend.ensureDebugInfo(function); |
| 342 return function.debugInfo.scopeInfoFor(bytecodeIndex); | 343 return function.debugInfo.scopeInfoFor(bytecodeIndex); |
| 343 } | 344 } |
| 344 | 345 |
| 345 DebugInfo debugInfoForPosition(String file, int position) { | 346 DebugInfo debugInfoForPosition(String file, int position) { |
| 346 return _compiler.debugInfoForPosition(file, position); | 347 return _compiler.debugInfoForPosition(file, position); |
| 347 } | 348 } |
| 348 | 349 |
| 349 int positionInFileFromPattern(String file, int line, String pattern) { | 350 int positionInFileFromPattern(String file, int line, String pattern) { |
| 350 return _compiler.positionInFileFromPattern(file, line, pattern); | 351 return _compiler.positionInFileFromPattern(file, line, pattern); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 461 |
| 461 Uri _guessPatchRoot(Uri libraryRoot) { | 462 Uri _guessPatchRoot(Uri libraryRoot) { |
| 462 Uri guess = libraryRoot.resolve('../../fletch/'); | 463 Uri guess = libraryRoot.resolve('../../fletch/'); |
| 463 if (_looksLikePatchRoot(guess)) return guess; | 464 if (_looksLikePatchRoot(guess)) return guess; |
| 464 return null; | 465 return null; |
| 465 } | 466 } |
| 466 | 467 |
| 467 bool _looksLikePatchRoot(Uri uri) { | 468 bool _looksLikePatchRoot(Uri uri) { |
| 468 return _containsFile(uri, 'lib/core/core_patch.dart'); | 469 return _containsFile(uri, 'lib/core/core_patch.dart'); |
| 469 } | 470 } |
| OLD | NEW |