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

Side by Side Diff: pkg/js_ast/lib/src/nodes.dart

Issue 1153243003: dart2js: Use frequency of occurence to sort metadata indices. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Minor cleanups Created 5 years, 6 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
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 part of js_ast; 5 part of js_ast;
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 T visitVariableUse(VariableUse node); 43 T visitVariableUse(VariableUse node);
44 T visitThis(This node); 44 T visitThis(This node);
45 T visitVariableDeclaration(VariableDeclaration node); 45 T visitVariableDeclaration(VariableDeclaration node);
46 T visitParameter(Parameter node); 46 T visitParameter(Parameter node);
47 T visitAccess(PropertyAccess node); 47 T visitAccess(PropertyAccess node);
48 48
49 T visitNamedFunction(NamedFunction node); 49 T visitNamedFunction(NamedFunction node);
50 T visitFun(Fun node); 50 T visitFun(Fun node);
51 51
52 T visitDeferredExpression(DeferredExpression node);
53 T visitDeferredNumber(DeferredNumber node);
54 T visitDeferredString(DeferredString node);
55
52 T visitLiteralBool(LiteralBool node); 56 T visitLiteralBool(LiteralBool node);
53 T visitLiteralString(LiteralString node); 57 T visitLiteralString(LiteralString node);
54 T visitLiteralNumber(LiteralNumber node); 58 T visitLiteralNumber(LiteralNumber node);
55 T visitLiteralNull(LiteralNull node); 59 T visitLiteralNull(LiteralNull node);
56 60
61 T visitStringConcatenation(StringConcatenation node);
62
57 T visitArrayInitializer(ArrayInitializer node); 63 T visitArrayInitializer(ArrayInitializer node);
58 T visitArrayHole(ArrayHole node); 64 T visitArrayHole(ArrayHole node);
59 T visitObjectInitializer(ObjectInitializer node); 65 T visitObjectInitializer(ObjectInitializer node);
60 T visitProperty(Property node); 66 T visitProperty(Property node);
61 T visitRegExpLiteral(RegExpLiteral node); 67 T visitRegExpLiteral(RegExpLiteral node);
62 68
63 T visitAwait(Await node); 69 T visitAwait(Await node);
64 70
65 T visitComment(Comment node); 71 T visitComment(Comment node);
66 72
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 138
133 T visitVariableUse(VariableUse node) => visitVariableReference(node); 139 T visitVariableUse(VariableUse node) => visitVariableReference(node);
134 T visitVariableDeclaration(VariableDeclaration node) 140 T visitVariableDeclaration(VariableDeclaration node)
135 => visitVariableReference(node); 141 => visitVariableReference(node);
136 T visitParameter(Parameter node) => visitVariableDeclaration(node); 142 T visitParameter(Parameter node) => visitVariableDeclaration(node);
137 T visitThis(This node) => visitParameter(node); 143 T visitThis(This node) => visitParameter(node);
138 144
139 T visitNamedFunction(NamedFunction node) => visitExpression(node); 145 T visitNamedFunction(NamedFunction node) => visitExpression(node);
140 T visitFun(Fun node) => visitExpression(node); 146 T visitFun(Fun node) => visitExpression(node);
141 147
148 T visitToken(DeferredToken node) => visitExpression(node);
149
150 T visitDeferredExpression(DeferredExpression node) => visitExpression(node);
151 T visitDeferredNumber(DeferredNumber node) => visitToken(node);
152 T visitDeferredString(DeferredString node) => visitToken(node);
153
142 T visitLiteral(Literal node) => visitExpression(node); 154 T visitLiteral(Literal node) => visitExpression(node);
143 155
144 T visitLiteralBool(LiteralBool node) => visitLiteral(node); 156 T visitLiteralBool(LiteralBool node) => visitLiteral(node);
145 T visitLiteralString(LiteralString node) => visitLiteral(node); 157 T visitLiteralString(LiteralString node) => visitLiteral(node);
146 T visitLiteralNumber(LiteralNumber node) => visitLiteral(node); 158 T visitLiteralNumber(LiteralNumber node) => visitLiteral(node);
147 T visitLiteralNull(LiteralNull node) => visitLiteral(node); 159 T visitLiteralNull(LiteralNull node) => visitLiteral(node);
148 160
161 T visitStringConcatenation(StringConcatenation node) => visitLiteral(node);
162
149 T visitArrayInitializer(ArrayInitializer node) => visitExpression(node); 163 T visitArrayInitializer(ArrayInitializer node) => visitExpression(node);
150 T visitArrayHole(ArrayHole node) => visitExpression(node); 164 T visitArrayHole(ArrayHole node) => visitExpression(node);
151 T visitObjectInitializer(ObjectInitializer node) => visitExpression(node); 165 T visitObjectInitializer(ObjectInitializer node) => visitExpression(node);
152 T visitProperty(Property node) => visitNode(node); 166 T visitProperty(Property node) => visitNode(node);
153 T visitRegExpLiteral(RegExpLiteral node) => visitExpression(node); 167 T visitRegExpLiteral(RegExpLiteral node) => visitExpression(node);
154 168
155 T visitInterpolatedNode(InterpolatedNode node) => visitNode(node); 169 T visitInterpolatedNode(InterpolatedNode node) => visitNode(node);
156 170
157 T visitInterpolatedExpression(InterpolatedExpression node) 171 T visitInterpolatedExpression(InterpolatedExpression node)
158 => visitInterpolatedNode(node); 172 => visitInterpolatedNode(node);
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 682
669 Call(this.target, this.arguments, 683 Call(this.target, this.arguments,
670 {JavaScriptNodeSourceInformation sourceInformation}) { 684 {JavaScriptNodeSourceInformation sourceInformation}) {
671 this._sourceInformation = sourceInformation; 685 this._sourceInformation = sourceInformation;
672 } 686 }
673 687
674 accept(NodeVisitor visitor) => visitor.visitCall(this); 688 accept(NodeVisitor visitor) => visitor.visitCall(this);
675 689
676 void visitChildren(NodeVisitor visitor) { 690 void visitChildren(NodeVisitor visitor) {
677 target.accept(visitor); 691 target.accept(visitor);
678 for (Expression arg in arguments) arg.accept(visitor); 692 for (Expression arg in arguments) {
693 arg.accept(visitor);
694 }
679 } 695 }
680 696
681 Call _clone() => new Call(target, arguments); 697 Call _clone() => new Call(target, arguments);
682 698
683 int get precedenceLevel => CALL; 699 int get precedenceLevel => CALL;
684 } 700 }
685 701
686 class New extends Call { 702 class New extends Call {
687 New(Expression cls, List<Expression> arguments) : super(cls, arguments); 703 New(Expression cls, List<Expression> arguments) : super(cls, arguments);
688 704
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 void visitChildren(NodeVisitor visitor) { 925 void visitChildren(NodeVisitor visitor) {
910 receiver.accept(visitor); 926 receiver.accept(visitor);
911 selector.accept(visitor); 927 selector.accept(visitor);
912 } 928 }
913 929
914 PropertyAccess _clone() => new PropertyAccess(receiver, selector); 930 PropertyAccess _clone() => new PropertyAccess(receiver, selector);
915 931
916 int get precedenceLevel => CALL; 932 int get precedenceLevel => CALL;
917 } 933 }
918 934
935 /// A [DeferredToken] is a placeholder for some [Expression] that is not known
936 /// at construction time of an ast. Other than [InterpolatedExpression],
sra1 2015/06/10 19:30:00 'Other than' -> 'Unlike' ?
herhut 2015/06/11 08:03:55 Done.
937 /// [DeferredToken] is not limited to templates but may also occur in
938 /// fully instantiated asts.
939 abstract class DeferredToken extends Expression {
940 void visitChildren(NodeVisitor visitor) {}
941
942 DeferredToken _clone() => this;
943 }
944
945 /// Interace for a deferred integer value. An implementation has to provide
946 /// a value via the [value] getter the latest when the ast is printed.
947 abstract class DeferredNumber extends DeferredToken implements Literal {
948 accept(NodeVisitor visitor) => visitor.visitDeferredNumber(this);
949
950 int get value;
951
952 int get precedenceLevel => PRIMARY;
953 }
954
955 /// Interace for a deferred string value. An implementation has to provide
956 /// a value via the [value] getter the latest when the ast is printed.
957 abstract class DeferredString extends DeferredToken implements Literal {
958 accept(NodeVisitor visitor) => visitor.visitDeferredString(this);
959
960 String get value;
961
962 int get precedenceLevel => PRIMARY;
963 }
964
965 /// Interace for a deferred [Expression] value. An implementation has to provide
966 /// a value via the [value] getter the latest when the ast is printed.
967 /// Also, [precedenceLevel] has to return the same value that
968 /// [value.precedenceLevel] returns once [value] is bound to an [Expression].
969 abstract class DeferredExpression extends DeferredToken {
970 accept(NodeVisitor visitor) => visitor.visitDeferredExpression(this);
971
972 Expression get value;
973 }
974
919 abstract class Literal extends Expression { 975 abstract class Literal extends Expression {
920 void visitChildren(NodeVisitor visitor) {} 976 void visitChildren(NodeVisitor visitor) {}
921 977
922 int get precedenceLevel => PRIMARY; 978 int get precedenceLevel => PRIMARY;
923 } 979 }
924 980
925 class LiteralBool extends Literal { 981 class LiteralBool extends Literal {
926 final bool value; 982 final bool value;
927 983
928 LiteralBool(this.value); 984 LiteralBool(this.value);
(...skipping 10 matching lines...) Expand all
939 LiteralNull _clone() => new LiteralNull(); 995 LiteralNull _clone() => new LiteralNull();
940 } 996 }
941 997
942 class LiteralString extends Literal { 998 class LiteralString extends Literal {
943 final String value; 999 final String value;
944 1000
945 /** 1001 /**
946 * Constructs a LiteralString from a string value. 1002 * Constructs a LiteralString from a string value.
947 * 1003 *
948 * The constructor does not add the required quotes. If [value] is not 1004 * The constructor does not add the required quotes. If [value] is not
949 * surrounded by quotes and property escaped, the resulting object is invalid 1005 * surrounded by quotes and properly escaped, the resulting object is invalid
950 * as a JS value. 1006 * as a JS value.
951 * 1007 *
952 * TODO(sra): Introduce variants for known valid strings that don't allocate a 1008 * TODO(sra): Introduce variants for known valid strings that don't allocate a
953 * new string just to add quotes. 1009 * new string just to add quotes.
954 */ 1010 */
955 LiteralString(this.value); 1011 LiteralString(this.value);
956 1012
957 accept(NodeVisitor visitor) => visitor.visitLiteralString(this); 1013 accept(NodeVisitor visitor) => visitor.visitLiteralString(this);
958 LiteralString _clone() => new LiteralString(value); 1014 LiteralString _clone() => new LiteralString(value);
959 } 1015 }
960 1016
1017 class StringConcatenation extends Literal {
1018 final List<Literal> parts;
1019
1020 /**
1021 * Constructs a StringConcatenation from a list of Literal elements.
1022 * The constructor does not add surrounding quotes to the resulting
1023 * concatenated string.
1024 */
1025 StringConcatenation(this.parts);
1026
1027 accept(NodeVisitor visitor) => visitor.visitStringConcatenation(this);
1028
1029 void visitChildren(NodeVisitor visitor) {
1030 for (Literal part in parts) part.accept(visitor);
1031 }
1032
1033 StringConcatenation _clone() => new StringConcatenation(this.parts);
1034 }
1035
961 class LiteralNumber extends Literal { 1036 class LiteralNumber extends Literal {
962 final String value; // Must be a valid JavaScript number literal. 1037 final String value; // Must be a valid JavaScript number literal.
963 1038
964 LiteralNumber(this.value); 1039 LiteralNumber(this.value);
965 1040
966 accept(NodeVisitor visitor) => visitor.visitLiteralNumber(this); 1041 accept(NodeVisitor visitor) => visitor.visitLiteralNumber(this);
967 LiteralNumber _clone() => new LiteralNumber(value); 1042 LiteralNumber _clone() => new LiteralNumber(value);
968 } 1043 }
969 1044
970 class ArrayInitializer extends Expression { 1045 class ArrayInitializer extends Expression {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 class Await extends Expression { 1229 class Await extends Expression {
1155 /** The awaited expression. */ 1230 /** The awaited expression. */
1156 final Expression expression; 1231 final Expression expression;
1157 1232
1158 Await(this.expression); 1233 Await(this.expression);
1159 1234
1160 int get precedenceLevel => UNARY; 1235 int get precedenceLevel => UNARY;
1161 accept(NodeVisitor visitor) => visitor.visitAwait(this); 1236 accept(NodeVisitor visitor) => visitor.visitAwait(this);
1162 void visitChildren(NodeVisitor visitor) => expression.accept(visitor); 1237 void visitChildren(NodeVisitor visitor) => expression.accept(visitor);
1163 Await _clone() => new Await(expression); 1238 Await _clone() => new Await(expression);
1164
1165 } 1239 }
1166 1240
1167 /** 1241 /**
1168 * A comment. 1242 * A comment.
1169 * 1243 *
1170 * Extends [Statement] so we can add comments before statements in 1244 * Extends [Statement] so we can add comments before statements in
1171 * [Block] and [Program]. 1245 * [Block] and [Program].
1172 */ 1246 */
1173 class Comment extends Statement { 1247 class Comment extends Statement {
1174 final String comment; 1248 final String comment;
1175 1249
1176 Comment(this.comment); 1250 Comment(this.comment);
1177 1251
1178 accept(NodeVisitor visitor) => visitor.visitComment(this); 1252 accept(NodeVisitor visitor) => visitor.visitComment(this);
1179 Comment _clone() => new Comment(comment); 1253 Comment _clone() => new Comment(comment);
1180 1254
1181 void visitChildren(NodeVisitor visitor) {} 1255 void visitChildren(NodeVisitor visitor) {}
1182 } 1256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698