diff --git a/nautilus-api/include/Interface/DataTypes/Val.hpp b/nautilus-api/include/Interface/DataTypes/Val.hpp index c11891e6..c3a9ac39 100644 --- a/nautilus-api/include/Interface/DataTypes/Val.hpp +++ b/nautilus-api/include/Interface/DataTypes/Val.hpp @@ -170,7 +170,11 @@ namespace nautilus { }*/ #else - + inline val() : state(tracing::traceConstant(0)) { + if (tracing::inTracer()) { + tracing::getVarRefMap()[state]++; + } + }; inline val(ValueType value) : value(value), state(tracing::traceConstant(value)) { if (tracing::inTracer()) { tracing::getVarRefMap()[state]++; @@ -678,7 +682,7 @@ namespace nautilus { } template - val inline operator>(LHS &left, RHS right) { + val inline operator>(LHS left, RHS right) { if constexpr (is_fundamental) { auto leftV = make_value(left); return details::gt<>(right, leftV); @@ -875,6 +879,8 @@ namespace nautilus { return left; } + + template auto &operator<<=(val &left, RHS right) { left = left << right; @@ -944,4 +950,5 @@ class sval { }; + #endif //NAUTILUS_LIB_VAL_HPP diff --git a/nautilus-api/test/ExecutionTests/ControlFlowFunctions.hpp b/nautilus-api/test/ExecutionTests/ControlFlowFunctions.hpp index d515ec0d..70450146 100644 --- a/nautilus-api/test/ExecutionTests/ControlFlowFunctions.hpp +++ b/nautilus-api/test/ExecutionTests/ControlFlowFunctions.hpp @@ -124,4 +124,177 @@ namespace nautilus::engine { equals = equals && (value == (int64_t) 42); return equals; } + + val nestedIf(val value) { + val result = 1; + if (value < 20) { + if (value > 10) { + result = 2; + } else { + result = 3; + } + } + return result; + } + + + val ifElseIfElse(val value) { + val result; + if (value == 0) { + result = 10; + } else if (value == 1) { + result = 20; + } else { + result = 30; + } + return result; + } + val logicalAnd(val value) { + val result = 0; + if (value > 5 && value < 15) { + result = 1; + } + return result; + } + val logicalOr(val value) { + val result = 0; + if (value == 10 || value == 20) { + result = 1; + } + return result; + } + + val ifNotEqual(val value) { + val result = 1; + if (value != 5) { + result = 2; + } + return result; + } + val multipleConditions(val value) { + val result = 0; + if (value > 0 && value < 10 || value == 20) { + result = 1; + } + return result; + } + val ifElseIfOnly(val value) { + val result = 0; + if (value < 5) { + result = 1; + } else if (value < 10) { + result = 2; + } + return result; + } + val compoundAssignment(val value) { + val result = 10; + if (value == 5) { + result += 5; + } + return result; + } + + val multipleElse(val value) { + val result; + if (value == 10) { + result = 1; + } else { + result = 2; + if (value == 5) { + result = 3; + } else { + result = 4; + } + } + return result; + } + val ifWithTernary(val value) { + val result = value > 5 ? 10 : 5; + if (value == 0) { + result = -1; + } + return result; + } + val ifInsideLoop(val value) { + val result = 0; + for (int i = 0; i < value; i++) { + if (i % 2 == 0) { + result += 1; + } + } + return result; + } + val complexLogicalExpressions(val value) { + val result = 0; + if ((value > 5 && value < 10) || (value > 15 && value < 20)) { + result = 1; + } + return result; + } + + val shortCircuitEvaluation(val value) { + val result = 0; + if ((value != 0) && ( (10 / value) > 1)) { + result = 1; + } + return result; + } + + val helperFunction(val x) { + return x * 2; + } + + val ifWithFunctionCall(val value) { + val result = 0; + if (helperFunction(value) > 10) { + result = 1; + } + return result; + } + val compoundStatements(val value) { + val result = 0; + if (value > 5) { + result = 1; + result *= 2; + } + return result; + } + val varyingComplexity(val value) { + val result; + if (value < 5) { + result = 1; + } else if (value >= 5 && value <= 10) { + result = 2; + if (value == 7) result += 1; + } else { + result = 3; + } + return result; + } + val logicalXOR(val value) { + val result = 0; + if ((value < 10) != (value > 5)) { // XOR + result = 1; + } + return result; + } + val nestedIfElseDifferentLevels(val value) { + val result = 0; + if (value > 0) { + if (value < 5) { + result = 1; + } else { + result = 2; + if (value == 6) { + result = 3; + } + } + } else { + result = -1; + } + return result; + } + + } diff --git a/nautilus-api/test/ExecutionTests/TracingTest.cpp b/nautilus-api/test/ExecutionTests/TracingTest.cpp index 221d8265..448b4b6c 100644 --- a/nautilus-api/test/ExecutionTests/TracingTest.cpp +++ b/nautilus-api/test/ExecutionTests/TracingTest.cpp @@ -140,8 +140,37 @@ namespace nautilus::engine { "deeplyNestedIfElseIfCondition", details::createFunctionWrapper(deeplyNestedIfElseIfCondition) }, { "andFunction", details::createFunctionWrapper(andFunction) - } - + }, { + "nestedIf", details::createFunctionWrapper(nestedIf) + }, { + "ifElseIfElse", details::createFunctionWrapper(ifElseIfElse) + }, { + "logicalAnd", details::createFunctionWrapper(logicalAnd) + }, { + "logicalOr", details::createFunctionWrapper(logicalOr) + }, { + "ifNotEqual", details::createFunctionWrapper(ifNotEqual) + }, { + "multipleConditions", details::createFunctionWrapper(multipleConditions) + }, { + "ifWithTernary", details::createFunctionWrapper(ifWithTernary) + }, { + "ifInsideLoop", details::createFunctionWrapper(ifInsideLoop) + }, { + "complexLogicalExpressions", details::createFunctionWrapper(complexLogicalExpressions) + }, { + "shortCircuitEvaluation", details::createFunctionWrapper(shortCircuitEvaluation) + }, { + "ifWithFunctionCall", details::createFunctionWrapper(ifWithFunctionCall) + }, { + "compoundStatements", details::createFunctionWrapper(compoundStatements) + }, { + "varyingComplexity", details::createFunctionWrapper(varyingComplexity) + }, { + "logicalXOR", details::createFunctionWrapper(logicalXOR) + }, { + "nestedIfElseDifferentLevels", details::createFunctionWrapper(nestedIfElseDifferentLevels) + }, }; for (auto test: tests) {