Chromium Code Reviews| 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 /// ----------------------------------------------------------------------- | 5 /// ----------------------------------------------------------------------- |
| 6 /// ERROR HANDLING | 6 /// ERROR HANDLING |
| 7 /// ----------------------------------------------------------------------- | 7 /// ----------------------------------------------------------------------- |
| 8 /// | 8 /// |
| 9 /// As a rule of thumb, errors that can be detected statically are handled by | 9 /// As a rule of thumb, errors that can be detected statically are handled by |
| 10 /// the frontend, typically by translating the erroneous code into a 'throw' or | 10 /// the frontend, typically by translating the erroneous code into a 'throw' or |
| (...skipping 2732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2743 return types.objectType; | 2743 return types.objectType; |
| 2744 } | 2744 } |
| 2745 | 2745 |
| 2746 accept(ExpressionVisitor v) => v.visitCheckLibraryIsLoaded(this); | 2746 accept(ExpressionVisitor v) => v.visitCheckLibraryIsLoaded(this); |
| 2747 accept1(ExpressionVisitor1 v, arg) => v.visitCheckLibraryIsLoaded(this, arg); | 2747 accept1(ExpressionVisitor1 v, arg) => v.visitCheckLibraryIsLoaded(this, arg); |
| 2748 | 2748 |
| 2749 visitChildren(Visitor v) {} | 2749 visitChildren(Visitor v) {} |
| 2750 transformChildren(Transformer v) {} | 2750 transformChildren(Transformer v) {} |
| 2751 } | 2751 } |
| 2752 | 2752 |
| 2753 /// Expression of the form `MakeVector(N)` where `N` is an integer representing | |
| 2754 /// the length of the vector. | |
| 2755 /// | |
| 2756 /// For detailed comment about Vectors see [VectorType]. | |
| 2757 class VectorCreation extends Expression { | |
| 2758 int length; | |
| 2759 | |
| 2760 VectorCreation(this.length); | |
| 2761 | |
| 2762 accept(ExpressionVisitor v) => v.visitVectorCreation(this); | |
| 2763 accept1(ExpressionVisitor1 v, arg) => v.visitVectorCreation(this, arg); | |
| 2764 | |
| 2765 visitChildren(Visitor v) {} | |
| 2766 | |
| 2767 transformChildren(Transformer v) {} | |
| 2768 | |
| 2769 DartType getStaticType(TypeEnvironment types) { | |
| 2770 return const VectorType(); | |
| 2771 } | |
| 2772 } | |
| 2773 | |
| 2774 /// Expression of the form `v[i]` where `v` is a vector expression, and `i` is | |
| 2775 /// an integer index. | |
| 2776 class VectorGet extends Expression { | |
| 2777 Expression vectorExpression; | |
| 2778 int index; | |
| 2779 | |
| 2780 VectorGet(this.vectorExpression, this.index) { | |
| 2781 vectorExpression?.parent = this; | |
| 2782 } | |
| 2783 | |
| 2784 accept(ExpressionVisitor v) => v.visitVectorGet(this); | |
| 2785 accept1(ExpressionVisitor1 v, arg) => v.visitVectorGet(this, arg); | |
| 2786 | |
| 2787 visitChildren(Visitor v) { | |
| 2788 vectorExpression.accept(v); | |
| 2789 } | |
| 2790 | |
| 2791 transformChildren(Transformer v) { | |
| 2792 if (vectorExpression != null) { | |
| 2793 vectorExpression = vectorExpression.accept(v); | |
| 2794 vectorExpression?.parent = this; | |
| 2795 } | |
| 2796 } | |
| 2797 | |
| 2798 DartType getStaticType(TypeEnvironment types) { | |
| 2799 return const DynamicType(); | |
| 2800 } | |
| 2801 } | |
| 2802 | |
| 2803 /// Expression of the form `v[i] = x` where `v` is a vector expression, `i` is | |
| 2804 /// an integer index, and `x` is an arbitrary expression. | |
| 2805 class VectorSet extends Expression { | |
| 2806 Expression vectorExpression; | |
| 2807 int index; | |
| 2808 Expression value; | |
| 2809 | |
| 2810 VectorSet(this.vectorExpression, this.index, this.value) { | |
| 2811 vectorExpression?.parent = this; | |
| 2812 value?.parent = this; | |
| 2813 } | |
| 2814 | |
| 2815 accept(ExpressionVisitor v) => v.visitVectorSet(this); | |
| 2816 accept1(ExpressionVisitor1 v, arg) => v.visitVectorSet(this, arg); | |
| 2817 | |
| 2818 visitChildren(Visitor v) { | |
| 2819 vectorExpression.accept(v); | |
| 2820 value.accept(v); | |
| 2821 } | |
| 2822 | |
| 2823 transformChildren(Transformer v) { | |
| 2824 if (vectorExpression != null) { | |
| 2825 vectorExpression = vectorExpression.accept(v); | |
| 2826 vectorExpression?.parent = this; | |
| 2827 } | |
| 2828 if (value != null) { | |
| 2829 value = value.accept(v); | |
| 2830 value?.parent = this; | |
| 2831 } | |
| 2832 } | |
| 2833 | |
| 2834 DartType getStaticType(TypeEnvironment types) { | |
| 2835 return value.getStaticType(types); | |
| 2836 } | |
| 2837 } | |
| 2838 | |
| 2839 /// Expression of the form `CopyVector(v)` where `v` is a vector expression. | |
| 2840 class VectorCopy extends Expression { | |
| 2841 Expression vectorExpression; | |
| 2842 | |
| 2843 VectorCopy(this.vectorExpression) { | |
| 2844 vectorExpression?.parent = this; | |
| 2845 } | |
| 2846 | |
| 2847 accept(ExpressionVisitor v) => v.visitVectorCopy(this); | |
| 2848 accept1(ExpressionVisitor1 v, arg) => v.visitVectorCopy(this, arg); | |
| 2849 | |
| 2850 visitChildren(Visitor v) { | |
| 2851 vectorExpression.accept(v); | |
| 2852 } | |
| 2853 | |
| 2854 transformChildren(Transformer v) { | |
| 2855 if (vectorExpression != null) { | |
| 2856 vectorExpression = vectorExpression.accept(v); | |
| 2857 vectorExpression?.parent = this; | |
| 2858 } | |
| 2859 } | |
| 2860 | |
| 2861 DartType getStaticType(TypeEnvironment types) { | |
| 2862 return const VectorType(); | |
| 2863 } | |
| 2864 } | |
| 2865 | |
| 2753 // ------------------------------------------------------------------------ | 2866 // ------------------------------------------------------------------------ |
| 2754 // STATEMENTS | 2867 // STATEMENTS |
| 2755 // ------------------------------------------------------------------------ | 2868 // ------------------------------------------------------------------------ |
| 2756 | 2869 |
| 2757 abstract class Statement extends TreeNode { | 2870 abstract class Statement extends TreeNode { |
| 2758 accept(StatementVisitor v); | 2871 accept(StatementVisitor v); |
| 2759 accept1(StatementVisitor1 v, arg); | 2872 accept1(StatementVisitor1 v, arg); |
| 2760 } | 2873 } |
| 2761 | 2874 |
| 2762 /// A statement with a compile-time error. | 2875 /// A statement with a compile-time error. |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3645 | 3758 |
| 3646 int get hashCode { | 3759 int get hashCode { |
| 3647 int hash = 0x3fffffff & className.hashCode; | 3760 int hash = 0x3fffffff & className.hashCode; |
| 3648 for (int i = 0; i < typeArguments.length; ++i) { | 3761 for (int i = 0; i < typeArguments.length; ++i) { |
| 3649 hash = 0x3fffffff & (hash * 31 + (hash ^ typeArguments[i].hashCode)); | 3762 hash = 0x3fffffff & (hash * 31 + (hash ^ typeArguments[i].hashCode)); |
| 3650 } | 3763 } |
| 3651 return hash; | 3764 return hash; |
| 3652 } | 3765 } |
| 3653 } | 3766 } |
| 3654 | 3767 |
| 3768 /// [VectorType] represents Vectors, a special kind of data that is not | |
| 3769 /// available for use by Dart programmers directly. It is used by Kernel | |
| 3770 /// transformations as efficient index-based storage. | |
| 3771 /// | |
| 3772 /// (1) Vectors aren't user-visible. For example, they are not supposed to | |
| 3773 /// be exposed to Dart programs through variables or be visible in stack | |
| 3774 /// traces. | |
| 3775 /// | |
| 3776 /// (2) Vectors have fixed length at runtime. The length is known at compile | |
| 3777 /// time, and [VectorCreation] AST node stores it in a field. | |
| 3778 /// | |
| 3779 /// (3) Indexes for accessing and assigning Vector items are known at | |
| 3780 /// compile time. The corresponding [VectorGet] and [VectorSet] AST nodes | |
| 3781 /// store the index in a field. | |
| 3782 /// | |
| 3783 /// (4) For efficiency considerations, bounds checks aren't performed for | |
| 3784 /// Vectors. If necessary, a transformer or verifier can do this checks at | |
| 3785 /// compile-time, after adding length field to [VectorType], to make sure | |
| 3786 /// that previous transformations didn't introduce any access errors. | |
| 3787 /// | |
| 3788 /// (5) Access to Vectors is untyped. | |
| 3789 /// | |
| 3790 /// (6) Vectors can be used by various transformations of Kernel programs. | |
| 3791 /// Currently they are used by Closure Conversion to represent closure | |
| 3792 /// contexts. | |
|
asgerf
2017/03/27 11:15:39
Great! Please use markdown syntax, though.
Dmitry Stefantsov
2017/03/27 12:17:24
Done.
| |
| 3793 class VectorType extends DartType { | |
| 3794 const VectorType(); | |
| 3795 | |
| 3796 accept(DartTypeVisitor v) => v.visitVectorType(this); | |
| 3797 visitChildren(Visitor v) {} | |
| 3798 } | |
| 3799 | |
| 3655 /// A possibly generic function type. | 3800 /// A possibly generic function type. |
| 3656 class FunctionType extends DartType { | 3801 class FunctionType extends DartType { |
| 3657 final List<TypeParameter> typeParameters; | 3802 final List<TypeParameter> typeParameters; |
| 3658 final int requiredParameterCount; | 3803 final int requiredParameterCount; |
| 3659 final List<DartType> positionalParameters; | 3804 final List<DartType> positionalParameters; |
| 3660 final List<NamedType> namedParameters; // Must be sorted. | 3805 final List<NamedType> namedParameters; // Must be sorted. |
| 3661 final DartType returnType; | 3806 final DartType returnType; |
| 3662 int _hashCode; | 3807 int _hashCode; |
| 3663 | 3808 |
| 3664 FunctionType(List<DartType> positionalParameters, this.returnType, | 3809 FunctionType(List<DartType> positionalParameters, this.returnType, |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4100 /// library has not been assigned a canonical name yet. | 4245 /// library has not been assigned a canonical name yet. |
| 4101 /// | 4246 /// |
| 4102 /// Returns `null` if the library is `null`. | 4247 /// Returns `null` if the library is `null`. |
| 4103 CanonicalName getCanonicalNameOfLibrary(Library library) { | 4248 CanonicalName getCanonicalNameOfLibrary(Library library) { |
| 4104 if (library == null) return null; | 4249 if (library == null) return null; |
| 4105 if (library.canonicalName == null) { | 4250 if (library.canonicalName == null) { |
| 4106 throw '$library has no canonical name'; | 4251 throw '$library has no canonical name'; |
| 4107 } | 4252 } |
| 4108 return library.canonicalName; | 4253 return library.canonicalName; |
| 4109 } | 4254 } |
| OLD | NEW |