ethers_solc/artifacts/ast/
yul.rs1use super::{macros::node_group, misc::SourceLocation};
2use crate::artifacts::serde_helpers;
3use serde::{Deserialize, Serialize};
4
5node_group! {
6 YulStatement;
7
8 YulAssignment,
9 YulBlock,
10 YulBreak,
11 YulContinue,
12 YulExpressionStatement,
13 YulLeave,
14 YulForLoop,
15 YulFunctionDefinition,
16 YulIf,
17 YulSwitch,
18 YulVariableDeclaration,
19}
20
21node_group! {
22 YulExpression;
23
24 YulFunctionCall,
25 YulIdentifier,
26 YulLiteral,
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
31pub struct YulBlock {
32 #[serde(with = "serde_helpers::display_from_str")]
33 pub src: SourceLocation,
34 pub statements: Vec<YulStatement>,
35}
36
37#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
39#[serde(rename_all = "camelCase")]
40pub struct YulAssignment {
41 #[serde(with = "serde_helpers::display_from_str")]
42 pub src: SourceLocation,
43 pub value: YulExpression,
44 pub variable_names: Vec<YulIdentifier>,
45}
46
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
49#[serde(rename_all = "camelCase")]
50pub struct YulFunctionCall {
51 #[serde(with = "serde_helpers::display_from_str")]
52 pub src: SourceLocation,
53 pub arguments: Vec<YulExpression>,
54 pub function_name: YulIdentifier,
55}
56
57#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
59pub struct YulIdentifier {
60 #[serde(with = "serde_helpers::display_from_str")]
61 pub src: SourceLocation,
62 pub name: String,
63}
64
65#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
67#[serde(rename_all = "camelCase")]
68pub struct YulLiteral {
69 #[serde(with = "serde_helpers::display_from_str")]
70 pub src: SourceLocation,
71 pub hex_value: Option<String>, pub value: Option<String>, pub kind: YulLiteralKind,
74 pub type_name: Option<String>, }
76
77#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
79#[serde(rename_all = "camelCase")]
80pub enum YulLiteralKind {
81 Number,
83 String,
85 Bool,
87}
88
89#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
91pub struct YulKeyword {
92 #[serde(with = "serde_helpers::display_from_str")]
93 pub src: SourceLocation,
94}
95
96pub type YulBreak = YulKeyword;
98pub type YulContinue = YulKeyword;
100pub type YulLeave = YulKeyword;
102
103#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
105pub struct YulExpressionStatement {
106 #[serde(with = "serde_helpers::display_from_str")]
107 pub src: SourceLocation,
108 pub expression: YulExpression,
109}
110
111#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
113pub struct YulForLoop {
114 #[serde(with = "serde_helpers::display_from_str")]
115 pub src: SourceLocation,
116 pub body: YulBlock,
117 pub condition: YulExpression,
118 pub post: YulBlock,
119 pub pre: YulBlock,
120}
121
122#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
124#[serde(rename_all = "camelCase")]
125pub struct YulFunctionDefinition {
126 #[serde(with = "serde_helpers::display_from_str")]
127 pub src: SourceLocation,
128 pub body: YulBlock,
129 pub name: String,
130 #[serde(default)]
131 pub parameters: Vec<YulTypedName>,
132 #[serde(default)]
133 pub return_variables: Vec<YulTypedName>,
134}
135
136#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
138#[serde(rename_all = "camelCase")]
139pub struct YulTypedName {
140 #[serde(with = "serde_helpers::display_from_str")]
141 pub src: SourceLocation,
142 pub name: String,
143 #[serde(rename = "type")]
144 pub type_name: String, }
146
147#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
149pub struct YulIf {
150 #[serde(with = "serde_helpers::display_from_str")]
151 pub src: SourceLocation,
152 pub body: YulBlock,
153 pub condition: YulExpression,
154}
155
156#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
158pub struct YulSwitch {
159 #[serde(with = "serde_helpers::display_from_str")]
160 pub src: SourceLocation,
161 pub cases: Vec<YulCase>,
162 pub expression: YulExpression,
163}
164
165#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
167pub struct YulCase {
168 #[serde(with = "serde_helpers::display_from_str")]
169 pub src: SourceLocation,
170 pub body: YulBlock,
171 pub value: YulCaseValue,
172}
173
174#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
176#[serde(untagged)]
177pub enum YulCaseValue {
178 YulLiteral(YulLiteral),
180 Default(String),
183}
184
185#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
187pub struct YulVariableDeclaration {
188 #[serde(with = "serde_helpers::display_from_str")]
189 pub src: SourceLocation,
190 pub value: Option<YulExpression>,
191 pub variables: Vec<YulTypedName>,
192}