# | Line 49 | Line 49 | namespace oopse { | |
---|---|---|
49 | namespace oopse { | |
50 | ||
51 | ||
52 | < | SelectionEvaluator::SelectionEvaluator(SimInfo* si, const std::string& script) : info(si), finder(info){ |
52 | > | SelectionEvaluator::SelectionEvaluator(SimInfo* si) : info(si), finder(info), isLoaded_(false){ |
53 | > | |
54 | } | |
55 | ||
56 | bool SelectionEvaluator::loadScript(const std::string& filename, const std::string& script) { | |
57 | + | clearDefinitionsAndLoadPredefined(); |
58 | this->filename = filename; | |
59 | this->script = script; | |
60 | if (! compiler.compile(filename, script)) { | |
61 | error = true; | |
62 | errorMessage = compiler.getErrorMessage(); | |
63 | + | std::cerr << "SelectionCompiler Error: " << errorMessage << std::endl; |
64 | return false; | |
65 | } | |
66 | ||
# | Line 65 | Line 68 | bool SelectionEvaluator::loadScript(const std::string& | |
68 | aatoken = compiler.getAatokenCompiled(); | |
69 | linenumbers = compiler.getLineNumbers(); | |
70 | lineIndices = compiler.getLineIndices(); | |
71 | + | |
72 | + | std::vector<std::vector<Token> >::const_iterator i; |
73 | + | |
74 | + | isDynamic_ = false; |
75 | + | for (i = aatoken.begin(); i != aatoken.end(); ++i) { |
76 | + | if (containDynamicToken(*i)) { |
77 | + | isDynamic_ = true; |
78 | + | break; |
79 | + | } |
80 | + | } |
81 | + | |
82 | + | isLoaded_ = true; |
83 | return true; | |
84 | } | |
85 | ||
86 | void SelectionEvaluator::clearState() { | |
87 | < | for (int i = scriptLevelMax; --i >= 0; ) |
88 | < | stack[i].clear(); |
89 | < | scriptLevel = 0; |
87 | > | //for (int i = scriptLevelMax; --i >= 0; ) |
88 | > | // stack[i].clear(); |
89 | > | //scriptLevel = 0; |
90 | error = false; | |
91 | errorMessage = ""; | |
92 | } | |
# | Line 87 | Line 102 | bool SelectionEvaluator::loadScriptFileInternal(const | |
102 | } | |
103 | ||
104 | bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) { | |
105 | < | return true; /**@todo */ |
105 | > | ifstream ifs(filename.c_str()); |
106 | > | if (!ifs.is_open()) { |
107 | > | return false; |
108 | > | } |
109 | > | |
110 | > | const int bufferSize = 65535; |
111 | > | char buffer[bufferSize]; |
112 | > | std::string script; |
113 | > | while(ifs.getline(buffer, bufferSize)) { |
114 | > | script += buffer; |
115 | > | } |
116 | > | return loadScript(filename, script); |
117 | } | |
118 | ||
119 | < | void SelectionEvaluator::instructionDispatchLoop(){ |
120 | < | |
119 | > | void SelectionEvaluator::instructionDispatchLoop(BitSet& bs){ |
120 | > | |
121 | while ( pc < aatoken.size()) { | |
122 | statement = aatoken[pc++]; | |
123 | statementLength = statement.size(); | |
# | Line 101 | Line 127 | void SelectionEvaluator::instructionDispatchLoop(){ | |
127 | define(); | |
128 | break; | |
129 | case Token::select: | |
130 | < | select(); |
130 | > | select(bs); |
131 | break; | |
132 | default: | |
133 | unrecognizedCommand(token); | |
134 | return; | |
135 | } | |
136 | } | |
137 | + | |
138 | } | |
139 | ||
140 | BitSet SelectionEvaluator::expression(const std::vector<Token>& code, int pcStart) { | |
141 | BitSet bs; | |
142 | std::stack<BitSet> stack; | |
143 | ||
144 | < | for (int pc = pcStart; ; ++pc) { |
144 | > | for (int pc = pcStart; pc < code.size(); ++pc) { |
145 | Token instruction = code[pc]; | |
146 | ||
147 | switch (instruction.tok) { | |
# | Line 301 | Line 328 | void SelectionEvaluator::predefine(const std::string& | |
328 | ||
329 | } | |
330 | ||
331 | < | void SelectionEvaluator::select(){ |
332 | < | //viewer.setSelectionSet(expression(statement, 1)); |
331 | > | void SelectionEvaluator::select(BitSet& bs){ |
332 | > | bs = expression(statement, 1); |
333 | } | |
334 | ||
335 | BitSet SelectionEvaluator::lookupValue(const std::string& variable){ | |
# | Line 323 | Line 350 | BitSet SelectionEvaluator::nameInstruction(const std:: | |
350 | } | |
351 | ||
352 | BitSet SelectionEvaluator::nameInstruction(const std::string& name){ | |
326 | – | BitSet bs(nStuntDouble); |
353 | ||
354 | < | bool hasError = finder.match(name, bs); |
355 | < | |
330 | < | return bs; |
354 | > | return finder.match(name); |
355 | > | |
356 | } | |
357 | ||
358 | + | bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){ |
359 | + | std::vector<Token>::const_iterator i; |
360 | + | for (i = tokens.begin(); i != tokens.end(); ++i) { |
361 | + | if (i->tok & Token::dynamic) { |
362 | + | return true; |
363 | + | } |
364 | + | } |
365 | ||
366 | + | return false; |
367 | + | } |
368 | + | |
369 | + | void SelectionEvaluator::clearDefinitionsAndLoadPredefined() { |
370 | + | variables.clear(); |
371 | + | //load predefine |
372 | + | //predefine(); |
373 | } | |
374 | + | |
375 | + | BitSet SelectionEvaluator::evaluate() { |
376 | + | BitSet bs(nStuntDouble); |
377 | + | if (isLoaded_) { |
378 | + | instructionDispatchLoop(bs); |
379 | + | } |
380 | + | |
381 | + | return bs; |
382 | + | } |
383 | + | |
384 | + | //BitSet SelectionEvaluator::evaluate(int frameNo) { |
385 | + | // |
386 | + | //} |
387 | + | |
388 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |