本文整理汇总了C++中SgInitializedName::get_scope方法的典型用法代码示例。如果您正苦于以下问题:C++ SgInitializedName::get_scope方法的具体用法?C++ SgInitializedName::get_scope怎么用?C++ SgInitializedName::get_scope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgInitializedName
的用法示例。
在下文中一共展示了SgInitializedName::get_scope方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visit
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());
}
}
示例2: visit
void StaticConstructorTraversal::visit(SgNode *n) {
// Get declared variables
SgInitializedName *vName = isSgInitializedName(n);
if (vName && !isAcreIgnore(vName->get_declaration())) {
Sg_File_Info *fInfo = vName->get_file_info();
SgScopeStatement *scope = vName->get_scope();
// Find global variables (variables in namespaces count, e.g. std)
if (!fInfo->isCompilerGenerated() && (isSgGlobal(scope) || isSgNamespaceDefinitionStatement(scope))) {
// Walk typedefs until reach pointer to base type
SgTypedefType *tdType = isSgTypedefType(vName->get_type());
while (tdType && isSgTypedefType(tdType->get_base_type()))
tdType = isSgTypedefType(tdType->get_base_type());
// Determine if type is a class (i.e. type with a constructor)
SgClassType *cType = isSgClassType(vName->get_type());
if (tdType)
cType = isSgClassType(tdType->get_base_type());
// Output location of globals with a static constructor
if (cType) {
*out << "Static Constructor Violation: " << fInfo->get_filename() << " @ " << fInfo->get_line() << "\n";
}
}
}
}
示例3: DCL02_C
/**
* Use visually distinct identifiers
*
* \note also checks DCL31-C
*/
bool DCL02_C( const SgNode *node ) {
static std::map<const SgScopeStatement *, std::set<std::string> > scopeMap;
static std::map<std::string, const SgInitializedName *> strVarMap;
const SgScopeStatement *scope = isSgScopeStatement(node);
if (!scope)
return false;
bool violation = false;
if (isSgGlobal(scope)) {
std::set<std::string> externNames;
/** populate scopeMap */
FOREACH_SUBNODE(scope, nodes, i, V_SgInitializedName) {
SgInitializedName *var = isSgInitializedName(*i);
assert(var);
if (isCompilerGeneratedNode(var)
|| !isSgDeclarationStatement(var->get_parent())
|| findParentOfType(var, SgCtorInitializerList)
|| findParentOfType(var, SgClassDeclaration) // Might be too strong
|| var->get_name().getString().empty()
|| (var->get_name().getString().substr(0,2) == "__"))
continue;
/** Ignore function prototypes */
const SgFunctionDeclaration * fnDecl = findParentOfType(var, SgFunctionDeclaration);
if (fnDecl && !fnDecl->get_definition())
continue;
if (isExternVar(var)) {
if (externNames.find(var->get_name().getString()) != externNames.end())
continue;
externNames.insert(var->get_name().getString());
}
const SgScopeStatement *varScope = var->get_scope();
std::string str (normalize_string(var->get_name().str(), isExternVar(var)));
if (scopeMap[varScope].find(str) != scopeMap[varScope].end()) {
DCL02_report_error(var);
violation = true;
} else {
scopeMap[varScope].insert(str);
strVarMap[str] = var;
}
}
return false;
}
示例4: isSgVarRefExp
foreach(SgAssignOp* op, assigns)
{
SgVarRefExp* var = isSgVarRefExp(op->get_lhs_operand());
SgInitializedName* decl = var->get_symbol()->get_declaration();
std::cout << "Found assignment to " << var->get_symbol()->get_name().str();
if (decl->get_protected_declaration())
{
std::cout << ", which is protected.";
}
std::cout << "\t\t" << op->unparseToString();
std::cout << std::endl;
SgNode* assign_scope = SageInterface::getScope(op);
SgNode* var_scope = decl->get_scope();
if (SageInterface::isAncestor(var_scope, assign_scope))
{
std::cout << "\tAnd both are in the same scope.\n";
}
else
{
std::cout << "\tIn different scopes.\n";
}
}
示例5: while
Rose_STL_Container<SgVarRefExp*>
buildListOfVariableReferenceExpressionsUsingGlobalVariables ( SgNode* node )
{
// This function builds a list of "uses" of variables (SgVarRefExp IR nodes) within the AST.
// return variable
Rose_STL_Container<SgVarRefExp*> globalVariableUseList;
// list of all variables (then select out the global variables by testing the scope)
Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree ( node, V_SgVarRefExp );
Rose_STL_Container<SgNode*>::iterator i = nodeList.begin();
while(i != nodeList.end())
{
SgVarRefExp *variableReferenceExpression = isSgVarRefExp(*i);
assert(variableReferenceExpression != NULL);
assert(variableReferenceExpression->get_symbol() != NULL);
assert(variableReferenceExpression->get_symbol()->get_declaration() != NULL);
assert(variableReferenceExpression->get_symbol()->get_declaration()->get_scope() != NULL);
// Note that variableReferenceExpression->get_symbol()->get_declaration() returns the
// SgInitializedName (not the SgVariableDeclaration where it was declared)!
SgInitializedName* variable = variableReferenceExpression->get_symbol()->get_declaration();
SgScopeStatement* variableScope = variable->get_scope();
// Check if this is a variable declared in global scope, if so, then save it
if (isSgGlobal(variableScope) != NULL)
{
globalVariableUseList.push_back(variableReferenceExpression);
}
i++;
}
return globalVariableUseList;
}
示例6: slidingRowOptimizer
void CudaOptimizer::slidingRowOptimizer(SgFunctionDeclaration* kernel,
const std::set<SgInitializedName*>& readOnlyVars,
SgInitializedName* candidateVar,
MintForClauses_t clauseList,
int num_planes, int order, bool first)
{
SgFunctionDefinition* func_def = kernel->get_definition();
SgBasicBlock* kernel_body = func_def ->get_body();
//if() opt:register flag is set? assumes it is already set
bool loadEvenCountZero = true;
SgVariableSymbol* upper_sym = CudaOptimizerInterface::getSymbolFromName(kernel_body, "_upper" + GIDZ);
//find the scope to declare the variable
SgScopeStatement* computeScope = CudaOptimizerInterface::findScopeForVarDeclaration(func_def, candidateVar);
ROSE_ASSERT(computeScope);
SgScopeStatement* upper_scope = NULL;
if(upper_sym != NULL)
upper_scope = upper_sym->get_scope();
else
upper_scope = computeScope ;
ROSE_ASSERT(upper_scope);
//load down into the register idz + 1
SgInitializedName* downReg = OnChipMemoryOpt::registerOptimizer(readOnlyVars, kernel, candidateVar,
computeScope, loadEvenCountZero, 1);
ROSE_ASSERT(downReg);
if (MintOptions::GetInstance()->isSharedOpt()){
//bool regSameShared = true;
//call shared memory optimization only if it is asked
//int num_planes = 1;
//int order = StencilAnalysis::performHigherOrderAnalysis(kernel_body, candidateVar, num_planes);
OnChipMemoryOpt::sharedMemoryOptimizer(kernel, readOnlyVars, candidateVar, clauseList, num_planes, first, order);
}
//load center
SgInitializedName* centerReg = OnChipMemoryOpt::registerOptimizer(readOnlyVars, kernel, candidateVar,
upper_scope, loadEvenCountZero);
ROSE_ASSERT(centerReg);
//load up idz - 1
SgInitializedName* upReg = OnChipMemoryOpt::registerOptimizer(readOnlyVars, kernel, candidateVar,
upper_scope, loadEvenCountZero, -1);
ROSE_ASSERT(upReg);
SgVarRefExp* upRef = buildVarRefExp(upReg, upper_scope);
SgVarRefExp* downRef = buildVarRefExp(downReg, downReg->get_scope());
SgVarRefExp* centerRef = buildVarRefExp(centerReg, upper_scope);
SgStatement* swap1 = buildAssignStatement(upRef, centerRef);
SgStatement* swap2 = buildAssignStatement(centerRef, downRef);
//SgStatement* loopBody = for_loop->get_loop_body();
//SgBasicBlock* loopBlock = isSgBasicBlock(loopBody);
//ROSE_ASSERT(loopBlock);
appendStatement(swap1, computeScope);
appendStatement(swap2, computeScope);
SgStatement *syncthreads= buildFunctionCallStmt("__syncthreads", buildVoidType(), NULL, computeScope);
ROSE_ASSERT(syncthreads);
appendStatement(syncthreads, computeScope );
//step4:
//checking if the variable is read-only
/* if(!isReadOnly(readOnlyVars,candidateVar))
{
SgExprStatement * writeBack= buildAssignStatement(glmem , regExp);
insertStatementAfter(inner_scope, writeBack);
}
*/
}
示例7: isSgStatement
//.........这里部分代码省略.........
ROSE_ASSERT ( initName );
newExpInit->set_parent( initName );
varSymbol = new SgVariableSymbol( initName );
ROSE_ASSERT ( varSymbol );
// create variable ref exp
varRefExp = new SgVarRefExp( assignLoc, varSymbol );
ROSE_ASSERT ( isSgVarRefExp( varRefExp ) );
// create the assignment
assignOp = new SgAssignOp( assignLoc, varRefExp, newExpAssign, expType );
assignStmt = new SgExprStatement( assignLoc, assignOp );
ROSE_ASSERT ( assignStmt );
initVarDeclaration->set_parent( stm->get_parent() );
isSgVariableDeclaration( initVarDeclaration )->set_definingDeclaration( isSgDeclarationStatement( initVarDeclaration ) );
// save new mapping
fct2Var.insert( Fct2Var( exp, varRefExp ) );
}
// save the 'declaration' structure, with all 3 statements and the variable name
newDecl->nonInitVarDeclaration = nonInitVarDeclaration;
newDecl->initVarDeclaration = initVarDeclaration;
newDecl->assignment = assignStmt;
newDecl->name = name;
nonInitVarDeclaration->set_parent( stm->get_parent() );
isSgVariableDeclaration( nonInitVarDeclaration )->set_definingDeclaration( isSgVariableDeclaration( nonInitVarDeclaration ) );
assignStmt->set_parent( stm->get_parent() );
declarations.push_back( newDecl );
} // end for
} // end if fct calls in crt stmt > 1
SgScopeStatement *scope = stm->get_scope();
ROSE_ASSERT ( scope );
// insert function bindings to variables; each 'declaration' structure in the list
// corresponds to one function call
for ( DeclarationPtrList::iterator i = declarations.begin(); i != declarations.end(); i++ )
{
Declaration *d = *i;
ROSE_ASSERT ( d && d->assignment && d->nonInitVarDeclaration );
// if the current statement is a for-loop, we insert Declarations before & in the loop body, depending on the case
if ( forStm )
{
SgStatement *parentScope = isSgStatement( stm->get_scope() );
SgBasicBlock *body = SageInterface::ensureBasicBlockAsBodyOfFor(forStm);
ROSE_ASSERT ( !inForTest.empty() && body && parentScope );
// SgStatementPtrList &list = body->get_statements();
// if function call is in loop condition, we add initialized variable before the loop and at its end
// hoist initialized variable declarations outside the loop
if ( inForTest.front() )
{
ROSE_ASSERT ( d->initVarDeclaration );
parentScope->insert_statement( stm, d->initVarDeclaration );
// set the scope of the initializedName
SgInitializedName *initName = isSgVariableDeclaration( d->initVarDeclaration )->get_decl_item( d->name );
ROSE_ASSERT ( initName );
initName->set_scope( isSgScopeStatement( parentScope ) );
ROSE_ASSERT ( initName->get_scope() );
}
// function call is in loop post increment so add noninitialized variable decls above the loop
else