ScummVM API documentation
block.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef STARK_TOOLS_BLOCK_H
23 #define STARK_TOOLS_BLOCK_H
24 
25 #include "common/array.h"
26 
27 namespace Stark {
28 namespace Tools {
29 
30 class CFGCommand;
31 struct ControlStructure;
32 
40 class Block {
41 public:
42  Block();
43 
45  void appendCommand(CFGCommand *command);
46 
49 
52 
54  bool isEmpty() const;
55 
57  bool isCondition() const;
58 
66  void setBranches(Block *trueBranch, Block *falseBranch);
67  void setFollower(Block *follower);
68  void addPredecessor(Block *predecessor);
69  Block *getTrueBranch() const;
70  Block *getFalseBranch() const;
71  Block *getFollower() const;
72 
76  void print() const;
77 
81  bool hasControlStructure() const;
82  ControlStructure *getControlStructure() const;
83  void setControlStructure(ControlStructure *controlStructure);
84 
86  bool isInfiniteLoopStart() const;
87  void setInfiniteLoopStart(bool infiniteLoopStart);
88 
90  bool allowDuplication() const;
91 
92  // Graph query methods
93  bool hasPredecessor(Block *predecessor) const;
94  bool hasSuccessor(Block *successor) const;
95  Block *findMergePoint(Block *other);
96  bool checkAllBranchesConverge(Block *junction) const;
97 
98 private:
99  bool hasPredecessorIntern(Common::Array<const Block *> &visited, Block *predecessor) const;
100  bool hasSuccessorIntern(Common::Array<const Block *> &visited, Block *successor) const;
101  bool hasChildSuccessorIntern(Common::Array<const Block *> &visited, Block *child, Block *successor) const;
102  Block *findMergePointIntern(Common::Array<const Block *> &visited, Block *other);
103  Block *findChildMergePoint(Common::Array<const Block *> &visited, Block *child, Block *other) const;
104  bool checkAllBranchesConvergeIntern(Common::Array<const Block *> &visited, Block *junction) const;
105  bool checkChildConvergeIntern(Common::Array<const Block *> &visited, Block *child, Block *junction) const;
106 
107  uint16 getFirstCommandIndex() const;
108 
109  Common::Array<CFGCommand *> _commands;
110 
111  Block *_follower;
112  Block *_trueBranch;
113  Block *_falseBranch;
114  Common::Array<Block *> _predecessors;
115 
116  ControlStructure *_controlStructure;
117  bool _infiniteLoopStart;
118 };
119 
121  enum ControlStructureType {
122  kTypeIf,
123  kTypeWhile
124  };
125 
126  ControlStructureType type;
127  Block *condition;
128  bool invertedCondition;
129  Block *loopHead;
130  Block *thenHead;
131  Block *elseHead;
132  Block *next;
133 
134  ControlStructure(ControlStructureType t);
135 };
136 
137 } // End of namespace Tools
138 } // End of namespace Stark
139 
140 #endif // STARK_TOOLS_BLOCK_H
bool isCondition() const
Definition: array.h:52
Definition: console.h:27
bool isEmpty() const
bool allowDuplication() const
void appendCommand(CFGCommand *command)
void print() const
void setBranches(Block *trueBranch, Block *falseBranch)
Common::Array< CFGCommand * > getLinearCommands() const
bool hasControlStructure() const
CFGCommand * getConditionCommand() const
Definition: block.h:120
Definition: command.h:94
bool isInfiniteLoopStart() const
Definition: block.h:40