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

Side by Side Diff: pkg/compiler/lib/src/elements/elements.dart

Issue 1408043002: Move native and js interop properties from the element model to the JS backend (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library elements; 5 library elements;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/resolution.dart' show 8 import '../common/resolution.dart' show
9 Resolution; 9 Resolution;
10 import '../compiler.dart' show 10 import '../compiler.dart' show
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 bool get isInstanceMember; 298 bool get isInstanceMember;
299 299
300 /// Returns true if this [Element] is a top level element. 300 /// Returns true if this [Element] is a top level element.
301 /// That is, if it is not defined within the scope of a class. 301 /// That is, if it is not defined within the scope of a class.
302 /// 302 ///
303 /// This means whether the enclosing element is a compilation unit. 303 /// This means whether the enclosing element is a compilation unit.
304 /// With the exception of [ClosureClassElement] that is considered top level 304 /// With the exception of [ClosureClassElement] that is considered top level
305 /// as all other classes. 305 /// as all other classes.
306 bool get isTopLevel; 306 bool get isTopLevel;
307 bool get isAssignable; 307 bool get isAssignable;
308 bool get isNative;
309 bool get isJsInterop;
310 308
311 bool get isDeferredLoaderGetter; 309 bool get isDeferredLoaderGetter;
312 310
313 /// True if the element is declared in a patch library but has no 311 /// True if the element is declared in a patch library but has no
314 /// corresponding declaration in the origin library. 312 /// corresponding declaration in the origin library.
315 bool get isInjected; 313 bool get isInjected;
316 314
317 /// `true` if this element is a constructor, top level or local variable, 315 /// `true` if this element is a constructor, top level or local variable,
318 /// or static field that is declared `const`. 316 /// or static field that is declared `const`.
319 bool get isConst; 317 bool get isConst;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 Element get patch; 392 Element get patch;
395 393
396 /// Returns the origin for this element if this element is a patch. 394 /// Returns the origin for this element if this element is a patch.
397 /// 395 ///
398 /// See [:patch_parser.dart:] for a description of the terminology. 396 /// See [:patch_parser.dart:] for a description of the terminology.
399 Element get origin; 397 Element get origin;
400 398
401 bool get isSynthesized; 399 bool get isSynthesized;
402 bool get isMixinApplication; 400 bool get isMixinApplication;
403 401
404 bool get hasFixedBackendName;
405 String get fixedBackendName;
406
407 String get jsInteropName;
408
409 bool get isAbstract; 402 bool get isAbstract;
410 403
411 Scope buildScope(); 404 Scope buildScope();
412 405
413 // TODO(johnniwinther): Move this to [AstElement]. 406 // TODO(johnniwinther): Move this to [AstElement].
414 /// Returns the [Element] that holds the [TreeElements] for this element. 407 /// Returns the [Element] that holds the [TreeElements] for this element.
415 AnalyzableElement get analyzableElement; 408 AnalyzableElement get analyzableElement;
416 409
417 accept(ElementVisitor visitor, arg); 410 accept(ElementVisitor visitor, arg);
418
419 void setJsInteropName(String name);
420 void markAsJsInterop();
421 } 411 }
422 412
423 class Elements { 413 class Elements {
424 static bool isUnresolved(Element e) { 414 static bool isUnresolved(Element e) {
425 return e == null || e.isErroneous; 415 return e == null || e.isErroneous;
426 } 416 }
427 static bool isErroneous(Element e) => e != null && e.isErroneous; 417 static bool isErroneous(Element e) => e != null && e.isErroneous;
428 418
429 /// Unwraps [element] reporting any warnings attached to it, if any. 419 /// Unwraps [element] reporting any warnings attached to it, if any.
430 static Element unwrap(Element element, 420 static Element unwrap(Element element,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 static bool isNonAbstractInstanceMember(Element element) { 503 static bool isNonAbstractInstanceMember(Element element) {
514 // The generative constructor body is not a function. We therefore treat 504 // The generative constructor body is not a function. We therefore treat
515 // it specially. 505 // it specially.
516 if (element.isGenerativeConstructorBody) return true; 506 if (element.isGenerativeConstructorBody) return true;
517 return !Elements.isUnresolved(element) && 507 return !Elements.isUnresolved(element) &&
518 !element.isAbstract && 508 !element.isAbstract &&
519 element.isInstanceMember && 509 element.isInstanceMember &&
520 (element.isFunction || element.isAccessor); 510 (element.isFunction || element.isAccessor);
521 } 511 }
522 512
523 static bool isNativeOrExtendsNative(ClassElement element) {
524 if (element == null) return false;
525 if (element.isNative || element.isJsInterop) return true;
526 assert(element.isResolved);
527 return isNativeOrExtendsNative(element.superclass);
528 }
529
530 static bool isInstanceSend(Send send, TreeElements elements) { 513 static bool isInstanceSend(Send send, TreeElements elements) {
531 Element element = elements[send]; 514 Element element = elements[send];
532 if (element == null) return !isClosureSend(send, element); 515 if (element == null) return !isClosureSend(send, element);
533 return isInstanceMethod(element) || 516 return isInstanceMethod(element) ||
534 isInstanceField(element) || 517 isInstanceField(element) ||
535 (send.isConditional && !element.isStatic); 518 (send.isConditional && !element.isStatic);
536 } 519 }
537 520
538 static bool isClosureSend(Send send, Element element) { 521 static bool isClosureSend(Send send, Element element) {
539 if (send.isPropertyAccess) return false; 522 if (send.isPropertyAccess) return false;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 } 722 }
740 723
741 static bool isConstructorOfTypedArraySubclass(Element element, 724 static bool isConstructorOfTypedArraySubclass(Element element,
742 Compiler compiler) { 725 Compiler compiler) {
743 if (compiler.typedDataLibrary == null) return false; 726 if (compiler.typedDataLibrary == null) return false;
744 if (!element.isConstructor) return false; 727 if (!element.isConstructor) return false;
745 ConstructorElement constructor = element.implementation; 728 ConstructorElement constructor = element.implementation;
746 constructor = constructor.effectiveTarget; 729 constructor = constructor.effectiveTarget;
747 ClassElement cls = constructor.enclosingClass; 730 ClassElement cls = constructor.enclosingClass;
748 return cls.library == compiler.typedDataLibrary 731 return cls.library == compiler.typedDataLibrary
749 && cls.isNative 732 && compiler.backend.isNative(cls)
750 && compiler.world.isSubtypeOf(cls, compiler.typedDataClass) 733 && compiler.world.isSubtypeOf(cls, compiler.typedDataClass)
751 && compiler.world.isSubtypeOf(cls, compiler.listClass) 734 && compiler.world.isSubtypeOf(cls, compiler.listClass)
752 && constructor.name == ''; 735 && constructor.name == '';
753 } 736 }
754 737
755 static bool switchStatementHasContinue(SwitchStatement node, 738 static bool switchStatementHasContinue(SwitchStatement node,
756 TreeElements elements) { 739 TreeElements elements) {
757 for (SwitchCase switchCase in node.cases) { 740 for (SwitchCase switchCase in node.cases) {
758 for (Node labelOrCase in switchCase.labelsAndCases) { 741 for (Node labelOrCase in switchCase.labelsAndCases) {
759 Node label = labelOrCase.asLabel(); 742 Node label = labelOrCase.asLabel();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 * the scheme 'package'. 880 * the scheme 'package'.
898 */ 881 */
899 bool get isPackageLibrary; 882 bool get isPackageLibrary;
900 883
901 /** 884 /**
902 * [:true:] if this library is a platform library whose path starts with 885 * [:true:] if this library is a platform library whose path starts with
903 * an underscore. 886 * an underscore.
904 */ 887 */
905 bool get isInternalLibrary; 888 bool get isInternalLibrary;
906 889
907 bool get canUseNative;
908 bool get exportsHandled; 890 bool get exportsHandled;
909 891
910 LibraryElement get implementation; 892 LibraryElement get implementation;
911 893
912 Element find(String elementName); 894 Element find(String elementName);
913 Element findLocal(String elementName); 895 Element findLocal(String elementName);
914 Element findExported(String elementName); 896 Element findExported(String elementName);
915 void forEachExport(f(Element element)); 897 void forEachExport(f(Element element));
916 898
917 /// Calls [f] for each [Element] imported into this library. 899 /// Calls [f] for each [Element] imported into this library.
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 Link<DartType> get interfaces; 1369 Link<DartType> get interfaces;
1388 1370
1389 bool get hasConstructor; 1371 bool get hasConstructor;
1390 Link<Element> get constructors; 1372 Link<Element> get constructors;
1391 1373
1392 ClassElement get patch; 1374 ClassElement get patch;
1393 ClassElement get origin; 1375 ClassElement get origin;
1394 ClassElement get declaration; 1376 ClassElement get declaration;
1395 ClassElement get implementation; 1377 ClassElement get implementation;
1396 1378
1397 String get nativeTagInfo;
1398
1399 /// `true` if this class is an enum declaration. 1379 /// `true` if this class is an enum declaration.
1400 bool get isEnumClass; 1380 bool get isEnumClass;
1401 1381
1402 /// `true` if this class is a mixin application, either named or unnamed. 1382 /// `true` if this class is a mixin application, either named or unnamed.
1403 bool get isMixinApplication; 1383 bool get isMixinApplication;
1404 1384
1405 /// `true` if this class is a named mixin application, e.g. 1385 /// `true` if this class is a named mixin application, e.g.
1406 /// 1386 ///
1407 /// class NamedMixinApplication = SuperClass with MixinClass; 1387 /// class NamedMixinApplication = SuperClass with MixinClass;
1408 /// 1388 ///
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 bool get isDeclaredByField; 1690 bool get isDeclaredByField;
1711 1691
1712 /// Returns `true` if this member is abstract. 1692 /// Returns `true` if this member is abstract.
1713 bool get isAbstract; 1693 bool get isAbstract;
1714 1694
1715 /// If abstract, [implementation] points to the overridden concrete member, 1695 /// If abstract, [implementation] points to the overridden concrete member,
1716 /// if any. Otherwise [implementation] points to the member itself. 1696 /// if any. Otherwise [implementation] points to the member itself.
1717 Member get implementation; 1697 Member get implementation;
1718 } 1698 }
1719 1699
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/elements/modelx.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698