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

Unified Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 296463003: Handle metadata on nested function parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update comment. Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart
diff --git a/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
index b95c03161efb138d7cf0a67fb569981907543a20..482f4ae6eb9a4efaba707df3a6ca3e9437e2e83d 100644
--- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -259,8 +259,11 @@ class ResolverTask extends CompilerTask {
return measure(() {
if (Elements.isErroneousElement(element)) return null;
- for (MetadataAnnotation metadata in element.metadata) {
- metadata.ensureResolved(compiler);
+ processMetadata([result]) {
+ for (MetadataAnnotation metadata in element.metadata) {
+ metadata.ensureResolved(compiler);
+ }
+ return result;
}
ElementKind kind = element.kind;
@@ -268,18 +271,19 @@ class ResolverTask extends CompilerTask {
identical(kind, ElementKind.FUNCTION) ||
identical(kind, ElementKind.GETTER) ||
identical(kind, ElementKind.SETTER)) {
- return resolveMethodElement(element);
+ return processMetadata(resolveMethodElement(element));
}
- if (identical(kind, ElementKind.FIELD)) return resolveField(element);
-
+ if (identical(kind, ElementKind.FIELD)) {
+ return processMetadata(resolveField(element));
+ }
if (element.isClass) {
ClassElement cls = element;
cls.ensureResolved(compiler);
- return null;
+ return processMetadata();
} else if (element.isTypedef) {
TypedefElement typdef = element;
- return resolveTypedef(typdef);
+ return processMetadata(resolveTypedef(typdef));
}
compiler.unimplemented(element, "resolve($element)");
@@ -542,10 +546,15 @@ class ResolverTask extends CompilerTask {
});
}
+ /// Creates a [ResolverVisitor] for resolving an AST in context of [element].
+ /// If [useEnclosingScope] is `true` then the initial scope of the visitor
+ /// does not include inner scope of [element].
+ ///
/// This method should only be used by this library (or tests of
/// this library).
- ResolverVisitor visitorFor(Element element) {
- return new ResolverVisitor(compiler, element, _ensureTreeElements(element));
+ ResolverVisitor visitorFor(Element element, {bool useEnclosingScope: false}) {
+ return new ResolverVisitor(compiler, element,
+ _ensureTreeElements(element), useEnclosingScope: useEnclosingScope);
}
TreeElements resolveField(VariableElementX element) {
@@ -1184,20 +1193,21 @@ class ResolverTask extends CompilerTask {
annotation.resolutionState = STATE_STARTED;
Node node = annotation.parseNode(compiler);
- // TODO(johnniwinther): Find the right analyzable element to hold the
- // [TreeElements] for the annotation.
Element annotatedElement = annotation.annotatedElement;
- Element context = annotatedElement.enclosingElement;
- if (context == null) {
- context = annotatedElement;
- }
- ResolverVisitor visitor = visitorFor(context);
+ Element context = annotatedElement.analyzableElement;
+ assert(invariant(node, context != null,
+ message: "No context found for metadata annotation "
+ "on $annotatedElement."));
+ assert(invariant(node, context is AnalyzableElement,
karlklose 2014/05/22 06:27:29 You could remove this, if the getter was typed ()
Johnni Winther 2014/05/22 10:09:09 Done.
+ message: "Unanalyzable context, $context, found for metadata "
+ "annotation on $annotatedElement."));
+ ResolverVisitor visitor = visitorFor(context, useEnclosingScope: true);
node.accept(visitor);
annotation.value =
constantCompiler.compileMetadata(annotation, node, visitor.mapping);
// TODO(johnniwinther): Register the relation between the annotation
- // and the annotated element instead. This will allow the backed to
- // retrieve the backend constant and only registered metadata on the
+ // and the annotated element instead. This will allow the backend to
+ // retrieve the backend constant and only register metadata on the
// elements for which it is needed. (Issue 17732).
compiler.backend.registerMetadataConstant(
annotation.value, visitor.mapping);
@@ -2002,7 +2012,8 @@ class ResolverVisitor extends MappingVisitor<Element> {
ResolverVisitor(Compiler compiler,
Element element,
- TreeElementMapping mapping)
+ TreeElementMapping mapping,
+ {bool useEnclosingScope: false})
: this.enclosingElement = element,
// When the element is a field, we are actually resolving its
// initial value, which should not have access to instance
@@ -2012,7 +2023,8 @@ class ResolverVisitor extends MappingVisitor<Element> {
this.currentClass = element.isMember ? element.enclosingClass
: null,
this.statementScope = new StatementScope(),
- scope = element.buildScope(),
+ scope = useEnclosingScope
+ ? Scope.buildEnclosingScope(element) : element.buildScope(),
// The type annotations on a typedef do not imply type checks.
// TODO(karlklose): clean this up (dartbug.com/8870).
inCheckContext = compiler.enableTypeAssertions &&

Powered by Google App Engine
This is Rietveld 408576698