This commit is contained in:
dalance 2021-11-12 11:39:01 +09:00
commit c225236236
2 changed files with 11 additions and 10 deletions

View File

@ -13,6 +13,7 @@ use sv_parser_syntaxtree::{
IncludeCompilerDirective, Locate, NodeEvent, RefNode, SourceDescription, TextMacroUsage, IncludeCompilerDirective, Locate, NodeEvent, RefNode, SourceDescription, TextMacroUsage,
WhiteSpace, WhiteSpace,
}; };
use std::collections::hash_map::RandomState;
const RECURSIVE_LIMIT: usize = 64; const RECURSIVE_LIMIT: usize = 64;
@ -81,14 +82,14 @@ impl PreprocessedText {
} }
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct Define { pub struct Define {
pub identifier: String, pub identifier: String,
pub arguments: Vec<(String, Option<String>)>, pub arguments: Vec<(String, Option<String>)>,
pub text: Option<DefineText>, pub text: Option<DefineText>,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct DefineText { pub struct DefineText {
pub text: String, pub text: String,
pub origin: Option<(PathBuf, Range)>, pub origin: Option<(PathBuf, Range)>,
@ -114,11 +115,11 @@ impl DefineText {
} }
} }
pub type Defines = HashMap<String, Option<Define>>; pub type Defines<V=RandomState> = HashMap<String, Option<Define>, V>;
pub fn preprocess<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>( pub fn preprocess<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
path: T, path: T,
pre_defines: &HashMap<String, Option<Define>, V>, pre_defines: &Defines<V>,
include_paths: &[U], include_paths: &[U],
strip_comments: bool, strip_comments: bool,
ignore_include: bool, ignore_include: bool,
@ -173,7 +174,7 @@ impl<'a> SkipNodes<'a> {
pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>( pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
s: &str, s: &str,
path: T, path: T,
pre_defines: &HashMap<String, Option<Define>, V>, pre_defines: &Defines<V>,
include_paths: &[U], include_paths: &[U],
ignore_include: bool, ignore_include: bool,
strip_comments: bool, strip_comments: bool,

View File

@ -1,7 +1,6 @@
#![recursion_limit = "256"] #![recursion_limit = "256"]
use nom_greedyerror::error_position; use nom_greedyerror::error_position;
use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::hash::BuildHasher; use std::hash::BuildHasher;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -127,7 +126,7 @@ impl<'a> IntoIterator for &'a SyntaxTree {
pub fn parse_sv<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>( pub fn parse_sv<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
path: T, path: T,
pre_defines: &HashMap<String, Option<Define>, V>, pre_defines: &Defines<V>,
include_paths: &[U], include_paths: &[U],
ignore_include: bool, ignore_include: bool,
allow_incomplete: bool, allow_incomplete: bool,
@ -178,7 +177,7 @@ pub fn parse_sv_pp(
pub fn parse_sv_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>( pub fn parse_sv_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
s: &str, s: &str,
path: T, path: T,
pre_defines: &HashMap<String, Option<Define>, V>, pre_defines: &Defines<V>,
include_paths: &[U], include_paths: &[U],
ignore_include: bool, ignore_include: bool,
allow_incomplete: bool, allow_incomplete: bool,
@ -197,7 +196,7 @@ pub fn parse_sv_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
pub fn parse_lib<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>( pub fn parse_lib<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
path: T, path: T,
pre_defines: &HashMap<String, Option<Define>, V>, pre_defines: &Defines<V>,
include_paths: &[U], include_paths: &[U],
ignore_include: bool, ignore_include: bool,
allow_incomplete: bool, allow_incomplete: bool,
@ -209,7 +208,7 @@ pub fn parse_lib<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
pub fn parse_lib_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>( pub fn parse_lib_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
s: &str, s: &str,
path: T, path: T,
pre_defines: &HashMap<String, Option<Define>, V>, pre_defines: &Defines<V>,
include_paths: &[U], include_paths: &[U],
ignore_include: bool, ignore_include: bool,
allow_incomplete: bool, allow_incomplete: bool,
@ -300,6 +299,7 @@ macro_rules! unwrap_locate {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use std::collections::HashMap;
#[test] #[test]
fn test() { fn test() {