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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library rasta.kernel; 5 library rasta.kernel;
6 6
7 import 'dart:async' show 7 import 'dart:async' show
8 Future; 8 Future;
9 9
10 import 'dart:collection' show 10 import 'dart:collection' show
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 import 'package:compiler/src/diagnostics/spannable.dart' show 43 import 'package:compiler/src/diagnostics/spannable.dart' show
44 Spannable; 44 Spannable;
45 45
46 import 'package:compiler/src/diagnostics/messages.dart' show 46 import 'package:compiler/src/diagnostics/messages.dart' show
47 MessageKind; 47 MessageKind;
48 48
49 import 'package:compiler/src/constants/expressions.dart' show 49 import 'package:compiler/src/constants/expressions.dart' show
50 TypeConstantExpression; 50 TypeConstantExpression;
51 51
52 import 'package:compiler/src/tree/tree.dart' show
53 FunctionExpression,
54 Node;
55
52 import 'custom_compiler.dart' show 56 import 'custom_compiler.dart' show
53 CustomCompiler; 57 CustomCompiler;
54 58
55 import 'kernel_visitor.dart' show 59 import 'kernel_visitor.dart' show
56 IrFunction, 60 IrFunction,
57 KernelVisitor; 61 KernelVisitor;
58 62
59 typedef void WorkAction(); 63 typedef void WorkAction();
60 64
61 class WorkItem { 65 class WorkItem {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 member.parent = elementToIr(element.enclosingElement); 327 member.parent = elementToIr(element.enclosingElement);
324 } else if (element.isTopLevel) { 328 } else if (element.isTopLevel) {
325 member.parent = elementToIr(element.library); 329 member.parent = elementToIr(element.library);
326 } else if (element.isClassMember) { 330 } else if (element.isClassMember) {
327 member.parent = elementToIr(element.enclosingClass); 331 member.parent = elementToIr(element.enclosingClass);
328 } else { 332 } else {
329 member.parent = elementToIr(element.enclosingElement); 333 member.parent = elementToIr(element.enclosingElement);
330 } 334 }
331 } 335 }
332 336
337 bool isNativeMethod(FunctionElement element) {
338 // This method is a (modified) copy of the same method in
339 // `pkg/compiler/lib/src/native/enqueue.dart`.
340 if (!compiler.backend.canLibraryUseNative(element.library)) return false;
341 return compiler.reporter.withCurrentElement(element, () {
342 FunctionExpression functionExpression =
343 element.node?.asFunctionExpression();
344 if (functionExpression == null) return false;
345 Node body = functionExpression.body;
346 if (body == null) return false;
347 if (identical(body.getBeginToken().stringValue, 'native')) return true;
348 return false;
349 });
350 }
351
333 ir.Member functionToIr(FunctionElement function) { 352 ir.Member functionToIr(FunctionElement function) {
334 if (function.isDeferredLoaderGetter) { 353 if (function.isDeferredLoaderGetter) {
335 internalError(function, "Deferred loader."); 354 internalError(function, "Deferred loader.");
336 } 355 }
337 if (function.isLocal) { 356 if (function.isLocal) {
338 internalError(function, "Local function."); 357 internalError(function, "Local function.");
339 } 358 }
340 if (isSyntheticError(function)) { 359 if (isSyntheticError(function)) {
341 internalError(function, "Synthetic error function: $function."); 360 internalError(function, "Synthetic error function: $function.");
342 } 361 }
343 function = function.declaration; 362 function = function.declaration;
344 return functions.putIfAbsent(function, () { 363 return functions.putIfAbsent(function, () {
345 compiler.analyzeElement(function); 364 compiler.analyzeElement(function);
346 compiler.enqueuer.resolution.emptyDeferredTaskQueue(); 365 compiler.enqueuer.resolution.emptyDeferredTaskQueue();
347 function = function.implementation; 366 function = function.implementation;
348 ir.Member member; 367 ir.Member member;
349 ir.Constructor constructor; 368 ir.Constructor constructor;
350 ir.Procedure procedure; 369 ir.Procedure procedure;
351 ir.Name name = irName(function.name, function); 370 ir.Name name = irName(function.name, function);
371 bool isNative = isNativeMethod(function);
352 if (function.isGenerativeConstructor) { 372 if (function.isGenerativeConstructor) {
353 member = constructor = new ir.Constructor( 373 member = constructor = new ir.Constructor(
354 null, name: name, isConst: function.isConst, 374 null, name: name, isConst: function.isConst,
355 isExternal: function.isExternal, initializers: null); 375 isExternal: isNative || function.isExternal, initializers: null);
356 } else { 376 } else {
357 member = procedure = new ir.Procedure( 377 member = procedure = new ir.Procedure(
358 name, null, null, isAbstract: function.isAbstract, 378 name, null, null, isAbstract: function.isAbstract,
359 isStatic: function.isStatic || function.isTopLevel 379 isStatic: function.isStatic || function.isTopLevel
360 || function.isFactoryConstructor, 380 || function.isFactoryConstructor,
361 isExternal: function.isExternal, 381 isExternal: isNative || function.isExternal,
362 isConst: false); // TODO(ahe): When is this true? 382 isConst: false); // TODO(ahe): When is this true?
363 } 383 }
364 addWork(function, () { 384 addWork(function, () {
365 setParent(member, function); 385 setParent(member, function);
366 KernelVisitor visitor = 386 KernelVisitor visitor =
367 new KernelVisitor(function, function.treeElements, this); 387 new KernelVisitor(function, function.treeElements, this);
368 beginFactoryScope(function); 388 beginFactoryScope(function);
369 IrFunction irFunction = visitor.buildFunction(); 389 IrFunction irFunction = visitor.buildFunction();
370 // TODO(ahe): Add addFunction/set function to [ir.Procedure]. 390 // TODO(ahe): Add addFunction/set function to [ir.Procedure].
371 irFunction.node.parent = member; 391 irFunction.node.parent = member;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 } 685 }
666 686
667 class ConstructorTarget { 687 class ConstructorTarget {
668 final ConstructorElement element; 688 final ConstructorElement element;
669 final DartType type; 689 final DartType type;
670 690
671 ConstructorTarget(this.element, this.type); 691 ConstructorTarget(this.element, this.type);
672 692
673 String toString() => "ConstructorTarget($element, $type)"; 693 String toString() => "ConstructorTarget($element, $type)";
674 } 694 }
OLDNEW
« 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