summaryrefslogtreecommitdiff
path: root/sources/scalac/ast/LazyTreeFactory.java
blob: 43cef5652a8eaf2fbea84e128e2e62686f6f55d8 (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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
**                                                                      **
** $Id$
\*                                                                      */

package scalac.ast;

import scalac.util.Name;
import Tree.*;

public class LazyTreeFactory extends AbstractTreeCopyFactory {
    protected final TreeFactory make;

    public LazyTreeFactory(TreeFactory make) {
        this.make = make;
    }

    public Tree Bad(Tree tree) {
        return tree;
    }

    public Tree ClassDef(Tree tree,
                         int mods,
                         Name name,
                         TypeDef[] tparams,
                         ValDef[][] vparams,
			 Tree tpe,
                         Template impl) {
        ClassDef t = (ClassDef)tree;
        if ((t.mods == mods) &&
            (t.name == name) &&
            (t.tparams == tparams) &&
            (t.vparams == vparams) &&
	    (t.tpe == tpe) &&
            (t.impl == impl))
            return t;
        tree = make.ClassDef(t.pos, mods, name, tparams, vparams, tpe, impl);
        attribute(tree, t);
        return tree;
    }

    public Tree PackageDef(Tree tree,
                           Tree packaged,
                           Template impl) {
        PackageDef t = (PackageDef)tree;
        if ((t.packaged == packaged) &&
            (t.impl == impl))
            return t;
        tree = make.PackageDef(t.pos, packaged, impl);
        attribute(tree, t);
        return tree;
    }

    public Tree ModuleDef(Tree tree,
                          int mods,
                          Name name,
                          Tree tpe,
                          Template impl) {
        ModuleDef t = (ModuleDef)tree;
        if ((t.mods == mods) &&
            (t.name == name) &&
            (t.tpe == tpe) &&
            (t.impl == impl))
            return t;
        tree = make.ModuleDef(t.pos, mods, name, tpe, impl);
        attribute(tree, t);
        return tree;
    }

    public Tree ValDef(Tree tree,
                       int mods,
                       Name name,
                       Tree tpe,
                       Tree rhs) {
        ValDef t = (ValDef)tree;
        if ((t.mods == mods) &&
            (t.name == name) &&
            (t.tpe == tpe) &&
            (t.rhs == rhs))
            return t;
        tree = make.ValDef(t.pos, mods, name, tpe, rhs);
        attribute(tree, t);
        return tree;
    }

    public Tree PatDef(Tree tree,
                       int mods,
                       Tree pat,
                       Tree rhs) {
        PatDef t = (PatDef)tree;
        if ((t.mods == mods) &&
            (t.pat == pat) &&
            (t.rhs == rhs))
            return t;
        tree = make.PatDef(t.pos, mods, pat, rhs);
        attribute(tree, t);
        return tree;
    }

    public Tree DefDef(Tree tree,
                       int mods,
                       Name name,
                       TypeDef[] tparams,
                       ValDef[][] vparams,
                       Tree tpe,
                       Tree rhs) {
        DefDef t = (DefDef)tree;
        if ((t.mods == mods) &&
            (t.name == name) &&
            (t.tparams == tparams) &&
            (t.vparams == vparams) &&
            (t.tpe == tpe) &&
            (t.rhs == rhs))
            return t;
        tree = make.DefDef(t.pos, mods, name, tparams, vparams, tpe, rhs);
        attribute(tree, t);
        return tree;
    }

    public Tree TypeDef(Tree tree,
                        int mods,
                        Name name,
			TypeDef[] tparams,
                        Tree rhs) {
        TypeDef t = (TypeDef)tree;
        if ((t.mods == mods) &&
            (t.name == name) &&
	    (t.tparams == tparams) &&
            (t.rhs == rhs))
            return t;
        tree = make.TypeDef(t.pos, mods, name, tparams, rhs);
        attribute(tree, t);
        return tree;
    }

    public Tree Import(Tree tree,
                       Tree expr,
		       Name[] selectors) {
        Import t = (Import)tree;
        if (t.expr == expr && t.selectors == selectors)
            return t;
        tree = make.Import(t.pos, expr, selectors);
        attribute(tree, t);
        return tree;
    }

    public Tree CaseDef(Tree tree,
                        Tree pat,
                        Tree guard,
                        Tree body) {
        CaseDef t = (CaseDef)tree;
        if ((t.pat == pat) &&
            (t.guard == guard) &&
            (t.body == body))
            return t;
        tree = make.CaseDef(t.pos, pat, guard, body);
        attribute(tree, t);
        return tree;
    }

    public Template Template(Tree tree,
                             Tree[] parents,
                             Tree[] body) {
        Template t = (Template)tree;
        if ((t.parents == parents) &&
            (t.body == body))
            return t;
        Template newTree = make.Template(t.pos, parents, body);
        attribute(newTree, t);
        return newTree;
    }

    public Tree LabelDef(Tree tree,
			 Tree[] params,
			 Tree rhs) {
	LabelDef t = (LabelDef)tree;
	if ((t.params == params) &&
	    (t.rhs == rhs))
	    return t;
	tree = make.LabelDef(t.pos,params,rhs);
	attribute(tree,t);
	return tree;
    }

    public Tree Block(Tree tree,
                      Tree[] stats) {
        Block t = (Block)tree;
        if (t.stats == stats)
            return t;
        tree = make.Block(t.pos, stats);
        attribute(tree, t);
        return tree;
    }

    public Tree Tuple(Tree tree,
                      Tree[] trees) {
        Tuple t = (Tuple)tree;
        if (t.trees == trees)
            return t;
        tree = make.Tuple(t.pos, trees);
        attribute(tree, t);
        return tree;
    }

    public Tree Visitor(Tree tree,
                        CaseDef[] cases) {
        Visitor t = (Visitor)tree;
        if (t.cases == cases)
            return t;
        tree = make.Visitor(t.pos, cases);
        attribute(tree, t);
        return tree;
    }

    public Tree Function(Tree tree,
                         ValDef[] vparams,
                         Tree body) {
        Function t = (Function)tree;
        if ((t.vparams == vparams) &&
            (t.body == body))
            return t;
        tree = make.Function(t.pos, vparams, body);
        attribute(tree, t);
        return tree;
    }

    public Tree Assign(Tree tree,
                       Tree lhs,
                       Tree rhs) {
        Assign t = (Assign)tree;
        if ((t.lhs == lhs) &&
            (t.rhs == rhs))
            return t;
        tree = make.Assign(t.pos, lhs, rhs);
        attribute(tree, t);
        return tree;
    }

    public Tree If(Tree tree,
                   Tree cond,
                   Tree thenp,
                   Tree elsep) {
        If t = (If)tree;
        if ((t.cond == cond) &&
            (t.thenp == thenp) &&
            (t.elsep == elsep))
            return t;
        tree = make.If(t.pos, cond, thenp, elsep);
        attribute(tree, t);
        return tree;
    }

    public Tree New(Tree tree,
                    Template templ) {
        New t = (New)tree;
        if (t.templ == templ)
            return t;
        tree = make.New(t.pos, templ);
        attribute(tree, t);
        return tree;
    }

    public Tree Typed(Tree tree,
                      Tree expr,
                      Tree tpe) {
        Typed t = (Typed)tree;
        if ((t.expr == expr) &&
            (t.tpe == tpe))
            return t;
        tree = make.Typed(t.pos, expr, tpe);
        attribute(tree, t);
        return tree;
    }

    public Tree TypeApply(Tree tree,
                          Tree fun,
                          Tree[] args) {
        TypeApply t = (TypeApply)tree;
        if ((t.fun == fun) &&
            (t.args == args))
            return t;
        tree = make.TypeApply(t.pos, fun, args);
        attribute(tree, t);
        return tree;
    }

    public Tree Apply(Tree tree,
                      Tree fun,
                      Tree[] args) {
        Apply t = (Apply)tree;
        if ((t.fun == fun) &&
            (t.args == args))
            return t;
        tree = make.Apply(t.pos, fun, args);
        attribute(tree, t);
        return tree;
    }

    public Tree Super(Tree tree,
                      Tree tpe) {
        Super t = (Super)tree;
        if (t.tpe == tpe)
            return t;
        tree = make.Super(t.pos, tpe);
        attribute(tree, t);
        return tree;
    }

    public Tree This(Tree tree,
		     Tree qualifier) {
	This t = (This)tree;
	if (t.qualifier == qualifier)
	    return t;
	tree = make.This(t.pos, qualifier);
	attribute(tree, t);
	return tree;
    }

    public Tree Select(Tree tree,
                       Tree qualifier,
                       Name selector) {
        Select t = (Select)tree;
        if ((t.qualifier == qualifier) &&
            (t.selector == selector))
            return t;
        tree = make.Select(t.pos, qualifier, selector);
        attribute(tree, t);
        return tree;
    }

    public Tree Ident(Tree tree,
                      Name name) {
        Ident t = (Ident)tree;
        if (t.name == name)
            return t;
        tree = make.Ident(t.pos, name);
        attribute(tree, t);
        return tree;
    }

    public Tree Literal(Tree tree,
                        Object value) {
        Literal t = (Literal)tree;
        if (t.value == value)
            return t;
        tree = make.Literal(t.pos, value);
        attribute(tree, t);
        return tree;
    }

    public Tree SingletonType(Tree tree,
			      Tree ref) {
	SingletonType t = (SingletonType)tree;
	if (t.ref == ref)
	    return t;
	tree = make.SingletonType(t.pos, ref);
	attribute(tree, t);
	return tree;
    }

    public Tree SelectFromType(Tree tree,
			       Tree qualifier,
			       Name selector) {
	SelectFromType t = (SelectFromType)tree;
	if (t.qualifier == qualifier &&
	    t.selector == selector)
	    return t;
	tree = make.SelectFromType(t.pos, qualifier, selector);
	attribute(tree, t);
	return tree;
    }

    public Tree FunType(Tree tree,
                        Tree[] argtpes,
                        Tree restpe) {
        FunType t = (FunType)tree;
        if ((t.argtpes == argtpes) &&
            (t.restpe == restpe))
            return t;
        tree = make.FunType(t.pos, argtpes, restpe);
        attribute(tree, t);
        return tree;
    }

    public Tree CompoundType(Tree tree,
                             Tree[] parents,
                             Tree[] refinements) {
        CompoundType t = (CompoundType)tree;
        if ((t.parents == parents) &&
            (t.refinements == refinements))
            return t;
        tree = make.CompoundType(t.pos, parents, refinements);
        attribute(tree, t);
        return tree;
    }

    public Tree TupleType(Tree tree,
                          Tree[] types) {
        TupleType t = (TupleType)tree;
        if (t.types == types)
            return t;
        tree = make.TupleType(t.pos, types);
        attribute(tree, t);
        return tree;
    }

    public Tree AppliedType(Tree tree,
                            Tree tpe,
                            Tree[] args) {
        AppliedType t = (AppliedType)tree;
        if ((t.tpe == tpe) &&
            (t.args == args))
            return t;
        tree = make.AppliedType(t.pos, tpe, args);
        attribute(tree, t);
        return tree;
    }

    public Tree CovariantType(Tree tree,
			      Tree tpe) {
	CovariantType t = (CovariantType)tree;
	if (t.tpe == tpe) return t;
	tree = make.CovariantType(t.pos, tpe);
	attribute(tree, t);
	return tree;
    }
}