Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: pkg/kernel/lib/ast.dart

Issue 2767773004: Add Vector type to Kernel (Closed)
Patch Set: Reformat comment with Markdown, throw exception in type propagation Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/kernel/binary.md ('k') | pkg/kernel/lib/binary/ast_from_binary.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 /// * Vectors aren't user-visible. For example, they are not supposed to be
3773 /// exposed to Dart programs through variables or be visible in stack traces.
3774 ///
3775 /// * Vectors have fixed length at runtime. The length is known at compile
3776 /// time, and [VectorCreation] AST node stores it in a field.
3777 ///
3778 /// * Indexes for accessing and assigning Vector items are known at compile
3779 /// time. The corresponding [VectorGet] and [VectorSet] AST nodes store the
3780 /// index in a field.
3781 ///
3782 /// * For efficiency considerations, bounds checks aren't performed for Vectors.
3783 /// If necessary, a transformer or verifier can do this checks at compile-time,
3784 /// after adding length field to [VectorType], to make sure that previous
3785 /// transformations didn't introduce any access errors.
3786 ///
3787 /// * Access to Vectors is untyped.
3788 ///
3789 /// * Vectors can be used by various transformations of Kernel programs.
3790 /// Currently they are used by Closure Conversion to represent closure contexts.
3791 class VectorType extends DartType {
3792 const VectorType();
3793
3794 accept(DartTypeVisitor v) => v.visitVectorType(this);
3795 visitChildren(Visitor v) {}
3796 }
3797
3655 /// A possibly generic function type. 3798 /// A possibly generic function type.
3656 class FunctionType extends DartType { 3799 class FunctionType extends DartType {
3657 final List<TypeParameter> typeParameters; 3800 final List<TypeParameter> typeParameters;
3658 final int requiredParameterCount; 3801 final int requiredParameterCount;
3659 final List<DartType> positionalParameters; 3802 final List<DartType> positionalParameters;
3660 final List<NamedType> namedParameters; // Must be sorted. 3803 final List<NamedType> namedParameters; // Must be sorted.
3661 final DartType returnType; 3804 final DartType returnType;
3662 int _hashCode; 3805 int _hashCode;
3663 3806
3664 FunctionType(List<DartType> positionalParameters, this.returnType, 3807 FunctionType(List<DartType> positionalParameters, this.returnType,
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
4100 /// library has not been assigned a canonical name yet. 4243 /// library has not been assigned a canonical name yet.
4101 /// 4244 ///
4102 /// Returns `null` if the library is `null`. 4245 /// Returns `null` if the library is `null`.
4103 CanonicalName getCanonicalNameOfLibrary(Library library) { 4246 CanonicalName getCanonicalNameOfLibrary(Library library) {
4104 if (library == null) return null; 4247 if (library == null) return null;
4105 if (library.canonicalName == null) { 4248 if (library.canonicalName == null) {
4106 throw '$library has no canonical name'; 4249 throw '$library has no canonical name';
4107 } 4250 }
4108 return library.canonicalName; 4251 return library.canonicalName;
4109 } 4252 }
OLDNEW
« no previous file with comments | « pkg/kernel/binary.md ('k') | pkg/kernel/lib/binary/ast_from_binary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698