| 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.scanner.task; | 5 library dart2js.scanner.task; |
| 6 | 6 |
| 7 import '../common/tasks.dart' show | 7 import '../common/tasks.dart' show CompilerTask; |
| 8 CompilerTask; | 8 import '../compiler.dart' show Compiler; |
| 9 import '../compiler.dart' show | 9 import '../elements/elements.dart' show CompilationUnitElement, LibraryElement; |
| 10 Compiler; | 10 import '../script.dart' show Script; |
| 11 import '../elements/elements.dart' show | 11 import '../tokens/token.dart' show Token; |
| 12 CompilationUnitElement, | |
| 13 LibraryElement; | |
| 14 import '../script.dart' show | |
| 15 Script; | |
| 16 import '../tokens/token.dart' show | |
| 17 Token; | |
| 18 | 12 |
| 19 import 'scanner.dart' show | 13 import 'scanner.dart' show Scanner; |
| 20 Scanner; | 14 import 'string_scanner.dart' show StringScanner; |
| 21 import 'string_scanner.dart' show | |
| 22 StringScanner; | |
| 23 | 15 |
| 24 class ScannerTask extends CompilerTask { | 16 class ScannerTask extends CompilerTask { |
| 25 ScannerTask(Compiler compiler) : super(compiler); | 17 ScannerTask(Compiler compiler) : super(compiler); |
| 26 String get name => 'Scanner'; | 18 String get name => 'Scanner'; |
| 27 | 19 |
| 28 void scanLibrary(LibraryElement library) { | 20 void scanLibrary(LibraryElement library) { |
| 29 CompilationUnitElement compilationUnit = library.entryCompilationUnit; | 21 CompilationUnitElement compilationUnit = library.entryCompilationUnit; |
| 30 String canonicalUri = library.canonicalUri.toString(); | 22 String canonicalUri = library.canonicalUri.toString(); |
| 31 String resolvedUri = compilationUnit.script.resourceUri.toString(); | 23 String resolvedUri = compilationUnit.script.resourceUri.toString(); |
| 32 if (canonicalUri == resolvedUri) { | 24 if (canonicalUri == resolvedUri) { |
| 33 reporter.log("Scanning library $canonicalUri"); | 25 reporter.log("Scanning library $canonicalUri"); |
| 34 } else { | 26 } else { |
| 35 reporter.log("Scanning library $canonicalUri ($resolvedUri)"); | 27 reporter.log("Scanning library $canonicalUri ($resolvedUri)"); |
| 36 } | 28 } |
| 37 scan(compilationUnit); | 29 scan(compilationUnit); |
| 38 } | 30 } |
| 39 | 31 |
| 40 void scan(CompilationUnitElement compilationUnit) { | 32 void scan(CompilationUnitElement compilationUnit) { |
| 41 measure(() { | 33 measure(() { |
| 42 scanElements(compilationUnit); | 34 scanElements(compilationUnit); |
| 43 }); | 35 }); |
| 44 } | 36 } |
| 45 | 37 |
| 46 void scanElements(CompilationUnitElement compilationUnit) { | 38 void scanElements(CompilationUnitElement compilationUnit) { |
| 47 Script script = compilationUnit.script; | 39 Script script = compilationUnit.script; |
| 48 Token tokens = new Scanner(script.file, | 40 Token tokens = new Scanner(script.file, |
| 49 includeComments: compiler.options.preserveComments).tokenize(); | 41 includeComments: compiler.options.preserveComments) |
| 42 .tokenize(); |
| 50 if (compiler.options.preserveComments) { | 43 if (compiler.options.preserveComments) { |
| 51 tokens = compiler.processAndStripComments(tokens); | 44 tokens = compiler.processAndStripComments(tokens); |
| 52 } | 45 } |
| 53 compiler.dietParser.dietParse(compilationUnit, tokens); | 46 compiler.dietParser.dietParse(compilationUnit, tokens); |
| 54 } | 47 } |
| 55 | 48 |
| 56 /** | 49 /** |
| 57 * Returns the tokens for the [source]. | 50 * Returns the tokens for the [source]. |
| 58 * | 51 * |
| 59 * The [StringScanner] implementation works on strings that end with a '0' | 52 * The [StringScanner] implementation works on strings that end with a '0' |
| 60 * value ('\x00'). If [source] does not end with '0', the string is copied | 53 * value ('\x00'). If [source] does not end with '0', the string is copied |
| 61 * before scanning. | 54 * before scanning. |
| 62 */ | 55 */ |
| 63 Token tokenize(String source) { | 56 Token tokenize(String source) { |
| 64 return measure(() { | 57 return measure(() { |
| 65 return new StringScanner.fromString(source, includeComments: false) | 58 return new StringScanner.fromString(source, includeComments: false) |
| 66 .tokenize(); | 59 .tokenize(); |
| 67 }); | 60 }); |
| 68 } | 61 } |
| 69 } | 62 } |
| OLD | NEW |