OpenASIP  2.0
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes | List of all members
Reversible Class Referenceabstract

#include <Reversible.hh>

Inheritance diagram for Reversible:
Inheritance graph
Collaboration diagram for Reversible:
Collaboration graph

Public Member Functions

virtual bool operator() ()=0
 
virtual void undo ()
 
virtual ~Reversible ()
 
void deleteChildren (std::stack< Reversible * > &children)
 
int id ()
 
 Reversible ()
 

Protected Member Functions

bool runPreChild (Reversible *preChild)
 
bool runPostChild (Reversible *preChild)
 
bool runChild (std::stack< Reversible * > &children, Reversible *child)
 
bool runChild (Reversible *child, bool pre)
 
void undoAndRemovePreChildren ()
 
void undoAndRemovePostChildren ()
 
void undoAndRemoveChildren (std::stack< Reversible * > &children)
 
virtual void undoOnlyMe ()
 

Protected Attributes

std::stack< Reversible * > preChildren_
 
std::stack< Reversible * > postChildren_
 

Private Attributes

int id_
 

Static Private Attributes

static int idCounter_ = 0
 

Detailed Description

Definition at line 36 of file Reversible.hh.

Constructor & Destructor Documentation

◆ ~Reversible()

Reversible::~Reversible ( )
virtual

Delete the undo information. cannot revert after this

Definition at line 35 of file Reversible.cc.

References deleteChildren(), postChildren_, and preChildren_.

Here is the call graph for this function:

◆ Reversible()

Reversible::Reversible ( )
inline

Definition at line 44 of file Reversible.hh.

44 : id_(idCounter_++) {}

Member Function Documentation

◆ deleteChildren()

void Reversible::deleteChildren ( std::stack< Reversible * > &  children)

Delete children without reverting them. They cannot be reverted after this

Definition at line 42 of file Reversible.cc.

42  {
43  while (!children.empty()) {
44  Reversible* child = children.top();
45  assert(child != nullptr);
46  children.pop();
47  delete child;
48  }
49 }

References assert.

Referenced by ~Reversible().

◆ id()

int Reversible::id ( )
inline

Definition at line 43 of file Reversible.hh.

43 { return id_; }

References id_.

◆ operator()()

virtual bool Reversible::operator() ( )
pure virtual

◆ runChild() [1/2]

bool Reversible::runChild ( Reversible child,
bool  pre 
)
protected

Tries to run another Reversible and takes ownership of it.

Parameters
ifpre is true, make it a pre-child, if pre is false, make it a post-child.
Returns
true if running child succeeded, false if failed.

Definition at line 151 of file Reversible.cc.

151  {
152  if (pre) {
153  return runPreChild(child);
154  } else {
155  return runPostChild(child);
156  }
157 }

References runPostChild(), and runPreChild().

Here is the call graph for this function:

◆ runChild() [2/2]

bool Reversible::runChild ( std::stack< Reversible * > &  children,
Reversible child 
)
protected

Tries to run another Reversible and takes ownership of it.

If the running succeeds, makes it a child. If the running fails, deletes it.

Returns
true if running child succeeded, false if failed.

Definition at line 109 of file Reversible.cc.

109  {
110  if ((*child)()) {
111  children.push(child);
112  return true;
113  } else {
114  delete child;
115  return false;
116  }
117 }

Referenced by runPostChild(), runPreChild(), and BFMergeAndKeepUser::updateEdges().

◆ runPostChild()

bool Reversible::runPostChild ( Reversible postChild)
protected

◆ runPreChild()

bool Reversible::runPreChild ( Reversible preChild)
protected

◆ undo()

void Reversible::undo ( )
virtual

◆ undoAndRemoveChildren()

void Reversible::undoAndRemoveChildren ( std::stack< Reversible * > &  children)
protected

Undoes one stack of children.

Definition at line 55 of file Reversible.cc.

55  {
56  while (!children.empty()) {
57  Reversible* child = children.top();
58  assert(child != nullptr);
59  children.pop();
60  child->undo();
61  delete child;
62  }
63 }

References assert, and undo().

Referenced by BFPushMoveUp::operator()(), undoAndRemovePostChildren(), undoAndRemovePreChildren(), and BFRescheduleMove::undoOnlyMe().

Here is the call graph for this function:

◆ undoAndRemovePostChildren()

void Reversible::undoAndRemovePostChildren ( )
protected

Recursively calls undo for all children that were performed after this. So these are undoed before this is undoed

Definition at line 89 of file Reversible.cc.

89  {
91 }

References postChildren_, and undoAndRemoveChildren().

Referenced by BFRegCopyAfter::splitMove(), and undo().

Here is the call graph for this function:

◆ undoAndRemovePreChildren()

void Reversible::undoAndRemovePreChildren ( )
protected

Recursively calls undo for all children that were performed before this. So these are undoed after this is undoed

Definition at line 80 of file Reversible.cc.

80  {
82 }

References preChildren_, and undoAndRemoveChildren().

Referenced by BFLateBypasses::operator()(), BFPostpassBypass::operator()(), BFPushDepsUp::operator()(), BFScheduleTD::operator()(), BFScheduleBU::operator()(), BFScheduleExact::operator()(), and undo().

Here is the call graph for this function:

◆ undoOnlyMe()

void Reversible::undoOnlyMe ( )
protectedvirtual

Member Data Documentation

◆ id_

int Reversible::id_
private

Definition at line 61 of file Reversible.hh.

Referenced by id().

◆ idCounter_

int Reversible::idCounter_ = 0
staticprivate

Definition at line 62 of file Reversible.hh.

◆ postChildren_

std::stack<Reversible*> Reversible::postChildren_
protected

◆ preChildren_

std::stack<Reversible*> Reversible::preChildren_
protected

The documentation for this class was generated from the following files:
Reversible::postChildren_
std::stack< Reversible * > postChildren_
Definition: Reversible.hh:58
Reversible::idCounter_
static int idCounter_
Definition: Reversible.hh:62
Reversible::undoAndRemovePreChildren
void undoAndRemovePreChildren()
Definition: Reversible.cc:80
Reversible::id_
int id_
Definition: Reversible.hh:61
Reversible::undoAndRemoveChildren
void undoAndRemoveChildren(std::stack< Reversible * > &children)
Definition: Reversible.cc:55
Reversible
Definition: Reversible.hh:36
Reversible::preChildren_
std::stack< Reversible * > preChildren_
Definition: Reversible.hh:57
assert
#define assert(condition)
Definition: Application.hh:86
Reversible::undo
virtual void undo()
Definition: Reversible.cc:69
Reversible::undoOnlyMe
virtual void undoOnlyMe()
Definition: Reversible.cc:98
Reversible::deleteChildren
void deleteChildren(std::stack< Reversible * > &children)
Definition: Reversible.cc:42
Reversible::runChild
bool runChild(std::stack< Reversible * > &children, Reversible *child)
Definition: Reversible.cc:109
Reversible::runPreChild
bool runPreChild(Reversible *preChild)
Definition: Reversible.cc:127
Reversible::undoAndRemovePostChildren
void undoAndRemovePostChildren()
Definition: Reversible.cc:89
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139