Generate needed classes for constant maps in metadata.

BUG=http://dartbug.com/20776
R=floitsch@google.com

Review URL: https://codereview.chromium.org//541683002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@39860 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
johnniwinther@google.com 2014-09-04 11:48:48 +00:00
parent 4c747eae55
commit 7685bced04
5 changed files with 33 additions and 7 deletions

View file

@ -278,9 +278,9 @@ abstract class Backend {
/// Called during codegen when [constant] has been used.
void registerCompileTimeConstant(Constant constant, Registry registry) {}
/// Called during resolution when a metadata [constant] for [annotatedElement]
/// has been evaluated.
void registerMetadataConstant(Constant constant,
/// Called during resolution when a constant value for [metadata] on
/// [annotatedElement] has been evaluated.
void registerMetadataConstant(MetadataAnnotation metadata,
Element annotatedElement,
Registry registry) {}

View file

@ -726,10 +726,11 @@ class JavaScriptBackend extends Backend {
}
}
void registerMetadataConstant(Constant constant,
void registerMetadataConstant(MetadataAnnotation metadata,
Element annotatedElement,
Registry registry) {
assert(registry.isForResolution);
Constant constant = constants.getConstantForMetadata(metadata);
registerCompileTimeConstant(constant, registry);
metadataConstants.add(new Dependency(constant, annotatedElement));
}

View file

@ -1407,7 +1407,7 @@ class ResolverTask extends CompilerTask {
// 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).
registry.registerMetadataConstant(annotation.value, annotatedElement);
registry.registerMetadataConstant(annotation, annotatedElement);
annotation.resolutionState = STATE_DONE;
}));
}

View file

@ -205,8 +205,9 @@ class ResolutionRegistry extends Registry {
backend.resolutionCallbacks.onLazyField(this);
}
void registerMetadataConstant(Constant constant, Element annotatedElement) {
backend.registerMetadataConstant(constant, annotatedElement, this);
void registerMetadataConstant(MetadataAnnotation metadata,
Element annotatedElement) {
backend.registerMetadataConstant(metadata, annotatedElement, this);
}
void registerThrowRuntimeError() {

View file

@ -0,0 +1,24 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for issue 20776. Tests that the needed classes for the
// constant map in the metadata are generated.
library lib;
@MirrorsUsed(targets: 'lib')
import 'dart:mirrors';
class C {
final x;
const C(this.x);
}
@C(const {'foo': 'bar' })
class A {}
main() {
print(reflectClass(A).metadata);
}