Program Listing for File RoseAst.h

Program Listing for File RoseAst.h#

Return to documentation for file (src/midend/abstractLayer/RoseAst.h)

#ifndef ROSE_AST_H
#define ROSE_AST_H

/*************************************************************
 * Author   : Markus Schordan                                *
 *************************************************************/

#include <stack>
#include "roseInternal.h"

class RoseAst {
 public:
  typedef SgNode elementType;
  typedef elementType* pointer;
  typedef elementType& reference;
  typedef size_t size_type;

  // no default constructor

  RoseAst(SgNode* astNode);

  class iterator {
  public:

    iterator();

    iterator(SgNode* x,bool withNullValues, bool withTemplates);

    bool operator==(const iterator& x) const;

    bool operator!=(const iterator& x) const;

    SgNode* operator*() const;

    iterator& operator++(); // prefix
    iterator operator++(int); // postfix
    void skipChildrenOnForward();

    iterator& withoutNullValues();
    iterator& withNullValues();
    iterator& withoutTemplates();
    iterator& withTemplates();

    SgNode* parent() const;

    bool is_at_root() const;

    bool is_at_first_child() const;

    bool is_at_last_child() const;

    // internal
    bool is_past_the_end() const;
    // internal
    std::string current_node_id() const;
    // internal
    std::string parent_node_id() const;
    // internal
    void print_top_element() const;

    int stack_size() const;

  protected:
    SgNode* _startNode;
    bool _skipChildrenOnForward;
    bool _withNullValues;
    bool _withTemplates;

  private:
    static const int ROOT_NODE_INDEX=-2;
    friend class RoseAst;
    typedef struct {SgNode* node; int index;} stack_element;
    std::stack<stack_element> _stack;
    SgNode* access_node_by_parent_and_index(SgNode* p, int index) const;

    // not necessary with a children iterator
    int num_children(SgNode* p) const;
  };

  iterator begin();

  iterator end();

  // ast access function
  SgFunctionDefinition* findFunctionByName(std::string name);
  std::list<SgFunctionDeclaration*> findFunctionDeclarationsByName(std::string name);

  static bool isTemplateInstantiationNode(SgNode* node);

  static bool isTemplateNode(SgNode* node);

static bool isSubTypeOf(VariantT DerivedClassVariant, VariantT BaseClassVariant);
static bool isSubType(VariantT DerivedClassVariant, VariantT BaseClassVariant);
 void setWithNullValues(bool flag);
 void setWithTemplates(bool flag);

 protected:
  static SgNode* parent(SgNode* astNode);
 private:
  SgNode* _startNode;
  bool _withNullValues;
  bool _withTemplates;
};

#endif