2022-02-28 23:19:21 +01:00
|
|
|
use core::fmt::Debug;
|
|
|
|
|
2022-03-02 19:13:31 +01:00
|
|
|
use proc_macro2::TokenStream;
|
2022-02-28 23:19:21 +01:00
|
|
|
use serde::{Serialize, Deserialize};
|
2022-03-02 18:14:48 +01:00
|
|
|
use serde_wrapper::TokenStreamWrapper;
|
2022-02-28 23:19:21 +01:00
|
|
|
|
|
|
|
mod serde_wrapper;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
struct TraitProfile{
|
|
|
|
//functions: HashMap<String, FunctionProfile>,
|
2022-03-02 18:14:48 +01:00
|
|
|
functions: Vec<TokenStreamWrapper>,
|
2022-02-28 23:19:21 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 19:13:31 +01:00
|
|
|
impl TraitProfile{
|
|
|
|
pub fn new(streams: Vec<TokenStream>) -> Self {
|
|
|
|
let mut inner = vec!();
|
|
|
|
|
|
|
|
for stream in streams {
|
|
|
|
inner.push(TokenStreamWrapper::new(stream));
|
|
|
|
}
|
|
|
|
|
|
|
|
Self{
|
|
|
|
functions: inner
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 23:19:21 +01:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
enum DeduplicatedFunctionProfile {
|
2022-03-02 18:14:48 +01:00
|
|
|
Single(String, TokenStreamWrapper),
|
|
|
|
Multiple(Vec<String>, TokenStreamWrapper),
|
2022-02-28 23:19:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*impl<T> Evaluator<T> {
|
|
|
|
fn deduplicate_functions(&self) -> Self<T> {
|
|
|
|
let mut self = self.clone();
|
|
|
|
let mut functions: HashMap<String, DeduplicatedFunctionProfile>;
|
|
|
|
|
|
|
|
for (t_name, t_profile) in self.traits {
|
|
|
|
for (fun_name, fun_profile) in t_profile.functions {
|
|
|
|
if !functions.contains_key(fun_name) {
|
|
|
|
self.functions.insert(fun_name, DeduplicatedFunctionProfile::Single(t_name, fun_profile))
|
|
|
|
} else {
|
|
|
|
let other = self.functions.remove(fun_name).unwrap();
|
|
|
|
|
|
|
|
let traits: Vec<String>;
|
|
|
|
match other {
|
|
|
|
DeduplicatedFunctionProfile::Single(t, _) => traits = vec!(t),
|
|
|
|
DeduplicatedFunctionProfile::Multiple(ts, _) => traits = ts,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.functions.insert(fun_name, DeduplicatedFunctionProfile::Multiple(traits, fun_profile))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn it_works() {
|
|
|
|
let result = 2 + 2;
|
|
|
|
assert_eq!(result, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|