charon_lib/ast/items/
fun_decl.rs1use crate::ast::*;
2use derive_generic_visitor::{Drive, DriveMut, DriveTwo};
3use macros::EnumIsA;
4use macros::VariantName;
5use serde_state::DeserializeState;
6use serde_state::SerializeState;
7
8#[derive(Debug, Clone, SerializeState, DeserializeState, Drive, DriveMut, DriveTwo)]
10pub struct FunDecl {
11 pub def_id: FunDeclId,
12 pub item_meta: ItemMeta,
14 pub generics: GenericParams,
15 pub signature: Box<FunSig>,
17 pub src: FunSource,
19 pub body: Body,
21}
22
23#[derive(
25 Debug,
26 Clone,
27 PartialEq,
28 Eq,
29 PartialOrd,
30 Ord,
31 Hash,
32 SerializeState,
33 DeserializeState,
34 Drive,
35 DriveMut,
36 DriveTwo,
37)]
38pub struct FunSig {
39 pub is_unsafe: bool,
41 pub abi: Abi,
43 pub is_variadic: bool,
45 pub inputs: Vec<Ty>,
46 pub output: Ty,
47}
48
49#[derive(
50 Debug,
51 Clone,
52 PartialEq,
53 Eq,
54 PartialOrd,
55 Ord,
56 Hash,
57 VariantName,
58 EnumIsA,
59 SerializeState,
60 DeserializeState,
61 Drive,
62 DriveMut,
63 DriveTwo,
64)]
65#[serde_state(stateless)]
66#[cfg_attr(feature = "charon_on_charon", charon::variants_prefix("Abi"))]
67pub enum Abi {
68 Rust,
69 C,
70 Other(ustr::Ustr),
72}
73
74#[derive(Debug, Clone, SerializeState, DeserializeState, Drive, DriveMut, DriveTwo)]
76#[cfg_attr(feature = "charon_on_charon", charon::variants_suffix("Fun"))]
77pub enum FunSource {
78 Normal,
80 AdtConstructor,
82 TraitDefault {
84 trait_ref: TraitDeclRef,
86 item_id: TraitMethodId,
89 },
90 TraitImpl {
92 impl_ref: TraitImplRef,
94 trait_ref: TraitDeclRef,
96 item_id: TraitMethodId,
99 reuses_default: bool,
102 },
103 VTableShim,
107 GlobalInitializer(GlobalDeclRef),
109 TargetDependent { dispatcher: FunDeclRef },
112}
113
114impl FunDecl {
115 pub fn substitute_params(self, subst: Binder<GenericArgs>) -> Self {
117 let FunDecl {
118 def_id,
119 item_meta,
120 generics: _,
121 signature,
122 src,
123 body,
124 } = self;
125 let signature = signature.substitute(&subst.skip_binder);
126 let src = src.substitute(&subst.skip_binder);
127 let body = body.substitute(&subst.skip_binder);
128 FunDecl {
129 def_id,
130 item_meta,
131 generics: subst.params,
132 signature,
133 src,
134 body,
135 }
136 }
137}
138
139impl Abi {
140 pub fn rust() -> Self {
141 Self::Rust
142 }
143
144 pub fn rust_name(&self) -> &str {
145 match self {
146 Self::Rust => "Rust",
147 Self::C => "C",
148 Self::Other(name) => name.as_str(),
149 }
150 }
151}