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

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

Issue 2846463003: Instrument analyzer's type analysis and run front_end inference tests. (Closed)
Patch Set: Updates. Created 3 years, 7 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
« no previous file with comments | « pkg/analyzer/lib/src/dart/ast/ast.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import 'package:analyzer/dart/element/element.dart';
2 import 'package:analyzer/dart/element/type.dart';
3 import 'package:front_end/src/base/instrumentation.dart'
4 show Instrumentation, InstrumentationValue;
5
6 /**
7 * Instance of [InstrumentationValue] describing a [DartType].
8 */
9 class InstrumentationValueForType extends InstrumentationValue {
10 final DartType type;
11
12 InstrumentationValueForType(this.type);
13
14 @override
15 String toString() {
16 StringBuffer buffer = new StringBuffer();
17 _appendType(buffer, type);
18 return buffer.toString();
19 }
20
21 void _appendElementName(StringBuffer buffer, Element element) {
22 String name = element.name;
23 String libraryName = element.library.name;
24 if (libraryName == '') {
25 throw new StateError('The element $name must be in a named library.');
26 }
27 if (libraryName != 'dart.core' &&
28 libraryName != 'dart.async' &&
29 libraryName != 'test') {
30 buffer.write('$libraryName::$name');
31 } else {
32 buffer.write('$name');
33 }
34 }
35
36 void _appendList<T>(StringBuffer buffer, String open, String close,
37 List<T> items, String separator, writeItem(T item),
38 {bool includeEmpty: false}) {
39 if (!includeEmpty && items.isEmpty) {
40 return;
41 }
42 buffer.write(open);
43 bool first = true;
44 for (T item in items) {
45 if (!first) {
46 buffer.write(separator);
47 }
48 writeItem(item);
49 first = false;
50 }
51 buffer.write(close);
52 }
53
54 void _appendParameters(
55 StringBuffer buffer, List<ParameterElement> parameters) {
56 _appendList<ParameterElement>(buffer, '(', ')', parameters, ', ',
57 (parameter) {
58 _appendType(buffer, type);
59 buffer.write(' ');
60 buffer.write(parameter.name);
61 }, includeEmpty: true);
62 }
63
64 void _appendType(StringBuffer buffer, DartType type) {
65 if (type == null) {
66 buffer.write('none');
67 } else if (type is FunctionType) {
68 Element element = type.element;
69 _appendElementName(buffer, element);
70 _appendTypeArguments(buffer, type.typeArguments);
71 _appendParameters(buffer, type.parameters);
72 buffer.write(' → ');
73 _appendType(buffer, type.returnType);
74 } else if (type is InterfaceType) {
75 ClassElement element = type.element;
76 _appendElementName(buffer, element);
77 _appendTypeArguments(buffer, type.typeArguments);
78 } else {
79 buffer.write(type.toString());
80 }
81 }
82
83 void _appendTypeArguments(StringBuffer buffer, List<DartType> typeArguments) {
84 _appendList<DartType>(buffer, '<', '>', typeArguments, ', ',
85 (type) => _appendType(buffer, type));
86 }
87 }
88
89 /**
90 * Wrapper around [Instrumentation] for writing analyzer specific values
91 * for a single URI.
92 */
93 class UriInstrumentation {
94 final Instrumentation _instrumentation;
95 final Uri _uri;
96
97 UriInstrumentation(this._instrumentation, this._uri);
98
99 void recordInference(int offset, DartType type) {
100 _instrumentation.record(
101 _uri, offset, 'type', new InstrumentationValueForType(type));
102 }
103
104 void recordPromotion(int offset, DartType type) {
105 _instrumentation.record(
106 _uri, offset, 'promotedType', new InstrumentationValueForType(type));
107 }
108
109 void recordTopType(int offset, DartType type) {
110 _instrumentation.record(
111 _uri, offset, 'topType', new InstrumentationValueForType(type));
112 }
113 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/ast/ast.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698