|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdspl.intermediate.variable.Variable
public abstract class Variable
Variable is the base abstract class used as the parent of all other abstract Variable classes
| Field Summary | |
|---|---|
protected int |
arraySize
The number of elements in an array |
protected int |
byteSize
Stores the size (in bytes) of the Variable For primitives: float,int,uint = 4 bytes byte,ubyte = 1 byte complex = 8 bytes (2 floats) for arrays = # of elements * size of array's primitive type |
static int |
DATA_TYPE_BYTE
|
static int |
DATA_TYPE_COMPLEX
|
static int |
DATA_TYPE_FLOAT
Enumeration types of possible values. |
static int |
DATA_TYPE_INT
|
static int |
DATA_TYPE_STRING
|
static int |
DATA_TYPE_UBYTE
|
static int |
DATA_TYPE_UINT
|
protected int |
dataType
Stores the data type, using one of the possible DATA_TYPE_xxx values above |
protected Variable |
elementIndex
If the variable is an element of a larger variable (either array or complex), element index stores either: the index into the array, in the case where elementsParentVar is an array the flag indicating either the real or imaginary component of a complex, in the case where elementsParentVar is a DSPLComplex |
protected Variable |
elementsParentVar
For Atomic Elements of Arrays/Complex, elementsParentVar contains the parent variable (either the array or complex variable) |
protected java.lang.String |
identifier
Contains the identifier used within the actual source program For example, "complex_array a;" would create a Variable of data type complex_array with the identifier set to "a"; In the case of constants, the identifier is equal to the string representation of the constant. |
protected boolean |
isConstant
Refers to whether the Variable is a constant, meaning the actual value is known at compile time. |
protected boolean |
isElement
Refers to whether a Variable represents an element within either an array a Variable Example: Within "int_array x[5]; x[0] = 1;", "x[0]" should create an array element variable to pass into the IR |
protected int |
lineNumDecl
Contains the line within the source program where the Variable was declared |
static int |
SIZE_TYPE_ARRAY
Describes any arra of single elements (array of ints, array of floats, etc) |
static int |
SIZE_TYPE_ATOM
Describes any single elements (integer, float, etc) |
protected int |
sizeType
Stores the size type, using one of the possible SIZE_TYPE_xxx above |
java.lang.Object |
value
Stores the value of the object (Integer, Float, Array of Integers, Array of Floats, etc) |
| Fields inherited from interface dspl.frontend.ParserTokensTokenTypes |
|---|
ASSIGN, COMMA, COMMENT, DECLS, DIGITS, DIV, DOT, EOF, EQ, GE, GT, ID, LBRACE, LBRACK, LE, LITERAL_byte, LITERAL_byte_array, LITERAL_ccall, LITERAL_complex, LITERAL_complex_array, LITERAL_else, LITERAL_float, LITERAL_float_array, LITERAL_for, LITERAL_if, LITERAL_int, LITERAL_int_array, LITERAL_string, LITERAL_ubyte, LITERAL_ubyte_array, LITERAL_uint, LITERAL_uint_array, LITERAL_while, LPAREN, LT, MINUS, MUL, NE, NEGATE, NEWLINE, NULL_TREE_LOOKAHEAD, NUM, PLUS, PROGRAM, RBRACE, RBRACK, REAL, RPAREN, SEMI, STRING, TILDE, WS |
| Constructor Summary | |
|---|---|
Variable(int numElements)
Constructor immediately invoked by all derived classes of Variable in their atomic or array constructor |
|
| Method Summary | |
|---|---|
abstract java.lang.Object |
convertToObject(java.lang.String strValue)
Method responsible for taking a string from the source code and converting it into the appriopriate Java Object for the primitive. For all DSPL primitives except complex, the native java objects are used (String for string, Integer for int/uint, Float for float, etc). |
abstract java.lang.Object |
convertToObject(java.lang.String strValue1,
java.lang.String strValue2)
Method responsible for taking two strings from the source code and converting it into the appriopriate Java Object for the primitive. At time of writing, this is only required for Complex, which takes two strings (real and imag). For complex, the dspl.intermediate.variable.primitive.Complex object is used Note invoking the double string convertToObject on any type besides complex throws an error. |
static int |
getAntlrTypeFromVarType(int varType)
Returns the Antlr constant for a variable type based on the DSPL variable type. |
static int |
getAntlrTypeFromVarTypeArray(int varType)
|
int |
getArraySize()
Returns the data type of the Variable (either atomic or array) |
int |
getByteSize()
Returns the size of the Variable (size = (size of type) * (num of elements) |
abstract int |
getDataType()
|
abstract int |
getDataTypeByteSize()
Returns the size of the Variable type's byte size (for a single element) |
java.lang.String |
getIdentifier()
Gets the identifier for the Variable Throws an error if the variable has not yet been set. |
Variable |
getIndexVariable()
|
static Variable |
getNewArray(int parserTokenID,
java.lang.String identifier,
int arraySize,
int lineDecl)
Called to create a new array Variable of the appriopriate size based on the provided parserTokenID |
static Variable |
getNewAtomic(int parserTokenID,
java.lang.String identifier,
int lineDecl,
boolean isConstant)
Creates a new Atomic Variable. |
static Variable |
getNewAtomicElement(Variable parentVar,
Variable elementIndex,
int lineDecl)
Returns a new Atomic variable representing an element within an array or complex |
Variable |
getParentVariable()
|
int |
getSizeType()
|
java.lang.Object |
getValue()
Returns the Variable's value |
int |
getVariableSizeType()
|
void |
initVariable(int numElements)
The purpose of this function is to have a single function that all derived classes can call to perform the initialization steps of setting the byte size, data type, and size type While this could be done in the constructor, by putting it here and then relying on the necessary get calls that all descended classes must implement, this makes it easier to write correct code which fills in the proper values as one need only remember to call initVariables in the constructor, rather than remember to write out all of the fields below. |
boolean |
isArray()
Called to determine if the variable is an array or not |
boolean |
isAtomic()
Called to determine if the variable is an atomic or not |
boolean |
isConstant()
Returns whether the Variable is a constant variable or not |
boolean |
isElement()
|
abstract boolean |
isNaturalNum()
Natural numbers are ints, uints, chars, and uchars. |
abstract boolean |
isNumeric()
Numeric types are defiend in the context of the allowable operations performable on them. |
boolean |
isSameDataType(Variable otherVar)
Note that this function returns true so long as their type is the same, it does not take into account whether the sizes are the same. |
boolean |
isValueSet()
Retruns whether the Variable's value has been set The function has been included so that variables can have their initial values set implicitly when they are declared within the .data section of the ASM file instead of requiring a "mov" instruction to set it in the begining This feature is specificaly required for floating point values because floating point operations do not accept immediate operands. |
void |
setIdentifier(java.lang.String newID)
Sets the identifier of the Variable. |
void |
setValue(java.lang.String valueStr)
Used to set the value of a Variable. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DATA_TYPE_FLOAT
public static final int DATA_TYPE_INT
public static final int DATA_TYPE_UINT
public static final int DATA_TYPE_BYTE
public static final int DATA_TYPE_UBYTE
public static final int DATA_TYPE_COMPLEX
public static final int DATA_TYPE_STRING
public static final int SIZE_TYPE_ATOM
public static final int SIZE_TYPE_ARRAY
public java.lang.Object value
protected int dataType
protected int sizeType
protected int byteSize
protected int arraySize
For Variables declared which have sizeType = SIZE_TYPE_ARRAY this value must be >=1
For SIZE_TYPE_ATOM it should remain -1
protected boolean isConstant
Example: "int x=5;" in this case the Variable created for 5 would have isConstant = true, since its initial value is known at compile time. This is useful for generating assmebly code when one needs to decide whether to pass an actual variable or a immediate constant within the asm instruction.
protected boolean isElement
protected Variable elementIndex
protected Variable elementsParentVar
Should only be set in the case where isElement is true.
protected java.lang.String identifier
protected int lineNumDecl
| Constructor Detail |
|---|
public Variable(int numElements)
numElements - number of elements to be created, numElements=1 implies ATOMIC, numElements>1 implies ARRAY| Method Detail |
|---|
public boolean isConstant()
public java.lang.Object getValue()
public boolean isValueSet()
public void setValue(java.lang.String valueStr)
valueStr - public int getSizeType()
public int getArraySize()
public boolean isArray()
public boolean isElement()
public boolean isAtomic()
Atomic types include int, uint, float, byte, ubyte, complex, and string.
Non-atomic (array-types) include int_array, uint_array, ubyte_array, byte_array, and complex_array.
public java.lang.String getIdentifier()
public boolean isSameDataType(Variable otherVar)
otherVar: - the Variable to compare this to
public abstract boolean isNumeric()
public abstract boolean isNaturalNum()
public Variable getParentVariable()
public Variable getIndexVariable()
public abstract int getDataTypeByteSize()
public int getByteSize()
public void setIdentifier(java.lang.String newID)
newID - String to set identifier topublic abstract int getDataType()
public abstract java.lang.Object convertToObject(java.lang.String strValue)
strValue - the string expresion for the variable (i.e. "hello", "5", "3.4");
public abstract java.lang.Object convertToObject(java.lang.String strValue1,
java.lang.String strValue2)
strValue1 - the string expresion for the first variablestrValue2 - the string expression for the second variable
public int getVariableSizeType()
public void initVariable(int numElements)
public static Variable getNewArray(int parserTokenID,
java.lang.String identifier,
int arraySize,
int lineDecl)
parserTokenID - parser token id corresponding to wha tis listed in DSPLParserTokenTypes automatically generated by antleridentifier - the textual representation used to declare this variable within the source code of the programarraySize - the size of the arrayline - in the source file on which the array is declared
public static Variable getNewAtomic(int parserTokenID,
java.lang.String identifier,
int lineDecl,
boolean isConstant)
if isConstant is true, then the variable is a constant literal (i.e. "5")
else if isConstant is false, then a "normal" Variable is created (i.e. "int x;")
which will need a location in memory to be stored.
parserTokenID - identifier - lineDecl - isConstant - public static int getAntlrTypeFromVarType(int varType)
varType - public static int getAntlrTypeFromVarTypeArray(int varType)
public static Variable getNewAtomicElement(Variable parentVar,
Variable elementIndex,
int lineDecl)
throws java.lang.Exception
parentVar - parent variable array or complexelementIndex - 0-based index into the array or flag indicating real or imaginary component of ComplexlineDecl - line number where where array element is being used
java.lang.Exception - if elementIndex is outside of array bounds (0 --> (arraysize-1))
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||