ScummVM API documentation
command.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_COMMAND_H
23 #define STARK_TOOLS_COMMAND_H
24 
25 #include "common/array.h"
26 #include "common/hashmap.h"
27 #include "common/hash-ptr.h"
28 
29 #include "engines/stark/resources/command.h"
30 
31 namespace Stark {
32 namespace Tools {
33 
34 class Block;
35 class DefinitionRegistry;
36 
44 class Command {
45 public:
46  enum ControlFlowType {
47  kFlowNormal,
48  kFlowBranch,
49  kFlowEnd
50  };
52 
53  Command(Command *command);
54  Command(Resources::Command *resource);
55 
59  void printCall() const;
60 
62  uint16 getIndex() const;
63  Resources::Command::SubType getSubType() const;
64  bool hasSubtypeDescription() const;
65 
67  ArgumentArray getEffectiveArguments() const;
68 
69 protected:
70  struct SubTypeDesc {
71  Resources::Command::SubType subType;
72  const char *name;
73  ControlFlowType controlFlowType;
74  };
75 
77  static const SubTypeDesc *searchSubTypeDesc(Resources::Command::SubType subType);
78 
81 
82  uint16 _index;
83  Resources::Command::SubType _subType;
84  const SubTypeDesc *_subTypeDesc;
85  ArgumentArray _arguments;
86 };
87 
94 class CFGCommand : public Command {
95 public:
96  CFGCommand(Resources::Command *resource);
97 
99  bool isEntryPoint() const;
100 
102  bool isBranch() const;
103 
105  bool isBranchTarget() const;
106 
114  CFGCommand *getFollower() const;
115  CFGCommand *getTrueBranch() const;
116  CFGCommand *getFalseBranch() const;
117 
121  Block *getBlock() const;
122  void setBlock(Block *block);
123 
129  void linkBranches(const Common::Array<CFGCommand *> &commands);
130 
131 protected:
133  void initBranches();
134 
136  static CFGCommand *findCommandWithIndex(const Common::Array<CFGCommand *> &commands, int32 index);
137 
138  int32 _followerIndex;
139  int32 _trueBranchIndex;
140  int32 _falseBranchIndex;
141 
142  CFGCommand *_follower;
143  CFGCommand *_trueBranch;
144  CFGCommand *_falseBranch;
145  Common::Array<CFGCommand *> _predecessors;
146 
147  Block *_block;
148 };
149 
154 public:
160  void registerReference(const ResourceReference &reference);
161 
163  Common::String getFromReference(const ResourceReference &reference) const;
164 
166  void printAll() const;
167 
168 private:
170 
171  Common::String stringToCamelCase(const Common::String &input);
172 
173  DefinitionMap _definitions;
174 };
175 
176 } // End of namespace Tools
177 } // End of namespace Stark
178 
179 #endif // STARK_TOOLS_COMMAND_H
Common::String describeArguments(DefinitionRegistry *definitions) const
Definition: str.h:59
Definition: command.h:153
static const SubTypeDesc * searchSubTypeDesc(Resources::Command::SubType subType)
ArgumentArray getEffectiveArguments() const
void printCall() const
Definition: resourcereference.h:39
Definition: console.h:27
Definition: command.h:51
Definition: command.h:44
uint16 getIndex() const
Definition: command.h:94
Definition: command.h:70
Definition: block.h:40