| OLD | NEW |
| 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 '../constants/values.dart'; |
| 8 import '../util/util.dart'; | 8 import '../util/util.dart'; |
| 9 import 'cps_ir_nodes.dart'; | 9 import 'cps_ir_nodes.dart'; |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 String access(Reference<Definition> r) { | 29 String access(Reference<Definition> r) { |
| 30 return decorator(r.definition, namer.getName(r.definition)); | 30 return decorator(r.definition, namer.getName(r.definition)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 String visitParameter(Parameter node) { | 33 String visitParameter(Parameter node) { |
| 34 return namer.nameParameter(node); | 34 return namer.nameParameter(node); |
| 35 } | 35 } |
| 36 | 36 |
| 37 String visitClosureVariable(ClosureVariable node) { | 37 String visitClosureVariable(ClosureVariable node) { |
| 38 return namer.getName(node); | 38 return namer.nameClosureVariable(node); |
| 39 } | 39 } |
| 40 | 40 |
| 41 /// Main entry point for creating a [String] from a [Node]. All recursive | 41 /// Main entry point for creating a [String] from a [Node]. All recursive |
| 42 /// calls must go through this method. | 42 /// calls must go through this method. |
| 43 String visit(Node node) { | 43 String visit(Node node) { |
| 44 String s = super.visit(node); | 44 String s = super.visit(node); |
| 45 return decorator(node, s); | 45 return decorator(node, s); |
| 46 } | 46 } |
| 47 | 47 |
| 48 String visitFunctionDefinition(FunctionDefinition node) { | 48 String visitFunctionDefinition(FunctionDefinition node) { |
| 49 String name = node.element.name; | 49 String name = node.element.name; |
| 50 namer.setReturnContinuation(node.body.returnContinuation); | 50 namer.setReturnContinuation(node.body.returnContinuation); |
| 51 String closureVariables = | |
| 52 node.closureVariables.map(namer.nameClosureVariable).join(' '); | |
| 53 String parameters = node.parameters.map(visit).join(' '); | 51 String parameters = node.parameters.map(visit).join(' '); |
| 54 String body = indentBlock(() => visit(node.body.body)); | 52 String body = indentBlock(() => visit(node.body.body)); |
| 55 return '$indentation(FunctionDefinition $name ($parameters) return' | 53 return '$indentation(FunctionDefinition $name ($parameters) return\n' |
| 56 ' ($closureVariables)\n$body)'; | 54 '$body)'; |
| 57 } | 55 } |
| 58 | 56 |
| 59 String visitFieldDefinition(FieldDefinition node) { | 57 String visitFieldDefinition(FieldDefinition node) { |
| 60 String name = node.element.name; | 58 String name = node.element.name; |
| 61 if (node.hasInitializer) { | 59 if (node.hasInitializer) { |
| 62 namer.setReturnContinuation(node.body.returnContinuation); | 60 namer.setReturnContinuation(node.body.returnContinuation); |
| 63 String body = indentBlock(() => visit(node.body.body)); | 61 String body = indentBlock(() => visit(node.body.body)); |
| 64 return '$indentation(FieldDefinition $name () return\n' | 62 return '$indentation(FieldDefinition $name () return\n' |
| 65 '$body)'; | 63 '$body)'; |
| 66 } else { | 64 } else { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 indentBlock(() => indentBlock(() => visit(node.definition))); | 188 indentBlock(() => indentBlock(() => visit(node.definition))); |
| 191 return '(CreateFunction\n$function)'; | 189 return '(CreateFunction\n$function)'; |
| 192 } | 190 } |
| 193 | 191 |
| 194 String visitContinuation(Continuation node) { | 192 String visitContinuation(Continuation node) { |
| 195 // Continuations are visited directly in visitLetCont. | 193 // Continuations are visited directly in visitLetCont. |
| 196 return '(Unexpected Continuation)'; | 194 return '(Unexpected Continuation)'; |
| 197 } | 195 } |
| 198 | 196 |
| 199 String visitGetClosureVariable(GetClosureVariable node) { | 197 String visitGetClosureVariable(GetClosureVariable node) { |
| 200 return '(GetClosureVariable ${visit(node.variable.definition)})'; | 198 namer.nameClosureVariableIfAbsent(node.variable.definition); |
| 199 return '(GetClosureVariable ${access(node.variable)})'; |
| 201 } | 200 } |
| 202 | 201 |
| 203 String visitSetClosureVariable(SetClosureVariable node) { | 202 String visitSetClosureVariable(SetClosureVariable node) { |
| 203 namer.nameClosureVariableIfAbsent(node.variable.definition); |
| 204 String value = access(node.value); | 204 String value = access(node.value); |
| 205 String body = indentBlock(() => visit(node.body)); | 205 String body = indentBlock(() => visit(node.body)); |
| 206 return '$indentation(SetClosureVariable ${visit(node.variable.definition)} ' | 206 return '$indentation(SetClosureVariable ${access(node.variable)} ' |
| 207 '$value\n$body)'; | 207 '$value\n$body)'; |
| 208 } | 208 } |
| 209 | 209 |
| 210 String visitTypeOperator(TypeOperator node) { | 210 String visitTypeOperator(TypeOperator node) { |
| 211 String receiver = access(node.receiver); | 211 String receiver = access(node.receiver); |
| 212 String cont = access(node.continuation); | 212 String cont = access(node.continuation); |
| 213 String operator = node.isTypeTest ? 'is' : 'as'; | 213 String operator = node.isTypeTest ? 'is' : 'as'; |
| 214 return '$indentation(TypeOperator $operator $receiver ${node.type} $cont)'; | 214 return '$indentation(TypeOperator $operator $receiver ${node.type} $cont)'; |
| 215 } | 215 } |
| 216 | 216 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 242 String visitSetField(SetField node) { | 242 String visitSetField(SetField node) { |
| 243 String object = access(node.object); | 243 String object = access(node.object); |
| 244 String field = node.field.name; | 244 String field = node.field.name; |
| 245 String value = access(node.value); | 245 String value = access(node.value); |
| 246 String body = indentBlock(() => visit(node.body)); | 246 String body = indentBlock(() => visit(node.body)); |
| 247 return '$indentation(SetField $object $field $value)\n$body'; | 247 return '$indentation(SetField $object $field $value)\n$body'; |
| 248 } | 248 } |
| 249 | 249 |
| 250 String visitGetField(GetField node) { | 250 String visitGetField(GetField node) { |
| 251 String object = access(node.object); | 251 String object = access(node.object); |
| 252 String field = node.field.toString(); | 252 String field = node.field.name; |
| 253 return '(GetField $object $field)'; | 253 return '(GetField $object $field)'; |
| 254 } | 254 } |
| 255 | 255 |
| 256 String visitCreateBox(CreateBox node) { | 256 String visitCreateBox(CreateBox node) { |
| 257 return '(CreateBox)'; | 257 return '(CreateBox)'; |
| 258 } | 258 } |
| 259 | 259 |
| 260 String visitCreateInstance(CreateInstance node) { | 260 String visitCreateInstance(CreateInstance node) { |
| 261 String className = node.classElement.name; | 261 String className = node.classElement.name; |
| 262 String arguments = node.arguments.map(access).join(' '); | 262 String arguments = node.arguments.map(access).join(' '); |
| 263 return '(CreateInstance $className ($arguments))'; | 263 return '(CreateInstance $className ($arguments))'; |
| 264 } | 264 } |
| 265 | 265 |
| 266 String visitIdentical(Identical node) { | 266 String visitIdentical(Identical node) { |
| 267 String left = access(node.left); | 267 String left = access(node.left); |
| 268 String right = access(node.right); | 268 String right = access(node.right); |
| 269 return '(Identical $left $right)'; | 269 return '(Identical $left $right)'; |
| 270 } | 270 } |
| 271 | 271 |
| 272 String visitInterceptor(Interceptor node) { | 272 String visitInterceptor(Interceptor node) { |
| 273 return '(Interceptor ${node.input})'; | 273 return '(Interceptor ${access(node.input)})'; |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 | 276 |
| 277 class ConstantStringifier extends ConstantValueVisitor<String, Null> { | 277 class ConstantStringifier extends ConstantValueVisitor<String, Null> { |
| 278 // Some of these methods are unimplemented because we haven't had a need | 278 // Some of these methods are unimplemented because we haven't had a need |
| 279 // to print such constants. When printing is implemented, the corresponding | 279 // to print such constants. When printing is implemented, the corresponding |
| 280 // parsing support should be added to SExpressionUnstringifier.parseConstant | 280 // parsing support should be added to SExpressionUnstringifier.parseConstant |
| 281 // in the dart2js tests (currently in the file | 281 // in the dart2js tests (currently in the file |
| 282 // tests/compiler/dart2js/backend_dart/sexpr_unstringifier.dart). | 282 // tests/compiler/dart2js/backend_dart/sexpr_unstringifier.dart). |
| 283 | 283 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 String nameParameter(Parameter parameter) { | 346 String nameParameter(Parameter parameter) { |
| 347 assert(!_names.containsKey(parameter)); | 347 assert(!_names.containsKey(parameter)); |
| 348 return _names[parameter] = parameter.hint.name; | 348 return _names[parameter] = parameter.hint.name; |
| 349 } | 349 } |
| 350 | 350 |
| 351 String nameClosureVariable(ClosureVariable variable) { | 351 String nameClosureVariable(ClosureVariable variable) { |
| 352 assert(!_names.containsKey(variable)); | 352 assert(!_names.containsKey(variable)); |
| 353 return _names[variable] = variable.hint.name; | 353 return _names[variable] = variable.hint.name; |
| 354 } | 354 } |
| 355 | 355 |
| 356 String nameClosureVariableIfAbsent(ClosureVariable variable) { |
| 357 if (!_names.containsKey(variable)) { |
| 358 _names[variable] = variable.hint.name; |
| 359 } |
| 360 } |
| 361 |
| 356 String nameContinuation(Continuation node) { | 362 String nameContinuation(Continuation node) { |
| 357 assert(!_names.containsKey(node)); | 363 assert(!_names.containsKey(node)); |
| 358 return _names[node] = 'k${_continuationCounter++}'; | 364 return _names[node] = 'k${_continuationCounter++}'; |
| 359 } | 365 } |
| 360 | 366 |
| 361 String nameValue(Primitive node) { | 367 String nameValue(Primitive node) { |
| 362 assert(!_names.containsKey(node)); | 368 assert(!_names.containsKey(node)); |
| 363 return _names[node] = 'v${_valueCounter++}'; | 369 return _names[node] = 'v${_valueCounter++}'; |
| 364 } | 370 } |
| 365 | 371 |
| 366 void setReturnContinuation(Continuation node) { | 372 void setReturnContinuation(Continuation node) { |
| 367 assert(!_names.containsKey(node) || _names[node] == 'return'); | 373 assert(!_names.containsKey(node) || _names[node] == 'return'); |
| 368 _names[node] = 'return'; | 374 _names[node] = 'return'; |
| 369 } | 375 } |
| 370 | 376 |
| 371 String getName(Node node) { | 377 String getName(Node node) { |
| 372 assert(_names.containsKey(node)); | 378 assert(_names.containsKey(node)); |
| 373 return _names[node]; | 379 return _names[node]; |
| 374 } | 380 } |
| 375 } | 381 } |
| OLD | NEW |