本文整理汇总了C++中SgScopeStatement::get_scope方法的典型用法代码示例。如果您正苦于以下问题:C++ SgScopeStatement::get_scope方法的具体用法?C++ SgScopeStatement::get_scope怎么用?C++ SgScopeStatement::get_scope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgScopeStatement
的用法示例。
在下文中一共展示了SgScopeStatement::get_scope方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isSgScopeStatement
/*
* 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;
};
示例2: name
SgSymbol * ClangToSageTranslator::GetSymbolFromSymbolTable(clang::NamedDecl * decl) {
if (decl == NULL) return NULL;
SgScopeStatement * scope = SageBuilder::topScopeStack();
SgName name(decl->getNameAsString());
#if DEBUG_SYMBOL_TABLE_LOOKUP
std::cerr << "Lookup symbol for: " << name << std::endl;
#endif
if (name == "") {
return NULL;
}
std::list<SgScopeStatement *>::reverse_iterator it;
SgSymbol * sym = NULL;
switch (decl->getKind()) {
case clang::Decl::Typedef:
{
it = SageBuilder::ScopeStack.rbegin();
while (it != SageBuilder::ScopeStack.rend() && sym == NULL) {
sym = (*it)->lookup_typedef_symbol(name);
it++;
}
break;
}
case clang::Decl::Var:
case clang::Decl::ParmVar:
{
it = SageBuilder::ScopeStack.rbegin();
while (it != SageBuilder::ScopeStack.rend() && sym == NULL) {
sym = (*it)->lookup_variable_symbol(name);
it++;
}
break;
}
case clang::Decl::Function:
{
SgType * tmp_type = buildTypeFromQualifiedType(((clang::FunctionDecl *)decl)->getType());
SgFunctionType * type = isSgFunctionType(tmp_type);
ROSE_ASSERT(type);
it = SageBuilder::ScopeStack.rbegin();
while (it != SageBuilder::ScopeStack.rend() && sym == NULL) {
sym = (*it)->lookup_function_symbol(name, type);
it++;
}
break;
}
case clang::Decl::Field:
{
SgClassDeclaration * sg_class_decl = isSgClassDeclaration(Traverse(((clang::FieldDecl *)decl)->getParent()));
ROSE_ASSERT(sg_class_decl != NULL);
if (sg_class_decl->get_definingDeclaration() == NULL)
std::cerr << "Runtime Error: cannot find the definition of the class/struct associate to the field: " << name << std::endl;
else {
scope = isSgClassDeclaration(sg_class_decl->get_definingDeclaration())->get_definition();
// TODO: for C++, if 'scope' is in 'SageBuilder::ScopeStack': problem!!!
// It means that we are currently building the class
while (scope != NULL && sym == NULL) {
sym = scope->lookup_variable_symbol(name);
scope = scope->get_scope();
}
}
break;
}
case clang::Decl::CXXRecord:
case clang::Decl::Record:
{
it = SageBuilder::ScopeStack.rbegin();
while (it != SageBuilder::ScopeStack.rend() && sym == NULL) {
sym = (*it)->lookup_class_symbol(name);
it++;
}
break;
}
case clang::Decl::Label:
{
// Should not be reach as we use Traverse to retrieve Label (they are "terminal" statements) (it avoids the problem of forward use of label: goto before declaration)
name = SgName(((clang::LabelDecl *)decl)->getStmt()->getName());
it = SageBuilder::ScopeStack.rbegin();
while (it != SageBuilder::ScopeStack.rend() && sym == NULL) {
sym = (*it)->lookup_label_symbol(name);
it++;
}
break;
}
case clang::Decl::EnumConstant:
{
name = SgName(((clang::EnumConstantDecl *)decl)->getName());
it = SageBuilder::ScopeStack.rbegin();
while (it != SageBuilder::ScopeStack.rend() && sym == NULL) {
sym = (*it)->lookup_enum_field_symbol(name);
it++;
}
break;
}
case clang::Decl::Enum:
{
name = SgName(((clang::EnumDecl *)decl)->getName());
//.........这里部分代码省略.........
示例3: 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
示例4: if
// Count the load and store bytes for the
// I think we can only return expressions to calculate the value, not the actual values,
// since sizeof(type) is machine dependent
// Consider both scalar and array accesses by default. Consider both floating point and integer types by default.
// return a pair of expressions:
// load_byte_exp, and
// store_byte_exp
// Algorithm:
// 1. Call side effect analysis to find read/write variables, some reference may trigger both read and write accesses
// Accesses to the same array/scalar variable are grouped into one read (or write) access
// e.g. array[i][j], array[i][j+1], array[i][j-1], etc are counted a single access
// 2. Group accesses based on the types (same type? increment the same counter to shorten expression length)
// 4. Iterate on the results to generate expression like 2*sizeof(float) + 5* sizeof(double)
// As an approximate, we use simple analysis here assuming no function calls.
std::pair <SgExpression*, SgExpression*> CountLoadStoreBytes (SgLocatedNode* input, bool includeScalars /* = true */, bool includeIntType /* = true */)
{
std::pair <SgExpression*, SgExpression*> result;
assert (input != NULL);
// the input is essentially the loop body, a scope statement
SgScopeStatement* scope = isSgScopeStatement(input);
// We need to record the associated loop info.
//SgStatement* loop= NULL;
SgForStatement* forloop = isSgForStatement(scope->get_scope());
SgFortranDo* doloop = isSgFortranDo(scope->get_scope());
if (forloop)
{
//loop = forloop;
}
else if (doloop)
{
//loop = doloop;
}
else
{
cerr<<"Error in CountLoadStoreBytes (): input is not loop body type:"<< input->class_name()<<endl;
assert(false);
}
//Plan A: use and extend Qing's side effect analysis
std::set<SgInitializedName*> readVars;
std::set<SgInitializedName*> writeVars;
bool success = SageInterface::collectReadWriteVariables (isSgStatement(input), readVars, writeVars);
if (success!= true)
{
cout<<"Warning: CountLoadStoreBytes(): failed to collect load/store, mostly due to existence of function calls inside of loop body @ "<<input->get_file_info()->get_line()<<endl;
}
std::set<SgInitializedName*>::iterator it;
if (debug)
cout<<"debug: found read variables (SgInitializedName) count = "<<readVars.size()<<endl;
for (it=readVars.begin(); it!=readVars.end(); it++)
{
SgInitializedName* iname = (*it);
if (debug)
cout<<scalar_or_array (iname->get_type()) <<" "<<iname->get_name()<<"@"<<iname->get_file_info()->get_line()<<endl;
}
if (!includeScalars )
readVars = filterVariables (readVars);
if (debug)
cout<<"debug: found write variables (SgInitializedName) count = "<<writeVars.size()<<endl;
for (it=writeVars.begin(); it!=writeVars.end(); it++)
{
SgInitializedName* iname = (*it);
if (debug)
cout<<scalar_or_array(iname->get_type()) <<" "<<iname->get_name()<<"@"<<iname->get_file_info()->get_line()<<endl;
}
if (!includeScalars )
writeVars = filterVariables (writeVars);
result.first = calculateBytes (readVars, scope, true);
result.second = calculateBytes (writeVars, scope, false);
return result;
}
示例5: timer
//.........这里部分代码省略.........
printf ("SgTemplateInstantiationMemberFunctionDecl: *i = %p = %s \n",*i,(*i)->unparseToString().c_str());
// Call the AST's copy mechanism
SgShallowCopy shallow;
SgNode * forwardDeclarationNode = templateInstantiationMemberFunctionDeclaration->copy(shallow);
SgTemplateInstantiationMemberFunctionDecl* forwardDeclaration = isSgTemplateInstantiationMemberFunctionDecl(forwardDeclarationNode);
ROSE_ASSERT(forwardDeclaration != NULL);
// find the template declaration of the class contining the member function
SgClassDeclaration* classDeclaration = templateInstantiationMemberFunctionDeclaration->get_class_scope()->get_declaration();
ROSE_ASSERT(classDeclaration != NULL);
SgTemplateInstantiationDecl* templateInstantiationDeclaration = isSgTemplateInstantiationDecl(classDeclaration);
ROSE_ASSERT(templateInstantiationDeclaration != NULL);
SgTemplateDeclaration* templateDeclaration = templateInstantiationDeclaration->get_templateDeclaration();
ROSE_ASSERT (templateDeclaration != NULL);
// Reset the file info object so that we can mark this as compiler generated (copy builds a new Sg_File_Info object)
// ROSE_ASSERT (forwardDeclaration->get_file_info() != NULL);
// forwardDeclaration->set_file_info(new Sg_File_Info(*(forwardDeclaration->get_file_info())));
ROSE_ASSERT(forwardDeclaration->get_file_info() != templateInstantiationMemberFunctionDeclaration->get_file_info());
// Both of these may be set (implemented as bit flags internally)
forwardDeclaration->get_file_info()->setCompilerGenerated();
forwardDeclaration->get_file_info()->setTransformation();
// Remove the shallow copy of the function definition
forwardDeclaration->set_definition(NULL);
// Mark the declaration as a forward declarations
forwardDeclaration->setForward();
// Mark this function as a specialization (should be done within copy function)
// forwardDeclaration->set_specialization(SgTemplateInstantiationMemberFunctionDecl::e_specialization);
ROSE_ASSERT(forwardDeclaration->isSpecialization() == true);
ROSE_ASSERT(forwardDeclaration->isPartialSpecialization() == false);
// Now insert the forwardDeclaration after the templateDeclaration!
// templateDeclaration.insert_statement(forwardDeclaration,true);
SgScopeStatement* templateDeclarationScope = templateDeclaration->get_scope();
ROSE_ASSERT (templateDeclarationScope != NULL);
printf ("BEFORE loop: Insert before: templateDeclarationScope = %p = %s \n",templateDeclarationScope,templateDeclarationScope->sage_class_name());
// Trace back through the scopes to find a non class declaration scope into which to put the forward declaration
// Does this then work with nested template classes?????
while (isSgTemplateInstantiationDefn(templateDeclarationScope) != NULL)
{
templateDeclarationScope = templateDeclarationScope->get_scope();
printf ("In loop templateDeclarationScope = %p = %s \n",templateDeclarationScope,templateDeclarationScope->sage_class_name());
}
ROSE_ASSERT (templateDeclarationScope != NULL);
printf ("AFTER loop: Insert before: templateDeclarationScope = %p = %s \n",templateDeclarationScope,templateDeclarationScope->sage_class_name());
templateDeclaration->get_file_info()->display("templateDeclaration");
templateDeclarationScope->get_file_info()->display("templateDeclarationScope");
int insertBeforeStatement = false;
// printf ("Calling templateDeclarationScope->insert_statement() \n");
// templateDeclaration->insert_statement ( templateDeclaration, forwardDeclaration, insertBeforeStatement );
SgTemplateInstantiationDefn *templateClassDefinition = isSgTemplateInstantiationDefn(templateDeclarationScope);
if (templateClassDefinition != NULL)
{
SgDeclarationStatementPtrList::iterator start = templateClassDefinition->get_members().begin();
SgDeclarationStatementPtrList::iterator end = templateClassDefinition->get_members().end();
printf ("templateDeclaration unparsed = %s \n",templateDeclaration->unparseToString().c_str());
printf ("templateDeclaration name = %s string = %s \n",
templateDeclaration->get_name().str(),templateDeclaration->get_string().str());
for (SgDeclarationStatementPtrList::iterator i = start; i != end; i++)
{
string s = (*i)->unparseToString();
printf ("(*i)->unparseToString() = %s \n",s.c_str());
}
ROSE_ASSERT(find(start,end,templateInstantiationMemberFunctionDeclaration) != end);
templateDeclarationScope->insert_statement ( templateInstantiationMemberFunctionDeclaration, forwardDeclaration, insertBeforeStatement );
}
else
{
// ROSE_ASSERT(find(templateDeclarationScope->get_members().begin(),templateDeclarationScope->get_members().end(),templateDeclaration) != templateDeclarationScope->get_members().end() );
templateDeclarationScope->insert_statement ( templateDeclaration, forwardDeclaration, insertBeforeStatement );
}
printf ("forwardDeclaration = %s \n",forwardDeclaration->unparseToString().c_str());
// printf ("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD \n");
// printf ("Exiting after construction of forward declaration for template instantiation! \n");
// ROSE_ASSERT (false);
}
else
{
// This is a forward declaration (does it have the template arguments!)
printf ("SgTemplateInstantiationMemberFunctionDecl: (forward) *i = %p = %s \n",*i,(*i)->unparseToString().c_str());
}
#endif
i++;
}
}