From 88313670c046f0a11f29940357c26d1f94f80c3a Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Tue, 20 May 2008 20:32:42 -0700 Subject: [PATCH] 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. --- net_design.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/net_design.cc b/net_design.cc index d180f7160..595a90817 100644 --- a/net_design.cc +++ b/net_design.cc @@ -288,10 +288,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(expr)) { - cerr << (*cur).second.expr->get_fileline() + cerr << expr->get_fileline() << ": internal error: " << "unable to evaluate real parameter value: " << *expr << endl; @@ -303,7 +308,7 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur) case IVL_VT_LOGIC: case IVL_VT_BOOL: if (! dynamic_cast(expr)) { - cerr << (*cur).second.expr->get_fileline() + cerr << expr->get_fileline() << ": internal error: " << "unable to evaluate parameter " << (*cur).first @@ -314,7 +319,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; @@ -346,10 +351,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) {