01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2005-2007 Robert Grimm
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.type;
20:
21: import java.io.IOException;
22:
23: import java.util.List;
24:
25: import xtc.util.Nonce;
26:
27: /**
28: * A union type.
29: *
30: * @author Robert Grimm
31: * @version $Revision: 1.20 $
32: */
33: public class UnionT extends StructOrUnionT {
34:
35: /**
36: * Create a new, incomplete union type. The newly created union
37: * type has a fresh nonce.
38: *
39: * @param tag The tag.
40: * @throws NullPointerException Signals a null tag.
41: */
42: public UnionT(String tag) {
43: super (null, Nonce.create(), tag, null);
44: }
45:
46: /**
47: * Create a new union type with a fresh nonce. The newly created
48: * union type has a fresh nonce.
49: *
50: * @param tag The tag.
51: * @param members The members.
52: * @throws NullPointerException Signals a null tag.
53: */
54: public UnionT(String tag, List<VariableT> members) {
55: super (null, Nonce.create(), tag, members);
56: }
57:
58: /**
59: * Create a new union type.
60: *
61: * @param template The type whose annotations to copy.
62: * @param nonce The nonce.
63: * @param tag The tag.
64: * @param members The members.
65: * @throws NullPointerException Signals a null tag.
66: */
67: public UnionT(Type template, Nonce nonce, String tag,
68: List<VariableT> members) {
69: super (template, nonce, tag, members);
70: }
71:
72: public UnionT copy() {
73: return new UnionT(this , nonce, name, copy(members));
74: }
75:
76: public Type.Tag tag() {
77: return Type.Tag.UNION;
78: }
79:
80: public boolean isUnion() {
81: return true;
82: }
83:
84: public UnionT toUnion() {
85: return this ;
86: }
87:
88: public void write(Appendable out) throws IOException {
89: out.append("union ");
90: out.append(name);
91: }
92:
93: }
|