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 java.util.List;
022:
023: import xtc.util.Nonce;
024:
025: /**
026: * The interface of all tagged C types. Note that all tagged C types
027: * must have a name, even if they are unnamed in source code. For
028: * unnamed tagged types, the name must be of the form
029: * <code>tag(<i>nonce</i>)</code>.
030: *
031: * @author Robert Grimm
032: * @version $Revision: 1.5 $
033: */
034: public interface Tagged {
035:
036: /**
037: * Determine whether this tagged type is an enum.
038: *
039: * @return <code>true</code> if this tagged type is an enum.
040: */
041: public boolean isEnum();
042:
043: /**
044: * Determine whether this tagged type is a struct.
045: *
046: * @return <code>true</code> if this tagged type is a struct.
047: */
048: public boolean isStruct();
049:
050: /**
051: * Determine whether this tagged type is a union.
052: *
053: * @return <code>true</code> if this tagged type is a union.
054: */
055: public boolean isUnion();
056:
057: /**
058: * Get this tagged type's nonce. The nonce is used to determine
059: * equality of tagged types while still allowing for several
060: * type instances.
061: *
062: * @return The nonce.
063: */
064: public Nonce getNonce();
065:
066: /**
067: * Determine whether this tagged type is unnamed. Note that an
068: * unnamed tagged type still has a name of the form
069: * <code>tag(<i>nonce</i>)</code>.
070: *
071: * @return <code>true</code> if this tagged type is unnamed.
072: */
073: public boolean isUnnamed();
074:
075: /**
076: * Determine whether this tagged type has the specified name.
077: *
078: * @param name The name.
079: * @return <code>true</code> if this tagged type has the name.
080: */
081: public boolean hasName(String name);
082:
083: /**
084: * Get the name.
085: *
086: * @return The name.
087: */
088: public String getName();
089:
090: /**
091: * Look up the member with the specified name. If this type is a
092: * struct or union and has any unnnamed struct or union fields, this
093: * method also tries to look up the name in the unnamed struct or
094: * union.
095: *
096: * @param name The name.
097: * @return The type or {@link ErrorT#TYPE} if the tagged type has no
098: * such member.
099: */
100: public Type lookup(String name);
101:
102: /**
103: * Get the number of members. For struct and union types, the
104: * returned count excludes any anonymous bit-fields. It also
105: * excludes the individual members of an unnamed struct or union
106: * member.
107: *
108: * @return The number of members or <code>-1</code> if this type is
109: * incomplete.
110: */
111: public int getMemberCount();
112:
113: /**
114: * Get the member with the specified index. For struct and union
115: * types, anonymous bit-fields are not considered.
116: *
117: * @param index The index.
118: * @return The corresponding member.
119: * @throws IndexOutOfBoundsException Signals that the index is out
120: * of range.
121: */
122: public Type getMember(int index);
123:
124: /**
125: * Get the members of the tagged type.
126: *
127: * @return The list of members or <code>null</code> if this type is
128: * incomplete.
129: */
130: public List<? extends Type> getMembers();
131:
132: }
|