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

Side by Side Diff: pkg/analyzer2dart/lib/src/semantic_visitor.dart

Issue 609783002: Support static field access in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 2 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
« no previous file with comments | « pkg/analyzer2dart/lib/src/modely.dart ('k') | pkg/analyzer2dart/lib/src/tree_shaker.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer2dart.semantic_visitor;
6
7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/src/generated/source.dart';
9
10 import 'util.dart';
11 import 'package:analyzer2dart/src/identifier_semantics.dart';
12
13 /// An AST visitor which uses the [AccessSemantics] of invocations and accesses
14 /// to fine-grain visitor methods.
15 abstract class SemanticVisitor<R> extends RecursiveAstVisitor<R> {
16
17 Source get currentSource;
18
19 void reportMessage(AstNode node, String message) {
20 reportSourceMessage(currentSource, node, message);
21 }
22
23 giveUp(AstNode node, String message) {
24 reportMessage(node, message);
25 throw new UnimplementedError(message);
26 }
27
28 bool invariant(AstNode node, condition, String message) {
29 if (condition is Function) {
30 condition = condition();
31 }
32 if (!condition) {
33 reportMessage(node, message);
34 throw new AssertionError();
35 }
36 return true;
37 }
38
39 R visitDynamicInvocation(MethodInvocation node,
40 AccessSemantics semantics) {
41 return giveUp(node, 'visitDynamicInvocation of $semantics');
42 }
43
44 R visitLocalFunctionInvocation(MethodInvocation node,
45 AccessSemantics semantics) {
46 return giveUp(node, 'visitLocalFunctionInvocation of $semantics');
47 }
48
49 R visitLocalVariableInvocation(MethodInvocation node,
50 AccessSemantics semantics) {
51 return giveUp(node, 'visitLocalVariableInvocation of $semantics');
52 }
53
54 R visitParameterInvocation(MethodInvocation node,
55 AccessSemantics semantics) {
56 return giveUp(node, 'visitParameterInvocation of $semantics');
57 }
58
59 R visitStaticFieldInvocation(MethodInvocation node,
60 AccessSemantics semantics) {
61 return giveUp(node, 'visitStaticFieldInvocation of $semantics');
62 }
63
64 R visitStaticMethodInvocation(MethodInvocation node,
65 AccessSemantics semantics) {
66 return giveUp(node, 'visitStaticMethodInvocation of $semantics');
67 }
68
69 R visitStaticPropertyInvocation(MethodInvocation node,
70 AccessSemantics semantics) {
71 return giveUp(node, 'visitStaticPropertyInvocation of $semantics');
72 }
73
74 @override
75 R visitMethodInvocation(MethodInvocation node) {
76 if (node.target != null) {
77 node.target.accept(this);
78 }
79 node.argumentList.accept(this);
80 AccessSemantics semantics = classifyMethodInvocation(node);
81 switch (semantics.kind) {
82 case AccessKind.DYNAMIC:
83 return visitDynamicInvocation(node, semantics);
84 case AccessKind.LOCAL_FUNCTION:
85 return visitLocalFunctionInvocation(node, semantics);
86 case AccessKind.LOCAL_VARIABLE:
87 return visitLocalVariableInvocation(node, semantics);
88 case AccessKind.PARAMETER:
89 return visitParameterInvocation(node, semantics);
90 case AccessKind.STATIC_FIELD:
91 return visitStaticFieldInvocation(node, semantics);
92 case AccessKind.STATIC_METHOD:
93 return visitStaticMethodInvocation(node, semantics);
94 case AccessKind.STATIC_PROPERTY:
95 return visitStaticPropertyInvocation(node, semantics);
96 default:
97 // Unexpected access kind.
98 return giveUp(node,
99 'Unexpected ${semantics} in visitMethodInvocation.');
100 }
101 }
102
103 @override
104 R visitPropertyAccess(PropertyAccess node) {
105 if (node.target != null) {
106 node.target.accept(this);
107 }
108 return _handlePropertyAccess(node, classifyPropertyAccess(node));
109 }
110
111 @override
112 R visitPrefixedIdentifier(PrefixedIdentifier node) {
113 node.prefix.accept(this);
114 return _handlePropertyAccess(node, classifyPrefixedIdentifier(node));
115 }
116
117 @override
118 R visitSimpleIdentifier(SimpleIdentifier node) {
119 AccessSemantics semantics = classifySimpleIdentifier(node);
120 if (semantics != null) {
121 return _handlePropertyAccess(node, semantics);
122 } else {
123 return null;
124 }
125 }
126
127 R visitDynamicAccess(AstNode node, AccessSemantics semantics) {
128 return giveUp(node, 'visitDynamicAccess of $semantics');
129 }
130
131 R visitLocalFunctionAccess(AstNode node, AccessSemantics semantics) {
132 return giveUp(node, 'visitLocalFunctionAccess of $semantics');
133 }
134
135 R visitLocalVariableAccess(AstNode node, AccessSemantics semantics) {
136 return giveUp(node, 'visitLocalVariableAccess of $semantics');
137 }
138
139 R visitParameterAccess(AstNode node, AccessSemantics semantics) {
140 return giveUp(node, 'visitParameterAccess of $semantics');
141 }
142
143 R visitStaticFieldAccess(AstNode node, AccessSemantics semantics) {
144 return giveUp(node, 'visitStaticFieldAccess of $semantics');
145 }
146
147 R visitStaticMethodAccess(AstNode node, AccessSemantics semantics) {
148 return giveUp(node, 'visitStaticMethodAccess of $semantics');
149 }
150
151 R visitStaticPropertyAccess(AstNode node, AccessSemantics semantics) {
152 return giveUp(node, 'visitStaticPropertyAccess of $semantics');
153 }
154
155 R _handlePropertyAccess(AstNode node, AccessSemantics semantics) {
156 switch (semantics.kind) {
157 case AccessKind.DYNAMIC:
158 return visitDynamicAccess(node, semantics);
159 case AccessKind.LOCAL_FUNCTION:
160 return visitLocalFunctionAccess(node, semantics);
161 case AccessKind.LOCAL_VARIABLE:
162 return visitLocalVariableAccess(node, semantics);
163 case AccessKind.PARAMETER:
164 return visitParameterAccess(node, semantics);
165 case AccessKind.STATIC_FIELD:
166 return visitStaticFieldAccess(node, semantics);
167 case AccessKind.STATIC_METHOD:
168 return visitStaticMethodAccess(node, semantics);
169 case AccessKind.STATIC_PROPERTY:
170 return visitStaticPropertyAccess(node, semantics);
171 default:
172 // Unexpected access kind.
173 return giveUp(node,
174 'Unexpected ${semantics} in _handlePropertyAccess.');
175 }
176 }
177 }
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/lib/src/modely.dart ('k') | pkg/analyzer2dart/lib/src/tree_shaker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698