1#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct ParamInfo {
9 pub name: Option<String>,
11 pub ty: String,
13}
14
15#[derive(Clone, Debug, PartialEq, Eq)]
17pub struct BaseInfo {
18 pub name: String,
20 pub ident: String,
22}
23
24#[derive(Clone, Debug, PartialEq, Eq)]
26pub enum ContractKind {
27 Contract,
28 Abstract,
29 Interface,
30 Library,
31}
32
33impl ContractKind {
34 pub const fn as_str(&self) -> &'static str {
36 match self {
37 Self::Contract => "contract",
38 Self::Abstract => "abstract",
39 Self::Interface => "interface",
40 Self::Library => "library",
41 }
42 }
43}
44
45#[derive(Clone, Debug, PartialEq, Eq)]
47pub struct ContractSource {
48 pub name: String,
49 pub kind: ContractKind,
50 pub bases: Vec<BaseInfo>,
51}
52
53#[derive(Clone, Debug, PartialEq, Eq)]
55pub struct FunctionSource {
56 pub name: Option<String>,
58 pub kind: String,
60 pub params: Vec<ParamInfo>,
62 pub returns: Vec<ParamInfo>,
64}
65
66impl FunctionSource {
67 pub fn signature(&self) -> String {
69 let name = self.name.as_deref().unwrap_or(&self.kind);
70 if self.params.is_empty() {
71 return name.to_string();
72 }
73 format!(
74 "{}({})",
75 name,
76 self.params.iter().map(|p| p.ty.as_str()).collect::<Vec<_>>().join(",")
77 )
78 }
79}
80
81#[derive(Clone, Debug, PartialEq, Eq)]
83pub enum VariableAttr {
84 Constant,
85 Immutable,
86}
87
88#[derive(Clone, Debug, PartialEq, Eq)]
90pub struct VariableSource {
91 pub name: String,
92 pub attrs: Vec<VariableAttr>,
93}
94
95#[derive(Clone, Debug, PartialEq, Eq)]
97pub struct EventSource {
98 pub name: String,
99 pub fields: Vec<ParamInfo>,
100}
101
102#[derive(Clone, Debug, PartialEq, Eq)]
104pub struct ErrorSource {
105 pub name: String,
106 pub fields: Vec<ParamInfo>,
107}
108
109#[derive(Clone, Debug, PartialEq, Eq)]
111pub struct StructSource {
112 pub name: String,
113 pub fields: Vec<ParamInfo>,
114}
115
116#[derive(Clone, Debug, PartialEq, Eq)]
118pub struct EnumSource {
119 pub name: String,
120 pub variants: Vec<String>,
121}
122
123#[derive(Clone, Debug, PartialEq, Eq)]
125pub struct TypeSource {
126 pub name: String,
127}
128
129#[derive(Clone, Debug, PartialEq, Eq)]
131pub enum ParseSource {
132 Contract(ContractSource),
134 Function(FunctionSource),
136 Variable(VariableSource),
138 Event(EventSource),
140 Error(ErrorSource),
142 Struct(StructSource),
144 Enum(EnumSource),
146 Type(TypeSource),
148}
149
150impl ParseSource {
151 pub fn ident(&self) -> String {
153 match self {
154 Self::Contract(c) => c.name.clone(),
155 Self::Variable(v) => v.name.clone(),
156 Self::Event(e) => e.name.clone(),
157 Self::Error(e) => e.name.clone(),
158 Self::Struct(s) => s.name.clone(),
159 Self::Enum(e) => e.name.clone(),
160 Self::Function(f) => f.name.clone().unwrap_or_else(|| f.kind.clone()),
161 Self::Type(t) => t.name.clone(),
162 }
163 }
164
165 pub fn signature(&self) -> String {
167 match self {
168 Self::Function(f) => f.signature(),
169 _ => self.ident(),
170 }
171 }
172}