本文整理汇总了C++中SgStatement类的典型用法代码示例。如果您正苦于以下问题:C++ SgStatement类的具体用法?C++ SgStatement怎么用?C++ SgStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SgStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unparseMacroCalls
//Replace the unparsing of expanded macro calls with the actual macro call wherever possible
void unparseMacroCalls(SgNode* searchTree)
{
//Traverse AST to find all macro calls and the nodes they are attached to
findPreprocInfo findPre;
findPre.traverse(searchTree, preorder);
std::vector< std::pair<SgNode*, PreprocessingInfo*> >& wherePreprocIsAttached = findPre.wherePreprocIsAttached;
//Replace expanded macro calls with actual macro call from pre-cpp wherever possible
for( std::vector< std::pair<SgNode*, PreprocessingInfo*> >::iterator iItr = wherePreprocIsAttached.begin();
iItr != wherePreprocIsAttached.end(); ++iItr)
{
SgStatement* currentNode = isSgStatement( (*iItr).first );
PreprocessingInfo* curPreproc = (*iItr).second;
ROSE_ASSERT(currentNode != NULL);
std::vector<SgNode*> matchingSubTree;
if ( matchMacroToSubtrees(currentNode->get_scope(), curPreproc, matchingSubTree) )
{
for(unsigned int i = 0; i < matchingSubTree.size(); i++)
{
SgLocatedNode* macroNode = isSgLocatedNode(matchingSubTree[i]);
ROSE_ASSERT(macroNode != NULL);
std::string replacementString = ( i ==0 ? curPreproc->getString() : "" );
if( isSgExpression(macroNode) == NULL )
{
#ifndef USE_ROSE
#ifndef ROSE_SKIP_COMPILATION_OF_WAVE
// If we are using ROSE to compile ROSE source code then the Wave support is not present.
PreprocessingInfo::rose_macro_call* macroCall = curPreproc->get_macro_call();
if(macroCall->expanded_macro.size() > 0 && boost::wave::token_id(macroCall->expanded_macro.back()) != boost::wave::T_COLON)
replacementString +=";";
#endif
#endif
}
std::cout << "Doing line replacement " << macroNode->unparseToString() << " with " << replacementString << std::endl;
#if 0
std::string pos;
curPreproc->display(pos);
std::cout << macroNode->class_name() << " "<< pos << std::endl;
#endif
macroNode->addToAttachedPreprocessingInfo(new PreprocessingInfo(PreprocessingInfo::LineReplacement,
replacementString,macroNode->get_file_info()->get_filenameString(),1,1,1,PreprocessingInfo::before));
}
};
}
};
示例2: fortran_error_handler
/**
* handling error occured due to failed assertion
* this error handler only works during parser phase since it uses
* Token_t to know the line number
* TODO: we need to make this function more general
**/
void
fortran_error_handler(int signum)
{
// get the current filename
std::string sFilename = getCurrentFilename();
if (sFilename.size()==0) {
fprintf(stderr, "ERROR while parsing the source code\n");
} else {
SgScopeStatement* scope = astScopeStack.front();
SgStatement* lastStatement = scope;
SgStatementPtrList statementList = scope->generateStatementList();
if (statementList.empty() == false)
{
lastStatement = statementList.back();
}
int lineNumberOfLastStatement = (astScopeStack.empty() == false) ? lastStatement->get_file_info()->get_line() : 0;
// get the latest token parsed
if (lineNumberOfLastStatement > 0)
std::cerr <<"FATAL ERROR in file "<<sFilename<<":"<<lineNumberOfLastStatement<<std::endl;
else
std::cerr <<"FATAL ERROR while parsing "<<sFilename<<std::endl;
}
fflush(NULL); // flush all stdio
fortran_error_handler_end();
exit(-1);
}
示例3: translate_to_upc
/**
* Convert for_stmt to a upc_forall statement if it has an affinity exp
* in the global map.
*/
SgStatement* translate_to_upc(SgForStatement* for_stmt) {
/* return value is either SgUpcForAllStmt or SgForStmt */
SgStatement* retval;
/* translate if the for_stmt was upc_forall stmt */
aff_map_t::iterator affinity_exp_it = aff_exp_map.find(for_stmt);
if (affinity_exp_it != aff_exp_map.end()) {
/* build a new upc_forall statement */
retval = SageBuilder::buildUpcForAllStatement_nfi(
for_stmt->get_for_init_stmt(), /* initialize stmt */
for_stmt->get_test(), /* condition */
for_stmt->get_increment(), /* increment */
affinity_exp_it->second, /* affinity */
for_stmt->get_loop_body() /* loop body */
);
/* set file info */
Sg_File_Info* old_file_info = for_stmt->get_file_info();
retval->set_file_info( old_file_info );
} else {
/* for_stmt was never a upc_forall stmt */
retval = for_stmt;
}
return retval;
}
示例4: isSgStatement
void visitorTraversal::visit(SgNode* n)
{
// There are three types ir IR nodes that can be queried for scope:
// - SgStatement, and
// - SgInitializedName
SgStatement* statement = isSgStatement(n);
if (statement != NULL)
{
SgScopeStatement* scope = statement->get_scope();
ROSE_ASSERT(scope != NULL);
printf ("SgStatement = %12p = %30s has scope = %12p = %s (total number = %d) \n",
statement,statement->class_name().c_str(),
scope,scope->class_name().c_str(),(int)scope->numberOfNodes());
}
SgInitializedName* initializedName = isSgInitializedName(n);
if (initializedName != NULL)
{
SgScopeStatement* scope = initializedName->get_scope();
ROSE_ASSERT(scope != NULL);
printf ("SgInitializedName = %12p = %30s has scope = %12p = %s (total number = %d)\n",
initializedName,initializedName->get_name().str(),
scope,scope->class_name().c_str(),(int)scope->numberOfNodes());
}
}
示例5: getVariablesProcessedByInnerLoops
// obtain read or write variables processed by all nested loops, if any
void getVariablesProcessedByInnerLoops (SgScopeStatement* current_loop_body, bool isRead, std::set<SgInitializedName*>& var_set)
{
// AST query to find all loops
// add all read/write variables into the var_set
VariantVector vv;
vv.push_back(V_SgForStatement);
vv.push_back(V_SgFortranDo);
Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(current_loop_body, vv);
for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
{
SgStatement* loop = isSgStatement(*i);
if (debug)
cout<< "Found nested loop at line:"<< loop->get_file_info()->get_line()<<endl;
std::set<SgInitializedName*> src_var_set ;
if (isRead)
src_var_set = LoopLoadVariables[loop];
else
src_var_set = LoopStoreVariables[loop];
std::set<SgInitializedName*>::iterator j;
if (debug)
cout<< "\t Insert processed variable:"<<endl;
for (j= src_var_set.begin(); j!= src_var_set.end(); j++)
{
var_set.insert(*j);
if (debug)
cout<< "\t \t "<<(*j)->get_name()<<endl;
}
}
}
示例6: isSgPragmaDeclaration
//note that we keep mint for pragma as well
//#pragma mint for
//#pragma omp for
void MintCudaMidend::replaceMintForWithOmpFor(SgSourceFile* file)
{
Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(file, V_SgPragmaDeclaration);
Rose_STL_Container<SgNode*>::reverse_iterator nodeListIterator = nodeList.rbegin();
for ( ;nodeListIterator !=nodeList.rend(); ++nodeListIterator)
{
SgPragmaDeclaration* node = isSgPragmaDeclaration(*nodeListIterator);
ROSE_ASSERT(node != NULL);
//checks if the syntax is correct and the parallel region is followed by
//a basic block
if(MintPragmas::isForLoopPragma(node))
{
SgStatement* loop = getNextStatement(node);
ROSE_ASSERT(loop);
if(isSgForStatement(loop))
{
removeStatement(loop);
SgOmpForStatement* omp_stmt = new SgOmpForStatement(NULL, loop);
setOneSourcePositionForTransformation(omp_stmt);
loop->set_parent(omp_stmt);
insertStatementAfter(node, omp_stmt);
}
}
}
}
示例7: findScopes
/*
* The function
* findScope()
* takes as a parameter a SgNode* which is a SgStatement*. It returns a SgNodePtrVector of all
* preceding scopes the SgStatement is in.
*
*/
SgNodePtrVector
findScopes (SgNode * astNode)
{
ROSE_ASSERT (isSgStatement (astNode));
SgNodePtrVector returnVector;
SgScopeStatement *currentScope;
if (isSgScopeStatement (astNode))
{
currentScope = isSgScopeStatement (astNode);
ROSE_ASSERT (currentScope != NULL);
returnVector.push_back (astNode);
}
else
{
SgStatement *sageStatement = isSgStatement (astNode);
ROSE_ASSERT (sageStatement != NULL);
currentScope = sageStatement->get_scope ();
ROSE_ASSERT (currentScope != NULL);
returnVector.push_back (currentScope);
}
while (currentScope->variantT () != V_SgGlobal)
{
currentScope = currentScope->get_scope ();
ROSE_ASSERT (currentScope != NULL);
returnVector.push_back (currentScope);
}
//Must also include the Global Scopes of the other files in the project
if (currentScope->variantT () == V_SgGlobal)
{
SgFile *sageFile = isSgFile ((currentScope)->get_parent ());
ROSE_ASSERT (sageFile != NULL);
SgProject *sageProject = isSgProject (sageFile->get_parent ());
ROSE_ASSERT (sageProject != NULL);
//Get a list of all files in the current project
const SgFilePtrList& sageFilePtrList = sageProject->get_fileList ();
//Iterate over the list of files to find all Global Scopes
SgNodePtrVector globalScopes;
for (unsigned int i = 0; i < sageFilePtrList.size (); i += 1)
{
const SgSourceFile *sageFile = isSgSourceFile (sageFilePtrList[i]);
ROSE_ASSERT (sageFile != NULL);
SgGlobal *sageGlobal = sageFile->get_globalScope();
ROSE_ASSERT (sageGlobal != NULL);
returnVector.push_back (sageGlobal);
}
}
return returnVector;
};
示例8: returnFirstOrLastStatementFromCurrentFile
SgStatement*
returnFirstOrLastStatementFromCurrentFile (
SgStatement* target,
const SgStatementPtrList & statementList,
bool findFirstStatement )
{
// printf ("Inside of returnFirstOrLastStatement \n");
// Find the first statement from the current file being processed
SgStatement* statement = NULL;
if (findFirstStatement)
{
SgStatementPtrList::const_iterator statementIterator = statementList.begin();
while (statementIterator != statementList.end())
{
statement = *statementIterator;
ROSE_ASSERT (statement != NULL);
Sg_File_Info* fileInfo = statement->get_file_info();
ROSE_ASSERT (fileInfo != NULL);
string filename = fileInfo->get_filename();
if (filename == ROSE::getFileNameByTraversalBackToFileNode(target))
{
// printf ("Found the first statement in this file = %s \n",filename.c_str());
// printf ("First statement = %s \n",statement->unparseToCompleteString().c_str());
break;
}
statementIterator++;
}
}
else
{
SgStatementPtrList::const_reverse_iterator statementIterator = statementList.rbegin();
while (statementIterator != statementList.rend())
{
statement = *statementIterator;
ROSE_ASSERT (statement != NULL);
Sg_File_Info* fileInfo = statement->get_file_info();
ROSE_ASSERT (fileInfo != NULL);
string filename = fileInfo->get_filename();
if (filename == ROSE::getFileNameByTraversalBackToFileNode(target))
{
// printf ("Found the last statement in this file = %s \n",filename.c_str());
// printf ("First statement = %s \n",statement->unparseToCompleteString().c_str());
break;
}
statementIterator++;
}
}
ROSE_ASSERT (statement != NULL);
return statement;
}
示例9: isSgExprStatement
SgStatement *findSafeInsertPoint(SgNode *node) {
SgStatement *insertPoint = SageInterface::getEnclosingStatement(node);
SgStatement *es = isSgExprStatement(insertPoint);
SgStatement *esParent = es ? isSgStatement(es->get_parent()) : 0;
if (es && (isSgSwitchStatement(esParent) || isSgIfStmt(esParent))) {
// Make sure insertion point is outside of the condition of an if-stmt
// or the selector of a switch-stmt.
insertPoint = esParent;
} else {
if (esParent) {
assert(isSgBasicBlock(esParent));
}
}
return insertPoint;
}
示例10: printf
FrontierDetectionForTokenStreamMapping_InheritedAttribute
FrontierDetectionForTokenStreamMapping::evaluateInheritedAttribute(SgNode* n, FrontierDetectionForTokenStreamMapping_InheritedAttribute inheritedAttribute)
{
static int random_counter = 0;
#if 1
// Ignore IR nodes that are front-end specific (declarations of builtin functions, etc.).
if (n->get_file_info()->isFrontendSpecific() == false)
{
printf ("In FrontierDetectionForTokenStreamMapping::evaluateInheritedAttribute(): n = %p = %s \n",n,n->class_name().c_str());
// Count the IR nodes traversed so that we can make a subset transformations.
random_counter++;
}
#endif
FrontierDetectionForTokenStreamMapping_InheritedAttribute returnAttribute;
SgStatement* statement = isSgStatement(n);
// if (statement != NULL && random_counter > 30 && random_counter < 40)
if (statement != NULL)
{
string name = "token_frontier";
string options = "color=\"blue\"";
if (random_counter > 30 && random_counter < 40)
{
printf ("In FrontierDetectionForTokenStreamMapping::evaluateInheritedAttribute(): Mark this statement as a transformation: random_counter = %d statement = %p = %s \n",random_counter,statement,statement->class_name().c_str());
options = "color=\"red\"";
returnAttribute.containsFrontier = true;
}
// AstAttribute::AttributeNodeInfo* attribute = new FrontierDetectionForTokenStreamMappingAttribute ( (SgNode*) n, name, options);
AstAttribute* attribute = new FrontierDetectionForTokenStreamMappingAttribute ( (SgNode*) n, name, options);
statement->setAttribute(name,attribute);
}
// return FrontierDetectionForTokenStreamMapping_InheritedAttribute();
return returnAttribute;
}
示例11: printf
PrefixInheritedAttribute
PrefixSuffixGenerationTraversal::evaluateInheritedAttribute (
SgNode* astNode,
PrefixInheritedAttribute inputInheritedAttribute )
{
#if 0
printf ("!!! In evaluateInheritedAttribute: astNode = %s \n",astNode->sage_class_name());
#endif
if ( isSgScopeStatement(astNode) != NULL)
{
// printf ("Found a new scope! currentScope.size() = %zu \n",currentScope.size());
stackOfScopes.push(currentScope);
// empty the current scope stack
while (currentScope.empty() == false)
currentScope.pop_front();
}
SgStatement* currentStatement = isSgStatement(astNode);
if ( currentStatement != NULL )
{
// printf ("Found a statement! \n");
// string declarationFilename = ROSE::getFileName(currentStatement);
string declarationFilename = currentStatement->get_file_info()->get_filename();
string targetFilename = ROSE::getFileNameByTraversalBackToFileNode(currentStatement);
// printf ("targetFilename = %s declarationFilename = %s counter = %d (*i)->sage_class_name() = %s \n",
// targetFilename.c_str(),declarationFilename.c_str(),counter,(*i)->sage_class_name());
if ( generateIncludeDirectives == false || declarationFilename == targetFilename )
{
// printf ("Found a declaration statement! currentScope.size() = %zu \n",currentScope.size());
currentScope.push_front(currentStatement);
}
}
// printf ("Leaving evaluateInheritedAttribute() \n");
return inputInheritedAttribute;
}
示例12: buildExprStatement
SgIfStmt *
RoseStatementsAndExpressionsBuilder::buildIfStatementWithEmptyElse (
SgExpression * ifGuard, SgScopeStatement * thenBlock)
{
using namespace SageBuilder;
using namespace SageInterface;
SgStatement * ifGuardStatement = buildExprStatement (ifGuard);
SgIfStmt * ifStatement = new SgIfStmt (ifGuardStatement, thenBlock, NULL);
ifStatement->setCaseInsensitive (true);
ifStatement->set_use_then_keyword (true);
ifStatement->set_has_end_statement (true);
setOneSourcePositionForTransformation (ifStatement);
ifGuardStatement->set_parent (ifStatement);
thenBlock->set_parent (ifStatement);
return ifStatement;
}
示例13: getIfConds
void getIfConds(SgIfStmt* fixIf, SgScopeStatement* parentScope) {
SgStatement* conditional = fixIf->get_conditional();
if (isSgExprStatement(conditional)) {
SgExpression* expr = isSgExprStatement(conditional)->get_expression();
std::pair<SgVariableDeclaration*, SgExpression*> pr = SageInterface::createTempVariableForExpression(expr,isSgScopeStatement(fixIf),true);
SgInitializedNamePtrList lptr = pr.first->get_variables();
//std::cout << "lprt size: " << lptr.size() << std::endl;
ROSE_ASSERT(lptr.size() <= 1);
SgVarRefExp* varRef = SageBuilder::buildVarRefExp(pr.first);
SgIntVal* iv = SageBuilder::buildIntVal(0);
SgNotEqualOp* nop = SageBuilder::buildNotEqualOp(isSgExpression(varRef),isSgExpression(iv));
SgExprStatement* ses = SageBuilder::buildExprStatement(isSgExpression(nop));
SageInterface::replaceStatement(conditional,ses);
//SageInterface::moveVariableDeclaration(pr.first, parentScope);
// SageInterface::appendStatement(pr.first, parentScope);
SageInterface::insertStatementBefore(fixIf,pr.first);
std::cout << "conditional type: " << conditional->class_name() << std::endl;
}
return;
}
示例14: computePreviousAndNextNodes
std::map<SgNode*,PreviousAndNextNodeData*>
computePreviousAndNextNodes(SgGlobal* globalScope, std::vector<FrontierNode*> frontierNodes)
{
// This is an alternative way to compute the previous/next node map using the token/AST unparsing frontier list directly.
std::map<SgNode*,PreviousAndNextNodeData*> previousAndNextNodeMap;
SgStatement* previousNode = globalScope;
SgStatement* previousPreviousNode = globalScope;
for (size_t j = 0; j < frontierNodes.size(); j++)
{
// SgStatement* statement = topAttribute.frontierNodes[j];
// ROSE_ASSERT(statement != NULL);
FrontierNode* frontierNode = frontierNodes[j];
ROSE_ASSERT(frontierNode != NULL);
SgStatement* statement = frontierNode->node;
ROSE_ASSERT(statement != NULL);
#if 0
printf (" (%p = %s) ",statement,statement->class_name().c_str());
#endif
PreviousAndNextNodeData* previousAndNextNodeData = new PreviousAndNextNodeData(previousPreviousNode,statement);
#if 0
printf ("Building previousAndNextNodeData = %p previousPreviousNode = %p = %s previousNode = %p = %s statement = %p = %s \n",
previousAndNextNodeData,previousPreviousNode,previousPreviousNode->class_name().c_str(),
previousNode,previousNode->class_name().c_str(),statement,statement->class_name().c_str());
#endif
// Insert a element into the map for the current IR node being traversed.
if (previousNode != NULL)
{
#if 0
printf ("Insert previousAndNextNodeData = %p into previousAndNextNodeMap \n",previousAndNextNodeData);
#endif
previousAndNextNodeMap.insert(std::pair<SgNode*,PreviousAndNextNodeData*>(previousNode,previousAndNextNodeData));
}
else
{
printf ("WARNING: previousNode == NULL: j = %" PRIuPTR " can't insert entry into previousAndNextNodeMap: statement = %p = %s \n",j,statement,statement->class_name().c_str());
}
previousPreviousNode = previousNode;
previousNode = statement;
}
// Handle the last frontier IR node
if (frontierNodes.empty() == false)
{
PreviousAndNextNodeData* previousAndNextNodeData = new PreviousAndNextNodeData(previousPreviousNode,globalScope);
// Insert a element into the map for the current IR node being traversed.
previousAndNextNodeMap.insert(std::pair<SgNode*,PreviousAndNextNodeData*>(previousNode,previousAndNextNodeData));
}
return previousAndNextNodeMap;
}
示例15: isSgFile
void
visitorTraversal::visit(SgNode* n)
{
SgFile* file = isSgFile(n);
if (file != NULL)
{
filename = file->get_sourceFileNameWithPath();
}
// On each statement node and output it's position.
SgStatement* statement = isSgStatement(n);
bool outputStatement = (statement != NULL) ? true : false;
// Check for the statement to exist in the input source file
outputStatement = outputStatement && (statement->get_file_info()->get_filenameString() == filename);
// Skip SgGlobal IR nodes
outputStatement = outputStatement && (isSgGlobal(statement) == NULL);
if (outputStatement == true)
{
AttachedPreprocessingInfoType* comments = statement->getAttachedPreprocessingInfo();
if (comments != NULL)
{
// printf ("Found attached comments (to IR node at %p of type: %s): \n",statement,statement->class_name().c_str());
// int counter = 0;
AttachedPreprocessingInfoType::iterator i;
for (i = comments->begin(); i != comments->end(); i++)
{
#if 0
printf (" Attached Comment #%d in file %s (relativePosition=%s): classification %s :\n%s\n",
counter++,(*i)->get_file_info()->get_filenameString().c_str(),
((*i)->getRelativePosition() == PreprocessingInfo::before) ? "before" : "after",
PreprocessingInfo::directiveTypeName((*i)->getTypeOfDirective()).c_str(),
(*i)->getString().c_str());
#endif
// Mark comments and CPP directives a few different colors.
int startingLineNumber = (*i)->get_file_info()->get_line();
int startingColumnNumber = (*i)->get_file_info()->get_col();
// Subtract 1 from number of lines to avoid over counting the current line.
int endingLineNumber = startingLineNumber + ((*i)->getNumberOfLines() - 1);
int endingColumnNumber = (*i)->getColumnNumberOfEndOfString();
string color = directiveTypeColor((*i)->getTypeOfDirective());
#if 0
printf ("%d,%d,%s,%d,%d\n",startingLineNumber,startingColumnNumber,color.c_str(),endingLineNumber,endingColumnNumber);
#endif
dataFile << startingLineNumber << "," << startingColumnNumber << "," << color << "," << endingLineNumber << "," << endingColumnNumber << endl;
}
}
else
{
// printf ("No attached comments (at %p of type: %s): \n",statement,statement->sage_class_name());
}
ROSE_ASSERT(statement->get_startOfConstruct() != NULL);
int startingLineNumber = statement->get_startOfConstruct()->get_line();
int startingColumnNumber = statement->get_startOfConstruct()->get_col();
if (statement->get_endOfConstruct() == NULL)
{
printf ("Error: statement->get_endOfConstruct() == NULL (statement = %p = %s) \n",statement,statement->class_name().c_str());
}
ROSE_ASSERT(statement->get_endOfConstruct() != NULL);
int endingLineNumber = statement->get_endOfConstruct()->get_line();
int endingColumnNumber = statement->get_endOfConstruct()->get_col();
// Catch errors (likely compiler generate IR node or NULL file)
if (endingLineNumber == 0)
{
endingLineNumber = startingLineNumber;
endingColumnNumber = startingColumnNumber;
}
#if 0
// Mark all statements blue
string color = "blue";
if (isSgScopeStatement(statement) != NULL)
color = "red";
#else
string color = nodeColor(statement);
#endif
#if 0
printf ("%d,%d,%s,%d,%d %s = %p \n",startingLineNumber,startingColumnNumber,color.c_str(),endingLineNumber,endingColumnNumber,statement->class_name().c_str(),statement);
#endif
dataFile << startingLineNumber << "," << startingColumnNumber << "," << color << "," << endingLineNumber << "," << endingColumnNumber << endl;
}
// On each statement node and output it's position.
SgExpression* expression = isSgExpression(n);
bool outputExpression = (expression != NULL) ? true : false;
// Check for the statement to exist in the input source file
outputExpression = outputExpression && (expression->get_file_info()->get_filenameString() == filename);
//.........这里部分代码省略.........