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

Unified Diff: pkg/compiler/lib/src/native/resolver.dart

Issue 2824423002: Compute NativeBasicData for KernelWorldBuilder (Closed)
Patch Set: Updated cf. comments. Created 3 years, 8 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: pkg/compiler/lib/src/native/resolver.dart
diff --git a/pkg/compiler/lib/src/native/resolver.dart b/pkg/compiler/lib/src/native/resolver.dart
index 8eaf14bbef7ad42f33549c7f746bddc71f07ffad..a90d780121fcf9d99ffd9facce05db88612d27d6 100644
--- a/pkg/compiler/lib/src/native/resolver.dart
+++ b/pkg/compiler/lib/src/native/resolver.dart
@@ -26,6 +26,7 @@ import '../elements/modelx.dart' show FunctionElementX, MetadataAnnotationX;
import '../elements/resolution_types.dart' show ResolutionDartType;
import '../js_backend/js_backend.dart';
import '../js_backend/native_data.dart';
+import '../kernel/world_builder.dart' show KernelAnnotationProcessor;
import '../patch_parser.dart';
import '../tree/tree.dart';
import 'behavior.dart';
@@ -34,7 +35,9 @@ import 'behavior.dart';
abstract class AnnotationProcessor {
factory AnnotationProcessor(Compiler compiler) =>
compiler.options.loadFromDill
- ? new _KernelAnnotationProcessor()
+ // TODO(johnniwinther): Pass the [KernelWorldBuilder] to
+ // [KernelAnnotationProcessor].
+ ? new KernelAnnotationProcessor(null)
: new _ElementAnnotationProcessor(compiler);
void extractNativeAnnotations(
@@ -44,20 +47,6 @@ abstract class AnnotationProcessor {
LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder);
}
-class _KernelAnnotationProcessor implements AnnotationProcessor {
- void extractNativeAnnotations(
- LibraryEntity entity, NativeBasicDataBuilder nativeBasicDataBuilder) {
- throw new UnimplementedError(
- '_KernelAnnotationProcessor.extractNativeAnnotations');
- }
-
- void extractJsInteropAnnotations(
- LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) {
- throw new UnimplementedError(
- '_KernelAnnotationProcessor.extractJsInteropAnnotations');
- }
-}
-
/// Original logic for annotation processing, which involves in some cases
/// triggering pre-parsing and validation of the annotations.
class _ElementAnnotationProcessor implements AnnotationProcessor {
@@ -294,33 +283,21 @@ class NativeDataResolverImpl implements NativeDataResolver {
/// Returns the JSName annotation string or `null` if no JSName annotation is
/// present.
String _findJsNameFromAnnotation(Element element) {
- String name = null;
- ClassElement annotationClass =
- _compiler.commonElements.annotationJSNameClass;
+ String jsName = null;
for (MetadataAnnotation annotation in element.implementation.metadata) {
annotation.ensureResolved(_compiler.resolution);
ConstantValue value =
_compiler.constants.getConstantValue(annotation.constant);
- if (!value.isConstructedObject) continue;
- ConstructedConstantValue constructedObject = value;
- if (constructedObject.type.element != annotationClass) continue;
-
- Iterable<ConstantValue> fields = constructedObject.fields.values;
- // TODO(sra): Better validation of the constant.
- if (fields.length != 1 || fields.single is! StringConstantValue) {
- _reporter.internalError(
- annotation, 'Annotations needs one string: ${annotation}');
- }
- StringConstantValue specStringConstant = fields.single;
- String specString = specStringConstant.toDartString().slowToString();
- if (name == null) {
- name = specString;
- } else {
- _reporter.internalError(
+ String name = readAnnotationName(
+ annotation, value, _compiler.commonElements.annotationJSNameClass);
+ if (jsName == null) {
+ jsName = name;
+ } else if (name != null) {
+ throw new SpannableAssertionFailure(
annotation, 'Too many JSName annotations: ${annotation}');
}
}
- return name;
+ return jsName;
}
@override
@@ -376,7 +353,8 @@ class NativeAnnotationHandler extends EagerAnnotationHandler<String> {
ClassElement cls = element;
String native = getNativeAnnotation(annotation);
if (native != null) {
- _nativeBasicDataBuilder.setNativeClassTagInfo(cls, native);
+ String tagText = native.substring(1, native.length - 1);
+ _nativeBasicDataBuilder.setNativeClassTagInfo(cls, tagText);
return native;
}
}
@@ -616,3 +594,21 @@ class NativeClassResolverImpl implements NativeClassResolver {
});
}
}
+
+/// Extracts the name if [value] is a named annotation based on
+/// [annotationClass], otherwise returns `null`.
+String readAnnotationName(
+ Spannable spannable, ConstantValue value, ClassEntity annotationClass) {
+ if (!value.isConstructedObject) return null;
+ ConstructedConstantValue constructedObject = value;
+ if (constructedObject.type.element != annotationClass) return null;
+
+ Iterable<ConstantValue> fields = constructedObject.fields.values;
+ // TODO(sra): Better validation of the constant.
+ if (fields.length != 1 || fields.single is! StringConstantValue) {
+ throw new SpannableAssertionFailure(
+ spannable, 'Annotations needs one string: ${value.toStructuredText()}');
+ }
+ StringConstantValue specStringConstant = fields.single;
+ return specStringConstant.toDartString().slowToString();
+}
« no previous file with comments | « pkg/compiler/lib/src/kernel/world_builder.dart ('k') | tests/compiler/dart2js/kernel/closed_world2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698