OLD | NEW |
---|---|
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 part of resolution; | 5 part of resolution; |
6 | 6 |
7 abstract class TreeElements { | 7 abstract class TreeElements { |
8 AnalyzableElement get analyzedElement; | 8 AnalyzableElement get analyzedElement; |
9 Iterable<Node> get superUses; | 9 Iterable<Node> get superUses; |
10 | 10 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 if (seen.contains(redirection)) { | 485 if (seen.contains(redirection)) { |
486 resolver.visitor.error(node, MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE); | 486 resolver.visitor.error(node, MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE); |
487 return; | 487 return; |
488 } | 488 } |
489 seen.add(redirection); | 489 seen.add(redirection); |
490 redirection = resolver.visitor.resolveConstructorRedirection(redirection); | 490 redirection = resolver.visitor.resolveConstructorRedirection(redirection); |
491 } | 491 } |
492 } | 492 } |
493 | 493 |
494 static void processAsyncMarker(Compiler compiler, | 494 static void processAsyncMarker(Compiler compiler, |
495 BaseFunctionElementX element) { | 495 BaseFunctionElementX element, |
496 Registry registry) { | |
496 FunctionExpression functionExpression = element.node; | 497 FunctionExpression functionExpression = element.node; |
497 AsyncModifier asyncModifier = functionExpression.asyncModifier; | 498 AsyncModifier asyncModifier = functionExpression.asyncModifier; |
498 if (asyncModifier != null) { | 499 if (asyncModifier != null) { |
499 if (!compiler.enableAsyncAwait) { | |
500 compiler.reportError(asyncModifier, | |
501 MessageKind.EXPERIMENTAL_ASYNC_AWAIT, | |
502 {'modifier': element.asyncMarker}); | |
503 } else if (!compiler.analyzeOnly) { | |
504 compiler.reportError(asyncModifier, | |
505 MessageKind.EXPERIMENTAL_ASYNC_AWAIT, | |
506 {'modifier': element.asyncMarker}); | |
507 } | |
508 | 500 |
509 if (asyncModifier.isAsynchronous) { | 501 if (asyncModifier.isAsynchronous) { |
510 element.asyncMarker = asyncModifier.isYielding | 502 element.asyncMarker = asyncModifier.isYielding |
511 ? AsyncMarker.ASYNC_STAR : AsyncMarker.ASYNC; | 503 ? AsyncMarker.ASYNC_STAR : AsyncMarker.ASYNC; |
504 Backend backend = compiler.backend; | |
Johnni Winther
2015/02/02 10:45:10
Unneeded?
sigurdm
2015/02/03 16:59:27
Yes. Thanks!
| |
505 | |
512 } else { | 506 } else { |
513 element.asyncMarker = AsyncMarker.SYNC_STAR; | 507 element.asyncMarker = AsyncMarker.SYNC_STAR; |
514 } | 508 } |
515 if (element.isAbstract) { | 509 if (element.isAbstract) { |
516 compiler.reportError(asyncModifier, | 510 compiler.reportError(asyncModifier, |
517 MessageKind.ASYNC_MODIFIER_ON_ABSTRACT_METHOD, | 511 MessageKind.ASYNC_MODIFIER_ON_ABSTRACT_METHOD, |
518 {'modifier': element.asyncMarker}); | 512 {'modifier': element.asyncMarker}); |
519 } else if (element.isConstructor) { | 513 } else if (element.isConstructor) { |
520 compiler.reportError(asyncModifier, | 514 compiler.reportError(asyncModifier, |
521 MessageKind.ASYNC_MODIFIER_ON_CONSTRUCTOR, | 515 MessageKind.ASYNC_MODIFIER_ON_CONSTRUCTOR, |
522 {'modifier': element.asyncMarker}); | 516 {'modifier': element.asyncMarker}); |
523 } else if (functionExpression.body.asReturn() != null && | 517 } else if (functionExpression.body.asReturn() != null && |
524 element.asyncMarker.isYielding) { | 518 element.asyncMarker.isYielding) { |
525 compiler.reportError(asyncModifier, | 519 compiler.reportError(asyncModifier, |
526 MessageKind.YIELDING_MODIFIER_ON_ARROW_BODY, | 520 MessageKind.YIELDING_MODIFIER_ON_ARROW_BODY, |
527 {'modifier': element.asyncMarker}); | 521 {'modifier': element.asyncMarker}); |
528 } | 522 } |
523 registry.registerAsyncMarker(element); | |
529 } | 524 } |
530 } | 525 } |
531 | 526 |
532 TreeElements resolveMethodElementImplementation( | 527 TreeElements resolveMethodElementImplementation( |
533 FunctionElement element, FunctionExpression tree) { | 528 FunctionElement element, FunctionExpression tree) { |
534 return compiler.withCurrentElement(element, () { | 529 return compiler.withCurrentElement(element, () { |
535 if (element.isExternal && tree.hasBody()) { | 530 if (element.isExternal && tree.hasBody()) { |
536 compiler.reportError(element, | 531 compiler.reportError(element, |
537 MessageKind.EXTERNAL_WITH_BODY, | 532 MessageKind.EXTERNAL_WITH_BODY, |
538 {'functionName': element.name}); | 533 {'functionName': element.name}); |
539 } | 534 } |
540 if (element.isConstructor) { | 535 if (element.isConstructor) { |
541 if (tree.returnType != null) { | 536 if (tree.returnType != null) { |
542 compiler.reportError(tree, MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE); | 537 compiler.reportError(tree, MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE); |
543 } | 538 } |
544 if (element.isConst && | 539 if (element.isConst && |
545 tree.hasBody() && | 540 tree.hasBody() && |
546 !tree.isRedirectingFactory) { | 541 !tree.isRedirectingFactory) { |
547 compiler.reportError(tree, MessageKind.CONST_CONSTRUCTOR_HAS_BODY); | 542 compiler.reportError(tree, MessageKind.CONST_CONSTRUCTOR_HAS_BODY); |
548 } | 543 } |
549 } | 544 } |
550 | 545 |
551 ResolverVisitor visitor = visitorFor(element); | 546 ResolverVisitor visitor = visitorFor(element); |
552 ResolutionRegistry registry = visitor.registry; | 547 ResolutionRegistry registry = visitor.registry; |
553 registry.defineFunction(tree, element); | 548 registry.defineFunction(tree, element); |
554 visitor.setupFunction(tree, element); | 549 visitor.setupFunction(tree, element); |
550 processAsyncMarker(compiler, element, registry); | |
555 | 551 |
556 if (element.isGenerativeConstructor) { | 552 if (element.isGenerativeConstructor) { |
557 // Even if there is no initializer list we still have to do the | 553 // Even if there is no initializer list we still have to do the |
558 // resolution in case there is an implicit super constructor call. | 554 // resolution in case there is an implicit super constructor call. |
559 InitializerResolver resolver = new InitializerResolver(visitor); | 555 InitializerResolver resolver = new InitializerResolver(visitor); |
560 FunctionElement redirection = | 556 FunctionElement redirection = |
561 resolver.resolveInitializers(element, tree); | 557 resolver.resolveInitializers(element, tree); |
562 if (redirection != null) { | 558 if (redirection != null) { |
563 resolveRedirectingConstructor(resolver, tree, element, redirection); | 559 resolveRedirectingConstructor(resolver, tree, element, redirection); |
564 } | 560 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 registry.registerImplicitSuperCall(target); | 615 registry.registerImplicitSuperCall(target); |
620 } | 616 } |
621 return registry.mapping; | 617 return registry.mapping; |
622 } else { | 618 } else { |
623 assert(element.isDeferredLoaderGetter || element.isErroneous); | 619 assert(element.isDeferredLoaderGetter || element.isErroneous); |
624 return _ensureTreeElements(element); | 620 return _ensureTreeElements(element); |
625 } | 621 } |
626 } else { | 622 } else { |
627 element.parseNode(compiler); | 623 element.parseNode(compiler); |
628 element.computeType(compiler); | 624 element.computeType(compiler); |
629 processAsyncMarker(compiler, element); | |
630 FunctionElementX implementation = element; | 625 FunctionElementX implementation = element; |
631 if (element.isExternal) { | 626 if (element.isExternal) { |
632 implementation = compiler.backend.resolveExternalFunction(element); | 627 implementation = compiler.backend.resolveExternalFunction(element); |
633 } | 628 } |
634 return resolveMethodElementImplementation( | 629 return resolveMethodElementImplementation( |
635 implementation, implementation.node); | 630 implementation, implementation.node); |
636 } | 631 } |
637 }); | 632 }); |
638 } | 633 } |
639 | 634 |
(...skipping 1830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2470 name = ""; | 2465 name = ""; |
2471 } else { | 2466 } else { |
2472 name = node.name.asIdentifier().source; | 2467 name = node.name.asIdentifier().source; |
2473 } | 2468 } |
2474 LocalFunctionElementX function = new LocalFunctionElementX( | 2469 LocalFunctionElementX function = new LocalFunctionElementX( |
2475 name, node, ElementKind.FUNCTION, Modifiers.EMPTY, | 2470 name, node, ElementKind.FUNCTION, Modifiers.EMPTY, |
2476 enclosingElement); | 2471 enclosingElement); |
2477 function.functionSignatureCache = | 2472 function.functionSignatureCache = |
2478 SignatureResolver.analyze(compiler, node.parameters, node.returnType, | 2473 SignatureResolver.analyze(compiler, node.parameters, node.returnType, |
2479 function, registry, createRealParameters: true); | 2474 function, registry, createRealParameters: true); |
2480 ResolverTask.processAsyncMarker(compiler, function); | 2475 ResolverTask.processAsyncMarker(compiler, function, registry); |
2481 checkLocalDefinitionName(node, function); | 2476 checkLocalDefinitionName(node, function); |
2482 registry.defineFunction(node, function); | 2477 registry.defineFunction(node, function); |
2483 if (doAddToScope) { | 2478 if (doAddToScope) { |
2484 addToScope(function); | 2479 addToScope(function); |
2485 } | 2480 } |
2486 Scope oldScope = scope; // The scope is modified by [setupFunction]. | 2481 Scope oldScope = scope; // The scope is modified by [setupFunction]. |
2487 setupFunction(node, function); | 2482 setupFunction(node, function); |
2488 | 2483 |
2489 Element previousEnclosingElement = enclosingElement; | 2484 Element previousEnclosingElement = enclosingElement; |
2490 enclosingElement = function; | 2485 enclosingElement = function; |
(...skipping 2539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5030 } | 5025 } |
5031 | 5026 |
5032 /// The result for the resolution of the `assert` method. | 5027 /// The result for the resolution of the `assert` method. |
5033 class AssertResult implements ResolutionResult { | 5028 class AssertResult implements ResolutionResult { |
5034 const AssertResult(); | 5029 const AssertResult(); |
5035 | 5030 |
5036 Element get element => null; | 5031 Element get element => null; |
5037 | 5032 |
5038 String toString() => 'AssertResult()'; | 5033 String toString() => 'AssertResult()'; |
5039 } | 5034 } |
OLD | NEW |