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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2745163004: Optionally use Fasta with the new analysis driver. (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | pkg/analyzer/test/src/dart/analysis/driver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/file_state.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index a8c867004c63c969e7d90f9e03720a6a8b1aac90..11e3674946d17b84a8a4341eea58c226bfca8492 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -28,6 +28,13 @@ import 'package:analyzer/src/summary/name_filter.dart';
import 'package:analyzer/src/summary/summarize_ast.dart';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
+import 'package:front_end/src/fasta/analyzer/ast_builder.dart' as fasta;
+import 'package:front_end/src/fasta/analyzer/element_store.dart' as fasta;
+import 'package:front_end/src/fasta/analyzer/mock_element.dart' as fasta;
+import 'package:front_end/src/fasta/builder/builder.dart' as fasta;
+import 'package:front_end/src/fasta/builder/scope.dart' as fasta;
+import 'package:front_end/src/fasta/parser/parser.dart' as fasta;
+import 'package:front_end/src/fasta/scanner.dart' as fasta;
import 'package:meta/meta.dart';
/**
@@ -68,6 +75,8 @@ class FileContentOverlay {
* should be called.
*/
class FileState {
+ static const bool USE_FASTA_PARSER = false;
+
final FileSystemState _fsState;
/**
@@ -86,6 +95,7 @@ class FileState {
Source source;
bool _exists;
+ List<int> _contentBytes;
String _content;
String _contentHash;
LineInfo _lineInfo;
@@ -345,18 +355,38 @@ class FileState {
CompilationUnit parse(AnalysisErrorListener errorListener) {
AnalysisOptions analysisOptions = _fsState._analysisOptions;
- CharSequenceReader reader = new CharSequenceReader(content);
- Scanner scanner = new Scanner(source, reader, errorListener);
- scanner.scanGenericMethodComments = analysisOptions.strongMode;
- Token token = scanner.tokenize();
- LineInfo lineInfo = new LineInfo(scanner.lineStarts);
-
- Parser parser = new Parser(source, errorListener);
- parser.enableAssertInitializer = analysisOptions.enableAssertInitializer;
- parser.parseGenericMethodComments = analysisOptions.strongMode;
- CompilationUnit unit = parser.parseCompilationUnit(token);
- unit.lineInfo = lineInfo;
- return unit;
+ if (USE_FASTA_PARSER) {
+ try {
+ fasta.ScannerResult scanResult = fasta.scan(_contentBytes);
+
+ var listener = new fasta.AstBuilder(null, null,
+ new _FastaElementStoreProxy(), new _FastaEmptyScope(), uri);
+ var parser = new fasta.Parser(listener);
+ parser.parseUnit(scanResult.tokens);
+ var unit = listener.pop() as CompilationUnit;
+
+ LineInfo lineInfo = new LineInfo(scanResult.lineStarts);
+ unit.lineInfo = lineInfo;
+ return unit;
+ } catch (e, st) {
+ print(e);
+ print(st);
+ rethrow;
+ }
+ } else {
+ CharSequenceReader reader = new CharSequenceReader(content);
+ Scanner scanner = new Scanner(source, reader, errorListener);
+ scanner.scanGenericMethodComments = analysisOptions.strongMode;
+ Token token = scanner.tokenize();
+ LineInfo lineInfo = new LineInfo(scanner.lineStarts);
+
+ Parser parser = new Parser(source, errorListener);
+ parser.enableAssertInitializer = analysisOptions.enableAssertInitializer;
+ parser.parseGenericMethodComments = analysisOptions.strongMode;
+ CompilationUnit unit = parser.parseCompilationUnit(token);
+ unit.lineInfo = lineInfo;
+ return unit;
+ }
}
/**
@@ -376,6 +406,13 @@ class FileState {
_exists = false;
}
+ if (USE_FASTA_PARSER) {
+ var bytes = UTF8.encode(_content);
+ _contentBytes = new Uint8List(bytes.length + 1);
+ _contentBytes.setRange(0, bytes.length, bytes);
+ _contentBytes[_contentBytes.length - 1] = 0;
+ }
+
// Compute the content hash.
List<int> contentBytes = UTF8.encode(_content);
{
@@ -740,3 +777,29 @@ class FileSystemStateTestView {
.toSet();
}
}
+
+class _FastaElementProxy implements fasta.KernelClassElement {
+ @override
+ final fasta.KernelInterfaceType rawType = new _FastaInterfaceTypeProxy();
+
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+}
+
+class _FastaElementStoreProxy implements fasta.ElementStore {
+ final _elements = <fasta.Builder, _FastaElementProxy>{};
+
+ @override
+ _FastaElementProxy operator [](fasta.Builder builder) =>
+ _elements.putIfAbsent(builder, () => new _FastaElementProxy());
+
+ @override
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+}
+
+class _FastaEmptyScope extends fasta.Scope {
+ _FastaEmptyScope() : super({}, null);
+}
+
+class _FastaInterfaceTypeProxy implements fasta.KernelInterfaceType {
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698