49 |
|
#include "brains/SimInfo.hpp" |
50 |
|
#include "selection/Token.hpp" |
51 |
|
#include "selection/SelectionCompiler.hpp" |
52 |
+ |
#include "selection/NameFinder.hpp" |
53 |
+ |
#include "selection/DistanceFinder.hpp" |
54 |
|
#include "utils/BitSet.hpp" |
55 |
< |
|
55 |
> |
#include "primitives/StuntDouble.hpp" |
56 |
> |
#include "utils/StringUtils.hpp" |
57 |
|
namespace oopse { |
58 |
|
|
56 |
– |
class Context { |
57 |
– |
public: |
58 |
– |
|
59 |
– |
void clear() { |
60 |
– |
linenumbers.clear(); |
61 |
– |
lineIndices.clear(); |
62 |
– |
aatoken.clear(); |
63 |
– |
} |
64 |
– |
|
65 |
– |
std::string filename; |
66 |
– |
std::string script; |
67 |
– |
std::vector<int> linenumbers; |
68 |
– |
std::vector<int> lineIndices; |
69 |
– |
std::vector<std::vector<Token> > aatoken; |
70 |
– |
int pc; |
71 |
– |
}; |
59 |
|
|
60 |
+ |
//class Context { |
61 |
+ |
// public: |
62 |
+ |
// |
63 |
+ |
// void clear() { |
64 |
+ |
// linenumbers.clear(); |
65 |
+ |
// lineIndices.clear(); |
66 |
+ |
// aatoken.clear(); |
67 |
+ |
// } |
68 |
+ |
// |
69 |
+ |
// std::string filename; |
70 |
+ |
// std::string script; |
71 |
+ |
// std::vector<int> linenumbers; |
72 |
+ |
// std::vector<int> lineIndices; |
73 |
+ |
// std::vector<std::vector<Token> > aatoken; |
74 |
+ |
// int pc; |
75 |
+ |
//}; |
76 |
+ |
|
77 |
+ |
|
78 |
|
/** |
79 |
|
* @class SelectionEvaluator SelectionEvaluator.hpp "selection/SelectionEvaluator" |
80 |
|
* @brief Evalute the tokens compiled by SelectionCompiler and return a BitSet |
82 |
|
class SelectionEvaluator{ |
83 |
|
public: |
84 |
|
|
85 |
< |
SelectionEvaluator(SimInfo* info, const std::string& script); |
85 |
> |
SelectionEvaluator(SimInfo* info); |
86 |
|
|
87 |
|
|
88 |
+ |
bool loadScriptString(const std::string& script); |
89 |
+ |
bool loadScriptFile(const std::string& filename); |
90 |
+ |
|
91 |
|
BitSet evaluate(); |
92 |
|
|
93 |
< |
BitSet evaluate(int frameNo); |
93 |
> |
//BitSet evaluate(Snapshot* snapshot); |
94 |
|
|
95 |
|
/** |
96 |
< |
* Tests if the result from evaluation of script is static. |
89 |
< |
* @return true if the result keeps the same even the frame change, otherwise return false |
96 |
> |
* Tests if the result from evaluation of script is dynamic. |
97 |
|
*/ |
98 |
< |
bool isStatic(); |
98 |
> |
bool isDynamic() { |
99 |
> |
return isDynamic_; |
100 |
> |
} |
101 |
|
|
102 |
|
bool hadRuntimeError() const{ |
103 |
|
return error; |
127 |
|
void clearState(); |
128 |
|
|
129 |
|
bool loadScript(const std::string& filename, const std::string& script); |
130 |
< |
bool loadScriptString(const std::string& script); |
130 |
> |
|
131 |
|
bool loadScriptFileInternal(const std::string& filename); |
123 |
– |
bool loadScriptFile(const std::string& filename); |
132 |
|
|
133 |
+ |
|
134 |
|
void clearDefinitionsAndLoadPredefined(); |
135 |
|
|
136 |
|
void define(); |
137 |
< |
void select(); |
138 |
< |
void predefine(); |
137 |
> |
void select(BitSet& bs); |
138 |
> |
void predefine(const std::string& script); |
139 |
|
|
140 |
< |
void instructionDispatchLoop(); |
140 |
> |
void instructionDispatchLoop(BitSet& bs); |
141 |
|
|
142 |
< |
void withinInstruction(const Token& instruction, BitSet& , BitSet&); |
142 |
> |
void withinInstruction(const Token& instruction, BitSet& bs); |
143 |
> |
|
144 |
> |
BitSet comparatorInstruction(const Token& instruction); |
145 |
> |
void compareProperty(StuntDouble* sd, BitSet& bs, int property, int comparator, float comparisonValue); |
146 |
> |
BitSet nameInstruction(const std::string& name); |
147 |
> |
BitSet indexInstruction(const boost::any& value); |
148 |
> |
BitSet expression(const std::vector<Token>& tokens, int pc); |
149 |
|
|
150 |
< |
BitSet expression(std::vector<Token>& tokens, int pc); |
150 |
> |
BitSet lookupValue(const std::string& variable); |
151 |
> |
|
152 |
> |
void evalError(const std::string& message) { |
153 |
> |
std::cerr << "SelectionEvaulator Error: " << message << std::endl; |
154 |
> |
} |
155 |
|
|
137 |
– |
|
138 |
– |
void evalError(const std::string& message); |
139 |
– |
|
156 |
|
void unrecognizedCommand(const Token& token) { |
157 |
< |
evalError("unrecognized command:" + token.value); |
157 |
> |
evalError("unrecognized command:" + boost::any_cast<std::string>(token.value)); |
158 |
|
} |
159 |
+ |
|
160 |
+ |
void unrecognizedExpression() { |
161 |
+ |
evalError("unrecognized expression"); |
162 |
+ |
} |
163 |
+ |
|
164 |
+ |
void unrecognizedAtomProperty(int property){ |
165 |
+ |
evalError("unrecognized atom property"); |
166 |
+ |
} |
167 |
+ |
|
168 |
+ |
void unrecognizedIdentifier(const std::string& identifier) { |
169 |
+ |
evalError("unrecognized identifier:" + identifier); |
170 |
+ |
} |
171 |
+ |
|
172 |
+ |
void invalidIndexRange(std::pair<int, int> range) { |
173 |
+ |
evalError("invalid index range: [" + toString(range.first) + ", " + toString(range.second) + ")"); |
174 |
+ |
} |
175 |
+ |
|
176 |
+ |
void invalidIndex(int index) { |
177 |
+ |
evalError("invalid index : " + toString(index) ); |
178 |
+ |
} |
179 |
+ |
|
180 |
|
|
181 |
+ |
bool containDynamicToken(const std::vector<Token>& tokens); |
182 |
+ |
|
183 |
|
SelectionCompiler compiler; |
184 |
|
|
185 |
< |
const static int scriptLevelMax = 10; |
186 |
< |
int scriptLevel; |
185 |
> |
//const static int scriptLevelMax = 10; |
186 |
> |
//int scriptLevel; |
187 |
|
|
188 |
< |
Context stack[scriptLevelMax]; |
188 |
> |
//Context stack[scriptLevelMax]; |
189 |
|
|
190 |
|
std::string filename; |
191 |
|
std::string script; |
201 |
|
int statementLength; |
202 |
|
|
203 |
|
SimInfo* info; |
204 |
+ |
NameFinder nameFinder; |
205 |
+ |
DistanceFinder distanceFinder; |
206 |
+ |
int nStuntDouble; //natoms + nrigidbodies |
207 |
+ |
std::map<std::string, boost::any > variables; |
208 |
|
|
209 |
< |
std::map<std::string, std::vector<Token> > variables; |
209 |
> |
bool isDynamic_; |
210 |
> |
bool isLoaded_; |
211 |
> |
|
212 |
|
}; |
213 |
|
|
214 |
|
} |