neo_solidity/frontend/frontend_ir.rs
1/// Natspec documentation extracted from source comments.
2#[derive(Debug, Clone, Default)]
3pub struct NatspecDocIR {
4 /// @title - Contract title
5 pub title: Option<String>,
6 /// @author - Author information
7 pub author: Option<String>,
8 /// @notice - User-facing description
9 pub notice: Option<String>,
10 /// @dev - Developer-facing notes
11 pub dev: Option<String>,
12 /// @param name description
13 pub params: Vec<(String, String)>,
14 /// @return descriptions
15 pub returns: Vec<String>,
16 /// @custom:tag value pairs
17 pub custom: Vec<(String, String)>,
18}
19
20/// Representation of a Solidity contract.
21#[derive(Debug, Clone)]
22pub struct ContractIR {
23 pub name: String,
24 pub kind: ContractKind,
25 /// Inheritance specifiers (`contract X is A, B(...) { ... }`).
26 pub bases: Vec<Base>,
27 pub functions: Vec<FunctionIR>,
28 pub events: Vec<EventIR>,
29 pub state_variables: Vec<StateVariableIR>,
30 pub structs: Vec<StructIR>,
31 pub enums: Vec<EnumIR>,
32 /// Natspec documentation for this contract
33 pub doc: NatspecDocIR,
34 /// Whether this contract contains `using X for Y` directives.
35 ///
36 /// The compiler merges library functions into the contract wholesale,
37 /// so basic `using LibName for Type` works implicitly. This flag is
38 /// set when advanced forms (`using X for *`, `using { f, g } for Y`)
39 /// are present so that diagnostics can be emitted.
40 pub has_using_for_star: bool,
41 pub has_using_function_list: bool,
42 /// Library names referenced by `using X for Y` directives.
43 ///
44 /// The compiler merges all non-builtin library functions into the contract
45 /// wholesale, so `using LibName for Type` member-call syntax (e.g. `x.add(y)`)
46 /// resolves to `LibName.add(x, y)` automatically. This list is kept for
47 /// diagnostic purposes.
48 pub using_for_libraries: Vec<String>,
49 /// Whether this contract contains `type X is Y` definitions.
50 pub has_type_definitions: bool,
51 /// User-defined value type aliases (`type X is Y`).
52 ///
53 /// Maps the user-defined type name to its underlying Solidity type string.
54 /// During type resolution, `X` is transparently replaced by `Y`.
55 /// `X.wrap(v)` and `X.unwrap(v)` compile to no-ops.
56 pub type_aliases: std::collections::HashMap<String, String>,
57 /// Mapping from original method name to the renamed super-method name.
58 ///
59 /// When inheritance flattening detects an override, the base version of the
60 /// function is preserved as `__super_{methodName}` and this map records the
61 /// relationship so that `super.method()` can be resolved during IR lowering.
62 pub super_method_map: std::collections::HashMap<String, String>,
63}
64
65/// Classification of contract kinds.
66#[derive(Debug, Clone, Copy, PartialEq, Eq)]
67pub enum ContractKind {
68 Contract,
69 AbstractContract,
70 Interface,
71 Library,
72}
73
74/// Representation of a Solidity function or constructor.
75#[derive(Debug, Clone)]
76pub struct FunctionIR {
77 pub name: String,
78 pub ty: FunctionTy,
79 pub parameters: Vec<ParameterIR>,
80 pub returns: Vec<ParameterIR>,
81 pub mutability: MutabilityKind,
82 pub visibility: VisibilityKind,
83 /// Whether this function is marked `virtual`.
84 pub is_virtual: bool,
85 /// Whether this function is marked `override`.
86 pub is_override: bool,
87 /// Modifier applications and constructor base invocations.
88 pub base_or_modifiers: Vec<Base>,
89 pub body: Option<Statement>,
90 /// Natspec documentation for this function
91 pub doc: NatspecDocIR,
92}
93
94/// Function mutability classification based on Solidity state mutability.
95#[derive(Debug, Clone, Copy, PartialEq, Eq)]
96pub enum MutabilityKind {
97 Pure,
98 View,
99 Payable,
100 NonPayable,
101}
102
103#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104pub enum VisibilityKind {
105 External,
106 Public,
107 Internal,
108 Private,
109}
110
111/// Representation of a Solidity parameter.
112#[derive(Debug, Clone)]
113pub struct ParameterIR {
114 pub name: Option<String>,
115 pub ty: String,
116 pub storage: Option<String>,
117}
118
119/// Representation of a Solidity event.
120#[derive(Debug, Clone)]
121pub struct EventIR {
122 pub name: String,
123 pub parameters: Vec<EventParameterIR>,
124}
125
126/// Representation of a Solidity event parameter.
127#[derive(Debug, Clone)]
128pub struct EventParameterIR {
129 pub name: Option<String>,
130 pub ty: String,
131 pub indexed: bool,
132}
133
134/// Representation of a state variable.
135#[derive(Debug, Clone)]
136pub struct StateVariableIR {
137 pub name: Option<String>,
138 pub ty: String,
139 pub is_constant: bool,
140 pub is_immutable: bool,
141 pub visibility: Option<String>,
142 pub has_initializer: bool,
143 pub initializer: Option<Expression>,
144}
145
146#[derive(Debug, Clone)]
147pub struct StructIR {
148 pub name: String,
149 pub fields: Vec<StructFieldIR>,
150}
151
152#[derive(Debug, Clone)]
153pub struct StructFieldIR {
154 pub name: String,
155 pub ty: String,
156}
157
158#[derive(Debug, Clone)]
159pub struct EnumIR {
160 pub name: String,
161 pub values: Vec<String>,
162}