Skip to content

Commit 9557f01

Browse files
committed
Handle SendSet and NewExpression through NewResolvedVisitor.
This allows for the handling assignment and new expression through the SemanticSendVisitor methods in SsaBuilder and InferrerVisitor(s). BUG= R=karlklose@google.com Review URL: https://codereview.chromium.org//1079533002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45091 260f80e4-7a28-3924-810f-c04153c831b5
1 parent c035148 commit 9557f01

File tree

6 files changed

+114
-22
lines changed

6 files changed

+114
-22
lines changed

pkg/compiler/lib/src/dart_backend/placeholder_collector.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ class SendVisitor extends OldResolvedVisitor {
152152
}
153153
}
154154
}
155+
156+
@override
157+
handleNewExpression(NewExpression node) => visitNode(node);
158+
159+
@override
160+
handleSendSet(SendSet node) => visitNode(node);
155161
}
156162

157163
class PlaceholderCollector extends Visitor {

pkg/compiler/lib/src/inferrer/inferrer_visitor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ abstract class InferrerVisitor
703703
locals = new LocalsHandler<T>(inferrer, types, compiler, node, fieldScope);
704704
}
705705

706-
T visitSendSet(SendSet node);
706+
T handleSendSet(SendSet node);
707707

708708
T visitSuperSend(Send node);
709709

@@ -736,7 +736,7 @@ abstract class InferrerVisitor
736736
return node.visitChildren(this);
737737
}
738738

739-
T visitNewExpression(NewExpression node) {
739+
T handleNewExpression(NewExpression node) {
740740
return node.send.accept(this);
741741
}
742742

pkg/compiler/lib/src/inferrer/simple_types_inferrer.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@ class SimpleTypeInferrerVisitor<T>
773773
|| (element != null && element.isInstanceMember);
774774
}
775775

776-
T visitSendSet(ast.SendSet node) {
776+
@override
777+
T handleSendSet(ast.SendSet node) {
777778
Element element = elements[node];
778779
if (!Elements.isUnresolved(element) && element.impliesType) {
779780
node.visitChildren(this);

pkg/compiler/lib/src/resolution/send_structure.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ import '../tree/tree.dart';
1414
import '../universe/universe.dart';
1515
import '../util/util.dart';
1616

17+
/// Interface for the structure of the semantics of a [Send] or [NewExpression]
18+
/// node.
19+
abstract class SemanticSendStructure<R, A> {
20+
/// Calls the matching visit method on [visitor] with [node] and [arg].
21+
R dispatch(SemanticSendVisitor<R, A> visitor, Node node, A arg);
22+
}
23+
1724
/// Interface for the structure of the semantics of a [Send] node.
1825
///
1926
/// Subclasses handle each of the [Send] variations; `assert(e)`, `a && b`,
2027
/// `a.b`, `a.b(c)`, etc.
21-
abstract class SendStructure<R, A> {
28+
abstract class SendStructure<R, A> extends SemanticSendStructure<R, A> {
2229
/// Calls the matching visit method on [visitor] with [send] and [arg].
2330
R dispatch(SemanticSendVisitor<R, A> visitor, Send send, A arg);
2431
}
@@ -1811,7 +1818,7 @@ class PostfixStructure<R, A> implements SendStructure<R, A> {
18111818
}
18121819

18131820
/// The structure for a [NewExpression] of a new invocation.
1814-
abstract class NewStructure<R, A> {
1821+
abstract class NewStructure<R, A> implements SemanticSendStructure<R, A> {
18151822
/// Calls the matching visit method on [visitor] with [node] and [arg].
18161823
R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg);
18171824
}

pkg/compiler/lib/src/resolved_visitor.dart

Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ enum ResolvedKind {
1717
CLOSURE,
1818
DYNAMIC,
1919
ERROR,
20+
SEND_SET,
21+
NEW,
2022
}
2123

2224
/// Abstract interface for a [ResolvedVisitor].
@@ -28,6 +30,8 @@ abstract class ResolvedKindVisitor<R> {
2830
R visitClosureSend(Send node);
2931
R visitDynamicSend(Send node);
3032
R visitStaticSend(Send node);
33+
R handleSendSet(SendSet node);
34+
R handleNewExpression(NewExpression node);
3135

3236
/// Visitor callback for a type literal.
3337
R visitTypeLiteralSend(Send node);
@@ -56,6 +60,8 @@ class ResolvedKindComputer implements ResolvedKindVisitor {
5660
ResolvedKind visitTypeLiteralSend(Send node) => ResolvedKind.TYPE_LITERAL;
5761
ResolvedKind visitTypePrefixSend(Send node) => ResolvedKind.TYPE_PREFIX;
5862
ResolvedKind visitAssertSend(Send node) => ResolvedKind.ASSERT;
63+
ResolvedKind handleSendSet(SendSet node) => ResolvedKind.SEND_SET;
64+
ResolvedKind handleNewExpression(NewExpression node) => ResolvedKind.NEW;
5965
internalError(Spannable node, String reason) => ResolvedKind.ERROR;
6066
}
6167

@@ -130,6 +136,14 @@ abstract class OldResolvedVisitor<R> extends BaseResolvedVisitor<R> {
130136
R visitSend(Send node) {
131137
return _oldDispatch(node, this);
132138
}
139+
140+
R visitSendSet(SendSet node) {
141+
return handleSendSet(node);
142+
}
143+
144+
R visitNewExpression(NewExpression node) {
145+
return handleNewExpression(node);
146+
}
133147
}
134148

135149
abstract class NewResolvedVisitor<R> extends BaseResolvedVisitor<R>
@@ -185,18 +199,54 @@ abstract class NewResolvedVisitor<R> extends BaseResolvedVisitor<R>
185199
}
186200
}
187201

202+
bool checkResolvedKind(Node node,
203+
ResolvedKind oldKind,
204+
ResolvedKind newKind) {
205+
return invariant(node, oldKind == newKind, message: '$oldKind != $newKind');
206+
}
207+
208+
ResolvedKind computeResolvedKindFromStructure(
209+
Node node, SemanticSendStructure structure) {
210+
return structure.dispatch(
211+
_resolvedKindDispatcher, node, const ResolvedKindComputer());
212+
}
213+
214+
@override
188215
R visitSend(Send node) {
189-
ResolvedKind oldKind;
190-
ResolvedKind newKind;
191-
assert(invariant(node, () {
192-
oldKind = _oldDispatch(node, const ResolvedKindComputer());
193-
newKind = _newDispatch(
194-
node, const ResolvedKindComputer(), _resolvedKindDispatcher);
195-
return oldKind == newKind;
196-
}, message: () => '$oldKind != $newKind'));
216+
assert(checkResolvedKind(
217+
node,
218+
_oldDispatch(node, const ResolvedKindComputer()),
219+
_newDispatch(node, const ResolvedKindComputer(),
220+
_resolvedKindDispatcher)));
197221
return _newDispatch(node, this, this);
198222
}
199223

224+
@override
225+
R visitSendSet(Send node) {
226+
SendStructure structure = computeSendStructure(node);
227+
if (structure == null) {
228+
return internalError(node, 'No structure for $node');
229+
} else {
230+
assert(checkResolvedKind(node,
231+
ResolvedKind.SEND_SET,
232+
computeResolvedKindFromStructure(node, structure)));
233+
return structure.dispatch(this, node, structure);
234+
}
235+
}
236+
237+
@override
238+
R visitNewExpression(NewExpression node) {
239+
NewStructure structure = computeNewStructure(node);
240+
if (structure == null) {
241+
return internalError(node, 'No structure for $node');
242+
} else {
243+
assert(checkResolvedKind(node,
244+
ResolvedKind.NEW,
245+
computeResolvedKindFromStructure(node, structure)));
246+
return structure.dispatch(this, node, structure);
247+
}
248+
}
249+
200250
@override
201251
R apply(Node node, arg) {
202252
return visitNode(node);
@@ -206,8 +256,8 @@ abstract class NewResolvedVisitor<R> extends BaseResolvedVisitor<R>
206256
R bulkHandleNode(
207257
Node node,
208258
String message,
209-
SendStructure sendStructure) {
210-
return sendStructure.dispatch(_semanticDispatcher, node, this);
259+
SemanticSendStructure structure) {
260+
return structure.dispatch(_semanticDispatcher, node, this);
211261
}
212262
}
213263

@@ -239,13 +289,16 @@ class ResolvedSemanticDispatcher<R> extends Object
239289
Node node,
240290
String message,
241291
ResolvedKindVisitor<R> visitor) {
242-
// Set, Compound, IndexSet, and NewExpression are not handled by
243-
// [ResolvedVisitor].
244292
return bulkHandleError(node, visitor);
245293
}
246294

247295
R bulkHandleError(Node node, ResolvedKindVisitor<R> visitor) {
248-
return visitor.internalError(node, "No resolved kind for node.");
296+
if (node.asSendSet() != null) {
297+
return visitor.handleSendSet(node);
298+
} else if (node.asNewExpression() != null) {
299+
return visitor.handleNewExpression(node);
300+
}
301+
return visitor.internalError(node, "No resolved kind for $node.");
249302
}
250303

251304
@override
@@ -261,19 +314,42 @@ class ResolvedSemanticDispatcher<R> extends Object
261314

262315
@override
263316
R bulkHandlePrefix(Node node, ResolvedKindVisitor<R> visitor) {
264-
return visitor.visitOperatorSend(node);
317+
return visitor.handleSendSet(node);
265318
}
266319

267320
@override
268321
R bulkHandlePostfix(Node node, ResolvedKindVisitor<R> visitor) {
269-
return visitor.visitOperatorSend(node);
322+
return visitor.handleSendSet(node);
270323
}
271324

272325
@override
273326
R bulkHandleSuper(Node node, ResolvedKindVisitor<R> visitor) {
327+
if (node.asSendSet() != null) {
328+
return visitor.handleSendSet(node);
329+
}
274330
return visitor.visitSuperSend(node);
275331
}
276332

333+
@override
334+
R bulkHandleSet(SendSet node, ResolvedKindVisitor<R> visitor) {
335+
return visitor.handleSendSet(node);
336+
}
337+
338+
@override
339+
R bulkHandleCompound(SendSet node, ResolvedKindVisitor<R> visitor) {
340+
return visitor.handleSendSet(node);
341+
}
342+
343+
@override
344+
R bulkHandleIndexSet(SendSet node, ResolvedKindVisitor<R> visitor) {
345+
return visitor.handleSendSet(node);
346+
}
347+
348+
@override
349+
R bulkHandleNew(NewExpression node, ResolvedKindVisitor<R> visitor) {
350+
return visitor.handleNewExpression(node);
351+
}
352+
277353
@override
278354
R errorInvalidAssert(
279355
Send node,

pkg/compiler/lib/src/ssa/builder.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4778,7 +4778,8 @@ class SsaBuilder extends NewResolvedVisitor {
47784778
existingArguments: existingArguments);
47794779
}
47804780

4781-
visitNewExpression(ast.NewExpression node) {
4781+
@override
4782+
handleNewExpression(ast.NewExpression node) {
47824783
Element element = elements[node.send];
47834784
final bool isSymbolConstructor = element == compiler.symbolConstructor;
47844785
if (!Elements.isErroneous(element)) {
@@ -4965,7 +4966,8 @@ class SsaBuilder extends NewResolvedVisitor {
49654966
elements.getOperatorSelectorInComplexSendSet(node), node);
49664967
}
49674968

4968-
visitSendSet(ast.SendSet node) {
4969+
@override
4970+
handleSendSet(ast.SendSet node) {
49694971
generateIsDeferredLoadedCheckIfNeeded(node);
49704972
Element element = elements[node];
49714973
if (!Elements.isUnresolved(element) && element.impliesType) {

0 commit comments

Comments
 (0)