From d37cc5a160942faa38eeb623524e54bb16883e39 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 17 Sep 2009 22:00:17 -0400 Subject: [PATCH] Fix preprocessing commas in deep parameterized macros. --- Changes | 2 ++ src/V3PreProc.cpp | 7 ++++++- test_regress/t/t_preproc.out | 8 +++++++- test_regress/t/t_preproc.v | 6 ++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 64959209c..acf1f8684 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Don't require SYSTEMPERL_INCLUDE if SYSTEMPERL/src exists. [Gary Thomas] +**** Fix preprocessing commas in deep parameterized macros. [Brad Dobbie] + **** Fix tracing escaped dotted identifiers, bug107. **** Fix $display with uppercase %M. diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 4f76ba8be..562ba3894 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -794,6 +794,7 @@ int V3PreProcImp::getToken() { if (m_defRefs.empty()) v3fatalSrc("Shouldn't be in DEFARG w/o active defref"); V3DefineRef* refp = &(m_defRefs.top()); refp->nextarg(refp->nextarg()+m_lexp->m_defValue); m_lexp->m_defValue=""; + UINFO(4,"defarg++ "<nextarg()<args().push_back(refp->nextarg()); m_state = ps_DEFARG; @@ -806,13 +807,17 @@ int V3PreProcImp::getToken() { // Substitute in and prepare for next action // Similar code in non-parenthesized define (Search for END_OF_DEFARG) m_defRefs.pop(); - m_lexp->unputString(out.c_str()); if (m_defRefs.empty()) { + m_lexp->unputString(out.c_str()); m_state = ps_TOP; m_lexp->m_parenLevel = 0; } else { // Finished a defref inside a upper defref + // Can't subst now, or + // `define a(ign) x,y + // foo(`a(ign),`b) would break because a contains comma refp = &(m_defRefs.top()); // We popped, so new top + refp->nextarg(refp->nextarg()+m_lexp->m_defValue+out); m_lexp->m_defValue=""; m_lexp->m_parenLevel = refp->parenLevel(); m_state = ps_DEFARG; } diff --git a/test_regress/t/t_preproc.out b/test_regress/t/t_preproc.out index 85833e9a1..50fa1e5a3 100644 --- a/test_regress/t/t_preproc.out +++ b/test_regress/t/t_preproc.out @@ -191,4 +191,10 @@ Line_Preproc_Check 131 (x,y ) Line_Preproc_Check 144 -`line 146 "t/t_preproc.v" 2 + + + + + +x,y)--bee submacro has comma paren +`line 152 "t/t_preproc.v" 2 diff --git a/test_regress/t/t_preproc.v b/test_regress/t/t_preproc.v index a9f1c9630..255deebf1 100644 --- a/test_regress/t/t_preproc.v +++ b/test_regress/t/t_preproc.v @@ -143,3 +143,9 @@ Line_Preproc_Check `__LINE__ ) Line_Preproc_Check `__LINE__ +//====================================================================== +// misparsed comma in submacro +`define sb bee +`define sa(l) x,y) +`define sfoo(q,r) q--r +`sfoo(`sa(el),`sb) submacro has comma paren