Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.modelx; | 5 library elements.modelx; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/names.dart' show Identifiers; | 8 import '../common/names.dart' show Identifiers; |
| 9 import '../common/resolution.dart' show Resolution, ParsingContext; | 9 import '../common/resolution.dart' show Resolution, ParsingContext; |
| 10 import '../compiler.dart' show Compiler; | 10 import '../compiler.dart' show Compiler; |
| (...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 constantCache = value; | 1466 constantCache = value; |
| 1467 } | 1467 } |
| 1468 } | 1468 } |
| 1469 | 1469 |
| 1470 abstract class VariableElementX extends ElementX | 1470 abstract class VariableElementX extends ElementX |
| 1471 with AstElementMixin, ConstantVariableMixin | 1471 with AstElementMixin, ConstantVariableMixin |
| 1472 implements VariableElement { | 1472 implements VariableElement { |
| 1473 final Token token; | 1473 final Token token; |
| 1474 final VariableList variables; | 1474 final VariableList variables; |
| 1475 VariableDefinitions definitionsCache; | 1475 VariableDefinitions definitionsCache; |
| 1476 Expression definitionCache; | |
| 1476 Expression initializerCache; | 1477 Expression initializerCache; |
| 1477 | 1478 |
| 1478 Modifiers get modifiers => variables.modifiers; | 1479 Modifiers get modifiers => variables.modifiers; |
| 1479 | 1480 |
| 1480 VariableElementX(String name, ElementKind kind, Element enclosingElement, | 1481 VariableElementX(String name, ElementKind kind, Element enclosingElement, |
| 1481 VariableList variables, this.token) | 1482 VariableList variables, this.token) |
| 1482 : this.variables = variables, | 1483 : this.variables = variables, |
| 1483 super(name, kind, enclosingElement); | 1484 super(name, kind, enclosingElement); |
| 1484 | 1485 |
| 1485 // TODO(johnniwinther): Ensure that the [TreeElements] for this variable hold | 1486 // TODO(johnniwinther): Ensure that the [TreeElements] for this variable hold |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1498 AstElement get definingElement => this; | 1499 AstElement get definingElement => this; |
| 1499 | 1500 |
| 1500 bool get hasNode => definitionsCache != null; | 1501 bool get hasNode => definitionsCache != null; |
| 1501 | 1502 |
| 1502 VariableDefinitions get node { | 1503 VariableDefinitions get node { |
| 1503 assert(invariant(this, definitionsCache != null, | 1504 assert(invariant(this, definitionsCache != null, |
| 1504 message: "Node has not been computed for $this.")); | 1505 message: "Node has not been computed for $this.")); |
| 1505 return definitionsCache; | 1506 return definitionsCache; |
| 1506 } | 1507 } |
| 1507 | 1508 |
| 1509 /// Returns the node that defines this field. | |
| 1510 /// | |
| 1511 /// For instance in `var a, b = true`, the definitions nodes for fields 'a' | |
| 1512 /// and 'b' are the nodes for `a` and `b = true`, respectively. | |
| 1513 Expression get definition { | |
| 1514 assert(invariant(this, definitionCache != null, | |
| 1515 message: "Definition node has not been computed for $this.")); | |
| 1516 return definitionCache; | |
| 1517 } | |
| 1518 | |
| 1508 Expression get initializer { | 1519 Expression get initializer { |
| 1509 assert(invariant(this, definitionsCache != null, | 1520 assert(invariant(this, definitionsCache != null, |
| 1510 message: "Initializer has not been computed for $this.")); | 1521 message: "Initializer has not been computed for $this.")); |
| 1511 return initializerCache; | 1522 return initializerCache; |
| 1512 } | 1523 } |
| 1513 | 1524 |
| 1514 Node parseNode(ParsingContext parsing) { | 1525 Node parseNode(ParsingContext parsing) { |
| 1515 if (definitionsCache != null) return definitionsCache; | 1526 if (definitionsCache != null) return definitionsCache; |
| 1516 | 1527 |
| 1517 VariableDefinitions definitions = variables.parseNode(this, parsing); | 1528 VariableDefinitions definitions = variables.parseNode(this, parsing); |
| 1518 createDefinitions(definitions); | 1529 createDefinitions(definitions); |
| 1519 return definitionsCache; | 1530 return definitionsCache; |
| 1520 } | 1531 } |
| 1521 | 1532 |
| 1522 void createDefinitions(VariableDefinitions definitions) { | 1533 void createDefinitions(VariableDefinitions definitions) { |
| 1523 assert(invariant(this, definitionsCache == null, | 1534 assert(invariant(this, definitionsCache == null, |
| 1524 message: "VariableDefinitions has already been computed for $this.")); | 1535 message: "VariableDefinitions has already been computed for $this.")); |
| 1525 Expression node; | |
| 1526 int count = 0; | 1536 int count = 0; |
| 1527 for (Link<Node> link = definitions.definitions.nodes; | 1537 for (Link<Node> link = definitions.definitions.nodes; |
| 1528 !link.isEmpty; | 1538 !link.isEmpty; |
| 1529 link = link.tail) { | 1539 link = link.tail) { |
| 1530 Expression initializedIdentifier = link.head; | 1540 Expression initializedIdentifier = link.head; |
| 1531 Identifier identifier = initializedIdentifier.asIdentifier(); | 1541 Identifier identifier = initializedIdentifier.asIdentifier(); |
| 1532 if (identifier == null) { | 1542 if (identifier == null) { |
| 1533 SendSet sendSet = initializedIdentifier.asSendSet(); | 1543 SendSet sendSet = initializedIdentifier.asSendSet(); |
| 1534 identifier = sendSet.selector.asIdentifier(); | 1544 identifier = sendSet.selector.asIdentifier(); |
| 1535 if (identical(name, identifier.source)) { | 1545 if (identical(name, identifier.source)) { |
| 1536 node = initializedIdentifier; | 1546 definitionCache = initializedIdentifier; |
| 1537 initializerCache = sendSet.arguments.first; | 1547 initializerCache = sendSet.arguments.first; |
| 1538 } | 1548 } |
| 1539 } else if (identical(name, identifier.source)) { | 1549 } else if (identical(name, identifier.source)) { |
| 1540 node = initializedIdentifier; | 1550 definitionCache = initializedIdentifier; |
| 1541 } | 1551 } |
| 1542 count++; | 1552 count++; |
|
Siggi Cherem (dart-lang)
2016/08/16 15:14:39
dead variable now?
Johnni Winther
2016/08/17 08:04:01
Removed.
| |
| 1543 } | 1553 } |
| 1544 invariant(definitions, node != null, message: "Could not find '$name'."); | 1554 invariant(definitions, definitionCache != null, |
| 1545 if (count == 1) { | 1555 message: "Could not find '$name'."); |
| 1546 definitionsCache = definitions; | 1556 definitionsCache = definitions; |
| 1547 } else { | |
| 1548 // Create a [VariableDefinitions] node for the single definition of | |
| 1549 // [node]. | |
| 1550 definitionsCache = new VariableDefinitions( | |
| 1551 definitions.type, | |
| 1552 definitions.modifiers, | |
| 1553 new NodeList( | |
| 1554 definitions.definitions.beginToken, | |
| 1555 const Link<Node>().prepend(node), | |
| 1556 definitions.definitions.endToken)); | |
| 1557 } | |
| 1558 } | 1557 } |
| 1559 | 1558 |
| 1560 DartType computeType(Resolution resolution) { | 1559 DartType computeType(Resolution resolution) { |
| 1561 if (variables.type != null) return variables.type; | 1560 if (variables.type != null) return variables.type; |
| 1562 // Call [parseNode] to ensure that [definitionsCache] and [initializerCache] | 1561 // Call [parseNode] to ensure that [definitionsCache] and [initializerCache] |
| 1563 // are set as a consequence of calling [computeType]. | 1562 // are set as a consequence of calling [computeType]. |
| 1564 parseNode(resolution.parsingContext); | 1563 parseNode(resolution.parsingContext); |
| 1565 return variables.computeType(this, resolution); | 1564 return variables.computeType(this, resolution); |
| 1566 } | 1565 } |
| 1567 | 1566 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1652 bool get hasResolvedAst => false; | 1651 bool get hasResolvedAst => false; |
| 1653 | 1652 |
| 1654 ResolvedAst get resolvedAst { | 1653 ResolvedAst get resolvedAst { |
| 1655 throw new UnsupportedError("resolvedAst"); | 1654 throw new UnsupportedError("resolvedAst"); |
| 1656 } | 1655 } |
| 1657 | 1656 |
| 1658 DynamicType get type => const DynamicType(); | 1657 DynamicType get type => const DynamicType(); |
| 1659 | 1658 |
| 1660 Token get token => node.getBeginToken(); | 1659 Token get token => node.getBeginToken(); |
| 1661 | 1660 |
| 1661 get definitionCache { | |
| 1662 throw new UnsupportedError("definitionCache"); | |
| 1663 } | |
| 1664 | |
| 1665 set definitionCache(_) { | |
| 1666 throw new UnsupportedError("definitionCache="); | |
| 1667 } | |
| 1668 | |
| 1662 get initializerCache { | 1669 get initializerCache { |
| 1663 throw new UnsupportedError("initializerCache"); | 1670 throw new UnsupportedError("initializerCache"); |
| 1664 } | 1671 } |
| 1665 | 1672 |
| 1666 set initializerCache(_) { | 1673 set initializerCache(_) { |
| 1667 throw new UnsupportedError("initializerCache="); | 1674 throw new UnsupportedError("initializerCache="); |
| 1668 } | 1675 } |
| 1669 | 1676 |
| 1670 void createDefinitions(VariableDefinitions definitions) { | 1677 void createDefinitions(VariableDefinitions definitions) { |
| 1671 throw new UnsupportedError("createDefinitions"); | 1678 throw new UnsupportedError("createDefinitions"); |
| 1672 } | 1679 } |
| 1673 | 1680 |
| 1674 get initializer => null; | 1681 get initializer => null; |
| 1675 | 1682 |
| 1683 get definition => null; | |
| 1684 | |
| 1676 bool get isMalformed => true; | 1685 bool get isMalformed => true; |
| 1677 | 1686 |
| 1678 get nestedClosures { | 1687 get nestedClosures { |
| 1679 throw new UnsupportedError("nestedClosures"); | 1688 throw new UnsupportedError("nestedClosures"); |
| 1680 } | 1689 } |
| 1681 | 1690 |
| 1682 set nestedClosures(_) { | 1691 set nestedClosures(_) { |
| 1683 throw new UnsupportedError("nestedClosures="); | 1692 throw new UnsupportedError("nestedClosures="); |
| 1684 } | 1693 } |
| 1685 | 1694 |
| (...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3009 /// where the `index` and `values` fields are encoded using this element. | 3018 /// where the `index` and `values` fields are encoded using this element. |
| 3010 /// | 3019 /// |
| 3011 class EnumFieldElementX extends FieldElementX { | 3020 class EnumFieldElementX extends FieldElementX { |
| 3012 EnumFieldElementX(Identifier name, EnumClassElementX enumClass, | 3021 EnumFieldElementX(Identifier name, EnumClassElementX enumClass, |
| 3013 VariableList variableList, Node definition, | 3022 VariableList variableList, Node definition, |
| 3014 [Expression initializer]) | 3023 [Expression initializer]) |
| 3015 : super(name, enumClass, variableList) { | 3024 : super(name, enumClass, variableList) { |
| 3016 definitionsCache = new VariableDefinitions( | 3025 definitionsCache = new VariableDefinitions( |
| 3017 null, variableList.modifiers, new NodeList.singleton(definition)); | 3026 null, variableList.modifiers, new NodeList.singleton(definition)); |
| 3018 initializerCache = initializer; | 3027 initializerCache = initializer; |
| 3028 definitionCache = definition; | |
| 3019 } | 3029 } |
| 3020 | 3030 |
| 3021 @override | 3031 @override |
| 3022 SourceSpan get sourcePosition => enclosingClass.sourcePosition; | 3032 SourceSpan get sourcePosition => enclosingClass.sourcePosition; |
| 3023 } | 3033 } |
| 3024 | 3034 |
| 3025 /// This element is used to encode the constant value in an enum class. | 3035 /// This element is used to encode the constant value in an enum class. |
| 3026 /// | 3036 /// |
| 3027 /// For instance | 3037 /// For instance |
| 3028 /// | 3038 /// |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3394 body = node.asFunctionExpression().body; | 3404 body = node.asFunctionExpression().body; |
| 3395 } | 3405 } |
| 3396 return new ParsedResolvedAst( | 3406 return new ParsedResolvedAst( |
| 3397 declaration, | 3407 declaration, |
| 3398 node, | 3408 node, |
| 3399 body, | 3409 body, |
| 3400 definingElement.treeElements, | 3410 definingElement.treeElements, |
| 3401 definingElement.compilationUnit.script.resourceUri); | 3411 definingElement.compilationUnit.script.resourceUri); |
| 3402 } | 3412 } |
| 3403 } | 3413 } |
| OLD | NEW |