use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PropertyType {
Int,
Bool,
String,
Var,
Double,
Real,
Url,
Color,
List,
Custom(String),
}
impl PropertyType {
pub fn from_token(s: &str) -> Self {
match s {
"int" => Self::Int,
"bool" => Self::Bool,
"string" => Self::String,
"var" => Self::Var,
"double" => Self::Double,
"real" => Self::Real,
"url" => Self::Url,
"color" => Self::Color,
"list" => Self::List,
other => Self::Custom(other.to_string()),
}
}
}
impl std::str::FromStr for PropertyType {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::from_token(s))
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PropertyValue {
Int(i64),
Bool(bool),
String(String),
Double(f64),
Null,
TooComplex,
Unset,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Property {
pub name: String,
pub prop_type: PropertyType,
pub value: PropertyValue,
pub accessed_properties: Vec<String>,
#[serde(skip, default)]
pub is_simple_ref: bool,
#[serde(skip)]
pub line: usize,
}
impl PartialEq for Property {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
&& self.prop_type == other.prop_type
&& self.value == other.value
&& self.accessed_properties == other.accessed_properties
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionUsedName {
pub name: String,
pub accessed_item: Option<String>,
#[serde(skip, default)]
pub line: usize,
}
impl PartialEq for FunctionUsedName {
fn eq(&self, other: &Self) -> bool {
self.name == other.name && self.accessed_item == other.accessed_item
}
}
impl Eq for FunctionUsedName {}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MemberAssignment {
pub object: String,
pub member: String,
pub value: PropertyValue,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Function {
pub name: String,
pub is_signal_handler: bool,
pub parameters: Vec<String>,
pub used_names: Vec<FunctionUsedName>,
#[serde(default)]
pub declared_locals: Vec<String>,
#[serde(default)]
pub member_assignments: Vec<MemberAssignment>,
#[serde(skip)]
pub line: usize,
}
impl PartialEq for Function {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
&& self.is_signal_handler == other.is_signal_handler
&& self.parameters == other.parameters
&& self.used_names == other.used_names
&& self.declared_locals == other.declared_locals
&& self.member_assignments == other.member_assignments
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QmlChild {
pub type_name: String,
pub id: Option<String>,
pub properties: Vec<Property>,
pub functions: Vec<Function>,
pub children: Vec<Self>,
#[serde(skip)]
pub assignments: Vec<(String, String, usize)>,
#[serde(skip)]
pub line: usize,
}
impl PartialEq for QmlChild {
fn eq(&self, other: &Self) -> bool {
self.type_name == other.type_name
&& self.id == other.id
&& self.properties == other.properties
&& self.functions == other.functions
&& self.children == other.children
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FileItem {
pub name: String,
pub base_type: String,
pub id: Option<String>,
pub imports: Vec<String>,
pub signals: Vec<Signal>,
pub properties: Vec<Property>,
pub functions: Vec<Function>,
pub children: Vec<QmlChild>,
#[serde(skip)]
pub assignments: Vec<(String, String, usize)>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Signal {
pub name: String,
pub parameters: Vec<SignalParameter>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SignalParameter {
pub param_type: String,
pub param_name: String,
}