| 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 interface Visitor<R> { | 5 interface Visitor<R> { |
| 6 R visitBlock(Block node); | 6 R visitBlock(Block node); |
| 7 R visitBreakStatement(BreakStatement node); | 7 R visitBreakStatement(BreakStatement node); |
| 8 R visitCascade(Cascade node); | 8 R visitCascade(Cascade node); |
| 9 R visitCascadeReceiver(CascadeReceiver node); | 9 R visitCascadeReceiver(CascadeReceiver node); |
| 10 R visitCaseMatch(CaseMatch node); | 10 R visitCaseMatch(CaseMatch node); |
| (...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 Token getBeginToken() => beginToken; | 1074 Token getBeginToken() => beginToken; |
| 1075 | 1075 |
| 1076 Token getEndToken() => beginToken.endGroup; | 1076 Token getEndToken() => beginToken.endGroup; |
| 1077 } | 1077 } |
| 1078 | 1078 |
| 1079 /** Representation of modifiers such as static, abstract, final, etc. */ | 1079 /** Representation of modifiers such as static, abstract, final, etc. */ |
| 1080 class Modifiers extends Node { | 1080 class Modifiers extends Node { |
| 1081 /* TODO(ahe): The following should be validated relating to modifiers: | 1081 /* TODO(ahe): The following should be validated relating to modifiers: |
| 1082 * 1. The nodes must come in a certain order. | 1082 * 1. The nodes must come in a certain order. |
| 1083 * 2. The keywords "var" and "final" may not be used at the same time. | 1083 * 2. The keywords "var" and "final" may not be used at the same time. |
| 1084 * 3. The type of an element must be null if isVar() is true. | 1084 * 3. The keywords "abstract" and "external" may not be used at the same time. |
| 1085 * 4. The type of an element must be null if isVar() is true. |
| 1085 */ | 1086 */ |
| 1086 | 1087 |
| 1087 final NodeList nodes; | 1088 final NodeList nodes; |
| 1088 /** Bit pattern to easy check what modifiers are present. */ | 1089 /** Bit pattern to easy check what modifiers are present. */ |
| 1089 final int flags; | 1090 final int flags; |
| 1090 | 1091 |
| 1091 static final int FLAG_STATIC = 1; | 1092 static final int FLAG_STATIC = 1; |
| 1092 static final int FLAG_ABSTRACT = FLAG_STATIC << 1; | 1093 static final int FLAG_ABSTRACT = FLAG_STATIC << 1; |
| 1093 static final int FLAG_FINAL = FLAG_ABSTRACT << 1; | 1094 static final int FLAG_FINAL = FLAG_ABSTRACT << 1; |
| 1094 static final int FLAG_VAR = FLAG_FINAL << 1; | 1095 static final int FLAG_VAR = FLAG_FINAL << 1; |
| 1095 static final int FLAG_CONST = FLAG_VAR << 1; | 1096 static final int FLAG_CONST = FLAG_VAR << 1; |
| 1096 static final int FLAG_FACTORY = FLAG_CONST << 1; | 1097 static final int FLAG_FACTORY = FLAG_CONST << 1; |
| 1098 static final int FLAG_EXTERNAL = FLAG_FACTORY << 1; |
| 1097 | 1099 |
| 1098 Modifiers(NodeList nodes) : this.withFlags(nodes, computeFlags(nodes.nodes)); | 1100 Modifiers(NodeList nodes) : this.withFlags(nodes, computeFlags(nodes.nodes)); |
| 1099 | 1101 |
| 1100 Modifiers.empty() : this(new NodeList.empty()); | 1102 Modifiers.empty() : this(new NodeList.empty()); |
| 1101 | 1103 |
| 1102 Modifiers.withFlags(this.nodes, this.flags); | 1104 Modifiers.withFlags(this.nodes, this.flags); |
| 1103 | 1105 |
| 1104 static int computeFlags(Link<Node> nodes) { | 1106 static int computeFlags(Link<Node> nodes) { |
| 1105 int flags = 0; | 1107 int flags = 0; |
| 1106 for (; !nodes.isEmpty(); nodes = nodes.tail) { | 1108 for (; !nodes.isEmpty(); nodes = nodes.tail) { |
| 1107 String value = nodes.head.asIdentifier().source.stringValue; | 1109 String value = nodes.head.asIdentifier().source.stringValue; |
| 1108 if (value === 'static') flags += FLAG_STATIC; | 1110 if (value === 'static') flags |= FLAG_STATIC; |
| 1109 else if (value === 'abstract') flags += FLAG_ABSTRACT; | 1111 else if (value === 'abstract') flags |= FLAG_ABSTRACT; |
| 1110 else if (value === 'final') flags += FLAG_FINAL; | 1112 else if (value === 'final') flags |= FLAG_FINAL; |
| 1111 else if (value === 'var') flags += FLAG_VAR; | 1113 else if (value === 'var') flags |= FLAG_VAR; |
| 1112 else if (value === 'const') flags += FLAG_CONST; | 1114 else if (value === 'const') flags |= FLAG_CONST; |
| 1113 else if (value === 'factory') flags += FLAG_FACTORY; | 1115 else if (value === 'factory') flags |= FLAG_FACTORY; |
| 1116 else if (value === 'external') flags |= FLAG_EXTERNAL; |
| 1114 else throw 'internal error: ${nodes.head}'; | 1117 else throw 'internal error: ${nodes.head}'; |
| 1115 } | 1118 } |
| 1116 return flags; | 1119 return flags; |
| 1117 } | 1120 } |
| 1118 | 1121 |
| 1119 Modifiers asModifiers() => this; | 1122 Modifiers asModifiers() => this; |
| 1120 Token getBeginToken() => nodes.getBeginToken(); | 1123 Token getBeginToken() => nodes.getBeginToken(); |
| 1121 Token getEndToken() => nodes.getEndToken(); | 1124 Token getEndToken() => nodes.getEndToken(); |
| 1122 accept(Visitor visitor) => visitor.visitModifiers(this); | 1125 accept(Visitor visitor) => visitor.visitModifiers(this); |
| 1123 visitChildren(Visitor visitor) => nodes.accept(visitor); | 1126 visitChildren(Visitor visitor) => nodes.accept(visitor); |
| 1124 | 1127 |
| 1125 bool isStatic() => (flags & FLAG_STATIC) != 0; | 1128 bool isStatic() => (flags & FLAG_STATIC) != 0; |
| 1126 bool isAbstract() => (flags & FLAG_ABSTRACT) != 0; | 1129 bool isAbstract() => (flags & FLAG_ABSTRACT) != 0; |
| 1127 bool isFinal() => (flags & FLAG_FINAL) != 0; | 1130 bool isFinal() => (flags & FLAG_FINAL) != 0; |
| 1128 bool isVar() => (flags & FLAG_VAR) != 0; | 1131 bool isVar() => (flags & FLAG_VAR) != 0; |
| 1129 bool isConst() => (flags & FLAG_CONST) != 0; | 1132 bool isConst() => (flags & FLAG_CONST) != 0; |
| 1130 bool isFactory() => (flags & FLAG_FACTORY) != 0; | 1133 bool isFactory() => (flags & FLAG_FACTORY) != 0; |
| 1134 bool isExternal() => (flags & FLAG_EXTERNAL) != 0; |
| 1131 | 1135 |
| 1132 String toString() { | 1136 String toString() { |
| 1133 LinkBuilder<String> builder = new LinkBuilder<String>(); | 1137 LinkBuilder<String> builder = new LinkBuilder<String>(); |
| 1134 if (isStatic()) builder.addLast('static'); | 1138 if (isStatic()) builder.addLast('static'); |
| 1135 if (isAbstract()) builder.addLast('abstract'); | 1139 if (isAbstract()) builder.addLast('abstract'); |
| 1136 if (isFinal()) builder.addLast('final'); | 1140 if (isFinal()) builder.addLast('final'); |
| 1137 if (isVar()) builder.addLast('var'); | 1141 if (isVar()) builder.addLast('var'); |
| 1138 if (isConst()) builder.addLast('const'); | 1142 if (isConst()) builder.addLast('const'); |
| 1139 if (isFactory()) builder.addLast('factory'); | 1143 if (isFactory()) builder.addLast('factory'); |
| 1144 if (isExternal()) builder.addLast('external'); |
| 1140 StringBuffer buffer = new StringBuffer(); | 1145 StringBuffer buffer = new StringBuffer(); |
| 1141 builder.toLink().printOn(buffer, ', '); | 1146 builder.toLink().printOn(buffer, ', '); |
| 1142 return buffer.toString(); | 1147 return buffer.toString(); |
| 1143 } | 1148 } |
| 1144 } | 1149 } |
| 1145 | 1150 |
| 1146 class StringInterpolation extends StringNode { | 1151 class StringInterpolation extends StringNode { |
| 1147 final LiteralString string; | 1152 final LiteralString string; |
| 1148 final NodeList parts; | 1153 final NodeList parts; |
| 1149 | 1154 |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 * argument). | 1745 * argument). |
| 1741 * | 1746 * |
| 1742 * TODO(ahe): This method is controversial, the team needs to discuss | 1747 * TODO(ahe): This method is controversial, the team needs to discuss |
| 1743 * if top-level methods are acceptable and what naming conventions to | 1748 * if top-level methods are acceptable and what naming conventions to |
| 1744 * use. | 1749 * use. |
| 1745 */ | 1750 */ |
| 1746 initializerDo(Node node, f(Node node)) { | 1751 initializerDo(Node node, f(Node node)) { |
| 1747 SendSet send = node.asSendSet(); | 1752 SendSet send = node.asSendSet(); |
| 1748 if (send !== null) return f(send.arguments.head); | 1753 if (send !== null) return f(send.arguments.head); |
| 1749 } | 1754 } |
| OLD | NEW |