11 |
#include <string.h> |
#include <string.h> |
12 |
#include "tree.h" |
#include "tree.h" |
13 |
#include "../common/global_private.h" |
#include "../common/global_private.h" |
14 |
|
#include <assert.h> |
15 |
|
|
16 |
namespace LinuxSampler { |
namespace LinuxSampler { |
17 |
|
|
275 |
IntVariable::IntVariable(ParserContext* ctx) |
IntVariable::IntVariable(ParserContext* ctx) |
276 |
: Variable(ctx, ctx ? ctx->globalIntVarCount++ : 0, false), polyphonic(false) |
: Variable(ctx, ctx ? ctx->globalIntVarCount++ : 0, false), polyphonic(false) |
277 |
{ |
{ |
278 |
|
//printf("globalIntVar parserctx=0x%lx memPOS=%d\n", ctx, memPos); |
279 |
|
assert(ctx); |
280 |
|
} |
281 |
|
|
282 |
|
inline static int postfixInc(int& object, int incBy) { |
283 |
|
const int i = object; |
284 |
|
object += incBy; |
285 |
|
return i; |
286 |
} |
} |
287 |
|
|
288 |
IntVariable::IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, int size) |
IntVariable::IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, int size) |
289 |
: Variable(ctx, !ctx ? 0 : polyphonic ? ctx->polyphonicIntVarCount += size : ctx->globalIntVarCount += size, bConst), |
: Variable(ctx, !ctx ? 0 : polyphonic ? postfixInc(ctx->polyphonicIntVarCount, size) : postfixInc(ctx->globalIntVarCount, size), bConst), |
290 |
polyphonic(polyphonic) |
polyphonic(polyphonic) |
291 |
{ |
{ |
292 |
|
//printf("InvVar size=%d parserCtx=0x%lx\n", size, (uint64_t)ctx); |
293 |
|
if (polyphonic) { |
294 |
|
//printf("polyIntVar memPOS=%d\n", memPos); |
295 |
|
assert(ctx); |
296 |
|
} |
297 |
} |
} |
298 |
|
|
299 |
void IntVariable::assign(Expression* expr) { |
void IntVariable::assign(Expression* expr) { |
307 |
|
|
308 |
int IntVariable::evalInt() { |
int IntVariable::evalInt() { |
309 |
//printf("IntVariable::eval pos=%d\n", memPos); |
//printf("IntVariable::eval pos=%d\n", memPos); |
310 |
if (polyphonic) |
if (polyphonic) { |
311 |
|
//printf("evalInt() poly memPos=%d execCtx=0x%lx\n", memPos, (uint64_t)context->execContext); |
312 |
return context->execContext->polyphonicIntMemory[memPos]; |
return context->execContext->polyphonicIntMemory[memPos]; |
313 |
|
} |
314 |
return (*context->globalIntMemory)[memPos]; |
return (*context->globalIntMemory)[memPos]; |
315 |
} |
} |
316 |
|
|
317 |
void IntVariable::dump(int level) { |
void IntVariable::dump(int level) { |
318 |
printIndents(level); |
printIndents(level); |
319 |
printf("IntVariable memPos=%d\n", memPos); |
//printf("IntVariable memPos=%d\n", memPos); |
320 |
} |
} |
321 |
|
|
322 |
//ConstIntVariable::ConstIntVariable(ParserContext* ctx, int value) |
//ConstIntVariable::ConstIntVariable(ParserContext* ctx, int value) |
734 |
return globalVar(name); |
return globalVar(name); |
735 |
} |
} |
736 |
|
|
737 |
|
ParserContext::~ParserContext() { |
738 |
|
destroyScanner(); |
739 |
|
if (globalIntMemory) { |
740 |
|
delete globalIntMemory; |
741 |
|
globalIntMemory = NULL; |
742 |
|
} |
743 |
|
} |
744 |
|
|
745 |
void ParserContext::addErr(int line, const char* txt) { |
void ParserContext::addErr(int line, const char* txt) { |
746 |
ParserIssue e; |
ParserIssue e; |
747 |
e.type = PARSER_ERROR; |
e.type = PARSER_ERROR; |
748 |
e.txt = txt; |
e.txt = txt; |
749 |
e.line = line; |
e.line = line; |
750 |
errors.push_back(e); |
vErrors.push_back(e); |
751 |
issues.push_back(e); |
vIssues.push_back(e); |
752 |
} |
} |
753 |
|
|
754 |
void ParserContext::addWrn(int line, const char* txt) { |
void ParserContext::addWrn(int line, const char* txt) { |
756 |
w.type = PARSER_WARNING; |
w.type = PARSER_WARNING; |
757 |
w.txt = txt; |
w.txt = txt; |
758 |
w.line = line; |
w.line = line; |
759 |
warnings.push_back(w); |
vWarnings.push_back(w); |
760 |
issues.push_back(w); |
vIssues.push_back(w); |
761 |
} |
} |
762 |
|
|
763 |
bool ParserContext::setPreprocessorCondition(const char* name) { |
bool ParserContext::setPreprocessorCondition(const char* name) { |
779 |
return userPreprocessorConditions.count(name); |
return userPreprocessorConditions.count(name); |
780 |
} |
} |
781 |
|
|
782 |
|
std::vector<ParserIssue> ParserContext::issues() const { |
783 |
|
return vIssues; |
784 |
|
} |
785 |
|
|
786 |
|
std::vector<ParserIssue> ParserContext::errors() const { |
787 |
|
return vErrors; |
788 |
|
} |
789 |
|
|
790 |
|
std::vector<ParserIssue> ParserContext::warnings() const { |
791 |
|
return vWarnings; |
792 |
|
} |
793 |
|
|
794 |
|
VMEventHandler* ParserContext::eventHandler(uint index) { |
795 |
|
if (!handlers) return NULL; |
796 |
|
return handlers->eventHandler(index); |
797 |
|
} |
798 |
|
|
799 |
|
VMEventHandler* ParserContext::eventHandlerByName(const String& name) { |
800 |
|
if (!handlers) return NULL; |
801 |
|
return handlers->eventHandlerByName(name); |
802 |
|
} |
803 |
|
|
804 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |