Iterator over the Abstract Syntax Trees (ASTs, ast) in the tree rooted at a particular ast.
More...
|
| typedef const ast * | const_pointer |
| | const pointer to the type of the iterator elements. |
| |
| typedef const ast & | const_reference |
| | const reference to the type of the iterator elements. |
| |
| typedef cs_ssize_t | difference_type |
| | Type of distance between iterators. |
| |
| typedef std::forward_iterator_tag | iterator_category |
| | Iterator is a ForwardIterator. |
| |
| typedef ast * | pointer |
| | Pointer to the type of the iterator elements. |
| |
| typedef ast & | reference |
| | Reference to the type of the iterator elements. |
| |
|
(Note that these are not member symbols.)
|
| std::ostream & | operator<< (std::ostream &out, const ast_iterator &a) |
| | Print a representation of an ast_iterator object to the specified stream. |
| |
Iterator over the Abstract Syntax Trees (ASTs, ast) in the tree rooted at a particular ast.
Initialize with ast::traverse().
At any point during traversal with an ast_iterator, ast_traverse_directives can be applied by invoking apply_directives(). See the apply_directives() documentation for an example.
Use as you would any other C++ iterator. For example:
std::cout << "ast: " << *it;
}
Iterator over the Abstract Syntax Trees (ASTs, ast) in the tree rooted at a particular ast.
Definition cs_tplt_instantiations.hpp:502
◆ const_pointer
| typedef const ast* cs::ast_iterator::const_pointer |
|
inherited |
const pointer to the type of the iterator elements.
◆ const_reference
| typedef const ast& cs::ast_iterator::const_reference |
|
inherited |
const reference to the type of the iterator elements.
◆ difference_type
| typedef cs_ssize_t cs::ast_iterator::difference_type |
|
inherited |
Type of distance between iterators.
◆ iterator_category
| typedef std::forward_iterator_tag cs::ast_iterator::iterator_category |
|
inherited |
Iterator is a ForwardIterator.
◆ pointer
| typedef ast* cs::ast_iterator::pointer |
|
inherited |
Pointer to the type of the iterator elements.
◆ reference
| typedef ast& cs::ast_iterator::reference |
|
inherited |
Reference to the type of the iterator elements.
◆ ast_iterator()
| cs::ast_iterator::ast_iterator |
( |
const ast_iterator & |
other | ) |
|
◆ advance()
| void cs::ast_iterator::advance |
( |
| ) |
|
|
inlineinherited |
Advance the iterator by one position.
- Exceptions
-
◆ apply_directives()
Apply ast_traverse_directives to an ast_iterator.
- Parameters
-
- Returns
- void
Invoke at any point during traversal to specify how traversal should proceed from/within the AST (ast) at the current iterator position.
The following example defines two functions that traverse ASTs and print their contents.
traverse_entire_ast() uses an ast_iterator to traverse the entire tree under an AST.
traverse_ast_prune_under_casts() uses an ast_iterator in combination with ast_traverse_directives to traverse a pruned version of the tree that excludes subtrees of c:cast ASTs.
void print_ast_summary(
cs::ast inast){
std::vector< cs::ast_field > ch = inast.
children();
std::cout << inast << " | " ;
for(std::vector<cs::ast_field>::iterator fit = ch.begin(); fit != ch.end(); ++fit) {
std::cout << (*fit) << ' ';
}
std::cout << std::endl;
}
void traverse_entire_ast(
cs::ast inast){
print_ast_summary(*ait);
}
}
void traverse_ast_prune_under_casts(
cs::ast inast){
std::vector< cs::ast_field > ch;
}
print_ast_summary(*ait);
}
}
static const ast_class NC_CASTEXPR
Normalized C/C++ AST class: NC_CASTEXPR
Definition cs_ast_class_decls.hpp:281
static const ast_traverse_directives SKIP_CHILDREN
Skip the children of the current node, but continue with remainder of traversal.
Definition cs_ast_decl.hpp:348
An Abstract Syntax Tree (AST).
Definition cs_ast_decl.hpp:452
ast_iterator traverse(ast_traverse_flags flags=ast_traverse_flags::NONE) const
Get an iterator over an ast.
Definition cs_ast.hpp:203
std::vector< ast_field > children() const
Get all children of an ast.
Definition cs_ast.hpp:165
◆ as_repr()
| std::string cs::ast_iterator::as_repr |
( |
| ) |
const |
|
inlineinherited |
Get a representation of the iterator that includes information useful for debugging.
- Returns
- The string representation.
◆ as_string()
| std::string cs::ast_iterator::as_string |
( |
| ) |
const |
|
inlineinherited |
Get a simple string representation of the iterator.
- Returns
- The string representation.
◆ at_end()
| bool cs::ast_iterator::at_end |
( |
| ) |
const |
|
inlineinherited |
Check: is the iterator at the end of the structure?
- Returns
true if the iterator is at the end of the structure (there are no more elements to iterate over), false otherwise.
◆ operator!=()
| bool cs::ast_iterator::operator!= |
( |
const ast_iterator & |
other | ) |
const |
|
inlineinherited |
Iterator inequality.
- Parameters
-
| [in] | other | The iterator to compare against. |
- Returns
false if and only if this and other are at the same position. Behavior is undefined if this and other are not iterating over the same collection.
◆ operator*()
| ast cs::ast_iterator::operator* |
( |
| ) |
const |
Iterator dereference operator.
- Returns
- The element at the current iterator position.
- Exceptions
-
◆ operator++()
Advance the iterator.
- Exceptions
-
◆ operator=()
Iterator assignment operator.
- Parameters
-
| [in] | other | The iterator to assign. |
- Returns
- A pointer to
this.
◆ operator==()
| bool cs::ast_iterator::operator== |
( |
const ast_iterator & |
other | ) |
const |
|
inlineinherited |
Iterator equality.
- Returns
true if and only if this and other are at the same position. Behavior is undefined if this and other are not iterating over the same collection.
◆ swap()
Exchange the contents of this and other.
◆ operator<<()
| std::ostream & operator<< |
( |
std::ostream & |
out, |
|
|
const ast_iterator & |
a |
|
) |
| |
|
related |
Print a representation of an ast_iterator object to the specified stream.
- Parameters
-
| [in] | out | The stream to print to. |
| [in] | a | The ast_iterator object to print. |
- Returns
- void
The documentation for this class was generated from the following file: