1use super::set_attrs;
2#[cfg(rapx_ge_99)]
3use rustc_ast::MutRestriction;
4#[cfg(rapx_ge_99)]
5use rustc_ast::RestrictionKind;
6use rustc_ast::*;
7use rustc_span::{
8 DUMMY_SP,
9 symbol::{Ident, Symbol},
10};
11use thin_vec::ThinVec;
12
13pub(crate) fn create_ssa_struct(_krate: &mut Crate, build_std: bool) {
14 rap_debug!("[CALLBACK] Injecting new structs into the AST...");
15
16 let ssa_struct = create_struct(
17 "SSAstmt",
18 vec![
19 ("para1", Symbol::intern("i128")),
20 ("para2", Symbol::intern("i128")),
21 ("para3", Symbol::intern("i128")),
22 ("para4", Symbol::intern("i128")),
23 ("para5", Symbol::intern("i128")),
24 ("para6", Symbol::intern("i128")),
25 ("para7", Symbol::intern("i128")),
26 ("para8", Symbol::intern("i128")),
27 ("para9", Symbol::intern("i128")),
28 ("para10", Symbol::intern("i128")),
29 ],
30 build_std,
31 );
32
33 let essa_struct = create_struct(
34 "ESSAstmt",
35 vec![
36 ("op1", Symbol::intern("i128")),
37 ("op2", Symbol::intern("i128")),
38 ("cmp", Symbol::intern("i128")),
39 ("switch_bb", Symbol::intern("i128")),
40 ],
41 build_std,
42 );
43
44 _krate.items.push(ssa_struct);
45 _krate.items.push(essa_struct);
46
47 }
49pub(crate) fn create_struct(
50 name: &str,
51 fields_def: Vec<(&str, Symbol)>,
52 build_std: bool,
53) -> Box<Item> {
54 let fields: ThinVec<FieldDef> = fields_def
55 .into_iter()
56 .map(|(fname, fty)| {
57 #[cfg(rapx_has_fielddef_extras)]
58 {
59 FieldDef {
60 attrs: set_attrs(build_std),
61 vis: Visibility {
62 span: DUMMY_SP,
63 kind: VisibilityKind::Public,
64 },
65 extras: Some(Box::new(FieldDefExtras {
66 safety: Safety::Default,
67 mut_restriction: MutRestriction {
68 kind: RestrictionKind::Unrestricted,
69 span: DUMMY_SP,
70 },
71 default: None,
72 })),
73 ident: Some(Ident::from_str(fname)),
74 ty: Box::new(Ty {
75 id: NodeId::from_u32(0),
76 kind: TyKind::Path(None, Path::from_ident(Ident::with_dummy_span(fty))),
77 span: DUMMY_SP,
78 }),
79 id: NodeId::from_u32(0),
80 span: DUMMY_SP,
81 is_placeholder: false,
82 }
83 }
84 #[cfg(not(rapx_has_fielddef_extras))]
85 {
86 FieldDef {
87 attrs: set_attrs(build_std),
88 vis: Visibility {
89 span: DUMMY_SP,
90 kind: VisibilityKind::Public,
91 #[cfg(not(rapx_ge_99))]
92 tokens: None,
93 },
94 #[cfg(rapx_ge_99)]
95 mut_restriction: MutRestriction {
96 kind: RestrictionKind::Unrestricted,
97 span: DUMMY_SP,
98 },
99 ident: Some(Ident::from_str(fname)),
100 ty: Box::new(Ty {
101 id: NodeId::from_u32(0),
102 kind: TyKind::Path(None, Path::from_ident(Ident::with_dummy_span(fty))),
103 span: DUMMY_SP,
104 #[cfg(not(rapx_ge_99))]
105 tokens: None,
106 }),
107 id: NodeId::from_u32(0),
108 span: DUMMY_SP,
109 is_placeholder: false,
110 safety: Safety::Default,
111 default: None,
112 }
113 }
114 })
115 .collect();
116
117 let ident = Ident {
118 name: Symbol::intern(name),
119 span: DUMMY_SP,
120 };
121 let variant_data = VariantData::Struct {
122 fields,
123 recovered: Recovered::No,
124 };
125
126 let item_kind = ItemKind::Struct(ident, Generics::default(), variant_data);
127
128 Box::new(Item {
129 attrs: set_attrs(build_std),
130 id: NodeId::from_u32(0),
131 kind: item_kind,
132 vis: Visibility {
133 span: DUMMY_SP,
134 kind: VisibilityKind::Public,
135 #[cfg(not(rapx_ge_99))]
136 tokens: None,
137 },
138 span: DUMMY_SP,
139 tokens: None,
140 })
141}