Add include line check
This commit is contained in:
parent
1225d3e972
commit
6fdc341ed7
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.4.18...Unreleased) - ReleaseDate
|
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.4.18...Unreleased) - ReleaseDate
|
||||||
|
|
||||||
|
* [Added] include line check
|
||||||
|
|
||||||
## [v0.4.18](https://github.com/dalance/sv-parser/compare/v0.4.17...v0.4.18) - 2019-12-12
|
## [v0.4.18](https://github.com/dalance/sv-parser/compare/v0.4.17...v0.4.18) - 2019-12-12
|
||||||
|
|
||||||
## [v0.4.17](https://github.com/dalance/sv-parser/compare/v0.4.16...v0.4.17) - 2019-12-12
|
## [v0.4.17](https://github.com/dalance/sv-parser/compare/v0.4.16...v0.4.17) - 2019-12-12
|
||||||
|
@ -26,6 +26,8 @@ pub enum ErrorKind {
|
|||||||
DefineNoArgs,
|
DefineNoArgs,
|
||||||
#[fail(display = "Exceed recursive limit")]
|
#[fail(display = "Exceed recursive limit")]
|
||||||
ExceedRecursiveLimit,
|
ExceedRecursiveLimit,
|
||||||
|
#[fail(display = "Include line can't have other items")]
|
||||||
|
IncludeLine,
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -140,6 +140,9 @@ pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>>(
|
|||||||
let mut skip_nodes = vec![];
|
let mut skip_nodes = vec![];
|
||||||
let mut defines = HashMap::new();
|
let mut defines = HashMap::new();
|
||||||
|
|
||||||
|
let mut last_item_line = None;
|
||||||
|
let mut last_include_line = None;
|
||||||
|
|
||||||
for (k, v) in pre_defines {
|
for (k, v) in pre_defines {
|
||||||
defines.insert(k.clone(), (*v).clone());
|
defines.insert(k.clone(), (*v).clone());
|
||||||
}
|
}
|
||||||
@ -178,6 +181,33 @@ pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
match n.clone() {
|
||||||
|
NodeEvent::Enter(RefNode::SourceDescriptionNotDirective(x)) => {
|
||||||
|
let locate: Locate = x.try_into().unwrap();
|
||||||
|
if let Some(last_include_line) = last_include_line {
|
||||||
|
if last_include_line == locate.line {
|
||||||
|
return Err(ErrorKind::IncludeLine.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NodeEvent::Enter(RefNode::CompilerDirective(x)) => {
|
||||||
|
let locate: Locate = x.try_into().unwrap();
|
||||||
|
if let Some(last_include_line) = last_include_line {
|
||||||
|
if last_include_line == locate.line {
|
||||||
|
return Err(ErrorKind::IncludeLine.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NodeEvent::Leave(RefNode::SourceDescriptionNotDirective(x)) => {
|
||||||
|
let locate: Locate = x.try_into().unwrap();
|
||||||
|
last_item_line = Some(locate.line);
|
||||||
|
}
|
||||||
|
NodeEvent::Leave(RefNode::CompilerDirective(x)) => {
|
||||||
|
let locate: Locate = x.try_into().unwrap();
|
||||||
|
last_item_line = Some(locate.line);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
match n {
|
match n {
|
||||||
NodeEvent::Enter(RefNode::ResetallCompilerDirective(_)) if !skip => {}
|
NodeEvent::Enter(RefNode::ResetallCompilerDirective(_)) if !skip => {}
|
||||||
NodeEvent::Enter(RefNode::UndefineCompilerDirective(x)) if !skip => {
|
NodeEvent::Enter(RefNode::UndefineCompilerDirective(x)) if !skip => {
|
||||||
@ -315,6 +345,15 @@ pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>>(
|
|||||||
defines.insert(id, Some(define));
|
defines.insert(id, Some(define));
|
||||||
}
|
}
|
||||||
NodeEvent::Enter(RefNode::IncludeCompilerDirective(x)) if !skip => {
|
NodeEvent::Enter(RefNode::IncludeCompilerDirective(x)) if !skip => {
|
||||||
|
let locate: Locate = x.try_into().unwrap();
|
||||||
|
last_include_line = Some(locate.line);
|
||||||
|
|
||||||
|
if let Some(last_item_line) = last_item_line {
|
||||||
|
if last_item_line == locate.line {
|
||||||
|
return Err(ErrorKind::IncludeLine.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut path = match x {
|
let mut path = match x {
|
||||||
IncludeCompilerDirective::DoubleQuote(x) => {
|
IncludeCompilerDirective::DoubleQuote(x) => {
|
||||||
let (_, _, ref literal) = x.nodes;
|
let (_, _, ref literal) = x.nodes;
|
||||||
@ -722,4 +761,24 @@ endmodule
|
|||||||
"Err(Error { inner: \n\nExceed recursive limit })"
|
"Err(Error { inner: \n\nExceed recursive limit })"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test9() {
|
||||||
|
let include_paths = [get_testcase("")];
|
||||||
|
let ret = preprocess(get_testcase("test9.sv"), &HashMap::new(), &include_paths);
|
||||||
|
assert_eq!(
|
||||||
|
format!("{:?}", ret),
|
||||||
|
"Err(Error { inner: \n\nInclude line can\'t have other items })"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test10() {
|
||||||
|
let include_paths = [get_testcase("")];
|
||||||
|
let ret = preprocess(get_testcase("test10.sv"), &HashMap::new(), &include_paths);
|
||||||
|
assert_eq!(
|
||||||
|
format!("{:?}", ret),
|
||||||
|
"Err(Error { inner: \n\nInclude line can\'t have other items })"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
2
sv-parser-pp/testcases/test10.sv
Normal file
2
sv-parser-pp/testcases/test10.sv
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
module and_op (a, b, c);
|
||||||
|
`include "test2.svh" endmodule
|
3
sv-parser-pp/testcases/test9.sv
Normal file
3
sv-parser-pp/testcases/test9.sv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module and_op (a, b, c);
|
||||||
|
`include "test2.svh" `include "test2.svh"
|
||||||
|
endmodule
|
Loading…
x
Reference in New Issue
Block a user