ExprEngine; refactoring if()
This commit is contained in:
parent
1bf6a2f62b
commit
1ce5beb45f
|
@ -2499,11 +2499,11 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
const Token *cond = tok->next()->astOperand2(); // TODO: C++17 condition
|
const Token *cond = tok->next()->astOperand2(); // TODO: C++17 condition
|
||||||
const ExprEngine::ValuePtr condValue = executeExpression(cond, data);
|
const ExprEngine::ValuePtr condValue = executeExpression(cond, data);
|
||||||
|
|
||||||
bool alwaysFalse = false;
|
bool canBeFalse = true;
|
||||||
bool alwaysTrue = false;
|
bool canBeTrue = true;
|
||||||
if (auto b = std::dynamic_pointer_cast<ExprEngine::BinOpResult>(condValue)) {
|
if (auto b = std::dynamic_pointer_cast<ExprEngine::BinOpResult>(condValue)) {
|
||||||
alwaysFalse = !b->isTrue(&data);
|
canBeFalse = b->isEqual(&data, 0);
|
||||||
alwaysTrue = !alwaysFalse && !b->isEqual(&data, 0);
|
canBeTrue = b->isTrue(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Data &thenData(data);
|
Data &thenData(data);
|
||||||
|
@ -2529,10 +2529,10 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!alwaysFalse)
|
if (canBeTrue)
|
||||||
exec(thenStart->next(), end, thenData);
|
exec(thenStart->next(), end, thenData);
|
||||||
|
|
||||||
if (!alwaysTrue) {
|
if (canBeFalse) {
|
||||||
if (Token::simpleMatch(thenEnd, "} else {")) {
|
if (Token::simpleMatch(thenEnd, "} else {")) {
|
||||||
const Token *elseStart = thenEnd->tokAt(2);
|
const Token *elseStart = thenEnd->tokAt(2);
|
||||||
exec(elseStart->next(), end, elseData);
|
exec(elseStart->next(), end, elseData);
|
||||||
|
@ -2544,11 +2544,8 @@ static std::string execute(const Token *start, const Token *end, Data &data)
|
||||||
if (exceptionToken)
|
if (exceptionToken)
|
||||||
throw ExprEngineException(exceptionToken, exceptionMessage);
|
throw ExprEngineException(exceptionToken, exceptionMessage);
|
||||||
|
|
||||||
if (alwaysTrue)
|
return (canBeTrue ? thenData.str() : std::string()) +
|
||||||
return thenData.str();
|
(canBeFalse ? elseData.str() : std::string());
|
||||||
else if (alwaysFalse)
|
|
||||||
return elseData.str();
|
|
||||||
return thenData.str() + elseData.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::simpleMatch(tok, "switch (")) {
|
else if (Token::simpleMatch(tok, "switch (")) {
|
||||||
|
|
Loading…
Reference in New Issue