本文整理汇总了C++中UlamType::getDataAsString方法的典型用法代码示例。如果您正苦于以下问题:C++ UlamType::getDataAsString方法的具体用法?C++ UlamType::getDataAsString怎么用?C++ UlamType::getDataAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UlamType
的用法示例。
在下文中一共展示了UlamType::getDataAsString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: genCodeReadIntoATmpVar
void NodeCast::genCodeReadIntoATmpVar(File * fp, UlamValue& uvpass)
{
// e.g. called by NodeFunctionCall on a NodeTerminal..
if(!needsACast())
{
return m_node->genCodeReadIntoATmpVar(fp, uvpass);
}
UTI nuti = getNodeType();
UlamType * nut = m_state.getUlamTypeByIndex(nuti);
UTI vuti = uvpass.getUlamValueTypeIdx();
bool isTerminal = false;
s32 tmpVarNum = 0;
if(vuti == Ptr)
{
tmpVarNum = uvpass.getPtrSlotIndex();
vuti = uvpass.getPtrTargetType(); //replace
}
else
{
// an immediate terminal value
isTerminal = true;
}
if(nuti == vuti)
return; //nothing to do!
UlamType * vut = m_state.getUlamTypeByIndex(vuti); //after vuti replacement
ULAMCLASSTYPE nclasstype = nut->getUlamClass();
ULAMCLASSTYPE vclasstype = vut->getUlamClass();
//handle element-atom and atom-element casting differently:
// handle element->quark, atom->quark, not quark->element or quark->atom
if(nuti == UAtom || vuti == UAtom || vclasstype == UC_ELEMENT || vclasstype == UC_QUARK)
{
//only to be nclasstype quark makes sense!!! check first, one might be element
if(nclasstype == UC_QUARK || vclasstype == UC_QUARK)
return genCodeCastAtomAndQuark(fp, uvpass);
if(nclasstype == UC_ELEMENT || vclasstype == UC_ELEMENT)
return genCodeCastAtomAndElement(fp, uvpass);
{
std::ostringstream msg;
msg << "Casting 'incomplete' types: ";
msg << m_state.getUlamTypeNameByIndex(nuti).c_str();
msg << "(UTI" << nuti << ") to be " << m_state.getUlamTypeNameByIndex(vuti).c_str();
msg << "(UTI" << vuti << ")";
MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), DEBUG);
return;
}
}
s32 tmpVarCastNum = m_state.getNextTmpVarNumber();
m_state.indent(fp);
fp->write("const ");
fp->write(nut->getTmpStorageTypeAsString().c_str()); //e.g. u32, s32, u64, etc.
fp->write(" ");
fp->write(m_state.getTmpVarAsString(nuti, tmpVarCastNum).c_str());
fp->write(" = ");
// write the cast method (e.g. _Unsigned32ToInt32, _Int32ToUnary32, etc..)
fp->write(nut->castMethodForCodeGen(vuti).c_str());
fp->write("(");
if(isTerminal)
{
s32 len = m_state.getBitSize(vuti);
assert(len != UNKNOWNSIZE);
if(len <= MAXBITSPERINT)
{
u32 data = uvpass.getImmediateData(m_state);
char dstr[40];
vut->getDataAsString(data, dstr, 'z');
fp->write(dstr);
}
else if(len <= MAXBITSPERLONG)
{
u64 data = uvpass.getImmediateDataLong(m_state);
char dstr[70];
vut->getDataLongAsString(data, dstr, 'z');
fp->write(dstr);
}
else
assert(0);
}
else
{
fp->write(m_state.getTmpVarAsString(nuti, tmpVarNum).c_str());
}
fp->write(", ");
assert(!(nuti == UAtom || vuti == UAtom));
//LENGTH of node being casted (Uh_AP_mi::LENGTH ?)
//fp->write(m_state.getBitVectorLengthAsStringForCodeGen(nodetype).c_str());
//.........这里部分代码省略.........
示例2: printPostfixValuesOfVariableDeclarations
// replaces NodeVarDecl:printPostfix to learn the values of Class' storage in center site
void SymbolVariableDataMember::printPostfixValuesOfVariableDeclarations(File * fp, s32 slot, u32 startpos, ULAMCLASSTYPE classtype)
{
UTI vuti = getUlamTypeIdx();
UlamKeyTypeSignature vkey = m_state.getUlamKeyTypeSignatureByIndex(vuti);
UlamType * vut = m_state.getUlamTypeByIndex(vuti);
ULAMCLASSTYPE vclasstype = vut->getUlamClassType();
ULAMTYPE vetyp = vut->getUlamTypeEnum();
fp->write(" ");
if(vclasstype == UC_NOTACLASS)
fp->write(vkey.getUlamKeyTypeSignatureNameAndBitSize(&m_state).c_str());
else
fp->write(vut->getUlamTypeNameBrief().c_str());
fp->write(" ");
fp->write(m_state.m_pool.getDataAsString(getId()).c_str());
s32 arraysize = m_state.getArraySize(vuti);
//scalar has 'size=1'; empty array [0] is still '0'.
s32 size = (arraysize > NONARRAYSIZE ? arraysize : 1);
//output the arraysize (optional), and open paren
if(arraysize > NONARRAYSIZE)
{
fp->write("[");
fp->write_decimal(arraysize);
fp->write("]");
}
else if(arraysize == UNKNOWNSIZE)
{
fp->write("[UNKNOWN]");
}
fp->write("(");
if(vclasstype == UC_QUARK)
{
//outputs the data members, not just the lump value (e.g. SWV::printPostfixValue())
UTI scalarquark = m_state.getUlamTypeAsScalar(vuti);
//printPostfixValuesForClass:
SymbolClass * csym = NULL;
AssertBool isDefined = m_state.alreadyDefinedSymbolClass(scalarquark, csym);
assert(isDefined);
NodeBlockClass * classNode = csym->getClassBlockNode();
assert(classNode);
u32 newstartpos = startpos + getPosOffset();
s32 len = vut->getBitSize();
for(s32 i = 0; i < size; i++)
classNode->printPostfixDataMembersSymbols(fp, slot, newstartpos + len * i, vclasstype);
}
else
{
PACKFIT packFit = m_state.determinePackable(vuti);
assert(WritePacked(packFit)); //has to be to fit in an atom/site;
char * valstr = new char[size * 8 + MAXBITSPERLONG]; //was 32
if(size > 0)
{
//build the string of values (for both scalar and packed array)
UlamValue arrayPtr = UlamValue::makePtr(slot, EVENTWINDOW, vuti, packFit, m_state, startpos + getPosOffset(), getId());
UlamValue nextPtr = UlamValue::makeScalarPtr(arrayPtr, m_state);
UlamValue atval = m_state.getPtrTarget(nextPtr);
s32 len = m_state.getBitSize(vuti);
if(len == UNKNOWNSIZE)
{
sprintf(valstr,"unknown");
for(s32 i = 1; i < size; i++)
{
strcat(valstr,", unknown");
}
}
else if(len <= MAXBITSPERINT)
{
u32 data = atval.getDataFromAtom(nextPtr, m_state);
vut->getDataAsString(data, valstr, 'z'); //'z' -> no preceeding ','
if(vetyp == Unsigned || vetyp == Unary)
strcat(valstr, "u");
for(s32 i = 1; i < size; i++)
{
char tmpstr[8];
AssertBool isNext = nextPtr.incrementPtr(m_state);
assert(isNext);
atval = m_state.getPtrTarget(nextPtr);
data = atval.getDataFromAtom(nextPtr, m_state);
vut->getDataAsString(data, tmpstr, ',');
if(vetyp == Unsigned || vetyp == Unary)
strcat(tmpstr, "u");
strcat(valstr,tmpstr);
}
}
else if(len <= MAXBITSPERLONG)
{
u64 data = atval.getDataLongFromAtom(nextPtr, m_state);
vut->getDataLongAsString(data, valstr, 'z'); //'z' -> no preceeding ','
if(vetyp == Unsigned || vetyp == Unary)
//.........这里部分代码省略.........
示例3: printPostfixValuesOfVariableDeclarations
// replaces NodeVarDecl:printPostfix to learn the values of Class' storage in center site
void SymbolVariableDataMember::printPostfixValuesOfVariableDeclarations(File * fp, s32 slot, u32 startpos, ULAMCLASSTYPE classtype)
{
UTI vuti = getUlamTypeIdx();
UlamKeyTypeSignature vkey = m_state.getUlamKeyTypeSignatureByIndex(vuti);
UlamType * vut = m_state.getUlamTypeByIndex(vuti);
ULAMCLASSTYPE vclasstype = vut->getUlamClass();
fp->write(" ");
if(vclasstype == UC_NOTACLASS)
fp->write(vkey.getUlamKeyTypeSignatureNameAndBitSize(&m_state).c_str());
else
fp->write(vut->getUlamTypeNameBrief().c_str());
fp->write(" ");
fp->write(m_state.m_pool.getDataAsString(getId()).c_str());
s32 arraysize = m_state.getArraySize(vuti);
//scalar has 'size=1'; empty array [0] is still '0'.
s32 size = (arraysize > NONARRAYSIZE ? arraysize : 1);
//output the arraysize (optional), and open paren
if(arraysize > NONARRAYSIZE)
{
fp->write("[");
fp->write_decimal(arraysize);
fp->write("]");
}
else if(arraysize == UNKNOWNSIZE)
{
fp->write("[UNKNOWN]");
}
fp->write("(");
if(vclasstype == UC_QUARK)
{
//printPostfixValuesForClass:
SymbolClass * csym = NULL;
if(m_state.alreadyDefinedSymbolClass(vuti, csym))
{
NodeBlockClass * classNode = csym->getClassBlockNode();
assert(classNode);
SymbolTable * stptr = classNode->getSymbolTablePtr(); //ST of data members
u32 newstartpos = startpos + getPosOffset();
s32 len = vut->getBitSize();
for(s32 i = 0; i < size; i++)
stptr->printPostfixValuesForTableOfVariableDataMembers(fp, slot, newstartpos + len * i, vclasstype);
}
else
{
assert(0); //error!
}
}
else
{
PACKFIT packFit = m_state.determinePackable(vuti);
assert(WritePacked(packFit)); //has to be to fit in an atom/site;
char * valstr = new char[size * 8 + MAXBITSPERLONG]; //was 32
if(size > 0)
{
//simplifying assumption for testing purposes: center site
//Coord c0(0,0);
//u32 slot = c0.convertCoordToIndex();
//build the string of values (for both scalar and packed array)
UlamValue arrayPtr = UlamValue::makePtr(slot, EVENTWINDOW, vuti, packFit, m_state, startpos + getPosOffset(), getId());
UlamValue nextPtr = UlamValue::makeScalarPtr(arrayPtr, m_state);
UlamValue atval = m_state.getPtrTarget(nextPtr);
s32 len = nextPtr.getPtrLen();
assert(len != UNKNOWNSIZE);
if(len <= MAXBITSPERINT)
{
u32 data = atval.getDataFromAtom(nextPtr, m_state);
vut->getDataAsString(data, valstr, 'z'); //'z' -> no preceeding ','
for(s32 i = 1; i < size; i++)
{
char tmpstr[8];
assert(nextPtr.incrementPtr(m_state));
atval = m_state.getPtrTarget(nextPtr);
data = atval.getDataFromAtom(nextPtr, m_state);
vut->getDataAsString(data, tmpstr, ',');
strcat(valstr,tmpstr);
}
}
else if(len <= MAXBITSPERLONG)
{
u64 data = atval.getDataLongFromAtom(nextPtr, m_state);
vut->getDataLongAsString(data, valstr, 'z'); //'z' -> no preceeding ','
for(s32 i = 1; i < size; i++)
{
char tmpstr[8];
assert(nextPtr.incrementPtr(m_state));
atval = m_state.getPtrTarget(nextPtr);
data = atval.getDataLongFromAtom(nextPtr, m_state);
//.........这里部分代码省略.........