use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use super::cg::{FileChunk, FileLocation};
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct StateVariable {
pub id: i32,
pub name: String,
pub type_name: String,
pub relative_file_path: std::path::PathBuf,
pub loc: FileLocation,
pub content: String,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct ContractVariable {
pub contract_id: i32,
pub state_variable_id: i32,
pub description: Option<String>,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct FunctionStateVariable {
pub function_id: i32,
pub state_variable_id: i32,
pub is_write: bool,
pub description: Option<String>,
}
#[derive(Deserialize, Serialize, Clone, Debug, Default)]
pub struct StorageGraph {
pub state_variables: BTreeMap<i32, StateVariable>,
pub contract_variables: Vec<ContractVariable>,
pub function_state_variables: Vec<FunctionStateVariable>,
}
#[derive(Debug, Clone, Default)]
pub struct StorageDotOptions {
pub include_isolated_state_variables: bool,
}
pub(crate) fn dot_escape(s: &str) -> String {
s.replace('\\', "\\\\").replace('"', "\\\"")
}
pub fn make_state_variable(
id: i32,
name: String,
type_name: String,
relative_file_path: std::path::PathBuf,
chunk: FileChunk,
) -> StateVariable {
StateVariable {
id,
name,
type_name,
relative_file_path,
loc: chunk.loc,
content: chunk.content,
}
}