本文整理汇总了C++中UlamType::getUlamTypeEnum方法的典型用法代码示例。如果您正苦于以下问题:C++ UlamType::getUlamTypeEnum方法的具体用法?C++ UlamType::getUlamTypeEnum怎么用?C++ UlamType::getUlamTypeEnum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UlamType
的用法示例。
在下文中一共展示了UlamType::getUlamTypeEnum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
const std::string NodeBinaryOpEqualShift::methodNameForCodeGen()
{
std::ostringstream methodname;
//methodname << "_Shift"; determined by each op
UlamType * nut = m_state.getUlamTypeByIndex(getNodeType());
// common part of name
ULAMTYPE etyp = nut->getUlamTypeEnum();
switch(etyp)
{
case Int:
case Unsigned:
case Bool:
case Unary:
case Bits:
methodname << UlamType::getUlamTypeEnumAsString(etyp);
break;
default:
m_state.abortUndefinedUlamPrimitiveType();
break;
};
methodname << nut->getTotalWordSize();
return methodname.str();
} //methodNameForCodeGen
示例2: explicitlyCastable
FORECAST UlamTypePrimitive::explicitlyCastable(UTI typidx)
{
FORECAST scr = UlamType::safeCast(typidx); //default
if(scr == CAST_CLEAR)
{
// primitives must be the same sizes when casting to a reference type
if(isReference() && !UlamType::checkReferenceCast(typidx))
scr = CAST_BAD;
// strings cannot be cast explicitly to other primitive types, except Void (t3961)
UlamType * vut = m_state.getUlamTypeByIndex(typidx);
ULAMTYPE valtypEnum = vut->getUlamTypeEnum();
if((getUlamTypeEnum() != Void) && ((valtypEnum == String) ^ (getUlamTypeEnum() == String)))
scr = CAST_BAD;
//only quarks may be cast to Ints, explicitly or not; requires toInt method (t3996)
if(valtypEnum == Class)
{
ULAMCLASSTYPE vclasstype = vut->getUlamClassType();
if(vclasstype != UC_QUARK)
scr = CAST_BAD;
}
}
return scr;
} //explicitlyCastable
示例3: printTypeAndName
void NodeVarRef::printTypeAndName(File * fp)
{
UTI vuti = m_varSymbol->getUlamTypeIdx();
UlamKeyTypeSignature vkey = m_state.getUlamKeyTypeSignatureByIndex(vuti);
UlamType * vut = m_state.getUlamTypeByIndex(vuti);
if(m_state.isConstantRefType(vuti))
fp->write(" constant"); //t41242,3
fp->write(" ");
if(vut->getUlamTypeEnum() != Class)
{
fp->write(vkey.getUlamKeyTypeSignatureNameAndBitSize(&m_state).c_str());
fp->write("&"); //<--the only difference!!!
}
else
fp->write(vut->getUlamTypeClassNameBrief(vuti).c_str()); //includes any &
fp->write(" ");
fp->write(getName());
s32 arraysize = m_state.getArraySize(vuti);
if(arraysize > NONARRAYSIZE)
{
fp->write("[");
fp->write_decimal(arraysize);
fp->write("]");
}
else if(arraysize == UNKNOWNSIZE)
{
fp->write("[UNKNOWN]");
}
} //printTypeAndName
示例4: checkAndLabelType
UTI NodeBinaryOpEqualArith::checkAndLabelType()
{
UTI nodeType = NodeBinaryOpEqual::checkAndLabelType();
UlamType * nut = m_state.getUlamTypeByIndex(nodeType);
// common part of name
ULAMTYPE enodetyp = nut->getUlamTypeEnum();
if(enodetyp == Bits)
{
// can happen with op-equal operations when both sides are the same type
MSG(getNodeLocationAsString().c_str(), "Arithmetic Operations are invalid on 'Bits' type", ERR);
nodeType = Nav;
}
if(enodetyp == Bool)
{
// can happen with op-equal operations when both sides are the same type
MSG(getNodeLocationAsString().c_str(), "Arithmetic Operations are invalid on 'Bool' type", ERR);
nodeType = Nav;
}
if((nodeType != Nav) && !nut->isScalar())
{
std::ostringstream msg;
msg << "Non-scalars require a loop for operator" << getName();
MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), ERR);
nodeType = Nav;
}
setNodeType(nodeType);
return nodeType;
} //checkAndLabelType
示例5: printPostfixValuesOfVariableDeclarations
// replaces NodeTypedef:printPostfix to learn the values of Class' storage in center site
void SymbolTypedef::printPostfixValuesOfVariableDeclarations(File * fp, s32 slot, u32 startpos, ULAMCLASSTYPE classtype)
{
UTI tuti = getUlamTypeIdx();
UlamKeyTypeSignature tkey = m_state.getUlamKeyTypeSignatureByIndex(tuti);
UlamType * tut = m_state.getUlamTypeByIndex(tuti);
fp->write(" typedef");
fp->write(" ");
if(tut->getUlamTypeEnum() != Class)
fp->write(tkey.getUlamKeyTypeSignatureNameAndBitSize(&m_state).c_str());
else
fp->write(tut->getUlamTypeNameBrief().c_str());
fp->write(" ");
fp->write(m_state.m_pool.getDataAsString(getId()).c_str());
s32 arraysize = m_state.getArraySize(tuti);
if(arraysize > NONARRAYSIZE)
{
fp->write("[");
fp->write_decimal(arraysize);
fp->write("]");
}
else if(arraysize == UNKNOWNSIZE)
{
fp->write("[UNKNOWN]");
}
fp->write("; ");
} //printPostfixValuesOfVariableDeclarations
示例6: switch
const std::string NodeBinaryOpEqualArith::methodNameForCodeGen()
{
std::ostringstream methodname;
//methodname << "_BitwiseOr"; determined by each op
UlamType * nut = m_state.getUlamTypeByIndex(getNodeType());
// common part of name
ULAMTYPE etyp = nut->getUlamTypeEnum();
switch(etyp)
{
case Int:
case Unsigned:
case Bool:
case Unary:
methodname << UlamType::getUlamTypeEnumAsString(etyp);
break;
case Bits:
default:
assert(0);
methodname << "NAV";
break;
};
methodname << nut->getTotalWordSize();
return methodname.str();
} //methodNameForCodeGen
示例7: switch
const std::string NodeBinaryOpCompare::methodNameForCodeGen()
{
std::ostringstream methodname;
//methodname << "_BitwiseOr"; determined by each op
UlamType * lut = m_state.getUlamTypeByIndex(m_nodeLeft->getNodeType());
// common part of name
ULAMTYPE etyp = lut->getUlamTypeEnum();
switch(etyp)
{
case Int:
methodname << "Int";
break;
case Unsigned:
methodname << "Unsigned";
break;
case Bits:
methodname << "Bits";
break;
case Bool:
methodname << "Bool";
break;
case String:
methodname << "String";
break;
default:
m_state.abortUndefinedUlamPrimitiveType();
methodname << "NAV";
break;
};
methodname << lut->getTotalWordSize();
return methodname.str();
} // methodNameForCodeGen
示例8: checkAndLabelType
UTI NodeBinaryOpCompare::checkAndLabelType()
{
assert(m_nodeLeft && m_nodeRight);
UTI leftType = m_nodeLeft->checkAndLabelType();
UTI rightType = m_nodeRight->checkAndLabelType();
UlamType * lut = m_state.getUlamTypeByIndex(leftType);
if((lut->getUlamTypeEnum() == Class))
{
Node * newnode = buildOperatorOverloadFuncCallNode();
if(newnode)
{
AssertBool swapOk = Node::exchangeNodeWithParent(newnode);
assert(swapOk);
m_nodeLeft = NULL; //recycle as memberselect
m_nodeRight = NULL; //recycle as func call arg
delete this; //suicide is painless..
return newnode->checkAndLabelType(); //t41109
}
//else should fail again as non-primitive;
} //done
UTI newType = calcNodeType(leftType, rightType); //for casting
if(m_state.isComplete(newType))
{
u32 errCnt = 0;
if(UlamType::compareForMakingCastingNode(rightType, newType, m_state) != UTIC_SAME)
{
if(!Node::makeCastingNode(m_nodeRight, newType, m_nodeRight))
errCnt++;
}
if(UlamType::compareForMakingCastingNode(leftType, newType, m_state) != UTIC_SAME)
{
if(!Node::makeCastingNode(m_nodeLeft, newType, m_nodeLeft))
errCnt++;
}
if(errCnt)
newType = Nav;
else
newType = Bool; //always Bool (default size) for node; after castings!
}
setNodeType(newType);
if(newType == Hzy) m_state.setGoAgain(); //nolonger needed in calcnodetypes
Node::setStoreIntoAble(TBOOL_FALSE);
//still may need casting (e.g. unary compared to an int) before constantfolding
if((newType != Nav) && isAConstant() && m_nodeLeft->isReadyConstant() && m_nodeRight->isReadyConstant())
return NodeBinaryOp::constantFold();
return newType;
} //checkAndLabelType
示例9: convertValueToANonPrettyString
bool SymbolWithValue::convertValueToANonPrettyString(u64 varg, UTI tuti, std::string& vstr, CompilerState & state)
{
std::ostringstream ostr;
UlamType * tut = state.getUlamTypeByIndex(tuti);
s32 bs = tut->getBitSize();
ULAMTYPE etyp = tut->getUlamTypeEnum();
switch(etyp)
{
case Int:
{
if(bs <= MAXBITSPERINT)
{
s32 sval = _Int32ToInt32((u32) varg, bs, MAXBITSPERINT);
ostr << sval;
}
else if(bs <= MAXBITSPERLONG)
{
s64 sval = _Int64ToInt64(varg, bs, MAXBITSPERLONG);
ostr << sval;
}
else
state.abortGreaterThanMaxBitsPerLong();
}
break;
case Unsigned:
{
if( bs <= MAXBITSPERINT)
ostr << (u32) varg << "u";
else if( bs <= MAXBITSPERLONG)
ostr << varg << "u";
else
state.abortGreaterThanMaxBitsPerLong();
}
break;
case Unary:
case Bool:
case Bits:
case Class:
{
ostr << "0x" << std::hex << varg;
}
break;
case String:
{
std::string fstr = state.getDataAsUnFormattedUserString((u32) varg);
u32 flen = fstr.length() - 1; //exclude null terminator
for(u32 i = 0; i < flen; i++)
ostr << std::hex << std::setfill('0') << std::setw(2) << (u32) fstr[i];
}
break;
default:
state.abortUndefinedUlamType();
};
vstr = ostr.str();
return true;
} //convertValueToANonPrettyString (static helper)
示例10: checkAndLabelType
UTI NodeControl::checkAndLabelType()
{
assert(m_nodeCondition && m_nodeBody);
UTI newType = Bool;
ULAMTYPE newEnumTyp = Bool;
// condition should be a bool, safely cast
UTI cuti = m_nodeCondition->checkAndLabelType();
if(m_state.okUTItoContinue(cuti) && m_state.isComplete(cuti))
{
assert(m_state.isScalar(cuti));
UlamType * cut = m_state.getUlamTypeByIndex(cuti);
ULAMTYPE ctypEnum = cut->getUlamTypeEnum();
if(ctypEnum != newEnumTyp)
{
if(checkSafeToCastTo(cuti, newType))
{
if(!Node::makeCastingNode(m_nodeCondition, newType, m_nodeCondition))
newType = Nav;
}
//else not safe, newType changed
}
else
{
//caution: c&l called multiple times
//always cast: Bools are maintained as unsigned in gen code,
//until c-bool is needed
if(cuti != newType)
{
if(checkSafeToCastTo(cuti, newType))
{
if(!Node::makeCastingNode(m_nodeCondition, cuti, m_nodeCondition))
newType = Nav;
else
newType = cuti;
}
}
}
}
else
{
newType = Hzy; //was = cuti;
m_state.setGoAgain();
}
m_nodeBody->checkAndLabelType(); //side-effect
setNodeType(newType); //stays the same
Node::setStoreIntoAble(TBOOL_FALSE);
return getNodeType();
} //checkAndLabelType
示例11: safeCast
FORECAST UlamTypeInt::safeCast(UTI typidx)
{
FORECAST scr = UlamType::safeCast(typidx);
if(scr != CAST_CLEAR)
return scr;
bool brtn = true;
UlamType * vut = m_state.getUlamTypeByIndex(typidx);
s32 valbitsize = m_state.getBitSize(typidx);
s32 bitsize = getBitSize();
ULAMTYPE valtypEnum = vut->getUlamTypeEnum();
switch(valtypEnum)
{
case Int:
brtn = (bitsize >= valbitsize);
break;
case Unsigned:
brtn = (bitsize > valbitsize);
break;
case Unary:
brtn = (bitsize > (s32) _getLogBase2(valbitsize) + 1);
break;
case Bool:
case Bits:
case Void:
case UAtom:
brtn = false;
break;
case Class:
{
//must be Quark! treat as Int if it has a toInt method
if(vut->isNumericType())
brtn = (bitsize >= MAXBITSPERINT);
else
{
std::ostringstream msg;
msg << "Class: ";
msg << m_state.getUlamTypeNameBriefByIndex(typidx).c_str();
msg << " is not a numeric type and cannot be safely cast to an Int";
MSG(m_state.getFullLocationAsString(m_state.m_locOfNextLineText).c_str(),msg.str().c_str(), ERR);
brtn = false;
}
}
break;
default:
assert(0);
//std::cerr << "UlamTypeInt (cast) error! Value Type was: " << valtypidx << std::endl;
brtn = false;
};
return brtn ? CAST_CLEAR : CAST_BAD;
} //safeCast
示例12: castThyselfToResultType
UTI NodeBinaryOpArithRemainder::castThyselfToResultType(UTI rt, UTI lt, UTI newType)
{
UTI nuti = newType;
//because the result bitsize for mod should be the right bitsize
// create a cast! combining newType's base type and right resultbitsize.
// could be the same, or "unsafe".
if(m_state.okUTItoContinue(newType) && m_state.isComplete(newType))
{
UlamType * newut = m_state.getUlamTypeByIndex(newType);
ULAMTYPE typEnum = newut->getUlamTypeEnum();
u32 convertSize = m_state.getUlamTypeByIndex(rt)->bitsizeToConvertTypeTo(typEnum);
u32 enumStrIdx = m_state.m_pool.getIndexForDataString(UlamType::getUlamTypeEnumAsString(typEnum));
UlamKeyTypeSignature tokey(enumStrIdx, convertSize, NONARRAYSIZE);
ULAMCLASSTYPE newclasstype = newut->getUlamClassType();
nuti = m_state.makeUlamType(tokey, typEnum, newclasstype);
if(UlamType::compareForMakingCastingNode(nuti, newType, m_state) != UTIC_SAME) //not same, or dontknow
{
NNO pno = Node::getYourParentNo(); //save
assert(pno);
//not using use makeCastingNode since don't want recursive c&l call
Node * castNode = Node::newCastingNode(this, nuti);
Node * parentNode = m_state.findNodeNoInThisClass(pno);
if(!parentNode)
{
std::ostringstream msg;
msg << "Remainder cast cannot be exchanged at this time while compiling class: ";
msg << m_state.getUlamTypeNameBriefByIndex(m_state.getCompileThisIdx()).c_str();
msg << " Parent required";
MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), DEBUG);
assert(0); //parent required
}
AssertBool swapOk = parentNode->exchangeKids(this, castNode);
assert(swapOk);
std::ostringstream msg;
msg << "Exchanged kids! of parent of binary operator" << getName();
msg << ", with a cast to type: ";
msg << m_state.getUlamTypeNameBriefByIndex(nuti).c_str();
msg << " while compiling class: ";
msg << m_state.getUlamTypeNameBriefByIndex(m_state.getCompileThisIdx()).c_str();
MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), DEBUG);
castNode->setYourParentNo(pno); //inverts normal update lineage
setYourParentNo(castNode->getNodeNo());
}
}
return nuti;
} //castThyselfToResultType
示例13: safeCast
FORECAST UlamTypePrimitiveInt::safeCast(UTI typidx)
{
FORECAST scr = UlamType::safeCast(typidx);
if(scr != CAST_CLEAR)
return scr;
bool brtn = true;
UlamType * vut = m_state.getUlamTypeByIndex(typidx);
s32 valbitsize = m_state.getBitSize(typidx);
s32 bitsize = getBitSize();
ULAMTYPE valtypEnum = vut->getUlamTypeEnum();
switch(valtypEnum)
{
case Int:
brtn = (bitsize >= valbitsize);
break;
case Unsigned:
brtn = (bitsize > valbitsize);
break;
case Unary:
brtn = (bitsize > (s32) _getLogBase2(valbitsize) + 1);
break;
case Bool:
case Bits:
case Void:
case UAtom:
brtn = false;
break;
case Class:
{
//must be Quark! treat as Int if it has a toInt method
if(vut->isNumericType())
brtn = (bitsize >= MAXBITSPERINT);
else
brtn = false; //t41131 called by matching args (no error msg please)
}
break;
default:
m_state.abortUndefinedUlamType();
//std::cerr << "UlamTypePrimitiveInt (cast) error! Value Type was: " << valtypidx << std::endl;
brtn = false;
};
return brtn ? CAST_CLEAR : CAST_BAD;
} //safeCast
示例14: printPostfixValueArrayStringAsComment
void SymbolWithValue::printPostfixValueArrayStringAsComment(File * fp)
{
BV8K dval;
bool oktoprint = getValueReadyToPrint(dval);
UTI tuti = getUlamTypeIdx();
UlamType * tut = m_state.getUlamTypeByIndex(tuti);
bool isString = (tut->getUlamTypeEnum() == String); //t3953
assert(isString);
if(!oktoprint)
{
fp->write("// ");
fp->write(getMangledName().c_str());
fp->write(": NONREADYCONSTARRAY OF STRINGS"); GCNL;
return;
}
//like the code generated in CS::genCodeClassDefaultConstantArray
u32 uvals[ARRAY_LEN8K];
dval.ToArray(uvals);
u32 nwords = tut->getTotalNumberOfWords();
//indented comments of string value items (one per line); e.g. t3953,4
for(u32 w = 0; w < nwords; w++)
{
m_state.indent(fp);
fp->write("// ");
fp->write("[");
fp->write_decimal_unsigned(w);
fp->write("] = ");
fp->write(m_state.getDataAsFormattedUserString(uvals[w]).c_str());
fp->write("\n");
}
m_state.indent(fp);
fp->write("// = ");
fp->write(getMangledName().c_str());
fp->write("[");
fp->write_decimal_unsigned(nwords);
fp->write("]");
GCNL;
} //printPostfixValueArrayStringAsComment
示例15: checkAbstractInstanceErrors
void NodeVarRef::checkAbstractInstanceErrors()
{
//unlike NodeVarDecl, an abstract class can be a reference!
UTI nuti = getNodeType();
UlamType * nut = m_state.getUlamTypeByIndex(nuti);
if(nut->getUlamTypeEnum() == Class)
{
SymbolClass * csym = NULL;
AssertBool isDefined = m_state.alreadyDefinedSymbolClass(nuti, csym);
assert(isDefined);
if(csym->isAbstract())
{
std::ostringstream msg;
msg << "Instance of Abstract Class ";
msg << m_state.getUlamTypeNameBriefByIndex(nuti).c_str();
msg << " used with reference variable symbol name '";
msg << getName() << "'";
MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), INFO);
}
}
} //checkAbstractInstanceErrors