coins.ir.hir
Class ExpImpl

java.lang.Object
  extended bycoins.ir.hir.HIR_Impl
      extended bycoins.ir.hir.ExpImpl
All Implemented Interfaces:
java.lang.Cloneable, Exp, HasStringObject, HIR, HIR0, IR, IR0
Direct Known Subclasses:
ComplexExp, ExpListExpImpl, FortranCharacterExp, FunctionExpImpl, NullNodeImpl, PhiExpImpl, PointedExpImpl, QualifiedExpImpl, SubscriptedExpImpl, SymNodeImpl

public class ExpImpl
extends HIR_Impl
implements Exp

ExpImpl HIR expression class. The expression class Exp is a subclass of HIR.


Field Summary
 
Fields inherited from class coins.ir.hir.HIR_Impl
fAdditionalChild, fChildCount, fChildNode1, fChildNode2, fDbgLevel, fHirAnnex, fOperator, fParentNode, fType, hirRoot, inversionTable, machineParam, sourceLanguage
 
Fields inherited from interface coins.ir.hir.HIR
OP_CODE_NAME, OP_CODE_NAME_DENSE
 
Fields inherited from interface coins.ir.IR
OP_INF, OP_LIST, OP_PROG, OP_SUBP_DEF
 
Fields inherited from interface coins.ir.hir.HIR0
FLAG_C_PTR, FLAG_CONST_EXP, FLAG_INIT_BLOCK, FLAG_LOOP_WITH_CONDITIONAL_INIT, FLAG_NOCHANGE, FLAG_NONTERMINAL, OP_ADD, OP_ADD_ASSIGN, OP_ADDR, OP_AND, OP_AND_ASSIGN, OP_ARROW, OP_ASM, OP_ASSIGN, OP_BLOCK, OP_CALL, OP_CMP_EQ, OP_CMP_GE, OP_CMP_GT, OP_CMP_LE, OP_CMP_LT, OP_CMP_NE, OP_COMMA, OP_CONST, OP_CONTENTS, OP_CONV, OP_DECAY, OP_DIV, OP_DIV_ASSIGN, OP_ELEM, OP_ENCLOSE, OP_EQ_ZERO, OP_EXP_STMT, OP_EXPLIST, OP_EXPREPEAT, OP_FOR, OP_IF, OP_INDEX, OP_INDEXED_LOOP, OP_JUMP, OP_LABEL, OP_LABEL_DEF, OP_LABELED_STMT, OP_LG_AND, OP_LG_OR, OP_MOD, OP_MOD_ASSIGN, OP_MULT, OP_MULT_ASSIGN, OP_NEG, OP_NOT, OP_NULL, OP_OFFSET, OP_OR, OP_OR_ASSIGN, OP_PARAM, OP_PHI, OP_POST_DECR, OP_POST_INCR, OP_PRE_DECR, OP_PRE_INCR, OP_QUAL, OP_REPEAT, OP_RETURN, OP_SELECT, OP_SEQ, OP_SETDATA, OP_SHIFT_L_ASSIGN, OP_SHIFT_LL, OP_SHIFT_R, OP_SHIFT_R_ASSIGN, OP_SHIFT_RL, OP_SIZEOF, OP_STMT, OP_STMT_UPPER, OP_SUB, OP_SUB_ASSIGN, OP_SUBP, OP_SUBS, OP_SWITCH, OP_SYM, OP_TYPE, OP_UNDECAY, OP_UNTIL, OP_VAR, OP_WHILE, OP_XOR, OP_XOR_ASSIGN
 
Constructor Summary
ExpImpl(HirRoot pHirRoot)
           
ExpImpl(HirRoot pHirRoot, int pOperator)
           
ExpImpl(HirRoot pHirRoot, int pOperator, Exp pExp1)
          Build an instance of unary expression.
ExpImpl(HirRoot pHirRoot, int pOperator, Exp pExp1, Exp pExp2)
          Build an instance of binary expression.
ExpImpl(HirRoot pHirRoot, int pOperator, Exp pExp1, Exp pExp2, Exp pExp3)
           
 
Method Summary
 void accept(HirVisitor pVisitor)
          accept Acceptor used in HIR visitor.
 Exp adjustTypesOfBinaryOperands(Exp pExp1, Exp pExp2)
          Adjust the types of binary operands according to the C language specifications (See ISO/IEC 9899-1999 Programming language C section 6.3.1.8).
 Const evaluate()
          Evaluate "this" expression.
 double evaluateAsDouble()
          evaluateAsDouble Evaluate "this" expression as double.
 float evaluateAsFloat()
          evaluateAsFloat Evaluate "this" expression as float.
 int evaluateAsInt()
          evaluateAsInt Evaluate "this" expression as int.
 long evaluateAsLong()
          Evaluate "this" expression as long.
 SubpType findSubpType()
          findSubpType Find SubpType represented by this expression.
 Exp fold()
          Fold "this" expression.
 IrList getActualParamList()
           
 Exp getArrayExp()
          getArrayExp (##2) getSubscriptExp getElemSizeExp (##2) Get a component of a subscripted variable.
 Const getConstSym()
          getConstSym Get constant symbol attached to this node.
 Elem getElem()
          getElem Get symbol of spefified class from SymNode.
 Exp getElemSizeExp()
           
 Exp getExp1()
          getExp1 Get source operand 1 from unary or binary expression.
 Exp getExp2()
          getExp2 Get source operand 2 from binary expression.
 Label getLabel()
          getLabel Get symbol of spefified class from SymNode.
 Elem getPointedElem()
           
 Exp getPointerExp()
          getPointerExp getPointedElem Get a component of pointed variable expression.
 Elem getQualifiedElem()
           
 Exp getQualifierExp()
          getQualifier getQualifiedElem Get a component of qualified variable expression.
 Subp getSubp()
          getSubp Get symbol of spefified class from SymNode.
 Exp getSubpSpec()
          getSubpSpec (##2) getActualParamList Get a component expression of the function expression.
 Exp getSubscriptExp()
           
 Sym getSym()
          getSym Get symbol from SymNode.
 java.lang.String getValueString()
          getValueString //##40 Evaluate this subtree and return the result as a string.
 Var getVar()
          getVar Get symbol of specified class from SymNode.
 Stmt initiateArray(Exp pArray, Exp pInitExp, Exp pFrom, Exp pTo, Subp pSubp)
          initiateArray //##15 Create loop statement to initiate all elements of the array pArray and append it to the initiation block of subprogram pSubp.
 boolean isEvaluable()
          isEvaluable: See if "this" expression can be currently evaluated or not.
 boolean isLValue()
           
 
Methods inherited from class coins.ir.hir.HIR_Impl
addInf, addrExp, asmStmt, assignStmt, blockStmt, callStmt, checkLinkage, clone, conditionalExp, conditionalExp1, constNode, contains, contentsExp, convExp, copyInfListFrom, copyWithOperands, copyWithOperandsChangingLabels, cutParentLink, cutParentLink, decayExp, elemNode, exp, exp, exp, expList, expRepeat, expStmt, falseNode, fatalError, finishHir, flagsAreAllFalse, forStmt, forStmt, functionExp, getChild, getChild1, getChild2, getChildCount, getChildNumber, getClone, getExpId, getFlag, getFlagBox, getFlowAnalSym, getIndentSpace, getIndex, getInf, getInfList, getInfString, getIrName, getNextNode, getNextNodeSeeingAncestor, getNextStmt, getOperator, getParent, getResultOperand, getResultVar, getSourceNode, getSourceNode1, getSourceNode2, getStmtContainingThisNode, getSymOrExpId, getType, getWork, hirClone, hirIterator, hirList, hirNodeClone, hirSeq, hirSeq, hirSeq, ifStmt, indexedLoopStmt, indexedLoopStmt, infStmt, infStmt, intConstNode, intConstNode, irList, irList, isEmpty, isHIR, isLIR, isSameAs, isStmt, isSym, isTerminal, isTree, isTree, jumpStmt, labelDef, labeledStmt, labelNode, nullNode, nullStmt, offsetConstNode, phiExp, pointedExp, print, print, program, qualifiedExp, removeInf, repeatStmt, repeatStmt, replaceOperator, replaceResultOperand, replaceResultVar, replaceSource, replaceSource1, replaceSource2, replaceThisNode, returnStmt, returnStmt, setChild, setChild1, setChild2, setChildren, setChildren, setChildren, setChildren, setDataStmt, setFlag, setIndex, setIndexNumberToAllNodes, setIndexNumberToAllNodes, setIndexNumberToAllNodes2, setParameters, setParent, setType, setWork, severeError, sizeofExp, sizeofExp, slightError, subpDefinition, subpDefinition, subpDefinition, subpIterator, subpNode, subscriptedExp, subscriptedExp, switchStmt, symNode, toString, toStringDetail, toStringShort, toStringWithChildren, trueNode, typeNode, undecayExp, undecayExp, undecayExp, undecayExp, varNode, warinig, whileStmt, whileStmt, withInf
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface coins.ir.hir.HIR
addrExp, asmStmt, checkLinkage, conditionalExp, contains, copyInfListFrom, cutParentLink, exp, expList, expRepeat, forStmt, getExpId, getFlowAnalSym, getIndentSpace, getInfString, getIrName, getSourceNode, getSourceNode1, getSourceNode2, getSymOrExpId, getWork, hirNodeClone, hirSeq, hirSeq, indexedLoopStmt, indexedLoopStmt, infStmt, infStmt, intConstNode, irList, isEmpty, isStmt, isTree, nullNode, nullStmt, offsetConstNode, phiExp, repeatStmt, replaceSource, replaceSource1, replaceSource2, returnStmt, setChild1, setChild2, setChildren, setChildren, setDataStmt, setIndex, setIndexNumberToAllNodes, setParent, setType, setWork, subpDefinition, subpIterator, subscriptedExp, toString, toStringDetail, toStringShort, toStringWithChildren, undecayExp, undecayExp, undecayExp, whileStmt
 
Methods inherited from interface coins.ir.IR
addInf, getChild1, getChild2, getInf, getInfList, getParent, print, print, removeInf
 
Methods inherited from interface coins.ir.IR0
getChild, getChildCount, getIndex, getOperator, setChild
 
Methods inherited from interface coins.ir.hir.HIR0
assignStmt, blockStmt, callStmt, constNode, contentsExp, convExp, copyWithOperands, copyWithOperandsChangingLabels, decayExp, elemNode, exp, exp, expStmt, falseNode, finishHir, forStmt, functionExp, getChildNumber, getFlag, getFlagBox, getNextStmt, getStmtContainingThisNode, getType, hirClone, hirIterator, hirList, hirSeq, ifStmt, intConstNode, irList, isSameAs, jumpStmt, labelDef, labeledStmt, labelNode, pointedExp, print, program, qualifiedExp, repeatStmt, replaceThisNode, returnStmt, setFlag, setIndexNumberToAllNodes, sizeofExp, sizeofExp, subpDefinition, subpNode, subscriptedExp, switchStmt, symNode, trueNode, undecayExp, varNode, whileStmt
 

Constructor Detail

ExpImpl

public ExpImpl(HirRoot pHirRoot)

ExpImpl

public ExpImpl(HirRoot pHirRoot,
               int pOperator)

ExpImpl

public ExpImpl(HirRoot pHirRoot,
               int pOperator,
               Exp pExp1)
Build an instance of unary expression. The type of resultant expression is set according to the rule described in the HIR specifications, however, it may be necessary to do language-wise treatment. In such case, front-end part of the language should set type after creating the instance of Exp. (In C, expressions related to pointer and vector are specially treated in C front end ToHirC.)

Parameters:
pHirRoot - Specify the current instance of HirRoot.
pOperator - Operator of the unary expression.
pExp1 - Operand expression.

ExpImpl

public ExpImpl(HirRoot pHirRoot,
               int pOperator,
               Exp pExp1,
               Exp pExp2)
Build an instance of binary expression. The type of resultant expression is set according to the rule described in the HIR specifications, however, it may be necessary to do language-wise treatment. In such case, front-end part of the language should set type after creating the instance of Exp. (In C, expressions related to pointer and vector are specially treated in C front end ToHirC.)

Parameters:
pHirRoot - Specify the current instance of HirRoot.
pOperator - Operator of the binary expression.
pExp1 - Operand 1 expression.

ExpImpl

public ExpImpl(HirRoot pHirRoot,
               int pOperator,
               Exp pExp1,
               Exp pExp2,
               Exp pExp3)
Method Detail

getConstSym

public Const getConstSym()
getConstSym Get constant symbol attached to this node. "this" should be a constant node.

Specified by:
getConstSym in interface Exp
Returns:
constant symbol attached to this node.

getSym

public Sym getSym()
getSym Get symbol from SymNode. "this" should be a SymNode (either VarNode, SubpNode, LabelNode, ElemNode, or FieldNode). (##2)

Specified by:
getSym in interface IR
Overrides:
getSym in class HIR_Impl
Returns:
the symbol attached to the node (either Var, Subp, Label, Elem, or Field).

getVar

public Var getVar()
Description copied from interface: Exp
getVar Get symbol of specified class from SymNode. (##2) "this" should be a SymNode.

Specified by:
getVar in interface Exp
Returns:
the symbol of specified class attached to the node. If the symbol is not attached to the node or if its class is not the specified class, then return null.

getSubp

public Subp getSubp()
Description copied from interface: Exp
getSubp Get symbol of spefified class from SymNode. (##2) "this" should be a SymNode.

Specified by:
getSubp in interface Exp
Returns:
the symbol of specified class attached to the node. If the symbol is not attached to the node or if its class is not the specified class, then return null.

getLabel

public Label getLabel()
Description copied from interface: Exp
getLabel Get symbol of spefified class from SymNode. (##2) "this" should be a SymNode.

Specified by:
getLabel in interface Exp
Returns:
the symbol of specified class attached to the node. If the symbol is not attached to the node or if its class is not the specified class, then return null.

getElem

public Elem getElem()
Description copied from interface: Exp
getElem Get symbol of spefified class from SymNode. (##2) "this" should be a SymNode.

Specified by:
getElem in interface Exp
Returns:
the symbol of specified class attached to the node. If the symbol is not attached to the node or if its class is not the specified class, then return null.

getExp1

public Exp getExp1()
getExp1 Get source operand 1 from unary or binary expression. "this" should be either unary or binary expression.

Specified by:
getExp1 in interface Exp
Returns:
the source operand 1 expression of this node.

getExp2

public Exp getExp2()
getExp2 Get source operand 2 from binary expression. "this" should be a binary expression.

Specified by:
getExp2 in interface Exp
Returns:
the source operand 2 expression of this node.

getArrayExp

public Exp getArrayExp()
Description copied from interface: Exp
getArrayExp (##2) getSubscriptExp getElemSizeExp (##2) Get a component of a subscripted variable. "this" should be a node built by buildSubscriptedVar method.

Specified by:
getArrayExp in interface Exp
Returns:
a component expression of this subscripted variable.

getSubscriptExp

public Exp getSubscriptExp()
Specified by:
getSubscriptExp in interface Exp

getElemSizeExp

public Exp getElemSizeExp()
Specified by:
getElemSizeExp in interface Exp

getPointerExp

public Exp getPointerExp()
Description copied from interface: Exp
getPointerExp getPointedElem Get a component of pointed variable expression. "this" should be a node built by buildPointedVar method.

Specified by:
getPointerExp in interface Exp
Returns:
a component expression of this pointed variable.

getPointedElem

public Elem getPointedElem()
Specified by:
getPointedElem in interface Exp

getQualifierExp

public Exp getQualifierExp()
Description copied from interface: Exp
getQualifier getQualifiedElem Get a component of qualified variable expression. "this" should be a node built by BuildQualifiedVar method.

Specified by:
getQualifierExp in interface Exp
Returns:
a component of "this" QualifiedVar expression. (##2)

getQualifiedElem

public Elem getQualifiedElem()
Specified by:
getQualifiedElem in interface Exp

getSubpSpec

public Exp getSubpSpec()
getSubpSpec (##2) getActualParamList Get a component expression of the function expression. (##2) "this" should be a node built by functionExp. getSubpSpec return the expression specifying the subprogram to be called (pSubpSpec). (##2) getActualParamList return the actual parameter list (pParamList). If this has no parameter, then return null.

Specified by:
getSubpSpec in interface Exp

getActualParamList

public IrList getActualParamList()
Specified by:
getActualParamList in interface Exp

findSubpType

public SubpType findSubpType()
findSubpType Find SubpType represented by this expression. If this is SubpNode then return SubpType pointed by this node type, else decompose this expression to find Subpnode. If illegal type is encountered, return null.

Specified by:
findSubpType in interface Exp

isEvaluable

public boolean isEvaluable()
isEvaluable: See if "this" expression can be currently evaluated or not.

Specified by:
isEvaluable in interface Exp
Returns:
true if this expression can be evaluated as constant value at the invocation of this method, false otherwise.

evaluate

public Const evaluate()
Evaluate "this" expression.

Specified by:
evaluate in interface Exp
Returns:
constant as the result of evaluation or null(when failing in the evaluation)

evaluateAsInt

public int evaluateAsInt()
Description copied from interface: Exp
evaluateAsInt Evaluate "this" expression as int. "this" should be an evaluable expression. If not, this method returns 0. It is strongly recommended to confirm isEvaluable() returns true for this expression before calling this method.

Specified by:
evaluateAsInt in interface Exp
Returns:
integer value as the result of evaluation.

evaluateAsLong

public long evaluateAsLong()
Description copied from interface: Exp
Evaluate "this" expression as long. "this" should be an evaluable expression. If not, this method returns 0.

Specified by:
evaluateAsLong in interface Exp
Returns:
long value as the result of evaluation.

evaluateAsFloat

public float evaluateAsFloat()
Description copied from interface: Exp
evaluateAsFloat Evaluate "this" expression as float. "this" should be an evaluable expression. If not, this method returns 0.0. It is strongly recommended to confirm isEvaluable() returns true for this expression before calling this method.

Specified by:
evaluateAsFloat in interface Exp
Returns:
float value as the result of evaluation.

evaluateAsDouble

public double evaluateAsDouble()
Description copied from interface: Exp
evaluateAsDouble Evaluate "this" expression as double. "this" should be an evaluable expression. If not, this method returns 0.0. It is strongly recommended to confirm isEvaluable() returns true for this expression before calling this method.

Specified by:
evaluateAsDouble in interface Exp
Returns:
float value as the result of evaluation.

adjustTypesOfBinaryOperands

public Exp adjustTypesOfBinaryOperands(Exp pExp1,
                                       Exp pExp2)
Description copied from interface: Exp
Adjust the types of binary operands according to the C language specifications (See ISO/IEC 9899-1999 Programming language C section 6.3.1.8). The result is an expression (HIR.OP_SEQ, adjusted_operand1, adjusted_operand2). The operands can be get by ((HIR)lResult.getChild1()).copyWithOperands() ((HIR)lResult.getChild2()).copyWithOperands()

Specified by:
adjustTypesOfBinaryOperands in interface Exp
Parameters:
pExp1 - operand 1.
pExp2 - operand 2.
Returns:
(HIR.OP_SEQ, adjusted_operand1, adjusted_operand2)

fold

public Exp fold()
Fold "this" expression. evaluate() is called by recursive. If the evaluation succeeded, former node is substituted for the constant node generated as evaluation result.

Specified by:
fold in interface Exp
Returns:
constant as the result of evaluation or null (when failing in the evaluation)

initiateArray

public Stmt initiateArray(Exp pArray,
                          Exp pInitExp,
                          Exp pFrom,
                          Exp pTo,
                          Subp pSubp)
Description copied from interface: Exp
initiateArray //##15 Create loop statement to initiate all elements of the array pArray and append it to the initiation block of subprogram pSubp. The initiation statement to be created for pSubp is for (i = pFrom; i <= pTo; i++) pArray[i] = pInitExp; If pSubp is null, set-data statement is generated.

Specified by:
initiateArray in interface Exp
Parameters:
pArray - array variable expression.
pInitExp - initial value to be set.
pFrom - array index start position
pTo - array index end position
pSubp - subprogram containing the initiation statement. null for global variable initiation.
Returns:
the loop statement to set initial value.

getValueString

public java.lang.String getValueString()
Description copied from interface: Exp
getValueString //##40 Evaluate this subtree and return the result as a string. If the result is constant, then return the string representing the constant. If the result is not a constant, then return a string representing the resultant expression. It is strongly recommended to confirm isEvaluable() returns true for this expression before calling this method.

Specified by:
getValueString in interface Exp
Returns:
a string representing the evaluated result.

isLValue

public boolean isLValue()

accept

public void accept(HirVisitor pVisitor)
Description copied from interface: HIR0
accept Acceptor used in HIR visitor. See HirVisitor, HirVisitorModel1, HirVisitormodel2.

Specified by:
accept in interface HIR0
Overrides:
accept in class HIR_Impl