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

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

Issue 9454014: Support named parameters for super initializers and redirections. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use addStaticSendArguments. Created 8 years, 10 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/ssa/builder.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 interface TreeElements { 5 interface TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 } 8 }
9 9
10 class TreeElementMapping implements TreeElements { 10 class TreeElementMapping implements TreeElements {
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // Check that there are no other initializers. 362 // Check that there are no other initializers.
363 if (!initializers.tail.isEmpty()) { 363 if (!initializers.tail.isEmpty()) {
364 error(call, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER); 364 error(call, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER);
365 } 365 }
366 } else { 366 } else {
367 visitor.error(call, MessageKind.CONSTRUCTOR_CALL_EXPECTED); 367 visitor.error(call, MessageKind.CONSTRUCTOR_CALL_EXPECTED);
368 validTarget = false; 368 validTarget = false;
369 } 369 }
370 370
371 if (validTarget) { 371 if (validTarget) {
372 // Resolve the arguments of the call to get a selector.
ngeoffray 2012/02/24 13:43:01 This is not just for getting a selector, but also
373 visitor.inStaticContext( () => visitor.handleArguments(call) );
374 // Lookup constructor and try to match it to the selector.
372 ResolverTask resolver = visitor.compiler.resolver; 375 ResolverTask resolver = visitor.compiler.resolver;
373 result = resolver.lookupConstructor(lookupTarget, call); 376 result = resolver.lookupConstructor(lookupTarget, call);
374 if (result === null) { 377 if (result === null) {
375 SourceString constructorName = resolver.getConstructorName(call); 378 SourceString constructorName = resolver.getConstructorName(call);
376 SourceString className = lookupTarget.name; 379 SourceString className = lookupTarget.name;
377 String name = (constructorName === const SourceString('')) 380 String name = (constructorName === const SourceString(''))
378 ? className.stringValue 381 ? className.stringValue
379 : "$className.$constructorName"; 382 : "$className.$constructorName";
380 error(call, MessageKind.CANNOT_RESOLVE_CONSTRUCTOR, [name]); 383 error(call, MessageKind.CANNOT_RESOLVE_CONSTRUCTOR, [name]);
381 } else { 384 } else {
382 final Compiler compiler = visitor.compiler; 385 final Compiler compiler = visitor.compiler;
386 Selector selector = visitor.mapping.getSelector(call);
383 // TODO(karlklose): support optional arguments. 387 // TODO(karlklose): support optional arguments.
384 if (result.parameterCount(compiler) != call.argumentCount()) { 388 if (!selector.applies(compiler, result)) {
385 error(call, MessageKind.NO_MATCHING_CONSTRUCTOR); 389 error(call, MessageKind.NO_MATCHING_CONSTRUCTOR);
386 } 390 }
387 } 391 }
388 visitor.useElement(call, result); 392 visitor.useElement(call, result);
389 } 393 }
390 // Resolve the arguments of the call.
391 for (Link<Node> arguments = call.arguments;
392 !arguments.isEmpty();
393 arguments = arguments.tail) {
394 visitor.visitInStaticContext(arguments.head);
395 }
396 return result; 394 return result;
397 } 395 }
398 396
399 FunctionElement resolveRedirection(FunctionElement constructor, 397 FunctionElement resolveRedirection(FunctionElement constructor,
400 FunctionExpression functionNode) { 398 FunctionExpression functionNode) {
401 if (functionNode.initializers === null) return null; 399 if (functionNode.initializers === null) return null;
402 Link<Node> link = functionNode.initializers.nodes; 400 Link<Node> link = functionNode.initializers.nodes;
403 if (!link.isEmpty() && Initializers.isConstructorRedirect(link.head)) { 401 if (!link.isEmpty() && Initializers.isConstructorRedirect(link.head)) {
404 return resolveSuperOrThis(constructor, functionNode, link.head); 402 return resolveSuperOrThis(constructor, functionNode, link.head);
405 } 403 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 super(compiler); 546 super(compiler);
549 547
550 Element lookup(Node node, SourceString name) { 548 Element lookup(Node node, SourceString name) {
551 Element result = context.lookup(name); 549 Element result = context.lookup(name);
552 if (!inInstanceContext && result != null && result.isInstanceMember()) { 550 if (!inInstanceContext && result != null && result.isInstanceMember()) {
553 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); 551 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]);
554 } 552 }
555 return result; 553 return result;
556 } 554 }
557 555
558 visitInStaticContext(Node node) { 556 inStaticContext(action()) {
559 bool wasInstanceContext = inInstanceContext; 557 bool wasInstanceContext = inInstanceContext;
560 inInstanceContext = false; 558 inInstanceContext = false;
561 visit(node); 559 action();
562 inInstanceContext = wasInstanceContext; 560 inInstanceContext = wasInstanceContext;
563 } 561 }
564 562
563 visitInStaticContext(Node node) {
564 inStaticContext(() => visit(node));
565 }
566
565 visitIdentifier(Identifier node) { 567 visitIdentifier(Identifier node) {
566 if (node.isThis()) { 568 if (node.isThis()) {
567 if (!inInstanceContext) { 569 if (!inInstanceContext) {
568 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]); 570 error(node, MessageKind.NO_INSTANCE_AVAILABLE, [node]);
569 } 571 }
570 return null; 572 return null;
571 } else if (node.isSuper()) { 573 } else if (node.isSuper()) {
572 if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC); 574 if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC);
573 return null; 575 return null;
574 } else { 576 } else {
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 class TopScope extends Scope { 1434 class TopScope extends Scope {
1433 LibraryElement get library() => element; 1435 LibraryElement get library() => element;
1434 1436
1435 TopScope(LibraryElement library) : super(null, library); 1437 TopScope(LibraryElement library) : super(null, library);
1436 Element lookup(SourceString name) => library.find(name); 1438 Element lookup(SourceString name) => library.find(name);
1437 1439
1438 Element add(Element element) { 1440 Element add(Element element) {
1439 throw "Cannot add an element in the top scope"; 1441 throw "Cannot add an element in the top scope";
1440 } 1442 }
1441 } 1443 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698