Chromium Code Reviews| Index: pkg/compiler/lib/src/kernel/native_basic_data.dart |
| diff --git a/pkg/compiler/lib/src/kernel/native_basic_data.dart b/pkg/compiler/lib/src/kernel/native_basic_data.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b1e0386c12434553fb0a2c1fb95f7fe84d85bc61 |
| --- /dev/null |
| +++ b/pkg/compiler/lib/src/kernel/native_basic_data.dart |
| @@ -0,0 +1,60 @@ |
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +part of dart2js.kernel.world_builder; |
| + |
| +/// Computes that NativeBasicData for the libraries in [worldBuilder]. |
| +// 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.
|
| +// committed. |
| +NativeBasicData computeNativeBasicData(KernelWorldBuilder worldBuilder) { |
| + NativeBasicDataBuilderImpl builder = new NativeBasicDataBuilderImpl(); |
| + ElementEnvironment elementEnvironment = worldBuilder.elementEnvironment; |
| + for (LibraryEntity library in elementEnvironment.libraries) { |
| + /// TODO(johnniwinther): Reuse `JavaScriptBackend.canLibraryUseNative` |
| + /// instead. |
| + if (library.canonicalUri.scheme == 'dart') { |
| + new KernelAnnotationProcessor(worldBuilder) |
| + .extractNativeAnnotations(library, builder); |
| + } |
| + } |
| + return builder.close(elementEnvironment); |
| +} |
| + |
| +class KernelAnnotationProcessor implements AnnotationProcessor { |
| + final KernelWorldBuilder worldBuilder; |
| + |
| + KernelAnnotationProcessor(this.worldBuilder); |
| + |
| + void extractNativeAnnotations( |
| + LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) { |
| + ElementEnvironment elementEnvironment = worldBuilder.elementEnvironment; |
| + CommonElements commonElements = worldBuilder.commonElements; |
| + |
| + elementEnvironment.forEachClass(library, (ClassEntity cls) { |
| + String annotationName; |
| + for (ConstantExpression annotation |
| + 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.
|
| + ConstantValue value = |
| + worldBuilder.constantEnvironment.getConstantValue(annotation); |
| + String name = readAnnotationName( |
| + cls, value, commonElements.nativeAnnotationClass); |
| + if (annotationName == null) { |
| + annotationName = name; |
| + } else if (name != null) { |
| + throw new SpannableAssertionFailure( |
| + cls, 'Too many name annotations.'); |
| + } |
| + } |
| + if (annotationName != null) { |
| + nativeBasicDataBuilder.setNativeClassTagInfo(cls, annotationName); |
| + } |
| + }); |
| + } |
| + |
| + void extractJsInteropAnnotations( |
| + LibraryEntity library, NativeBasicDataBuilder nativeBasicDataBuilder) { |
| + throw new UnimplementedError( |
| + 'KernelAnnotationProcessor.extractJsInteropAnnotations'); |
| + } |
| +} |