2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart = 2.10
6
-
7
5
library dart2js.inferrer.type_graph_dump;
8
6
9
7
import '../../compiler_api.dart' as api;
@@ -70,22 +68,21 @@ class TypeGraphDump {
70
68
Map <MemberEntity , List <TypeInformation >> nodes =
71
69
< MemberEntity , List <TypeInformation >> {};
72
70
for (TypeInformation node in inferrer.types.allTypes) {
73
- if (node.contextMember != null ) {
74
- nodes
75
- .putIfAbsent (node.contextMember, () => < TypeInformation > [])
76
- .add (node);
71
+ final contextMember = node.contextMember;
72
+ if (contextMember != null ) {
73
+ nodes.putIfAbsent (contextMember, () => < TypeInformation > []).add (node);
77
74
}
78
75
}
79
76
// Print every group separately.
80
77
for (MemberEntity element in nodes.keys) {
81
- api.OutputSink output;
78
+ api.OutputSink ? output;
82
79
try {
83
80
String name = filenameFromElement (element);
84
81
output = compilerOutput.createOutputSink (
85
82
'$outputDir /$name ' , 'dot' , api.OutputType .debug);
86
83
_GraphGenerator visitor = _GraphGenerator (
87
84
this , element, output, inferrer.abstractValueDomain.getCompactText);
88
- for (TypeInformation node in nodes[element]) {
85
+ for (TypeInformation node in nodes[element]! ) {
89
86
visitor.visit (node);
90
87
}
91
88
visitor.addMissingNodes ();
@@ -106,22 +103,22 @@ class TypeGraphDump {
106
103
String filenameFromElement (MemberEntity element) {
107
104
// The toString method of elements include characters that are unsuitable
108
105
// for URIs and file systems.
109
- List <String > parts = < String > [];
106
+ List <String ? > parts = [];
110
107
parts.add (element.library.canonicalUri.pathSegments.last);
111
108
parts.add (element.enclosingClass? .name);
112
109
if (element.isGetter) {
113
110
parts.add ('get-${element .name }' );
114
111
} else if (element.isSetter) {
115
112
parts.add ('set-${element .name }' );
116
113
} else if (element.isConstructor) {
117
- if (element.name.isEmpty) {
114
+ if (element.name! .isEmpty) {
118
115
parts.add ('-constructor' );
119
116
} else {
120
117
parts.add (element.name);
121
118
}
122
119
} else {
123
120
parts.add (
124
- utils.operatorNameToIdentifier (element.name).replaceAll (r'$' , '-' ));
121
+ utils.operatorNameToIdentifier (element.name)! .replaceAll (r'$' , '-' ));
125
122
}
126
123
String filename = parts.where ((x) => x != null && x != '' ).join ('.' );
127
124
if (usedFilenames.add (filename)) return filename;
@@ -145,10 +142,10 @@ class _GraphGenerator extends TypeInformationVisitor {
145
142
int usedIds = 0 ;
146
143
final api.OutputSink output;
147
144
final MemberEntity element;
148
- TypeInformation returnValue;
145
+ final TypeInformation returnValue;
149
146
150
- _GraphGenerator (this .global, this .element, this .output, this .formatType) {
151
- returnValue = global.inferrer.types.getInferredTypeOfMember (element);
147
+ _GraphGenerator (this .global, this .element, this .output, this .formatType)
148
+ : returnValue = global.inferrer.types.getInferredTypeOfMember (element) {
152
149
getNode (returnValue); // Ensure return value is part of graph.
153
150
append ('digraph {' );
154
151
}
@@ -210,7 +207,7 @@ class _GraphGenerator extends TypeInformationVisitor {
210
207
/// If [dst] is a record type node, [port] may refer to one of the fields
211
208
/// defined in that record (e.g. `obj` , `arg0` , `arg1` , etc)
212
209
void addEdge (TypeInformation src, TypeInformation dst,
213
- {String port, String color = 'black' }) {
210
+ {String ? port, String ? color = 'black' }) {
214
211
if (isExternal (src) && isExternal (dst)) {
215
212
return ; // Do not add edges between external nodes.
216
213
}
@@ -273,7 +270,7 @@ class _GraphGenerator extends TypeInformationVisitor {
273
270
/// [inputs] specify named inputs to the node. If omitted, edges will be
274
271
/// based on [node.inputs] .
275
272
void addNode (TypeInformation node, String text,
276
- {String color = defaultNodeColor, Map <String , TypeInformation > inputs}) {
273
+ {String color = defaultNodeColor, Map <String , TypeInformation >? inputs}) {
277
274
seen.add (node);
278
275
String style = getStyleForNode (node, color);
279
276
text = appendDetails (node, text);
@@ -286,15 +283,15 @@ class _GraphGenerator extends TypeInformationVisitor {
286
283
String label = '{{$header }|$text |<returnType> $returnType }' ;
287
284
append ('$id [shape=record,label="$label ",$style ]' );
288
285
for (String key in keys) {
289
- addEdge (inputs[key], node, port: 'a$key ' );
286
+ addEdge (inputs[key]! , node, port: 'a$key ' );
290
287
}
291
288
} else {
292
289
String label = '{$text |<returnType> $returnType }' ;
293
290
append ('$id [shape=record,label="$label ",$style ]' );
294
291
// Add assignment edges. Color the edges based on whether they were
295
292
// added, removed, temporary, or unchanged.
296
- dynamic originalSet = global.assignmentsBeforeAnalysis[node] ?? const [] ;
297
- var tracerSet = global.assignmentsBeforeTracing[node] ?? const [] ;
293
+ final originalSet = global.assignmentsBeforeAnalysis[node] ?? const {} ;
294
+ var tracerSet = global.assignmentsBeforeTracing[node] ?? const {} ;
298
295
var currentSet = node.inputs.toSet ();
299
296
for (TypeInformation assignment in currentSet) {
300
297
String color =
@@ -393,12 +390,13 @@ class _GraphGenerator extends TypeInformationVisitor {
393
390
Map <String , TypeInformation > inputs) {
394
391
String sourceCode = shorten ('${info .debugName }' );
395
392
text = '$text \n $sourceCode ' ;
396
- if (info.arguments != null ) {
397
- for (int i = 0 ; i < info.arguments.positional.length; ++ i) {
398
- inputs['arg$i ' ] = info.arguments.positional[i];
393
+ final arguments = info.arguments;
394
+ if (arguments != null ) {
395
+ for (int i = 0 ; i < arguments.positional.length; ++ i) {
396
+ inputs['arg$i ' ] = arguments.positional[i];
399
397
}
400
- for (String argName in info. arguments.named.keys) {
401
- inputs[argName] = info. arguments.named[argName];
398
+ for (String argName in arguments.named.keys) {
399
+ inputs[argName] = arguments.named[argName]! ;
402
400
}
403
401
}
404
402
addNode (info, text, color: callColor, inputs: inputs);
0 commit comments