use serde::{Deserialize, Serialize};
use super::{
Expression, IdentifierPath, NodeID, ParameterList, StateMutability, TypeDescriptions,
Visibility,
};
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(tag = "nodeType")]
pub enum TypeName {
ElementaryTypeName(ElementaryTypeName),
UserDefinedTypeName(UserDefinedTypeName),
FunctionTypeName(FunctionTypeName),
Mapping(Mapping),
ArrayTypeName(ArrayTypeName),
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ElementaryTypeName {
pub id: NodeID,
pub src: String,
pub name: String,
#[serde(default)]
pub state_mutability: Option<StateMutability>,
#[serde(default)]
pub type_descriptions: TypeDescriptions,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UserDefinedTypeName {
pub id: NodeID,
pub src: String,
#[serde(default)]
pub path_node: Option<IdentifierPath>,
pub referenced_declaration: Option<NodeID>,
#[serde(default)]
pub type_descriptions: TypeDescriptions,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct FunctionTypeName {
pub id: NodeID,
pub src: String,
pub visibility: Visibility,
pub state_mutability: StateMutability,
pub parameter_types: ParameterList,
pub return_parameter_types: ParameterList,
#[serde(default)]
pub type_descriptions: TypeDescriptions,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Mapping {
pub id: NodeID,
pub src: String,
pub key_type: Box<TypeName>,
#[serde(default)]
pub key_name: Option<String>,
#[serde(default)]
pub key_name_location: Option<String>,
pub value_type: Box<TypeName>,
#[serde(default)]
pub value_name: Option<String>,
#[serde(default)]
pub value_name_location: Option<String>,
#[serde(default)]
pub type_descriptions: TypeDescriptions,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ArrayTypeName {
pub id: NodeID,
pub src: String,
pub base_type: Box<TypeName>,
#[serde(default)]
pub length: Option<Expression>,
#[serde(default)]
pub type_descriptions: TypeDescriptions,
}