fix conditionals, in particular the nested else handling

this also removes the optimization to skip test function calls which
appear to be part of a failed test, as this could skip includes, etc. as
well.
This commit is contained in:
Oswald Buddenhagen
2009-05-14 14:35:37 +02:00
parent 68b1b828e6
commit ed00bd2c85

View File

@@ -193,11 +193,9 @@ public:
QStringList qmakeFeaturePaths(); QStringList qmakeFeaturePaths();
enum Condition { ConditionFalse, ConditionTrue, ConditionElse };
struct State { struct State {
Condition condition; bool condition;
Condition prevCondition; bool prevCondition;
bool updateCondition; // == !(enclosingBlock()->kind() & ScopeContents)
} m_sts; } m_sts;
bool m_invertNext; // Short-lived, so not in State bool m_invertNext; // Short-lived, so not in State
int m_skipLevel; int m_skipLevel;
@@ -240,8 +238,8 @@ ProFileEvaluator::Private::Private(ProFileEvaluator *q_)
m_cumulative = true; m_cumulative = true;
// Evaluator state // Evaluator state
m_sts.updateCondition = false; m_sts.condition = false;
m_sts.condition = ConditionFalse; m_sts.prevCondition = false;
m_invertNext = false; m_invertNext = false;
m_skipLevel = 0; m_skipLevel = 0;
m_isFirstVariableValue = true; m_isFirstVariableValue = true;
@@ -559,20 +557,20 @@ void ProFileEvaluator::Private::updateItem()
bool ProFileEvaluator::Private::visitBeginProBlock(ProBlock *block) bool ProFileEvaluator::Private::visitBeginProBlock(ProBlock *block)
{ {
if (block->blockKind() == ProBlock::ScopeKind) { if (block->blockKind() & ProBlock::ScopeContentsKind) {
m_sts.updateCondition = true; if (!m_sts.condition)
if (!m_skipLevel) {
m_sts.prevCondition = m_sts.condition;
m_sts.condition = ConditionFalse;
} else {
Q_ASSERT(m_sts.condition != ConditionTrue);
}
} else if (block->blockKind() & ProBlock::ScopeContentsKind) {
m_sts.updateCondition = false;
if (m_sts.condition != ConditionTrue)
++m_skipLevel; ++m_skipLevel;
else else
Q_ASSERT(!m_skipLevel); Q_ASSERT(!m_skipLevel);
} else {
if (!m_skipLevel) {
if (m_sts.condition) {
m_sts.prevCondition = true;
m_sts.condition = false;
}
} else {
Q_ASSERT(!m_sts.condition);
}
} }
return true; return true;
} }
@@ -581,12 +579,12 @@ bool ProFileEvaluator::Private::visitEndProBlock(ProBlock *block)
{ {
if (block->blockKind() & ProBlock::ScopeContentsKind) { if (block->blockKind() & ProBlock::ScopeContentsKind) {
if (m_skipLevel) { if (m_skipLevel) {
Q_ASSERT(m_sts.condition != ConditionTrue); Q_ASSERT(!m_sts.condition);
--m_skipLevel; --m_skipLevel;
} else { } else if (!(block->blockKind() & ProBlock::SingleLine)) {
// Conditionals contained inside this block may have changed the state. // Conditionals contained inside this block may have changed the state.
// So we reset it here to make an else following us do the right thing. // So we reset it here to make an else following us do the right thing.
m_sts.condition = ConditionTrue; m_sts.condition = true;
} }
} }
return true; return true;
@@ -621,15 +619,11 @@ bool ProFileEvaluator::Private::visitProCondition(ProCondition *cond)
{ {
if (!m_skipLevel) { if (!m_skipLevel) {
if (cond->text().toLower() == QLatin1String("else")) { if (cond->text().toLower() == QLatin1String("else")) {
// The state ConditionElse makes sure that subsequential elses are ignored. m_sts.condition = !m_sts.prevCondition;
// That's braindead, but qmake is like that. } else {
if (m_sts.prevCondition == ConditionTrue) m_sts.prevCondition = false;
m_sts.condition = ConditionElse; if (!m_sts.condition && isActiveConfig(cond->text(), true) ^ m_invertNext)
else if (m_sts.prevCondition == ConditionFalse) m_sts.condition = true;
m_sts.condition = ConditionTrue;
} else if (m_sts.condition == ConditionFalse) {
if (isActiveConfig(cond->text(), true) ^ m_invertNext)
m_sts.condition = ConditionTrue;
} }
} }
m_invertNext = false; m_invertNext = false;
@@ -872,7 +866,9 @@ bool ProFileEvaluator::Private::visitProFunction(ProFunction *func)
// Make sure that called subblocks don't inherit & destroy the state // Make sure that called subblocks don't inherit & destroy the state
bool invertThis = m_invertNext; bool invertThis = m_invertNext;
m_invertNext = false; m_invertNext = false;
if (!m_sts.updateCondition || m_sts.condition == ConditionFalse) { if (!m_skipLevel)
m_sts.prevCondition = false;
if (m_cumulative || !m_sts.condition) {
QString text = func->text(); QString text = func->text();
int lparen = text.indexOf(QLatin1Char('(')); int lparen = text.indexOf(QLatin1Char('('));
int rparen = text.lastIndexOf(QLatin1Char(')')); int rparen = text.lastIndexOf(QLatin1Char(')'));
@@ -882,7 +878,7 @@ bool ProFileEvaluator::Private::visitProFunction(ProFunction *func)
m_lineNo = func->lineNumber(); m_lineNo = func->lineNumber();
bool result = evaluateConditionalFunction(funcName.trimmed(), arguments); bool result = evaluateConditionalFunction(funcName.trimmed(), arguments);
if (!m_skipLevel && (result ^ invertThis)) if (!m_skipLevel && (result ^ invertThis))
m_sts.condition = ConditionTrue; m_sts.condition = true;
} }
return true; return true;
} }