Index: pkg/compiler/lib/src/elements/modelx.dart |
diff --git a/pkg/compiler/lib/src/elements/modelx.dart b/pkg/compiler/lib/src/elements/modelx.dart |
index ded05a0bbc428553a272cdba120a6f83f3d34f0f..4eb76bb1ba583d0ec502f3e3f0149ce591437a5c 100644 |
--- a/pkg/compiler/lib/src/elements/modelx.dart |
+++ b/pkg/compiler/lib/src/elements/modelx.dart |
@@ -1473,6 +1473,7 @@ abstract class VariableElementX extends ElementX |
final Token token; |
final VariableList variables; |
VariableDefinitions definitionsCache; |
+ Expression definitionCache; |
Expression initializerCache; |
Modifiers get modifiers => variables.modifiers; |
@@ -1505,6 +1506,16 @@ abstract class VariableElementX extends ElementX |
return definitionsCache; |
} |
+ /// Returns the node that defines this field. |
+ /// |
+ /// For instance in `var a, b = true`, the definitions nodes for fields 'a' |
+ /// and 'b' are the nodes for `a` and `b = true`, respectively. |
+ Expression get definition { |
+ assert(invariant(this, definitionCache != null, |
+ message: "Definition node has not been computed for $this.")); |
+ return definitionCache; |
+ } |
+ |
Expression get initializer { |
assert(invariant(this, definitionsCache != null, |
message: "Initializer has not been computed for $this.")); |
@@ -1522,8 +1533,6 @@ abstract class VariableElementX extends ElementX |
void createDefinitions(VariableDefinitions definitions) { |
assert(invariant(this, definitionsCache == null, |
message: "VariableDefinitions has already been computed for $this.")); |
- Expression node; |
- int count = 0; |
for (Link<Node> link = definitions.definitions.nodes; |
!link.isEmpty; |
link = link.tail) { |
@@ -1533,28 +1542,16 @@ abstract class VariableElementX extends ElementX |
SendSet sendSet = initializedIdentifier.asSendSet(); |
identifier = sendSet.selector.asIdentifier(); |
if (identical(name, identifier.source)) { |
- node = initializedIdentifier; |
+ definitionCache = initializedIdentifier; |
initializerCache = sendSet.arguments.first; |
} |
} else if (identical(name, identifier.source)) { |
- node = initializedIdentifier; |
+ definitionCache = initializedIdentifier; |
} |
- count++; |
- } |
- invariant(definitions, node != null, message: "Could not find '$name'."); |
- if (count == 1) { |
- definitionsCache = definitions; |
- } else { |
- // Create a [VariableDefinitions] node for the single definition of |
- // [node]. |
- definitionsCache = new VariableDefinitions( |
- definitions.type, |
- definitions.modifiers, |
- new NodeList( |
- definitions.definitions.beginToken, |
- const Link<Node>().prepend(node), |
- definitions.definitions.endToken)); |
} |
+ invariant(definitions, definitionCache != null, |
+ message: "Could not find '$name'."); |
+ definitionsCache = definitions; |
} |
DartType computeType(Resolution resolution) { |
@@ -1659,6 +1656,14 @@ class ErroneousFieldElementX extends ElementX |
Token get token => node.getBeginToken(); |
+ get definitionCache { |
+ throw new UnsupportedError("definitionCache"); |
+ } |
+ |
+ set definitionCache(_) { |
+ throw new UnsupportedError("definitionCache="); |
+ } |
+ |
get initializerCache { |
throw new UnsupportedError("initializerCache"); |
} |
@@ -1673,6 +1678,8 @@ class ErroneousFieldElementX extends ElementX |
get initializer => null; |
+ get definition => null; |
+ |
bool get isMalformed => true; |
get nestedClosures { |
@@ -3016,6 +3023,7 @@ class EnumFieldElementX extends FieldElementX { |
definitionsCache = new VariableDefinitions( |
null, variableList.modifiers, new NodeList.singleton(definition)); |
initializerCache = initializer; |
+ definitionCache = definition; |
} |
@override |