01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2006-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: /**
24: * Representation of an indirect reference.
25: *
26: * @author Robert Grimm
27: * @version $Revision: 1.4 $
28: */
29: public class IndirectReference extends RelativeReference {
30:
31: /**
32: * Create a new indirect reference. The specified base reference
33: * must have a pointer type. The type of the newly created indirect
34: * reference is the pointed-to type, unless that type is an array,
35: * in which case the type is the array's element type.
36: *
37: * @param base The base reference.
38: * @throws IllegalArgumentException Signals that the base reference
39: * does not have a pointer type.
40: */
41: public IndirectReference(Reference base) {
42: super (base.type, base);
43:
44: // Update the type.
45: if (!type.isPointer()) {
46: throw new IllegalArgumentException("not a pointer");
47: }
48:
49: type = ((PointerT) type).getType().resolve();
50: normalize();
51: }
52:
53: public boolean isPrefix() {
54: return true;
55: }
56:
57: public boolean isIndirect() {
58: return true;
59: }
60:
61: public int hashCode() {
62: return base.hashCode();
63: }
64:
65: public boolean equals(Object o) {
66: if (this == o)
67: return true;
68: if (!(o instanceof IndirectReference))
69: return false;
70: return this .base.equals(((IndirectReference) o).base);
71: }
72:
73: public void write(Appendable out) throws IOException {
74: out.append('*');
75: base.write(out);
76: }
77:
78: }
|