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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/kernel/world_builder.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'package:front_end/src/fasta/scanner.dart' 5 import 'package:front_end/src/fasta/scanner.dart'
6 show BeginGroupToken, StringToken, Token; 6 show BeginGroupToken, StringToken, Token;
7 import 'package:front_end/src/fasta/scanner.dart' as Tokens show EOF_TOKEN; 7 import 'package:front_end/src/fasta/scanner.dart' as Tokens show EOF_TOKEN;
8 8
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common_elements.dart' show CommonElements; 10 import '../common_elements.dart' show CommonElements;
(...skipping 12 matching lines...) Expand all
23 MethodElement; 23 MethodElement;
24 import '../elements/entities.dart'; 24 import '../elements/entities.dart';
25 import '../elements/modelx.dart' show FunctionElementX, MetadataAnnotationX; 25 import '../elements/modelx.dart' show FunctionElementX, MetadataAnnotationX;
26 import '../elements/resolution_types.dart' show ResolutionDartType; 26 import '../elements/resolution_types.dart' show ResolutionDartType;
27 import '../js_backend/js_backend.dart'; 27 import '../js_backend/js_backend.dart';
28 import '../js_backend/native_data.dart'; 28 import '../js_backend/native_data.dart';
29 import '../patch_parser.dart'; 29 import '../patch_parser.dart';
30 import '../tree/tree.dart'; 30 import '../tree/tree.dart';
31 import 'behavior.dart'; 31 import 'behavior.dart';
32 32
33 /// Class that performs the mechanics to investigate annotations in the code.
34 abstract class AnnotationProcessor {
35 factory AnnotationProcessor(Compiler compiler) =>
36 compiler.options.loadFromDill
37 ? new _KernelAnnotationProcessor()
38 : new _ElementAnnotationProcessor(compiler);
39
40 void extractNativeAnnotations(
41 LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder);
42
43 void extractJsInteropAnnotations(
44 LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder);
45 }
46
47 class _KernelAnnotationProcessor implements AnnotationProcessor {
48 void extractNativeAnnotations(
49 LibraryEntity entity, NativeBasicDataBuilder nativeBasicDataBuilder) {
50 throw new UnimplementedError(
51 '_KernelAnnotationProcessor.extractNativeAnnotations');
52 }
53
54 void extractJsInteropAnnotations(
55 LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) {
56 throw new UnimplementedError(
57 '_KernelAnnotationProcessor.extractJsInteropAnnotations');
58 }
59 }
60
61 /// Original logic for annotation processing, which involves in some cases
62 /// triggering pre-parsing and validation of the annotations.
63 class _ElementAnnotationProcessor implements AnnotationProcessor {
64 Compiler _compiler;
65
66 _ElementAnnotationProcessor(this._compiler);
67
68 /// Check whether [cls] has a `@Native(...)` annotation, and if so, set its
69 /// native name from the annotation.
70 void extractNativeAnnotations(
71 LibraryElement library, NativeBasicDataBuilder nativeBasicDataBuilder) {
72 library.forEachLocalMember((Element element) {
73 if (element.isClass) {
74 EagerAnnotationHandler.checkAnnotation(_compiler, element,
75 new NativeAnnotationHandler(nativeBasicDataBuilder));
76 }
77 });
78 }
79
80 void extractJsInteropAnnotations(
81 LibraryElement library, NativeBasicDataBuilder nativeBasicDataBuilder) {
82 bool checkJsInteropAnnotation(Element element) {
83 return EagerAnnotationHandler.checkAnnotation(
84 _compiler, element, const JsInteropAnnotationHandler());
85 }
86
87 if (checkJsInteropAnnotation(library)) {
88 nativeBasicDataBuilder.markAsJsInteropLibrary(library);
89 }
90 library.forEachLocalMember((Element element) {
91 if (element.isClass) {
92 ClassElement cls = element;
93 if (checkJsInteropAnnotation(element)) {
94 nativeBasicDataBuilder.markAsJsInteropClass(cls);
95 }
96 }
97 });
98 }
99 }
100
33 /// Interface for computing native members and [NativeBehavior]s in member code 101 /// Interface for computing native members and [NativeBehavior]s in member code
34 /// based on the AST. 102 /// based on the AST.
35 abstract class NativeDataResolver { 103 abstract class NativeDataResolver {
36 /// Returns `true` if [element] is a JsInterop member. 104 /// Returns `true` if [element] is a JsInterop member.
37 bool isJsInteropMember(MemberElement element); 105 bool isJsInteropMember(MemberElement element);
38 106
39 /// Computes whether [element] is native or JsInterop and, if so, registers 107 /// Computes whether [element] is native or JsInterop and, if so, registers
40 /// its [NativeBehavior]s to [registry]. 108 /// its [NativeBehavior]s to [registry].
41 void resolveNativeMember(MemberElement element, NativeRegistry registry); 109 void resolveNativeMember(MemberElement element, NativeRegistry registry);
42 110
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 ResolutionDartType annotationType = 388 ResolutionDartType annotationType =
321 constant.getType(compiler.commonElements); 389 constant.getType(compiler.commonElements);
322 if (annotationType.element != 390 if (annotationType.element !=
323 compiler.commonElements.nativeAnnotationClass) { 391 compiler.commonElements.nativeAnnotationClass) {
324 DiagnosticReporter reporter = compiler.reporter; 392 DiagnosticReporter reporter = compiler.reporter;
325 reporter.internalError(annotation, 'Invalid @Native(...) annotation.'); 393 reporter.internalError(annotation, 'Invalid @Native(...) annotation.');
326 } 394 }
327 } 395 }
328 } 396 }
329 397
330 void checkJsInteropClassAnnotations(Compiler compiler, LibraryElement library,
331 NativeBasicDataBuilder nativeBasicDataBuilder) {
332 bool checkJsInteropAnnotation(Element element) {
333 return EagerAnnotationHandler.checkAnnotation(
334 compiler, element, const JsInteropAnnotationHandler());
335 }
336
337 if (checkJsInteropAnnotation(library)) {
338 nativeBasicDataBuilder.markAsJsInteropLibrary(library);
339 }
340 library.forEachLocalMember((Element element) {
341 if (element.isClass) {
342 ClassElement cls = element;
343 if (checkJsInteropAnnotation(element)) {
344 nativeBasicDataBuilder.markAsJsInteropClass(cls);
345 }
346 }
347 });
348 }
349
350 bool checkJsInteropMemberAnnotations(Compiler compiler, MemberElement element, 398 bool checkJsInteropMemberAnnotations(Compiler compiler, MemberElement element,
351 NativeDataBuilder nativeDataBuilder) { 399 NativeDataBuilder nativeDataBuilder) {
352 bool isJsInterop = EagerAnnotationHandler.checkAnnotation( 400 bool isJsInterop = EagerAnnotationHandler.checkAnnotation(
353 compiler, element, const JsInteropAnnotationHandler()); 401 compiler, element, const JsInteropAnnotationHandler());
354 if (isJsInterop) { 402 if (isJsInterop) {
355 nativeDataBuilder.markAsJsInteropMember(element); 403 nativeDataBuilder.markAsJsInteropMember(element);
356 } 404 }
357 return isJsInterop; 405 return isJsInterop;
358 } 406 }
359 407
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 } 609 }
562 // Should be at '{', 'with', 'implements', '<' or 'native'. 610 // Should be at '{', 'with', 'implements', '<' or 'native'.
563 return id.lexeme; 611 return id.lexeme;
564 } 612 }
565 613
566 return _reporter.withCurrentElement(classElement, () { 614 return _reporter.withCurrentElement(classElement, () {
567 return scanForExtendsName(classElement.position); 615 return scanForExtendsName(classElement.position);
568 }); 616 });
569 } 617 }
570 } 618 }
OLDNEW
« 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