From ab4845a964330fda1046eba0272f6efd28366c78 Mon Sep 17 00:00:00 2001 From: damc Date: Tue, 26 Jul 2022 13:10:52 +0200 Subject: [PATCH] ppTests Avoid removal of `undef and `undefineall directives. - Similarly to how `define is left in-place, `undef and `undefine are also left in-place. - Corresponding fixes to macro_LINE and macro_FILE. - These directives were not in any testcases before this branch. --- sv-parser-pp/src/preprocess.rs | 22 ++++++++++++++----- sv-parser-pp/testcases/expected/macro_FILE.sv | 2 ++ sv-parser-pp/testcases/expected/macro_LINE.sv | 2 ++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index d79061c..2793f1f 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -379,18 +379,28 @@ pub fn preprocess_str, U: AsRef, V: BuildHasher>( skip_whitespace = false; } NodeEvent::Enter(RefNode::UndefineCompilerDirective(x)) => { - skip_nodes.push(x.into()); - skip = true; - let (_, _, ref name) = x.nodes; let id = identifier((&name.nodes.0).into(), &s).unwrap(); defines.remove(&id); + + let locate: Locate = x.try_into().unwrap(); + let range = Range::new(locate.offset, locate.offset + locate.len); + ret.push(locate.str(&s), Some((path.as_ref(), range))); + skip_whitespace = true; + } + NodeEvent::Leave(RefNode::UndefineCompilerDirective(_)) => { + skip_whitespace = false; } NodeEvent::Enter(RefNode::UndefineallCompilerDirective(x)) => { - skip_nodes.push(x.into()); - skip = true; - defines.clear(); + + let locate: Locate = x.try_into().unwrap(); + let range = Range::new(locate.offset, locate.offset + locate.len); + ret.push(locate.str(&s), Some((path.as_ref(), range))); + skip_whitespace = true; + } + NodeEvent::Leave(RefNode::UndefineallCompilerDirective(_)) => { + skip_whitespace = false; } NodeEvent::Enter(RefNode::IfdefDirective(x)) => { let (_, ref keyword, ref ifid, ref ifbody, ref elsif, ref elsebody, _, _) = x.nodes; diff --git a/sv-parser-pp/testcases/expected/macro_FILE.sv b/sv-parser-pp/testcases/expected/macro_FILE.sv index 402c6d1..6edf5c2 100644 --- a/sv-parser-pp/testcases/expected/macro_FILE.sv +++ b/sv-parser-pp/testcases/expected/macro_FILE.sv @@ -10,4 +10,6 @@ `define __FILE__ "FOO" // The following undef should have no effect. +`undef __FILE__ + // NOTE: Comparison against expected value are destined to fail in testcase. diff --git a/sv-parser-pp/testcases/expected/macro_LINE.sv b/sv-parser-pp/testcases/expected/macro_LINE.sv index 46752cd..58ec595 100644 --- a/sv-parser-pp/testcases/expected/macro_LINE.sv +++ b/sv-parser-pp/testcases/expected/macro_LINE.sv @@ -10,6 +10,8 @@ `define __LINE__ -2 // The following undef should have no effect. +`undef __LINE__ + module M; initial if (26 == 28) // Should be "26 == 28".