ScummVM API documentation
abstractsyntaxtree.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_ABSTRACT_SYNTAX_TREE_H
23 #define STARK_TOOLS_ABSTRACT_SYNTAX_TREE_H
24 
25 #include "common/array.h"
26 
27 #include "engines/stark/tools/command.h"
28 
29 namespace Stark {
30 namespace Tools {
31 
32 struct ASTCommand;
33 
39 struct ASTNode {
40  ASTNode(ASTNode *parent);
41  virtual ~ASTNode();
42 
44  virtual void print(uint depth, DefinitionRegistry *definitions) = 0;
45 
47  virtual Common::Array<const ASTCommand *> listCommands(uint16 index) const = 0;
48 
50  void findSuccessors(ASTNode **follower, ASTNode **trueBranch, ASTNode **falseBranch) const;
51  virtual void findSuccessorsIntern(const ASTNode *node, ASTNode **follower, ASTNode **trueBranch, ASTNode **falseBranch) const = 0;
52 
54  virtual const ASTCommand *getFirstCommand() const = 0;
55 
56 protected:
57  void printWithDepth(uint depth, const Common::String &string) const;
58 
59  ASTNode *_parent;
60 };
61 
67 struct ASTCommand : public ASTNode, public Command {
68  ASTCommand(ASTNode *parent, Command *command, DefinitionRegistry *definitions);
69 
70  // ASTNode API
71  void print(uint depth, DefinitionRegistry *definitions) override;
72  Common::Array<const ASTCommand *> listCommands(uint16 index) const override;
73  void findSuccessorsIntern(const ASTNode *node, ASTNode **follower, ASTNode **trueBranch, ASTNode **falseBranch) const override;
74  const ASTCommand *getFirstCommand() const override;
75 
77  Common::String callString(DefinitionRegistry *definitions);
78 };
79 
85 struct ASTBlock : public ASTNode {
86  ASTBlock(ASTNode *parent);
87  ~ASTBlock() override;
88 
89  // ASTNode API
90  void print(uint depth, DefinitionRegistry *definitions) override;
91  Common::Array<const ASTCommand *> listCommands(uint16 index) const override;
92  void findSuccessorsIntern(const ASTNode *node, ASTNode **follower, ASTNode **trueBranch, ASTNode **falseBranch) const override;
93  const ASTCommand *getFirstCommand() const override;
94 
96  void addNode(ASTNode *node);
97 
98 private:
99  Common::Array<ASTNode *> _children;
100 };
101 
107 struct ASTCondition : public ASTNode {
108  ASTCondition(ASTNode *parent);
109  ~ASTCondition() override;
110 
111  // ASTNode API
112  void print(uint depth, DefinitionRegistry *definitions) override;
113  Common::Array<const ASTCommand *> listCommands(uint16 index) const override;
114  void findSuccessorsIntern(const ASTNode *node, ASTNode **follower, ASTNode **trueBranch, ASTNode **falseBranch) const override;
115  const ASTCommand *getFirstCommand() const override;
116 
117  ASTCommand *condition;
118  bool invertedCondition;
119  ASTBlock *thenBlock;
120  ASTBlock *elseBlock;
121 };
122 
128 struct ASTLoop : public ASTNode {
129  ASTLoop(ASTNode *parent);
130  ~ASTLoop() override;
131 
132  // ASTNode API
133  void print(uint depth, DefinitionRegistry *definitions) override;
134  Common::Array<const ASTCommand *> listCommands(uint16 index) const override;
135  void findSuccessorsIntern(const ASTNode *node, ASTNode **follower, ASTNode **trueBranch, ASTNode **falseBranch) const override;
136  const ASTCommand *getFirstCommand() const override;
137 
138  ASTCommand *condition;
139  bool invertedCondition;
140  ASTBlock *loopBlock;
141 };
142 
143 } // End of namespace Tools
144 } // End of namespace Stark
145 
146 #endif // STARK_TOOLS_ABSTRACT_SYNTAX_TREE_H
Definition: abstractsyntaxtree.h:107
Definition: str.h:59
virtual Common::Array< const ASTCommand * > listCommands(uint16 index) const =0
virtual void print(uint depth, DefinitionRegistry *definitions)=0
Definition: command.h:153
Definition: array.h:52
void findSuccessors(ASTNode **follower, ASTNode **trueBranch, ASTNode **falseBranch) const
virtual const ASTCommand * getFirstCommand() const =0
Definition: console.h:27
Definition: abstractsyntaxtree.h:39
Definition: abstractsyntaxtree.h:128
Definition: command.h:44
Definition: abstractsyntaxtree.h:85
Definition: abstractsyntaxtree.h:67