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

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

Issue 2856123002: Add flag to track if a constructor is the synthetic default constructor. (Closed)
Patch Set: Created 3 years, 7 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/analyzer/lib/src/kernel/loader.dart ('k') | pkg/kernel/lib/text/ast_to_text.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 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 /// For unnamed constructors, the name is an empty string (in a [Name]). 931 /// For unnamed constructors, the name is an empty string (in a [Name]).
932 class Constructor extends Member { 932 class Constructor extends Member {
933 int flags = 0; 933 int flags = 0;
934 FunctionNode function; 934 FunctionNode function;
935 List<Initializer> initializers; 935 List<Initializer> initializers;
936 936
937 Constructor(this.function, 937 Constructor(this.function,
938 {Name name, 938 {Name name,
939 bool isConst: false, 939 bool isConst: false,
940 bool isExternal: false, 940 bool isExternal: false,
941 bool isSyntheticDefault: false,
941 List<Initializer> initializers, 942 List<Initializer> initializers,
942 int transformerFlags: 0, 943 int transformerFlags: 0,
943 Reference reference}) 944 Reference reference})
944 : this.initializers = initializers ?? <Initializer>[], 945 : this.initializers = initializers ?? <Initializer>[],
945 super(name, reference) { 946 super(name, reference) {
946 function?.parent = this; 947 function?.parent = this;
947 setParents(this.initializers, this); 948 setParents(this.initializers, this);
948 this.isConst = isConst; 949 this.isConst = isConst;
949 this.isExternal = isExternal; 950 this.isExternal = isExternal;
951 this.isSyntheticDefault = isSyntheticDefault;
950 this.transformerFlags = transformerFlags; 952 this.transformerFlags = transformerFlags;
951 } 953 }
952 954
953 static const int FlagConst = 1 << 0; // Must match serialized bit positions. 955 static const int FlagConst = 1 << 0; // Must match serialized bit positions.
954 static const int FlagExternal = 1 << 1; 956 static const int FlagExternal = 1 << 1;
957 static const int FlagSyntheticDefault = 1 << 2;
955 958
956 bool get isConst => flags & FlagConst != 0; 959 bool get isConst => flags & FlagConst != 0;
957 bool get isExternal => flags & FlagExternal != 0; 960 bool get isExternal => flags & FlagExternal != 0;
958 961
962 /// True if this is a synthetic default constructor inserted in a class that
963 /// does not otherwise declare any constructors.
964 bool get isSyntheticDefault => flags & FlagSyntheticDefault != 0;
965
959 void set isConst(bool value) { 966 void set isConst(bool value) {
960 flags = value ? (flags | FlagConst) : (flags & ~FlagConst); 967 flags = value ? (flags | FlagConst) : (flags & ~FlagConst);
961 } 968 }
962 969
963 void set isExternal(bool value) { 970 void set isExternal(bool value) {
964 flags = value ? (flags | FlagExternal) : (flags & ~FlagExternal); 971 flags = value ? (flags | FlagExternal) : (flags & ~FlagExternal);
965 } 972 }
966 973
974 void set isSyntheticDefault(bool value) {
975 flags = value
976 ? (flags | FlagSyntheticDefault)
977 : (flags & ~FlagSyntheticDefault);
978 }
979
967 bool get isInstanceMember => false; 980 bool get isInstanceMember => false;
968 bool get hasGetter => false; 981 bool get hasGetter => false;
969 bool get hasSetter => false; 982 bool get hasSetter => false;
970 983
971 accept(MemberVisitor v) => v.visitConstructor(this); 984 accept(MemberVisitor v) => v.visitConstructor(this);
972 985
973 acceptReference(MemberReferenceVisitor v) => 986 acceptReference(MemberReferenceVisitor v) =>
974 v.visitConstructorReference(this); 987 v.visitConstructorReference(this);
975 988
976 visitChildren(Visitor v) { 989 visitChildren(Visitor v) {
(...skipping 3484 matching lines...) Expand 10 before | Expand all | Expand 10 after
4461 /// typedef has not been assigned a canonical name yet. 4474 /// typedef has not been assigned a canonical name yet.
4462 /// 4475 ///
4463 /// Returns `null` if the typedef is `null`. 4476 /// Returns `null` if the typedef is `null`.
4464 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) { 4477 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) {
4465 if (typedef_ == null) return null; 4478 if (typedef_ == null) return null;
4466 if (typedef_.canonicalName == null) { 4479 if (typedef_.canonicalName == null) {
4467 throw '$typedef_ has no canonical name'; 4480 throw '$typedef_ has no canonical name';
4468 } 4481 }
4469 return typedef_.canonicalName; 4482 return typedef_.canonicalName;
4470 } 4483 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/kernel/loader.dart ('k') | pkg/kernel/lib/text/ast_to_text.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698