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

Side by Side Diff: pkg/compiler/lib/src/native/behavior.dart

Issue 1302333006: Support metadata on patches. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Remove partial renaming Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 native; 5 part of native;
6 6
7 /// This class is a temporary work-around until we get a more powerful DartType. 7 /// This class is a temporary work-around until we get a more powerful DartType.
8 class SpecialType { 8 class SpecialType {
9 final String name; 9 final String name;
10 const SpecialType._(this.name); 10 const SpecialType._(this.name);
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 static NativeBehavior ofFieldStore(MemberElement field, Compiler compiler) { 645 static NativeBehavior ofFieldStore(MemberElement field, Compiler compiler) {
646 DartType type = field.computeType(compiler); 646 DartType type = field.computeType(compiler);
647 var behavior = new NativeBehavior(); 647 var behavior = new NativeBehavior();
648 behavior._escape(type, compiler); 648 behavior._escape(type, compiler);
649 // We don't override the default behaviour - the annotations apply to 649 // We don't override the default behaviour - the annotations apply to
650 // loading the field. 650 // loading the field.
651 return behavior; 651 return behavior;
652 } 652 }
653 653
654 void _overrideWithAnnotations(Element element, Compiler compiler) { 654 void _overrideWithAnnotations(Element element, Compiler compiler) {
655 if (element.metadata.isEmpty) return; 655 if (element.implementation.metadata.isEmpty) return;
656 656
657 DartType lookup(String name) { 657 DartType lookup(String name) {
658 Element e = element.buildScope().lookup(name); 658 Element e = element.buildScope().lookup(name);
659 if (e == null) return null; 659 if (e == null) return null;
660 if (e is! ClassElement) return null; 660 if (e is! ClassElement) return null;
661 ClassElement cls = e; 661 ClassElement cls = e;
662 cls.ensureResolved(compiler); 662 cls.ensureResolved(compiler);
663 return cls.thisType; 663 return cls.thisType;
664 } 664 }
665 665
(...skipping 12 matching lines...) Expand all
678 } 678 }
679 679
680 /** 680 /**
681 * Returns a list of type constraints from the annotations of 681 * Returns a list of type constraints from the annotations of
682 * [annotationClass]. 682 * [annotationClass].
683 * Returns `null` if no constraints. 683 * Returns `null` if no constraints.
684 */ 684 */
685 static _collect(Element element, Compiler compiler, Element annotationClass, 685 static _collect(Element element, Compiler compiler, Element annotationClass,
686 lookup(str)) { 686 lookup(str)) {
687 var types = null; 687 var types = null;
688 for (Link<MetadataAnnotation> link = element.metadata; 688 for (MetadataAnnotation annotation in element.implementation.metadata) {
689 !link.isEmpty; 689 annotation.ensureResolved(compiler);
690 link = link.tail) {
691 MetadataAnnotation annotation = link.head.ensureResolved(compiler);
692 ConstantValue value = 690 ConstantValue value =
693 compiler.constants.getConstantValue(annotation.constant); 691 compiler.constants.getConstantValue(annotation.constant);
694 if (!value.isConstructedObject) continue; 692 if (!value.isConstructedObject) continue;
695 ConstructedConstantValue constructedObject = value; 693 ConstructedConstantValue constructedObject = value;
696 if (constructedObject.type.element != annotationClass) continue; 694 if (constructedObject.type.element != annotationClass) continue;
697 695
698 Iterable<ConstantValue> fields = constructedObject.fields.values; 696 Iterable<ConstantValue> fields = constructedObject.fields.values;
699 // TODO(sra): Better validation of the constant. 697 // TODO(sra): Better validation of the constant.
700 if (fields.length != 1 || !fields.single.isString) { 698 if (fields.length != 1 || !fields.single.isString) {
701 PartialMetadataAnnotation partial = annotation; 699 PartialMetadataAnnotation partial = annotation;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 MessageKind.GENERIC, 769 MessageKind.GENERIC,
772 {'text': "Type '$typeString' not found."}); 770 {'text': "Type '$typeString' not found."});
773 return const DynamicType(); 771 return const DynamicType();
774 } 772 }
775 773
776 static _errorNode(locationNodeOrElement, compiler) { 774 static _errorNode(locationNodeOrElement, compiler) {
777 if (locationNodeOrElement is Node) return locationNodeOrElement; 775 if (locationNodeOrElement is Node) return locationNodeOrElement;
778 return locationNodeOrElement.parseNode(compiler); 776 return locationNodeOrElement.parseNode(compiler);
779 } 777 }
780 } 778 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698