Add non static evaluation for simple expressions

This commit is contained in:
Jan
2022-08-13 14:13:11 +02:00
parent 403d7f2c44
commit 886bcfeaf8
21 changed files with 161 additions and 59 deletions

View File

@ -110,7 +110,7 @@ namespace IW4
if (!dvarNameExpression->IsStatic())
return false;
const auto staticDvarNameExpressionValue = dvarNameExpression->Evaluate();
const auto staticDvarNameExpressionValue = dvarNameExpression->EvaluateStatic();
if (staticDvarNameExpressionValue.m_type != SimpleExpressionValue::Type::STRING)
return false;
@ -353,7 +353,7 @@ namespace IW4
{
if (!m_disable_optimizations && expression->IsStatic())
{
const auto expressionStaticValue = expression->Evaluate();
const auto expressionStaticValue = expression->EvaluateStatic();
ConvertExpressionEntryExpressionValue(entries, &expressionStaticValue);
}
else if (const auto* expressionValue = dynamic_cast<const SimpleExpressionValue*>(expression))
@ -419,7 +419,7 @@ namespace IW4
if (expression->IsStatic())
{
const auto value = expression->Evaluate();
const auto value = expression->EvaluateStatic();
switch (value.m_type)
{
case SimpleExpressionValue::Type::DOUBLE:
@ -447,7 +447,7 @@ namespace IW4
if (expression->IsStatic())
{
const auto value = expression->Evaluate();
const auto value = expression->EvaluateStatic();
switch (value.m_type)
{
case SimpleExpressionValue::Type::STRING:
@ -474,7 +474,7 @@ namespace IW4
if (expression->IsStatic())
{
const auto value = expression->Evaluate();
const auto value = expression->EvaluateStatic();
switch (value.m_type)
{
case SimpleExpressionValue::Type::STRING:
@ -507,7 +507,7 @@ namespace IW4
else
{
isStatic = expression->IsStatic();
isTruthy = isStatic && expression->Evaluate().IsTruthy();
isTruthy = isStatic && expression->EvaluateStatic().IsTruthy();
}
if (isStatic)
@ -580,7 +580,7 @@ namespace IW4
if(!m_disable_optimizations && condition->m_condition->IsStatic())
{
const auto staticValueIsTruthy = condition->m_condition->Evaluate().IsTruthy();
const auto staticValueIsTruthy = condition->m_condition->EvaluateStatic().IsTruthy();
if(staticValueIsTruthy)
ConvertEventHandlerElements(elements, condition->m_condition_elements.get(), menu, item);
@ -725,7 +725,7 @@ namespace IW4
if (expressionIsStatic)
{
const auto evaluatedValue = expression->Evaluate();
const auto evaluatedValue = expression->EvaluateStatic();
if (evaluatedValue.m_type == SimpleExpressionValue::Type::INT)
{

View File

@ -37,7 +37,12 @@ bool CommonExpressionBaseFunctionCall::IsStatic() const
return false;
}
SimpleExpressionValue CommonExpressionBaseFunctionCall::Evaluate() const
SimpleExpressionValue CommonExpressionBaseFunctionCall::EvaluateStatic() const
{
return SimpleExpressionValue(0);
}
SimpleExpressionValue CommonExpressionBaseFunctionCall::EvaluateNonStatic(ISimpleExpressionScopeValues* scopeValues) const
{
return SimpleExpressionValue(0);
}

View File

@ -16,6 +16,7 @@ namespace menu
_NODISCARD bool Equals(const ISimpleExpression* other) const override;
_NODISCARD bool IsStatic() const override;
_NODISCARD SimpleExpressionValue Evaluate() const override;
_NODISCARD SimpleExpressionValue EvaluateStatic() const override;
_NODISCARD SimpleExpressionValue EvaluateNonStatic(ISimpleExpressionScopeValues* scopeValues) const override;
};
}

View File

@ -18,7 +18,12 @@ bool CommonExpressionCustomFunctionCall::IsStatic() const
return false;
}
SimpleExpressionValue CommonExpressionCustomFunctionCall::Evaluate() const
SimpleExpressionValue CommonExpressionCustomFunctionCall::EvaluateStatic() const
{
return SimpleExpressionValue(0);
}
SimpleExpressionValue CommonExpressionCustomFunctionCall::EvaluateNonStatic(ISimpleExpressionScopeValues* scopeValues) const
{
return SimpleExpressionValue(0);
}

View File

@ -13,6 +13,7 @@ namespace menu
_NODISCARD bool Equals(const ISimpleExpression* other) const override;
_NODISCARD bool IsStatic() const override;
_NODISCARD SimpleExpressionValue Evaluate() const override;
_NODISCARD SimpleExpressionValue EvaluateStatic() const override;
_NODISCARD SimpleExpressionValue EvaluateNonStatic(ISimpleExpressionScopeValues* scopeValues) const override;
};
}

View File

@ -120,7 +120,7 @@ int MenuMatcherFactory::TokenIntExpressionValue(MenuFileParserState* state, Sequ
if (!expression || !expression->IsStatic())
throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), "Not a valid static expression");
const auto value = expression->Evaluate();
const auto value = expression->EvaluateStatic();
if (value.m_type != SimpleExpressionValue::Type::INT)
throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), "Expression MUST be int type");
@ -150,7 +150,7 @@ double MenuMatcherFactory::TokenNumericExpressionValue(MenuFileParserState* stat
if (!expression || !expression->IsStatic())
throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), "Not a valid static expression");
const auto value = expression->Evaluate();
const auto value = expression->EvaluateStatic();
if (value.m_type == SimpleExpressionValue::Type::INT)
return value.m_int_value;

View File

@ -573,7 +573,7 @@ namespace menu::event_handler_set_scope_sequences
static void EmitStaticSetLocalVar(MenuFileParserState* state, const TokenPos& pos, const SetLocalVarType type, const std::string& varName, std::unique_ptr<ISimpleExpression> expression)
{
state->m_current_script << "\"" << ScriptKeywordForType(type) << "\" \"" << varName << "\" \"";
const auto staticValue = expression->Evaluate();
const auto staticValue = expression->EvaluateStatic();
CheckStaticValueType(pos, type, staticValue);
EmitStaticValue(state, staticValue);
state->m_current_script << "\" ; ";