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

Side by Side Diff: pkg/analyzer/lib/src/generated/element.dart

Issue 1050203002: Begin making copies of AST nodes for constants during resolution. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.element; 8 library engine.element;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 safelyVisitChildren(_functions, visitor); 1486 safelyVisitChildren(_functions, visitor);
1487 safelyVisitChildren(_typeAliases, visitor); 1487 safelyVisitChildren(_typeAliases, visitor);
1488 safelyVisitChildren(_types, visitor); 1488 safelyVisitChildren(_types, visitor);
1489 safelyVisitChildren(_variables, visitor); 1489 safelyVisitChildren(_variables, visitor);
1490 } 1490 }
1491 } 1491 }
1492 1492
1493 /** 1493 /**
1494 * A [FieldElement] for a 'const' field that has an initializer. 1494 * A [FieldElement] for a 'const' field that has an initializer.
1495 */ 1495 */
1496 class ConstFieldElementImpl extends FieldElementImpl { 1496 class ConstFieldElementImpl extends FieldElementImpl
1497 implements ConstVariableElementImpl {
1497 /** 1498 /**
1498 * The result of evaluating this variable's initializer. 1499 * The result of evaluating this variable's initializer.
1499 */ 1500 */
1500 EvaluationResultImpl _result; 1501 EvaluationResultImpl _result;
1501 1502
1502 /** 1503 /**
1504 * A copy of the AST for the variable's initializer.
1505 */
1506 Expression _constantInitializer;
1507
1508 /**
1503 * Initialize a newly created field element to have the given [name]. 1509 * Initialize a newly created field element to have the given [name].
1504 */ 1510 */
1505 ConstFieldElementImpl.con1(Identifier name) : super.forNode(name); 1511 ConstFieldElementImpl.con1(Identifier name) : super.forNode(name);
1506 1512
1507 /** 1513 /**
1508 * Initialize a newly created synthetic field element to have the given 1514 * Initialize a newly created synthetic field element to have the given
1509 * [name] and [offset]. 1515 * [name] and [offset].
1510 */ 1516 */
1511 ConstFieldElementImpl.con2(String name, int offset) : super(name, offset); 1517 ConstFieldElementImpl.con2(String name, int offset) : super(name, offset);
1512 1518
1513 @override 1519 @override
1520 Expression get constantInitializer => _constantInitializer;
scheglov 2015/04/01 23:34:16 It looks that we don't process this field. So, why
Paul Berry 2015/04/02 15:18:49 Done.
1521
1522 @override
1523 void set constantInitializer(Expression value) {
1524 _constantInitializer = value;
1525 }
1526
1527 @override
1514 EvaluationResultImpl get evaluationResult => _result; 1528 EvaluationResultImpl get evaluationResult => _result;
1515 1529
1516 @override 1530 @override
1517 void set evaluationResult(EvaluationResultImpl result) { 1531 void set evaluationResult(EvaluationResultImpl result) {
1518 this._result = result; 1532 this._result = result;
1519 } 1533 }
1520 } 1534 }
1521 1535
1522 /** 1536 /**
1523 * A [LocalVariableElement] for a local 'const' variable that has an 1537 * A [LocalVariableElement] for a local 'const' variable that has an
1524 * initializer. 1538 * initializer.
1525 */ 1539 */
1526 class ConstLocalVariableElementImpl extends LocalVariableElementImpl { 1540 class ConstLocalVariableElementImpl extends LocalVariableElementImpl
1541 implements ConstVariableElementImpl {
1527 /** 1542 /**
1528 * The result of evaluating this variable's initializer. 1543 * The result of evaluating this variable's initializer.
1529 */ 1544 */
1530 EvaluationResultImpl _result; 1545 EvaluationResultImpl _result;
1531 1546
1532 /** 1547 /**
1548 * A copy of the AST for the variable's initializer.
1549 */
1550 Expression _constantInitializer;
1551
1552 /**
1553 * Initialize a newly created local variable element to have the given [name]
1554 * and [offset].
1555 */
1556 ConstLocalVariableElementImpl(String name, int offset) : super(name, offset);
1557
1558 /**
1533 * Initialize a newly created local variable element to have the given [name]. 1559 * Initialize a newly created local variable element to have the given [name].
1534 */ 1560 */
1535 ConstLocalVariableElementImpl(Identifier name) : super.forNode(name); 1561 ConstLocalVariableElementImpl.forNode(Identifier name) : super.forNode(name);
1562
1563 @override
1564 Expression get constantInitializer => _constantInitializer;
1565
1566 @override
1567 void set constantInitializer(Expression value) {
1568 _constantInitializer = value;
1569 }
1536 1570
1537 @override 1571 @override
1538 EvaluationResultImpl get evaluationResult => _result; 1572 EvaluationResultImpl get evaluationResult => _result;
1539 1573
1540 @override 1574 @override
1541 void set evaluationResult(EvaluationResultImpl result) { 1575 void set evaluationResult(EvaluationResultImpl result) {
1542 this._result = result; 1576 this._result = result;
1543 } 1577 }
1544 } 1578 }
1545 1579
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 */ 1656 */
1623 int periodOffset; 1657 int periodOffset;
1624 1658
1625 /** 1659 /**
1626 * Return the offset of the character immediately following the last character 1660 * Return the offset of the character immediately following the last character
1627 * of this constructor's name, or `null` if not named. 1661 * of this constructor's name, or `null` if not named.
1628 */ 1662 */
1629 int nameEnd; 1663 int nameEnd;
1630 1664
1631 /** 1665 /**
1666 * True if this constructor has been found by constant evaluation to be free
1667 * of redirect cycles, and is thus safe to evaluate.
1668 */
1669 bool isCycleFree = false;
1670
1671 /**
1632 * Initialize a newly created constructor element to have the given [name] and 1672 * Initialize a newly created constructor element to have the given [name] and
1633 * [offset]. 1673 * [offset].
1634 */ 1674 */
1635 ConstructorElementImpl(String name, int offset) : super(name, offset); 1675 ConstructorElementImpl(String name, int offset) : super(name, offset);
1636 1676
1637 /** 1677 /**
1638 * Initialize a newly created constructor element to have the given [name]. 1678 * Initialize a newly created constructor element to have the given [name].
1639 */ 1679 */
1640 ConstructorElementImpl.forNode(Identifier name) : super.forNode(name); 1680 ConstructorElementImpl.forNode(Identifier name) : super.forNode(name);
1641 1681
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 // instance. It would use more memory but speed up some operations. 1859 // instance. It would use more memory but speed up some operations.
1820 // We need to see how often the type is being re-computed. 1860 // We need to see how often the type is being re-computed.
1821 return new ConstructorMember(constructor, definingType); 1861 return new ConstructorMember(constructor, definingType);
1822 } 1862 }
1823 } 1863 }
1824 1864
1825 /** 1865 /**
1826 * A [TopLevelVariableElement] for a top-level 'const' variable that has an 1866 * A [TopLevelVariableElement] for a top-level 'const' variable that has an
1827 * initializer. 1867 * initializer.
1828 */ 1868 */
1829 class ConstTopLevelVariableElementImpl extends TopLevelVariableElementImpl { 1869 class ConstTopLevelVariableElementImpl extends TopLevelVariableElementImpl
1870 implements ConstVariableElementImpl {
1830 /** 1871 /**
1831 * The result of evaluating this variable's initializer. 1872 * The result of evaluating this variable's initializer.
1832 */ 1873 */
1833 EvaluationResultImpl _result; 1874 EvaluationResultImpl _result;
1834 1875
1835 /** 1876 /**
1877 * A copy of the AST for the variable's initializer.
1878 */
1879 Expression _constantInitializer;
1880
1881 /**
1836 * Initialize a newly created top-level variable element to have the given 1882 * Initialize a newly created top-level variable element to have the given
1837 * [name]. 1883 * [name].
1838 */ 1884 */
1839 ConstTopLevelVariableElementImpl(Identifier name) : super.forNode(name); 1885 ConstTopLevelVariableElementImpl(Identifier name) : super.forNode(name);
1840 1886
1841 @override 1887 @override
1888 Expression get constantInitializer => _constantInitializer;
1889
1890 @override
1891 void set constantInitializer(Expression value) {
1892 _constantInitializer = value;
1893 }
1894
1895 @override
1842 EvaluationResultImpl get evaluationResult => _result; 1896 EvaluationResultImpl get evaluationResult => _result;
1843 1897
1844 @override 1898 @override
1845 void set evaluationResult(EvaluationResultImpl result) { 1899 void set evaluationResult(EvaluationResultImpl result) {
1846 this._result = result; 1900 this._result = result;
1847 } 1901 }
1848 } 1902 }
1849 1903
1850 /** 1904 /**
1905 * Common interface shared by elements that represent constant variables and
1906 * have initializers.
1907 *
1908 * Note that in correct Dart code, all constant variables must have
1909 * initializers. However, analyzer also needs to handle incorrect Dart code,
1910 * in which case there might be some constant variables that lack initializers.
1911 * This interface is only used for constant variables that have initializers.
1912 *
1913 * This class has "Impl" in the name to emphasize the fact that it is not
1914 * intended to be part of the public API for analyzer.
Brian Wilkerson 2015/04/01 20:31:54 That's a little odd. When I first saw it I assumed
Paul Berry 2015/04/02 15:18:49 Fair enough. I've removed "Impl" from the name of
1915 */
1916 abstract class ConstVariableElementImpl
1917 extends PotentiallyConstVariableElementImpl {
1918 /**
1919 * Store a copy of the initializer for this variable (which will later be
1920 * usd for evaluating constants).
Brian Wilkerson 2015/04/01 20:31:54 "usd" --> "used"
Paul Berry 2015/04/02 15:18:49 Done.
1921 */
1922 void set constantInitializer(Expression value);
1923 }
1924
1925 /**
1851 * The type associated with elements in the element model. 1926 * The type associated with elements in the element model.
1852 */ 1927 */
1853 abstract class DartType { 1928 abstract class DartType {
1854 /** 1929 /**
1855 * Return the name of this type as it should appear when presented to users in 1930 * Return the name of this type as it should appear when presented to users in
1856 * contexts such as error messages. 1931 * contexts such as error messages.
1857 */ 1932 */
1858 String get displayName; 1933 String get displayName;
1859 1934
1860 /** 1935 /**
(...skipping 1864 matching lines...) Expand 10 before | Expand all | Expand 10 after
3725 * so parsing and resolving will be performed. 3800 * so parsing and resolving will be performed.
3726 */ 3801 */
3727 @override 3802 @override
3728 AstNode get node; 3803 AstNode get node;
3729 } 3804 }
3730 3805
3731 /** 3806 /**
3732 * A concrete implementation of a [FieldElement]. 3807 * A concrete implementation of a [FieldElement].
3733 */ 3808 */
3734 class FieldElementImpl extends PropertyInducingElementImpl 3809 class FieldElementImpl extends PropertyInducingElementImpl
3735 implements FieldElement { 3810 implements FieldElement, PotentiallyConstVariableElementImpl {
3736 /** 3811 /**
3737 * An empty list of field elements. 3812 * An empty list of field elements.
3738 */ 3813 */
3739 static const List<FieldElement> EMPTY_ARRAY = const <FieldElement>[]; 3814 static const List<FieldElement> EMPTY_ARRAY = const <FieldElement>[];
3740 3815
3741 /** 3816 /**
3742 * Initialize a newly created synthetic field element to have the given [name] 3817 * Initialize a newly created synthetic field element to have the given [name]
3743 * at the given [offset]. 3818 * at the given [offset].
3744 */ 3819 */
3745 FieldElementImpl(String name, int offset) : super(name, offset); 3820 FieldElementImpl(String name, int offset) : super(name, offset);
3746 3821
3747 /** 3822 /**
3748 * Initialize a newly created field element to have the given [name]. 3823 * Initialize a newly created field element to have the given [name].
3749 */ 3824 */
3750 FieldElementImpl.forNode(Identifier name) : super.forNode(name); 3825 FieldElementImpl.forNode(Identifier name) : super.forNode(name);
3751 3826
3752 @override 3827 @override
3828 Expression get constantInitializer => null;
3829
3830 @override
3753 ClassElement get enclosingElement => super.enclosingElement as ClassElement; 3831 ClassElement get enclosingElement => super.enclosingElement as ClassElement;
3754 3832
3755 @override 3833 @override
3756 bool get isEnumConstant => 3834 bool get isEnumConstant =>
3757 enclosingElement != null ? enclosingElement.isEnum : false; 3835 enclosingElement != null ? enclosingElement.isEnum : false;
3758 3836
3759 @override 3837 @override
3760 bool get isStatic => hasModifier(Modifier.STATIC); 3838 bool get isStatic => hasModifier(Modifier.STATIC);
3761 3839
3762 @override 3840 @override
(...skipping 3565 matching lines...) Expand 10 before | Expand all | Expand 10 after
7328 7406
7329 /** 7407 /**
7330 * A local variable. 7408 * A local variable.
7331 */ 7409 */
7332 abstract class LocalVariableElement implements LocalElement, VariableElement {} 7410 abstract class LocalVariableElement implements LocalElement, VariableElement {}
7333 7411
7334 /** 7412 /**
7335 * A concrete implementation of a [LocalVariableElement]. 7413 * A concrete implementation of a [LocalVariableElement].
7336 */ 7414 */
7337 class LocalVariableElementImpl extends VariableElementImpl 7415 class LocalVariableElementImpl extends VariableElementImpl
7338 implements LocalVariableElement { 7416 implements LocalVariableElement, PotentiallyConstVariableElementImpl {
7339 /** 7417 /**
7340 * An empty list of field elements. 7418 * An empty list of field elements.
7341 */ 7419 */
7342 static const List<LocalVariableElement> EMPTY_ARRAY = 7420 static const List<LocalVariableElement> EMPTY_ARRAY =
7343 const <LocalVariableElement>[]; 7421 const <LocalVariableElement>[];
7344 7422
7345 /** 7423 /**
7346 * The offset to the beginning of the visible range for this element. 7424 * The offset to the beginning of the visible range for this element.
7347 */ 7425 */
7348 int _visibleRangeOffset = 0; 7426 int _visibleRangeOffset = 0;
7349 7427
7350 /** 7428 /**
7351 * The length of the visible range for this element, or `-1` if this element 7429 * The length of the visible range for this element, or `-1` if this element
7352 * does not have a visible range. 7430 * does not have a visible range.
7353 */ 7431 */
7354 int _visibleRangeLength = -1; 7432 int _visibleRangeLength = -1;
7355 7433
7356 /** 7434 /**
7357 * Initialize a newly created method element to have the given [name] and 7435 * Initialize a newly created method element to have the given [name] and
7358 * [offset]. 7436 * [offset].
7359 */ 7437 */
7360 LocalVariableElementImpl(String name, int offset) : super(name, offset); 7438 LocalVariableElementImpl(String name, int offset) : super(name, offset);
7361 7439
7362 /** 7440 /**
7363 * Initialize a newly created local variable element to have the given [name]. 7441 * Initialize a newly created local variable element to have the given [name].
7364 */ 7442 */
7365 LocalVariableElementImpl.forNode(Identifier name) : super.forNode(name); 7443 LocalVariableElementImpl.forNode(Identifier name) : super.forNode(name);
7366 7444
7367 @override 7445 @override
7446 Expression get constantInitializer => null;
7447
7448 @override
7368 String get identifier { 7449 String get identifier {
7369 int enclosingOffset = 7450 int enclosingOffset =
7370 enclosingElement != null ? enclosingElement.nameOffset : 0; 7451 enclosingElement != null ? enclosingElement.nameOffset : 0;
7371 int delta = nameOffset - enclosingOffset; 7452 int delta = nameOffset - enclosingOffset;
7372 return '${super.identifier}@$delta'; 7453 return '${super.identifier}@$delta';
7373 } 7454 }
7374 7455
7375 @override 7456 @override
7376 bool get isPotentiallyMutatedInClosure => 7457 bool get isPotentiallyMutatedInClosure =>
7377 hasModifier(Modifier.POTENTIALLY_MUTATED_IN_CONTEXT); 7458 hasModifier(Modifier.POTENTIALLY_MUTATED_IN_CONTEXT);
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
8520 // We need to see how often the type is being re-computed. 8601 // We need to see how often the type is being re-computed.
8521 if (isFieldFormal) { 8602 if (isFieldFormal) {
8522 return new FieldFormalParameterMember( 8603 return new FieldFormalParameterMember(
8523 parameter as FieldFormalParameterElement, definingType); 8604 parameter as FieldFormalParameterElement, definingType);
8524 } 8605 }
8525 return new ParameterMember(parameter, definingType); 8606 return new ParameterMember(parameter, definingType);
8526 } 8607 }
8527 } 8608 }
8528 8609
8529 /** 8610 /**
8611 * Common interface shared by elements that might represent constant variables.
8612 *
8613 * This class has "Impl" in the name to emphasize the fact that it is not
8614 * intended to be part of the public API for analyzer.
8615 */
8616 abstract class PotentiallyConstVariableElementImpl extends VariableElement {
8617 /**
8618 * If this element represents a constant variable, and it has an initializer,
8619 * a copy of the initializer for the constant. Otherwise `null`.
8620 *
8621 * Note that in correct Dart code, all constant variables must have
8622 * initializers. However, analyzer also needs to handle incorrect Dart code,
8623 * in which case there might be some constant variables that lack
8624 * initializers.
8625 */
8626 Expression get constantInitializer;
8627 }
8628
8629 /**
8530 * A prefix used to import one or more libraries into another library. 8630 * A prefix used to import one or more libraries into another library.
8531 */ 8631 */
8532 abstract class PrefixElement implements Element { 8632 abstract class PrefixElement implements Element {
8533 /** 8633 /**
8534 * Return the library into which other libraries are imported using this 8634 * Return the library into which other libraries are imported using this
8535 * prefix. 8635 * prefix.
8536 */ 8636 */
8537 @override 8637 @override
8538 LibraryElement get enclosingElement; 8638 LibraryElement get enclosingElement;
8539 8639
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
9300 9400
9301 /** 9401 /**
9302 * A top-level variable. 9402 * A top-level variable.
9303 */ 9403 */
9304 abstract class TopLevelVariableElement implements PropertyInducingElement {} 9404 abstract class TopLevelVariableElement implements PropertyInducingElement {}
9305 9405
9306 /** 9406 /**
9307 * A concrete implementation of a [TopLevelVariableElement]. 9407 * A concrete implementation of a [TopLevelVariableElement].
9308 */ 9408 */
9309 class TopLevelVariableElementImpl extends PropertyInducingElementImpl 9409 class TopLevelVariableElementImpl extends PropertyInducingElementImpl
9310 implements TopLevelVariableElement { 9410 implements TopLevelVariableElement, PotentiallyConstVariableElementImpl {
9311 /** 9411 /**
9312 * An empty list of top-level variable elements. 9412 * An empty list of top-level variable elements.
9313 */ 9413 */
9314 static const List<TopLevelVariableElement> EMPTY_ARRAY = 9414 static const List<TopLevelVariableElement> EMPTY_ARRAY =
9315 const <TopLevelVariableElement>[]; 9415 const <TopLevelVariableElement>[];
9316 9416
9317 /** 9417 /**
9318 * Initialize a newly created synthetic top-level variable element to have the 9418 * Initialize a newly created synthetic top-level variable element to have the
9319 * given [name] and [offset]. 9419 * given [name] and [offset].
9320 */ 9420 */
9321 TopLevelVariableElementImpl(String name, int offset) : super(name, offset); 9421 TopLevelVariableElementImpl(String name, int offset) : super(name, offset);
9322 9422
9323 /** 9423 /**
9324 * Initialize a newly created top-level variable element to have the given 9424 * Initialize a newly created top-level variable element to have the given
9325 * [name]. 9425 * [name].
9326 */ 9426 */
9327 TopLevelVariableElementImpl.forNode(Identifier name) : super.forNode(name); 9427 TopLevelVariableElementImpl.forNode(Identifier name) : super.forNode(name);
9328 9428
9329 @override 9429 @override
9430 Expression get constantInitializer => null;
9431
9432 @override
9330 bool get isStatic => true; 9433 bool get isStatic => true;
9331 9434
9332 @override 9435 @override
9333 ElementKind get kind => ElementKind.TOP_LEVEL_VARIABLE; 9436 ElementKind get kind => ElementKind.TOP_LEVEL_VARIABLE;
9334 9437
9335 @override 9438 @override
9336 accept(ElementVisitor visitor) => visitor.visitTopLevelVariableElement(this); 9439 accept(ElementVisitor visitor) => visitor.visitTopLevelVariableElement(this);
9337 } 9440 }
9338 9441
9339 /** 9442 /**
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
10453 // void <: void (by reflexivity) 10556 // void <: void (by reflexivity)
10454 // bottom <: void (as bottom is a subtype of all types). 10557 // bottom <: void (as bottom is a subtype of all types).
10455 // void <: dynamic (as dynamic is a supertype of all types) 10558 // void <: dynamic (as dynamic is a supertype of all types)
10456 return identical(type, this) || type.isDynamic; 10559 return identical(type, this) || type.isDynamic;
10457 } 10560 }
10458 10561
10459 @override 10562 @override
10460 VoidTypeImpl substitute2( 10563 VoidTypeImpl substitute2(
10461 List<DartType> argumentTypes, List<DartType> parameterTypes) => this; 10564 List<DartType> argumentTypes, List<DartType> parameterTypes) => this;
10462 } 10565 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698