xtc.type
Class VariableT

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

public class VariableT
extends WrappedT

A variable. This pseudo-type captures the name for globals, locals, parameters, fields, and bitfields. For the latter, it also captures the field width.

Version:
$Revision: 1.10 $
Author:
Robert Grimm

Nested Class Summary
static class VariableT.Kind
          The variable kind.
 
Nested classes/interfaces inherited from class xtc.type.Type
Type.Tag
 
Constructor Summary
VariableT(Type template, Type type, java.lang.String name, int width)
          Create a new bit-field.
VariableT(Type template, Type type, VariableT.Kind kind, java.lang.String name)
          Create a new variable type.
 
Method Summary
 VariableT copy()
          Create a deep copy of this type.
 VariableT.Kind getKind()
          Get the kind.
 java.lang.String getName()
          Get the name.
 int getWidth()
          Get this variable's width.
 boolean hasKind(VariableT.Kind kind)
          Determine whether this variable has the specified kind.
 boolean hasName()
          Determine whether this variable has a name.
 boolean hasName(java.lang.String name)
          Determine whether this variable has the specified name.
 boolean hasVariable()
          Determine whether this type contains a variable.
 boolean hasWidth()
          Determine whether this variable has a width.
 boolean isVariable()
          Determine whether this type is a variable.
static VariableT newBitfield(Type type, java.lang.String name, int width)
          Create a new bitfield.
static VariableT newField(Type type, java.lang.String name)
          Create a new field.
static VariableT newGlobal(Type type, java.lang.String name)
          Create a new global variable.
static VariableT newLocal(Type type, java.lang.String name)
          Create a new local variable.
static VariableT newParam(Type type, java.lang.String name)
          Create a new parameter.
 VariableT toVariable()
          Get this type as a variable.
 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
equals, getAttribute, getConstant, getLanguage, getLocation, getScope, getShape, getType, hasAlias, hasAnnotated, hasAttribute, hasConstant, hasEnum, hasEnumerator, hashCode, hasInstantiated, hasLanguage, hasLocation, hasParameterized, hasScope, hasShape, hasTagged, isWrapped, resolve, seal, setType, tag, toAlias, toAnnotated, toEnum, toEnumerator, toInstantiated, toParameterized, toStructOrUnion, toTagged, 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, isEnum, isEnumerator, isError, isFloat, isFunction, isInstantiated, isInteger, isInterface, isInternal, isInternalParameter, isLabel, isMethod, isNamedParameter, isNumber, isPackage, isParameter, isParameterized, isPointer, isSealed, isStruct, isTuple, isUnion, isUnit, 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
 

Constructor Detail

VariableT

public VariableT(Type template,
                 Type type,
                 VariableT.Kind kind,
                 java.lang.String name)
Create a new variable type.

Parameters:
template - The type whose annotations to copy.
type - The type.
kind - The kind.
name - The name.

VariableT

public VariableT(Type template,
                 Type type,
                 java.lang.String name,
                 int width)
Create a new bit-field.

Parameters:
template - The type whose annotations to copy.
type - The type.
name - The name.
width - The width.
Method Detail

copy

public VariableT 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.

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()

isVariable

public boolean isVariable()
Description copied from class: Type
Determine whether this type is a variable.

Overrides:
isVariable in class Type
Returns:
true if this type is a variable.

hasVariable

public boolean hasVariable()
Description copied from class: Type
Determine whether this type contains a variable.

Overrides:
hasVariable in class WrappedT
Returns:
true if this type contains a variable.
See Also:
Node.hasTraversal()

toVariable

public VariableT toVariable()
Description copied from class: Type
Get this type as a variable.

Overrides:
toVariable in class WrappedT
Returns:
This type as a variable.

hasKind

public boolean hasKind(VariableT.Kind kind)
Determine whether this variable has the specified kind.

Parameters:
kind - The kind.
Returns:
true if this variable has the specified kind.

getKind

public VariableT.Kind getKind()
Get the kind.

Returns:
The kind.

hasName

public boolean hasName()
Determine whether this variable has a name.

Returns:
true if this variable has a name.

hasName

public boolean hasName(java.lang.String name)
Determine whether this variable has the specified name.

Overrides:
hasName in class Node
Parameters:
name - The name.
Returns:
true if this variable has the name.

getName

public java.lang.String getName()
Get the name.

Overrides:
getName in class Node
Returns:
The name.

hasWidth

public boolean hasWidth()
Determine whether this variable has a width.

Returns:
true if this variable has a width.

getWidth

public int getWidth()
Get this variable's width. If this variable is a bitfield, this method returns the bitfield's width. Otherwise, it returns -1.

Returns:
This variable's width.

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.

newGlobal

public static VariableT newGlobal(Type type,
                                  java.lang.String name)
Create a new global variable.

Parameters:
type - The type.
name - The name.

newLocal

public static VariableT newLocal(Type type,
                                 java.lang.String name)
Create a new local variable.

Parameters:
type - The type.
name - The name.

newParam

public static VariableT newParam(Type type,
                                 java.lang.String name)
Create a new parameter.

Parameters:
type - The type.
name - The name.

newField

public static VariableT newField(Type type,
                                 java.lang.String name)
Create a new field.

Parameters:
type - The type.
name - The name.

newBitfield

public static VariableT newBitfield(Type type,
                                    java.lang.String name,
                                    int width)
Create a new bitfield.

Parameters:
type - The type.
name - The name.
width - The width.


Copyright © 2012. All Rights Reserved.