Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 .where((entry) => entry is File && entry.path.endsWith('.dart')) | 51 .where((entry) => entry is File && entry.path.endsWith('.dart')) |
| 52 .map((entry) => entry as File) | 52 .map((entry) => entry as File) |
| 53 .toList(); | 53 .toList(); |
| 54 | 54 |
| 55 for (File file in dartFiles) { | 55 for (File file in dartFiles) { |
| 56 var test = new _FrontEndInferenceTest(); | 56 var test = new _FrontEndInferenceTest(); |
| 57 await test.setUp(); | 57 await test.setUp(); |
| 58 try { | 58 try { |
| 59 String code = file.readAsStringSync(); | 59 String code = file.readAsStringSync(); |
| 60 await test.runTest(file.path, code); | 60 await test.runTest(file.path, code); |
| 61 } catch (_) { | 61 } catch (_, st) { |
| 62 print(_); | 62 print(_); |
| 63 print(st); | |
| 63 } finally { | 64 } finally { |
| 64 await test.tearDown(); | 65 await test.tearDown(); |
| 65 } | 66 } |
| 66 } | 67 } |
| 67 } | 68 } |
| 68 | 69 |
| 69 class _FrontEndInferenceTest extends BaseAnalysisDriverTest { | 70 class _FrontEndInferenceTest extends BaseAnalysisDriverTest { |
| 70 Future<Null> runTest(String path, String code) async { | 71 Future<Null> runTest(String path, String code) async { |
| 72 // if (!path | |
|
Paul Berry
2017/04/27 21:19:29
Was this left in by accident?
| |
| 73 // .endsWith('downwards_inference_on_generic_function_expressions.dart')) { | |
| 74 // return; | |
| 75 // } | |
| 71 Uri uri = provider.pathContext.toUri(path); | 76 Uri uri = provider.pathContext.toUri(path); |
| 72 | 77 |
| 73 List<int> lineStarts = new LineInfo.fromContent(code).lineStarts; | 78 List<int> lineStarts = new LineInfo.fromContent(code).lineStarts; |
| 74 fasta.CompilerContext.current.uriToSource[uri.toString()] = | 79 fasta.CompilerContext.current.uriToSource[uri.toString()] = |
| 75 new fasta.Source(lineStarts, UTF8.encode(code)); | 80 new fasta.Source(lineStarts, UTF8.encode(code)); |
| 76 | 81 |
| 77 var validation = new fasta.ValidatingInstrumentation(); | 82 var validation = new fasta.ValidatingInstrumentation(); |
| 78 await validation.loadExpectations(uri); | 83 await validation.loadExpectations(uri); |
| 79 | 84 |
| 80 provider.newFile(path, code); | 85 provider.newFile(path, code); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 100 | 105 |
| 101 @override | 106 @override |
| 102 String toString() { | 107 String toString() { |
| 103 StringBuffer buffer = new StringBuffer(); | 108 StringBuffer buffer = new StringBuffer(); |
| 104 _appendType(buffer, type); | 109 _appendType(buffer, type); |
| 105 return buffer.toString(); | 110 return buffer.toString(); |
| 106 } | 111 } |
| 107 | 112 |
| 108 void _appendElementName(StringBuffer buffer, Element element) { | 113 void _appendElementName(StringBuffer buffer, Element element) { |
| 109 String name = element.name; | 114 String name = element.name; |
| 115 if (element.library == null) { | |
| 116 // TODO(scheglov) This is wrong - every element must be in a library. | |
| 117 buffer.write('<unknown>::$name'); | |
| 118 return; | |
| 119 } | |
| 110 String libraryName = element.library.name; | 120 String libraryName = element.library.name; |
| 111 if (libraryName == '') { | 121 if (libraryName == '') { |
| 112 throw new StateError('The element $name must be in a named library.'); | 122 throw new StateError('The element $name must be in a named library.'); |
| 113 } | 123 } |
| 114 if (libraryName != 'dart.core' && | 124 if (libraryName != 'dart.core' && |
| 115 libraryName != 'dart.async' && | 125 libraryName != 'dart.async' && |
| 116 libraryName != 'test') { | 126 libraryName != 'test') { |
| 117 buffer.write('$libraryName::$name'); | 127 buffer.write('$libraryName::$name'); |
| 118 } else { | 128 } else { |
| 119 buffer.write('$name'); | 129 buffer.write('$name'); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 135 writeItem(item); | 145 writeItem(item); |
| 136 first = false; | 146 first = false; |
| 137 } | 147 } |
| 138 buffer.write(close); | 148 buffer.write(close); |
| 139 } | 149 } |
| 140 | 150 |
| 141 void _appendParameters( | 151 void _appendParameters( |
| 142 StringBuffer buffer, List<ParameterElement> parameters) { | 152 StringBuffer buffer, List<ParameterElement> parameters) { |
| 143 _appendList<ParameterElement>(buffer, '(', ')', parameters, ', ', | 153 _appendList<ParameterElement>(buffer, '(', ')', parameters, ', ', |
| 144 (parameter) { | 154 (parameter) { |
| 145 _appendType(buffer, type); | 155 _appendType(buffer, parameter.type); |
| 146 buffer.write(' '); | 156 buffer.write(' '); |
| 147 buffer.write(parameter.name); | 157 buffer.write(parameter.name); |
| 148 }, includeEmpty: true); | 158 }, includeEmpty: true); |
| 149 } | 159 } |
| 150 | 160 |
| 151 void _appendType(StringBuffer buffer, DartType type) { | 161 void _appendType(StringBuffer buffer, DartType type) { |
| 152 if (type is FunctionType) { | 162 if (type is FunctionType) { |
| 153 Element element = type.element; | 163 Element element = type.element; |
| 154 _appendElementName(buffer, element); | 164 _appendElementName(buffer, element); |
| 155 _appendTypeArguments(buffer, type.typeArguments); | 165 _appendTypeArguments(buffer, type.typeArguments); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 super.visitInstanceCreationExpression(node); | 226 super.visitInstanceCreationExpression(node); |
| 217 DartType type = node.staticType; | 227 DartType type = node.staticType; |
| 218 if (type is InterfaceType) { | 228 if (type is InterfaceType) { |
| 219 if (type.typeParameters.isNotEmpty && | 229 if (type.typeParameters.isNotEmpty && |
| 220 node.constructorName.type.typeArguments == null) { | 230 node.constructorName.type.typeArguments == null) { |
| 221 _recordTypeArguments(node.offset, type.typeArguments); | 231 _recordTypeArguments(node.offset, type.typeArguments); |
| 222 } | 232 } |
| 223 } | 233 } |
| 224 } | 234 } |
| 225 | 235 |
| 236 visitListLiteral(ListLiteral node) { | |
| 237 super.visitListLiteral(node); | |
| 238 if (node.typeArguments == null) { | |
| 239 DartType type = node.staticType; | |
| 240 if (type is InterfaceType) { | |
| 241 _recordTypeArguments(node.offset, type.typeArguments); | |
| 242 } | |
| 243 } | |
| 244 } | |
| 245 | |
| 246 visitMapLiteral(MapLiteral node) { | |
| 247 super.visitMapLiteral(node); | |
| 248 if (node.typeArguments == null) { | |
| 249 DartType type = node.staticType; | |
| 250 if (type is InterfaceType) { | |
| 251 _recordTypeArguments(node.offset, type.typeArguments); | |
| 252 } | |
| 253 } | |
| 254 } | |
| 255 | |
| 226 visitSimpleIdentifier(SimpleIdentifier node) { | 256 visitSimpleIdentifier(SimpleIdentifier node) { |
| 227 super.visitSimpleIdentifier(node); | 257 super.visitSimpleIdentifier(node); |
| 228 Element element = node.staticElement; | 258 Element element = node.staticElement; |
| 229 if (element is LocalVariableElement && node.inGetterContext()) { | 259 if (element is LocalVariableElement && node.inGetterContext()) { |
| 230 int offset = node.offset; | 260 int offset = node.offset; |
| 231 DartType type = node.staticType; | 261 DartType type = node.staticType; |
| 232 if (identical(type, element.type)) { | 262 if (identical(type, element.type)) { |
| 233 _instrumentation.record(uri, offset, 'promotedType', | 263 _instrumentation.record(uri, offset, 'promotedType', |
| 234 const fasta.InstrumentationValueLiteral('none')); | 264 const fasta.InstrumentationValueLiteral('none')); |
| 235 } else { | 265 } else { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 261 void _recordType(int offset, DartType type) { | 291 void _recordType(int offset, DartType type) { |
| 262 _instrumentation.record( | 292 _instrumentation.record( |
| 263 uri, offset, 'type', new _InstrumentationValueForType(type)); | 293 uri, offset, 'type', new _InstrumentationValueForType(type)); |
| 264 } | 294 } |
| 265 | 295 |
| 266 void _recordTypeArguments(int offset, List<DartType> typeArguments) { | 296 void _recordTypeArguments(int offset, List<DartType> typeArguments) { |
| 267 _instrumentation.record(uri, offset, 'typeArgs', | 297 _instrumentation.record(uri, offset, 'typeArgs', |
| 268 new _InstrumentationValueForTypeArgs(typeArguments)); | 298 new _InstrumentationValueForTypeArgs(typeArguments)); |
| 269 } | 299 } |
| 270 } | 300 } |
| OLD | NEW |