OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.clone; | 4 library kernel.clone; |
5 | 5 |
6 import 'ast.dart'; | 6 import 'ast.dart'; |
7 import 'type_algebra.dart'; | 7 import 'type_algebra.dart'; |
8 | 8 |
9 /// Visitor that return a clone of a tree, maintaining references to cloned | 9 /// Visitor that return a clone of a tree, maintaining references to cloned |
10 /// objects. | 10 /// objects. |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 fileUri: node.fileUri); | 367 fileUri: node.fileUri); |
368 } | 368 } |
369 | 369 |
370 visitTypeParameter(TypeParameter node) { | 370 visitTypeParameter(TypeParameter node) { |
371 var newNode = new TypeParameter(node.name); | 371 var newNode = new TypeParameter(node.name); |
372 typeSubstitution[node] = new TypeParameterType(newNode); | 372 typeSubstitution[node] = new TypeParameterType(newNode); |
373 newNode.bound = visitType(node.bound); | 373 newNode.bound = visitType(node.bound); |
374 return newNode; | 374 return newNode; |
375 } | 375 } |
376 | 376 |
| 377 TreeNode cloneFunctionNodeBody(FunctionNode node) => cloneOptional(node.body); |
| 378 |
377 visitFunctionNode(FunctionNode node) { | 379 visitFunctionNode(FunctionNode node) { |
378 var typeParameters = node.typeParameters.map(clone).toList(); | 380 var typeParameters = node.typeParameters.map(clone).toList(); |
379 var positional = node.positionalParameters.map(clone).toList(); | 381 var positional = node.positionalParameters.map(clone).toList(); |
380 var named = node.namedParameters.map(clone).toList(); | 382 var named = node.namedParameters.map(clone).toList(); |
381 return new FunctionNode(cloneOptional(node.body), | 383 return new FunctionNode(cloneFunctionNodeBody(node), |
382 typeParameters: typeParameters, | 384 typeParameters: typeParameters, |
383 positionalParameters: positional, | 385 positionalParameters: positional, |
384 namedParameters: named, | 386 namedParameters: named, |
385 requiredParameterCount: node.requiredParameterCount, | 387 requiredParameterCount: node.requiredParameterCount, |
386 returnType: visitType(node.returnType), | 388 returnType: visitType(node.returnType), |
387 asyncMarker: node.asyncMarker); | 389 asyncMarker: node.asyncMarker); |
388 } | 390 } |
389 | 391 |
390 visitArguments(Arguments node) { | 392 visitArguments(Arguments node) { |
391 return new Arguments(node.positional.map(clone).toList(), | 393 return new Arguments(node.positional.map(clone).toList(), |
392 types: node.types.map(visitType).toList(), | 394 types: node.types.map(visitType).toList(), |
393 named: node.named.map(clone).toList()); | 395 named: node.named.map(clone).toList()); |
394 } | 396 } |
395 | 397 |
396 visitNamedExpression(NamedExpression node) { | 398 visitNamedExpression(NamedExpression node) { |
397 return new NamedExpression(node.name, clone(node.value)); | 399 return new NamedExpression(node.name, clone(node.value)); |
398 } | 400 } |
399 } | 401 } |
OLD | NEW |