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 part of js; | 5 part of js_ast; |
6 | 6 |
7 class TemplateManager { | 7 class TemplateManager { |
8 Map<String, Template> expressionTemplates = new Map<String, Template>(); | 8 Map<String, Template> expressionTemplates = new Map<String, Template>(); |
9 Map<String, Template> statementTemplates = new Map<String, Template>(); | 9 Map<String, Template> statementTemplates = new Map<String, Template>(); |
10 | 10 |
11 TemplateManager(); | 11 TemplateManager(); |
12 | 12 |
13 | 13 |
14 Template lookupExpressionTemplate(String source) { | 14 Template lookupExpressionTemplate(String source) { |
15 return expressionTemplates[source]; | 15 return expressionTemplates[source]; |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 new FunctionDeclaration(makeName(arguments), makeFunction(arguments)); | 492 new FunctionDeclaration(makeName(arguments), makeFunction(arguments)); |
493 } | 493 } |
494 | 494 |
495 Instantiator visitLabeledStatement(LabeledStatement node) { | 495 Instantiator visitLabeledStatement(LabeledStatement node) { |
496 Instantiator makeBody = visit(node.body); | 496 Instantiator makeBody = visit(node.body); |
497 return (arguments) => new LabeledStatement(node.label, makeBody(arguments)); | 497 return (arguments) => new LabeledStatement(node.label, makeBody(arguments)); |
498 } | 498 } |
499 | 499 |
500 Instantiator visitLiteralStatement(LiteralStatement node) => | 500 Instantiator visitLiteralStatement(LiteralStatement node) => |
501 TODO('visitLiteralStatement'); | 501 TODO('visitLiteralStatement'); |
502 Instantiator visitBlob(Blob node) => | |
503 TODO('visitBlob'); | |
504 Instantiator visitLiteralExpression(LiteralExpression node) => | 502 Instantiator visitLiteralExpression(LiteralExpression node) => |
505 TODO('visitLiteralExpression'); | 503 TODO('visitLiteralExpression'); |
506 | 504 |
507 Instantiator visitVariableDeclarationList(VariableDeclarationList node) { | 505 Instantiator visitVariableDeclarationList(VariableDeclarationList node) { |
508 List<Instantiator> declarationMakers = | 506 List<Instantiator> declarationMakers = |
509 node.declarations.map(visit).toList(); | 507 node.declarations.map(visit).toList(); |
510 return (arguments) { | 508 return (arguments) { |
511 List<VariableInitialization> declarations = <VariableInitialization>[]; | 509 List<VariableInitialization> declarations = <VariableInitialization>[]; |
512 for (Instantiator instantiator in declarationMakers) { | 510 for (Instantiator instantiator in declarationMakers) { |
513 var result = instantiator(arguments); | 511 var result = instantiator(arguments); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 | 700 |
703 Instantiator visitAwait(Await node) { | 701 Instantiator visitAwait(Await node) { |
704 Instantiator makeExpression = visit(node.expression); | 702 Instantiator makeExpression = visit(node.expression); |
705 return (arguments) { | 703 return (arguments) { |
706 return new Await(makeExpression(arguments)); | 704 return new Await(makeExpression(arguments)); |
707 }; | 705 }; |
708 } | 706 } |
709 } | 707 } |
710 | 708 |
711 /** | 709 /** |
712 * InterpolatedNodeAnalysis extract [InterpolatedNode]s from AST. | 710 * InterpolatedNodeAnalysis determines which AST trees contain |
| 711 * [InterpolatedNode]s, and the names of the named interpolated nodes. |
713 */ | 712 */ |
714 class InterpolatedNodeAnalysis extends BaseVisitor { | 713 class InterpolatedNodeAnalysis extends BaseVisitor { |
715 final Setlet<Node> containsInterpolatedNode = new Setlet<Node>(); | 714 final Set<Node> containsInterpolatedNode = new Set<Node>(); |
716 final List<InterpolatedNode> interpolatedNodes = <InterpolatedNode>[]; | 715 final Set<String> holeNames = new Set<String>(); |
717 final Setlet<String> holeNames = new Setlet<String>(); | |
718 int count = 0; | 716 int count = 0; |
719 | 717 |
720 InterpolatedNodeAnalysis(); | 718 InterpolatedNodeAnalysis(); |
721 | 719 |
722 bool containsInterpolatedNodes(Node node) => | 720 bool containsInterpolatedNodes(Node node) => |
723 containsInterpolatedNode.contains(node); | 721 containsInterpolatedNode.contains(node); |
724 | 722 |
725 void visit(Node node) { | 723 void visit(Node node) { |
726 node.accept(this); | 724 node.accept(this); |
727 } | 725 } |
728 | 726 |
729 void visitNode(Node node) { | 727 void visitNode(Node node) { |
730 int before = count; | 728 int before = count; |
731 node.visitChildren(this); | 729 node.visitChildren(this); |
732 if (count != before) containsInterpolatedNode.add(node); | 730 if (count != before) containsInterpolatedNode.add(node); |
733 return null; | 731 return null; |
734 } | 732 } |
735 | 733 |
736 visitInterpolatedNode(InterpolatedNode node) { | 734 visitInterpolatedNode(InterpolatedNode node) { |
737 interpolatedNodes.add(node); | |
738 containsInterpolatedNode.add(node); | 735 containsInterpolatedNode.add(node); |
739 if (node.isNamed) holeNames.add(node.nameOrPosition); | 736 if (node.isNamed) holeNames.add(node.nameOrPosition); |
740 ++count; | 737 ++count; |
741 } | 738 } |
742 } | 739 } |
OLD | NEW |