ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

block.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef STARK_TOOLS_BLOCK_H
00024 #define STARK_TOOLS_BLOCK_H
00025 
00026 #include "common/array.h"
00027 
00028 namespace Stark {
00029 namespace Tools {
00030 
00031 class CFGCommand;
00032 struct ControlStructure;
00033 
00041 class Block {
00042 public:
00043     Block();
00044 
00046     void appendCommand(CFGCommand *command);
00047 
00049     Common::Array<CFGCommand *> getLinearCommands() const;
00050 
00052     CFGCommand *getConditionCommand() const;
00053 
00055     bool isEmpty() const;
00056 
00058     bool isCondition() const;
00059 
00067     void setBranches(Block *trueBranch, Block *falseBranch);
00068     void setFollower(Block *follower);
00069     void addPredecessor(Block *predecessor);
00070     Block *getTrueBranch() const;
00071     Block *getFalseBranch() const;
00072     Block *getFollower() const;
00073 
00077     void print() const;
00078 
00082     bool hasControlStructure() const;
00083     ControlStructure *getControlStructure() const;
00084     void setControlStructure(ControlStructure *controlStructure);
00085 
00087     bool isInfiniteLoopStart() const;
00088     void setInfiniteLoopStart(bool infiniteLoopStart);
00089 
00091     bool allowDuplication() const;
00092 
00093     // Graph query methods
00094     bool hasPredecessor(Block *predecessor) const;
00095     bool hasSuccessor(Block *successor) const;
00096     Block *findMergePoint(Block *other);
00097     bool checkAllBranchesConverge(Block *junction) const;
00098 
00099 private:
00100     bool hasPredecessorIntern(Common::Array<const Block *> &visited, Block *predecessor) const;
00101     bool hasSuccessorIntern(Common::Array<const Block *> &visited, Block *successor) const;
00102     bool hasChildSuccessorIntern(Common::Array<const Block *> &visited, Block *child, Block *successor) const;
00103     Block *findMergePointIntern(Common::Array<const Block *> &visited, Block *other);
00104     Block *findChildMergePoint(Common::Array<const Block *> &visited, Block *child, Block *other) const;
00105     bool checkAllBranchesConvergeIntern(Common::Array<const Block *> &visited, Block *junction) const;
00106     bool checkChildConvergeIntern(Common::Array<const Block *> &visited, Block *child, Block *junction) const;
00107 
00108     uint16 getFirstCommandIndex() const;
00109 
00110     Common::Array<CFGCommand *> _commands;
00111 
00112     Block *_follower;
00113     Block *_trueBranch;
00114     Block *_falseBranch;
00115     Common::Array<Block *> _predecessors;
00116 
00117     ControlStructure *_controlStructure;
00118     bool _infiniteLoopStart;
00119 };
00120 
00121 struct ControlStructure {
00122     enum ControlStructureType {
00123         kTypeIf,
00124         kTypeWhile
00125     };
00126 
00127     ControlStructureType type;
00128     Block *condition;
00129     bool invertedCondition;
00130     Block *loopHead;
00131     Block *thenHead;
00132     Block *elseHead;
00133     Block *next;
00134 
00135     ControlStructure(ControlStructureType t);
00136 };
00137 
00138 } // End of namespace Tools
00139 } // End of namespace Stark
00140 
00141 #endif // STARK_TOOLS_BLOCK_H


Generated on Sat Mar 16 2019 05:01:20 for ResidualVM by doxygen 1.7.1
curved edge   curved edge