Skip to content

RoseAst::iterator

AST iterator.

Synopsis

Declared in <src/midend/abstractLayer/RoseAst.h>

class iterator;

Description

This is an STL-compliant forward iterator for traversing AST nodes in depth-first pre-order. The withNullValues function includes null child pointers, which are skipped by default. Entire subtrees can be excluded from traversal with the skipChildrenOnForward function.

The iterator also provides a number of auxiliary functions for querying some structural properties of the AST w.r.t. the position in the traversal (e.g., parent and stack_size).

Note

Comparison of iterators is also correct for null values. Only if two iterators refer to the same (identical) null value, they are equal, otherwise they are not. If they refer to different null values they are different. Hence, different null values in the AST are treated like different nodes. This is necessary to allow STL algorithms to work properly on the AST.

Member Functions

Name Description
iterator
iterator(); [constructor]
Constructors
is_past_the_end
bool is_past_the_end() const;
operator*
SgNode* operator*() const;
Dereference an iterator.
operator++
iterator& operator++();
Advance the iterator.
parent
SgNode* parent() const;
Parent AST node relative to the iteration.
skipChildrenOnForward
void skipChildrenOnForward();
Cause children to be skipped on the next advancement.
stack_size
int stack_size() const;
Depth of traversal.
withNullValues
iterator& withNullValues();
Include null child pointers in subsequent traversal.
operator==
bool operator==(iterator const& x) const;
Test iterator equality.
operator!=
bool operator!=(iterator const& x) const;
Test iterator inequality.

Protected Data Members

Name
_skipChildrenOnForward
_withNullValues

Private Types

Name
stack_element

Private Member Functions

Name
access_node_by_parent_and_index
SgNode* access_node_by_parent_and_index( SgNode* p, int index) const;

Private Data Members

Name
_stack

Private Static Data Members

Name
ROOT_NODE_INDEX

Friends

Name Description
RoseAst Interface for iterating over an AST.

Created with MrDocs