Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 part of dart2js.kernel.world_builder; | |
| 6 | |
| 7 /// Computes that NativeBasicData for the libraries in [worldBuilder]. | |
| 8 // TODO(johnnniwinther): Move this to the AnnotationProcessor when it has been | |
|
Siggi Cherem (dart-lang)
2017/04/21 16:29:39
update TODO? I'm guessing this function will entir
Johnni Winther
2017/04/24 06:50:06
Done.
| |
| 9 // committed. | |
| 10 NativeBasicData computeNativeBasicData(KernelWorldBuilder worldBuilder) { | |
| 11 NativeBasicDataBuilderImpl builder = new NativeBasicDataBuilderImpl(); | |
| 12 ElementEnvironment elementEnvironment = worldBuilder.elementEnvironment; | |
| 13 for (LibraryEntity library in elementEnvironment.libraries) { | |
| 14 /// TODO(johnniwinther): Reuse `JavaScriptBackend.canLibraryUseNative` | |
| 15 /// instead. | |
| 16 if (library.canonicalUri.scheme == 'dart') { | |
| 17 new KernelAnnotationProcessor(worldBuilder) | |
| 18 .extractNativeAnnotations(library, builder); | |
| 19 } | |
| 20 } | |
| 21 return builder.close(elementEnvironment); | |
| 22 } | |
| 23 | |
| 24 class KernelAnnotationProcessor implements AnnotationProcessor { | |
| 25 final KernelWorldBuilder worldBuilder; | |
| 26 | |
| 27 KernelAnnotationProcessor(this.worldBuilder); | |
| 28 | |
| 29 void extractNativeAnnotations( | |
| 30 LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) { | |
| 31 ElementEnvironment elementEnvironment = worldBuilder.elementEnvironment; | |
| 32 CommonElements commonElements = worldBuilder.commonElements; | |
| 33 | |
| 34 elementEnvironment.forEachClass(library, (ClassEntity cls) { | |
| 35 String annotationName; | |
| 36 for (ConstantExpression annotation | |
| 37 in worldBuilder._getClassMetadata(cls)) { | |
|
Siggi Cherem (dart-lang)
2017/04/21 16:29:39
add TODO:
- make getClassMetadata public (with ou
Johnni Winther
2017/04/24 06:50:06
Done.
| |
| 38 ConstantValue value = | |
| 39 worldBuilder.constantEnvironment.getConstantValue(annotation); | |
| 40 String name = readAnnotationName( | |
| 41 cls, value, commonElements.nativeAnnotationClass); | |
| 42 if (annotationName == null) { | |
| 43 annotationName = name; | |
| 44 } else if (name != null) { | |
| 45 throw new SpannableAssertionFailure( | |
| 46 cls, 'Too many name annotations.'); | |
| 47 } | |
| 48 } | |
| 49 if (annotationName != null) { | |
| 50 nativeBasicDataBuilder.setNativeClassTagInfo(cls, annotationName); | |
| 51 } | |
| 52 }); | |
| 53 } | |
| 54 | |
| 55 void extractJsInteropAnnotations( | |
| 56 LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) { | |
| 57 throw new UnimplementedError( | |
| 58 'KernelAnnotationProcessor.extractJsInteropAnnotations'); | |
| 59 } | |
| 60 } | |
| OLD | NEW |