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

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

Issue 2916333002: Setup correct scope for initializers and complain about fields initialized more than once. (Closed)
Patch Set: A parenthesized expression doesn't have a name. Created 3 years, 6 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:kernel/ast.dart' 7 import 'package:kernel/ast.dart'
8 show 8 show
9 Arguments, 9 Arguments,
10 Class, 10 Class,
(...skipping 10 matching lines...) Expand all
21 MapLiteral, 21 MapLiteral,
22 MethodInvocation, 22 MethodInvocation,
23 ProcedureKind, 23 ProcedureKind,
24 ReturnStatement, 24 ReturnStatement,
25 StaticGet, 25 StaticGet,
26 StringLiteral, 26 StringLiteral,
27 SuperInitializer, 27 SuperInitializer,
28 ThisExpression, 28 ThisExpression,
29 VariableGet; 29 VariableGet;
30 30
31 import 'package:front_end/src/scanner/token.dart' show Token;
32
31 import '../errors.dart' show inputError; 33 import '../errors.dart' show inputError;
32 34
33 import '../modifier.dart' show constMask, finalMask, staticMask; 35 import '../modifier.dart' show constMask, finalMask, staticMask;
34 36
35 import '../names.dart' show indexGetName; 37 import '../names.dart' show indexGetName;
36 38
37 import '../source/source_class_builder.dart' show SourceClassBuilder; 39 import '../source/source_class_builder.dart' show SourceClassBuilder;
38 40
39 import 'kernel_builder.dart' 41 import 'kernel_builder.dart'
40 show 42 show
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 /// From Dart Programming Language Specification 4th Edition/December 2015: 114 /// From Dart Programming Language Specification 4th Edition/December 2015:
113 /// metadata class E { 115 /// metadata class E {
114 /// final int index; 116 /// final int index;
115 /// const E(this.index); 117 /// const E(this.index);
116 /// static const E id0 = const E(0); 118 /// static const E id0 = const E(0);
117 /// ... 119 /// ...
118 /// static const E idn-1 = const E(n - 1); 120 /// static const E idn-1 = const E(n - 1);
119 /// static const List<E> values = const <E>[id0, ..., idn-1]; 121 /// static const List<E> values = const <E>[id0, ..., idn-1];
120 /// String toString() => { 0: ‘E.id0’, . . ., n-1: ‘E.idn-1’}[index] 122 /// String toString() => { 0: ‘E.id0’, . . ., n-1: ‘E.idn-1’}[index]
121 /// } 123 /// }
122 members["index"] = new KernelFieldBuilder( 124 members["index"] = new KernelFieldBuilder(null, intType, "index", finalMask,
123 null, intType, "index", finalMask, parent, charOffset, null); 125 parent, charOffset, new Token.eof(charOffset));
Johnni Winther 2017/06/06 10:35:08 Document why you pass `new Token.eof(...)`
ahe 2017/06/06 15:08:24 Done.
124 KernelConstructorBuilder constructorBuilder = new KernelConstructorBuilder( 126 KernelConstructorBuilder constructorBuilder = new KernelConstructorBuilder(
125 null, 127 null,
126 constMask, 128 constMask,
127 null, 129 null,
128 "", 130 "",
129 null, 131 null,
130 <FormalParameterBuilder>[ 132 <FormalParameterBuilder>[
131 new KernelFormalParameterBuilder( 133 new KernelFormalParameterBuilder(
132 null, 0, intType, "index", true, parent, charOffset) 134 null, 0, intType, "index", true, parent, charOffset)
133 ], 135 ],
134 parent, 136 parent,
135 charOffset, 137 charOffset,
136 charOffset, 138 charOffset,
137 charEndOffset); 139 charEndOffset);
138 constructors[""] = constructorBuilder; 140 constructors[""] = constructorBuilder;
139 int index = 0; 141 int index = 0;
140 List<MapEntry> toStringEntries = <MapEntry>[]; 142 List<MapEntry> toStringEntries = <MapEntry>[];
141 KernelFieldBuilder valuesBuilder = new KernelFieldBuilder(null, listType, 143 KernelFieldBuilder valuesBuilder = new KernelFieldBuilder(
142 "values", constMask | staticMask, parent, charOffset, null); 144 null,
145 listType,
146 "values",
147 constMask | staticMask,
148 parent,
149 charOffset,
150 new Token.eof(charOffset));
143 members["values"] = valuesBuilder; 151 members["values"] = valuesBuilder;
144 KernelProcedureBuilder toStringBuilder = new KernelProcedureBuilder( 152 KernelProcedureBuilder toStringBuilder = new KernelProcedureBuilder(
145 null, 153 null,
146 0, 154 0,
147 stringType, 155 stringType,
148 "toString", 156 "toString",
149 null, 157 null,
150 null, 158 null,
151 ProcedureKind.Method, 159 ProcedureKind.Method,
152 parent, 160 parent,
153 charOffset, 161 charOffset,
154 charOffset, 162 charOffset,
155 charEndOffset); 163 charEndOffset);
156 members["toString"] = toStringBuilder; 164 members["toString"] = toStringBuilder;
157 String className = name; 165 String className = name;
158 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { 166 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) {
159 String name = constantNamesAndOffsets[i]; 167 String name = constantNamesAndOffsets[i];
160 int charOffset = constantNamesAndOffsets[i + 1]; 168 int charOffset = constantNamesAndOffsets[i + 1];
161 if (members.containsKey(name)) { 169 if (members.containsKey(name)) {
162 inputError(null, null, "Duplicated name: $name"); 170 inputError(null, null, "Duplicated name: $name");
163 continue; 171 continue;
164 } 172 }
165 KernelFieldBuilder fieldBuilder = new KernelFieldBuilder(null, selfType, 173 KernelFieldBuilder fieldBuilder = new KernelFieldBuilder(
166 name, constMask | staticMask, parent, charOffset, null); 174 null,
175 selfType,
176 name,
177 constMask | staticMask,
178 parent,
179 charOffset,
180 new Token.eof(charOffset));
167 members[name] = fieldBuilder; 181 members[name] = fieldBuilder;
168 toStringEntries.add(new MapEntry( 182 toStringEntries.add(new MapEntry(
169 new IntLiteral(index), new StringLiteral("$className.$name"))); 183 new IntLiteral(index), new StringLiteral("$className.$name")));
170 index++; 184 index++;
171 } 185 }
172 MapLiteral toStringMap = new MapLiteral(toStringEntries, isConst: true); 186 MapLiteral toStringMap = new MapLiteral(toStringEntries, isConst: true);
173 KernelEnumBuilder enumBuilder = new KernelEnumBuilder.internal( 187 KernelEnumBuilder enumBuilder = new KernelEnumBuilder.internal(
174 metadata, 188 metadata,
175 name, 189 name,
176 new Scope(members, null, parent.scope, isModifiable: false), 190 new Scope(members, null, parent.scope, isModifiable: false),
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 281 }
268 return super.build(libraryBuilder, coreLibrary); 282 return super.build(libraryBuilder, coreLibrary);
269 } 283 }
270 284
271 @override 285 @override
272 Builder findConstructorOrFactory( 286 Builder findConstructorOrFactory(
273 String name, int charOffset, Uri uri, LibraryBuilder library) { 287 String name, int charOffset, Uri uri, LibraryBuilder library) {
274 return null; 288 return null;
275 } 289 }
276 } 290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698