xtc.type
Class EnumT

java.lang.Object
  extended by xtc.tree.Node
      extended by xtc.type.Type
          extended by xtc.type.WrappedT
              extended by xtc.type.EnumT
All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>, Locatable, Tagged

public class EnumT
extends WrappedT
implements Tagged

An enumerated type. Note that the list of members for an enumerated type is the list of enumerators.

Version:
$Revision: 1.40 $
Author:
Robert Grimm

Nested Class Summary
 
Nested classes/interfaces inherited from class xtc.type.Type
Type.Tag
 
Constructor Summary
EnumT(java.lang.String name)
          Create a new, incomplete enum type.
EnumT(Type type, java.lang.String name, java.util.List<EnumeratorT> enumerators)
          Create a new enum type.
EnumT(Type template, Type type, Nonce nonce, java.lang.String name, java.util.List<EnumeratorT> enumerators)
          Create a new enum type.
 
Method Summary
 EnumT copy()
          Create a deep copy of this type.
 boolean equals(java.lang.Object o)
          Determine whether this type equals the specified object.
 EnumeratorT getMember(int index)
          Get the member with the specified index.
 int getMemberCount()
          Get the number of members.
 java.util.List<EnumeratorT> getMembers()
          Get the members of the tagged type.
 java.lang.String getName()
          Get the name of this node.
 Nonce getNonce()
          Get this tagged type's nonce.
 boolean hasEnum()
          Determine whether this type contains an enum.
 int hashCode()
          Get this type's hash code.
 boolean hasName(java.lang.String name)
          Determine whether this node's name is the same as the specified name.
 boolean hasTagged()
          Determine whether this type is tagged.
 boolean isEnum()
          Determine whether this type is an enum.
 boolean isUnnamed()
          Determine whether this tagged type is unnamed.
 Type lookup(java.lang.String name)
          Look up the member with the specified name.
 Type seal()
          Seal this enum.
 void setMembers(java.util.List<EnumeratorT> enumerators)
          Set the list of enumerators.
 void setType(Type type)
          Set the type.
 EnumT toEnum()
          Get this type as an enum.
 Tagged toTagged()
          Get this type as a tagged type.
 void write(java.lang.Appendable out)
          Write a human readable representation to the specified appendable.
 Type.Tag wtag()
          Get this wrapped type's tag.
 
Methods inherited from class xtc.type.WrappedT
getAttribute, getConstant, getLanguage, getLocation, getScope, getShape, getType, hasAlias, hasAnnotated, hasAttribute, hasConstant, hasEnumerator, hasInstantiated, hasLanguage, hasLocation, hasParameterized, hasScope, hasShape, hasVariable, isWrapped, resolve, tag, toAlias, toAnnotated, toEnumerator, toInstantiated, toParameterized, toStructOrUnion, toVariable, toWrapped
 
Methods inherited from class xtc.type.Type
addAttribute, annotate, attribute, attribute, attribute, attributes, cast, checkNotSealed, constant, constant, copy, deannotate, getAttribute, getConstant, getLanguage, getLocation, getScope, getShape, hasAttribute, hasAttribute, hasAttribute, hasAttributes, hasConstant, hasError, hasLanguage, hasLocation, hasScope, hasShape, hasStructOrUnion, hasTag, hasWTag, isAlias, isAnnotated, isArray, isBoolean, isClass, isConcrete, isDerived, isEnumerator, isError, isFloat, isFunction, isInstantiated, isInteger, isInterface, isInternal, isInternalParameter, isLabel, isMethod, isNamedParameter, isNumber, isPackage, isParameter, isParameterized, isPointer, isSealed, isStruct, isTuple, isUnion, isUnit, isVariable, isVariant, isVoid, isWildcard, language, locate, locate, mark, properties, removeAttribute, removeProperty, resolve, scope, seal, setLocation, setLocation, setProperty, shape, shape, toArray, toBoolean, toClass, toFloat, toFunction, toInteger, toInterface, toInternal, toInternalParameter, toLabel, toMethod, toNamedParameter, toNumber, toPackage, toParameter, toPointer, toStruct, toTuple, toUnion, toUnit, toVariant, toVoid, toWildcard, trace
 
Methods inherited from class xtc.tree.Node
add, add, addAll, addAll, addAll, addAll, addAllTo, addNode, contains, get, getBoolean, getBooleanProperty, getGeneric, getList, getNode, getProperty, getString, getStringProperty, getTokenText, hasProperty, hasTraversal, indexOf, isAnnotation, isEmpty, isGeneric, isList, isToken, iterator, lastIndexOf, remove, set, size, strip, toAnnotation, toList, toString, toToken
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface xtc.type.Tagged
isStruct, isUnion
 

Constructor Detail

EnumT

public EnumT(java.lang.String name)
Create a new, incomplete enum type. The newly created enum type has a fresh nonce and ErrorT.TYPE as its type.

Parameters:
name - The name.
Throws:
java.lang.NullPointerException - Signals a null name.

EnumT

public EnumT(Type type,
             java.lang.String name,
             java.util.List<EnumeratorT> enumerators)
Create a new enum type. The newly created enum type has a fresh nonce.

Parameters:
type - The underlying type.
name - The name.
enumerators - The enumerators.
Throws:
java.lang.NullPointerException - Signals a null name.

EnumT

public EnumT(Type template,
             Type type,
             Nonce nonce,
             java.lang.String name,
             java.util.List<EnumeratorT> enumerators)
Create a new enum type.

Parameters:
template - The type whose annotations to copy.
type - The underlying type.
nonce - The nonce.
name - The name.
enumerators - The enumerators.
Throws:
java.lang.NullPointerException - Signals a null name.
Method Detail

copy

public EnumT copy()
Description copied from class: Type
Create a deep copy of this type. The resulting type is not sealed.

Specified by:
copy in class Type
Returns:
A deep copy of this type.

seal

public Type seal()
Seal this enum. If this enum is incomplete, i.e., does not have any enumerators, invocations to this method have no effect.

Overrides:
seal in class WrappedT
Returns:
This type.
See Also:
Type.seal(List)

wtag

public Type.Tag wtag()
Description copied from class: Type
Get this wrapped type's tag. Invocations to this method are not forwarded across wrapped types.

Overrides:
wtag in class Type
Returns:
This wrapped type's tag.
See Also:
Type.tag()

isEnum

public boolean isEnum()
Description copied from class: Type
Determine whether this type is an enum.

Specified by:
isEnum in interface Tagged
Overrides:
isEnum in class Type
Returns:
true if this type is an enum.

hasEnum

public boolean hasEnum()
Description copied from class: Type
Determine whether this type contains an enum.

Overrides:
hasEnum in class WrappedT
Returns:
true if this type contains an enum.

toEnum

public EnumT toEnum()
Description copied from class: Type
Get this type as an enum.

Overrides:
toEnum in class WrappedT
Returns:
This type as an enum.

hasTagged

public boolean hasTagged()
Description copied from class: Type
Determine whether this type is tagged.

Overrides:
hasTagged in class WrappedT
Returns:
true if this type is tagged.

toTagged

public Tagged toTagged()
Description copied from class: Type
Get this type as a tagged type.

Overrides:
toTagged in class WrappedT
Returns:
This type as a tagged type.
See Also:
Type.hasTagged()

setType

public void setType(Type type)
Set the type. This method sets the enumerators' types to the specified type, which should be an integer. When modifying an incomplete type, this method should be called after the appropriate call to setMembers(List).

Overrides:
setType in class WrappedT
Parameters:
type - The type.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

getNonce

public Nonce getNonce()
Description copied from interface: Tagged
Get this tagged type's nonce. The nonce is used to determine equality of tagged types while still allowing for several type instances.

Specified by:
getNonce in interface Tagged
Returns:
The nonce.

isUnnamed

public boolean isUnnamed()
Description copied from interface: Tagged
Determine whether this tagged type is unnamed. Note that an unnamed tagged type still has a name of the form tag(nonce).

Specified by:
isUnnamed in interface Tagged
Returns:
true if this tagged type is unnamed.

hasName

public boolean hasName(java.lang.String name)
Description copied from class: Node
Determine whether this node's name is the same as the specified name.

User-specified classes must not override this method.

Specified by:
hasName in interface Tagged
Overrides:
hasName in class Node
Parameters:
name - The name.
Returns:
true if this node's name equals the specified name.

getName

public java.lang.String getName()
Description copied from class: Node
Get the name of this node. For strongly typed nodes, the name is implicitly specified by the node's class. For generic nodes, the name is the generic node's explicit name. The default implementation returns the node's class name.

User-specified classes must not override this method.

Specified by:
getName in interface Tagged
Overrides:
getName in class Node
Returns:
The name.

lookup

public Type lookup(java.lang.String name)
Description copied from interface: Tagged
Look up the member with the specified name. If this type is a struct or union and has any unnnamed struct or union fields, this method also tries to look up the name in the unnamed struct or union.

Specified by:
lookup in interface Tagged
Parameters:
name - The name.
Returns:
The type or ErrorT.TYPE if the tagged type has no such member.

getMemberCount

public int getMemberCount()
Description copied from interface: Tagged
Get the number of members. For struct and union types, the returned count excludes any anonymous bit-fields. It also excludes the individual members of an unnamed struct or union member.

Specified by:
getMemberCount in interface Tagged
Returns:
The number of members or -1 if this type is incomplete.

getMember

public EnumeratorT getMember(int index)
Description copied from interface: Tagged
Get the member with the specified index. For struct and union types, anonymous bit-fields are not considered.

Specified by:
getMember in interface Tagged
Parameters:
index - The index.
Returns:
The corresponding member.

getMembers

public java.util.List<EnumeratorT> getMembers()
Description copied from interface: Tagged
Get the members of the tagged type.

Specified by:
getMembers in interface Tagged
Returns:
The list of members or null if this type is incomplete.

setMembers

public void setMembers(java.util.List<EnumeratorT> enumerators)
Set the list of enumerators. This method does not change the type of the enumerators.

Parameters:
enumerators - The enumerators.
Throws:
java.lang.IllegalStateException - Signals that this type is sealed.

hashCode

public int hashCode()
Description copied from class: WrappedT
Get this type's hash code. This method forwards the method invocation to the wrapped type.

Overrides:
hashCode in class WrappedT
Returns:
The hash code.

equals

public boolean equals(java.lang.Object o)
Determine whether this type equals the specified object. This enum type equals the specified object if the object is an enum type with the same nonce.

Overrides:
equals in class WrappedT
Parameters:
o - The object.
Returns:
true if this type equals the object.

write

public void write(java.lang.Appendable out)
           throws java.io.IOException
Description copied from class: Node
Write a human readable representation to the specified appendable. If this node supports generic traversal, the default implementation writes this node in algebraic term-format; otherwise, it writes the string returned by Object.toString().

Overrides:
write in class Node
Parameters:
out - The appendable.
Throws:
java.io.IOException - Signals an I/O error.


Copyright © 2012. All Rights Reserved.