use super::{macros::node_group, misc::SourceLocation};
use crate::artifacts::serde_helpers;
use serde::{Deserialize, Serialize};
node_group! {
YulStatement;
YulAssignment,
YulBlock,
YulBreak,
YulContinue,
YulExpressionStatement,
YulLeave,
YulForLoop,
YulFunctionDefinition,
YulIf,
YulSwitch,
YulVariableDeclaration,
}
node_group! {
YulExpression;
YulFunctionCall,
YulIdentifier,
YulLiteral,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct YulBlock {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub statements: Vec<YulStatement>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct YulAssignment {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub value: YulExpression,
pub variable_names: Vec<YulIdentifier>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct YulFunctionCall {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub arguments: Vec<YulExpression>,
pub function_name: YulIdentifier,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct YulIdentifier {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub name: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct YulLiteral {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub hex_value: Option<String>, pub value: Option<String>, pub kind: YulLiteralKind,
pub type_name: Option<String>, }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum YulLiteralKind {
Number,
String,
Bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct YulKeyword {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
}
pub type YulBreak = YulKeyword;
pub type YulContinue = YulKeyword;
pub type YulLeave = YulKeyword;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct YulExpressionStatement {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub expression: YulExpression,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct YulForLoop {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub body: YulBlock,
pub condition: YulExpression,
pub post: YulBlock,
pub pre: YulBlock,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct YulFunctionDefinition {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub body: YulBlock,
pub name: String,
#[serde(default)]
pub parameters: Vec<YulTypedName>,
#[serde(default)]
pub return_variables: Vec<YulTypedName>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct YulTypedName {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub name: String,
#[serde(rename = "type")]
pub type_name: String, }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct YulIf {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub body: YulBlock,
pub condition: YulExpression,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct YulSwitch {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub cases: Vec<YulCase>,
pub expression: YulExpression,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct YulCase {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub body: YulBlock,
pub value: YulCaseValue,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum YulCaseValue {
YulLiteral(YulLiteral),
Default(String),
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct YulVariableDeclaration {
#[serde(with = "serde_helpers::display_from_str")]
pub src: SourceLocation,
pub value: Option<YulExpression>,
pub variables: Vec<YulTypedName>,
}