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

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

Issue 2824123003: Make backend.setAnnotations (mostly) handle LibraryEntities. (Closed)
Patch Set: 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
« no previous file with comments | « pkg/compiler/lib/src/kernel/world_builder.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 b7163e9a559a7c88cc5b0816bc9d2ef3b9ba2a82..8eaf14bbef7ad42f33549c7f746bddc71f07ffad 100644
--- a/pkg/compiler/lib/src/native/resolver.dart
+++ b/pkg/compiler/lib/src/native/resolver.dart
@@ -30,6 +30,74 @@ import '../patch_parser.dart';
import '../tree/tree.dart';
import 'behavior.dart';
+/// Class that performs the mechanics to investigate annotations in the code.
+abstract class AnnotationProcessor {
+ factory AnnotationProcessor(Compiler compiler) =>
+ compiler.options.loadFromDill
+ ? new _KernelAnnotationProcessor()
+ : new _ElementAnnotationProcessor(compiler);
+
+ void extractNativeAnnotations(
+ LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder);
+
+ void extractJsInteropAnnotations(
+ 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 {
+ Compiler _compiler;
+
+ _ElementAnnotationProcessor(this._compiler);
+
+ /// Check whether [cls] has a `@Native(...)` annotation, and if so, set its
+ /// native name from the annotation.
+ void extractNativeAnnotations(
+ LibraryElement library, NativeBasicDataBuilder nativeBasicDataBuilder) {
+ library.forEachLocalMember((Element element) {
+ if (element.isClass) {
+ EagerAnnotationHandler.checkAnnotation(_compiler, element,
+ new NativeAnnotationHandler(nativeBasicDataBuilder));
+ }
+ });
+ }
+
+ void extractJsInteropAnnotations(
+ LibraryElement library, NativeBasicDataBuilder nativeBasicDataBuilder) {
+ bool checkJsInteropAnnotation(Element element) {
+ return EagerAnnotationHandler.checkAnnotation(
+ _compiler, element, const JsInteropAnnotationHandler());
+ }
+
+ if (checkJsInteropAnnotation(library)) {
+ nativeBasicDataBuilder.markAsJsInteropLibrary(library);
+ }
+ library.forEachLocalMember((Element element) {
+ if (element.isClass) {
+ ClassElement cls = element;
+ if (checkJsInteropAnnotation(element)) {
+ nativeBasicDataBuilder.markAsJsInteropClass(cls);
+ }
+ }
+ });
+ }
+}
+
/// Interface for computing native members and [NativeBehavior]s in member code
/// based on the AST.
abstract class NativeDataResolver {
@@ -327,26 +395,6 @@ class NativeAnnotationHandler extends EagerAnnotationHandler<String> {
}
}
-void checkJsInteropClassAnnotations(Compiler compiler, LibraryElement library,
- NativeBasicDataBuilder nativeBasicDataBuilder) {
- bool checkJsInteropAnnotation(Element element) {
- return EagerAnnotationHandler.checkAnnotation(
- compiler, element, const JsInteropAnnotationHandler());
- }
-
- if (checkJsInteropAnnotation(library)) {
- nativeBasicDataBuilder.markAsJsInteropLibrary(library);
- }
- library.forEachLocalMember((Element element) {
- if (element.isClass) {
- ClassElement cls = element;
- if (checkJsInteropAnnotation(element)) {
- nativeBasicDataBuilder.markAsJsInteropClass(cls);
- }
- }
- });
-}
-
bool checkJsInteropMemberAnnotations(Compiler compiler, MemberElement element,
NativeDataBuilder nativeDataBuilder) {
bool isJsInterop = EagerAnnotationHandler.checkAnnotation(
« no previous file with comments | « pkg/compiler/lib/src/kernel/world_builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698