OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013, 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 // IrNodes are kept in a separate library to have precise control over their | |
6 // dependencies on other parts of the system | |
kasperl
2013/11/25 11:32:54
Terminate comment with .
lukas
2013/11/25 14:50:52
Done.
| |
7 library ir_nodes; | |
8 | |
9 import '../dart2jslib.dart' show Constant; | |
kasperl
2013/11/25 11:32:54
It's a little bit scary to drag in the entire Cons
lukas
2013/11/25 14:50:52
Yes - I'll address this in the next CL which will
| |
10 | |
11 /** | |
12 * A pair of source offset and an identifier name. Identifier names are used in | |
13 * the Javascript backend to generate source maps. | |
14 */ | |
15 class PositionWithIdentifierName { | |
16 final int offset; | |
17 final String sourceName; | |
18 PositionWithIdentifierName(this.offset, this.sourceName); | |
19 } | |
20 | |
21 abstract class IrNode { | |
22 final /* int | PositionWithIdentifierName */ position; | |
23 | |
24 const IrNode(this.position); | |
25 | |
26 int get offset => | |
27 (position is PositionWithIdentifierName) ? position.offset : position; | |
kasperl
2013/11/25 11:32:54
'is int' is simpler?
lukas
2013/11/25 14:50:52
Done.
| |
28 | |
29 String get sourceName => | |
30 (position is PositionWithIdentifierName) ? position.sourceName : null; | |
31 | |
32 accept(IrNodesVisitor visitor); | |
33 } | |
34 | |
35 class IrFunction extends IrNode { | |
36 final List<IrNode> statements; | |
37 | |
38 final int endOffset; | |
39 final int namePosition; | |
40 | |
41 IrFunction(position, this.endOffset, this.namePosition, this.statements) | |
42 : super(position); | |
43 | |
44 accept(IrNodesVisitor visitor) => visitor.visitIrFunction(this); | |
45 } | |
46 | |
47 class IrReturn extends IrNode { | |
48 final IrNode value; | |
49 | |
50 IrReturn(position, this.value) : super(position); | |
51 | |
52 accept(IrNodesVisitor visitor) => visitor.visitIrReturn(this); | |
53 } | |
54 | |
55 class IrConstant extends IrNode { | |
56 final Constant value; | |
57 | |
58 IrConstant(position, this.value) : super(position); | |
59 | |
60 accept(IrNodesVisitor visitor) => visitor.visitIrConstant(this); | |
61 } | |
62 | |
63 | |
64 abstract class IrNodesVisitor<T> { | |
65 T visit(IrNode node) => node.accept(this); | |
66 | |
67 void visitAll(List<IrNode> nodes) { | |
68 for (IrNode n in nodes) visit(n); | |
69 } | |
70 | |
71 T visitNode(IrNode node); | |
72 | |
73 T visitIrFunction(IrFunction node) => visitNode(node); | |
74 T visitIrReturn(IrReturn node) => visitNode(node); | |
75 T visitIrConstant(IrConstant node) => visitNode(node); | |
76 } | |
OLD | NEW |