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

Unified Diff: lib/kernel.dart

Issue 2201803002: Mark native methods as external. (Closed) Base URL: git@github.com:dart-lang/rasta.git@dill
Patch Set: Created 4 years, 4 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 | « lib/custom_compiler_options.dart ('k') | test/kernel/regression/native/native_is_external.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/kernel.dart
diff --git a/lib/kernel.dart b/lib/kernel.dart
index 380045ad581c0ded54cf11c5042a6c02486fc1c3..8a8c0756e7ba262d1ec7249f61956d162b14240c 100644
--- a/lib/kernel.dart
+++ b/lib/kernel.dart
@@ -49,6 +49,10 @@ import 'package:compiler/src/diagnostics/messages.dart' show
import 'package:compiler/src/constants/expressions.dart' show
TypeConstantExpression;
+import 'package:compiler/src/tree/tree.dart' show
+ FunctionExpression,
+ Node;
+
import 'custom_compiler.dart' show
CustomCompiler;
@@ -330,6 +334,21 @@ class Kernel {
}
}
+ bool isNativeMethod(FunctionElement element) {
+ // This method is a (modified) copy of the same method in
+ // `pkg/compiler/lib/src/native/enqueue.dart`.
+ if (!compiler.backend.canLibraryUseNative(element.library)) return false;
+ return compiler.reporter.withCurrentElement(element, () {
+ FunctionExpression functionExpression =
+ element.node?.asFunctionExpression();
+ if (functionExpression == null) return false;
+ Node body = functionExpression.body;
+ if (body == null) return false;
+ if (identical(body.getBeginToken().stringValue, 'native')) return true;
+ return false;
+ });
+ }
+
ir.Member functionToIr(FunctionElement function) {
if (function.isDeferredLoaderGetter) {
internalError(function, "Deferred loader.");
@@ -349,16 +368,17 @@ class Kernel {
ir.Constructor constructor;
ir.Procedure procedure;
ir.Name name = irName(function.name, function);
+ bool isNative = isNativeMethod(function);
if (function.isGenerativeConstructor) {
member = constructor = new ir.Constructor(
null, name: name, isConst: function.isConst,
- isExternal: function.isExternal, initializers: null);
+ isExternal: isNative || function.isExternal, initializers: null);
} else {
member = procedure = new ir.Procedure(
name, null, null, isAbstract: function.isAbstract,
isStatic: function.isStatic || function.isTopLevel
|| function.isFactoryConstructor,
- isExternal: function.isExternal,
+ isExternal: isNative || function.isExternal,
isConst: false); // TODO(ahe): When is this true?
}
addWork(function, () {
« no previous file with comments | « lib/custom_compiler_options.dart ('k') | test/kernel/regression/native/native_is_external.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698