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.
This commit is contained in:
damc 2022-07-26 13:10:52 +02:00
parent 543915011b
commit ab4845a964
3 changed files with 20 additions and 6 deletions

View File

@ -379,18 +379,28 @@ pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
skip_whitespace = false; skip_whitespace = false;
} }
NodeEvent::Enter(RefNode::UndefineCompilerDirective(x)) => { NodeEvent::Enter(RefNode::UndefineCompilerDirective(x)) => {
skip_nodes.push(x.into());
skip = true;
let (_, _, ref name) = x.nodes; let (_, _, ref name) = x.nodes;
let id = identifier((&name.nodes.0).into(), &s).unwrap(); let id = identifier((&name.nodes.0).into(), &s).unwrap();
defines.remove(&id); 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)) => { NodeEvent::Enter(RefNode::UndefineallCompilerDirective(x)) => {
skip_nodes.push(x.into());
skip = true;
defines.clear(); 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)) => { NodeEvent::Enter(RefNode::IfdefDirective(x)) => {
let (_, ref keyword, ref ifid, ref ifbody, ref elsif, ref elsebody, _, _) = x.nodes; let (_, ref keyword, ref ifid, ref ifbody, ref elsif, ref elsebody, _, _) = x.nodes;

View File

@ -10,4 +10,6 @@
`define __FILE__ "FOO" `define __FILE__ "FOO"
// The following undef should have no effect. // The following undef should have no effect.
`undef __FILE__
// NOTE: Comparison against expected value are destined to fail in testcase. // NOTE: Comparison against expected value are destined to fail in testcase.

View File

@ -10,6 +10,8 @@
`define __LINE__ -2 `define __LINE__ -2
// The following undef should have no effect. // The following undef should have no effect.
`undef __LINE__
module M; module M;
initial initial
if (26 == 28) // Should be "26 == 28". if (26 == 28) // Should be "26 == 28".