Commit c01aaaf7 authored by js9's avatar js9

Made previous fix (for unary negatives in enumerate()) more

general, applying to all expressions, and becoming an
optimization for some math operations in the process.
 


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@5838 18c085ea-50e0-402c-830e-de6fd14e8384
parent b6ec9c1e
......@@ -185,6 +185,11 @@ avtApplyEnumerationExpression::DeriveVariable(vtkDataSet *in_ds)
// Jeremy Meredith, Mon Dec 15 12:52:34 EST 2008
// Account for negative values in the enumeration list.
//
// Jeremy Meredith, Mon Dec 15 14:31:42 EST 2008
// Moved the accounting for unary minus into the parser itself, so
// I removed the check for it in here. The new fix/optimization
// should apply to all expressions now.
//
// ****************************************************************************
void
......@@ -223,30 +228,15 @@ avtApplyEnumerationExpression::ProcessArguments(ArgsExpr *args,
}
ExprNode *item = (*elems)[i]->GetItem();
// We interpret negative values as unary minus + positive value.
// So keep inspecting down here.
double scale = +1;
while (item->GetTypeName() == "Unary")
{
UnaryExpr *u = dynamic_cast<UnaryExpr*>(item);
if (u->GetOp() != '-')
EXCEPTION2(ExpressionException, outputVariableName,
"got an unexpected unary operator "
"which wasn't '-'.");
scale *= -1;
item = u->GetExpr();
}
if (item->GetTypeName() == "FloatConst")
{
ConstExpr *c = dynamic_cast<ConstExpr*>(item);
enumeratedValues[i] = scale * dynamic_cast<FloatConstExpr*>(c)->GetValue();
enumeratedValues[i] = dynamic_cast<FloatConstExpr*>(c)->GetValue();
}
else if (item->GetTypeName() == "IntegerConst")
{
ConstExpr *c = dynamic_cast<ConstExpr*>(item);
enumeratedValues[i] = scale * dynamic_cast<IntegerConstExpr*>(c)->GetValue();
enumeratedValues[i] = dynamic_cast<IntegerConstExpr*>(c)->GetValue();
}
else
{
......
......@@ -152,6 +152,10 @@ ExprParser::ExprParser(ExprNodeFactory *f) : Parser(), factory(f)
// Jeremy Meredith, Wed Jul 23 11:20:17 EDT 2008
// Allow backslashes in paths for better windows support.
//
// Jeremy Meredith, Mon Dec 15 14:30:57 EST 2008
// Allow unary minus to get integrated directly into float and int
// constants.
//
// ****************************************************************************
ParseTreeNode*
ExprParser::ApplyRule(const Symbol &sym,
......@@ -214,9 +218,28 @@ ExprParser::ApplyRule(const Symbol &sym,
((IntegerConst*)T[2])->GetValue());
break;
case 7:
node = factory->CreateUnaryExpr(p,
((Character*)T[0])->GetVal(),
(ExprNode*)(E[1]));
// We can be a little smart and condense "-int" or "-float"
// into a single constant here.
if (((Character*)T[0])->GetVal() == '-' &&
E[1]->GetTypeName() == "IntegerConst")
{
ConstExpr *c = dynamic_cast<ConstExpr*>(E[1]);
int v = dynamic_cast<IntegerConstExpr*>(c)->GetValue();
node = factory->CreateIntegerConstExpr(p,-v);
}
else if (((Character*)T[0])->GetVal() == '-' &&
E[1]->GetTypeName() == "FloatConst")
{
ConstExpr *c = dynamic_cast<ConstExpr*>(E[1]);
float v = dynamic_cast<FloatConstExpr*>(c)->GetValue();
node = factory->CreateFloatConstExpr(p,-v);
}
else
{
node = factory->CreateUnaryExpr(p,
((Character*)T[0])->GetVal(),
(ExprNode*)(E[1]));
}
break;
case 8:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment