| 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 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 /** Bit pattern to easy check what modifiers are present. */ | 1068 /** Bit pattern to easy check what modifiers are present. */ |
| 1069 final int flags; | 1069 final int flags; |
| 1070 | 1070 |
| 1071 static final int FLAG_STATIC = 1; | 1071 static final int FLAG_STATIC = 1; |
| 1072 static final int FLAG_ABSTRACT = FLAG_STATIC << 1; | 1072 static final int FLAG_ABSTRACT = FLAG_STATIC << 1; |
| 1073 static final int FLAG_FINAL = FLAG_ABSTRACT << 1; | 1073 static final int FLAG_FINAL = FLAG_ABSTRACT << 1; |
| 1074 static final int FLAG_VAR = FLAG_FINAL << 1; | 1074 static final int FLAG_VAR = FLAG_FINAL << 1; |
| 1075 static final int FLAG_CONST = FLAG_VAR << 1; | 1075 static final int FLAG_CONST = FLAG_VAR << 1; |
| 1076 static final int FLAG_FACTORY = FLAG_CONST << 1; | 1076 static final int FLAG_FACTORY = FLAG_CONST << 1; |
| 1077 | 1077 |
| 1078 Modifiers(NodeList nodes) | 1078 Modifiers(NodeList nodes) : this.withFlags(nodes, computeFlags(nodes.nodes)); |
| 1079 : this.nodes = nodes, flags = computeFlags(nodes.nodes); | |
| 1080 | 1079 |
| 1081 Modifiers.empty() : this(new NodeList.empty()); | 1080 Modifiers.empty() : this(new NodeList.empty()); |
| 1082 | 1081 |
| 1082 Modifiers.withFlags(this.nodes, this.flags); |
| 1083 |
| 1083 static int computeFlags(Link<Node> nodes) { | 1084 static int computeFlags(Link<Node> nodes) { |
| 1084 int flags = 0; | 1085 int flags = 0; |
| 1085 for (; !nodes.isEmpty(); nodes = nodes.tail) { | 1086 for (; !nodes.isEmpty(); nodes = nodes.tail) { |
| 1086 String value = nodes.head.asIdentifier().source.stringValue; | 1087 String value = nodes.head.asIdentifier().source.stringValue; |
| 1087 if (value === 'static') flags += FLAG_STATIC; | 1088 if (value === 'static') flags += FLAG_STATIC; |
| 1088 else if (value === 'abstract') flags += FLAG_ABSTRACT; | 1089 else if (value === 'abstract') flags += FLAG_ABSTRACT; |
| 1089 else if (value === 'final') flags += FLAG_FINAL; | 1090 else if (value === 'final') flags += FLAG_FINAL; |
| 1090 else if (value === 'var') flags += FLAG_VAR; | 1091 else if (value === 'var') flags += FLAG_VAR; |
| 1091 else if (value === 'const') flags += FLAG_CONST; | 1092 else if (value === 'const') flags += FLAG_CONST; |
| 1092 else if (value === 'factory') flags += FLAG_FACTORY; | 1093 else if (value === 'factory') flags += FLAG_FACTORY; |
| 1093 else throw 'internal error: ${nodes.head}'; | 1094 else throw 'internal error: ${nodes.head}'; |
| 1094 } | 1095 } |
| 1095 return flags; | 1096 return flags; |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1098 Modifiers asModifiers() => this; | 1099 Modifiers asModifiers() => this; |
| 1099 Token getBeginToken() => nodes.getBeginToken(); | 1100 Token getBeginToken() => nodes.getBeginToken(); |
| 1100 Token getEndToken() => nodes.getEndToken(); | 1101 Token getEndToken() => nodes.getEndToken(); |
| 1101 accept(Visitor visitor) => visitor.visitModifiers(this); | 1102 accept(Visitor visitor) => visitor.visitModifiers(this); |
| 1102 visitChildren(Visitor visitor) => nodes.accept(visitor); | 1103 visitChildren(Visitor visitor) => nodes.accept(visitor); |
| 1103 | 1104 |
| 1104 bool isStatic() => (flags & FLAG_STATIC) != 0; | 1105 bool isStatic() => (flags & FLAG_STATIC) != 0; |
| 1105 bool isAbstract() => (flags & FLAG_ABSTRACT) != 0; | 1106 bool isAbstract() => (flags & FLAG_ABSTRACT) != 0; |
| 1106 bool isFinal() => (flags & FLAG_FINAL) != 0; | 1107 bool isFinal() => (flags & FLAG_FINAL) != 0; |
| 1107 bool isVar() => (flags & FLAG_VAR) != 0; | 1108 bool isVar() => (flags & FLAG_VAR) != 0; |
| 1108 bool isConst() => (flags & FLAG_CONST) != 0; | 1109 bool isConst() => (flags & FLAG_CONST) != 0; |
| 1109 bool isFactory() => (flags & FLAG_FACTORY) != 0; | 1110 bool isFactory() => (flags & FLAG_FACTORY) != 0; |
| 1111 |
| 1112 String toString() { |
| 1113 LinkBuilder<String> builder = new LinkBuilder<String>(); |
| 1114 if (isStatic()) builder.addLast('static'); |
| 1115 if (isAbstract()) builder.addLast('abstract'); |
| 1116 if (isFinal()) builder.addLast('final'); |
| 1117 if (isVar()) builder.addLast('var'); |
| 1118 if (isConst()) builder.addLast('const'); |
| 1119 if (isFactory()) builder.addLast('factory'); |
| 1120 StringBuffer buffer = new StringBuffer(); |
| 1121 builder.toLink().printOn(buffer, ', '); |
| 1122 return buffer.toString(); |
| 1123 } |
| 1110 } | 1124 } |
| 1111 | 1125 |
| 1112 class StringInterpolation extends StringNode { | 1126 class StringInterpolation extends StringNode { |
| 1113 final LiteralString string; | 1127 final LiteralString string; |
| 1114 final NodeList parts; | 1128 final NodeList parts; |
| 1115 | 1129 |
| 1116 StringInterpolation(this.string, this.parts); | 1130 StringInterpolation(this.string, this.parts); |
| 1117 | 1131 |
| 1118 StringInterpolation asStringInterpolation() => this; | 1132 StringInterpolation asStringInterpolation() => this; |
| 1119 | 1133 |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1706 * argument). | 1720 * argument). |
| 1707 * | 1721 * |
| 1708 * TODO(ahe): This method is controversial, the team needs to discuss | 1722 * TODO(ahe): This method is controversial, the team needs to discuss |
| 1709 * if top-level methods are acceptable and what naming conventions to | 1723 * if top-level methods are acceptable and what naming conventions to |
| 1710 * use. | 1724 * use. |
| 1711 */ | 1725 */ |
| 1712 initializerDo(Node node, f(Node node)) { | 1726 initializerDo(Node node, f(Node node)) { |
| 1713 SendSet send = node.asSendSet(); | 1727 SendSet send = node.asSendSet(); |
| 1714 if (send !== null) return f(send.arguments.head); | 1728 if (send !== null) return f(send.arguments.head); |
| 1715 } | 1729 } |
| OLD | NEW |