Skip to main content

oxilean_codegen/vyper_backend/
vyperexpr_traits.rs

1//! # VyperExpr - Trait Implementations
2//!
3//! This module contains trait implementations for `VyperExpr`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::types::VyperExpr;
12use std::fmt;
13
14impl fmt::Display for VyperExpr {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            VyperExpr::IntLit(n) => write!(f, "{}", n),
18            VyperExpr::BoolLit(b) => write!(f, "{}", if *b { "True" } else { "False" }),
19            VyperExpr::StrLit(s) => write!(f, "\"{}\"", s),
20            VyperExpr::HexLit(h) => write!(f, "{}", h),
21            VyperExpr::Var(v) => write!(f, "{}", v),
22            VyperExpr::SelfField(field) => write!(f, "self.{}", field),
23            VyperExpr::MsgSender => write!(f, "msg.sender"),
24            VyperExpr::MsgValue => write!(f, "msg.value"),
25            VyperExpr::BlockTimestamp => write!(f, "block.timestamp"),
26            VyperExpr::BlockNumber => write!(f, "block.number"),
27            VyperExpr::ChainId => write!(f, "chain.id"),
28            VyperExpr::TxOrigin => write!(f, "tx.origin"),
29            VyperExpr::Len(expr) => write!(f, "len({})", expr),
30            VyperExpr::Convert(expr, ty) => write!(f, "convert({}, {})", expr, ty),
31            VyperExpr::Concat(args) => {
32                let strs: Vec<String> = args.iter().map(|a| a.to_string()).collect();
33                write!(f, "concat({})", strs.join(", "))
34            }
35            VyperExpr::Keccak256(expr) => write!(f, "keccak256({})", expr),
36            VyperExpr::Sha256(expr) => write!(f, "sha256({})", expr),
37            VyperExpr::Ecrecover(h, v, r, s) => {
38                write!(f, "ecrecover({}, {}, {}, {})", h, v, r, s)
39            }
40            VyperExpr::Extract32(expr, start) => {
41                write!(f, "extract32({}, {})", expr, start)
42            }
43            VyperExpr::FieldAccess(expr, field) => write!(f, "{}.{}", expr, field),
44            VyperExpr::Index(expr, idx) => write!(f, "{}[{}]", expr, idx),
45            VyperExpr::Call(name, args) => {
46                let strs: Vec<String> = args.iter().map(|a| a.to_string()).collect();
47                write!(f, "{}({})", name, strs.join(", "))
48            }
49            VyperExpr::ExtCall(iface, addr, method, args) => {
50                let strs: Vec<String> = args.iter().map(|a| a.to_string()).collect();
51                write!(f, "{}({}).{}({})", iface, addr, method, strs.join(", "))
52            }
53            VyperExpr::BinOp(op, lhs, rhs) => write!(f, "({} {} {})", lhs, op, rhs),
54            VyperExpr::UnaryOp(op, expr) => {
55                if op == "not" {
56                    write!(f, "not {}", expr)
57                } else {
58                    write!(f, "{}{}", op, expr)
59                }
60            }
61            VyperExpr::IfExpr(val, cond, default) => {
62                write!(f, "{} if {} else {}", val, cond, default)
63            }
64            VyperExpr::StructLit(name, fields) => {
65                let field_strs: Vec<String> = fields
66                    .iter()
67                    .map(|(k, v)| format!("{}: {}", k, v))
68                    .collect();
69                write!(f, "{}({{{}}})", name, field_strs.join(", "))
70            }
71            VyperExpr::ListLit(elems) => {
72                let strs: Vec<String> = elems.iter().map(|e| e.to_string()).collect();
73                write!(f, "[{}]", strs.join(", "))
74            }
75            VyperExpr::Empty(ty) => write!(f, "empty({})", ty),
76            VyperExpr::MaxValue(ty) => write!(f, "max_value({})", ty),
77            VyperExpr::MinValue(ty) => write!(f, "min_value({})", ty),
78            VyperExpr::Isqrt(expr) => write!(f, "isqrt({})", expr),
79            VyperExpr::Uint2Str(expr) => write!(f, "uint2str({})", expr),
80            VyperExpr::RawCall {
81                addr,
82                data,
83                value,
84                gas,
85            } => {
86                write!(f, "raw_call({}, {}", addr, data)?;
87                if let Some(v) = value {
88                    write!(f, ", value={}", v)?;
89                }
90                if let Some(g) = gas {
91                    write!(f, ", gas={}", g)?;
92                }
93                write!(f, ")")
94            }
95            VyperExpr::CreateMinimalProxy(target) => {
96                write!(f, "create_minimal_proxy_to({})", target)
97            }
98            VyperExpr::CreateCopyOf(target) => write!(f, "create_copy_of({})", target),
99            VyperExpr::CreateFromBlueprint(bp, args) => {
100                let strs: Vec<String> = args.iter().map(|a| a.to_string()).collect();
101                if strs.is_empty() {
102                    write!(f, "create_from_blueprint({})", bp)
103                } else {
104                    write!(f, "create_from_blueprint({}, {})", bp, strs.join(", "))
105                }
106            }
107        }
108    }
109}