1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// use std::fmt::{Display, Formatter};
// use quote::ToTokens;
// use syn::{BareFnArg, Type};
// use syn::punctuated::Punctuated;
// use crate::ast::CommaPunctuated;
// use crate::composable::TypeModel;
// use crate::composer::Composer;
// use crate::context::{ScopeContext, ScopeSearch};
// use crate::kind::{DictFermentableModelKind, DictTypeModelKind, GenericTypeKind, ObjectKind, ScopeItemKind, SmartPointerModelKind, TypeKind, TypeModelKind};
// use crate::ext::{AsType, FFISpecialTypeResolve, GenericNestedArg, Primitive, Resolve, SpecialType, ToType};
// use crate::lang::LangAttrSpecification;
// use crate::presentable::Expression;
// use crate::presentation::Name;
//
// #[allow(unused)]
// #[derive(Clone, Debug)]
// pub struct FromConversionComposer<'a, LANG, SPEC>
// where LANG: LangFermentable,
// SPEC: LangAttrSpecification<LANG>
// + Default {
// pub name: Name,
// pub search: ScopeSearch<'a>,
// pub expr: Option<Expression<LANG, SPEC>>,
// }
//
// impl<'a, LANG, SPEC> FromConversionComposer<'a, LANG, SPEC>
// where LANG: LangFermentable,
// SPEC: LangAttrSpecification<LANG>
// + Default {
// pub fn new(name: Name, search: ScopeSearch<'a>, expr: Option<Expression<LANG, SPEC>>) -> Self {
// Self { name, search , expr }
// }
// pub fn expr_less(name: Name, search: ScopeSearch<'a>) -> Self {
// Self::new(name, search, None)
// }
// }
// impl<'a, LANG, SPEC> Display for FromConversionComposer<'a, LANG, SPEC> {
// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
// f.write_str(format!("{} --- {} --- {}", self.name, self.search, self.expr.as_ref().map_or("None".to_string(), |e| format!("{}", e))).as_str())
// }
// }
//
// impl<'a> Composer<'a> for FromConversionComposer<'a> {
// type Source = ScopeContext;
// type Result = Expression;
//
// fn compose(&self, source: &'a Self::Source) -> Self::Result {
// let Self { name, search, expr } = self;
// let search_key = self.search.search_key();
// println!("FromConversionFullComposer:: {}({}) -- {} -- {:?}", name, name.to_token_stream(), search, expr);
// let field_path = expr.clone().unwrap_or(Expression::Simple(name.to_token_stream()));
// let maybe_object = source.maybe_object_by_predicate(search.clone());
// let full_type = maybe_object.as_ref().and_then(ObjectKind::maybe_type).unwrap_or(search_key.to_type());
// println!("FromConversionFullComposer::maybe_object {} ", maybe_object.as_ref().map_or("None".to_string(), |o| format!("{o}")));
// let composition = maybe_object.as_ref()
// .and_then(|external_type| {
// match external_type {
// ObjectKind::Item(.., ScopeItemKind::Fn(..)) => {
// source.scope
// .parent_object()
// .and_then(|parent_obj| parent_obj.maybe_trait_or_regular_model_kind(source))
// },
// ObjectKind::Type(ref ty_conversion) |
// ObjectKind::Item(ref ty_conversion, ..) =>
// ty_conversion.maybe_trait_model_kind_or_same(source),
// ObjectKind::Empty => {
// // println!("Type::<TypeModelKind> Has no object --> {}", external_type.type_conversion().to_token_stream());
// None
// }
// }
// })
// .unwrap_or_else(|| {
// // println!("Type::<TypeModelKind> Default Unknown --> {}", self.to_token_stream());
// TypeModelKind::Unknown(TypeModel::new(search_key.to_type(), None, Punctuated::new()))
// });
//
//
//
// let expression = match full_type.maybe_special_type(source) {
// Some(SpecialType::Opaque(..)) => {
// println!("FromConversionFullComposer:: Opaque: {}({})", search_key, full_type.to_token_stream());
// match composition {
// TypeModelKind::FnPointer(..) |
// TypeModelKind::Dictionary(DictTypeModelKind::LambdaFn(..)) => field_path,
// TypeModelKind::Bounds(bounds) => {
// if bounds.bounds.is_empty() {
// field_path
// } else if bounds.is_lambda() {
// if let Some(lambda_args) = bounds.bounds.first().unwrap().maybe_lambda_args() {
// Expression::FromLambda(field_path.into(), lambda_args)
// } else {
// Expression::From(field_path.into())
// }
// } else {
// Expression::From(field_path.into())
// }
// },
// _ => {
// println!("FromConversionFullComposer: FROMPTRCLONE ({}): {}", search_key.maybe_originally_is_const_ptr(), search_key);
// if search_key.maybe_originally_is_const_ptr() {
// field_path
// } else if search_key.maybe_originally_is_mut_ptr() {
// field_path
// } else {
// Expression::FromPtrClone(field_path.into())
// }
// }
// }
// },
// Some(SpecialType::Custom(..)) =>
// Expression::From(field_path.into()),
// None => {
// println!("FromConversionFullComposer (Non Special): {} ({})", search_key, full_type.to_token_stream());
// match composition {
// TypeModelKind::Dictionary(DictTypeModelKind::LambdaFn(..)) =>
// field_path,
// TypeModelKind::FnPointer(..) => {
// println!("FromConversionFullComposer (Non Special FnPointer): {} --- {}", search_key, maybe_object.to_token_stream());
// if let Some(bare) = source.maybe_fn_sig(&full_type) {
// let lambda_args = CommaPunctuated::from_iter(bare.inputs.iter().enumerate().map(|(index, BareFnArg { name, ..})| match name {
// Some((ident, ..)) => Name::Ident(ident.clone()),
// None => Name::UnnamedArg(index)
// }));
// Expression::FromLambda(field_path.into(), lambda_args)
// } else {
// field_path
// }
// },
// TypeModelKind::Optional(ty) => if ty.as_type().first_nested_type().unwrap().is_primitive() {
// Expression::FromOptPrimitive(field_path.into())
// } else {
// Expression::FromOpt(field_path.into())
// }
// TypeModelKind::Dictionary(DictTypeModelKind::NonPrimitiveFermentable(DictFermentableModelKind::SmartPointer(SmartPointerModelKind::Box(TypeModel { ty: ref full_ty, .. })))) => {
// let full_nested_ty = full_ty.first_nested_type().unwrap();
// // println!("FromConversionComposer (Non Special Boxed): {} ({}) --- {} ---- {}", nested_ty.to_token_stream(), full_nested_ty.to_token_stream(), Resolve::<Option<SpecialType>>::resolve(full_nested_ty, source).to_token_stream(), nested_ty.maybe_object(source).to_token_stream());
// match (Resolve<Option<SpecialType>>::resolve(full_nested_ty, source),
// source.maybe_object_by_value(full_nested_ty)) {
// (Some(SpecialType::Opaque(..)),
// Some(ObjectKind::Item(TypeModelKind::FnPointer(..) | TypeModelKind::Dictionary(DictTypeModelKind::LambdaFn(..)), ..) |
// ObjectKind::Type(TypeModelKind::FnPointer(..) | TypeModelKind::Dictionary(DictTypeModelKind::LambdaFn(..))))
// ) =>
// Expression::IntoBox(field_path.into()),
// (Some(SpecialType::Opaque(..)), _any_other) =>
// Expression::FromRawBox(field_path.into()),
// (Some(SpecialType::Custom(..)), _any) =>
// Expression::IntoBox(Expression::From(field_path.into()).into()),
// (_, Some(obj)) => {
// println!("FromConversionFullComposer (Non Special Boxed Lambda): {}", obj);
// Expression::IntoBox(match obj.maybe_lambda_args() {
// Some(lambda_args) =>
// Expression::FromLambda(field_path.into(), lambda_args),
// None =>
// Expression::From(field_path.into())
// }.into())
// }
// _ =>
// Expression::IntoBox(Expression::From(field_path.into()).into())
// }
// },
// TypeModelKind::Bounds(bounds) => {
// println!("FromConversionFullComposer (Bounds): {}", bounds);
// if bounds.bounds.is_empty() {
// field_path
// } else if bounds.is_lambda() {
// if let Some(lambda_args) = bounds.bounds.first().unwrap().maybe_lambda_args() {
// Expression::FromLambda(field_path.into(), lambda_args)
// } else {
// Expression::From(field_path.into())
// }
// } else {
// Expression::From(field_path.into())
// }
// },
// TypeModelKind::Unknown(..) => {
// println!("FromConversionFullComposer (Unknown): {}", search_key);
//
// match TypeKind::from(search_key.to_type()) {
// TypeKind::Primitive(_) =>
// field_path,
// TypeKind::Generic(GenericTypeKind::Optional(ty)) => match TypeKind::from(ty.first_nested_type().unwrap()) {
// TypeKind::Primitive(_) => Expression::FromOptPrimitive(field_path.into()),
// _ => Expression::FromOpt(field_path.into()),
// }
// TypeKind::Generic(..) =>
// Expression::From(field_path.into()),
// _ =>
// field_path,
// }
// },
// _ => {
// println!("FromConversionFullComposer (Regular): {}", composition);
// match TypeKind::from(search_key.to_type()) {
// TypeKind::Primitive(_) =>
// field_path,
// TypeKind::Generic(GenericTypeKind::Optional(ty)) => match TypeKind::from(ty.first_nested_type().unwrap()) {
// TypeKind::Primitive(_) => Expression::FromOptPrimitive(field_path.into()),
// _ => Expression::FromOpt(field_path.into()),
// }
// _ =>
// Expression::From(field_path.into())
// }
// }
// }
// }
// };
// expression
// }
// }