Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Unified Diff: pkg/compiler/lib/src/scanner/scanner_task.dart

Issue 1867243004: Begin refactoring compiler out of diet parser and scanner (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/resolution/class_hierarchy.dart ('k') | tests/compiler/dart2js/exit_code_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/scanner/scanner_task.dart
diff --git a/pkg/compiler/lib/src/scanner/scanner_task.dart b/pkg/compiler/lib/src/scanner/scanner_task.dart
index b40dbf7acb94c443d2fde6529d0be6df3b492765..3d694a3d7110d4762f94b5764be74e85461665d2 100644
--- a/pkg/compiler/lib/src/scanner/scanner_task.dart
+++ b/pkg/compiler/lib/src/scanner/scanner_task.dart
@@ -8,13 +8,30 @@ import '../common/tasks.dart' show CompilerTask;
import '../compiler.dart' show Compiler;
import '../elements/elements.dart' show CompilationUnitElement, LibraryElement;
import '../script.dart' show Script;
+import '../parser/diet_parser_task.dart' show DietParserTask;
import '../tokens/token.dart' show Token;
+import '../tokens/token_constants.dart' as Tokens show COMMENT_TOKEN, EOF_TOKEN;
+import '../tokens/token_map.dart' show TokenMap;
import 'scanner.dart' show Scanner;
import 'string_scanner.dart' show StringScanner;
class ScannerTask extends CompilerTask {
- ScannerTask(Compiler compiler) : super(compiler);
+ final DietParserTask _dietParser;
+ final bool _preserveComments;
+ final TokenMap _commentMap;
+
+ ScannerTask(Compiler compiler, this._dietParser,
+ {bool preserveComments: false, TokenMap commentMap})
+ : _preserveComments = preserveComments,
+ _commentMap = commentMap,
+ super(compiler) {
+ if (_preserveComments && _commentMap == null) {
+ throw new ArgumentError(
+ "commentMap must be provided if preserveComments is true");
+ }
+ }
+
String get name => 'Scanner';
void scanLibrary(LibraryElement library) {
@@ -37,13 +54,12 @@ class ScannerTask extends CompilerTask {
void scanElements(CompilationUnitElement compilationUnit) {
Script script = compilationUnit.script;
- Token tokens = new Scanner(script.file,
- includeComments: compiler.options.preserveComments)
- .tokenize();
- if (compiler.options.preserveComments) {
- tokens = compiler.processAndStripComments(tokens);
+ Token tokens =
+ new Scanner(script.file, includeComments: _preserveComments).tokenize();
+ if (_preserveComments) {
+ tokens = processAndStripComments(tokens);
}
- compiler.dietParser.dietParse(compilationUnit, tokens);
+ _dietParser.dietParse(compilationUnit, tokens);
}
/**
@@ -59,4 +75,26 @@ class ScannerTask extends CompilerTask {
.tokenize();
});
}
+
+ Token processAndStripComments(Token currentToken) {
+ Token firstToken = currentToken;
+ Token prevToken;
+ while (currentToken.kind != Tokens.EOF_TOKEN) {
+ if (identical(currentToken.kind, Tokens.COMMENT_TOKEN)) {
+ Token firstCommentToken = currentToken;
+ while (identical(currentToken.kind, Tokens.COMMENT_TOKEN)) {
+ currentToken = currentToken.next;
+ }
+ _commentMap[currentToken] = firstCommentToken;
+ if (prevToken == null) {
+ firstToken = currentToken;
+ } else {
+ prevToken.next = currentToken;
+ }
+ }
+ prevToken = currentToken;
+ currentToken = currentToken.next;
+ }
+ return firstToken;
+ }
}
« no previous file with comments | « pkg/compiler/lib/src/resolution/class_hierarchy.dart ('k') | tests/compiler/dart2js/exit_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698