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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js/nodes.dart

Issue 246633006: Revert "JS templates" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 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
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 visitInterpolatedLiteral(InterpolatedLiteral node);
68 T visitInterpolatedParameter(InterpolatedParameter node);
69 T visitInterpolatedSelector(InterpolatedSelector node);
70 T visitInterpolatedStatement(InterpolatedStatement node); 67 T visitInterpolatedStatement(InterpolatedStatement node);
68 T visitJSExpression(JSExpression node);
71 } 69 }
72 70
73 class BaseVisitor<T> implements NodeVisitor<T> { 71 class BaseVisitor<T> implements NodeVisitor<T> {
74 T visitNode(Node node) { 72 T visitNode(Node node) {
75 node.visitChildren(this); 73 node.visitChildren(this);
76 return null; 74 return null;
77 } 75 }
78 76
79 T visitProgram(Program node) => visitNode(node); 77 T visitProgram(Program node) => visitNode(node);
80 78
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 T visitLiteralString(LiteralString node) => visitLiteral(node); 143 T visitLiteralString(LiteralString node) => visitLiteral(node);
146 T visitLiteralNumber(LiteralNumber node) => visitLiteral(node); 144 T visitLiteralNumber(LiteralNumber node) => visitLiteral(node);
147 T visitLiteralNull(LiteralNull node) => visitLiteral(node); 145 T visitLiteralNull(LiteralNull node) => visitLiteral(node);
148 146
149 T visitArrayInitializer(ArrayInitializer node) => visitExpression(node); 147 T visitArrayInitializer(ArrayInitializer node) => visitExpression(node);
150 T visitArrayElement(ArrayElement node) => visitNode(node); 148 T visitArrayElement(ArrayElement node) => visitNode(node);
151 T visitObjectInitializer(ObjectInitializer node) => visitExpression(node); 149 T visitObjectInitializer(ObjectInitializer node) => visitExpression(node);
152 T visitProperty(Property node) => visitNode(node); 150 T visitProperty(Property node) => visitNode(node);
153 T visitRegExpLiteral(RegExpLiteral node) => visitExpression(node); 151 T visitRegExpLiteral(RegExpLiteral node) => visitExpression(node);
154 152
155 T visitInterpolatedNode(InterpolatedNode node) => visitNode(node);
156
157 T visitInterpolatedExpression(InterpolatedExpression node) 153 T visitInterpolatedExpression(InterpolatedExpression node)
158 => visitInterpolatedNode(node); 154 => visitExpression(node);
159 T visitInterpolatedLiteral(InterpolatedLiteral node)
160 => visitInterpolatedNode(node);
161 T visitInterpolatedParameter(InterpolatedParameter node)
162 => visitInterpolatedNode(node);
163 T visitInterpolatedSelector(InterpolatedSelector node)
164 => visitInterpolatedNode(node);
165 T visitInterpolatedStatement(InterpolatedStatement node) 155 T visitInterpolatedStatement(InterpolatedStatement node)
166 => visitInterpolatedNode(node); 156 => visitStatement(node);
157 T visitJSExpression(JSExpression node) => visitExpression(node);
167 158
168 // Ignore comments by default. 159 // Ignore comments by default.
169 T visitComment(Comment node) => null; 160 T visitComment(Comment node) => null;
170 } 161 }
171 162
172 abstract class Node { 163 abstract class Node {
173 var sourcePosition; 164 var sourcePosition;
174 var endSourcePosition; 165 var endSourcePosition;
175 166
176 accept(NodeVisitor visitor); 167 accept(NodeVisitor visitor);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 447
457 LiteralStatement(this.code); 448 LiteralStatement(this.code);
458 449
459 accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this); 450 accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this);
460 void visitChildren(NodeVisitor visitor) { } 451 void visitChildren(NodeVisitor visitor) { }
461 } 452 }
462 453
463 abstract class Expression extends Node { 454 abstract class Expression extends Node {
464 int get precedenceLevel; 455 int get precedenceLevel;
465 456
457 Call callWith(List<Expression> arguments) => new Call(this, arguments);
458
459 PropertyAccess operator [](expression) {
460 if (expression is Expression) {
461 return new PropertyAccess(this, expression);
462 } else if (expression is int) {
463 return new PropertyAccess.indexed(this, expression);
464 } else if (expression is String) {
465 return new PropertyAccess.field(this, expression);
466 } else {
467 throw new ArgumentError('Expected an int, String, or Expression');
468 }
469 }
470
466 Statement toStatement() => new ExpressionStatement(this); 471 Statement toStatement() => new ExpressionStatement(this);
472
473 Call call([expression]) {
474 List<Expression> arguments;
475 if (expression == null) {
476 arguments = <Expression>[];
477 } else if (expression is List) {
478 arguments = expression.map(js.toExpression).toList();
479 } else {
480 arguments = <Expression>[js.toExpression(expression)];
481 }
482 return callWith(arguments);
483 }
484
485 Expression operator +(expression) => binary('+', expression);
486
487 Expression operator -(expression) => binary('-', expression);
488
489 Expression operator &(expression) => binary('&', expression);
490
491 Expression operator <(expression) => binary('<', expression);
492
493 Expression operator >(expression) => binary('>', expression);
494
495 Expression operator >=(expression) => binary('>=', expression);
496
497 Expression binary(String operator, expression) {
498 return new Binary(operator, this, js.toExpression(expression));
499 }
500
501 Expression update(String operator, expression) {
502 return new Assignment.compound(this, operator, js.toExpression(expression));
503 }
504
505 Expression get plusPlus => new Postfix('++', this);
506
507 Prefix get typeof => new Prefix('typeof', this);
508
509 Prefix get not => new Prefix('!', this);
467 } 510 }
468 511
469 /// Wrap a CodeBuffer as an expression. 512 /// Wrap a CodeBuffer as an expression.
470 class Blob extends Expression { 513 class Blob extends Expression {
471 // TODO(ahe): This class is an aid to convert everything to ASTs, remove when 514 // TODO(ahe): This class is an aid to convert everything to ASTs, remove when
472 // not needed anymore. 515 // not needed anymore.
473 516
474 final leg.CodeBuffer buffer; 517 final leg.CodeBuffer buffer;
475 518
476 Blob(this.buffer); 519 Blob(this.buffer);
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 946
904 accept(NodeVisitor visitor) => visitor.visitProperty(this); 947 accept(NodeVisitor visitor) => visitor.visitProperty(this);
905 948
906 void visitChildren(NodeVisitor visitor) { 949 void visitChildren(NodeVisitor visitor) {
907 name.accept(visitor); 950 name.accept(visitor);
908 value.accept(visitor); 951 value.accept(visitor);
909 } 952 }
910 } 953 }
911 954
912 /// Tag class for all interpolated positions. 955 /// Tag class for all interpolated positions.
913 abstract class InterpolatedNode implements Node { 956 abstract class InterpolatedNode implements Node {}
914 get name; // 'int' for positional interpolated nodes, 'String' for named.
915 }
916 957
917 class InterpolatedExpression extends Expression implements InterpolatedNode { 958 class InterpolatedExpression extends Expression implements InterpolatedNode {
918 final name; 959 Expression value;
919 960
920 InterpolatedExpression(this.name); 961 InterpolatedExpression(this.value);
962
963 void assign(Expression newValue) {
964 value = newValue;
965 }
921 966
922 accept(NodeVisitor visitor) => visitor.visitInterpolatedExpression(this); 967 accept(NodeVisitor visitor) => visitor.visitInterpolatedExpression(this);
923 void visitChildren(NodeVisitor visitor) {}
924 968
925 int get precedenceLevel => PRIMARY; 969 void visitChildren(NodeVisitor visitor) {
926 } 970 if (value != null) value.accept(visitor);
971 }
927 972
928 class InterpolatedLiteral extends Literal implements InterpolatedNode { 973 int get precedenceLevel => value.precedenceLevel;
929 final name;
930
931 InterpolatedLiteral(this.name);
932
933 accept(NodeVisitor visitor) => visitor.visitInterpolatedLiteral(this);
934 void visitChildren(NodeVisitor visitor) {}
935 }
936
937 class InterpolatedParameter extends Expression
938 implements Parameter, InterpolatedNode {
939 final name;
940
941 InterpolatedParameter(this.name);
942
943 accept(NodeVisitor visitor) => visitor.visitInterpolatedParameter(this);
944 void visitChildren(NodeVisitor visitor) {}
945
946 int get precedenceLevel => PRIMARY;
947 }
948
949 class InterpolatedSelector extends Expression implements InterpolatedNode {
950 final name;
951
952 InterpolatedSelector(this.name);
953
954 accept(NodeVisitor visitor) => visitor.visitInterpolatedSelector(this);
955 void visitChildren(NodeVisitor visitor) {}
956
957 int get precedenceLevel => PRIMARY;
958 } 974 }
959 975
960 class InterpolatedStatement extends Statement implements InterpolatedNode { 976 class InterpolatedStatement extends Statement implements InterpolatedNode {
961 final name; 977 Statement value;
962 978
963 InterpolatedStatement(this.name); 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 }
964 987
965 accept(NodeVisitor visitor) => visitor.visitInterpolatedStatement(this); 988 accept(NodeVisitor visitor) => visitor.visitInterpolatedStatement(this);
966 void visitChildren(NodeVisitor visitor) {} 989
990 void visitChildren(NodeVisitor visitor) {
991 if (value != null) value.accept(visitor);
992 }
967 } 993 }
968 994
995 class JSExpression extends Expression {
996 Expression value;
997 List<InterpolatedNode> interpolatedNodes;
998
999 JSExpression(this.value, this.interpolatedNodes);
1000
1001 accept(NodeVisitor visitor) => visitor.visitJSExpression(this);
1002
1003 void visitChildren(NodeVisitor visitor) {
1004 value.accept(visitor);
1005 for (InterpolatedNode node in interpolatedNodes) {
1006 node.accept(visitor);
1007 }
1008 }
1009
1010 int get precedenceLevel => value.precedenceLevel;
1011 }
1012
1013 // TODO(sra): JSStatement like JSExpression.
1014
969 /** 1015 /**
970 * [RegExpLiteral]s, despite being called "Literal", do not inherit from 1016 * [RegExpLiteral]s, despite being called "Literal", do not inherit from
971 * [Literal]. Indeed, regular expressions in JavaScript have a side-effect and 1017 * [Literal]. Indeed, regular expressions in JavaScript have a side-effect and
972 * are thus not in the same category as numbers or strings. 1018 * are thus not in the same category as numbers or strings.
973 */ 1019 */
974 class RegExpLiteral extends Expression { 1020 class RegExpLiteral extends Expression {
975 /** Contains the pattern and the flags.*/ 1021 /** Contains the pattern and the flags.*/
976 String pattern; 1022 String pattern;
977 1023
978 RegExpLiteral(this.pattern); 1024 RegExpLiteral(this.pattern);
(...skipping 12 matching lines...) Expand all
991 */ 1037 */
992 class Comment extends Statement { 1038 class Comment extends Statement {
993 final String comment; 1039 final String comment;
994 1040
995 Comment(this.comment); 1041 Comment(this.comment);
996 1042
997 accept(NodeVisitor visitor) => visitor.visitComment(this); 1043 accept(NodeVisitor visitor) => visitor.visitComment(this);
998 1044
999 void visitChildren(NodeVisitor visitor) {} 1045 void visitChildren(NodeVisitor visitor) {}
1000 } 1046 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js/js.dart ('k') | sdk/lib/_internal/compiler/implementation/js/printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698