001: /*
002: * xtc - The eXTensible Compiler
003: * Copyright (C) 2006-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 xtc.tree.Attribute;
022: import xtc.tree.Location;
023:
024: /**
025: * The superclass of all wrapped types. A wrapped type adds (mostly)
026: * symbolic information to another, more basic type.
027: *
028: * @author Robert Grimm
029: * @version $Revision: 1.36 $
030: */
031: public abstract class WrappedT extends Type {
032:
033: /** The actual type. */
034: private Type type;
035:
036: /**
037: * Create a new wrapped type.
038: *
039: * @param type The actual type.
040: */
041: public WrappedT(Type type) {
042: this .type = type;
043: }
044:
045: /**
046: * Create a new wrapped type.
047: *
048: * @param template The type whose annotations to copy.
049: * @param type The actual type.
050: */
051: public WrappedT(Type template, Type type) {
052: super (template);
053: this .type = type;
054: }
055:
056: public Type seal() {
057: if (!isSealed()) {
058: super .seal();
059: type.seal();
060: }
061: return this ;
062: }
063:
064: public Type.Tag tag() {
065: return type.tag();
066: }
067:
068: public boolean isWrapped() {
069: return true;
070: }
071:
072: public WrappedT toWrapped() {
073: return this ;
074: }
075:
076: public boolean hasLocation(boolean forward) {
077: Location loc = super .getLocation(false);
078: return null != loc ? true : forward ? type.hasLocation(true)
079: : false;
080: }
081:
082: public Location getLocation(boolean forward) {
083: Location loc = super .getLocation(false);
084: return null != loc ? loc : forward ? type.getLocation(true)
085: : null;
086: }
087:
088: public boolean hasLanguage(boolean forward) {
089: return null != language ? true : forward ? type
090: .hasLanguage(true) : false;
091: }
092:
093: public Language getLanguage(boolean forward) {
094: return null != language ? language : forward ? type
095: .getLanguage(true) : null;
096: }
097:
098: public boolean hasScope(boolean forward) {
099: return null != scope ? true : forward ? type.hasScope(true)
100: : false;
101: }
102:
103: public String getScope(boolean forward) {
104: return null != scope ? scope : forward ? type.getScope(true)
105: : null;
106: }
107:
108: public boolean hasConstant(boolean forward) {
109: return null != constant ? true : forward ? type
110: .hasConstant(true) : false;
111: }
112:
113: public Constant getConstant(boolean forward) {
114: return null != constant ? constant : forward ? type
115: .getConstant(true) : null;
116: }
117:
118: public boolean hasShape(boolean forward) {
119: return null != shape ? true : forward ? type.hasShape(true)
120: : false;
121: }
122:
123: public Reference getShape(boolean forward) {
124: return null != shape ? shape : forward ? type.getShape(true)
125: : null;
126: }
127:
128: public boolean hasAttribute(Attribute att, boolean forward) {
129: return (null != attributes) && attributes.contains(att) ? true
130: : forward ? type.hasAttribute(att, true) : false;
131: }
132:
133: public Attribute getAttribute(String name, boolean forward) {
134: Attribute att = Attribute.get(name, attributes);
135: return null != att ? att : forward ? type.getAttribute(name,
136: true) : null;
137: }
138:
139: /**
140: * Get the type.
141: *
142: * @return The type.
143: */
144: public Type getType() {
145: return type;
146: }
147:
148: /**
149: * Set the type.
150: *
151: * @param type The type.
152: * @throws IllegalStateException Signals that this type is sealed.
153: */
154: public void setType(Type type) {
155: checkNotSealed();
156: this .type = type;
157: }
158:
159: public boolean hasAnnotated() {
160: return type.hasAnnotated();
161: }
162:
163: public AnnotatedT toAnnotated() {
164: return type.toAnnotated();
165: }
166:
167: public boolean hasAlias() {
168: return type.hasAlias();
169: }
170:
171: public AliasT toAlias() {
172: return type.toAlias();
173: }
174:
175: public boolean hasEnum() {
176: return type.hasEnum();
177: }
178:
179: public EnumT toEnum() {
180: return type.toEnum();
181: }
182:
183: public boolean hasEnumerator() {
184: return type.hasEnumerator();
185: }
186:
187: public EnumeratorT toEnumerator() {
188: return type.toEnumerator();
189: }
190:
191: public boolean hasVariable() {
192: return type.hasVariable();
193: }
194:
195: public boolean hasInstantiated() {
196: return type.hasInstantiated();
197: }
198:
199: public InstantiatedT toInstantiated() {
200: return type.toInstantiated();
201: }
202:
203: public boolean hasParameterized() {
204: return type.hasParameterized();
205: }
206:
207: public ParameterizedT toParameterized() {
208: return type.toParameterized();
209: }
210:
211: public VariableT toVariable() {
212: return type.toVariable();
213: }
214:
215: public boolean hasTagged() {
216: return type.hasTagged();
217: }
218:
219: public Tagged toTagged() {
220: return type.toTagged();
221: }
222:
223: public Type resolve() {
224: return type.resolve();
225: }
226:
227: /**
228: * Get this type's hash code. This method forwards the method
229: * invocation to the wrapped type.
230: *
231: * @return The hash code.
232: */
233: public int hashCode() {
234: return type.hashCode();
235: }
236:
237: /**
238: * Determine whether this type equals the specified object. This
239: * method forwards the method invocation to the wrapped type.
240: *
241: * @param o The object.
242: * @return <code>true</code> if this type equals the object.
243: */
244: public boolean equals(Object o) {
245: return getType().equals(o);
246: }
247:
248: }
|