| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show EventSink, Future; | 7 import 'dart:async' show EventSink, Future; |
| 8 | 8 |
| 9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
| 10 import 'cache_strategy.dart' show CacheStrategy; | 10 import 'cache_strategy.dart' show CacheStrategy; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 LibraryElementX, | 40 LibraryElementX, |
| 41 PrefixElementX; | 41 PrefixElementX; |
| 42 import 'enqueue.dart' | 42 import 'enqueue.dart' |
| 43 show | 43 show |
| 44 CodegenEnqueuer, | 44 CodegenEnqueuer, |
| 45 Enqueuer, | 45 Enqueuer, |
| 46 EnqueueTask, | 46 EnqueueTask, |
| 47 ResolutionEnqueuer, | 47 ResolutionEnqueuer, |
| 48 QueueFilter; | 48 QueueFilter; |
| 49 import 'environment.dart'; | 49 import 'environment.dart'; |
| 50 import 'id_generator.dart'; |
| 50 import 'io/source_information.dart' show SourceInformation; | 51 import 'io/source_information.dart' show SourceInformation; |
| 51 import 'js_backend/backend_helpers.dart' as js_backend show BackendHelpers; | 52 import 'js_backend/backend_helpers.dart' as js_backend show BackendHelpers; |
| 52 import 'js_backend/js_backend.dart' as js_backend show JavaScriptBackend; | 53 import 'js_backend/js_backend.dart' as js_backend show JavaScriptBackend; |
| 53 import 'library_loader.dart' | 54 import 'library_loader.dart' |
| 54 show | 55 show |
| 55 ElementScanner, | 56 ElementScanner, |
| 56 LibraryLoader, | 57 LibraryLoader, |
| 57 LibraryLoaderTask, | 58 LibraryLoaderTask, |
| 58 LoadedLibraries, | 59 LoadedLibraries, |
| 59 LibraryLoaderListener, | 60 LibraryLoaderListener, |
| 60 ResolvedUriTranslator, | 61 ResolvedUriTranslator, |
| 61 ScriptLoader; | 62 ScriptLoader; |
| 62 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; | 63 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; |
| 63 import 'common/names.dart' show Selectors; | 64 import 'common/names.dart' show Selectors; |
| 64 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; | 65 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; |
| 65 import 'options.dart' show CompilerOptions, DiagnosticOptions, ParserOptions; | 66 import 'options.dart' show CompilerOptions, DiagnosticOptions, ParserOptions; |
| 66 import 'parser/diet_parser_task.dart' show DietParserTask; | 67 import 'parser/diet_parser_task.dart' show DietParserTask; |
| 67 import 'parser/element_listener.dart' show ScannerOptions; | 68 import 'parser/element_listener.dart' show ScannerOptions; |
| 68 import 'parser/parser_task.dart' show ParserTask; | 69 import 'parser/parser_task.dart' show ParserTask; |
| 69 import 'patch_parser.dart' show PatchParserTask; | 70 import 'patch_parser.dart' show PatchParserTask; |
| 70 import 'resolution/registry.dart' show ResolutionRegistry; | 71 import 'resolution/registry.dart' show ResolutionRegistry; |
| 71 import 'resolution/resolution.dart' show ResolverTask; | 72 import 'resolution/resolution.dart' show ResolverTask; |
| 72 import 'resolution/tree_elements.dart' show TreeElementMapping; | 73 import 'resolution/tree_elements.dart' show TreeElementMapping; |
| 73 import 'scanner/scanner_task.dart' show ScannerTask; | 74 import 'scanner/scanner_task.dart' show ScannerTask; |
| 74 import 'serialization/task.dart' show SerializationTask; | 75 import 'serialization/task.dart' show SerializationTask; |
| 75 import 'script.dart' show Script; | 76 import 'script.dart' show Script; |
| 76 import 'ssa/nodes.dart' show HInstruction; | 77 import 'ssa/nodes.dart' show HInstruction; |
| 77 import 'tracer.dart' show Tracer; | 78 import 'tracer.dart' show Tracer; |
| 78 import 'tokens/token.dart' show StringToken, Token, TokenPair; | 79 import 'tokens/token.dart' show StringToken, Token, TokenPair; |
| 79 import 'tokens/token_constants.dart' as Tokens show COMMENT_TOKEN, EOF_TOKEN; | |
| 80 import 'tokens/token_map.dart' show TokenMap; | 80 import 'tokens/token_map.dart' show TokenMap; |
| 81 import 'tree/tree.dart' show Node, TypeAnnotation; | 81 import 'tree/tree.dart' show Node, TypeAnnotation; |
| 82 import 'typechecker.dart' show TypeCheckerTask; | 82 import 'typechecker.dart' show TypeCheckerTask; |
| 83 import 'types/types.dart' as ti; | 83 import 'types/types.dart' as ti; |
| 84 import 'universe/call_structure.dart' show CallStructure; | 84 import 'universe/call_structure.dart' show CallStructure; |
| 85 import 'universe/selector.dart' show Selector; | 85 import 'universe/selector.dart' show Selector; |
| 86 import 'universe/universe.dart' show Universe; | 86 import 'universe/universe.dart' show Universe; |
| 87 import 'universe/use.dart' show StaticUse; | 87 import 'universe/use.dart' show StaticUse; |
| 88 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact; | 88 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact; |
| 89 import 'util/util.dart' show Link, Setlet; | 89 import 'util/util.dart' show Link, Setlet; |
| 90 import 'world.dart' show World; | 90 import 'world.dart' show World; |
| 91 | 91 |
| 92 abstract class Compiler implements LibraryLoaderListener { | 92 abstract class Compiler implements LibraryLoaderListener, IdGenerator { |
| 93 final Stopwatch totalCompileTime = new Stopwatch(); | 93 final Stopwatch totalCompileTime = new Stopwatch(); |
| 94 int nextFreeClassId = 0; | 94 final IdGenerator idGenerator = new IdGenerator(); |
| 95 World world; | 95 World world; |
| 96 Types types; | 96 Types types; |
| 97 _CompilerCoreTypes _coreTypes; | 97 _CompilerCoreTypes _coreTypes; |
| 98 _CompilerDiagnosticReporter _reporter; | 98 _CompilerDiagnosticReporter _reporter; |
| 99 _CompilerResolution _resolution; | 99 _CompilerResolution _resolution; |
| 100 _CompilerParsing _parsing; | 100 _CompilerParsing _parsing; |
| 101 | 101 |
| 102 final CacheStrategy cacheStrategy; | 102 final CacheStrategy cacheStrategy; |
| 103 | 103 |
| 104 ImpactStrategy impactStrategy = const ImpactStrategy(); | 104 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 throw new ArgumentError('--dump-info is not supported for dart2dart.'); | 333 throw new ArgumentError('--dump-info is not supported for dart2dart.'); |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 | 336 |
| 337 if (options.dumpInfo && options.useStartupEmitter) { | 337 if (options.dumpInfo && options.useStartupEmitter) { |
| 338 throw new ArgumentError( | 338 throw new ArgumentError( |
| 339 '--dump-info is not supported with the fast startup emitter'); | 339 '--dump-info is not supported with the fast startup emitter'); |
| 340 } | 340 } |
| 341 | 341 |
| 342 tasks = [ | 342 tasks = [ |
| 343 dietParser = new DietParserTask(this, parsing.parserOptions), | 343 dietParser = new DietParserTask(this, parsing.parserOptions, idGenerator), |
| 344 scanner = createScannerTask(), | 344 scanner = createScannerTask(), |
| 345 serialization = new SerializationTask(this), | 345 serialization = new SerializationTask(this), |
| 346 libraryLoader = new LibraryLoaderTask( | 346 libraryLoader = new LibraryLoaderTask( |
| 347 this, | 347 this, |
| 348 new _ResolvedUriTranslator(this), | 348 new _ResolvedUriTranslator(this), |
| 349 new _ScriptLoader(this), | 349 new _ScriptLoader(this), |
| 350 new _ElementScanner(scanner), | 350 new _ElementScanner(scanner), |
| 351 this.serialization, | 351 this.serialization, |
| 352 this, | 352 this, |
| 353 environment), | 353 environment), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 364 dumpInfoTask = new DumpInfoTask(this), | 364 dumpInfoTask = new DumpInfoTask(this), |
| 365 reuseLibraryTask = new GenericTask('Reuse library', this), | 365 reuseLibraryTask = new GenericTask('Reuse library', this), |
| 366 ]; | 366 ]; |
| 367 | 367 |
| 368 tasks.addAll(backend.tasks); | 368 tasks.addAll(backend.tasks); |
| 369 } | 369 } |
| 370 | 370 |
| 371 /// Creates the scanner task. | 371 /// Creates the scanner task. |
| 372 /// | 372 /// |
| 373 /// Override this to mock the scanner for testing. | 373 /// Override this to mock the scanner for testing. |
| 374 ScannerTask createScannerTask() => new ScannerTask(this); | 374 ScannerTask createScannerTask() => new ScannerTask(this, dietParser, |
| 375 preserveComments: options.preserveComments, commentMap: commentMap); |
| 375 | 376 |
| 376 /// Creates the resolver task. | 377 /// Creates the resolver task. |
| 377 /// | 378 /// |
| 378 /// Override this to mock the resolver for testing. | 379 /// Override this to mock the resolver for testing. |
| 379 ResolverTask createResolverTask() { | 380 ResolverTask createResolverTask() { |
| 380 return new ResolverTask(this, backend.constantCompilerTask); | 381 return new ResolverTask(this, backend.constantCompilerTask); |
| 381 } | 382 } |
| 382 | 383 |
| 383 Universe get resolverWorld => enqueuer.resolution.universe; | 384 Universe get resolverWorld => enqueuer.resolution.universe; |
| 384 Universe get codegenWorld => enqueuer.codegen.universe; | 385 Universe get codegenWorld => enqueuer.codegen.universe; |
| 385 | 386 |
| 386 bool get analyzeAll => options.analyzeAll || compileAll; | 387 bool get analyzeAll => options.analyzeAll || compileAll; |
| 387 | 388 |
| 388 bool get compileAll => false; | 389 bool get compileAll => false; |
| 389 | 390 |
| 390 bool get disableTypeInference => | 391 bool get disableTypeInference => |
| 391 options.disableTypeInference || compilationFailed; | 392 options.disableTypeInference || compilationFailed; |
| 392 | 393 |
| 393 int getNextFreeClassId() => nextFreeClassId++; | 394 // TODO(het): remove this and pass idGenerator directly instead |
| 395 @deprecated |
| 396 int getNextFreeId() => idGenerator.getNextFreeId(); |
| 394 | 397 |
| 395 void unimplemented(Spannable spannable, String methodName) { | 398 void unimplemented(Spannable spannable, String methodName) { |
| 396 reporter.internalError(spannable, "$methodName not implemented."); | 399 reporter.internalError(spannable, "$methodName not implemented."); |
| 397 } | 400 } |
| 398 | 401 |
| 399 // Compiles the dart script at [uri]. | 402 // Compiles the dart script at [uri]. |
| 400 // | 403 // |
| 401 // The resulting future will complete with true if the compilation | 404 // The resulting future will complete with true if the compilation |
| 402 // succeded. | 405 // succeded. |
| 403 Future<bool> run(Uri uri) { | 406 Future<bool> run(Uri uri) { |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 Element lookupElementIn(ScopeContainerElement container, String name) { | 1145 Element lookupElementIn(ScopeContainerElement container, String name) { |
| 1143 Element element = container.localLookup(name); | 1146 Element element = container.localLookup(name); |
| 1144 if (element == null) { | 1147 if (element == null) { |
| 1145 throw 'Could not find $name in $container'; | 1148 throw 'Could not find $name in $container'; |
| 1146 } | 1149 } |
| 1147 return element; | 1150 return element; |
| 1148 } | 1151 } |
| 1149 | 1152 |
| 1150 bool get isMockCompilation => false; | 1153 bool get isMockCompilation => false; |
| 1151 | 1154 |
| 1152 Token processAndStripComments(Token currentToken) { | |
| 1153 Token firstToken = currentToken; | |
| 1154 Token prevToken; | |
| 1155 while (currentToken.kind != Tokens.EOF_TOKEN) { | |
| 1156 if (identical(currentToken.kind, Tokens.COMMENT_TOKEN)) { | |
| 1157 Token firstCommentToken = currentToken; | |
| 1158 while (identical(currentToken.kind, Tokens.COMMENT_TOKEN)) { | |
| 1159 currentToken = currentToken.next; | |
| 1160 } | |
| 1161 commentMap[currentToken] = firstCommentToken; | |
| 1162 if (prevToken == null) { | |
| 1163 firstToken = currentToken; | |
| 1164 } else { | |
| 1165 prevToken.next = currentToken; | |
| 1166 } | |
| 1167 } | |
| 1168 prevToken = currentToken; | |
| 1169 currentToken = currentToken.next; | |
| 1170 } | |
| 1171 return firstToken; | |
| 1172 } | |
| 1173 | |
| 1174 void reportUnusedCode() { | 1155 void reportUnusedCode() { |
| 1175 void checkLive(member) { | 1156 void checkLive(member) { |
| 1176 if (member.isMalformed) return; | 1157 if (member.isMalformed) return; |
| 1177 if (member.isFunction) { | 1158 if (member.isFunction) { |
| 1178 if (!enqueuer.resolution.hasBeenProcessed(member)) { | 1159 if (!enqueuer.resolution.hasBeenProcessed(member)) { |
| 1179 reporter.reportHintMessage( | 1160 reporter.reportHintMessage( |
| 1180 member, MessageKind.UNUSED_METHOD, {'name': member.name}); | 1161 member, MessageKind.UNUSED_METHOD, {'name': member.name}); |
| 1181 } | 1162 } |
| 1182 } else if (member.isClass) { | 1163 } else if (member.isClass) { |
| 1183 if (!member.isResolved) { | 1164 if (!member.isResolved) { |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2073 _ElementScanner(this.scanner); | 2054 _ElementScanner(this.scanner); |
| 2074 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2055 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2075 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2056 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2076 } | 2057 } |
| 2077 | 2058 |
| 2078 class _EmptyEnvironment implements Environment { | 2059 class _EmptyEnvironment implements Environment { |
| 2079 const _EmptyEnvironment(); | 2060 const _EmptyEnvironment(); |
| 2080 | 2061 |
| 2081 String valueOf(String key) => null; | 2062 String valueOf(String key) => null; |
| 2082 } | 2063 } |
| OLD | NEW |