本文整理汇总了C++中SgInitializedName::set_type方法的典型用法代码示例。如果您正苦于以下问题:C++ SgInitializedName::set_type方法的具体用法?C++ SgInitializedName::set_type怎么用?C++ SgInitializedName::set_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgInitializedName
的用法示例。
在下文中一共展示了SgInitializedName::set_type方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
}
}
示例2: rand
DoxygenFile::DoxygenFile(SgProject *prj, string filename)
{
Sg_File_Info *info = new Sg_File_Info(filename, 0, 0);
SgInitializedName *iname = new SgInitializedName;
stringstream sname;
sname << "SAGE_Doxygen_Dummy_" << rand();
iname->set_name(sname.str());
iname->set_type(new SgTypeInt);
iname->set_file_info(info);
iname->get_storageModifier().setExtern();
SgVariableDeclaration *decl = new SgVariableDeclaration;
decl->get_variables().push_back(iname);
decl->set_startOfConstruct(info);
decl->set_endOfConstruct(info);
decl->get_declarationModifier().get_storageModifier().setExtern();
iname->set_parent(decl);
iname->set_prev_decl_item(iname);
// SgGlobal *glob = prj->get_file(0).get_globalScope();
SgSourceFile* sourceFile = isSgSourceFile(prj->get_fileList()[0]);
ROSE_ASSERT(sourceFile != NULL);
SgGlobal *glob = sourceFile->get_globalScope();
// glob->insertStatementInScope(decl, true);
glob->get_declarations().insert(glob->get_declarations().begin(),decl);
decl->set_parent(glob);
SgVariableSymbol* variableSymbol = new SgVariableSymbol(iname);
glob->insert_symbol(sname.str(),variableSymbol);
decl->set_parent(glob);
std::cout << "Before complete string." << std::endl;
//glob->append_declaration(decl);
iname->set_scope(glob);
decl->unparseToCompleteString();
std::cout << "After complete string." << std::endl;
commentParent = decl;
printf("commentParent = %p\n", commentParent);
}
示例3: main
int main( int argc, char * argv[] )
{
// Option to linearize the array.
Rose_STL_Container<std::string> localCopy_argv = CommandlineProcessing::generateArgListFromArgcArgv(argc, argv);
int newArgc;
char** newArgv = NULL;
vector<string> argList = localCopy_argv;
if (CommandlineProcessing::isOption(argList,"-f2c:","linearize",true) == true)
{
isLinearlizeArray = true;
}
CommandlineProcessing::generateArgcArgvFromList(argList,newArgc, newArgv);
// Build the AST used by ROSE
SgProject* project = frontend(newArgc,newArgv);
AstTests::runAllTests(project);
if (SgProject::get_verbose() > 2)
generateAstGraph(project,8000,"_orig");
// Traversal with Memory Pool to search for variableDeclaration
variableDeclTraversal translateVariableDeclaration;
traverseMemoryPoolVisitorPattern(translateVariableDeclaration);
for(vector<SgVariableDeclaration*>::iterator dec=variableDeclList.begin(); dec!=variableDeclList.end(); ++dec)
{
/*
For the Fortran AST, a single variableDeclaration can be shared by multiple variables.
This violated the normalization rules for C unparser. Therefore, we have to transform it.
*/
SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(*dec);
ROSE_ASSERT(variableDeclaration);
if((variableDeclaration->get_variables()).size() != 1)
{
updateVariableDeclarationList(variableDeclaration);
statementList.push_back(variableDeclaration);
removeList.push_back(variableDeclaration);
}
}
// reset the vector that collects all variable declaration. We need to walk through memory pool again to find types
variableDeclList.clear();
traverseMemoryPoolVisitorPattern(translateVariableDeclaration);
for(vector<SgVariableDeclaration*>::iterator dec=variableDeclList.begin(); dec!=variableDeclList.end(); ++dec)
{
SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(*dec);
ROSE_ASSERT(variableDeclaration);
SgInitializedNamePtrList initializedNameList = variableDeclaration->get_variables();
for(SgInitializedNamePtrList::iterator i=initializedNameList.begin(); i!=initializedNameList.end();++i)
{
SgInitializedName* initiallizedName = isSgInitializedName(*i);
SgType* baseType = initiallizedName->get_type();
if(baseType->variantT() == V_SgArrayType)
{
SgArrayType* arrayBase = isSgArrayType(baseType);
// At this moment, we are still working on the Fortran-stype AST. Therefore, there is no nested types for multi-dim array.
if(arrayBase->findBaseType()->variantT() == V_SgTypeString)
{
arrayBase->reset_base_type(translateType(arrayBase->findBaseType()));
arrayBase->set_rank(arrayBase->get_rank()+1);
}
}
else
{
initiallizedName->set_type(translateType(baseType));
}
}
}
// replace the AttributeSpecificationStatement
Rose_STL_Container<SgNode*> AttributeSpecificationStatement = NodeQuery::querySubTree (project,V_SgAttributeSpecificationStatement);
for (Rose_STL_Container<SgNode*>::iterator i = AttributeSpecificationStatement.begin(); i != AttributeSpecificationStatement.end(); i++)
{
SgAttributeSpecificationStatement* attributeSpecificationStatement = isSgAttributeSpecificationStatement(*i);
ROSE_ASSERT(attributeSpecificationStatement);
translateAttributeSpecificationStatement(attributeSpecificationStatement);
statementList.push_back(attributeSpecificationStatement);
removeList.push_back(attributeSpecificationStatement);
}
// replace the parameter reference
parameterTraversal translateParameterRef;
traverseMemoryPoolVisitorPattern(translateParameterRef);
for(vector<SgVarRefExp*>::iterator i=parameterRefList.begin(); i!=parameterRefList.end(); ++i)
{
SgVarRefExp* parameterRef = isSgVarRefExp(*i);
if(parameterSymbolList.find(parameterRef->get_symbol()) != parameterSymbolList.end())
{
SgExpression* newExpr = isSgExpression(deepCopy(parameterSymbolList.find(parameterRef->get_symbol())->second));
ROSE_ASSERT(newExpr);
newExpr->set_parent(parameterRef->get_parent());
replaceExpression(parameterRef,
newExpr,
false);
}
}
/*
Parameters will be replaced by #define, all the declarations should be removed
*/
for(map<SgVariableSymbol*,SgExpression*>::iterator i=parameterSymbolList.begin();i!=parameterSymbolList.end();++i)
//.........这里部分代码省略.........