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

Unified Diff: pkg/compiler/lib/src/js_backend/native_data.dart

Issue 2721403006: Split NativeData (Closed)
Patch Set: Created 3 years, 10 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/js_backend/native_data.dart
diff --git a/pkg/compiler/lib/src/js_backend/native_data.dart b/pkg/compiler/lib/src/js_backend/native_data.dart
index 969fc3a2d3f0117f163dbffbfa902b23fcb77129..268eb3f79eb4c62732e558613dbd620dbc547a28 100644
--- a/pkg/compiler/lib/src/js_backend/native_data.dart
+++ b/pkg/compiler/lib/src/js_backend/native_data.dart
@@ -6,13 +6,110 @@ library js_backend.native_data;
import '../common.dart';
import '../elements/elements.dart'
- show ClassElement, Element, FieldElement, FunctionElement, MemberElement;
+ show
+ ClassElement,
+ Element,
+ FieldElement,
+ FunctionElement,
+ MemberElement,
+ MethodElement;
import '../elements/entities.dart';
import '../native/behavior.dart' show NativeBehavior;
/// Additional element information for native classes and methods and js-interop
/// methods.
-class NativeData {
+abstract class NativeData {
+ /// Returns `true` if [cls] corresponds to a native JavaScript class.
+ ///
+ /// A class is marked as native either through the `@Native(...)` annotation
+ /// allowed for internal libraries or via the typed JavaScriptInterop
+ /// mechanism allowed for user libraries.
+ bool isNativeClass(ClassEntity element);
+
+ /// Returns `true` if [element] corresponds to a native JavaScript member.
+ ///
+ /// A member is marked as native either through the native mechanism
+ /// (`@Native(...)` or the `native` pseudo keyword) allowed for internal
Siggi Cherem (dart-lang) 2017/03/14 00:15:59 doesn't this require also `external`?
Johnni Winther 2017/03/14 15:48:04 We correctly don't use external in dart:html.
+ /// libraries or via the typed JavaScriptInterop mechanism allowed for user
+ /// libraries.
+ bool isNativeMember(MemberEntity element);
+
+ /// Returns `true` if [element] or any of its superclasses is native.
+ bool isNativeOrExtendsNative(ClassElement element);
+
+ /// Returns `true` if the name of [element] is fixed for the generated
+ /// JavaScript.
+ bool hasFixedBackendName(Element element);
+
+ /// Computes the name for [element] to use in the generated JavaScript. This
+ /// is either given through a native annotation or a js interop annotation.
+ String getFixedBackendName(Entity entity);
+
+ /// Returns the list of non-directive native tag words for [cls].
+ List<String> getNativeTagsOfClass(ClassElement cls);
+
+ /// Returns `true` if [cls] has a `!nonleaf` tag word.
+ bool hasNativeTagsForcedNonLeaf(ClassElement cls);
+
+ /// Returns the [NativeBehavior] for calling the native [method].
+ NativeBehavior getNativeMethodBehavior(MethodElement method);
+
+ /// Returns the [NativeBehavior] for reading from the native [field].
+ NativeBehavior getNativeFieldLoadBehavior(FieldElement field);
+
+ /// Returns the [NativeBehavior] for writing to the native [field].
+ NativeBehavior getNativeFieldStoreBehavior(FieldElement field);
+
+ /// Returns `true` if [element] is part of JsInterop.
+ bool isJsInterop(Element element);
+
+ /// Returns `true` if [element] is a JsInterop class.
+ bool isJsInteropClass(ClassElement element);
+
+ /// Returns `true` if [element] is a JsInterop method.
+ bool isJsInteropMethod(MethodElement element);
+
+ /// Returns the explicit js interop name for [element].
+ String getJsInteropName(Element element);
+
+ /// Apply JS$ escaping scheme to convert possible escaped Dart names into
+ /// JS names.
+ String getUnescapedJSInteropName(String name);
+}
+
+abstract class NativeDataBuilder {
+ /// Sets the native tag info for [cls].
+ ///
+ /// The tag info string contains comma-separated 'words' which are either
+ /// dispatch tags (having JavaScript identifier syntax) and directives that
+ /// begin with `!`.
Siggi Cherem (dart-lang) 2017/03/14 00:15:59 is there a more detailed description of the tags e
Johnni Winther 2017/03/14 15:48:04 Haven't seen any. Stephen might know more.
+ void setNativeClassTagInfo(ClassElement cls, String tagInfo);
+
+ /// Returns the list of native tag words for [cls].
+ List<String> getNativeTagsOfClassRaw(ClassElement cls);
+
+ /// Sets the native [name] for the member [element]. This name is used for
+ /// [element] in the generated JavaScript.
+ void setNativeMemberName(MemberElement element, String name);
+
+ /// Registers the [behavior] for calling the native [method].
+ void setNativeMethodBehavior(MethodElement method, NativeBehavior behavior);
+
+ /// Registers the [behavior] for reading from the native [field].
+ void setNativeFieldLoadBehavior(FieldElement field, NativeBehavior behavior);
+
+ /// Registers the [behavior] for writing to the native [field].
+ void setNativeFieldStoreBehavior(FieldElement field, NativeBehavior behavior);
+
+ /// Returns [element] as an explicit part of JsInterop. The js interop name is
Siggi Cherem (dart-lang) 2017/03/14 00:15:59 Returns => marks?
Johnni Winther 2017/03/14 15:48:04 Done.
+ /// expected to be computed later.
+ void markAsJsInterop(Element element);
+
+ /// Sets the explicit js interop [name] for [element].
+ void setJsInteropName(Element element, String name);
+}
+
+class NativeDataImpl implements NativeData, NativeDataBuilder {
/// The JavaScript names for elements implemented via typed JavaScript
/// interop.
Map<Element, String> jsInteropNames = <Element, String>{};
@@ -25,8 +122,8 @@ class NativeData {
Map<ClassElement, String> nativeClassTagInfo = <ClassElement, String>{};
/// Cache for [NativeBehavior]s for calling native methods.
- Map<FunctionElement, NativeBehavior> nativeMethodBehavior =
- <FunctionElement, NativeBehavior>{};
+ Map<MethodElement, NativeBehavior> nativeMethodBehavior =
+ <MethodElement, NativeBehavior>{};
/// Cache for [NativeBehavior]s for reading from native fields.
Map<MemberElement, NativeBehavior> nativeFieldLoadBehavior =
@@ -82,6 +179,12 @@ class NativeData {
}
}
+ /// Returns `true` if [element] is a JsInterop class.
+ bool isJsInteropClass(ClassElement element) => isJsInterop(element);
+
+ /// Returns `true` if [element] is a JsInterop method.
+ bool isJsInteropMethod(MethodElement element) => isJsInterop(element);
+
/// Returns `true` if the name of [element] is fixed for the generated
/// JavaScript.
bool hasFixedBackendName(Element element) {
@@ -131,10 +234,16 @@ class NativeData {
}
}
+ /// Returns `true` if [cls] is a native class.
+ bool isNativeClass(ClassElement element) => isNative(element);
+
+ /// Returns `true` if [element] is a native member of a native class.
+ bool isNativeMember(MemberElement element) => isNative(element);
+
/// Returns `true` if [element] or any of its superclasses is native.
bool isNativeOrExtendsNative(ClassElement element) {
if (element == null) return false;
- if (isNative(element) || isJsInterop(element)) {
+ if (isNativeClass(element) || isJsInteropClass(element)) {
return true;
}
assert(element.isResolved);
@@ -196,7 +305,7 @@ class NativeData {
}
/// Returns the [NativeBehavior] for calling the native [method].
- NativeBehavior getNativeMethodBehavior(FunctionElement method) {
+ NativeBehavior getNativeMethodBehavior(MethodElement method) {
assert(invariant(method, nativeMethodBehavior.containsKey(method),
message: "No native method behavior has been computed for $method."));
return nativeMethodBehavior[method];
@@ -219,8 +328,7 @@ class NativeData {
}
/// Registers the [behavior] for calling the native [method].
- void setNativeMethodBehavior(
- FunctionElement method, NativeBehavior behavior) {
+ void setNativeMethodBehavior(MethodElement method, NativeBehavior behavior) {
nativeMethodBehavior[method] = behavior;
}

Powered by Google App Engine
This is Rietveld 408576698