本文整理汇总了C++中SgVariableDeclaration::reset_initializer方法的典型用法代码示例。如果您正苦于以下问题:C++ SgVariableDeclaration::reset_initializer方法的具体用法?C++ SgVariableDeclaration::reset_initializer怎么用?C++ SgVariableDeclaration::reset_initializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgVariableDeclaration
的用法示例。
在下文中一共展示了SgVariableDeclaration::reset_initializer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: transformCharArrayInitialization
void BasicProgmemTransform::transformCharArrayInitialization(SgFunctionDeclaration *func) {
/* *
* Translates statements of the form:
* char arr[n] = "some string"; to:
* char arr[n];
* strcpy_P(arr, <progmem placeholder>);
* */
Rose_STL_Container<SgNode *> initNames = NodeQuery::querySubTree(func, V_SgInitializedName);
for(auto &item: initNames) {
SgInitializedName *initName = isSgInitializedName(item);
if(initName->get_initializer() == NULL) {
continue;
}
SgVariableDeclaration * varDecl = isSgVariableDeclaration(initName->get_declaration());
if(varDecl == NULL) {
continue;
}
SgAssignInitializer *assignInit = isSgAssignInitializer(initName->get_initializer());
if(assignInit == NULL) {
continue;
}
SgType *type = initName->get_type();
SgType *eleType = SageInterface::getElementType(type);
if(isSgArrayType(type) && eleType != NULL && isSgTypeChar(eleType)) {
SgStringVal* strVal = isSgStringVal(assignInit->get_operand());
std::string str = strVal->get_value();
int arrSize = getDeclaredArraySize(isSgArrayType(type));
if(arrSize == 0) {
//char arr[] = "something";
int size = str.length() + 1;
SgArrayType *type = SageBuilder::buildArrayType(SageBuilder::buildCharType(), SageBuilder::buildIntVal(size));
initName->set_type(type);
}
varDecl->reset_initializer(NULL);
SgVariableDeclaration *placeholder = getVariableDeclPlaceholderForString(str);
SgVarRefExp *ref = SageBuilder::buildVarRefExp(placeholder);
std::stringstream instr;
instr << "\n strcpy_P(" << initName->get_name().getString();
instr << ", " << ref->get_symbol()->get_name().getString() << ");\n";
SageInterface::attachComment(varDecl, instr.str(), PreprocessingInfo::after);
printf("transformed %s\n", initName->unparseToString().c_str());
}
}
}