Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: lib/compiler/implementation/tree/nodes.dart

Issue 10996062: Use static final empty Modifier instead of null. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Missing uses fixed. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 abstract class Visitor<R> { 5 abstract class 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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 final NodeList parameters; 602 final NodeList parameters;
603 603
604 final Statement body; 604 final Statement body;
605 final TypeAnnotation returnType; 605 final TypeAnnotation returnType;
606 final Modifiers modifiers; 606 final Modifiers modifiers;
607 final NodeList initializers; 607 final NodeList initializers;
608 608
609 final Token getOrSet; 609 final Token getOrSet;
610 610
611 FunctionExpression(this.name, this.parameters, this.body, this.returnType, 611 FunctionExpression(this.name, this.parameters, this.body, this.returnType,
612 this.modifiers, this.initializers, this.getOrSet); 612 this.modifiers, this.initializers, this.getOrSet) {
613 assert(modifiers !== null);
614 }
613 615
614 FunctionExpression asFunctionExpression() => this; 616 FunctionExpression asFunctionExpression() => this;
615 617
616 accept(Visitor visitor) => visitor.visitFunctionExpression(this); 618 accept(Visitor visitor) => visitor.visitFunctionExpression(this);
617 619
618 visitChildren(Visitor visitor) { 620 visitChildren(Visitor visitor) {
619 if (modifiers !== null) modifiers.accept(visitor); 621 if (modifiers !== null) modifiers.accept(visitor);
620 if (returnType !== null) returnType.accept(visitor); 622 if (returnType !== null) returnType.accept(visitor);
621 if (name !== null) name.accept(visitor); 623 if (name !== null) name.accept(visitor);
622 if (parameters !== null) parameters.accept(visitor); 624 if (parameters !== null) parameters.accept(visitor);
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 return (bound !== null) ? bound.getEndToken() : name.getEndToken(); 989 return (bound !== null) ? bound.getEndToken() : name.getEndToken();
988 } 990 }
989 } 991 }
990 992
991 class VariableDefinitions extends Statement { 993 class VariableDefinitions extends Statement {
992 final Token endToken; 994 final Token endToken;
993 final TypeAnnotation type; 995 final TypeAnnotation type;
994 final Modifiers modifiers; 996 final Modifiers modifiers;
995 final NodeList definitions; 997 final NodeList definitions;
996 VariableDefinitions(this.type, this.modifiers, this.definitions, 998 VariableDefinitions(this.type, this.modifiers, this.definitions,
997 this.endToken); 999 this.endToken) {
1000 assert(modifiers !== null);
1001 }
998 1002
999 VariableDefinitions asVariableDefinitions() => this; 1003 VariableDefinitions asVariableDefinitions() => this;
1000 1004
1001 accept(Visitor visitor) => visitor.visitVariableDefinitions(this); 1005 accept(Visitor visitor) => visitor.visitVariableDefinitions(this);
1002 1006
1003 visitChildren(Visitor visitor) { 1007 visitChildren(Visitor visitor) {
1004 if (type !== null) type.accept(visitor); 1008 if (type !== null) type.accept(visitor);
1005 if (definitions !== null) definitions.accept(visitor); 1009 if (definitions !== null) definitions.accept(visitor);
1006 } 1010 }
1007 1011
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 if (expression !== null) expression.accept(visitor); 1090 if (expression !== null) expression.accept(visitor);
1087 } 1091 }
1088 1092
1089 Token getBeginToken() => beginToken; 1093 Token getBeginToken() => beginToken;
1090 1094
1091 Token getEndToken() => beginToken.endGroup; 1095 Token getEndToken() => beginToken.endGroup;
1092 } 1096 }
1093 1097
1094 /** Representation of modifiers such as static, abstract, final, etc. */ 1098 /** Representation of modifiers such as static, abstract, final, etc. */
1095 class Modifiers extends Node { 1099 class Modifiers extends Node {
1100 /**
1101 * Pseudo-constant for empty modifiers. Use this instead of null.
floitsch 2012/10/01 09:02:59 Remove "Use this instead of null".
Johnni Winther 2012/10/01 09:12:11 Why?
1102 */
1103 static final Modifiers EMPTY = new Modifiers(new NodeList.empty());
1104
1096 /* TODO(ahe): The following should be validated relating to modifiers: 1105 /* TODO(ahe): The following should be validated relating to modifiers:
1097 * 1. The nodes must come in a certain order. 1106 * 1. The nodes must come in a certain order.
1098 * 2. The keywords "var" and "final" may not be used at the same time. 1107 * 2. The keywords "var" and "final" may not be used at the same time.
1099 * 3. The keywords "abstract" and "external" may not be used at the same time. 1108 * 3. The keywords "abstract" and "external" may not be used at the same time.
1100 * 4. The type of an element must be null if isVar() is true. 1109 * 4. The type of an element must be null if isVar() is true.
1101 */ 1110 */
1102 1111
1103 final NodeList nodes; 1112 final NodeList nodes;
1104 /** Bit pattern to easy check what modifiers are present. */ 1113 /** Bit pattern to easy check what modifiers are present. */
1105 final int flags; 1114 final int flags;
1106 1115
1107 static const int FLAG_STATIC = 1; 1116 static const int FLAG_STATIC = 1;
1108 static const int FLAG_ABSTRACT = FLAG_STATIC << 1; 1117 static const int FLAG_ABSTRACT = FLAG_STATIC << 1;
1109 static const int FLAG_FINAL = FLAG_ABSTRACT << 1; 1118 static const int FLAG_FINAL = FLAG_ABSTRACT << 1;
1110 static const int FLAG_VAR = FLAG_FINAL << 1; 1119 static const int FLAG_VAR = FLAG_FINAL << 1;
1111 static const int FLAG_CONST = FLAG_VAR << 1; 1120 static const int FLAG_CONST = FLAG_VAR << 1;
1112 static const int FLAG_FACTORY = FLAG_CONST << 1; 1121 static const int FLAG_FACTORY = FLAG_CONST << 1;
1113 static const int FLAG_EXTERNAL = FLAG_FACTORY << 1; 1122 static const int FLAG_EXTERNAL = FLAG_FACTORY << 1;
1114 1123
1115 Modifiers(NodeList nodes) : this.withFlags(nodes, computeFlags(nodes.nodes)); 1124 Modifiers(NodeList nodes) : this.withFlags(nodes, computeFlags(nodes.nodes));
1116 1125
1117 Modifiers.empty() : this(new NodeList.empty());
1118
1119 Modifiers.withFlags(this.nodes, this.flags); 1126 Modifiers.withFlags(this.nodes, this.flags);
1120 1127
1121 static int computeFlags(Link<Node> nodes) { 1128 static int computeFlags(Link<Node> nodes) {
1122 int flags = 0; 1129 int flags = 0;
1123 for (; !nodes.isEmpty(); nodes = nodes.tail) { 1130 for (; !nodes.isEmpty(); nodes = nodes.tail) {
1124 String value = nodes.head.asIdentifier().source.stringValue; 1131 String value = nodes.head.asIdentifier().source.stringValue;
1125 if (value === 'static') flags |= FLAG_STATIC; 1132 if (value === 'static') flags |= FLAG_STATIC;
1126 else if (value === 'abstract') flags |= FLAG_ABSTRACT; 1133 else if (value === 'abstract') flags |= FLAG_ABSTRACT;
1127 else if (value === 'final') flags |= FLAG_FINAL; 1134 else if (value === 'final') flags |= FLAG_FINAL;
1128 else if (value === 'var') flags |= FLAG_VAR; 1135 else if (value === 'var') flags |= FLAG_VAR;
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 * argument). 1900 * argument).
1894 * 1901 *
1895 * TODO(ahe): This method is controversial, the team needs to discuss 1902 * TODO(ahe): This method is controversial, the team needs to discuss
1896 * if top-level methods are acceptable and what naming conventions to 1903 * if top-level methods are acceptable and what naming conventions to
1897 * use. 1904 * use.
1898 */ 1905 */
1899 initializerDo(Node node, f(Node node)) { 1906 initializerDo(Node node, f(Node node)) {
1900 SendSet send = node.asSendSet(); 1907 SendSet send = node.asSendSet();
1901 if (send !== null) return f(send.arguments.head); 1908 if (send !== null) return f(send.arguments.head);
1902 } 1909 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/ssa/optimize.dart ('k') | lib/compiler/implementation/tree/unparser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698