| 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 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 DartType type; // Not null. Defaults to DynamicType. | 973 DartType type; // Not null. Defaults to DynamicType. |
| 974 int flags = 0; | 974 int flags = 0; |
| 975 Expression initializer; // May be null. | 975 Expression initializer; // May be null. |
| 976 | 976 |
| 977 /// The uri of the source file this field was loaded from. | 977 /// The uri of the source file this field was loaded from. |
| 978 String fileUri; | 978 String fileUri; |
| 979 | 979 |
| 980 Field(Name name, | 980 Field(Name name, |
| 981 {this.type: const DynamicType(), | 981 {this.type: const DynamicType(), |
| 982 this.initializer, | 982 this.initializer, |
| 983 bool isCovariant: false, |
| 983 bool isFinal: false, | 984 bool isFinal: false, |
| 984 bool isConst: false, | 985 bool isConst: false, |
| 985 bool isStatic: false, | 986 bool isStatic: false, |
| 986 bool hasImplicitGetter, | 987 bool hasImplicitGetter, |
| 987 bool hasImplicitSetter, | 988 bool hasImplicitSetter, |
| 988 int transformerFlags: 0, | 989 int transformerFlags: 0, |
| 989 this.fileUri, | 990 this.fileUri, |
| 990 Reference reference}) | 991 Reference reference}) |
| 991 : super(name, reference) { | 992 : super(name, reference) { |
| 992 assert(type != null); | 993 assert(type != null); |
| 993 initializer?.parent = this; | 994 initializer?.parent = this; |
| 995 this.isCovariant = isCovariant; |
| 994 this.isFinal = isFinal; | 996 this.isFinal = isFinal; |
| 995 this.isConst = isConst; | 997 this.isConst = isConst; |
| 996 this.isStatic = isStatic; | 998 this.isStatic = isStatic; |
| 997 this.hasImplicitGetter = hasImplicitGetter ?? !isStatic; | 999 this.hasImplicitGetter = hasImplicitGetter ?? !isStatic; |
| 998 this.hasImplicitSetter = hasImplicitSetter ?? (!isStatic && !isFinal); | 1000 this.hasImplicitSetter = hasImplicitSetter ?? (!isStatic && !isFinal); |
| 999 this.transformerFlags = transformerFlags; | 1001 this.transformerFlags = transformerFlags; |
| 1000 } | 1002 } |
| 1001 | 1003 |
| 1002 static const int FlagFinal = 1 << 0; // Must match serialized bit positions. | 1004 static const int FlagFinal = 1 << 0; // Must match serialized bit positions. |
| 1003 static const int FlagConst = 1 << 1; | 1005 static const int FlagConst = 1 << 1; |
| 1004 static const int FlagStatic = 1 << 2; | 1006 static const int FlagStatic = 1 << 2; |
| 1005 static const int FlagHasImplicitGetter = 1 << 3; | 1007 static const int FlagHasImplicitGetter = 1 << 3; |
| 1006 static const int FlagHasImplicitSetter = 1 << 4; | 1008 static const int FlagHasImplicitSetter = 1 << 4; |
| 1009 static const int FlagCovariant = 1 << 5; |
| 1010 |
| 1011 /// Whether the field is declared with the `covariant` keyword. |
| 1012 bool get isCovariant => flags & FlagCovariant != 0; |
| 1007 | 1013 |
| 1008 bool get isFinal => flags & FlagFinal != 0; | 1014 bool get isFinal => flags & FlagFinal != 0; |
| 1009 bool get isConst => flags & FlagConst != 0; | 1015 bool get isConst => flags & FlagConst != 0; |
| 1010 bool get isStatic => flags & FlagStatic != 0; | 1016 bool get isStatic => flags & FlagStatic != 0; |
| 1011 | 1017 |
| 1012 /// If true, a getter should be generated for this field. | 1018 /// If true, a getter should be generated for this field. |
| 1013 /// | 1019 /// |
| 1014 /// If false, there may or may not exist an explicit getter in the same class | 1020 /// If false, there may or may not exist an explicit getter in the same class |
| 1015 /// with the same name as the field. | 1021 /// with the same name as the field. |
| 1016 /// | 1022 /// |
| 1017 /// By default, all non-static fields have implicit getters. | 1023 /// By default, all non-static fields have implicit getters. |
| 1018 bool get hasImplicitGetter => flags & FlagHasImplicitGetter != 0; | 1024 bool get hasImplicitGetter => flags & FlagHasImplicitGetter != 0; |
| 1019 | 1025 |
| 1020 /// If true, a setter should be generated for this field. | 1026 /// If true, a setter should be generated for this field. |
| 1021 /// | 1027 /// |
| 1022 /// If false, there may or may not exist an explicit setter in the same class | 1028 /// If false, there may or may not exist an explicit setter in the same class |
| 1023 /// with the same name as the field. | 1029 /// with the same name as the field. |
| 1024 /// | 1030 /// |
| 1025 /// Final fields never have implicit setters, but a field without an implicit | 1031 /// Final fields never have implicit setters, but a field without an implicit |
| 1026 /// setter is not necessarily final, as it may be mutated by direct field | 1032 /// setter is not necessarily final, as it may be mutated by direct field |
| 1027 /// access. | 1033 /// access. |
| 1028 /// | 1034 /// |
| 1029 /// By default, all non-static, non-final fields have implicit setters. | 1035 /// By default, all non-static, non-final fields have implicit setters. |
| 1030 bool get hasImplicitSetter => flags & FlagHasImplicitSetter != 0; | 1036 bool get hasImplicitSetter => flags & FlagHasImplicitSetter != 0; |
| 1031 | 1037 |
| 1038 void set isCovariant(bool value) { |
| 1039 flags = value ? (flags | FlagCovariant) : (flags & ~FlagCovariant); |
| 1040 } |
| 1041 |
| 1032 void set isFinal(bool value) { | 1042 void set isFinal(bool value) { |
| 1033 flags = value ? (flags | FlagFinal) : (flags & ~FlagFinal); | 1043 flags = value ? (flags | FlagFinal) : (flags & ~FlagFinal); |
| 1034 } | 1044 } |
| 1035 | 1045 |
| 1036 void set isConst(bool value) { | 1046 void set isConst(bool value) { |
| 1037 flags = value ? (flags | FlagConst) : (flags & ~FlagConst); | 1047 flags = value ? (flags | FlagConst) : (flags & ~FlagConst); |
| 1038 } | 1048 } |
| 1039 | 1049 |
| 1040 void set isStatic(bool value) { | 1050 void set isStatic(bool value) { |
| 1041 flags = value ? (flags | FlagStatic) : (flags & ~FlagStatic); | 1051 flags = value ? (flags | FlagStatic) : (flags & ~FlagStatic); |
| (...skipping 2749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3791 /// For parameters, this is the default value. | 3801 /// For parameters, this is the default value. |
| 3792 /// | 3802 /// |
| 3793 /// Should be null in other cases. | 3803 /// Should be null in other cases. |
| 3794 Expression initializer; // May be null. | 3804 Expression initializer; // May be null. |
| 3795 | 3805 |
| 3796 VariableDeclaration(this.name, | 3806 VariableDeclaration(this.name, |
| 3797 {this.initializer, | 3807 {this.initializer, |
| 3798 this.type: const DynamicType(), | 3808 this.type: const DynamicType(), |
| 3799 bool isFinal: false, | 3809 bool isFinal: false, |
| 3800 bool isConst: false, | 3810 bool isConst: false, |
| 3801 bool isFieldFormal: false}) { | 3811 bool isFieldFormal: false, |
| 3812 bool isCovariant: false}) { |
| 3802 assert(type != null); | 3813 assert(type != null); |
| 3803 initializer?.parent = this; | 3814 initializer?.parent = this; |
| 3804 this.isFinal = isFinal; | 3815 this.isFinal = isFinal; |
| 3805 this.isConst = isConst; | 3816 this.isConst = isConst; |
| 3806 this.isFieldFormal = isFieldFormal; | 3817 this.isFieldFormal = isFieldFormal; |
| 3818 this.isCovariant = isCovariant; |
| 3807 } | 3819 } |
| 3808 | 3820 |
| 3809 /// Creates a synthetic variable with the given expression as initializer. | 3821 /// Creates a synthetic variable with the given expression as initializer. |
| 3810 VariableDeclaration.forValue(this.initializer, | 3822 VariableDeclaration.forValue(this.initializer, |
| 3811 {bool isFinal: true, | 3823 {bool isFinal: true, |
| 3812 bool isConst: false, | 3824 bool isConst: false, |
| 3813 bool isFieldFormal: false, | 3825 bool isFieldFormal: false, |
| 3814 this.type: const DynamicType()}) { | 3826 this.type: const DynamicType()}) { |
| 3815 assert(type != null); | 3827 assert(type != null); |
| 3816 initializer?.parent = this; | 3828 initializer?.parent = this; |
| 3817 this.isFinal = isFinal; | 3829 this.isFinal = isFinal; |
| 3818 this.isConst = isConst; | 3830 this.isConst = isConst; |
| 3819 this.isFieldFormal = isFieldFormal; | 3831 this.isFieldFormal = isFieldFormal; |
| 3820 } | 3832 } |
| 3821 | 3833 |
| 3822 static const int FlagFinal = 1 << 0; // Must match serialized bit positions. | 3834 static const int FlagFinal = 1 << 0; // Must match serialized bit positions. |
| 3823 static const int FlagConst = 1 << 1; | 3835 static const int FlagConst = 1 << 1; |
| 3824 static const int FlagFieldFormal = 1 << 2; | 3836 static const int FlagFieldFormal = 1 << 2; |
| 3825 static const int FlagInScope = 1 << 3; // Temporary flag used by verifier. | 3837 static const int FlagCovariant = 1 << 3; |
| 3838 static const int FlagInScope = 1 << 4; // Temporary flag used by verifier. |
| 3826 | 3839 |
| 3827 bool get isFinal => flags & FlagFinal != 0; | 3840 bool get isFinal => flags & FlagFinal != 0; |
| 3828 bool get isConst => flags & FlagConst != 0; | 3841 bool get isConst => flags & FlagConst != 0; |
| 3829 | 3842 |
| 3843 /// Whether the parameter is declared with the `covariant` keyword. |
| 3844 bool get isCovariant => flags & FlagCovariant != 0; |
| 3845 |
| 3830 /// Whether the variable is declared as a field formal parameter of | 3846 /// Whether the variable is declared as a field formal parameter of |
| 3831 /// a constructor. | 3847 /// a constructor. |
| 3832 @informative | 3848 @informative |
| 3833 bool get isFieldFormal => flags & FlagFieldFormal != 0; | 3849 bool get isFieldFormal => flags & FlagFieldFormal != 0; |
| 3834 | 3850 |
| 3835 void set isFinal(bool value) { | 3851 void set isFinal(bool value) { |
| 3836 flags = value ? (flags | FlagFinal) : (flags & ~FlagFinal); | 3852 flags = value ? (flags | FlagFinal) : (flags & ~FlagFinal); |
| 3837 } | 3853 } |
| 3838 | 3854 |
| 3839 void set isConst(bool value) { | 3855 void set isConst(bool value) { |
| 3840 flags = value ? (flags | FlagConst) : (flags & ~FlagConst); | 3856 flags = value ? (flags | FlagConst) : (flags & ~FlagConst); |
| 3841 } | 3857 } |
| 3842 | 3858 |
| 3859 void set isCovariant(bool value) { |
| 3860 flags = value ? (flags | FlagCovariant) : (flags & ~FlagCovariant); |
| 3861 } |
| 3862 |
| 3843 @informative | 3863 @informative |
| 3844 void set isFieldFormal(bool value) { | 3864 void set isFieldFormal(bool value) { |
| 3845 flags = value ? (flags | FlagFieldFormal) : (flags & ~FlagFieldFormal); | 3865 flags = value ? (flags | FlagFieldFormal) : (flags & ~FlagFieldFormal); |
| 3846 } | 3866 } |
| 3847 | 3867 |
| 3848 accept(StatementVisitor v) => v.visitVariableDeclaration(this); | 3868 accept(StatementVisitor v) => v.visitVariableDeclaration(this); |
| 3849 accept1(StatementVisitor1 v, arg) => v.visitVariableDeclaration(this, arg); | 3869 accept1(StatementVisitor1 v, arg) => v.visitVariableDeclaration(this, arg); |
| 3850 | 3870 |
| 3851 visitChildren(Visitor v) { | 3871 visitChildren(Visitor v) { |
| 3852 type?.accept(v); | 3872 type?.accept(v); |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4743 if (typedef_.canonicalName == null) { | 4763 if (typedef_.canonicalName == null) { |
| 4744 throw '$typedef_ has no canonical name'; | 4764 throw '$typedef_ has no canonical name'; |
| 4745 } | 4765 } |
| 4746 return typedef_.canonicalName; | 4766 return typedef_.canonicalName; |
| 4747 } | 4767 } |
| 4748 | 4768 |
| 4749 /// Annotation describing information which is not part of Dart semantics; in | 4769 /// Annotation describing information which is not part of Dart semantics; in |
| 4750 /// other words, if this information (or any information it refers to) changes, | 4770 /// other words, if this information (or any information it refers to) changes, |
| 4751 /// static analysis and runtime behavior of the library are unaffected. | 4771 /// static analysis and runtime behavior of the library are unaffected. |
| 4752 const informative = null; | 4772 const informative = null; |
| OLD | NEW |