summaryrefslogtreecommitdiff
path: root/sources/meta/scalac/ast/MetaStrictTreeCopier.java
blob: cd0ec6bf585cd363828b8d2433d4b2566cd9d113 (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
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// $Id$

package meta.scalac.ast;

public class MetaStrictTreeCopier extends AbstractTreeMethodExpander {

    //########################################################################
    // Public Methods

    public void printTreeMethod(TreeNode node, boolean withSymbol) {
        TreeField symbol = node.getSymbol();
        node.printMethod(writer, tree.getFormal("tree"), withSymbol).lbrace();
        if (!withSymbol && node.hasLinkedFields())
            writer.println("assert tree.symbol() == null : "+
                "\"tree's symbol is not null\";");
        writer.print(node.getType(0)).print(" t = make.");
        node.printCall(writer, "tree.pos", withSymbol).println(";");
        writer.println("t.type = tree.type;");
        if (!withSymbol && node.hasSymbol() && !node.hasLinkedFields())
            writer.println("t.setSymbol(tree.symbol());");
        writer.println("return t;");
        writer.rbrace();

        if (withSymbol && node.hasLinkedFields()) {
            node.printMethod(writer, tree.getFormal("tree"), false, true);
            writer.lbrace();
            symbol.print(writer, true).println(" = tree.symbol();");
            node.printCall(writer.print("return "), "tree", true).println(";");
            writer.rbrace();
        }
    }

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