Impl __LINE__ and __FILE__
This commit is contained in:
parent
d429e77fc8
commit
44b2422433
@ -2,6 +2,7 @@
|
||||
|
||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.4.19...Unreleased) - ReleaseDate
|
||||
|
||||
* [Added] `` `__LINE__`` and `` `__FILE__`` are preprocessed
|
||||
* [Fixed] parser priority about specify
|
||||
* [Fixed] escaped_ideitifier including `` ` ``
|
||||
* [Fixed] time_literal spacing
|
||||
|
@ -425,6 +425,22 @@ pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>>(
|
||||
defines = new_defines;
|
||||
}
|
||||
}
|
||||
NodeEvent::Enter(RefNode::PositionCompilerDirective(x)) if !skip => {
|
||||
let (_, ref x) = x.nodes;
|
||||
let locate: Locate = x.try_into().unwrap();
|
||||
let x = locate.str(s);
|
||||
if x.starts_with("__FILE__") {
|
||||
ret.push::<PathBuf>(
|
||||
&x.replace(
|
||||
"__FILE__",
|
||||
&format!("\"{}\"", path.as_ref().to_string_lossy()),
|
||||
),
|
||||
None,
|
||||
);
|
||||
} else if x.starts_with("__LINE__") {
|
||||
ret.push::<PathBuf>(&x.replace("__LINE__", &format!("{}", locate.line)), None);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@ -793,6 +809,22 @@ endmodule
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test11() {
|
||||
let (ret, _) =
|
||||
preprocess(get_testcase("test11.sv"), &HashMap::new(), &[] as &[String]).unwrap();
|
||||
assert_eq!(
|
||||
ret.text(),
|
||||
r##"module a;
|
||||
initial begin
|
||||
if (3 == 0) begin
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
"##
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test12() {
|
||||
let (ret, _) =
|
||||
|
6
sv-parser-pp/testcases/test11.sv
Normal file
6
sv-parser-pp/testcases/test11.sv
Normal file
@ -0,0 +1,6 @@
|
||||
module a;
|
||||
initial begin
|
||||
if (`__LINE__ == 0) begin
|
||||
end
|
||||
end
|
||||
endmodule
|
Loading…
x
Reference in New Issue
Block a user