001: /*
002: * xtc - The eXTensible Compiler
003: * Copyright (C) 2005-2007 Robert Grimm
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * version 2 as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
017: * USA.
018: */
019: package xtc.type;
020:
021: import java.io.IOException;
022:
023: /**
024: * A pointer type.
025: *
026: * @author Robert Grimm
027: * @version $Revision: 1.31 $
028: */
029: public class PointerT extends DerivedT {
030:
031: /** The canonical pointer to void. */
032: public static final PointerT TO_VOID = new PointerT(VoidT.TYPE);
033:
034: static {
035: TO_VOID.seal();
036: }
037:
038: /** The pointed-to type. */
039: private Type type;
040:
041: /**
042: * Create a new pointer type.
043: *
044: * @param type The pointed-to type.
045: */
046: public PointerT(Type type) {
047: this .type = type;
048: }
049:
050: /**
051: * Create a new pointer type.
052: *
053: * @param template The type whose annotations to copy.
054: * @param type The pointed-to type.
055: */
056: public PointerT(Type template, Type type) {
057: super (template);
058: this .type = type;
059: }
060:
061: public PointerT copy() {
062: return new PointerT(this , type.copy());
063: }
064:
065: public Type seal() {
066: if (!isSealed()) {
067: super .seal();
068: type.seal();
069: }
070: return this ;
071: }
072:
073: public Type.Tag tag() {
074: return Type.Tag.POINTER;
075: }
076:
077: public boolean isPointer() {
078: return true;
079: }
080:
081: public PointerT toPointer() {
082: return this ;
083: }
084:
085: /**
086: * Get the pointed-to type.
087: *
088: * @return The pointed-to type.
089: */
090: public Type getType() {
091: return type;
092: }
093:
094: public int hashCode() {
095: return type.hashCode();
096: }
097:
098: public boolean equals(Object o) {
099: if (!(o instanceof Type))
100: return false;
101: Type t = resolve(o);
102:
103: if (this == t)
104: return true;
105: if (!t.isPointer())
106: return false;
107: return type.equals(((PointerT) t).type);
108: }
109:
110: public void write(Appendable out) throws IOException {
111: out.append("pointer(");
112: type.write(out);
113: out.append(')');
114: }
115:
116: }
|