501 |
return STMT_SUCCESS; |
return STMT_SUCCESS; |
502 |
} |
} |
503 |
|
|
504 |
EventHandler::EventHandler(StatementsRef statements) { |
Subroutine::Subroutine(StatementsRef statements) { |
505 |
this->statements = statements; |
this->statements = statements; |
506 |
|
} |
507 |
|
|
508 |
|
void Subroutine::dump(int level) { |
509 |
|
printIndents(level); |
510 |
|
printf("Subroutine {\n"); |
511 |
|
statements->dump(level+1); |
512 |
|
printIndents(level); |
513 |
|
printf("}\n"); |
514 |
|
} |
515 |
|
|
516 |
|
UserFunction::UserFunction(StatementsRef statements) |
517 |
|
: Subroutine(statements) |
518 |
|
{ |
519 |
|
} |
520 |
|
|
521 |
|
EventHandler::EventHandler(StatementsRef statements) |
522 |
|
: Subroutine(statements) |
523 |
|
{ |
524 |
usingPolyphonics = statements->isPolyphonic(); |
usingPolyphonics = statements->isPolyphonic(); |
525 |
} |
} |
526 |
|
|
527 |
void EventHandler::dump(int level) { |
void EventHandler::dump(int level) { |
528 |
printIndents(level); |
printIndents(level); |
529 |
printf("EventHandler {\n"); |
printf("EventHandler {\n"); |
530 |
statements->dump(level+1); |
Subroutine::dump(level+1); |
531 |
printIndents(level); |
printIndents(level); |
532 |
printf("}\n"); |
printf("}\n"); |
533 |
} |
} |
594 |
Unit( |
Unit( |
595 |
(fn) ? fn->returnUnitType(dynamic_cast<VMFnArgs*>(&*args)) : VM_NO_UNIT |
(fn) ? fn->returnUnitType(dynamic_cast<VMFnArgs*>(&*args)) : VM_NO_UNIT |
596 |
), |
), |
597 |
functionName(function), args(args), fn(fn), result(NULL) |
functionName(function), args(args), fn(fn), |
598 |
|
result( (fn) ? fn->allocResult(dynamic_cast<VMFnArgs*>(&*args)) : NULL ) |
599 |
{ |
{ |
600 |
} |
} |
601 |
|
|
602 |
|
FunctionCall::~FunctionCall() { |
603 |
|
if (result) { |
604 |
|
delete result; |
605 |
|
result = NULL; |
606 |
|
} |
607 |
|
} |
608 |
|
|
609 |
void FunctionCall::dump(int level) { |
void FunctionCall::dump(int level) { |
610 |
printIndents(level); |
printIndents(level); |
611 |
printf("FunctionCall '%s' args={\n", functionName.c_str()); |
printf("FunctionCall '%s' args={\n", functionName.c_str()); |
637 |
|
|
638 |
VMFnResult* FunctionCall::execVMFn() { |
VMFnResult* FunctionCall::execVMFn() { |
639 |
if (!fn) return NULL; |
if (!fn) return NULL; |
640 |
|
|
641 |
|
// tell function where it shall dump its return value to |
642 |
|
VMFnResult* oldRes = fn->boundResult(); |
643 |
|
fn->bindResult(result); |
644 |
|
|
645 |
// assuming here that all argument checks (amount and types) have been made |
// assuming here that all argument checks (amount and types) have been made |
646 |
// at parse time, to avoid time intensive checks on each function call |
// at parse time, to avoid time intensive checks on each function call |
647 |
VMFnResult* res = fn->exec(dynamic_cast<VMFnArgs*>(&*args)); |
VMFnResult* res = fn->exec(dynamic_cast<VMFnArgs*>(&*args)); |
648 |
|
|
649 |
|
// restore previous result binding of some potential toplevel or concurrent |
650 |
|
// caller, i.e. if exactly same function is called more than one time, |
651 |
|
// concurrently in a term by other FunctionCall objects, e.g.: |
652 |
|
// ~c := ceil( ceil(~a) + ~b) |
653 |
|
fn->bindResult(oldRes); |
654 |
|
|
655 |
if (!res) return res; |
if (!res) return res; |
656 |
|
|
657 |
VMExpr* expr = res->resultValue(); |
VMExpr* expr = res->resultValue(); |
674 |
} |
} |
675 |
|
|
676 |
StmtFlags_t FunctionCall::exec() { |
StmtFlags_t FunctionCall::exec() { |
677 |
result = execVMFn(); |
VMFnResult* result = execVMFn(); |
678 |
if (!result) |
if (!result) |
679 |
return StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
return StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED); |
680 |
return result->resultFlags(); |
return result->resultFlags(); |
681 |
} |
} |
682 |
|
|
683 |
vmint FunctionCall::evalInt() { |
vmint FunctionCall::evalInt() { |
684 |
result = execVMFn(); |
VMFnResult* result = execVMFn(); |
685 |
if (!result) return 0; |
if (!result) return 0; |
686 |
VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue()); |
VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue()); |
687 |
if (!intExpr) return 0; |
if (!intExpr) return 0; |
689 |
} |
} |
690 |
|
|
691 |
vmfloat FunctionCall::evalReal() { |
vmfloat FunctionCall::evalReal() { |
692 |
result = execVMFn(); |
VMFnResult* result = execVMFn(); |
693 |
if (!result) return 0; |
if (!result) return 0; |
694 |
VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue()); |
VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue()); |
695 |
if (!realExpr) return 0; |
if (!realExpr) return 0; |
704 |
// calls to be evaluated at all. This issue should be addressed cleanly by |
// calls to be evaluated at all. This issue should be addressed cleanly by |
705 |
// adjusting the API appropriately. |
// adjusting the API appropriately. |
706 |
FunctionCall* rwSelf = const_cast<FunctionCall*>(this); |
FunctionCall* rwSelf = const_cast<FunctionCall*>(this); |
707 |
rwSelf->result = rwSelf->execVMFn(); |
VMFnResult* result = rwSelf->execVMFn(); |
708 |
|
|
709 |
if (!result) return 0; |
if (!result) return 0; |
710 |
VMIntArrayExpr* intArrExpr = dynamic_cast<VMIntArrayExpr*>(result->resultValue()); |
VMIntArrayExpr* intArrExpr = dynamic_cast<VMIntArrayExpr*>(result->resultValue()); |
719 |
// calls to be evaluated at all. This issue should be addressed cleanly by |
// calls to be evaluated at all. This issue should be addressed cleanly by |
720 |
// adjusting the API appropriately. |
// adjusting the API appropriately. |
721 |
FunctionCall* rwSelf = const_cast<FunctionCall*>(this); |
FunctionCall* rwSelf = const_cast<FunctionCall*>(this); |
722 |
rwSelf->result = rwSelf->execVMFn(); |
VMFnResult* result = rwSelf->execVMFn(); |
723 |
|
|
724 |
if (!result) return 0; |
if (!result) return 0; |
725 |
VMRealArrayExpr* realArrExpr = dynamic_cast<VMRealArrayExpr*>(result->resultValue()); |
VMRealArrayExpr* realArrExpr = dynamic_cast<VMRealArrayExpr*>(result->resultValue()); |
727 |
} |
} |
728 |
|
|
729 |
String FunctionCall::evalStr() { |
String FunctionCall::evalStr() { |
730 |
result = execVMFn(); |
VMFnResult* result = execVMFn(); |
731 |
if (!result) return ""; |
if (!result) return ""; |
732 |
VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(result->resultValue()); |
VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(result->resultValue()); |
733 |
if (!strExpr) return ""; |
if (!strExpr) return ""; |
735 |
} |
} |
736 |
|
|
737 |
String FunctionCall::evalCastToStr() { |
String FunctionCall::evalCastToStr() { |
738 |
result = execVMFn(); |
VMFnResult* result = execVMFn(); |
739 |
if (!result) return ""; |
if (!result) return ""; |
740 |
const ExprType_t resultType = result->resultValue()->exprType(); |
const ExprType_t resultType = result->resultValue()->exprType(); |
741 |
if (resultType == STRING_EXPR) { |
if (resultType == STRING_EXPR) { |
1064 |
if (expr) { |
if (expr) { |
1065 |
this->values[i] = expr->evalInt(); |
this->values[i] = expr->evalInt(); |
1066 |
this->unitFactors[i] = expr->unitFactor(); |
this->unitFactors[i] = expr->unitFactor(); |
1067 |
|
} else { |
1068 |
|
this->values[i] = 0; |
1069 |
|
this->unitFactors[i] = VM_NO_FACTOR; |
1070 |
} |
} |
1071 |
} |
} |
1072 |
|
for (vmint i = values->argsCount(); i < size; ++i) { |
1073 |
|
this->values[i] = 0; |
1074 |
|
this->unitFactors[i] = VM_NO_FACTOR; |
1075 |
|
} |
1076 |
} |
} |
1077 |
|
|
1078 |
IntArrayVariable::IntArrayVariable(ParserContext* ctx, bool bConst) : |
IntArrayVariable::IntArrayVariable(ParserContext* ctx, bool bConst) : |
1163 |
if (expr) { |
if (expr) { |
1164 |
this->values[i] = expr->evalReal(); |
this->values[i] = expr->evalReal(); |
1165 |
this->unitFactors[i] = expr->unitFactor(); |
this->unitFactors[i] = expr->unitFactor(); |
1166 |
|
} else { |
1167 |
|
this->values[i] = (vmfloat) 0; |
1168 |
|
this->unitFactors[i] = VM_NO_FACTOR; |
1169 |
} |
} |
1170 |
} |
} |
1171 |
|
for (vmint i = values->argsCount(); i < size; ++i) { |
1172 |
|
this->values[i] = (vmfloat) 0; |
1173 |
|
this->unitFactors[i] = VM_NO_FACTOR; |
1174 |
|
} |
1175 |
} |
} |
1176 |
|
|
1177 |
RealArrayVariable::RealArrayVariable(ParserContext* ctx, bool bConst) : |
RealArrayVariable::RealArrayVariable(ParserContext* ctx, bool bConst) : |
1836 |
printf(")\n"); |
printf(")\n"); |
1837 |
} |
} |
1838 |
|
|
1839 |
StatementsRef ParserContext::userFunctionByName(const String& name) { |
UserFunctionRef ParserContext::userFunctionByName(const String& name) { |
1840 |
if (!userFnTable.count(name)) { |
if (!userFnTable.count(name)) { |
1841 |
return StatementsRef(); |
return UserFunctionRef(); |
1842 |
} |
} |
1843 |
return userFnTable.find(name)->second; |
return userFnTable.find(name)->second; |
1844 |
} |
} |
1882 |
delete globalRealMemory; |
delete globalRealMemory; |
1883 |
globalRealMemory = NULL; |
globalRealMemory = NULL; |
1884 |
} |
} |
1885 |
|
for (void* data : vAutoFreeAfterParse) |
1886 |
|
free(data); |
1887 |
|
vAutoFreeAfterParse.clear(); |
1888 |
} |
} |
1889 |
|
|
1890 |
void ParserContext::addErr(int firstLine, int lastLine, int firstColumn, |
void ParserContext::addErr(int firstLine, int lastLine, int firstColumn, |
1954 |
return userPreprocessorConditions.count(name); |
return userPreprocessorConditions.count(name); |
1955 |
} |
} |
1956 |
|
|
1957 |
|
void ParserContext::autoFreeAfterParse(void* data) { |
1958 |
|
vAutoFreeAfterParse.push_back(data); |
1959 |
|
} |
1960 |
|
|
1961 |
std::vector<ParserIssue> ParserContext::issues() const { |
std::vector<ParserIssue> ParserContext::issues() const { |
1962 |
return vIssues; |
return vIssues; |
1963 |
} |
} |