| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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; |
| 6 | 6 |
| 7 abstract class NodeVisitor<T> { | 7 abstract class NodeVisitor<T> { |
| 8 T visitProgram(Program node); | 8 T visitProgram(Program node); |
| 9 | 9 |
| 10 T visitBlock(Block node); | 10 T visitBlock(Block node); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 T visitArrayInitializer(ArrayInitializer node); | 58 T visitArrayInitializer(ArrayInitializer node); |
| 59 T visitArrayElement(ArrayElement node); | 59 T visitArrayElement(ArrayElement node); |
| 60 T visitObjectInitializer(ObjectInitializer node); | 60 T visitObjectInitializer(ObjectInitializer node); |
| 61 T visitProperty(Property node); | 61 T visitProperty(Property node); |
| 62 T visitRegExpLiteral(RegExpLiteral node); | 62 T visitRegExpLiteral(RegExpLiteral node); |
| 63 | 63 |
| 64 T visitComment(Comment node); | 64 T visitComment(Comment node); |
| 65 | 65 |
| 66 T visitInterpolatedExpression(InterpolatedExpression node); | 66 T visitInterpolatedExpression(InterpolatedExpression node); |
| 67 T visitInterpolatedStatement(InterpolatedStatement node); |
| 67 T visitJSExpression(JSExpression node); | 68 T visitJSExpression(JSExpression node); |
| 68 } | 69 } |
| 69 | 70 |
| 70 class BaseVisitor<T> implements NodeVisitor<T> { | 71 class BaseVisitor<T> implements NodeVisitor<T> { |
| 71 T visitNode(Node node) { | 72 T visitNode(Node node) { |
| 72 node.visitChildren(this); | 73 node.visitChildren(this); |
| 73 return null; | 74 return null; |
| 74 } | 75 } |
| 75 | 76 |
| 76 T visitProgram(Program node) => visitNode(node); | 77 T visitProgram(Program node) => visitNode(node); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 T visitLiteralNull(LiteralNull node) => visitLiteral(node); | 145 T visitLiteralNull(LiteralNull node) => visitLiteral(node); |
| 145 | 146 |
| 146 T visitArrayInitializer(ArrayInitializer node) => visitExpression(node); | 147 T visitArrayInitializer(ArrayInitializer node) => visitExpression(node); |
| 147 T visitArrayElement(ArrayElement node) => visitNode(node); | 148 T visitArrayElement(ArrayElement node) => visitNode(node); |
| 148 T visitObjectInitializer(ObjectInitializer node) => visitExpression(node); | 149 T visitObjectInitializer(ObjectInitializer node) => visitExpression(node); |
| 149 T visitProperty(Property node) => visitNode(node); | 150 T visitProperty(Property node) => visitNode(node); |
| 150 T visitRegExpLiteral(RegExpLiteral node) => visitExpression(node); | 151 T visitRegExpLiteral(RegExpLiteral node) => visitExpression(node); |
| 151 | 152 |
| 152 T visitInterpolatedExpression(InterpolatedExpression node) | 153 T visitInterpolatedExpression(InterpolatedExpression node) |
| 153 => visitExpression(node); | 154 => visitExpression(node); |
| 155 T visitInterpolatedStatement(InterpolatedStatement node) |
| 156 => visitStatement(node); |
| 154 T visitJSExpression(JSExpression node) => visitExpression(node); | 157 T visitJSExpression(JSExpression node) => visitExpression(node); |
| 155 | 158 |
| 156 // Ignore comments by default. | 159 // Ignore comments by default. |
| 157 T visitComment(Comment node) => null; | 160 T visitComment(Comment node) => null; |
| 158 } | 161 } |
| 159 | 162 |
| 160 abstract class Node { | 163 abstract class Node { |
| 161 var sourcePosition; | 164 var sourcePosition; |
| 162 var endSourcePosition; | 165 var endSourcePosition; |
| 163 | 166 |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 Property(this.name, this.value); | 945 Property(this.name, this.value); |
| 943 | 946 |
| 944 accept(NodeVisitor visitor) => visitor.visitProperty(this); | 947 accept(NodeVisitor visitor) => visitor.visitProperty(this); |
| 945 | 948 |
| 946 void visitChildren(NodeVisitor visitor) { | 949 void visitChildren(NodeVisitor visitor) { |
| 947 name.accept(visitor); | 950 name.accept(visitor); |
| 948 value.accept(visitor); | 951 value.accept(visitor); |
| 949 } | 952 } |
| 950 } | 953 } |
| 951 | 954 |
| 952 class InterpolatedExpression extends Expression { | 955 /// Tag class for all interpolated positions. |
| 956 abstract class InterpolatedNode implements Node {} |
| 957 |
| 958 class InterpolatedExpression extends Expression implements InterpolatedNode { |
| 953 Expression value; | 959 Expression value; |
| 954 | 960 |
| 955 InterpolatedExpression(this.value); | 961 InterpolatedExpression(this.value); |
| 956 | 962 |
| 963 void assign(Expression newValue) { |
| 964 value = newValue; |
| 965 } |
| 966 |
| 957 accept(NodeVisitor visitor) => visitor.visitInterpolatedExpression(this); | 967 accept(NodeVisitor visitor) => visitor.visitInterpolatedExpression(this); |
| 958 | 968 |
| 959 void visitChildren(NodeVisitor visitor) { | 969 void visitChildren(NodeVisitor visitor) { |
| 960 if (value != null) value.accept(visitor); | 970 if (value != null) value.accept(visitor); |
| 961 } | 971 } |
| 962 | 972 |
| 963 int get precedenceLevel => value.precedenceLevel; | 973 int get precedenceLevel => value.precedenceLevel; |
| 964 } | 974 } |
| 965 | 975 |
| 976 class InterpolatedStatement extends Statement implements InterpolatedNode { |
| 977 Statement value; |
| 978 |
| 979 InterpolatedStatement(this.value); |
| 980 |
| 981 void assign(Node newValue) { |
| 982 if (newValue is Expression) |
| 983 value = new ExpressionStatement(newValue); |
| 984 else |
| 985 value = newValue; |
| 986 } |
| 987 |
| 988 accept(NodeVisitor visitor) => visitor.visitInterpolatedStatement(this); |
| 989 |
| 990 void visitChildren(NodeVisitor visitor) { |
| 991 if (value != null) value.accept(visitor); |
| 992 } |
| 993 } |
| 994 |
| 966 class JSExpression extends Expression { | 995 class JSExpression extends Expression { |
| 967 Expression value; | 996 Expression value; |
| 968 List<InterpolatedExpression> interpolatedExpressions; | 997 List<InterpolatedNode> interpolatedNodes; |
| 969 | 998 |
| 970 JSExpression(this.value, this.interpolatedExpressions); | 999 JSExpression(this.value, this.interpolatedNodes); |
| 971 | 1000 |
| 972 accept(NodeVisitor visitor) => visitor.visitJSExpression(this); | 1001 accept(NodeVisitor visitor) => visitor.visitJSExpression(this); |
| 973 | 1002 |
| 974 void visitChildren(NodeVisitor visitor) { | 1003 void visitChildren(NodeVisitor visitor) { |
| 975 value.accept(visitor); | 1004 value.accept(visitor); |
| 976 for (InterpolatedExpression expression in interpolatedExpressions) { | 1005 for (InterpolatedNode node in interpolatedNodes) { |
| 977 expression.accept(visitor); | 1006 node.accept(visitor); |
| 978 } | 1007 } |
| 979 } | 1008 } |
| 980 | 1009 |
| 981 int get precedenceLevel => value.precedenceLevel; | 1010 int get precedenceLevel => value.precedenceLevel; |
| 982 } | 1011 } |
| 983 | 1012 |
| 1013 // TODO(sra): JSStatement like JSExpression. |
| 1014 |
| 984 /** | 1015 /** |
| 985 * [RegExpLiteral]s, despite being called "Literal", do not inherit from | 1016 * [RegExpLiteral]s, despite being called "Literal", do not inherit from |
| 986 * [Literal]. Indeed, regular expressions in JavaScript have a side-effect and | 1017 * [Literal]. Indeed, regular expressions in JavaScript have a side-effect and |
| 987 * are thus not in the same category as numbers or strings. | 1018 * are thus not in the same category as numbers or strings. |
| 988 */ | 1019 */ |
| 989 class RegExpLiteral extends Expression { | 1020 class RegExpLiteral extends Expression { |
| 990 /** Contains the pattern and the flags.*/ | 1021 /** Contains the pattern and the flags.*/ |
| 991 String pattern; | 1022 String pattern; |
| 992 | 1023 |
| 993 RegExpLiteral(this.pattern); | 1024 RegExpLiteral(this.pattern); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1006 */ | 1037 */ |
| 1007 class Comment extends Statement { | 1038 class Comment extends Statement { |
| 1008 final String comment; | 1039 final String comment; |
| 1009 | 1040 |
| 1010 Comment(this.comment); | 1041 Comment(this.comment); |
| 1011 | 1042 |
| 1012 accept(NodeVisitor visitor) => visitor.visitComment(this); | 1043 accept(NodeVisitor visitor) => visitor.visitComment(this); |
| 1013 | 1044 |
| 1014 void visitChildren(NodeVisitor visitor) {} | 1045 void visitChildren(NodeVisitor visitor) {} |
| 1015 } | 1046 } |
| OLD | NEW |