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

Unified Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 2244333003: Remove AST-hack for multi-field declarations. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/resolution/resolution.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/resolution/resolution.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698