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

Side by Side Diff: frog/leg/elements/elements.dart

Issue 9243011: Implement named constructors and resolving of redirecting constructors and super-initializers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename field. Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | frog/leg/emitter.dart » ('j') | frog/leg/resolver.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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('elements'); 5 #library('elements');
6 6
7 #import('../tree/tree.dart'); 7 #import('../tree/tree.dart');
8 #import('../scanner/scannerlib.dart'); 8 #import('../scanner/scannerlib.dart');
9 #import('../leg.dart'); // TODO(karlklose): we only need type. 9 #import('../leg.dart'); // TODO(karlklose): we only need type.
10 #import('../util/util.dart'); 10 #import('../util/util.dart');
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 Link<Element> parameters; 207 Link<Element> parameters;
208 FunctionExpression node; 208 FunctionExpression node;
209 Type type; 209 Type type;
210 final Modifiers modifiers; 210 final Modifiers modifiers;
211 211
212 FunctionElement(SourceString name, 212 FunctionElement(SourceString name,
213 ElementKind kind, 213 ElementKind kind,
214 Modifiers this.modifiers, 214 Modifiers this.modifiers,
215 Element enclosing) 215 Element enclosing)
216 : super(name, kind, enclosing); 216 : super(name, kind, enclosing);
217 FunctionElement.node(FunctionExpression node, 217 FunctionElement.node(SourceString name,
218 FunctionExpression node,
218 ElementKind kind, 219 ElementKind kind,
219 Modifiers this.modifiers, 220 Modifiers this.modifiers,
220 Element enclosing) 221 Element enclosing)
221 : super(node.name.asIdentifier().source, kind, enclosing), 222 : super(name, kind, enclosing),
222 this.node = node; 223 this.node = node;
223 224
224 bool isInstanceMember() { 225 bool isInstanceMember() {
225 return isMember() 226 return isMember()
226 && kind != ElementKind.GENERATIVE_CONSTRUCTOR 227 && kind != ElementKind.GENERATIVE_CONSTRUCTOR
227 && !modifiers.isFactory() 228 && !modifiers.isFactory()
228 && !modifiers.isStatic(); 229 && !modifiers.isStatic();
229 } 230 }
230 231
231 FunctionType computeType(Compiler compiler) { 232 FunctionType computeType(Compiler compiler) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 new Block(new NodeList.empty()), 291 new Block(new NodeList.empty()),
291 null, null, null); 292 null, null, null);
292 return node; 293 return node;
293 } 294 }
294 } 295 }
295 296
296 class ClassElement extends Element { 297 class ClassElement extends Element {
297 Type type; 298 Type type;
298 Type supertype; 299 Type supertype;
299 Link<Element> members = const EmptyLink<Element>(); 300 Link<Element> members = const EmptyLink<Element>();
301 Map<SourceString, Element> localMembers;
302 Map<SourceString, Element> constructors;
300 Link<Type> interfaces = const EmptyLink<Type>(); 303 Link<Type> interfaces = const EmptyLink<Type>();
301 bool isResolved = false; 304 bool isResolved = false;
302 ClassNode node; 305 ClassNode node;
303 // backendMembers are members that have been added by the backend to simplify 306 // backendMembers are members that have been added by the backend to simplify
304 // compilation. They don't have any user-side counter-part. 307 // compilation. They don't have any user-side counter-part.
305 Link<Element> backendMembers = const EmptyLink<Element>(); 308 Link<Element> backendMembers = const EmptyLink<Element>();
306 SynthesizedConstructorElement synthesizedConstructor; 309 SynthesizedConstructorElement synthesizedConstructor;
307 310
308 ClassElement(SourceString name, CompilationUnitElement enclosing) 311 ClassElement(SourceString name, CompilationUnitElement enclosing)
309 : super(name, ElementKind.CLASS, enclosing); 312 : localMembers = new Map<SourceString, Element>(),
313 constructors = new Map<SourceString, Element>(),
314 super(name, ElementKind.CLASS, enclosing);
310 315
311 void addMember(Element element) { 316 void addMember(Element element) {
312 members = members.prepend(element); 317 members = members.prepend(element);
318 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR ||
319 element.modifiers.isFactory()) {
320 constructors[element.name] = element;
321 } else {
322 localMembers[element.name] = element;
323 }
313 } 324 }
314 325
315 Type computeType(compiler) { 326 Type computeType(compiler) {
316 if (type === null) { 327 if (type === null) {
317 type = new SimpleType(name, this); 328 type = new SimpleType(name, this);
318 } 329 }
319 return type; 330 return type;
320 } 331 }
321 332
322 ClassElement resolve(Compiler compiler) { 333 ClassElement resolve(Compiler compiler) {
323 if (!isResolved) { 334 if (!isResolved) {
324 compiler.resolveType(this); 335 compiler.resolveType(this);
325 isResolved = true; 336 isResolved = true;
326 } 337 }
327 return this; 338 return this;
328 } 339 }
329 340
330 Element lookupLocalElement(SourceString name, bool matches(Element)) { 341 Element lookupLocalMember(SourceString name) {
331 // TODO(karlklose): replace with more efficient solution. 342 return localMembers[name];
332 for (Link<Element> link = members;
333 link !== null && !link.isEmpty();
334 link = link.tail) {
335 Element element = link.head;
336 if (matches(element)) return element;
337 }
338 return null;
339 } 343 }
340 344
341 Element lookupLocalMember(SourceString name) { 345 Element lookupConstructor(SourceString name, [Element noMatch(Element)]) {
342 bool matches(Element element) { 346 Element result = constructors[name];
343 return element.name == name 347 if (result === null && noMatch !== null) {
344 && element.kind != ElementKind.GENERATIVE_CONSTRUCTOR; 348 result = noMatch(lookupLocalMember(name));
345 } 349 }
346 return lookupLocalElement(name, matches); 350 return result;
347 }
348
349 Element lookupConstructor(SourceString name) {
350 bool matches(Element element) {
351 return element.name == name
352 && (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR
353 || element.modifiers.isFactory());
354 }
355 return lookupLocalElement(name, matches);
356 } 351 }
357 352
358 // TODO(ngeoffray): Implement these. 353 // TODO(ngeoffray): Implement these.
359 bool canHaveDefaultConstructor() => true; 354 bool canHaveDefaultConstructor() => constructors.length == 0;
360 355
361 SynthesizedConstructorElement getSynthesizedConstructor() { 356 SynthesizedConstructorElement getSynthesizedConstructor() {
362 if (synthesizedConstructor === null && canHaveDefaultConstructor()) { 357 if (synthesizedConstructor === null && canHaveDefaultConstructor()) {
363 synthesizedConstructor = new SynthesizedConstructorElement(this); 358 synthesizedConstructor = new SynthesizedConstructorElement(this);
364 } 359 }
365 return synthesizedConstructor; 360 return synthesizedConstructor;
366 } 361 }
367 362
368 parseNode(Canceler canceler, Logger logger) => node; 363 parseNode(Canceler canceler, Logger logger) => node;
369 364
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 if (send.isPropertyAccess) return false; 396 if (send.isPropertyAccess) return false;
402 if (send.receiver !== null) return false; 397 if (send.receiver !== null) return false;
403 Element element = elements[send]; 398 Element element = elements[send];
404 // (o)() or foo()(). 399 // (o)() or foo()().
405 if (element === null && send.selector.asIdentifier() === null) return true; 400 if (element === null && send.selector.asIdentifier() === null) return true;
406 if (element === null) return false; 401 if (element === null) return false;
407 // foo() with foo a local or a parameter. 402 // foo() with foo a local or a parameter.
408 return element.isVariable() || element.isParameter(); 403 return element.isVariable() || element.isParameter();
409 } 404 }
410 } 405 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/emitter.dart » ('j') | frog/leg/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698