-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update functionality that transfers definitions to the header files t…
…o deal with duplicates.
- Loading branch information
Showing
3 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::collections::HashSet; | ||
|
||
use crate::lexer; | ||
use anyhow::{Result, anyhow}; | ||
|
||
|
||
/// Returns an error if there are any duplicate definitions | ||
/// Otherwise, adds all definitions in `src` to `dst` | ||
pub(super) fn merge_defines<'a>(dst: &mut Vec<&'a [lexer::Token<'a>]>, src: &[&'a [lexer::Token<'a>]]) -> Result<()> { | ||
let mut dst_set = HashSet::new(); | ||
|
||
for &tokens in dst.iter() { | ||
let s = lexer::get_define_name(tokens); | ||
dst_set.insert(s); | ||
} | ||
|
||
for &tokens in src.iter() { | ||
let s = lexer::get_define_name(tokens); | ||
if dst_set.contains(&s) { | ||
return Err(anyhow!("Duplicate #define definitions for {}", s)); | ||
} | ||
} | ||
|
||
dst.extend_from_slice(src); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Returns an error if there are any duplicate definitions | ||
/// Otherwise, adds all definitions in `src` to `dst` | ||
pub(super) fn merge_structs<'a>(dst: &mut Vec<&'a [lexer::Token<'a>]>, src: &[&'a [lexer::Token<'a>]]) -> Result<()> { | ||
let mut dst_set = HashSet::new(); | ||
|
||
for &tokens in dst.iter() { | ||
let s = lexer::get_struct_name(tokens); | ||
dst_set.insert(s); | ||
} | ||
|
||
for &tokens in src.iter() { | ||
let s = lexer::get_struct_name(tokens); | ||
if dst_set.contains(&s) { | ||
return Err(anyhow!("Duplicate struct definitions for {}", s)); | ||
} | ||
} | ||
|
||
dst.extend_from_slice(src); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters