本文整理汇总了C++中Traversal::traverse方法的典型用法代码示例。如果您正苦于以下问题:C++ Traversal::traverse方法的具体用法?C++ Traversal::traverse怎么用?C++ Traversal::traverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Traversal
的用法示例。
在下文中一共展示了Traversal::traverse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visit
// size_t getLocalScopeNum ( SgFunctionDefinition* func_def, const SgScopeStatement* target)
size_t
getLocalScopeNum (const SgFunctionDefinition* func_def, const SgScopeStatement* target)
{
#if SKIP_BLOCK_NUMBER_CACHING
// DQ (10/4/2006): This takes too long and stalls the compilation of
// some large codes (plum hall e.g. cvs06a/conform/ch7_22.c). It is
// rewritten below to use a cache mechanisk link to a cache invalidation
// mechanism.
// Preorder traversal to count the number of basic blocks preceeding 'target'
class Traversal : public AstSimpleProcessing
{
public:
Traversal (const SgScopeStatement* target)
: target_ (target), count_ (0), found_ (false)
{}
void visit (SgNode* node)
{
if (!found_)
{
const SgScopeStatement* stmt = isSgScopeStatement (node);
if (stmt)
{
count_++;
found_ = (stmt == target_);
}
}
}
size_t count (void) const { return found_ ? count_ : 0; }
private:
const SgScopeStatement* target_; // Target scope statement
size_t count_; // found_ ? number of target : number of last block seen
bool found_; // true <==> target_ has been found
};
Traversal counter (target);
counter.traverse (const_cast<SgFunctionDefinition *> (func_def), preorder);
return counter.count ();
#else
// DQ (10/6/2006): Implemented caching of computed lables for scopes in
// functions to avoid quadratic behavior of previous implementation. The model
// for this is the same a s what will be done to support caching of mangled names.
// printf ("getLocalScopeNum calling func_def->get_scope_number(target)! \n");
return func_def->get_scope_number(target);
#endif
}
示例2: testAST
void testAST( SgProject* project )
{
class Traversal : public SgSimpleProcessing
{
public:
Traversal() {}
void visit ( SgNode* n )
{
SgLocatedNode* locatedNode = isSgLocatedNode(n);
if (locatedNode != NULL)
{
AttachedPreprocessingInfoType* comments = locatedNode->getAttachedPreprocessingInfo();
if (comments != NULL)
{
printf ("Found attached comments (at %p of type: %s): \n",locatedNode,locatedNode->sage_class_name());
AttachedPreprocessingInfoType::iterator i;
for (i = comments->begin(); i != comments->end(); i++)
{
ROSE_ASSERT ( (*i) != NULL );
printf (" Attached Comment (relativePosition=%s): %s\n",
((*i)->getRelativePosition() == PreprocessingInfo::before) ? "before" : "after",
(*i)->getString().c_str());
#if 1
// This does not appear to be a valid object when read in from an AST file.
printf ("Comment/Directive getNumberOfLines = %d getColumnNumberOfEndOfString = %d \n",(*i)->getNumberOfLines(),(*i)->getColumnNumberOfEndOfString());
#endif
#if 1
// This does not appear to be a valid object when read in from an AST file.
(*i)->get_file_info()->display("comment/directive location");
#endif
}
}
}
}
};
Traversal counter;
counter.traverse(project,preorder);
}
示例3: main
int main (int argc, char* argv[])
{
// We retrieve the traversal kind from the command line
TraversalKind traversalKind = getTraversalKind (argc, argv);
//! [snippet1_traversal]
const char* seqs[] =
{
"CGCTACAGCAGCTAGTTCATCATTGTTTATCAATGATAAAATATAATAAGCTAAAAGGAAACTATAAATA",
"CGCTACAGCAGCTAGTTCATCATTGTTTATCGATGATAAAATATAATAAGCTAAAAGGAAACTATAAATA"
// SNP HERE at pos 31 x
};
// We create a fake bank with a SNP
IBank* bank = new BankStrings (seqs, ARRAY_SIZE(seqs));
// We load the graph
Graph graph = Graph::create (bank, "-abundance-min 1 -kmer-size 15 -verbose 0");
// We create a Terminator object
BranchingTerminator terminator (graph);
// We create a Traversal instance according to the chosen traversal kind
Traversal* traversal = Traversal::create (traversalKind, graph, terminator);
LOCAL (traversal);
// We create a node from the start of the first sequence
Node node = graph.buildNode (seqs[0]);
Path path;
int len = traversal->traverse (node, DIR_OUTCOMING, path);
// We dump the length, the starting node and the path
cout << "length=" << len << " " << graph.toString (node) << path << endl;
//! [snippet1_traversal]
return EXIT_SUCCESS;
}