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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart

Issue 813753002: Change the S-expression representation of constant values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 dart2js.ir_nodes_sexpr; 5 library dart2js.ir_nodes_sexpr;
6 6
7 import '../constants/values.dart';
7 import '../util/util.dart'; 8 import '../util/util.dart';
8 import 'cps_ir_nodes.dart'; 9 import 'cps_ir_nodes.dart';
9 10
10 /// A [Decorator] is a function used by [SExpressionStringifier] to augment the 11 /// A [Decorator] is a function used by [SExpressionStringifier] to augment the
11 /// output produced for a node. It can be provided to the constructor. 12 /// output produced for a node. It can be provided to the constructor.
12 typedef String Decorator(Node node, String s); 13 typedef String Decorator(Node node, String s);
13 14
14 /// Generate a Lisp-like S-expression representation of an IR node as a string. 15 /// Generate a Lisp-like S-expression representation of an IR node as a string.
15 class SExpressionStringifier extends Visitor<String> with Indentation { 16 class SExpressionStringifier extends Visitor<String> with Indentation {
16 final _Namer namer = new _Namer(); 17 final _Namer namer = new _Namer();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 153 }
153 154
154 String visitBranch(Branch node) { 155 String visitBranch(Branch node) {
155 String condition = visit(node.condition); 156 String condition = visit(node.condition);
156 String trueCont = access(node.trueContinuation); 157 String trueCont = access(node.trueContinuation);
157 String falseCont = access(node.falseContinuation); 158 String falseCont = access(node.falseContinuation);
158 return '$indentation(Branch $condition $trueCont $falseCont)'; 159 return '$indentation(Branch $condition $trueCont $falseCont)';
159 } 160 }
160 161
161 String visitConstant(Constant node) { 162 String visitConstant(Constant node) {
162 return '(Constant ${node.expression.value.toStructuredString()})'; 163 String value =
164 node.expression.value.accept(new ConstantStringifier(), null);
165 return '(Constant $value)';
163 } 166 }
164 167
165 String visitThis(This node) { 168 String visitThis(This node) {
166 return '(This)'; 169 return '(This)';
167 } 170 }
168 171
169 String visitReifyTypeVar(ReifyTypeVar node) { 172 String visitReifyTypeVar(ReifyTypeVar node) {
170 return '$indentation(ReifyTypeVar ${node.typeVariable.name})'; 173 return '$indentation(ReifyTypeVar ${node.typeVariable.name})';
171 } 174 }
172 175
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 String left = access(node.left); 230 String left = access(node.left);
228 String right = access(node.right); 231 String right = access(node.right);
229 return '(Identical $left $right)'; 232 return '(Identical $left $right)';
230 } 233 }
231 234
232 String visitInterceptor(Interceptor node) { 235 String visitInterceptor(Interceptor node) {
233 return '(Interceptor ${node.input})'; 236 return '(Interceptor ${node.input})';
234 } 237 }
235 } 238 }
236 239
240 class ConstantStringifier extends ConstantValueVisitor<String, Null> {
241 // Some of these methods are unimplemented because we haven't had a need
242 // to print such constants. When printing is implemented, the corresponding
243 // parsing support should be added to SExpressionUnstringifier.parseConstant
244 // in the dart2js tests (currently in the file
245 // tests/compiler/dart2js/backend_dart/sexpr_unstringifier.dart).
246
247 String _failWith(ConstantValue constant) {
248 throw 'Stringification not supported for ${constant.toStructuredString()}';
249 }
250
251 String visitFunction(FunctionConstantValue constant, _) {
252 return _failWith(constant);
253 }
254
255 String visitNull(NullConstantValue constant, _) {
256 return '(Null)';
257 }
258
259 String visitInt(IntConstantValue constant, _) {
260 return '(Int ${constant.unparse()})';
261 }
262
263 String visitDouble(DoubleConstantValue constant, _) {
264 return '(Double ${constant.unparse()})';
265 }
266
267 String visitBool(BoolConstantValue constant, _) {
268 return '(Bool ${constant.unparse()})';
269 }
270
271 String visitString(StringConstantValue constant, _) {
272 return '(String ${constant.unparse()})';
273 }
274
275 String visitList(ListConstantValue constant, _) {
276 return _failWith(constant);
277 }
278
279 String visitMap(MapConstantValue constant, _) {
280 return _failWith(constant);
281 }
282
283 String visitConstructed(ConstructedConstantValue constant, _) {
284 return _failWith(constant);
285 }
286
287 String visitType(TypeConstantValue constant, _) {
288 return _failWith(constant);
289 }
290
291 String visitInterceptor(InterceptorConstantValue constant, _) {
292 return _failWith(constant);
293 }
294
295 String visitDummy(DummyConstantValue constant, _) {
296 return _failWith(constant);
297 }
298
299 String visitDeferred(DeferredConstantValue constant, _) {
300 return _failWith(constant);
301 }
302 }
303
237 class _Namer { 304 class _Namer {
238 final Map<Node, String> _names = <Node, String>{}; 305 final Map<Node, String> _names = <Node, String>{};
239 int _valueCounter = 0; 306 int _valueCounter = 0;
240 int _continuationCounter = 0; 307 int _continuationCounter = 0;
241 308
242 String nameParameter(Parameter parameter) { 309 String nameParameter(Parameter parameter) {
243 assert(!_names.containsKey(parameter)); 310 assert(!_names.containsKey(parameter));
244 return _names[parameter] = parameter.hint.name; 311 return _names[parameter] = parameter.hint.name;
245 } 312 }
246 313
(...skipping 15 matching lines...) Expand all
262 void setReturnContinuation(Continuation node) { 329 void setReturnContinuation(Continuation node) {
263 assert(!_names.containsKey(node) || _names[node] == 'return'); 330 assert(!_names.containsKey(node) || _names[node] == 'return');
264 _names[node] = 'return'; 331 _names[node] = 'return';
265 } 332 }
266 333
267 String getName(Node node) { 334 String getName(Node node) {
268 assert(_names.containsKey(node)); 335 assert(_names.containsKey(node));
269 return _names[node]; 336 return _names[node];
270 } 337 }
271 } 338 }
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/test/sexpr_data.dart ('k') | tests/compiler/dart2js/backend_dart/opt_constprop_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698