mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-24 13:11:33 +00:00
Let min/max pre-solve for 2+ constants, even if there are non-constants
This commit is contained in:
parent
1ffb7ad109
commit
1f09341d2b
1 changed files with 64 additions and 53 deletions
|
@ -2065,7 +2065,6 @@ FxMinMax::FxMinMax(TArray<FxExpression*> &expr, int type, const FScriptPosition
|
||||||
FxExpression *FxMinMax::Resolve(FCompileContext &ctx)
|
FxExpression *FxMinMax::Resolve(FCompileContext &ctx)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
bool isconst;
|
|
||||||
int intcount, floatcount;
|
int intcount, floatcount;
|
||||||
|
|
||||||
CHECKRESOLVED();
|
CHECKRESOLVED();
|
||||||
|
@ -2113,24 +2112,25 @@ FxExpression *FxMinMax::Resolve(FCompileContext &ctx)
|
||||||
ValueType = VAL_Int;
|
ValueType = VAL_Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if every argument is constant
|
// If at least two arguments are constants, they can be solved now.
|
||||||
isconst = true;
|
|
||||||
|
// Look for first constant
|
||||||
for (i = 0; i < choices.Size(); ++i)
|
for (i = 0; i < choices.Size(); ++i)
|
||||||
{
|
{
|
||||||
if (!choices[i]->isConstant())
|
if (choices[i]->isConstant())
|
||||||
{
|
{
|
||||||
isconst = false;
|
ExpVal best = static_cast<FxConstant *>(choices[i])->GetValue();
|
||||||
break;
|
// Compare against remaining constants, which are removed.
|
||||||
|
// The best value gets stored in this one.
|
||||||
|
for (unsigned j = i + 1; j < choices.Size(); )
|
||||||
|
{
|
||||||
|
if (!choices[j]->isConstant())
|
||||||
|
{
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
|
||||||
// If every argument is constant, we can decide this now.
|
|
||||||
if (isconst)
|
|
||||||
{
|
{
|
||||||
ExpVal best = static_cast<FxConstant *>(choices[0])->GetValue();
|
ExpVal value = static_cast<FxConstant *>(choices[j])->GetValue();
|
||||||
for (i = 1; i < choices.Size(); ++i)
|
|
||||||
{
|
|
||||||
ExpVal value = static_cast<FxConstant *>(choices[i])->GetValue();
|
|
||||||
assert(value.Type == ValueType.Type);
|
assert(value.Type == ValueType.Type);
|
||||||
if (Type == TK_Min)
|
if (Type == TK_Min)
|
||||||
{
|
{
|
||||||
|
@ -2166,11 +2166,22 @@ FxExpression *FxMinMax::Resolve(FCompileContext &ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delete choices[j];
|
||||||
|
choices[j] = NULL;
|
||||||
|
choices.Delete(j);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FxExpression *x = new FxConstant(best, ScriptPosition);
|
FxExpression *x = new FxConstant(best, ScriptPosition);
|
||||||
|
if (i == 0 && choices.Size() == 1)
|
||||||
|
{ // Every choice was constant
|
||||||
delete this;
|
delete this;
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
delete choices[i];
|
||||||
|
choices[i] = x;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue