summaryrefslogtreecommitdiff
path: root/sources/scalac/ast/Tree.java
blob: a3cc94cf3e93a45a773d15ca3be1228fc698c7ca (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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// $Id$

package scalac.ast;

import scalac.ast.printer.*;
import scalac.Global;
import scalac.util.Debug;
import scalac.util.Name;
import scalac.util.Position;
import scalac.symtab.Type;
import scalac.symtab.Symbol;

public class Tree {

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

    public int pos = Position.NOPOS;
    public Type type;

    //########################################################################
    // Public Constants

    /** Empty tree array */
    public static final Tree[] EMPTY_ARRAY = new Tree[0];

    //########################################################################
    // Public Cases

    /**
     * Representation for parser errors
     * - introduced by: parser
     * - eliminated by: -
     */
    public case Bad();

    /**
     * A tree node for the absence of a tree
     * - introduced by: parser, ... !!! ?
     * - eliminated by: !!! ?
     */
    public case Empty; static { Empty.type = Type.NoType; }

    /**
     * Class and data declaration
     * - introduced by: parser
     * - eliminated by: -
     */
    public case ClassDef(int mods,
                         Name name,
                         TypeDef[] tparams,
                         ValDef[][] vparams,
			 Tree tpe,
                         Template impl) {
	assert name.isTypeName();
    }

    /**
     * Package declaration
     * - introduced by: parser
     * - eliminated by: !!! ?
     */
    public case PackageDef(Tree packaged,
                           Template impl) {
	if (!packaged.isTerm())
	    throw unexpected("PackageDef expects term as rhs", packaged);
    }

    /**
     * Module declaration
     * - introduced by: parser
     * - eliminated by: !!! ?
     */
    public case ModuleDef(int mods,
                          Name name,
                          Tree tpe,
                          Template impl) {
	assert !name.isTypeName();
    }

    /**
     * Value declaration (var or let)
     * - introduced by: parser
     * - eliminated by: -
     */
    public case ValDef(int mods,
                       Name name,
                       Tree tpe,
                       Tree rhs) {
	assert !name.isTypeName();
	if (!tpe.isType())
	    throw unexpected("ValDef expects type as tpe", tpe);
	if (!rhs.isTerm())
	    throw unexpected("ValDef expects term as rhs", rhs);
    }

    /**
     * Value declaration with patterns (val)
     * - introduced by: parser
     * - eliminated by: desugarizer
     */
    public case PatDef(int mods,
                       Tree pat,
                       Tree rhs) {
	if (!rhs.isTerm())
	    throw unexpected("PatDef expects term as rhs", rhs);
    }

    /**
     * Function declaration (def)
     * - introduced by: parser
     * - eliminated by: -
     */
    public case DefDef(int mods,
                       Name name,
                       TypeDef[] tparams,
                       ValDef[][] vparams,
                       Tree tpe,
                       Tree rhs) {
	assert !name.isTypeName();
	if (!tpe.isType())
	    throw unexpected("DefDef expects type as tpe", tpe);
	if (!rhs.isTerm())
	    throw unexpected("DefDef expects term as rhs", rhs);
    }

    /**
     * Type declaration
     * - introduced by: parser
     * - eliminated by: ersure // !!! could/should be don earlier?)
     */
    public case TypeDef(int mods,
                        Name name,
                        Tree rhs) {
	assert name.isTypeName();
	if (!rhs.isType())
	    throw unexpected("TypeDef expects type as rhs", rhs);
    }

    /**
     * Import declaration
     * - introduced by: parser
     * - eliminated by: analyzer
     */
    public case Import(Tree expr, Name[] selectors) {
	if (!expr.isTerm())
	    throw unexpected("Import expects term", expr);
    }

    /**
     * Case declaration
     * - introduced by: parser
     * - eliminated by: !!! ?
     */
    public case CaseDef(Tree pat,
                        Tree guard,
                        Tree body) {
	if (!guard.isTerm())
	    throw unexpected("CaseDef expects term as guard", guard);
	if (!body.isTerm())
	    throw unexpected("CaseDef expects term as body", body);
    }

    /**
     * Instantiation templates
     * - introduced by: parser
     * - eliminated by: -
     */
    public case Template(Tree[] parents,
                         Tree[] body) {
	if (parents != null) {
	    for (int i = 0; i < parents.length; i++) {
		if (!parents[i].isTerm())
		    throw unexpected("Template requires terms as baseClasses", parents[i]);
	    }
	}
    }

    /**
     * Labelled expression - the symbols in the array (must be
     * Idents!) are those the label takes as argument
     * - introduced by: optimizer
     * - eliminated by: -
     */
    public case LabelDef(Tree[] params,Tree rhs) {
	for (int i = 0;i < params.length; i++) {
	    if (!(params[i] instanceof Ident))
		throw unexpected("LabelDef requires Idents", params[i]);
	}
    }

    /**
     * Block of expressions (semicolon separated expressions)
     * - introduced by: parser
     * - eliminated by: !!! ?
     */
    public case Block(Tree[] stats);

    /**
     * Tuple of expressions (comma separated expressions)
     * - introduced by: uncurry
     * - eliminated by: lambdalift
     */
    public case Tuple(Tree[] trees) {
	if (trees != null) {
	    for (int i = 0; i < trees.length; i++) {
		if (!trees[i].isTerm())
		    throw unexpected("Tuple requires terms", trees[i]);
	    }
	}
    }

    /**
     * Visitor (a sequence of cases)
     * - introduced by: parser
     * - eliminated by: transmatch
     */
    public case Visitor(CaseDef[] cases);

    /**
     * Anonymous function
     * - introduced by: parser
     * - eliminated by: analyzer
     */
    public case Function(ValDef[] vparams,
                         Tree body) {
	if (!body.isTerm())
	    throw unexpected("Function body has to be a term", body);
    }

    /**
     * Assignment
     * - introduced by: parser
     * - eliminated by: -
     */
    public case Assign(Tree lhs,
                       Tree rhs) {
	if (!lhs.isTerm())
	    throw unexpected("lhs of Assign has to be a term", lhs);
	if (!rhs.isTerm())
	    throw unexpected("rhs of Assign has to be a term", rhs);
    }

    /**
     * Conditional expression
     * - introduced by: parser
     * - eliminated by: -
     */
    public case If(Tree cond,
                   Tree thenp,
                   Tree elsep) {
        assert cond.isTerm() &&
               thenp.isTerm() &&
               elsep.isTerm();
    }

    /**
     * Instantiation
     * - introduced by: parser
     * - eliminated by: -
     */
    public case New(Template templ);

    /**
     * Type annotation
     * - introduced by: parser
     * - eliminated by: !!! ? (could be done by analyzer ?)
     */
    public case Typed(Tree expr,
                      Tree tpe) {
	if (!expr.isTerm())
	    throw unexpected("Typed expects term as first argument", expr);
	if (!tpe.isType())
	    throw unexpected("Typed expects type as second argument", tpe);
    }

    /**
     * Type application
     * - introduced by: parser
     * - eliminated by: erasure
     */
    public case TypeApply(Tree fun,
                          Tree[] args) {
	if (!fun.isTerm()) {
	    new TextTreePrinter().print(fun).println().end();//debug
	    throw unexpected("TypeApply expects term as function", fun);
	}
	for (int i = 0; i < args.length; i++) {
	    if (!args[i].isType())
		throw unexpected("TypeApply expects types as arguments", args[i]);
	}
    }

    /**
     * Value application
     * - introduced by: parser
     * - eliminated by: -
     */
    public case Apply(Tree fun,
                      Tree[] args) {
	if (args != null) {
	    for (int i = 0; i < args.length; i++) {
		if (!args[i].isTerm())
		    throw unexpected("Apply expects terms as arguments", args[i]);
	    }
	}
    }

    /**
     * Super reference
     * - introduced by: parser
     * - eliminated by: -
     */
    public case Super(Tree tpe) {
	if (!tpe.isType()) {
	    throw unexpected("Super expects type", tpe);
	}
    }

    /**
     * Self reference
     * - introduced by: parser
     * - eliminated by: -
     */
    public case This(Tree qualifier) {
	if (!qualifier.isType())
	    throw unexpected("This expects type", qualifier);
    }

    /**
     * Designator
     * - introduced by: parser
     * - eliminated by: -
     */
    public case Select(Tree qualifier,
                       Name selector) {
	if (!qualifier.isTerm())
	    throw unexpected("Select expects term", qualifier);
    }

    /**
     * Identifier
     * - introduced by: parser
     * - eliminated by: -
     */
    public case Ident(Name name) {
        assert name != null;
    }

    /**
     * Literal
     * - introduced by: parser
     * - eliminated by: -
     */
    public case Literal(Object value);

    /**
     * TypeTerm
     * - introduced by: Analyzer
     * - eliminated by: -
     */
    public case TypeTerm();

    /**
     * Singleton type
     * - introduced by: parser
     * - eliminated by: Analyzer
     */
    public case SingletonType(Tree ref) {
	if (!ref.isTerm())
	    throw unexpected("SingletonType expects term", ref);
    }

    /**
     * Type selection
     * - introduced by: parser
     * - eliminated by: Analyzer
     */
    public case SelectFromType(Tree qualifier,
			       Name selector) {
	if (!qualifier.isType())
	    throw unexpected("SelectFromType expects type", qualifier);
	assert selector.isTypeName();
    }

    /**
     * Function type
     * - introduced by: parser
     * - eliminated by: Analyzer
     */
    public case FunType(Tree[] argtpes,
                        Tree restpe) {
	for (int i = 0; i < argtpes.length; i++)
	    if (!argtpes[i].isType())
		throw unexpected("FunType requires types as args", argtpes[i]);
	if (!restpe.isType())
	    throw unexpected("FunType requires type as result", restpe);
    }

    /**
     * Object type (~ Template)
     * - introduced by: parser
     * - eliminated by: Analyzer
     */
    public case CompoundType(Tree[] parents,
                             Tree[] refinements) {
	if (parents != null) {
	    assert parents.length > 0;
	    for (int i = 0; i < parents.length; i++) {
		if (!parents[i].isType())
		    throw unexpected("CompoundType requires types as parents", parents[i]);
	    }
	}
    }

    /**
     * Applied type
     * - introduced by: parser
     * - eliminated by: analyzer
     */
    public case AppliedType(Tree tpe, Tree[] args) {
	assert tpe.isType() : this;
	for (int i = 0; i < args.length; i++) assert args[i].isType() : args[i];
    }

    /**
     * Covariant type
     * - introduced by: parser
     * - eliminated by: analyzer
     */
    public case CovariantType(Tree tpe) {
        assert tpe.isType();
    }

    //########################################################################
    // Public Methods - queries

    /** Returns true if this tree is a term. */
    public boolean isTerm() {
	switch(this) {
        case Bad():
	case Empty:
	case Tuple(_):
	case If(_, _, _):
	case Typed(_, _):
	case Apply(_, _):
	case TypeApply(_, _):
	case Visitor(_):
	case New(_):
	case Literal(_):
	case LabelDef(_,_):
	case Block(_):
	case Function(_, _):
	case Assign(_, _):
	case Super(_):
	case This(_):
	    return true;
	case Ident(Name name):
	    return !name.isTypeName();
	case Select(_, Name name):
	    return !name.isTypeName();
	default:
	    return false;
	}
    }

    /** Returns true if this tree is a type. */
    public boolean isType() {
	switch(this) {
        case Bad():
	case Empty:
	case TypeTerm():
	case SingletonType(_):
	case SelectFromType(_, _):
	case CompoundType(_, _):
	case FunType(_, _):
	case AppliedType(_, _):
	case CovariantType(_):
	    return true;
	case Ident(Name name):
	    return name.isTypeName();
	case Select(_, Name name):
	    return name.isTypeName();
	default:
	    return false;
	}
    }

    /** Returns true if this tree is empty or error. */
    public boolean isMissing() {
	switch(this) {
        case Bad():
	case Empty:
	    return true;
	default:
	    return false;
	}
    }

    //########################################################################
    // Public Methods - tree type

    /** Get the type of the node. */
    public Type type() {
        assert type != null : this;
        return type;
    }

    /** Set the type of the node. */
    public Tree setType(Type type) {
	assert !(type instanceof Type.LazyType) : symbol();
        this.type = type;
	return this;
    }

    /** Get types attached to array of nodes. */
    public static Type[] typeOf(Tree[] trees) {
	Type[] tps = new Type[trees.length];
	for (int i = 0; i < trees.length; i++)
	     tps[i] = trees[i].type();
	return tps;
    }

    //########################################################################
    // Public Methods - tree symbol

    /** Has this tree a symbol field? */
    public boolean hasSymbol() {
        return false;
    }

    /** Get symbol attached to the node, if any. */
    public Symbol symbol () {
        return null;
    }

    /** Set symbol attached to the node, if possible. */
    public Tree setSymbol(Symbol sym) {
        throw Debug.abort("no settable symbol for node", this);
    }

    /** Get symbols attached to array of nodes. */
    public static Symbol[] symbolOf(Tree[] trees) {
	Symbol[] syms = new Symbol[trees.length];
	for (int i = 0; i < trees.length; i++)
	     syms[i] = trees[i].symbol();
	return syms;
    }

    /** Tells if the tree defines a symbol. */
    public boolean definesSymbol() {
	return false;
    }

    //########################################################################
    // Public Methods - tree to string

    /**
     * Get string corresponding to this tree only implemented for
     * prefix trees, maybe we should generalize this; the PatternMatch
     * phase needs support for Apply, so this case got added
     */
    public String toString() {
	switch (this) {
	case This(Tree qual):
	    return (qual == Tree.Empty) ? "this" : qual + ".this";
	case Select(Tree qual, Name name):
	    return qual + "." + name;
	case Ident(Name name):
	    return name.toString();
        case TypeApply(Tree fn, Tree[] args):
            String res = fn + "[";
            if ((args == null) || (args.length == 0))
                return res + "]";
            res += args[0].toString();
            for (int i = 1; i < args.length; i++)
                res += ", " + args[i];
            return res + "]";
        case Apply(Tree fn, Tree[] args):
            String res = fn + "(";
            if ((args == null) || (args.length == 0))
                return res + ")";
            res += args[0].toString();
            for (int i = 1; i < args.length; i++)
                res += ", " + args[i];
            return res + ")";
        case Literal(Object value):
            if (value instanceof String)
                return "\"" + value + "\"";
            else
                return value.toString();
        case Import(Tree expr, _):
            return "import " + expr;
	case Empty:
	    return "<empty>";
        case TypeTerm():
            return type().toString();
	default:
	    return super.toString();
	}
    }

    //########################################################################
    // Private Methods

    private static Error unexpected(String message, Tree actual) {
        return Debug.abort(message + "; found", actual);
    }

    //########################################################################
    // Public Extended Classes

    public static class ExtBad extends Bad {
        private Symbol symbol;

        public ExtBad() {
            super();
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }
    }

    public static class ExtClassDef extends ClassDef {
        private Symbol symbol;

        public ExtClassDef(int mods, Name name, TypeDef[] tparams,
            ValDef[][] vparams, Tree tpe, Template impl)
        {
            super(mods, name, tparams, vparams, tpe, impl);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }

	public boolean definesSymbol() {
	    return true;
	}
    }

    public static class ExtModuleDef extends ModuleDef {
        private Symbol symbol;

        public ExtModuleDef(int mods, Name name, Tree tpe, Template impl)
        {
            super(mods, name, tpe, impl);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }

	public boolean definesSymbol() {
	    return true;
	}
    }

    public static class ExtValDef extends ValDef {

	public static final ValDef[] EMPTY_ARRAY = new ValDef[0];
	public static final ValDef[][] EMPTY_ARRAY_ARRAY = new ValDef[0][0];

        private Symbol symbol;

        public ExtValDef(int mods, Name name, Tree tpe, Tree rhs)
        {
            super(mods, name, tpe, rhs);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }

	public boolean definesSymbol() {
	    return true;
	}
    }

    public static class ExtDefDef extends DefDef {
        private Symbol symbol;

        public ExtDefDef(int mods, Name name, TypeDef[] tparams,
                         ValDef[][] vparams, Tree tpe, Tree rhs)
        {
            super(mods, name, tparams, vparams, tpe, rhs);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }

	public boolean definesSymbol() {
	    return true;
	}
    }

    public static class ExtTypeDef extends TypeDef {
        private Symbol symbol;

	public static final TypeDef[] EMPTY_ARRAY = new TypeDef[0];

        public ExtTypeDef(int mods, Name name, Tree rhs)
        {
            super(mods, name, rhs);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }

	public boolean definesSymbol() {
	    return true;
	}
    }

    public static class ExtImport extends Import {
        private Symbol symbol;

        public ExtImport(Tree expr, Name[] selectors) {
            super(expr, selectors);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }
    }

    public static class ExtLabelDef extends LabelDef {
	private Symbol symbol;

	public ExtLabelDef(Tree[] params,Tree rhs) {
	    super(params,rhs);
	}

	public boolean hasSymbol() {
	    return true;
	}

	public Symbol symbol() {
	    return symbol;
	}

	public Tree setSymbol(Symbol symbol) {
	    this.symbol = symbol;
	    return this;
	}

	public boolean definesSymbol() {
	    return true;
	}
    }

    public static class ExtSelect extends Select {
        private Symbol symbol;

        public ExtSelect(Tree qualifier, Name selector) {
            super(qualifier, selector);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }
    }

    public static class ExtSelectFromType extends SelectFromType {
        private Symbol symbol;

        public ExtSelectFromType(Tree qualifier, Name selector) {
            super(qualifier, selector);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }
    }

    public static class ExtIdent extends Ident {
        private Symbol symbol;

        public ExtIdent(Name name) {
            super(name);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }
    }

    public static class ExtTemplate extends Template {
        private Symbol symbol;

        public ExtTemplate(Tree[] parents, Tree[] body) {
	    super(parents, body);
        }

        public boolean hasSymbol() {
            return true;
        }

        public Symbol symbol() {
            return symbol;
        }

        public Tree setSymbol(Symbol symbol) {
            this.symbol = symbol;
            return this;
        }

	public boolean definesSymbol() {
	    return true;
	}
    }

    //########################################################################
    // duplication

    public static Transformer duplicator =
       new Transformer(
	    Global.instance, Global.instance.make,
	    new StrictTreeFactory(Global.instance.make));

    public Tree duplicate() {
	return duplicator.transform(this);
    }
}