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