OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Encapsulates how to invoke the analyzer resolver and overrides how it | 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it |
6 /// computes types on expressions to use our restricted set of types. | 6 /// computes types on expressions to use our restricted set of types. |
7 library ddc.src.checker.resolver; | 7 library ddc.src.checker.resolver; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 // otherLib.visibleLibraries.contains(thisLib), however because we are not | 356 // otherLib.visibleLibraries.contains(thisLib), however because we are not |
357 // inferring type on any library that belongs to a cycle or that contains | 357 // inferring type on any library that belongs to a cycle or that contains |
358 // parts, we know that this cannot be true. | 358 // parts, we know that this cannot be true. |
359 return thisLib == otherLib; | 359 return thisLib == otherLib; |
360 } | 360 } |
361 | 361 |
362 @override // to propagate types to identifiers | 362 @override // to propagate types to identifiers |
363 visitMethodInvocation(MethodInvocation node) { | 363 visitMethodInvocation(MethodInvocation node) { |
364 // TODO(sigmund): follow up with analyzer team - why is this needed? | 364 // TODO(sigmund): follow up with analyzer team - why is this needed? |
365 visitSimpleIdentifier(node.methodName); | 365 visitSimpleIdentifier(node.methodName); |
366 return super.visitMethodInvocation(node); | 366 super.visitMethodInvocation(node); |
| 367 |
| 368 var e = node.methodName.staticElement; |
| 369 if (e is FunctionElement && |
| 370 e.library.name == '_foreign_helper' && |
| 371 e.name == 'JS') { |
| 372 // Fix types for JS builtin calls. |
| 373 // |
| 374 // This code was taken from analyzer. It's not super sophisticated: |
| 375 // only looks for the type name in dart:core, so we just copy it here. |
| 376 // |
| 377 // TODO(jmesserly): we'll likely need something that can handle a wider |
| 378 // variety of types, especially when we get to JS interop. |
| 379 var args = node.argumentList.arguments; |
| 380 if (args.isNotEmpty && args.first is SimpleStringLiteral) { |
| 381 var coreLib = _typeProvider.objectType.element.library; |
| 382 var classElem = coreLib.getType(args.first.stringValue); |
| 383 if (classElem != null) node.staticType = classElem.type; |
| 384 } |
| 385 } |
367 } | 386 } |
368 | 387 |
369 // Review note: no longer need to override visitFunctionExpression, this is | 388 // Review note: no longer need to override visitFunctionExpression, this is |
370 // handled by the analyzer internally. | 389 // handled by the analyzer internally. |
371 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 390 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
372 // TODO(vsm): in visitConditionalExpression: check... LUB in rules? | 391 // TODO(vsm): in visitConditionalExpression: check... LUB in rules? |
373 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 392 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
374 // type in a (...) => expr or just the written type? | 393 // type in a (...) => expr or just the written type? |
375 | 394 |
376 } | 395 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 element.returnType.isDynamic && | 438 element.returnType.isDynamic && |
420 node.returnType == null) { | 439 node.returnType == null) { |
421 var type = searchTypeFor(element.enclosingElement.type, element); | 440 var type = searchTypeFor(element.enclosingElement.type, element); |
422 if (type != null && !type.returnType.isDynamic) { | 441 if (type != null && !type.returnType.isDynamic) { |
423 element.returnType = type.returnType; | 442 element.returnType = type.returnType; |
424 } | 443 } |
425 } | 444 } |
426 return res; | 445 return res; |
427 } | 446 } |
428 } | 447 } |
OLD | NEW |