| 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 dart_tree_printer; | 5 library dart_tree_printer; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../constants/values.dart' as values; | 8 import '../constants/values.dart' as values; |
| 9 import '../dart_types.dart' as types; | 9 import '../dart_types.dart' as types; |
| 10 import '../elements/elements.dart' as elements; | 10 import '../elements/elements.dart' as elements; |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 tree.NodeList parameters = makeParameters(exp.parameters); | 488 tree.NodeList parameters = makeParameters(exp.parameters); |
| 489 tree.NodeList initializers = | 489 tree.NodeList initializers = |
| 490 exp.initializers == null || exp.initializers.isEmpty | 490 exp.initializers == null || exp.initializers.isEmpty |
| 491 ? null | 491 ? null |
| 492 : makeList(",", exp.initializers.map(makeExpression).toList()); | 492 : makeList(",", exp.initializers.map(makeExpression).toList()); |
| 493 tree.Node body = exp.isConst || exp.body == null | 493 tree.Node body = exp.isConst || exp.body == null |
| 494 ? new tree.EmptyStatement(semicolon) | 494 ? new tree.EmptyStatement(semicolon) |
| 495 : makeFunctionBody(exp.body); | 495 : makeFunctionBody(exp.body); |
| 496 result = new tree.FunctionExpression( | 496 result = new tree.FunctionExpression( |
| 497 constructorName(exp), | 497 constructorName(exp), |
| 498 // TODO(eernst): retrieve and pass the actual type variables. |
| 499 null, // typeVariables |
| 498 parameters, | 500 parameters, |
| 499 body, | 501 body, |
| 500 null, // return type | 502 null, // return type |
| 501 makeFunctionModifiers(exp), | 503 makeFunctionModifiers(exp), |
| 502 initializers, | 504 initializers, |
| 503 null, // get/set | 505 null, // get/set |
| 504 null); // async modifier | 506 null); // async modifier |
| 505 setElement(result, exp.element, exp); | 507 setElement(result, exp.element, exp); |
| 506 } else if (exp is FunctionExpression) { | 508 } else if (exp is FunctionExpression) { |
| 507 precedence = PRIMARY; | 509 precedence = PRIMARY; |
| 508 if (beginStmt && exp.name != null) { | 510 if (beginStmt && exp.name != null) { |
| 509 needParen = true; // Do not mistake for function declaration. | 511 needParen = true; // Do not mistake for function declaration. |
| 510 } | 512 } |
| 511 Token getOrSet = exp.isGetter ? getToken : exp.isSetter ? setToken : null; | 513 Token getOrSet = exp.isGetter ? getToken : exp.isSetter ? setToken : null; |
| 512 tree.NodeList parameters = | 514 tree.NodeList parameters = |
| 513 exp.isGetter ? makeList("", []) : makeParameters(exp.parameters); | 515 exp.isGetter ? makeList("", []) : makeParameters(exp.parameters); |
| 514 tree.Node body = makeFunctionBody(exp.body); | 516 tree.Node body = makeFunctionBody(exp.body); |
| 515 result = new tree.FunctionExpression( | 517 result = new tree.FunctionExpression( |
| 516 functionName(exp), | 518 functionName(exp), |
| 519 // TODO(eernst): retrieve and pass the actual type variables. |
| 520 null, // typeVariables |
| 517 parameters, | 521 parameters, |
| 518 body, | 522 body, |
| 519 exp.returnType == null || exp.element.isConstructor | 523 exp.returnType == null || exp.element.isConstructor |
| 520 ? null | 524 ? null |
| 521 : makeType(exp.returnType), | 525 : makeType(exp.returnType), |
| 522 makeFunctionModifiers(exp), | 526 makeFunctionModifiers(exp), |
| 523 null, // initializers | 527 null, // initializers |
| 524 getOrSet, // get/set | 528 getOrSet, // get/set |
| 525 null); // async modifier | 529 null); // async modifier |
| 526 elements.Element element = exp.element; | 530 elements.Element element = exp.element; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 if (stmt.leftHandValue is Identifier) { | 795 if (stmt.leftHandValue is Identifier) { |
| 792 left = makeExpression(stmt.leftHandValue); | 796 left = makeExpression(stmt.leftHandValue); |
| 793 } else { | 797 } else { |
| 794 left = makeVariableDeclarations(stmt.leftHandValue); | 798 left = makeVariableDeclarations(stmt.leftHandValue); |
| 795 } | 799 } |
| 796 return new tree.SyncForIn(left, makeExpression(stmt.expression), | 800 return new tree.SyncForIn(left, makeExpression(stmt.expression), |
| 797 makeStatement(stmt.body, shortIf: shortIf), forToken, inToken); | 801 makeStatement(stmt.body, shortIf: shortIf), forToken, inToken); |
| 798 } else if (stmt is FunctionDeclaration) { | 802 } else if (stmt is FunctionDeclaration) { |
| 799 tree.FunctionExpression function = new tree.FunctionExpression( | 803 tree.FunctionExpression function = new tree.FunctionExpression( |
| 800 stmt.name != null ? makeIdentifier(stmt.name) : null, | 804 stmt.name != null ? makeIdentifier(stmt.name) : null, |
| 805 // TODO(eernst): retrieve and pass the actual type variables. |
| 806 null, // typeVariables |
| 801 makeParameters(stmt.parameters), | 807 makeParameters(stmt.parameters), |
| 802 makeFunctionBody(stmt.body), | 808 makeFunctionBody(stmt.body), |
| 803 stmt.returnType != null ? makeType(stmt.returnType) : null, | 809 stmt.returnType != null ? makeType(stmt.returnType) : null, |
| 804 makeEmptyModifiers(), | 810 makeEmptyModifiers(), |
| 805 null, // initializers | 811 null, // initializers |
| 806 null, // get/set | 812 null, // get/set |
| 807 null); // async modifier | 813 null); // async modifier |
| 808 setElement(function, stmt.function.element, stmt); | 814 setElement(function, stmt.function.element, stmt); |
| 809 return new tree.FunctionDeclaration(function); | 815 return new tree.FunctionDeclaration(function); |
| 810 } else if (stmt is If) { | 816 } else if (stmt is If) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 nodes.add(new tree.NodeList(open, makeLink(opt), close, ',')); | 964 nodes.add(new tree.NodeList(open, makeLink(opt), close, ',')); |
| 959 } | 965 } |
| 960 return argList(nodes); | 966 return argList(nodes); |
| 961 } | 967 } |
| 962 | 968 |
| 963 /// [assignOperator] is used for writing the default value. | 969 /// [assignOperator] is used for writing the default value. |
| 964 tree.Node makeParameter(Parameter param, [Token assignOperator]) { | 970 tree.Node makeParameter(Parameter param, [Token assignOperator]) { |
| 965 if (param.isFunction) { | 971 if (param.isFunction) { |
| 966 tree.Node definition = new tree.FunctionExpression( | 972 tree.Node definition = new tree.FunctionExpression( |
| 967 makeIdentifier(param.name), | 973 makeIdentifier(param.name), |
| 974 // TODO(eernst): retrieve and pass the actual type variables. |
| 975 null, // typeVariables |
| 968 makeParameters(param.parameters), | 976 makeParameters(param.parameters), |
| 969 null, // body | 977 null, // body |
| 970 param.type == null ? null : makeType(param.type), | 978 param.type == null ? null : makeType(param.type), |
| 971 makeEmptyModifiers(), // TODO: Function parameter modifiers? | 979 makeEmptyModifiers(), // TODO: Function parameter modifiers? |
| 972 null, // initializers | 980 null, // initializers |
| 973 null, // get/set | 981 null, // get/set |
| 974 null); // async modifier | 982 null); // async modifier |
| 975 if (param.element != null) { | 983 if (param.element != null) { |
| 976 setElement(definition, param.element, param); | 984 setElement(definition, param.element, param); |
| 977 } | 985 } |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 if (chunk.previous != null) { | 1340 if (chunk.previous != null) { |
| 1333 return new tree.StringJuxtaposition( | 1341 return new tree.StringJuxtaposition( |
| 1334 printStringChunk(chunk.previous), node); | 1342 printStringChunk(chunk.previous), node); |
| 1335 } else { | 1343 } else { |
| 1336 return node; | 1344 return node; |
| 1337 } | 1345 } |
| 1338 } | 1346 } |
| 1339 return printStringChunk(output.chunk); | 1347 return printStringChunk(output.chunk); |
| 1340 } | 1348 } |
| 1341 } | 1349 } |
| OLD | NEW |