1 |
schoenebeck |
2581 |
/* |
2 |
schoenebeck |
2935 |
* Copyright (c) 2014 - 2016 Christian Schoenebeck and Andreas Persson |
3 |
schoenebeck |
2581 |
* |
4 |
|
|
* http://www.linuxsampler.org |
5 |
|
|
* |
6 |
|
|
* This file is part of LinuxSampler and released under the same terms. |
7 |
|
|
* See README file for details. |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include <cstdio> |
11 |
|
|
#include <string.h> |
12 |
|
|
#include "tree.h" |
13 |
|
|
#include "../common/global_private.h" |
14 |
schoenebeck |
2588 |
#include <assert.h> |
15 |
schoenebeck |
2581 |
|
16 |
|
|
namespace LinuxSampler { |
17 |
|
|
|
18 |
|
|
bool isNoOperation(StatementRef statement) { |
19 |
|
|
NoOperation* noOp = dynamic_cast<NoOperation*>(&*statement); |
20 |
|
|
return noOp; |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
Node::Node() { |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
Node::~Node() { |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
void Node::printIndents(int n) { |
30 |
|
|
for (int i = 0; i < n; ++i) printf(" "); |
31 |
|
|
fflush(stdout); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
String IntExpr::evalCastToStr() { |
35 |
|
|
return ToString(evalInt()); |
36 |
|
|
} |
37 |
|
|
|
38 |
schoenebeck |
3056 |
/*String IntArrayExpr::evalCastToStr() { |
39 |
|
|
String s = "{"; |
40 |
|
|
for (int i = 0; i < arraySize(); ++i) { |
41 |
|
|
int val = evalIntElement(i); |
42 |
|
|
if (i) s += ","; |
43 |
|
|
s += ToString(val); |
44 |
|
|
} |
45 |
|
|
s += "}"; |
46 |
|
|
return s; |
47 |
|
|
}*/ |
48 |
|
|
|
49 |
schoenebeck |
2581 |
int IntLiteral::evalInt() { |
50 |
|
|
return value; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
void IntLiteral::dump(int level) { |
54 |
|
|
printIndents(level); |
55 |
|
|
printf("IntLiteral %d\n", value); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
void StringLiteral::dump(int level) { |
59 |
|
|
printIndents(level); |
60 |
|
|
printf("StringLiteral: '%s'\n", value.c_str()); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
int Add::evalInt() { |
64 |
|
|
IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs); |
65 |
|
|
IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);; |
66 |
|
|
return (pLHS && pRHS) ? pLHS->evalInt() + pRHS->evalInt() : 0; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
void Add::dump(int level) { |
70 |
|
|
printIndents(level); |
71 |
|
|
printf("Add(\n"); |
72 |
|
|
lhs->dump(level+1); |
73 |
|
|
printIndents(level); |
74 |
|
|
printf(",\n"); |
75 |
|
|
rhs->dump(level+1); |
76 |
|
|
printIndents(level); |
77 |
|
|
printf(")\n"); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
int Sub::evalInt() { |
81 |
|
|
IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs); |
82 |
|
|
IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);; |
83 |
|
|
return (pLHS && pRHS) ? pLHS->evalInt() - pRHS->evalInt() : 0; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
void Sub::dump(int level) { |
87 |
|
|
printIndents(level); |
88 |
|
|
printf("Sub(\n"); |
89 |
|
|
lhs->dump(level+1); |
90 |
|
|
printIndents(level); |
91 |
|
|
printf(",\n"); |
92 |
|
|
rhs->dump(level+1); |
93 |
|
|
printIndents(level); |
94 |
|
|
printf(")\n"); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
int Mul::evalInt() { |
98 |
|
|
IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs); |
99 |
|
|
IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);; |
100 |
|
|
return (pLHS && pRHS) ? pLHS->evalInt() * pRHS->evalInt() : 0; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
void Mul::dump(int level) { |
104 |
|
|
printIndents(level); |
105 |
|
|
printf("Mul(\n"); |
106 |
|
|
lhs->dump(level+1); |
107 |
|
|
printIndents(level); |
108 |
|
|
printf(",\n"); |
109 |
|
|
rhs->dump(level+1); |
110 |
|
|
printIndents(level); |
111 |
|
|
printf(")\n"); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
int Div::evalInt() { |
115 |
|
|
IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs); |
116 |
schoenebeck |
2945 |
IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs); |
117 |
|
|
if (!pLHS || !pRHS) return 0; |
118 |
|
|
int l = pLHS->evalInt(); |
119 |
|
|
int r = pRHS->evalInt(); |
120 |
|
|
if (r == 0) return 0; |
121 |
|
|
return l / r; |
122 |
schoenebeck |
2581 |
} |
123 |
|
|
|
124 |
|
|
void Div::dump(int level) { |
125 |
|
|
printIndents(level); |
126 |
|
|
printf("Div(\n"); |
127 |
|
|
lhs->dump(level+1); |
128 |
|
|
printIndents(level); |
129 |
|
|
printf(",\n"); |
130 |
|
|
rhs->dump(level+1); |
131 |
|
|
printIndents(level); |
132 |
|
|
printf(")\n"); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
int Mod::evalInt() { |
136 |
|
|
IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs); |
137 |
|
|
IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);; |
138 |
|
|
return (pLHS && pRHS) ? pLHS->evalInt() % pRHS->evalInt() : 0; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
void Mod::dump(int level) { |
142 |
|
|
printIndents(level); |
143 |
|
|
printf("Mod(\n"); |
144 |
|
|
lhs->dump(level+1); |
145 |
|
|
printIndents(level); |
146 |
|
|
printf(",\n"); |
147 |
|
|
rhs->dump(level+1); |
148 |
|
|
printIndents(level); |
149 |
|
|
printf(")\n"); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
void Args::dump(int level) { |
153 |
|
|
printIndents(level); |
154 |
|
|
printf("Args(\n"); |
155 |
|
|
for (std::vector<ExpressionRef>::iterator it = args.begin() ; it != args.end() ; ++it) { |
156 |
|
|
(*it)->dump(level+1); |
157 |
|
|
} |
158 |
|
|
printIndents(level); |
159 |
|
|
printf(")\n"); |
160 |
|
|
} |
161 |
|
|
|
162 |
schoenebeck |
2645 |
bool Args::isPolyphonic() const { |
163 |
|
|
for (int i = 0; i < args.size(); ++i) |
164 |
|
|
if (args[i]->isPolyphonic()) |
165 |
|
|
return true; |
166 |
|
|
return false; |
167 |
|
|
} |
168 |
|
|
|
169 |
schoenebeck |
2581 |
EventHandlers::EventHandlers() { |
170 |
|
|
//printf("EventHandlers::Constructor 0x%lx\n", (long long)this); |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
EventHandlers::~EventHandlers() { |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
void EventHandlers::add(EventHandlerRef arg) { |
177 |
|
|
args.push_back(arg); |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
void EventHandlers::dump(int level) { |
181 |
|
|
printIndents(level); |
182 |
|
|
printf("EventHandlers {\n"); |
183 |
|
|
for (std::vector<EventHandlerRef>::iterator it = args.begin() ; it != args.end() ; ++it) { |
184 |
|
|
(*it)->dump(level+1); |
185 |
|
|
} |
186 |
|
|
printIndents(level); |
187 |
|
|
printf("}\n"); |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
EventHandler* EventHandlers::eventHandlerByName(const String& name) const { |
191 |
|
|
for (int i = 0; i < args.size(); ++i) |
192 |
|
|
if (args.at(i)->eventHandlerName() == name) |
193 |
|
|
return const_cast<EventHandler*>(&*args.at(i)); |
194 |
|
|
return NULL; |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
EventHandler* EventHandlers::eventHandler(uint index) const { |
198 |
|
|
if (index >= args.size()) return NULL; |
199 |
|
|
return const_cast<EventHandler*>(&*args.at(index)); |
200 |
|
|
} |
201 |
|
|
|
202 |
schoenebeck |
2645 |
bool EventHandlers::isPolyphonic() const { |
203 |
|
|
for (int i = 0; i < args.size(); ++i) |
204 |
|
|
if (args[i]->isPolyphonic()) |
205 |
|
|
return true; |
206 |
|
|
return false; |
207 |
|
|
} |
208 |
|
|
|
209 |
schoenebeck |
2581 |
Assignment::Assignment(VariableRef variable, ExpressionRef value) |
210 |
|
|
: variable(variable), value(value) |
211 |
|
|
{ |
212 |
|
|
} |
213 |
|
|
|
214 |
|
|
void Assignment::dump(int level) { |
215 |
|
|
printIndents(level); |
216 |
|
|
printf("Assignment\n"); |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
StmtFlags_t Assignment::exec() { |
220 |
|
|
if (!variable) |
221 |
|
|
return StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
222 |
|
|
variable->assign(&*value); |
223 |
|
|
return STMT_SUCCESS; |
224 |
|
|
} |
225 |
|
|
|
226 |
schoenebeck |
2645 |
EventHandler::EventHandler(StatementsRef statements) { |
227 |
|
|
this->statements = statements; |
228 |
|
|
usingPolyphonics = statements->isPolyphonic(); |
229 |
|
|
} |
230 |
|
|
|
231 |
schoenebeck |
2581 |
void EventHandler::dump(int level) { |
232 |
|
|
printIndents(level); |
233 |
|
|
printf("EventHandler {\n"); |
234 |
|
|
statements->dump(level+1); |
235 |
|
|
printIndents(level); |
236 |
|
|
printf("}\n"); |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
void Statements::dump(int level) { |
240 |
|
|
printIndents(level); |
241 |
|
|
printf("Statements {\n"); |
242 |
|
|
for (std::vector<StatementRef>::iterator it = args.begin() ; it != args.end() ; ++it) { |
243 |
|
|
(*it)->dump(level+1); |
244 |
|
|
} |
245 |
|
|
printIndents(level); |
246 |
|
|
printf("}\n"); |
247 |
|
|
} |
248 |
|
|
|
249 |
|
|
Statement* Statements::statement(uint i) { |
250 |
|
|
if (i >= args.size()) return NULL; |
251 |
|
|
return &*args.at(i); |
252 |
|
|
} |
253 |
|
|
|
254 |
schoenebeck |
2645 |
bool Statements::isPolyphonic() const { |
255 |
|
|
for (int i = 0; i < args.size(); ++i) |
256 |
|
|
if (args[i]->isPolyphonic()) |
257 |
|
|
return true; |
258 |
|
|
return false; |
259 |
|
|
} |
260 |
|
|
|
261 |
schoenebeck |
2942 |
DynamicVariableCall::DynamicVariableCall(const String& name, ParserContext* ctx, VMDynVar* v) |
262 |
|
|
: Variable(ctx, 0, false), dynVar(v), varName(name) |
263 |
|
|
{ |
264 |
|
|
} |
265 |
|
|
|
266 |
|
|
int DynamicVariableCall::evalInt() { |
267 |
|
|
VMIntExpr* expr = dynamic_cast<VMIntExpr*>(dynVar); |
268 |
|
|
if (!expr) return 0; |
269 |
|
|
return expr->evalInt(); |
270 |
|
|
} |
271 |
|
|
|
272 |
|
|
String DynamicVariableCall::evalStr() { |
273 |
|
|
VMStringExpr* expr = dynamic_cast<VMStringExpr*>(dynVar); |
274 |
|
|
if (!expr) return ""; |
275 |
|
|
return expr->evalStr(); |
276 |
|
|
} |
277 |
|
|
|
278 |
|
|
String DynamicVariableCall::evalCastToStr() { |
279 |
|
|
if (dynVar->exprType() == STRING_EXPR) { |
280 |
|
|
return evalStr(); |
281 |
|
|
} else { |
282 |
|
|
VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(dynVar); |
283 |
|
|
return intExpr ? ToString(intExpr->evalInt()) : ""; |
284 |
|
|
} |
285 |
|
|
} |
286 |
|
|
|
287 |
|
|
void DynamicVariableCall::dump(int level) { |
288 |
|
|
printIndents(level); |
289 |
|
|
printf("Dynamic Variable '%s'\n", varName.c_str()); |
290 |
|
|
} |
291 |
|
|
|
292 |
schoenebeck |
2581 |
void FunctionCall::dump(int level) { |
293 |
|
|
printIndents(level); |
294 |
|
|
printf("FunctionCall '%s' args={\n", functionName.c_str()); |
295 |
|
|
args->dump(level+1); |
296 |
|
|
printIndents(level); |
297 |
|
|
printf("}\n"); |
298 |
|
|
} |
299 |
|
|
|
300 |
|
|
ExprType_t FunctionCall::exprType() const { |
301 |
|
|
if (!fn) return EMPTY_EXPR; |
302 |
|
|
return fn->returnType(); |
303 |
|
|
} |
304 |
|
|
|
305 |
|
|
VMFnResult* FunctionCall::execVMFn() { |
306 |
|
|
if (!fn) return NULL; |
307 |
|
|
// assuming here that all argument checks (amount and types) have been made |
308 |
|
|
// at parse time, to avoid time intensive checks on each function call |
309 |
|
|
return fn->exec(dynamic_cast<VMFnArgs*>(&*args)); |
310 |
|
|
} |
311 |
|
|
|
312 |
|
|
StmtFlags_t FunctionCall::exec() { |
313 |
|
|
VMFnResult* result = execVMFn(); |
314 |
|
|
if (!result) |
315 |
|
|
return StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
316 |
|
|
return result->resultFlags(); |
317 |
|
|
} |
318 |
|
|
|
319 |
|
|
int FunctionCall::evalInt() { |
320 |
|
|
VMFnResult* result = execVMFn(); |
321 |
|
|
if (!result) return 0; |
322 |
|
|
VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue()); |
323 |
|
|
if (!intExpr) return 0; |
324 |
|
|
return intExpr->evalInt(); |
325 |
|
|
} |
326 |
|
|
|
327 |
schoenebeck |
3056 |
VMIntArrayExpr* FunctionCall::asIntArray() const { |
328 |
|
|
VMFnResult* result = const_cast<FunctionCall*>(this)->execVMFn(); |
329 |
|
|
if (!result) return 0; |
330 |
|
|
VMIntArrayExpr* intArrExpr = dynamic_cast<VMIntArrayExpr*>(result->resultValue()); |
331 |
|
|
return intArrExpr; |
332 |
|
|
} |
333 |
|
|
|
334 |
schoenebeck |
2581 |
String FunctionCall::evalStr() { |
335 |
|
|
VMFnResult* result = execVMFn(); |
336 |
|
|
if (!result) return ""; |
337 |
|
|
VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(result->resultValue()); |
338 |
|
|
if (!strExpr) return ""; |
339 |
|
|
return strExpr->evalStr(); |
340 |
|
|
} |
341 |
|
|
|
342 |
|
|
String FunctionCall::evalCastToStr() { |
343 |
|
|
VMFnResult* result = execVMFn(); |
344 |
|
|
if (!result) return ""; |
345 |
|
|
if (result->resultValue()->exprType() == STRING_EXPR) { |
346 |
|
|
VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(result->resultValue()); |
347 |
|
|
return strExpr ? strExpr->evalStr() : ""; |
348 |
|
|
} else { |
349 |
|
|
VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue()); |
350 |
|
|
return intExpr ? ToString(intExpr->evalInt()) : ""; |
351 |
|
|
} |
352 |
|
|
} |
353 |
|
|
|
354 |
|
|
IntVariable::IntVariable(ParserContext* ctx) |
355 |
|
|
: Variable(ctx, ctx ? ctx->globalIntVarCount++ : 0, false), polyphonic(false) |
356 |
|
|
{ |
357 |
schoenebeck |
2588 |
//printf("globalIntVar parserctx=0x%lx memPOS=%d\n", ctx, memPos); |
358 |
|
|
assert(ctx); |
359 |
schoenebeck |
2581 |
} |
360 |
|
|
|
361 |
schoenebeck |
2588 |
inline static int postfixInc(int& object, int incBy) { |
362 |
|
|
const int i = object; |
363 |
|
|
object += incBy; |
364 |
|
|
return i; |
365 |
|
|
} |
366 |
|
|
|
367 |
schoenebeck |
2581 |
IntVariable::IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, int size) |
368 |
schoenebeck |
2588 |
: Variable(ctx, !ctx ? 0 : polyphonic ? postfixInc(ctx->polyphonicIntVarCount, size) : postfixInc(ctx->globalIntVarCount, size), bConst), |
369 |
schoenebeck |
2581 |
polyphonic(polyphonic) |
370 |
|
|
{ |
371 |
schoenebeck |
2588 |
//printf("InvVar size=%d parserCtx=0x%lx\n", size, (uint64_t)ctx); |
372 |
|
|
if (polyphonic) { |
373 |
|
|
//printf("polyIntVar memPOS=%d\n", memPos); |
374 |
|
|
assert(ctx); |
375 |
|
|
} |
376 |
schoenebeck |
2581 |
} |
377 |
|
|
|
378 |
|
|
void IntVariable::assign(Expression* expr) { |
379 |
|
|
IntExpr* intExpr = dynamic_cast<IntExpr*>(expr); |
380 |
schoenebeck |
3034 |
if (intExpr) { |
381 |
schoenebeck |
2581 |
if (polyphonic) |
382 |
|
|
context->execContext->polyphonicIntMemory[memPos] = intExpr->evalInt(); |
383 |
|
|
else |
384 |
|
|
(*context->globalIntMemory)[memPos] = intExpr->evalInt(); |
385 |
schoenebeck |
3034 |
} |
386 |
schoenebeck |
2581 |
} |
387 |
|
|
|
388 |
|
|
int IntVariable::evalInt() { |
389 |
|
|
//printf("IntVariable::eval pos=%d\n", memPos); |
390 |
schoenebeck |
2588 |
if (polyphonic) { |
391 |
|
|
//printf("evalInt() poly memPos=%d execCtx=0x%lx\n", memPos, (uint64_t)context->execContext); |
392 |
schoenebeck |
2581 |
return context->execContext->polyphonicIntMemory[memPos]; |
393 |
schoenebeck |
2588 |
} |
394 |
schoenebeck |
2581 |
return (*context->globalIntMemory)[memPos]; |
395 |
|
|
} |
396 |
|
|
|
397 |
|
|
void IntVariable::dump(int level) { |
398 |
|
|
printIndents(level); |
399 |
schoenebeck |
2945 |
printf("IntVariable\n"); |
400 |
schoenebeck |
2588 |
//printf("IntVariable memPos=%d\n", memPos); |
401 |
schoenebeck |
2581 |
} |
402 |
|
|
|
403 |
|
|
//ConstIntVariable::ConstIntVariable(ParserContext* ctx, int value) |
404 |
|
|
ConstIntVariable::ConstIntVariable(int value) |
405 |
|
|
: IntVariable(NULL,false,true), value(value) |
406 |
|
|
{ |
407 |
|
|
} |
408 |
|
|
|
409 |
|
|
void ConstIntVariable::assign(Expression* expr) { |
410 |
|
|
// ignore assignment |
411 |
|
|
/* |
412 |
|
|
printf("ConstIntVariable::assign()\n"); |
413 |
|
|
IntExpr* intExpr = dynamic_cast<IntExpr*>(expr); |
414 |
|
|
if (intExpr) { |
415 |
|
|
value = intExpr->evalInt(); |
416 |
|
|
} |
417 |
|
|
*/ |
418 |
|
|
} |
419 |
|
|
|
420 |
|
|
int ConstIntVariable::evalInt() { |
421 |
|
|
return value; |
422 |
|
|
} |
423 |
|
|
|
424 |
|
|
void ConstIntVariable::dump(int level) { |
425 |
|
|
printIndents(level); |
426 |
|
|
printf("ConstIntVariable val=%d\n", value); |
427 |
|
|
} |
428 |
|
|
|
429 |
schoenebeck |
2594 |
BuiltInIntVariable::BuiltInIntVariable(const String& name, VMIntRelPtr* ptr) |
430 |
|
|
: IntVariable(NULL,false,false), name(name), ptr(ptr) |
431 |
|
|
{ |
432 |
|
|
} |
433 |
|
|
|
434 |
|
|
void BuiltInIntVariable::assign(Expression* expr) { |
435 |
|
|
IntExpr* valueExpr = dynamic_cast<IntExpr*>(expr); |
436 |
|
|
if (!valueExpr) return; |
437 |
|
|
ptr->assign(valueExpr->evalInt()); |
438 |
|
|
} |
439 |
|
|
|
440 |
|
|
int BuiltInIntVariable::evalInt() { |
441 |
|
|
return ptr->evalInt(); |
442 |
|
|
} |
443 |
|
|
|
444 |
|
|
void BuiltInIntVariable::dump(int level) { |
445 |
|
|
printIndents(level); |
446 |
|
|
printf("Built-in IntVar '%s'\n", name.c_str()); |
447 |
|
|
} |
448 |
|
|
|
449 |
schoenebeck |
2581 |
PolyphonicIntVariable::PolyphonicIntVariable(ParserContext* ctx) |
450 |
|
|
: IntVariable(ctx,true,false) |
451 |
|
|
{ |
452 |
|
|
} |
453 |
|
|
|
454 |
|
|
void PolyphonicIntVariable::dump(int level) { |
455 |
|
|
printIndents(level); |
456 |
|
|
printf("PolyphonicIntVariable\n"); |
457 |
|
|
} |
458 |
|
|
|
459 |
|
|
IntArrayVariable::IntArrayVariable(ParserContext* ctx, int size) |
460 |
|
|
: Variable(ctx, 0, false) |
461 |
|
|
{ |
462 |
|
|
values.resize(size); |
463 |
|
|
memset(&values[0], 0, size * sizeof(int)); |
464 |
|
|
} |
465 |
|
|
|
466 |
schoenebeck |
3257 |
IntArrayVariable::IntArrayVariable(ParserContext* ctx, int size, ArgsRef values, bool _bConst) |
467 |
|
|
: Variable(ctx, 0, _bConst) |
468 |
schoenebeck |
2581 |
{ |
469 |
|
|
this->values.resize(size); |
470 |
|
|
for (int i = 0; i < values->argsCount(); ++i) { |
471 |
|
|
VMIntExpr* expr = dynamic_cast<VMIntExpr*>(values->arg(i)); |
472 |
|
|
if (expr) this->values[i] = expr->evalInt(); |
473 |
|
|
} |
474 |
|
|
} |
475 |
|
|
|
476 |
schoenebeck |
2594 |
IntArrayVariable::IntArrayVariable(ParserContext* ctx, bool bConst) |
477 |
|
|
: Variable(ctx, 0, bConst) |
478 |
|
|
{ |
479 |
|
|
} |
480 |
|
|
|
481 |
schoenebeck |
2581 |
int IntArrayVariable::evalIntElement(uint i) { |
482 |
|
|
if (i >= values.size()) return 0; |
483 |
|
|
return values[i]; |
484 |
|
|
} |
485 |
|
|
|
486 |
|
|
void IntArrayVariable::assignIntElement(uint i, int value) { |
487 |
|
|
if (i >= values.size()) return; |
488 |
|
|
values[i] = value; |
489 |
|
|
} |
490 |
|
|
|
491 |
|
|
void IntArrayVariable::dump(int level) { |
492 |
|
|
printIndents(level); |
493 |
|
|
printf("IntArray("); |
494 |
|
|
for (int i = 0; i < values.size(); ++i) { |
495 |
|
|
if (i % 12 == 0) { |
496 |
|
|
printf("\n"); |
497 |
|
|
printIndents(level+1); |
498 |
|
|
} |
499 |
|
|
printf("%d, ", values[i]); |
500 |
|
|
} |
501 |
|
|
printIndents(level); |
502 |
|
|
printf(")\n"); |
503 |
|
|
} |
504 |
|
|
|
505 |
schoenebeck |
2594 |
BuiltInIntArrayVariable::BuiltInIntArrayVariable(const String& name, VMInt8Array* array) |
506 |
|
|
: IntArrayVariable(NULL, false), name(name), array(array) |
507 |
|
|
{ |
508 |
|
|
} |
509 |
|
|
|
510 |
|
|
int BuiltInIntArrayVariable::evalIntElement(uint i) { |
511 |
|
|
return i >= array->size ? 0 : array->data[i]; |
512 |
|
|
} |
513 |
|
|
|
514 |
|
|
void BuiltInIntArrayVariable::assignIntElement(uint i, int value) { |
515 |
|
|
if (i >= array->size) return; |
516 |
|
|
array->data[i] = value; |
517 |
|
|
} |
518 |
|
|
|
519 |
|
|
void BuiltInIntArrayVariable::dump(int level) { |
520 |
|
|
printIndents(level); |
521 |
|
|
printf("Built-In Int Array Variable '%s'\n", name.c_str()); |
522 |
|
|
} |
523 |
|
|
|
524 |
schoenebeck |
2581 |
IntArrayElement::IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex) |
525 |
|
|
: IntVariable(NULL, false, false, 0), array(array), index(arrayIndex) |
526 |
|
|
{ |
527 |
|
|
} |
528 |
|
|
|
529 |
|
|
void IntArrayElement::assign(Expression* expr) { |
530 |
|
|
IntExpr* valueExpr = dynamic_cast<IntExpr*>(expr); |
531 |
|
|
if (!valueExpr) return; |
532 |
|
|
int value = valueExpr->evalInt(); |
533 |
|
|
|
534 |
|
|
if (!index) return; |
535 |
|
|
int idx = index->evalInt(); |
536 |
|
|
if (idx < 0 || idx >= array->arraySize()) return; |
537 |
|
|
|
538 |
|
|
array->assignIntElement(idx, value); |
539 |
|
|
} |
540 |
|
|
|
541 |
|
|
int IntArrayElement::evalInt() { |
542 |
|
|
if (!index) return 0; |
543 |
|
|
int idx = index->evalInt(); |
544 |
|
|
if (idx < 0 || idx >= array->arraySize()) return 0; |
545 |
|
|
|
546 |
|
|
return array->evalIntElement(idx); |
547 |
|
|
} |
548 |
|
|
|
549 |
|
|
void IntArrayElement::dump(int level) { |
550 |
|
|
printIndents(level); |
551 |
|
|
printf("IntArrayElement\n"); |
552 |
|
|
} |
553 |
|
|
|
554 |
|
|
StringVariable::StringVariable(ParserContext* ctx) |
555 |
|
|
: Variable(ctx,ctx->globalStrVarCount++,false) |
556 |
|
|
{ |
557 |
|
|
} |
558 |
|
|
|
559 |
|
|
StringVariable::StringVariable(ParserContext* ctx, bool bConst) |
560 |
|
|
: Variable(ctx,0,bConst) |
561 |
|
|
{ |
562 |
|
|
} |
563 |
|
|
|
564 |
|
|
void StringVariable::assign(Expression* expr) { |
565 |
|
|
StringExpr* strExpr = dynamic_cast<StringExpr*>(expr); |
566 |
|
|
(*context->globalStrMemory)[memPos] = strExpr->evalStr(); |
567 |
|
|
} |
568 |
|
|
|
569 |
|
|
String StringVariable::evalStr() { |
570 |
|
|
//printf("StringVariable::eval pos=%d\n", memPos); |
571 |
|
|
return (*context->globalStrMemory)[memPos]; |
572 |
|
|
} |
573 |
|
|
|
574 |
|
|
void StringVariable::dump(int level) { |
575 |
|
|
printIndents(level); |
576 |
|
|
printf("StringVariable memPos=%d\n", memPos); |
577 |
|
|
} |
578 |
|
|
|
579 |
|
|
ConstStringVariable::ConstStringVariable(ParserContext* ctx, String _value) |
580 |
|
|
: StringVariable(ctx,true), value(_value) |
581 |
|
|
{ |
582 |
|
|
} |
583 |
|
|
|
584 |
|
|
void ConstStringVariable::assign(Expression* expr) { |
585 |
|
|
// ignore assignment |
586 |
|
|
// StringExpr* strExpr = dynamic_cast<StringExpr*>(expr); |
587 |
|
|
// if (strExpr) value = strExpr->evalStr(); |
588 |
|
|
} |
589 |
|
|
|
590 |
|
|
String ConstStringVariable::evalStr() { |
591 |
|
|
return value; |
592 |
|
|
} |
593 |
|
|
|
594 |
|
|
void ConstStringVariable::dump(int level) { |
595 |
|
|
printIndents(level); |
596 |
|
|
printf("ConstStringVariable val='%s'\n", value.c_str()); |
597 |
|
|
} |
598 |
|
|
|
599 |
|
|
void If::dump(int level) { |
600 |
|
|
printIndents(level); |
601 |
|
|
if (ifStatements && elseStatements) |
602 |
|
|
printf("if cond stmts1 else stmts2 end if\n"); |
603 |
|
|
else if (ifStatements) |
604 |
|
|
printf("if cond statements end if\n"); |
605 |
|
|
else |
606 |
|
|
printf("if [INVALID]\n"); |
607 |
|
|
} |
608 |
|
|
|
609 |
|
|
int If::evalBranch() { |
610 |
|
|
if (condition->evalInt()) return 0; |
611 |
|
|
if (elseStatements) return 1; |
612 |
|
|
return -1; |
613 |
|
|
} |
614 |
|
|
|
615 |
|
|
Statements* If::branch(uint i) const { |
616 |
|
|
if (i == 0) return (Statements*) &*ifStatements; |
617 |
|
|
if (i == 1) return (elseStatements) ? (Statements*) &*elseStatements : NULL; |
618 |
|
|
return NULL; |
619 |
|
|
} |
620 |
|
|
|
621 |
schoenebeck |
2645 |
bool If::isPolyphonic() const { |
622 |
|
|
if (condition->isPolyphonic() || ifStatements->isPolyphonic()) |
623 |
|
|
return true; |
624 |
|
|
return elseStatements ? elseStatements->isPolyphonic() : false; |
625 |
|
|
} |
626 |
|
|
|
627 |
schoenebeck |
2581 |
void SelectCase::dump(int level) { |
628 |
|
|
printIndents(level); |
629 |
|
|
if (select) |
630 |
|
|
if (select->isConstExpr()) |
631 |
|
|
printf("Case select %d\n", select->evalInt()); |
632 |
|
|
else |
633 |
|
|
printf("Case select [runtime expr]\n"); |
634 |
|
|
else |
635 |
|
|
printf("Case select NULL\n"); |
636 |
|
|
for (int i = 0; i < branches.size(); ++i) { |
637 |
|
|
printIndents(level+1); |
638 |
|
|
CaseBranch& branch = branches[i]; |
639 |
|
|
if (branch.from && branch.to) |
640 |
|
|
if (branch.from->isConstExpr() && branch.to->isConstExpr()) |
641 |
|
|
printf("case %d to %d\n", branch.from->evalInt(), branch.to->evalInt()); |
642 |
|
|
else if (branch.from->isConstExpr() && !branch.to->isConstExpr()) |
643 |
|
|
printf("case %d to [runtime expr]\n", branch.from->evalInt()); |
644 |
|
|
else if (!branch.from->isConstExpr() && branch.to->isConstExpr()) |
645 |
|
|
printf("case [runtime expr] to %d\n", branch.to->evalInt()); |
646 |
|
|
else |
647 |
|
|
printf("case [runtime expr] to [runtime expr]\n"); |
648 |
|
|
else if (branch.from) |
649 |
|
|
if (branch.from->isConstExpr()) |
650 |
|
|
printf("case %d\n", branch.from->evalInt()); |
651 |
|
|
else |
652 |
|
|
printf("case [runtime expr]\n"); |
653 |
|
|
else |
654 |
|
|
printf("case NULL\n"); |
655 |
|
|
} |
656 |
|
|
} |
657 |
|
|
|
658 |
|
|
int SelectCase::evalBranch() { |
659 |
|
|
int value = select->evalInt(); |
660 |
|
|
for (int i = 0; i < branches.size(); ++i) { |
661 |
|
|
if (branches.at(i).from && branches.at(i).to) { // i.e. "case 4 to 7" ... |
662 |
|
|
if (branches.at(i).from->evalInt() <= value && |
663 |
|
|
branches.at(i).to->evalInt() >= value) return i; |
664 |
|
|
} else { // i.e. "case 5" ... |
665 |
|
|
if (branches.at(i).from->evalInt() == value) return i; |
666 |
|
|
} |
667 |
|
|
} |
668 |
|
|
return -1; |
669 |
|
|
} |
670 |
|
|
|
671 |
|
|
Statements* SelectCase::branch(uint i) const { |
672 |
|
|
if (i < branches.size()) |
673 |
|
|
return const_cast<Statements*>( &*branches[i].statements ); |
674 |
|
|
return NULL; |
675 |
|
|
} |
676 |
|
|
|
677 |
schoenebeck |
2645 |
bool SelectCase::isPolyphonic() const { |
678 |
|
|
if (select->isPolyphonic()) return true; |
679 |
|
|
for (int i = 0; i < branches.size(); ++i) |
680 |
|
|
if (branches[i].statements->isPolyphonic()) |
681 |
|
|
return true; |
682 |
|
|
return false; |
683 |
|
|
} |
684 |
|
|
|
685 |
schoenebeck |
2581 |
// void Case::addBranch(IntExprRef condition, StatementsRef statements) { |
686 |
|
|
// CaseBranchRef b = new CaseBranchRef; |
687 |
|
|
// b->from = condition; |
688 |
|
|
// b->statements = statements; |
689 |
|
|
// branches.push_back(b); |
690 |
|
|
// } |
691 |
|
|
// |
692 |
|
|
// void Case::addBranch(IntExprRef from, IntExprRef to, StatementsRef statements) { |
693 |
|
|
// CaseBranchRef b = new CaseBranchRef; |
694 |
|
|
// b->from = from; |
695 |
|
|
// b->to = to; |
696 |
|
|
// b->statements = statements; |
697 |
|
|
// branches.push_back(b); |
698 |
|
|
// } |
699 |
|
|
// |
700 |
|
|
// void Case::addBranch(CaseBranchRef branch) { |
701 |
|
|
// branches.push_back(branch); |
702 |
|
|
// } |
703 |
|
|
|
704 |
|
|
void While::dump(int level) { |
705 |
|
|
printIndents(level); |
706 |
|
|
if (m_condition) |
707 |
|
|
if (m_condition->isConstExpr()) |
708 |
|
|
printf("while (%d) {\n", m_condition->evalInt()); |
709 |
|
|
else |
710 |
|
|
printf("while ([runtime expr]) {\n"); |
711 |
|
|
else |
712 |
|
|
printf("while ([INVALID]) {\n"); |
713 |
|
|
m_statements->dump(level+1); |
714 |
|
|
printIndents(level); |
715 |
|
|
printf("}\n"); |
716 |
|
|
} |
717 |
|
|
|
718 |
|
|
Statements* While::statements() const { |
719 |
|
|
return (m_statements) ? const_cast<Statements*>( &*m_statements ) : NULL; |
720 |
|
|
} |
721 |
|
|
|
722 |
|
|
bool While::evalLoopStartCondition() { |
723 |
|
|
if (!m_condition) return false; |
724 |
|
|
return m_condition->evalInt(); |
725 |
|
|
} |
726 |
|
|
|
727 |
|
|
void Neg::dump(int level) { |
728 |
|
|
printIndents(level); |
729 |
|
|
printf("Negative Expr\n"); |
730 |
|
|
} |
731 |
|
|
|
732 |
|
|
String ConcatString::evalStr() { |
733 |
schoenebeck |
2945 |
// temporaries required here to enforce the associative left (to right) order |
734 |
schoenebeck |
2948 |
// ( required for GCC and Visual Studio, see: |
735 |
|
|
// http://stackoverflow.com/questions/25842902/why-stdstring-concatenation-operator-works-like-right-associative-one |
736 |
|
|
// Personally I am not convinced that this is "not a bug" of the |
737 |
|
|
// compiler/STL implementation and the allegedly underlying "function call" |
738 |
|
|
// nature causing this is IMO no profound reason that the C++ language's |
739 |
|
|
// "+" operator's left associativity is ignored. -- Christian, 2016-07-14 ) |
740 |
schoenebeck |
2945 |
String l = lhs->evalCastToStr(); |
741 |
|
|
String r = rhs->evalCastToStr(); |
742 |
|
|
return l + r; |
743 |
schoenebeck |
2581 |
} |
744 |
|
|
|
745 |
|
|
void ConcatString::dump(int level) { |
746 |
|
|
printIndents(level); |
747 |
|
|
printf("ConcatString(\n"); |
748 |
|
|
lhs->dump(level+1); |
749 |
|
|
printIndents(level); |
750 |
|
|
printf(",\n"); |
751 |
|
|
rhs->dump(level+1); |
752 |
|
|
printIndents(level); |
753 |
|
|
printf(")"); |
754 |
|
|
} |
755 |
|
|
|
756 |
|
|
bool ConcatString::isConstExpr() const { |
757 |
|
|
return lhs->isConstExpr() && rhs->isConstExpr(); |
758 |
|
|
} |
759 |
|
|
|
760 |
|
|
int Relation::evalInt() { |
761 |
|
|
switch (type) { |
762 |
|
|
case LESS_THAN: |
763 |
|
|
return lhs->evalInt() < rhs->evalInt(); |
764 |
|
|
case GREATER_THAN: |
765 |
|
|
return lhs->evalInt() > rhs->evalInt(); |
766 |
|
|
case LESS_OR_EQUAL: |
767 |
|
|
return lhs->evalInt() <= rhs->evalInt(); |
768 |
|
|
case GREATER_OR_EQUAL: |
769 |
|
|
return lhs->evalInt() >= rhs->evalInt(); |
770 |
|
|
case EQUAL: |
771 |
|
|
if (lhs->exprType() == STRING_EXPR || rhs->exprType() == STRING_EXPR) |
772 |
|
|
return lhs->evalCastToStr() == rhs->evalCastToStr(); |
773 |
|
|
else |
774 |
|
|
return lhs->evalInt() == rhs->evalInt(); |
775 |
|
|
case NOT_EQUAL: |
776 |
|
|
if (lhs->exprType() == STRING_EXPR || rhs->exprType() == STRING_EXPR) |
777 |
|
|
return lhs->evalCastToStr() != rhs->evalCastToStr(); |
778 |
|
|
else |
779 |
|
|
return lhs->evalInt() != rhs->evalInt(); |
780 |
|
|
} |
781 |
|
|
return 0; |
782 |
|
|
} |
783 |
|
|
|
784 |
|
|
void Relation::dump(int level) { |
785 |
|
|
printIndents(level); |
786 |
|
|
printf("Relation(\n"); |
787 |
|
|
lhs->dump(level+1); |
788 |
|
|
printIndents(level); |
789 |
|
|
switch (type) { |
790 |
|
|
case LESS_THAN: |
791 |
|
|
printf("LESS_THAN\n"); |
792 |
|
|
break; |
793 |
|
|
case GREATER_THAN: |
794 |
|
|
printf("GREATER_THAN\n"); |
795 |
|
|
break; |
796 |
|
|
case LESS_OR_EQUAL: |
797 |
|
|
printf("LESS_OR_EQUAL\n"); |
798 |
|
|
break; |
799 |
|
|
case GREATER_OR_EQUAL: |
800 |
|
|
printf("GREATER_OR_EQUAL\n"); |
801 |
|
|
break; |
802 |
|
|
case EQUAL: |
803 |
|
|
printf("EQUAL\n"); |
804 |
|
|
break; |
805 |
|
|
case NOT_EQUAL: |
806 |
|
|
printf("NOT_EQUAL\n"); |
807 |
|
|
break; |
808 |
|
|
} |
809 |
|
|
rhs->dump(level+1); |
810 |
|
|
printIndents(level); |
811 |
|
|
printf(")\n"); |
812 |
|
|
} |
813 |
|
|
|
814 |
|
|
bool Relation::isConstExpr() const { |
815 |
|
|
return lhs->isConstExpr() && rhs->isConstExpr(); |
816 |
|
|
} |
817 |
|
|
|
818 |
|
|
int Or::evalInt() { |
819 |
|
|
IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs); |
820 |
schoenebeck |
2611 |
if (pLHS->evalInt()) return 1; |
821 |
schoenebeck |
2581 |
IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);; |
822 |
schoenebeck |
2611 |
return (pRHS->evalInt()) ? 1 : 0; |
823 |
schoenebeck |
2581 |
} |
824 |
|
|
|
825 |
|
|
void Or::dump(int level) { |
826 |
|
|
printIndents(level); |
827 |
|
|
printf("Or(\n"); |
828 |
|
|
lhs->dump(level+1); |
829 |
|
|
printIndents(level); |
830 |
|
|
printf(",\n"); |
831 |
|
|
rhs->dump(level+1); |
832 |
|
|
printIndents(level); |
833 |
|
|
printf(")\n"); |
834 |
|
|
} |
835 |
|
|
|
836 |
schoenebeck |
2935 |
int BitwiseOr::evalInt() { |
837 |
|
|
IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs); |
838 |
|
|
IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs); |
839 |
|
|
return pLHS->evalInt() | pRHS->evalInt(); |
840 |
|
|
} |
841 |
|
|
|
842 |
|
|
void BitwiseOr::dump(int level) { |
843 |
|
|
printIndents(level); |
844 |
|
|
printf("BitwiseOr(\n"); |
845 |
|
|
lhs->dump(level+1); |
846 |
|
|
printIndents(level); |
847 |
|
|
printf(",\n"); |
848 |
|
|
rhs->dump(level+1); |
849 |
|
|
printIndents(level); |
850 |
|
|
printf(")\n"); |
851 |
|
|
} |
852 |
|
|
|
853 |
schoenebeck |
2581 |
int And::evalInt() { |
854 |
|
|
IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs); |
855 |
schoenebeck |
2611 |
if (!pLHS->evalInt()) return 0; |
856 |
|
|
IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs); |
857 |
|
|
return (pRHS->evalInt()) ? 1 : 0; |
858 |
schoenebeck |
2581 |
} |
859 |
|
|
|
860 |
|
|
void And::dump(int level) { |
861 |
|
|
printIndents(level); |
862 |
|
|
printf("And(\n"); |
863 |
|
|
lhs->dump(level+1); |
864 |
|
|
printIndents(level); |
865 |
|
|
printf(",\n"); |
866 |
|
|
rhs->dump(level+1); |
867 |
|
|
printIndents(level); |
868 |
|
|
printf(")\n"); |
869 |
|
|
} |
870 |
|
|
|
871 |
schoenebeck |
2935 |
int BitwiseAnd::evalInt() { |
872 |
|
|
IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs); |
873 |
|
|
IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs); |
874 |
|
|
return pLHS->evalInt() & pRHS->evalInt(); |
875 |
|
|
} |
876 |
|
|
|
877 |
|
|
void BitwiseAnd::dump(int level) { |
878 |
|
|
printIndents(level); |
879 |
|
|
printf("BitwiseAnd(\n"); |
880 |
|
|
lhs->dump(level+1); |
881 |
|
|
printIndents(level); |
882 |
|
|
printf(",\n"); |
883 |
|
|
rhs->dump(level+1); |
884 |
|
|
printIndents(level); |
885 |
|
|
printf(")\n"); |
886 |
|
|
} |
887 |
|
|
|
888 |
schoenebeck |
2581 |
void Not::dump(int level) { |
889 |
|
|
printIndents(level); |
890 |
|
|
printf("Not(\n"); |
891 |
|
|
expr->dump(level+1); |
892 |
|
|
printIndents(level); |
893 |
|
|
printf(")\n"); |
894 |
|
|
} |
895 |
|
|
|
896 |
schoenebeck |
2935 |
void BitwiseNot::dump(int level) { |
897 |
|
|
printIndents(level); |
898 |
|
|
printf("BitwiseNot(\n"); |
899 |
|
|
expr->dump(level+1); |
900 |
|
|
printIndents(level); |
901 |
|
|
printf(")\n"); |
902 |
|
|
} |
903 |
|
|
|
904 |
schoenebeck |
2951 |
StatementsRef ParserContext::userFunctionByName(const String& name) { |
905 |
|
|
if (!userFnTable.count(name)) { |
906 |
|
|
return StatementsRef(); |
907 |
|
|
} |
908 |
|
|
return userFnTable.find(name)->second; |
909 |
|
|
} |
910 |
|
|
|
911 |
schoenebeck |
2581 |
VariableRef ParserContext::variableByName(const String& name) { |
912 |
|
|
if (!vartable.count(name)) { |
913 |
|
|
return VariableRef(); |
914 |
|
|
} |
915 |
|
|
return vartable.find(name)->second; |
916 |
|
|
} |
917 |
|
|
|
918 |
|
|
VariableRef ParserContext::globalVar(const String& name) { |
919 |
|
|
if (!vartable.count(name)) { |
920 |
|
|
//printf("No global var '%s'\n", name.c_str()); |
921 |
|
|
//for (std::map<String,VariableRef>::const_iterator it = vartable.begin(); it != vartable.end(); ++it) |
922 |
|
|
// printf("-> var '%s'\n", it->first.c_str()); |
923 |
|
|
return VariableRef(); |
924 |
|
|
} |
925 |
|
|
return vartable.find(name)->second; |
926 |
|
|
} |
927 |
|
|
|
928 |
|
|
IntVariableRef ParserContext::globalIntVar(const String& name) { |
929 |
|
|
return globalVar(name); |
930 |
|
|
} |
931 |
|
|
|
932 |
|
|
StringVariableRef ParserContext::globalStrVar(const String& name) { |
933 |
|
|
return globalVar(name); |
934 |
|
|
} |
935 |
|
|
|
936 |
schoenebeck |
2588 |
ParserContext::~ParserContext() { |
937 |
|
|
destroyScanner(); |
938 |
|
|
if (globalIntMemory) { |
939 |
|
|
delete globalIntMemory; |
940 |
|
|
globalIntMemory = NULL; |
941 |
|
|
} |
942 |
|
|
} |
943 |
|
|
|
944 |
schoenebeck |
2889 |
void ParserContext::addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt) { |
945 |
schoenebeck |
2581 |
ParserIssue e; |
946 |
|
|
e.type = PARSER_ERROR; |
947 |
|
|
e.txt = txt; |
948 |
schoenebeck |
2889 |
e.firstLine = firstLine; |
949 |
|
|
e.lastLine = lastLine; |
950 |
|
|
e.firstColumn = firstColumn; |
951 |
|
|
e.lastColumn = lastColumn; |
952 |
schoenebeck |
2588 |
vErrors.push_back(e); |
953 |
|
|
vIssues.push_back(e); |
954 |
schoenebeck |
2581 |
} |
955 |
|
|
|
956 |
schoenebeck |
2889 |
void ParserContext::addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt) { |
957 |
schoenebeck |
2581 |
ParserIssue w; |
958 |
|
|
w.type = PARSER_WARNING; |
959 |
|
|
w.txt = txt; |
960 |
schoenebeck |
2889 |
w.firstLine = firstLine; |
961 |
|
|
w.lastLine = lastLine; |
962 |
|
|
w.firstColumn = firstColumn; |
963 |
|
|
w.lastColumn = lastColumn; |
964 |
schoenebeck |
2588 |
vWarnings.push_back(w); |
965 |
|
|
vIssues.push_back(w); |
966 |
schoenebeck |
2581 |
} |
967 |
|
|
|
968 |
|
|
bool ParserContext::setPreprocessorCondition(const char* name) { |
969 |
|
|
if (builtinPreprocessorConditions.count(name)) return false; |
970 |
|
|
if (userPreprocessorConditions.count(name)) return false; |
971 |
|
|
userPreprocessorConditions.insert(name); |
972 |
|
|
return true; |
973 |
|
|
} |
974 |
|
|
|
975 |
|
|
bool ParserContext::resetPreprocessorCondition(const char* name) { |
976 |
|
|
if (builtinPreprocessorConditions.count(name)) return false; |
977 |
|
|
if (!userPreprocessorConditions.count(name)) return false; |
978 |
|
|
userPreprocessorConditions.erase(name); |
979 |
|
|
return true; |
980 |
|
|
} |
981 |
|
|
|
982 |
|
|
bool ParserContext::isPreprocessorConditionSet(const char* name) { |
983 |
|
|
if (builtinPreprocessorConditions.count(name)) return true; |
984 |
|
|
return userPreprocessorConditions.count(name); |
985 |
|
|
} |
986 |
|
|
|
987 |
schoenebeck |
2588 |
std::vector<ParserIssue> ParserContext::issues() const { |
988 |
|
|
return vIssues; |
989 |
|
|
} |
990 |
|
|
|
991 |
|
|
std::vector<ParserIssue> ParserContext::errors() const { |
992 |
|
|
return vErrors; |
993 |
|
|
} |
994 |
|
|
|
995 |
|
|
std::vector<ParserIssue> ParserContext::warnings() const { |
996 |
|
|
return vWarnings; |
997 |
|
|
} |
998 |
|
|
|
999 |
|
|
VMEventHandler* ParserContext::eventHandler(uint index) { |
1000 |
|
|
if (!handlers) return NULL; |
1001 |
|
|
return handlers->eventHandler(index); |
1002 |
|
|
} |
1003 |
|
|
|
1004 |
|
|
VMEventHandler* ParserContext::eventHandlerByName(const String& name) { |
1005 |
|
|
if (!handlers) return NULL; |
1006 |
|
|
return handlers->eventHandlerByName(name); |
1007 |
|
|
} |
1008 |
|
|
|
1009 |
schoenebeck |
2594 |
void ParserContext::registerBuiltInConstIntVariables(const std::map<String,int>& vars) { |
1010 |
|
|
for (std::map<String,int>::const_iterator it = vars.begin(); |
1011 |
|
|
it != vars.end(); ++it) |
1012 |
|
|
{ |
1013 |
|
|
ConstIntVariableRef ref = new ConstIntVariable(it->second); |
1014 |
|
|
vartable[it->first] = ref; |
1015 |
|
|
} |
1016 |
|
|
} |
1017 |
|
|
|
1018 |
|
|
void ParserContext::registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars) { |
1019 |
|
|
for (std::map<String,VMIntRelPtr*>::const_iterator it = vars.begin(); |
1020 |
|
|
it != vars.end(); ++it) |
1021 |
|
|
{ |
1022 |
|
|
BuiltInIntVariableRef ref = new BuiltInIntVariable(it->first, it->second); |
1023 |
|
|
vartable[it->first] = ref; |
1024 |
|
|
} |
1025 |
|
|
} |
1026 |
|
|
|
1027 |
|
|
void ParserContext::registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars) { |
1028 |
|
|
for (std::map<String,VMInt8Array*>::const_iterator it = vars.begin(); |
1029 |
|
|
it != vars.end(); ++it) |
1030 |
|
|
{ |
1031 |
|
|
BuiltInIntArrayVariableRef ref = new BuiltInIntArrayVariable(it->first, it->second); |
1032 |
|
|
vartable[it->first] = ref; |
1033 |
|
|
} |
1034 |
|
|
} |
1035 |
|
|
|
1036 |
schoenebeck |
2942 |
void ParserContext::registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars) { |
1037 |
|
|
for (std::map<String,VMDynVar*>::const_iterator it = vars.begin(); |
1038 |
|
|
it != vars.end(); ++it) |
1039 |
|
|
{ |
1040 |
|
|
DynamicVariableCallRef ref = new DynamicVariableCall(it->first, this, it->second); |
1041 |
|
|
vartable[it->first] = ref; |
1042 |
|
|
} |
1043 |
|
|
} |
1044 |
|
|
|
1045 |
schoenebeck |
2581 |
} // namespace LinuxSampler |