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

Side by Side Diff: pkg/analyzer/lib/src/fasta/resolution_applier.dart

Issue 2981693002: Start copying resolution/inference data from front end to analyzer ASTs. (Closed)
Patch Set: Address code review comments. Created 3 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/visitor.dart';
7 import 'package:analyzer/dart/element/type.dart';
8
9 /// Visitor that applies resolution data from the front end (obtained via
10 /// [ResolutionStorer]) to an analyzer AST.
11 class ResolutionApplier extends GeneralizingAstVisitor {
12 final List<DartType> _types;
13 int _typeIndex = 0;
14
15 ResolutionApplier(this._types);
16
17 /// Verifies that all types passed to the constructor have been applied.
18 void checkDone() {
19 if (_typeIndex != _types.length) {
20 throw new StateError(
21 'Some types were not consumed, starting at ${_types[_typeIndex]}');
22 }
23 }
24
25 @override
26 void visitExpression(Expression node) {
27 visitNode(node);
28 node.staticType = _getTypeFor(node);
29 }
30
31 @override
32 void visitMethodInvocation(MethodInvocation node) {
33 node.target?.accept(this);
34 // TODO(paulberry): store resolution of node.methodName.
35 // TODO(paulberry): store resolution of node.typeArguments.
36 node.argumentList.accept(this);
37 node.staticType = _getTypeFor(node);
38 }
39
40 DartType _getTypeFor(Expression node) {
41 return _types[_typeIndex++];
42 }
43 }
44
45 /// Visitor that applies resolution data from the front end (obtained via
46 /// [ResolutionStorer]) to an analyzer AST, and also checks file offsets to
47 /// verify that the types are applied to the correct subexpressions.
48 class ValidatingResolutionApplier extends ResolutionApplier {
49 /// Indicates whether debug messages should be printed.
50 static const bool _debug = false;
51
52 final List<int> _typeOffsets;
53
54 ValidatingResolutionApplier(List<DartType> types, this._typeOffsets)
55 : super(types);
56
57 @override
58 void checkDone() {
59 if (_typeIndex != _types.length) {
60 throw new StateError('Some types were not consumed, starting at offset '
61 '${_typeOffsets[_typeIndex]}');
62 }
63 }
64
65 @override
66 DartType _getTypeFor(Expression node) {
67 if (_debug) print('Getting type for $node');
68 if (node.offset != _typeOffsets[_typeIndex]) {
69 throw new StateError(
70 'Expected a type for offset ${node.offset}; got one for '
71 '${_typeOffsets[_typeIndex]}');
72 }
73 return super._getTypeFor(node);
74 }
75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698