mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-08 17:48:46 -10:00
* use std::move() for local variables that are copied but not reused Addresses ~140 Coverity "Variable copied when it could be moved" defects across 74 files. Every std::move() targets a local variable whose value is consumed by push_back, emplace, assignment, lambda capture, or a function call and is never read again afterward. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * clang: use std::make_shared * clang: use std::make_unique * address feedback --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
|
|
#include "ActionExpression.h"
|
|
|
|
#include "ExpressionParser.h"
|
|
#include "TypeDefinition.h"
|
|
|
|
#include "actions/expression/nodes/AbstractExpression.h"
|
|
|
|
namespace actions {
|
|
namespace expression {
|
|
namespace {
|
|
|
|
SCP_string getTypeName(ValueType type)
|
|
{
|
|
const auto& typeDef = TypeDefinition::forValueType(type);
|
|
return typeDef.getName();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
ActionExpression ActionExpression::parseFromTable(ValueType expectedReturnType, const ParseContext& context)
|
|
{
|
|
SCP_string expressionText;
|
|
|
|
stuff_string(expressionText, F_NAME);
|
|
|
|
ExpressionParser parser(std::move(expressionText));
|
|
|
|
auto expression = parser.parse(context);
|
|
|
|
if (!expression) {
|
|
error_display(0, "Failed to parse action expression:\n%s", parser.getErrorText().c_str());
|
|
return ActionExpression();
|
|
}
|
|
|
|
auto type = expression->getExpressionType();
|
|
|
|
// Check if the type this evaluates to matches what we expect
|
|
if (!checkTypeWithImplicitConversion(type, expectedReturnType)) {
|
|
error_display(0,
|
|
"Expression evaluates to type <%s> but <%s> was expected!",
|
|
getTypeName(type).c_str(),
|
|
getTypeName(expectedReturnType).c_str());
|
|
return ActionExpression();
|
|
}
|
|
|
|
// Everything is valid
|
|
return ActionExpression(std::move(expression));
|
|
}
|
|
|
|
Value ActionExpression::execute(const ProgramVariables& variables) const
|
|
{
|
|
// Do not crash on invalid expressions
|
|
if (!isValid()) {
|
|
return Value();
|
|
}
|
|
|
|
return m_expression->execute(variables);
|
|
}
|
|
bool ActionExpression::isValid() const
|
|
{
|
|
return m_expression != nullptr;
|
|
}
|
|
|
|
} // namespace expression
|
|
} // namespace actions
|