| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 'package:js_runtime/shared/embedded_names.dart'; | 5 import 'package:js_runtime/shared/embedded_names.dart'; |
| 6 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
| 7 | 7 |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
| 10 import '../compiler.dart'; | 10 import '../compiler.dart'; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 // ConstantExpression constantExpression = | 313 // ConstantExpression constantExpression = |
| 314 // defaultExpression.accept(new Constantifier(this)); | 314 // defaultExpression.accept(new Constantifier(this)); |
| 315 // assert(constantExpression != null); | 315 // assert(constantExpression != null); |
| 316 ConstantExpression constantExpression = | 316 ConstantExpression constantExpression = |
| 317 kernel.parameterInitializerNodeToConstant[defaultExpression]; | 317 kernel.parameterInitializerNodeToConstant[defaultExpression]; |
| 318 if (constantExpression == null) return null; | 318 if (constantExpression == null) return null; |
| 319 return _backend.constants.getConstantValue(constantExpression); | 319 return _backend.constants.getConstantValue(constantExpression); |
| 320 } | 320 } |
| 321 | 321 |
| 322 ConstantValue getConstantForType(ir.DartType irType) { | 322 ConstantValue getConstantForType(ir.DartType irType) { |
| 323 DartType type = getDartType(irType); | 323 ResolutionDartType type = getDartType(irType); |
| 324 return _backend.constantSystem.createType(_compiler, type.asRaw()); | 324 return _backend.constantSystem.createType(_compiler, type.asRaw()); |
| 325 } | 325 } |
| 326 | 326 |
| 327 bool isIntercepted(ir.Node node) { | 327 bool isIntercepted(ir.Node node) { |
| 328 Selector selector = getSelector(node); | 328 Selector selector = getSelector(node); |
| 329 return _backend.isInterceptedSelector(selector); | 329 return _backend.isInterceptedSelector(selector); |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool isInterceptedSelector(Selector selector) { | 332 bool isInterceptedSelector(Selector selector) { |
| 333 return _backend.isInterceptedSelector(selector); | 333 return _backend.isInterceptedSelector(selector); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 assert(constant.fields.length == 1); | 477 assert(constant.fields.length == 1); |
| 478 ConstantValue indexConstant = constant.fields.values.single; | 478 ConstantValue indexConstant = constant.fields.values.single; |
| 479 if (indexConstant is IntConstantValue) { | 479 if (indexConstant is IntConstantValue) { |
| 480 return indexConstant.primitiveValue; | 480 return indexConstant.primitiveValue; |
| 481 } | 481 } |
| 482 } | 482 } |
| 483 } | 483 } |
| 484 return null; | 484 return null; |
| 485 } | 485 } |
| 486 | 486 |
| 487 DartType getDartType(ir.DartType type) { | 487 ResolutionDartType getDartType(ir.DartType type) { |
| 488 return type.accept(_typeConverter); | 488 return type.accept(_typeConverter); |
| 489 } | 489 } |
| 490 | 490 |
| 491 List<DartType> getDartTypes(List<ir.DartType> types) { | 491 List<ResolutionDartType> getDartTypes(List<ir.DartType> types) { |
| 492 return types.map(getDartType).toList(); | 492 return types.map(getDartType).toList(); |
| 493 } | 493 } |
| 494 | 494 |
| 495 DartType getDartTypeOfListLiteral(ir.ListLiteral list) { | 495 ResolutionDartType getDartTypeOfListLiteral(ir.ListLiteral list) { |
| 496 ast.Node node = getNodeOrNull(list); | 496 ast.Node node = getNodeOrNull(list); |
| 497 if (node != null) return elements.getType(node); | 497 if (node != null) return elements.getType(node); |
| 498 assertNodeIsSynthetic(list); | 498 assertNodeIsSynthetic(list); |
| 499 return _compiler.commonElements.listType(getDartType(list.typeArgument)); | 499 return _compiler.commonElements.listType(getDartType(list.typeArgument)); |
| 500 } | 500 } |
| 501 | 501 |
| 502 DartType getDartTypeOfMapLiteral(ir.MapLiteral literal) { | 502 ResolutionDartType getDartTypeOfMapLiteral(ir.MapLiteral literal) { |
| 503 ast.Node node = getNodeOrNull(literal); | 503 ast.Node node = getNodeOrNull(literal); |
| 504 if (node != null) return elements.getType(node); | 504 if (node != null) return elements.getType(node); |
| 505 assertNodeIsSynthetic(literal); | 505 assertNodeIsSynthetic(literal); |
| 506 return _compiler.commonElements | 506 return _compiler.commonElements |
| 507 .mapType(getDartType(literal.keyType), getDartType(literal.valueType)); | 507 .mapType(getDartType(literal.keyType), getDartType(literal.valueType)); |
| 508 } | 508 } |
| 509 | 509 |
| 510 DartType getFunctionReturnType(ir.FunctionNode node) { | 510 ResolutionDartType getFunctionReturnType(ir.FunctionNode node) { |
| 511 return getDartType(node.returnType); | 511 return getDartType(node.returnType); |
| 512 } | 512 } |
| 513 | 513 |
| 514 /// Computes the function type corresponding the signature of [node]. | 514 /// Computes the function type corresponding the signature of [node]. |
| 515 FunctionType getFunctionType(ir.FunctionNode node) { | 515 ResolutionFunctionType getFunctionType(ir.FunctionNode node) { |
| 516 DartType returnType = getFunctionReturnType(node); | 516 ResolutionDartType returnType = getFunctionReturnType(node); |
| 517 List<DartType> parameterTypes = <DartType>[]; | 517 List<ResolutionDartType> parameterTypes = <ResolutionDartType>[]; |
| 518 List<DartType> optionalParameterTypes = <DartType>[]; | 518 List<ResolutionDartType> optionalParameterTypes = <ResolutionDartType>[]; |
| 519 for (ir.VariableDeclaration variable in node.positionalParameters) { | 519 for (ir.VariableDeclaration variable in node.positionalParameters) { |
| 520 if (parameterTypes.length == node.requiredParameterCount) { | 520 if (parameterTypes.length == node.requiredParameterCount) { |
| 521 optionalParameterTypes.add(getDartType(variable.type)); | 521 optionalParameterTypes.add(getDartType(variable.type)); |
| 522 } else { | 522 } else { |
| 523 parameterTypes.add(getDartType(variable.type)); | 523 parameterTypes.add(getDartType(variable.type)); |
| 524 } | 524 } |
| 525 } | 525 } |
| 526 List<String> namedParameters = <String>[]; | 526 List<String> namedParameters = <String>[]; |
| 527 List<DartType> namedParameterTypes = <DartType>[]; | 527 List<ResolutionDartType> namedParameterTypes = <ResolutionDartType>[]; |
| 528 List<ir.VariableDeclaration> sortedNamedParameters = | 528 List<ir.VariableDeclaration> sortedNamedParameters = |
| 529 node.namedParameters.toList()..sort((a, b) => a.name.compareTo(b.name)); | 529 node.namedParameters.toList()..sort((a, b) => a.name.compareTo(b.name)); |
| 530 for (ir.VariableDeclaration variable in sortedNamedParameters) { | 530 for (ir.VariableDeclaration variable in sortedNamedParameters) { |
| 531 namedParameters.add(variable.name); | 531 namedParameters.add(variable.name); |
| 532 namedParameterTypes.add(getDartType(variable.type)); | 532 namedParameterTypes.add(getDartType(variable.type)); |
| 533 } | 533 } |
| 534 return new FunctionType.synthesized(returnType, parameterTypes, | 534 return new ResolutionFunctionType.synthesized(returnType, parameterTypes, |
| 535 optionalParameterTypes, namedParameters, namedParameterTypes); | 535 optionalParameterTypes, namedParameters, namedParameterTypes); |
| 536 } | 536 } |
| 537 | 537 |
| 538 /// Converts [annotations] into a list of [ConstantExpression]s. | 538 /// Converts [annotations] into a list of [ConstantExpression]s. |
| 539 List<ConstantExpression> getMetadata(List<ir.Expression> annotations) { | 539 List<ConstantExpression> getMetadata(List<ir.Expression> annotations) { |
| 540 List<ConstantExpression> metadata = <ConstantExpression>[]; | 540 List<ConstantExpression> metadata = <ConstantExpression>[]; |
| 541 annotations.forEach((ir.Expression node) { | 541 annotations.forEach((ir.Expression node) { |
| 542 ConstantExpression constant = node.accept(new Constantifier(this)); | 542 ConstantExpression constant = node.accept(new Constantifier(this)); |
| 543 if (constant == null) { | 543 if (constant == null) { |
| 544 throw new UnsupportedError( | 544 throw new UnsupportedError( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 565 } | 565 } |
| 566 return ForeignKind.NONE; | 566 return ForeignKind.NONE; |
| 567 } | 567 } |
| 568 | 568 |
| 569 /// Return `true` if [node] is the `dart:_foreign_helper` library. | 569 /// Return `true` if [node] is the `dart:_foreign_helper` library. |
| 570 bool isForeignLibrary(ir.Library node) { | 570 bool isForeignLibrary(ir.Library node) { |
| 571 return node.importUri == BackendHelpers.DART_FOREIGN_HELPER; | 571 return node.importUri == BackendHelpers.DART_FOREIGN_HELPER; |
| 572 } | 572 } |
| 573 | 573 |
| 574 /// Looks up [typeName] for use in the spec-string of a `JS` called. | 574 /// Looks up [typeName] for use in the spec-string of a `JS` called. |
| 575 // TODO(johnniwinther): Use this in [native.NativeBehavior] instead of calling
the | 575 // TODO(johnniwinther): Use this in [native.NativeBehavior] instead of calling |
| 576 // `ForeignResolver`. | 576 // the `ForeignResolver`. |
| 577 // TODO(johnniwinther): Cache the result to avoid redundant lookups? | 577 // TODO(johnniwinther): Cache the result to avoid redundant lookups? |
| 578 native.TypeLookup _typeLookup({bool resolveAsRaw: true}) { | 578 native.TypeLookup _typeLookup({bool resolveAsRaw: true}) { |
| 579 return (String typeName) { | 579 return (String typeName) { |
| 580 DartType findIn(Uri uri) { | 580 ResolutionDartType findIn(Uri uri) { |
| 581 LibraryElement library = _compiler.libraryLoader.lookupLibrary(uri); | 581 LibraryElement library = _compiler.libraryLoader.lookupLibrary(uri); |
| 582 if (library != null) { | 582 if (library != null) { |
| 583 Element element = library.find(typeName); | 583 Element element = library.find(typeName); |
| 584 if (element != null && element.isClass) { | 584 if (element != null && element.isClass) { |
| 585 ClassElement cls = element; | 585 ClassElement cls = element; |
| 586 // TODO(johnniwinther): Align semantics. | 586 // TODO(johnniwinther): Align semantics. |
| 587 return resolveAsRaw ? cls.rawType : cls.thisType; | 587 return resolveAsRaw ? cls.rawType : cls.thisType; |
| 588 } | 588 } |
| 589 } | 589 } |
| 590 return null; | 590 return null; |
| 591 } | 591 } |
| 592 | 592 |
| 593 DartType type = findIn(Uris.dart_core); | 593 ResolutionDartType type = findIn(Uris.dart_core); |
| 594 type ??= findIn(BackendHelpers.DART_JS_HELPER); | 594 type ??= findIn(BackendHelpers.DART_JS_HELPER); |
| 595 type ??= findIn(BackendHelpers.DART_INTERCEPTORS); | 595 type ??= findIn(BackendHelpers.DART_INTERCEPTORS); |
| 596 type ??= findIn(BackendHelpers.DART_ISOLATE_HELPER); | 596 type ??= findIn(BackendHelpers.DART_ISOLATE_HELPER); |
| 597 type ??= findIn(Uris.dart_collection); | 597 type ??= findIn(Uris.dart_collection); |
| 598 type ??= findIn(Uris.dart_html); | 598 type ??= findIn(Uris.dart_html); |
| 599 type ??= findIn(Uris.dart_svg); | 599 type ??= findIn(Uris.dart_svg); |
| 600 type ??= findIn(Uris.dart_web_audio); | 600 type ??= findIn(Uris.dart_web_audio); |
| 601 type ??= findIn(Uris.dart_web_gl); | 601 type ??= findIn(Uris.dart_web_gl); |
| 602 return type; | 602 return type; |
| 603 }; | 603 }; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 632 | 632 |
| 633 return native.NativeBehavior.ofJsCall( | 633 return native.NativeBehavior.ofJsCall( |
| 634 specString, | 634 specString, |
| 635 codeString, | 635 codeString, |
| 636 _typeLookup(resolveAsRaw: true), | 636 _typeLookup(resolveAsRaw: true), |
| 637 CURRENT_ELEMENT_SPANNABLE, | 637 CURRENT_ELEMENT_SPANNABLE, |
| 638 reporter, | 638 reporter, |
| 639 _compiler.commonElements); | 639 _compiler.commonElements); |
| 640 } | 640 } |
| 641 | 641 |
| 642 /// Computes the [native.NativeBehavior] for a call to the [JS_BUILTIN] functi
on. | 642 /// Computes the [native.NativeBehavior] for a call to the [JS_BUILTIN] |
| 643 /// function. |
| 643 // TODO(johnniwinther): Cache this for later use. | 644 // TODO(johnniwinther): Cache this for later use. |
| 644 native.NativeBehavior getNativeBehaviorForJsBuiltinCall( | 645 native.NativeBehavior getNativeBehaviorForJsBuiltinCall( |
| 645 ir.StaticInvocation node) { | 646 ir.StaticInvocation node) { |
| 646 if (node.arguments.positional.length < 1) { | 647 if (node.arguments.positional.length < 1) { |
| 647 reporter.internalError( | 648 reporter.internalError( |
| 648 CURRENT_ELEMENT_SPANNABLE, "JS builtin expression has no type."); | 649 CURRENT_ELEMENT_SPANNABLE, "JS builtin expression has no type."); |
| 649 return new native.NativeBehavior(); | 650 return new native.NativeBehavior(); |
| 650 } | 651 } |
| 651 if (node.arguments.positional.length < 2) { | 652 if (node.arguments.positional.length < 2) { |
| 652 reporter.internalError( | 653 reporter.internalError( |
| 653 CURRENT_ELEMENT_SPANNABLE, "JS builtin is missing name."); | 654 CURRENT_ELEMENT_SPANNABLE, "JS builtin is missing name."); |
| 654 return new native.NativeBehavior(); | 655 return new native.NativeBehavior(); |
| 655 } | 656 } |
| 656 String specString = _getStringArgument(node, 0); | 657 String specString = _getStringArgument(node, 0); |
| 657 if (specString == null) { | 658 if (specString == null) { |
| 658 reporter.internalError( | 659 reporter.internalError( |
| 659 CURRENT_ELEMENT_SPANNABLE, "Unexpected first argument."); | 660 CURRENT_ELEMENT_SPANNABLE, "Unexpected first argument."); |
| 660 return new native.NativeBehavior(); | 661 return new native.NativeBehavior(); |
| 661 } | 662 } |
| 662 return native.NativeBehavior.ofJsBuiltinCall( | 663 return native.NativeBehavior.ofJsBuiltinCall( |
| 663 specString, | 664 specString, |
| 664 _typeLookup(resolveAsRaw: true), | 665 _typeLookup(resolveAsRaw: true), |
| 665 CURRENT_ELEMENT_SPANNABLE, | 666 CURRENT_ELEMENT_SPANNABLE, |
| 666 reporter, | 667 reporter, |
| 667 _compiler.commonElements); | 668 _compiler.commonElements); |
| 668 } | 669 } |
| 669 | 670 |
| 670 /// Computes the [native.NativeBehavior] for a call to the [JS_EMBEDDED_GLOBAL
] | 671 /// Computes the [native.NativeBehavior] for a call to the |
| 671 /// function. | 672 /// [JS_EMBEDDED_GLOBAL] function. |
| 672 // TODO(johnniwinther): Cache this for later use. | 673 // TODO(johnniwinther): Cache this for later use. |
| 673 native.NativeBehavior getNativeBehaviorForJsEmbeddedGlobalCall( | 674 native.NativeBehavior getNativeBehaviorForJsEmbeddedGlobalCall( |
| 674 ir.StaticInvocation node) { | 675 ir.StaticInvocation node) { |
| 675 if (node.arguments.positional.length < 1) { | 676 if (node.arguments.positional.length < 1) { |
| 676 reporter.internalError(CURRENT_ELEMENT_SPANNABLE, | 677 reporter.internalError(CURRENT_ELEMENT_SPANNABLE, |
| 677 "JS embedded global expression has no type."); | 678 "JS embedded global expression has no type."); |
| 678 return new native.NativeBehavior(); | 679 return new native.NativeBehavior(); |
| 679 } | 680 } |
| 680 if (node.arguments.positional.length < 2) { | 681 if (node.arguments.positional.length < 2) { |
| 681 reporter.internalError( | 682 reporter.internalError( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 return true; | 714 return true; |
| 714 } | 715 } |
| 715 } | 716 } |
| 716 } | 717 } |
| 717 return false; | 718 return false; |
| 718 } | 719 } |
| 719 | 720 |
| 720 /// Computes the native behavior for reading the native [field]. | 721 /// Computes the native behavior for reading the native [field]. |
| 721 // TODO(johnniwinther): Cache this for later use. | 722 // TODO(johnniwinther): Cache this for later use. |
| 722 native.NativeBehavior getNativeBehaviorForFieldLoad(ir.Field field) { | 723 native.NativeBehavior getNativeBehaviorForFieldLoad(ir.Field field) { |
| 723 DartType type = getDartType(field.type); | 724 ResolutionDartType type = getDartType(field.type); |
| 724 List<ConstantExpression> metadata = getMetadata(field.annotations); | 725 List<ConstantExpression> metadata = getMetadata(field.annotations); |
| 725 return native.NativeBehavior.ofFieldLoad(CURRENT_ELEMENT_SPANNABLE, type, | 726 return native.NativeBehavior.ofFieldLoad(CURRENT_ELEMENT_SPANNABLE, type, |
| 726 metadata, _typeLookup(resolveAsRaw: false), _compiler, | 727 metadata, _typeLookup(resolveAsRaw: false), _compiler, |
| 727 isJsInterop: false); | 728 isJsInterop: false); |
| 728 } | 729 } |
| 729 | 730 |
| 730 /// Computes the native behavior for writing to the native [field]. | 731 /// Computes the native behavior for writing to the native [field]. |
| 731 // TODO(johnniwinther): Cache this for later use. | 732 // TODO(johnniwinther): Cache this for later use. |
| 732 native.NativeBehavior getNativeBehaviorForFieldStore(ir.Field field) { | 733 native.NativeBehavior getNativeBehaviorForFieldStore(ir.Field field) { |
| 733 DartType type = getDartType(field.type); | 734 ResolutionDartType type = getDartType(field.type); |
| 734 return native.NativeBehavior.ofFieldStore(type, _compiler.resolution); | 735 return native.NativeBehavior.ofFieldStore(type, _compiler.resolution); |
| 735 } | 736 } |
| 736 | 737 |
| 737 /// Computes the native behavior for calling [procedure]. | 738 /// Computes the native behavior for calling [procedure]. |
| 738 // TODO(johnniwinther): Cache this for later use. | 739 // TODO(johnniwinther): Cache this for later use. |
| 739 native.NativeBehavior getNativeBehaviorForMethod(ir.Procedure procedure) { | 740 native.NativeBehavior getNativeBehaviorForMethod(ir.Procedure procedure) { |
| 740 DartType type = getFunctionType(procedure.function); | 741 ResolutionDartType type = getFunctionType(procedure.function); |
| 741 List<ConstantExpression> metadata = getMetadata(procedure.annotations); | 742 List<ConstantExpression> metadata = getMetadata(procedure.annotations); |
| 742 return native.NativeBehavior.ofMethod(CURRENT_ELEMENT_SPANNABLE, type, | 743 return native.NativeBehavior.ofMethod(CURRENT_ELEMENT_SPANNABLE, type, |
| 743 metadata, _typeLookup(resolveAsRaw: false), _compiler, | 744 metadata, _typeLookup(resolveAsRaw: false), _compiler, |
| 744 isJsInterop: false); | 745 isJsInterop: false); |
| 745 } | 746 } |
| 746 } | 747 } |
| 747 | 748 |
| 748 /// Kinds of foreign functions. | 749 /// Kinds of foreign functions. |
| 749 enum ForeignKind { | 750 enum ForeignKind { |
| 750 JS, | 751 JS, |
| 751 JS_BUILTIN, | 752 JS_BUILTIN, |
| 752 JS_EMBEDDED_GLOBAL, | 753 JS_EMBEDDED_GLOBAL, |
| 753 JS_INTERCEPTOR_CONSTANT, | 754 JS_INTERCEPTOR_CONSTANT, |
| 754 NONE, | 755 NONE, |
| 755 } | 756 } |
| 756 | 757 |
| 757 /// Visitor that converts kernel dart types into [DartType]. | 758 /// Visitor that converts kernel dart types into [ResolutionDartType]. |
| 758 class DartTypeConverter extends ir.DartTypeVisitor<DartType> { | 759 class DartTypeConverter extends ir.DartTypeVisitor<ResolutionDartType> { |
| 759 final KernelAstAdapter astAdapter; | 760 final KernelAstAdapter astAdapter; |
| 760 | 761 |
| 761 DartTypeConverter(this.astAdapter); | 762 DartTypeConverter(this.astAdapter); |
| 762 | 763 |
| 763 DartType visitType(ir.DartType type) => type.accept(this); | 764 ResolutionDartType visitType(ir.DartType type) => type.accept(this); |
| 764 | 765 |
| 765 List<DartType> visitTypes(List<ir.DartType> types) { | 766 List<ResolutionDartType> visitTypes(List<ir.DartType> types) { |
| 766 return new List.generate( | 767 return new List.generate( |
| 767 types.length, (int index) => types[index].accept(this)); | 768 types.length, (int index) => types[index].accept(this)); |
| 768 } | 769 } |
| 769 | 770 |
| 770 @override | 771 @override |
| 771 DartType visitTypeParameterType(ir.TypeParameterType node) { | 772 ResolutionDartType visitTypeParameterType(ir.TypeParameterType node) { |
| 772 if (node.parameter.parent is ir.Class) { | 773 if (node.parameter.parent is ir.Class) { |
| 773 ir.Class cls = node.parameter.parent; | 774 ir.Class cls = node.parameter.parent; |
| 774 int index = cls.typeParameters.indexOf(node.parameter); | 775 int index = cls.typeParameters.indexOf(node.parameter); |
| 775 ClassElement classElement = astAdapter.getElement(cls); | 776 ClassElement classElement = astAdapter.getElement(cls); |
| 776 return classElement.typeVariables[index]; | 777 return classElement.typeVariables[index]; |
| 777 } else if (node.parameter.parent is ir.FunctionNode) { | 778 } else if (node.parameter.parent is ir.FunctionNode) { |
| 778 ir.FunctionNode func = node.parameter.parent; | 779 ir.FunctionNode func = node.parameter.parent; |
| 779 int index = func.typeParameters.indexOf(node.parameter); | 780 int index = func.typeParameters.indexOf(node.parameter); |
| 780 Element element = astAdapter.getElement(func); | 781 Element element = astAdapter.getElement(func); |
| 781 if (element.isConstructor) { | 782 if (element.isConstructor) { |
| 782 ClassElement classElement = element.enclosingClass; | 783 ClassElement classElement = element.enclosingClass; |
| 783 return classElement.typeVariables[index]; | 784 return classElement.typeVariables[index]; |
| 784 } else { | 785 } else { |
| 785 GenericElement genericElement = element; | 786 GenericElement genericElement = element; |
| 786 return genericElement.typeVariables[index]; | 787 return genericElement.typeVariables[index]; |
| 787 } | 788 } |
| 788 } | 789 } |
| 789 throw new UnsupportedError('Unsupported type parameter type node $node.'); | 790 throw new UnsupportedError('Unsupported type parameter type node $node.'); |
| 790 } | 791 } |
| 791 | 792 |
| 792 @override | 793 @override |
| 793 DartType visitFunctionType(ir.FunctionType node) { | 794 ResolutionDartType visitFunctionType(ir.FunctionType node) { |
| 794 return new FunctionType.synthesized( | 795 return new ResolutionFunctionType.synthesized( |
| 795 visitType(node.returnType), | 796 visitType(node.returnType), |
| 796 visitTypes(node.positionalParameters | 797 visitTypes(node.positionalParameters |
| 797 .take(node.requiredParameterCount) | 798 .take(node.requiredParameterCount) |
| 798 .toList()), | 799 .toList()), |
| 799 visitTypes(node.positionalParameters | 800 visitTypes(node.positionalParameters |
| 800 .skip(node.requiredParameterCount) | 801 .skip(node.requiredParameterCount) |
| 801 .toList()), | 802 .toList()), |
| 802 node.namedParameters.map((n) => n.name).toList(), | 803 node.namedParameters.map((n) => n.name).toList(), |
| 803 node.namedParameters.map((n) => visitType(n.type)).toList()); | 804 node.namedParameters.map((n) => visitType(n.type)).toList()); |
| 804 } | 805 } |
| 805 | 806 |
| 806 @override | 807 @override |
| 807 DartType visitInterfaceType(ir.InterfaceType node) { | 808 ResolutionDartType visitInterfaceType(ir.InterfaceType node) { |
| 808 ClassElement cls = astAdapter.getElement(node.classNode); | 809 ClassElement cls = astAdapter.getElement(node.classNode); |
| 809 return new InterfaceType(cls, visitTypes(node.typeArguments)); | 810 return new ResolutionInterfaceType(cls, visitTypes(node.typeArguments)); |
| 810 } | 811 } |
| 811 | 812 |
| 812 @override | 813 @override |
| 813 DartType visitVoidType(ir.VoidType node) { | 814 ResolutionDartType visitVoidType(ir.VoidType node) { |
| 814 return const VoidType(); | 815 return const ResolutionVoidType(); |
| 815 } | 816 } |
| 816 | 817 |
| 817 @override | 818 @override |
| 818 DartType visitDynamicType(ir.DynamicType node) { | 819 ResolutionDartType visitDynamicType(ir.DynamicType node) { |
| 819 return const DynamicType(); | 820 return const ResolutionDynamicType(); |
| 820 } | 821 } |
| 821 | 822 |
| 822 @override | 823 @override |
| 823 DartType visitInvalidType(ir.InvalidType node) { | 824 ResolutionDartType visitInvalidType(ir.InvalidType node) { |
| 824 throw new UnimplementedError("Invalid types not currently supported"); | 825 throw new UnimplementedError("Invalid types not currently supported"); |
| 825 } | 826 } |
| 826 } | 827 } |
| 827 | 828 |
| 828 /// Visitor that converts string literals and concatenations of string literals | 829 /// Visitor that converts string literals and concatenations of string literals |
| 829 /// into the string value. | 830 /// into the string value. |
| 830 class Stringifier extends ir.ExpressionVisitor<String> { | 831 class Stringifier extends ir.ExpressionVisitor<String> { |
| 831 @override | 832 @override |
| 832 String visitStringLiteral(ir.StringLiteral node) => node.value; | 833 String visitStringLiteral(ir.StringLiteral node) => node.value; |
| 833 | 834 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 847 /// [ConstantExpression]. | 848 /// [ConstantExpression]. |
| 848 class Constantifier extends ir.ExpressionVisitor<ConstantExpression> { | 849 class Constantifier extends ir.ExpressionVisitor<ConstantExpression> { |
| 849 final KernelAstAdapter astAdapter; | 850 final KernelAstAdapter astAdapter; |
| 850 | 851 |
| 851 Constantifier(this.astAdapter); | 852 Constantifier(this.astAdapter); |
| 852 | 853 |
| 853 @override | 854 @override |
| 854 ConstantExpression visitConstructorInvocation(ir.ConstructorInvocation node) { | 855 ConstantExpression visitConstructorInvocation(ir.ConstructorInvocation node) { |
| 855 ConstructorElement constructor = | 856 ConstructorElement constructor = |
| 856 astAdapter.getElement(node.target).declaration; | 857 astAdapter.getElement(node.target).declaration; |
| 857 List<DartType> typeArguments = <DartType>[]; | 858 List<ResolutionDartType> typeArguments = <ResolutionDartType>[]; |
| 858 for (ir.DartType type in node.arguments.types) { | 859 for (ir.DartType type in node.arguments.types) { |
| 859 typeArguments.add(astAdapter.getDartType(type)); | 860 typeArguments.add(astAdapter.getDartType(type)); |
| 860 } | 861 } |
| 861 List<ConstantExpression> arguments = <ConstantExpression>[]; | 862 List<ConstantExpression> arguments = <ConstantExpression>[]; |
| 862 List<String> argumentNames = <String>[]; | 863 List<String> argumentNames = <String>[]; |
| 863 for (ir.Expression argument in node.arguments.positional) { | 864 for (ir.Expression argument in node.arguments.positional) { |
| 864 ConstantExpression constant = argument.accept(this); | 865 ConstantExpression constant = argument.accept(this); |
| 865 if (constant == null) return null; | 866 if (constant == null) return null; |
| 866 arguments.add(constant); | 867 arguments.add(constant); |
| 867 } | 868 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 | 942 |
| 942 @override | 943 @override |
| 943 String get name => null; | 944 String get name => null; |
| 944 | 945 |
| 945 @override | 946 @override |
| 946 int get nestingLevel => 1; | 947 int get nestingLevel => 1; |
| 947 | 948 |
| 948 @override | 949 @override |
| 949 ast.Node get statement => null; | 950 ast.Node get statement => null; |
| 950 } | 951 } |
| OLD | NEW |