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

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

Issue 10825180: Add JavaScript AST. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 4 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
« no previous file with comments | « lib/compiler/implementation/js/js.dart ('k') | lib/compiler/implementation/js/precedence.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 interface NodeVisitor<T> {
6 T visitProgram(Program node);
7
8 T visitBlock(Block node);
9 T visitExpressionStatement(ExpressionStatement node);
10 T visitEmptyStatement(EmptyStatement node);
11 T visitIf(If node);
12 T visitFor(For node);
13 T visitForIn(ForIn node);
14 T visitWhile(While node);
15 T visitDo(Do node);
16 T visitContinue(Continue node);
17 T visitBreak(Break node);
18 T visitReturn(Return node);
19 T visitThrow(Throw node);
20 T visitTry(Try node);
21 T visitCatch(Catch node);
22 T visitSwitch(Switch node);
23 T visitCase(Case node);
24 T visitDefault(Default node);
25 T visitFunctionDeclaration(FunctionDeclaration node);
26 T visitLabeledStatement(LabeledStatement node);
27 T visitLiteralStatement(LiteralStatement node);
28
29 T visitLiteralExpression(LiteralExpression node);
30 T visitVariableDeclarationList(VariableDeclarationList node);
31 T visitSequence(Sequence node);
32 T visitAssignment(Assignment node);
33 T visitVariableInitialization(VariableInitialization node);
34 T visitConditional(Conditional cond);
35 T visitNew(New node);
36 T visitCall(Call node);
37 T visitBinary(Binary node);
38 T visitPrefix(Prefix node);
39 T visitPostfix(Postfix node);
40
41 T visitVariableUse(VariableUse node);
42 T visitThis(This node);
43 T visitVariableDeclaration(VariableDeclaration node);
44 T visitParameter(Parameter node);
45 T visitAccess(PropertyAccess node);
46
47 T visitNamedFunction(NamedFunction node);
48 T visitFun(Fun node);
49
50 T visitLiteralBool(LiteralBool node);
51 T visitLiteralString(LiteralString node);
52 T visitLiteralNumber(LiteralNumber node);
53 T visitLiteralNull(LiteralNull node);
54
55 T visitArrayInitializer(ArrayInitializer node);
56 T visitArrayElement(ArrayElement node);
57 T visitObjectInitializer(ObjectInitializer node);
58 T visitProperty(Property node);
59 T visitRegExpLiteral(RegExpLiteral node);
60 }
61
62 class BaseVisitor<T> implements NodeVisitor<T> {
63 T visitNode(Node node) {
64 node.visitChildren(this);
65 return null;
66 }
67
68 T visitProgram(Program node) => visitNode(node);
69
70 T visitStatement(Statement node) => visitNode(node);
71 T visitLoop(Loop node) => visitStatement(node);
72 T visitJump(Statement node) => visitStatement(node);
73
74 T visitBlock(Block node) => visitStatement(node);
75 T visitExpressionStatement(ExpressionStatement node)
76 => visitStatement(node);
77 T visitEmptyStatement(EmptyStatement node) => visitStatement(node);
78 T visitIf(If node) => visitStatement(node);
79 T visitFor(For node) => visitLoop(node);
80 T visitForIn(ForIn node) => visitLoop(node);
81 T visitWhile(While node) => visitLoop(node);
82 T visitDo(Do node) => visitLoop(node);
83 T visitContinue(Continue node) => visitJump(node);
84 T visitBreak(Break node) => visitJump(node);
85 T visitReturn(Return node) => visitJump(node);
86 T visitThrow(Throw node) => visitJump(node);
87 T visitTry(Try node) => visitStatement(node);
88 T visitSwitch(Switch node) => visitStatement(node);
89 T visitFunctionDeclaration(FunctionDeclaration node)
90 => visitStatement(node);
91 T visitLabeledStatement(LabeledStatement node) => visitStatement(node);
92 T visitLiteralStatement(LiteralStatement node) => visitStatement(node);
93
94 T visitCatch(Catch node) => visitNode(node);
95 T visitCase(Case node) => visitNode(node);
96 T visitDefault(Default node) => visitNode(node);
97
98 T visitExpression(Expression node) => visitNode(node);
99 T visitVariableReference(VariableReference node) => visitExpression(node);
100
101 T visitLiteralExpression(LiteralExpression node) => visitExpression(node);
102 T visitVariableDeclarationList(VariableDeclarationList node)
103 => visitExpression(node);
104 T visitSequence(Sequence node) => visitExpression(node);
105 T visitAssignment(Assignment node) => visitExpression(node);
106 T visitVariableInitialization(VariableInitialization node) {
ngeoffray 2012/08/16 13:22:15 So should VariableInitialization implement Stateme
floitsch 2012/08/16 14:12:52 I treat it as an ExpressionStatement. That seems t
107 if (node.value != null) {
108 visitAssignment(node);
109 } else {
110 visitExpression(node);
111 }
112 }
113 T visitConditional(Conditional node) => visitExpression(node);
114 T visitNew(New node) => visitExpression(node);
115 T visitCall(Call node) => visitExpression(node);
116 T visitBinary(Binary node) => visitCall(node);
117 T visitPrefix(Prefix node) => visitCall(node);
118 T visitPostfix(Postfix node) => visitCall(node);
119 T visitAccess(PropertyAccess node) => visitExpression(node);
120
121 T visitVariableUse(VariableUse node) => visitVariableReference(node);
122 T visitVariableDeclaration(VariableDeclaration node)
123 => visitVariableReference(node);
124 T visitParameter(Parameter node) => visitVariableDeclaration(node);
125 T visitThis(This node) => visitParameter(node);
126
127 T visitNamedFunction(NamedFunction node) => visitExpression(node);
128 T visitFun(Fun node) => visitExpression(node);
129
130 T visitLiteral(Literal node) => visitExpression(node);
131
132 T visitLiteralBool(LiteralBool node) => visitLiteral(node);
133 T visitLiteralString(LiteralString node) => visitLiteral(node);
134 T visitLiteralNumber(LiteralNumber node) => visitLiteral(node);
135 T visitLiteralNull(LiteralNull node) => visitLiteral(node);
136
137 T visitArrayInitializer(ArrayInitializer node) => visitExpression(node);
138 T visitArrayElement(ArrayElement node) => visitNode(node);
139 T visitObjectInitializer(ObjectInitializer node) => visitExpression(node);
140 T visitProperty(Property node) => visitNode(node);
141 T visitRegExpLiteral(RegExpLiteral node) => visitExpression(node);
142 }
143
144 class Node {
145 var sourcePosition;
146 var endSourcePosition;
147
148 abstract accept(NodeVisitor visitor);
149 abstract void visitChildren(NodeVisitor visitor);
150 }
151
152 class Program extends Node {
153 final List<Statement> body;
154 Program(this.body);
155
156 accept(NodeVisitor visitor) => visitor.visitProgram(this);
157 void visitChildren(NodeVisitor visitor) {
158 for (Statement statement in body) statement.accept(visitor);
159 }
160 }
161
162 abstract class Statement extends Node {
163 }
164
165 class Block extends Statement {
166 final List<Statement> statements;
167 Block(this.statements);
168 Block.empty() : this.statements = <Statement>[];
169
170 accept(NodeVisitor visitor) => visitor.visitBlock(this);
171 void visitChildren(NodeVisitor visitor) {
172 for (Statement statement in statements) statement.accept(visitor);
173 }
174 }
175
176 class ExpressionStatement extends Statement {
177 final Expression expression;
178 ExpressionStatement(this.expression);
179
180 accept(NodeVisitor visitor) => visitor.visitExpressionStatement(this);
181 void visitChildren(NodeVisitor visitor) { expression.accept(visitor); }
182 }
183
184 class EmptyStatement extends Statement {
185 EmptyStatement();
186
187 accept(NodeVisitor visitor) => visitor.visitEmptyStatement(this);
188 void visitChildren(NodeVisitor visitor) {}
189 }
190
191 class If extends Statement {
192 final Expression condition;
193 final Node then;
194 final Node otherwise;
195
196 If(this.condition, this.then, this.otherwise);
197 If.then(this.condition, this.then) : this.otherwise = new EmptyStatement();
198
199 bool get hasElse() => otherwise is !EmptyStatement;
200
201 accept(NodeVisitor visitor) => visitor.visitIf(this);
202
203 void visitChildren(NodeVisitor visitor) {
204 condition.accept(visitor);
205 then.accept(visitor);
206 otherwise.accept(visitor);
207 }
208 }
209
210 abstract class Loop extends Statement {
211 final Statement body;
212 Loop(this.body);
213 }
214
215 class For extends Loop {
216 final Expression init;
217 final Expression condition;
218 final Expression update;
219
220 For(this.init, this.condition, this.update, Statement body) : super(body);
221
222 accept(NodeVisitor visitor) => visitor.visitFor(this);
223
224 void visitChildren(NodeVisitor visitor) {
225 if (init !== null) init.accept(visitor);
226 if (condition !== null) condition.accept(visitor);
227 if (update !== null) update.accept(visitor);
228 body.accept(visitor);
229 }
230 }
231
232 class ForIn extends Loop {
233 // Note that [VariableDeclarationList] is a subclass of [Expression].
234 // Therefore we can type the leftHandSide as [Expression].
235 final Expression leftHandSide;
236 final Expression object;
237
238 ForIn(this.leftHandSide, this.object, Statement body) : super(body);
239
240 accept(NodeVisitor visitor) => visitor.visitForIn(this);
241
242 void visitChildren(NodeVisitor visitor) {
243 leftHandSide.accept(visitor);
244 object.accept(visitor);
245 body.accept(visitor);
246 }
247 }
248
249 class While extends Loop {
250 final Node condition;
251
252 While(this.condition, Statement body) : super(body);
253
254 accept(NodeVisitor visitor) => visitor.visitWhile(this);
255
256 void visitChildren(NodeVisitor visitor) {
257 condition.accept(visitor);
258 body.accept(visitor);
259 }
260 }
261
262 class Do extends Loop {
263 final Expression condition;
264
265 Do(Statement body, this.condition) : super(body);
266
267 accept(NodeVisitor visitor) => visitor.visitDo(this);
268
269 void visitChildren(NodeVisitor visitor) {
270 body.accept(visitor);
271 condition.accept(visitor);
272 }
273 }
274
275 class Continue extends Statement {
276 final String targetLabel; // Can be null.
277
278 Continue(this.targetLabel);
279
280 accept(NodeVisitor visitor) => visitor.visitContinue(this);
281 void visitChildren(NodeVisitor visitor) {}
282 }
283
284 class Break extends Statement {
285 final String targetLabel; // Can be null.
286
287 Break(this.targetLabel);
288
289 accept(NodeVisitor visitor) => visitor.visitBreak(this);
290 void visitChildren(NodeVisitor visitor) {}
291 }
292
293 class Return extends Statement {
294 final Expression value; // Can be null.
295
296 Return([this.value = null]);
297
298 accept(NodeVisitor visitor) => visitor.visitReturn(this);
299
300 void visitChildren(NodeVisitor visitor) {
301 if (value != null) value.accept(visitor);
302 }
303 }
304
305 class Throw extends Statement {
306 final Expression expression;
307
308 Throw(this.expression);
309
310 accept(NodeVisitor visitor) => visitor.visitThrow(this);
311
312 void visitChildren(NodeVisitor visitor) {
313 expression.accept(visitor);
314 }
315 }
316
317 class Try extends Statement {
318 final Block body;
319 final Catch catchPart; // Can be null if [finallyPart] is non-null.
320 final Block finallyPart; // Can be null if [catchPart] is non-null.
321
322 Try(this.body, this.catchPart, this.finallyPart) {
323 assert(catchPart != null || finallyPart != null);
324 }
325
326 accept(NodeVisitor visitor) => visitor.visitTry(this);
327
328 void visitChildren(NodeVisitor visitor) {
329 body.accept(visitor);
330 if (catchPart !== null) catchPart.accept(visitor);
331 if (finallyPart !== null) finallyPart.accept(visitor);
332 }
333 }
334
335 class Catch extends Node {
336 final VariableDeclaration declaration;
337 final Block body;
338
339 Catch(this.declaration, this.body);
340
341 accept(NodeVisitor visitor) => visitor.visitCatch(this);
342
343 void visitChildren(NodeVisitor visitor) {
344 declaration.accept(visitor);
345 body.accept(visitor);
346 }
347 }
348
349 class Switch extends Statement {
350 final Expression key;
351 final List<SwitchClause> cases;
352
353 Switch(this.key, this.cases);
354
355 accept(NodeVisitor visitor) => visitor.visitSwitch(this);
356
357 void visitChildren(NodeVisitor visitor) {
358 key.accept(visitor);
359 for (SwitchClause clause in cases) clause.accept(visitor);
360 }
361 }
362
363 abstract class SwitchClause extends Node {
364 final Block body;
365
366 SwitchClause(this.body);
367 }
368
369 class Case extends SwitchClause {
370 final Expression expression;
371
372 Case(this.expression, Block body) : super(body);
373
374 accept(NodeVisitor visitor) => visitor.visitCase(this);
375
376 void visitChildren(NodeVisitor visitor) {
377 expression.accept(visitor);
378 body.accept(visitor);
379 }
380 }
381
382 class Default extends SwitchClause {
383 Default(Block body) : super(body);
384
385 accept(NodeVisitor visitor) => visitor.visitDefault(this);
386
387 void visitChildren(NodeVisitor visitor) {
388 body.accept(visitor);
389 }
390 }
391
392 class FunctionDeclaration extends Statement {
393 final VariableDeclaration name;
394 final Fun function;
395
396 FunctionDeclaration(this.name, this.function);
397
398 accept(NodeVisitor visitor) => visitor.visitFunctionDeclaration(this);
399
400 void visitChildren(NodeVisitor visitor) {
401 name.accept(visitor);
402 function.accept(visitor);
403 }
404 }
405
406 class LabeledStatement extends Statement {
407 final String label;
408 final Statement body;
409
410 LabeledStatement(this.label, this.body);
411
412 accept(NodeVisitor visitor) => visitor.visitLabeledStatement(this);
413
414 void visitChildren(NodeVisitor visitor) {
415 body.accept(visitor);
416 }
417 }
418
419 class LiteralStatement extends Statement {
420 final String code;
421
422 LiteralStatement(this.code);
423
424 accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this);
425 void visitChildren(NodeVisitor visitor) { }
426 }
427
428 abstract class Expression extends Node {
429 abstract int get precedenceLevel();
430 }
431
432 class LiteralExpression extends Expression {
433 final String template;
434 final List<Expression> inputs;
435
436 LiteralExpression(this.template) : inputs = const [];
437 LiteralExpression.withData(this.template, this.inputs);
438
439 accept(NodeVisitor visitor) => visitor.visitLiteralExpression(this);
440
441 void visitChildren(NodeVisitor visitor) {
442 for (Expression expr in inputs) expr.accept(visitor);
443 }
444
445 int get precedenceLevel() => EXPRESSION;
446 }
447
448 /**
449 * [VariableDeclarationList] is a subclass of [Expression] to simplify the
450 * AST.
451 */
452 class VariableDeclarationList extends Expression {
453 final List<VariableInitialization> declarations;
454
455 VariableDeclarationList(this.declarations);
456
457 accept(NodeVisitor visitor) => visitor.visitVariableDeclarationList(this);
458
459 void visitChildren(NodeVisitor visitor) {
460 for (VariableInitialization declaration in declarations) {
461 declaration.accept(visitor);
462 }
463 }
464
465 int get precedenceLevel() => EXPRESSION;
466 }
467
468 class Sequence extends Expression {
469 final List<Expression> expressions;
470
471 Sequence(this.expressions);
472
473 accept(NodeVisitor visitor) => visitor.visitSequence(this);
474
475 void visitChildren(NodeVisitor visitor) {
476 for (Expression expr in expressions) expr.accept(visitor);
477 }
478
479 int get precedenceLevel() => EXPRESSION;
480 }
481
482 class Assignment extends Expression {
483 final Expression leftHandSide;
484 // Null, if the assignment is not compound.
485 final VariableReference compoundTarget;
486 final Expression value; // May be null, for [VariableInitialization]s.
487
488 Assignment(this.leftHandSide, this.value) : compoundTarget = null;
489 Assignment.compound(this.leftHandSide, String op, this.value)
490 : compoundTarget = new VariableUse(op);
491
492 int get precedenceLevel() => ASSIGNMENT;
493
494 bool get isCompound() => compoundTarget != null;
495 String get op() => compoundTarget == null ? null : compoundTarget.name;
496
497 accept(NodeVisitor visitor) => visitor.visitAssignment(this);
498
499 void visitChildren(NodeVisitor visitor) {
500 leftHandSide.accept(visitor);
501 if (compoundTarget != null) compoundTarget.accept(visitor);
502 if (value != null) value.accept(visitor);
503 }
504 }
505
506 class VariableInitialization extends Assignment {
507 /** [value] may be null. */
508 VariableInitialization(VariableDeclaration declaration, Expression value)
509 : super(declaration, value);
510
511 VariableDeclaration get declaration() => leftHandSide;
512
513 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this);
514 }
515
516 class Conditional extends Expression {
517 final Expression condition;
518 final Expression then;
519 final Expression otherwise;
520
521 Conditional(this.condition, this.then, this.otherwise);
522
523 accept(NodeVisitor visitor) => visitor.visitConditional(this);
524
525 void visitChildren(NodeVisitor visitor) {
526 condition.accept(visitor);
527 then.accept(visitor);
528 otherwise.accept(visitor);
529 }
530
531 int get precedenceLevel() => ASSIGNMENT;
532 }
533
534 class Call extends Expression {
535 Expression target;
536 List<Expression> arguments;
537
538 Call(this.target, this.arguments);
539
540 accept(NodeVisitor visitor) => visitor.visitCall(this);
541
542 void visitChildren(NodeVisitor visitor) {
543 target.accept(visitor);
544 for (Expression arg in arguments) arg.accept(visitor);
545 }
546
547 int get precedenceLevel() => CALL;
548 }
549
550 class New extends Call {
551 New(Expression cls, List<Expression> arguments) : super(cls, arguments);
552
553 accept(NodeVisitor visitor) => visitor.visitNew(this);
554 }
555
556 class Binary extends Call {
557 Binary(String op, Expression left, Expression right)
558 : super(new VariableUse(op), <Expression>[left, right]);
559
560 String get op() => (target as VariableUse).name;
561 Expression get left() => arguments[0];
562 Expression get right() => arguments[1];
563
564 accept(NodeVisitor visitor) => visitor.visitBinary(this);
565
566 int get precedenceLevel() {
567 // TODO(floitsch): switch to constant map.
568 switch (op) {
569 case "*":
570 case "/":
571 case "%":
572 return MULTIPLICATIVE;
573 case "+":
574 case "-":
575 return ADDITIVE;
576 case "<<":
577 case ">>":
578 case ">>>":
579 return SHIFT;
580 case "<":
581 case ">":
582 case "<=":
583 case ">=":
584 case "instanceof":
585 case "in":
586 return RELATIONAL;
587 case "==":
588 case "===":
589 case "!=":
590 case "!==":
591 return EQUALITY;
592 case "&":
593 return BIT_AND;
594 case "^":
595 return BIT_XOR;
596 case "|":
597 return BIT_OR;
598 case "&&":
599 return LOGICAL_AND;
600 case "||":
601 return LOGICAL_OR;
602 default:
603 throw new leg.CompilerCancelledException(
604 "Internal Error: Unhandled binary operator: $op");
605 }
606 }
607 }
608
609 class Prefix extends Call {
610 Prefix(String op, Expression arg)
611 : super(new VariableUse(op), <Expression>[arg]);
612
613 String get op() => (target as VariableUse).name;
614 Expression get argument() => arguments[0];
615
616 accept(NodeVisitor visitor) => visitor.visitPrefix(this);
617
618 int get precedenceLevel() => UNARY;
619 }
620
621 class Postfix extends Call {
622 Postfix(String op, Expression arg)
623 : super(new VariableUse(op), <Expression>[arg]);
624
625 String get op() => (target as VariableUse).name;
626 Expression get argument() => arguments[0];
627
628 accept(NodeVisitor visitor) => visitor.visitPostfix(this);
629
630 int get precedenceLevel() => UNARY;
631 }
632
633 abstract class VariableReference extends Expression {
634 final String name;
635
636 // We treat operators as if they were special functions. They can thus be
637 // referenced like other variables.
638 VariableReference(this.name);
639
640 abstract accept(NodeVisitor visitor);
641 int get precedenceLevel() => PRIMARY;
642 void visitChildren(NodeVisitor visitor) {}
643 }
644
645 class VariableUse extends VariableReference {
646 VariableUse(String name) : super(name);
647
648 accept(NodeVisitor visitor) => visitor.visitVariableUse(this);
649 }
650
651 class VariableDeclaration extends VariableReference {
652 VariableDeclaration(String name) : super(name);
653
654 accept(NodeVisitor visitor) => visitor.visitVariableDeclaration(this);
655 }
656
657 class Parameter extends VariableDeclaration {
658 Parameter(String id) : super(id);
659
660 accept(NodeVisitor visitor) => visitor.visitParameter(this);
661 }
662
663 class This extends Parameter {
664 This() : super("this");
665
666 accept(NodeVisitor visitor) => visitor.visitThis(this);
667 }
668
669 class NamedFunction extends Expression {
670 final VariableDeclaration name;
671 final Fun function;
672
673 NamedFunction(this.name, this.function);
674
675 accept(NodeVisitor visitor) => visitor.visitNamedFunction(this);
676
677 void visitChildren(NodeVisitor visitor) {
678 name.accept(visitor);
679 function.accept(visitor);
680 }
681
682 int get precedenceLevel() => CALL;
683 }
684
685 class Fun extends Expression {
686 final List<Parameter> params;
687 final Block body;
688
689 Fun(this.params, this.body);
690
691 accept(NodeVisitor visitor) => visitor.visitFun(this);
692
693 void visitChildren(NodeVisitor visitor) {
694 for (Parameter param in params) param.accept(visitor);
695 body.accept(visitor);
696 }
697
698 int get precedenceLevel() => CALL;
699 }
700
701 class PropertyAccess extends Expression {
702 final Expression receiver;
703 final Expression selector;
704
705 PropertyAccess(this.receiver, this.selector);
706 PropertyAccess.field(this.receiver, String fieldName)
707 : selector = new LiteralString("'$fieldName'");
708
709 accept(NodeVisitor visitor) => visitor.visitAccess(this);
710
711 void visitChildren(NodeVisitor visitor) {
712 receiver.accept(visitor);
713 selector.accept(visitor);
714 }
715
716 int get precedenceLevel() => CALL;
717 }
718
719 abstract class Literal extends Expression {
720 void visitChildren(NodeVisitor visitor) {}
721
722 int get precedenceLevel() => PRIMARY;
723 }
724
725 class LiteralBool extends Literal {
726 final bool value;
727
728 LiteralBool(this.value);
729
730 accept(NodeVisitor visitor) => visitor.visitLiteralBool(this);
731 // [visitChildren] inherited from [Literal].
732 }
733
734 class LiteralNull extends Literal {
735 LiteralNull();
736
737 accept(NodeVisitor visitor) => visitor.visitLiteralNull(this);
738 }
739
740 class LiteralString extends Literal {
741 final String value;
742
743 LiteralString(this.value);
744
745 accept(NodeVisitor visitor) => visitor.visitLiteralString(this);
746 }
747
748 class LiteralNumber extends Literal {
749 final String value;
750
751 LiteralNumber(this.value);
752
753 accept(NodeVisitor visitor) => visitor.visitLiteralNumber(this);
754 }
755
756 class ArrayInitializer extends Expression {
757 final int length;
758 // We represent the array as sparse list of elements. Each element knows its
759 // position in the array.
760 final List<ArrayElement> elements;
761
762 ArrayInitializer(this.length, this.elements);
763
764 accept(NodeVisitor visitor) => visitor.visitArrayInitializer(this);
765
766 void visitChildren(NodeVisitor visitor) {
767 for (ArrayElement element in elements) element.accept(visitor);
768 }
769
770 int get precedenceLevel() => PRIMARY;
771 }
772
773 /**
774 * An expression inside an [ArrayInitialization]. An [ArrayElement] knows
775 * its position in the containing [ArrayInitialization].
776 */
777 class ArrayElement extends Node {
778 int index;
779 Expression value;
780
781 ArrayElement(this.index, this.value);
782
783 accept(NodeVisitor visitor) => visitor.visitArrayElement(this);
784
785 void visitChildren(NodeVisitor visitor) {
786 value.accept(visitor);
787 }
788 }
789
790 class ObjectInitializer extends Expression {
791 List<Property> properties;
792
793 ObjectInitializer(this.properties);
794
795 accept(NodeVisitor visitor) => visitor.visitObjectInitializer(this);
796
797 void visitChildren(NodeVisitor visitor) {
798 for (Property init in properties) init.accept(visitor);
799 }
800
801 int get precedenceLevel() => PRIMARY;
802 }
803
804 class Property extends Node {
805 Literal name;
806 Expression value;
807
808 Property(this.name, this.value);
809
810 accept(NodeVisitor visitor) => visitor.visitProperty(this);
811
812 void visitChildren(NodeVisitor visitor) {
813 name.accept(visitor);
814 value.accept(visitor);
815 }
816 }
817
818 /**
819 * [RegExpLiteral]s, despite being called "Literal", are not inheriting from
820 * [Literal]. Indeed, regular expressions in JavaScript have a side-effect and
821 * are thus not in the same category as numbers or strings.
822 */
823 class RegExpLiteral extends Expression {
824 /** Contains the pattern and the flags.*/
825 String pattern;
826
827 RegExpLiteral(this.pattern);
828
829 accept(NodeVisitor visitor) => visitor.visitRegExpLiteral(this);
830 void visitChildren(NodeVisitor visitor) {}
831
832 int get precedenceLevel() => PRIMARY;
833 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/js/js.dart ('k') | lib/compiler/implementation/js/precedence.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698