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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_enum_builder.dart

Issue 2828253003: Add top level type inference logic for integer literals. (Closed)
Patch Set: Clean up, bug fix, and remove unintentional expectations changes Created 3 years, 8 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
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 library fasta.kernel_enum_builder; 5 library fasta.kernel_enum_builder;
6 6
7 import 'package:front_end/src/fasta/builder/ast_factory.dart' show AstFactory;
8
7 import 'package:kernel/ast.dart' 9 import 'package:kernel/ast.dart'
8 show 10 show
9 Arguments, 11 Arguments,
10 AsyncMarker, 12 AsyncMarker,
11 Class, 13 Class,
12 Constructor, 14 Constructor,
13 ConstructorInvocation, 15 ConstructorInvocation,
14 DirectPropertyGet, 16 DirectPropertyGet,
15 Expression, 17 Expression,
16 Field, 18 Field,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 this.intType, 82 this.intType,
81 this.listType, 83 this.listType,
82 this.objectType, 84 this.objectType,
83 this.stringType, 85 this.stringType,
84 LibraryBuilder parent, 86 LibraryBuilder parent,
85 int charOffset) 87 int charOffset)
86 : super(metadata, 0, name, null, null, null, scope, constructors, parent, 88 : super(metadata, 0, name, null, null, null, scope, constructors, parent,
87 null, charOffset, cls); 89 null, charOffset, cls);
88 90
89 factory KernelEnumBuilder( 91 factory KernelEnumBuilder(
92 AstFactory astFactory,
90 List<MetadataBuilder> metadata, 93 List<MetadataBuilder> metadata,
91 String name, 94 String name,
92 List<Object> constantNamesAndOffsets, 95 List<Object> constantNamesAndOffsets,
93 KernelLibraryBuilder parent, 96 KernelLibraryBuilder parent,
94 int charOffset, 97 int charOffset,
95 int charEndOffset) { 98 int charEndOffset) {
96 constantNamesAndOffsets ??= const <Object>[]; 99 constantNamesAndOffsets ??= const <Object>[];
97 // TODO(ahe): These types shouldn't be looked up in scope, they come 100 // TODO(ahe): These types shouldn't be looked up in scope, they come
98 // directly from dart:core. 101 // directly from dart:core.
99 KernelTypeBuilder intType = 102 KernelTypeBuilder intType =
(...skipping 14 matching lines...) Expand all
114 /// metadata class E { 117 /// metadata class E {
115 /// final int index; 118 /// final int index;
116 /// const E(this.index); 119 /// const E(this.index);
117 /// static const E id0 = const E(0); 120 /// static const E id0 = const E(0);
118 /// ... 121 /// ...
119 /// static const E idn-1 = const E(n - 1); 122 /// static const E idn-1 = const E(n - 1);
120 /// static const List<E> values = const <E>[id0, ..., idn-1]; 123 /// static const List<E> values = const <E>[id0, ..., idn-1];
121 /// String toString() => { 0: ‘E.id0’, . . ., n-1: ‘E.idn-1’}[index] 124 /// String toString() => { 0: ‘E.id0’, . . ., n-1: ‘E.idn-1’}[index]
122 /// } 125 /// }
123 members["index"] = new KernelFieldBuilder( 126 members["index"] = new KernelFieldBuilder(
124 null, intType, "index", finalMask, parent, charOffset); 127 astFactory,
128 parent.loader.topLevelTypeInferrer,
129 null,
130 intType,
131 "index",
132 finalMask,
133 parent,
134 charOffset,
135 null);
125 KernelConstructorBuilder constructorBuilder = new KernelConstructorBuilder( 136 KernelConstructorBuilder constructorBuilder = new KernelConstructorBuilder(
126 null, 137 null,
127 constMask, 138 constMask,
128 null, 139 null,
129 "", 140 "",
130 null, 141 null,
131 <FormalParameterBuilder>[ 142 <FormalParameterBuilder>[
132 new KernelFormalParameterBuilder( 143 new KernelFormalParameterBuilder(
133 null, 0, intType, "index", true, parent, charOffset) 144 null, 0, intType, "index", true, parent, charOffset)
134 ], 145 ],
135 parent, 146 parent,
136 charOffset, 147 charOffset,
137 charOffset, 148 charOffset,
138 charEndOffset); 149 charEndOffset);
139 constructors[""] = constructorBuilder; 150 constructors[""] = constructorBuilder;
140 int index = 0; 151 int index = 0;
141 List<MapEntry> toStringEntries = <MapEntry>[]; 152 List<MapEntry> toStringEntries = <MapEntry>[];
142 KernelFieldBuilder valuesBuilder = new KernelFieldBuilder( 153 KernelFieldBuilder valuesBuilder = new KernelFieldBuilder(
143 null, listType, "values", constMask | staticMask, parent, charOffset); 154 astFactory,
155 parent.loader.topLevelTypeInferrer,
156 null,
157 listType,
158 "values",
159 constMask | staticMask,
160 parent,
161 charOffset,
162 null);
144 members["values"] = valuesBuilder; 163 members["values"] = valuesBuilder;
145 KernelProcedureBuilder toStringBuilder = new KernelProcedureBuilder( 164 KernelProcedureBuilder toStringBuilder = new KernelProcedureBuilder(
146 null, 165 null,
147 0, 166 0,
148 stringType, 167 stringType,
149 "toString", 168 "toString",
150 null, 169 null,
151 null, 170 null,
152 AsyncMarker.Sync, 171 AsyncMarker.Sync,
153 ProcedureKind.Method, 172 ProcedureKind.Method,
154 parent, 173 parent,
155 charOffset, 174 charOffset,
156 charOffset, 175 charOffset,
157 charEndOffset); 176 charEndOffset);
158 members["toString"] = toStringBuilder; 177 members["toString"] = toStringBuilder;
159 String className = name; 178 String className = name;
160 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { 179 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) {
161 String name = constantNamesAndOffsets[i]; 180 String name = constantNamesAndOffsets[i];
162 int charOffset = constantNamesAndOffsets[i + 1]; 181 int charOffset = constantNamesAndOffsets[i + 1];
163 if (members.containsKey(name)) { 182 if (members.containsKey(name)) {
164 inputError(null, null, "Duplicated name: $name"); 183 inputError(null, null, "Duplicated name: $name");
165 continue; 184 continue;
166 } 185 }
167 KernelFieldBuilder fieldBuilder = new KernelFieldBuilder( 186 KernelFieldBuilder fieldBuilder = new KernelFieldBuilder(
168 null, selfType, name, constMask | staticMask, parent, charOffset); 187 astFactory,
188 parent.loader.topLevelTypeInferrer,
189 null,
190 selfType,
191 name,
192 constMask | staticMask,
193 parent,
194 charOffset,
195 null);
169 members[name] = fieldBuilder; 196 members[name] = fieldBuilder;
170 toStringEntries.add(new MapEntry( 197 toStringEntries.add(new MapEntry(
171 new IntLiteral(index), new StringLiteral("$className.$name"))); 198 new IntLiteral(index), new StringLiteral("$className.$name")));
172 index++; 199 index++;
173 } 200 }
174 MapLiteral toStringMap = new MapLiteral(toStringEntries, isConst: true); 201 MapLiteral toStringMap = new MapLiteral(toStringEntries, isConst: true);
175 KernelEnumBuilder enumBuilder = new KernelEnumBuilder.internal( 202 KernelEnumBuilder enumBuilder = new KernelEnumBuilder.internal(
176 metadata, 203 metadata,
177 name, 204 name,
178 new Scope(members, null, parent.scope, isModifiable: false), 205 new Scope(members, null, parent.scope, isModifiable: false),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 new ConstructorInvocation(constructor, arguments, isConst: true); 295 new ConstructorInvocation(constructor, arguments, isConst: true);
269 } 296 }
270 return super.build(libraryBuilder, coreLibrary); 297 return super.build(libraryBuilder, coreLibrary);
271 } 298 }
272 299
273 @override 300 @override
274 Builder findConstructorOrFactory(String name, int charOffset, Uri uri) { 301 Builder findConstructorOrFactory(String name, int charOffset, Uri uri) {
275 return null; 302 return null;
276 } 303 }
277 } 304 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698