Clear up some poor pointer management.

The expression for a paramter value was not well managed, given that
the eval_expr() function replaces pointers. Clear things up a bit.
This commit is contained in:
Stephen Williams 2008-05-20 20:32:42 -07:00
parent f9f68236bc
commit 5ec3b590bf
1 changed files with 8 additions and 7 deletions

View File

@ -289,10 +289,15 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur)
eval_expr(expr);
/* The eval_expr may delete any replace the expr pointer, so the
second.expr value cannot be relied on. Might as well replace
it now with the expression that we evaluated. */
(*cur).second.expr = expr;
switch (expr->expr_type()) {
case IVL_VT_REAL:
if (! dynamic_cast<const NetECReal*>(expr)) {
cerr << (*cur).second.expr->get_fileline()
cerr << expr->get_fileline()
<< ": internal error: "
<< "unable to evaluate real parameter value: "
<< *expr << endl;
@ -304,7 +309,7 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur)
case IVL_VT_LOGIC:
case IVL_VT_BOOL:
if (! dynamic_cast<const NetEConst*>(expr)) {
cerr << (*cur).second.expr->get_fileline()
cerr << expr->get_fileline()
<< ": internal error: "
<< "unable to evaluate parameter "
<< (*cur).first
@ -315,7 +320,7 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur)
break;
default:
cerr << (*cur).second.expr->get_fileline()
cerr << expr->get_fileline()
<< ": internal error: "
<< "unhandled expression type?" << endl;
des->errors += 1;
@ -347,10 +352,6 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur)
}
}
// Done fiddling with the expression, save it back in the parameter.
expr->set_line(*(*cur).second.expr);
(*cur).second.expr = expr;
// If there are no value ranges to test the value against,
// then we are done.
if ((*cur).second.range == 0) {