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

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

Issue 297903004: Revert "Handle metadata on nested function parameters." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
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 part of resolution; 5 part of resolution;
6 6
7 abstract class TreeElements { 7 abstract class TreeElements {
8 Element get currentElement; 8 Element get currentElement;
9 Setlet<Node> get superUses; 9 Setlet<Node> get superUses;
10 10
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 final ConstantCompiler constantCompiler; 252 final ConstantCompiler constantCompiler;
253 253
254 ResolverTask(Compiler compiler, this.constantCompiler) : super(compiler); 254 ResolverTask(Compiler compiler, this.constantCompiler) : super(compiler);
255 255
256 String get name => 'Resolver'; 256 String get name => 'Resolver';
257 257
258 TreeElements resolve(Element element) { 258 TreeElements resolve(Element element) {
259 return measure(() { 259 return measure(() {
260 if (Elements.isErroneousElement(element)) return null; 260 if (Elements.isErroneousElement(element)) return null;
261 261
262 processMetadata([result]) { 262 for (MetadataAnnotation metadata in element.metadata) {
263 for (MetadataAnnotation metadata in element.metadata) { 263 metadata.ensureResolved(compiler);
264 metadata.ensureResolved(compiler);
265 }
266 return result;
267 } 264 }
268 265
269 ElementKind kind = element.kind; 266 ElementKind kind = element.kind;
270 if (identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR) || 267 if (identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR) ||
271 identical(kind, ElementKind.FUNCTION) || 268 identical(kind, ElementKind.FUNCTION) ||
272 identical(kind, ElementKind.GETTER) || 269 identical(kind, ElementKind.GETTER) ||
273 identical(kind, ElementKind.SETTER)) { 270 identical(kind, ElementKind.SETTER)) {
274 return processMetadata(resolveMethodElement(element)); 271 return resolveMethodElement(element);
275 } 272 }
276 273
277 if (identical(kind, ElementKind.FIELD)) { 274 if (identical(kind, ElementKind.FIELD)) return resolveField(element);
278 return processMetadata(resolveField(element)); 275
279 }
280 if (element.isClass) { 276 if (element.isClass) {
281 ClassElement cls = element; 277 ClassElement cls = element;
282 cls.ensureResolved(compiler); 278 cls.ensureResolved(compiler);
283 return processMetadata(); 279 return null;
284 } else if (element.isTypedef) { 280 } else if (element.isTypedef) {
285 TypedefElement typdef = element; 281 TypedefElement typdef = element;
286 return processMetadata(resolveTypedef(typdef)); 282 return resolveTypedef(typdef);
287 } 283 }
288 284
289 compiler.unimplemented(element, "resolve($element)"); 285 compiler.unimplemented(element, "resolve($element)");
290 }); 286 });
291 } 287 }
292 288
293 String constructorNameForDiagnostics(String className, 289 String constructorNameForDiagnostics(String className,
294 String constructorName) { 290 String constructorName) {
295 String classNameString = className; 291 String classNameString = className;
296 String constructorNameString = constructorName; 292 String constructorNameString = constructorName;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 for (MixinApplicationElement mixinApplication in mixinUses) { 539 for (MixinApplicationElement mixinApplication in mixinUses) {
544 checkMixinSuperUses(resolutionTree, mixinApplication, mixin); 540 checkMixinSuperUses(resolutionTree, mixinApplication, mixin);
545 } 541 }
546 } 542 }
547 } 543 }
548 return resolutionTree; 544 return resolutionTree;
549 }); 545 });
550 }); 546 });
551 } 547 }
552 548
553 /// Creates a [ResolverVisitor] for resolving an AST in context of [element].
554 /// If [useEnclosingScope] is `true` then the initial scope of the visitor
555 /// does not include inner scope of [element].
556 ///
557 /// This method should only be used by this library (or tests of 549 /// This method should only be used by this library (or tests of
558 /// this library). 550 /// this library).
559 ResolverVisitor visitorFor(Element element, {bool useEnclosingScope: false}) { 551 ResolverVisitor visitorFor(Element element) {
560 return new ResolverVisitor(compiler, element, 552 return new ResolverVisitor(compiler, element,
561 new ResolutionRegistry(compiler, element), 553 new ResolutionRegistry(compiler, element));
562 useEnclosingScope: useEnclosingScope);
563 } 554 }
564 555
565 TreeElements resolveField(VariableElementX element) { 556 TreeElements resolveField(VariableElementX element) {
566 VariableDefinitions tree = element.parseNode(compiler); 557 VariableDefinitions tree = element.parseNode(compiler);
567 if(element.modifiers.isStatic && element.isTopLevel) { 558 if(element.modifiers.isStatic && element.isTopLevel) {
568 error(element.modifiers.getStatic(), 559 error(element.modifiers.getStatic(),
569 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC); 560 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC);
570 } 561 }
571 ResolverVisitor visitor = visitorFor(element); 562 ResolverVisitor visitor = visitorFor(element);
572 ResolutionRegistry registry = visitor.registry; 563 ResolutionRegistry registry = visitor.registry;
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 }); 1186 });
1196 }); 1187 });
1197 } 1188 }
1198 1189
1199 void resolveMetadataAnnotation(MetadataAnnotationX annotation) { 1190 void resolveMetadataAnnotation(MetadataAnnotationX annotation) {
1200 compiler.withCurrentElement(annotation.annotatedElement, () => measure(() { 1191 compiler.withCurrentElement(annotation.annotatedElement, () => measure(() {
1201 assert(annotation.resolutionState == STATE_NOT_STARTED); 1192 assert(annotation.resolutionState == STATE_NOT_STARTED);
1202 annotation.resolutionState = STATE_STARTED; 1193 annotation.resolutionState = STATE_STARTED;
1203 1194
1204 Node node = annotation.parseNode(compiler); 1195 Node node = annotation.parseNode(compiler);
1196 // TODO(johnniwinther): Find the right analyzable element to hold the
1197 // [TreeElements] for the annotation.
1205 Element annotatedElement = annotation.annotatedElement; 1198 Element annotatedElement = annotation.annotatedElement;
1206 AnalyzableElement context = annotatedElement.analyzableElement; 1199 Element context = annotatedElement.enclosingElement;
1207 assert(invariant(node, context != null, 1200 if (context == null) {
1208 message: "No context found for metadata annotation " 1201 context = annotatedElement;
1209 "on $annotatedElement.")); 1202 }
1210 ResolverVisitor visitor = visitorFor(context, useEnclosingScope: true); 1203 ResolverVisitor visitor = visitorFor(context);
1211 ResolutionRegistry registry = visitor.registry; 1204 ResolutionRegistry registry = visitor.registry;
1212 node.accept(visitor); 1205 node.accept(visitor);
1213 // TODO(johnniwinther): Avoid passing the [TreeElements] to 1206 // TODO(johnniwinther): Avoid passing the [TreeElements] to
1214 // [compileMetadata]. 1207 // [compileMetadata].
1215 annotation.value = 1208 annotation.value =
1216 constantCompiler.compileMetadata(annotation, node, registry.mapping); 1209 constantCompiler.compileMetadata(annotation, node, registry.mapping);
1217 // TODO(johnniwinther): Register the relation between the annotation 1210 // TODO(johnniwinther): Register the relation between the annotation
1218 // and the annotated element instead. This will allow the backend to 1211 // and the annotated element instead. This will allow the backed to
1219 // retrieve the backend constant and only register metadata on the 1212 // retrieve the backend constant and only registered metadata on the
1220 // elements for which it is needed. (Issue 17732). 1213 // elements for which it is needed. (Issue 17732).
1221 registry.registerMetadataConstant(annotation.value); 1214 registry.registerMetadataConstant(annotation.value);
1222 annotation.resolutionState = STATE_DONE; 1215 annotation.resolutionState = STATE_DONE;
1223 })); 1216 }));
1224 } 1217 }
1225 1218
1226 error(Spannable node, MessageKind kind, [arguments = const {}]) { 1219 error(Spannable node, MessageKind kind, [arguments = const {}]) {
1227 // TODO(ahe): Make non-fatal. 1220 // TODO(ahe): Make non-fatal.
1228 compiler.reportFatalError(node, kind, arguments); 1221 compiler.reportFatalError(node, kind, arguments);
1229 } 1222 }
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 r'>|' 1995 r'>|'
2003 r'<=|' 1996 r'<=|'
2004 r'<|' 1997 r'<|'
2005 r'&|' 1998 r'&|'
2006 r'\^|' 1999 r'\^|'
2007 r'\|' 2000 r'\|'
2008 r')$'); 2001 r')$');
2009 2002
2010 ResolverVisitor(Compiler compiler, 2003 ResolverVisitor(Compiler compiler,
2011 Element element, 2004 Element element,
2012 ResolutionRegistry registry, 2005 ResolutionRegistry registry)
2013 {bool useEnclosingScope: false})
2014 : this.enclosingElement = element, 2006 : this.enclosingElement = element,
2015 // When the element is a field, we are actually resolving its 2007 // When the element is a field, we are actually resolving its
2016 // initial value, which should not have access to instance 2008 // initial value, which should not have access to instance
2017 // fields. 2009 // fields.
2018 inInstanceContext = (element.isInstanceMember && !element.isField) 2010 inInstanceContext = (element.isInstanceMember && !element.isField)
2019 || element.isGenerativeConstructor, 2011 || element.isGenerativeConstructor,
2020 this.currentClass = element.isMember ? element.enclosingClass 2012 this.currentClass = element.isMember ? element.enclosingClass
2021 : null, 2013 : null,
2022 this.statementScope = new StatementScope(), 2014 this.statementScope = new StatementScope(),
2023 scope = useEnclosingScope 2015 scope = element.buildScope(),
2024 ? Scope.buildEnclosingScope(element) : element.buildScope(),
2025 // The type annotations on a typedef do not imply type checks. 2016 // The type annotations on a typedef do not imply type checks.
2026 // TODO(karlklose): clean this up (dartbug.com/8870). 2017 // TODO(karlklose): clean this up (dartbug.com/8870).
2027 inCheckContext = compiler.enableTypeAssertions && 2018 inCheckContext = compiler.enableTypeAssertions &&
2028 !element.isLibrary && 2019 !element.isLibrary &&
2029 !element.isTypedef && 2020 !element.isTypedef &&
2030 !element.enclosingElement.isTypedef, 2021 !element.enclosingElement.isTypedef,
2031 inCatchBlock = false, 2022 inCatchBlock = false,
2032 super(compiler, registry); 2023 super(compiler, registry);
2033 2024
2034 Element reportLookupErrorIfAny(Element result, Node node, String name) { 2025 Element reportLookupErrorIfAny(Element result, Node node, String name) {
(...skipping 2623 matching lines...) Expand 10 before | Expand all | Expand 10 after
4658 expression, expression); 4649 expression, expression);
4659 } 4650 }
4660 } 4651 }
4661 4652
4662 /// Looks up [name] in [scope] and unwraps the result. 4653 /// Looks up [name] in [scope] and unwraps the result.
4663 Element lookupInScope(Compiler compiler, Node node, 4654 Element lookupInScope(Compiler compiler, Node node,
4664 Scope scope, String name) { 4655 Scope scope, String name) {
4665 return Elements.unwrap(scope.lookup(name), compiler, node); 4656 return Elements.unwrap(scope.lookup(name), compiler, node);
4666 } 4657 }
4667 4658
4668 TreeElements _ensureTreeElements(AnalyzableElementX element) { 4659 TreeElements _ensureTreeElements(AnalyzableElement element) {
4669 if (element._treeElements == null) { 4660 if (element._treeElements == null) {
4670 element._treeElements = new TreeElementMapping(element); 4661 element._treeElements = new TreeElementMapping(element);
4671 } 4662 }
4672 return element._treeElements; 4663 return element._treeElements;
4673 } 4664 }
4674 4665
4675 abstract class AnalyzableElementX implements AnalyzableElement { 4666 abstract class AnalyzableElement implements Element {
4676 TreeElements _treeElements; 4667 TreeElements _treeElements;
4677 4668
4678 bool get hasTreeElements => _treeElements != null; 4669 bool get hasTreeElements => _treeElements != null;
4679 4670
4680 TreeElements get treeElements { 4671 TreeElements get treeElements {
4681 assert(invariant(this, _treeElements !=null, 4672 assert(invariant(this, _treeElements !=null,
4682 message: "TreeElements have not been computed for $this.")); 4673 message: "TreeElements have not been computed for $this."));
4683 return _treeElements; 4674 return _treeElements;
4684 } 4675 }
4685 } 4676 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirrors.dart ('k') | tests/language/metadata_scope1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698