summaryrefslogtreecommitdiff
path: root/sources/scalac/atree/ATreeFactory.java
blob: be6d0e563ad6f387a4f2d3ed8c6d2dc0a6af37d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// $Id$

package scalac.atree;

import scalac.ast.Tree;
import scalac.symtab.Symbol;
import scalac.symtab.Type;

/** This class implements an attributed tree factory. */
public class ATreeFactory {

    //########################################################################
    // Public Fields

    /** The unique Void node */
    public final ACode Void = ACode.Void;

    /** The unique UNIT constant */
    public final AConstant UNIT = AConstant.UNIT;

    /** The unique NULL constant */
    public final AConstant NULL = AConstant.NULL;

    /** The unique ZERO constant */
    public final AConstant ZERO = AConstant.ZERO;

    //########################################################################
    // Public Methods - Building code

    /** Builds a This node. */
    public ACode This(Tree t, Symbol clasz) {
        ACode.This code = ACode.This(clasz);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Constant node. */
    public ACode Constant(Tree t, AConstant constant) {
        ACode.Constant code = ACode.Constant(constant);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Load node. */
    public ACode Load(Tree t, ALocation location) {
        ACode.Load code = ACode.Load(location);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Store node. */
    public ACode Store(Tree t, ALocation location, ACode value) {
        ACode.Store code = ACode.Store(location, value);
        code.pos = t.pos;
        return code;
    }

    /** Builds an Apply node. */
    public ACode Apply(Tree t, AFunction function, Type[] targs,ACode[] vargs){
        ACode.Apply code = ACode.Apply(function, targs, vargs);
        code.pos = t.pos;
        return code;
    }

    /** Builds an IsAs node. */
    public ACode IsAs(Tree t, ACode value, Type type, boolean cast) {
        ACode.IsAs code = ACode.IsAs(value, type, cast);
        code.pos = t.pos;
        return code;
    }

    /** Builds an If node. */
    public ACode If(Tree t, ACode test, ACode success, ACode failure) {
        ACode.If code = ACode.If(test, success, failure);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Switch node. */
    public ACode Switch(Tree t, ACode test, int[][] tags, ACode[] bodies,
        ACode other)
    {
        ACode.Switch code = ACode.Switch(test, tags, bodies, other);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Synchronized node. */
    public ACode Synchronized(Tree t, ACode lock, ACode value) {
        ACode.Synchronized code = ACode.Synchronized(lock, value);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Block node. */
    public ACode Block(Tree t, Symbol[] locals,ACode[] statements,ACode value){
        ACode.Block code = ACode.Block(locals, statements, value);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Label node. */
    public ACode Label(Tree t, Symbol label, Symbol[] locals, ACode value) {
        ACode.Label code = ACode.Label(label, locals, value);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Goto node. */
    public ACode Goto(Tree t, Symbol label, ACode[] vargs) {
        ACode.Goto code = ACode.Goto(label, vargs);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Return node. */
    public ACode Return(Tree t, Symbol function, ACode value) {
        ACode.Return code = ACode.Return(function, value);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Throw node. */
    public ACode Throw(Tree t, ACode value) {
        ACode.Throw code = ACode.Throw(value);
        code.pos = t.pos;
        return code;
    }

    /** Builds a Drop node. */
    public ACode Drop(Tree t, ACode value, Type type) {
        ACode.Drop code = ACode.Drop(value, type);
        code.pos = t.pos;
        return code;
    }

    //########################################################################
    // Public Methods - Building constants

    /** Builds a BOOLEAN constant of given value. */
    public AConstant BOOLEAN(Boolean value) {
        return BOOLEAN(value.booleanValue());
    }

    /** Builds a BOOLEAN constant of given value. */
    public AConstant BOOLEAN(boolean value) {
        return AConstant.BOOLEAN(value);
    }

    /** Builds a BYTE constant of given value. */
    public AConstant BYTE(Byte value) {
        return BYTE(value.byteValue());
    }

    /** Builds a BYTE constant of given value. */
    public AConstant BYTE(byte value) {
        return AConstant.BYTE(value);
    }

    /** Builds a SHORT constant of given value. */
    public AConstant SHORT(Short value) {
        return SHORT(value.shortValue());
    }

    /** Builds a SHORT constant of given value. */
    public AConstant SHORT(short value) {
        return AConstant.SHORT(value);
    }

    /** Builds a CHAR constant of given value. */
    public AConstant CHAR(Character value) {
        return CHAR(value.charValue());
    }

    /** Builds a CHAR constant of given value. */
    public AConstant CHAR(char value) {
        return AConstant.CHAR(value);
    }

    /** Builds an INT constant of given value. */
    public AConstant INT(Integer value) {
        return INT(value.intValue());
    }

    /** Builds an INT constant of given value. */
    public AConstant INT(int value) {
        return AConstant.INT(value);
    }

    /** Builds a LONG constant of given value. */
    public AConstant LONG(Long value) {
        return LONG(value.longValue());
    }

    /** Builds a LONG constant of given value. */
    public AConstant LONG(long value) {
        return AConstant.LONG(value);
    }

    /** Builds a FLOAT constant of given value. */
    public AConstant FLOAT(Float value) {
        return FLOAT(value.floatValue());
    }

    /** Builds a FLOAT constant of given value. */
    public AConstant FLOAT(float value) {
        return AConstant.FLOAT(value);
    }

    /** Builds a DOUBLE constant of given value. */
    public AConstant DOUBLE(Double value) {
        return DOUBLE(value.doubleValue());
    }

    /** Builds a DOUBLE constant of given value. */
    public AConstant DOUBLE(double value) {
        return AConstant.DOUBLE(value);
    }

    /** Builds a STRING constant of given value. */
    public AConstant STRING(String value) {
        return AConstant.STRING(value);
    }

    //########################################################################
}