mago_codex/ttype/
shared.rs1use std::sync::Arc;
7use std::sync::LazyLock;
8
9use mago_atom::empty_atom;
10
11use crate::ttype::atomic::TAtomic;
12use crate::ttype::atomic::array::TArray;
13use crate::ttype::atomic::array::keyed::TKeyedArray;
14use crate::ttype::atomic::callable::TCallable;
15use crate::ttype::atomic::callable::TCallableSignature;
16use crate::ttype::atomic::iterable::TIterable;
17use crate::ttype::atomic::mixed::TMixed;
18use crate::ttype::atomic::object::TObject;
19use crate::ttype::atomic::resource::TResource;
20use crate::ttype::atomic::scalar::TScalar;
21use crate::ttype::atomic::scalar::int::TInteger;
22use crate::ttype::atomic::scalar::string::TString;
23use crate::ttype::atomic::scalar::string::TStringLiteral;
24use crate::ttype::get_arraykey;
25use crate::ttype::get_mixed;
26
27use super::atomic::scalar::string::TStringCasing;
28
29pub const ONE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::literal_int(1));
31pub const ZERO_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::literal_int(0));
33pub const MINUS_ONE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::literal_int(-1));
35pub const INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::int());
37pub const POSITIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::positive()));
39pub const NON_POSITIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::non_positive()));
41pub const NEGATIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::negative()));
43pub const NON_NEGATIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::non_negative()));
45pub const UNSPECIFIED_LITERAL_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::UnspecifiedLiteral));
47pub const STRING_ATOMIC: &TAtomic =
49 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, false, TStringCasing::Unspecified)));
50pub const LOWERCASE_STRING_ATOMIC: &TAtomic =
52 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, false, TStringCasing::Lowercase)));
53pub const UPPERCASE_STRING_ATOMIC: &TAtomic =
55 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, false, TStringCasing::Uppercase)));
56pub const NON_EMPTY_STRING_ATOMIC: &TAtomic =
58 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, false, TStringCasing::Unspecified)));
59pub const NON_EMPTY_LOWERCASE_STRING_ATOMIC: &TAtomic =
61 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, false, TStringCasing::Lowercase)));
62pub const NON_EMPTY_UPPERCASE_STRING_ATOMIC: &TAtomic =
64 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, false, TStringCasing::Uppercase)));
65pub const TRUTHY_STRING_ATOMIC: &TAtomic =
67 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, false, TStringCasing::Unspecified)));
68pub const TRUTHY_LOWERCASE_STRING_ATOMIC: &TAtomic =
70 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, false, TStringCasing::Lowercase)));
71pub const TRUTHY_UPPERCASE_STRING_ATOMIC: &TAtomic =
73 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, false, TStringCasing::Uppercase)));
74pub const CALLABLE_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::String(TString::callable()));
76pub const LOWERCASE_CALLABLE_STRING_ATOMIC: &TAtomic =
77 &TAtomic::Scalar(TScalar::String(TString::callable_with_casing(TStringCasing::Lowercase)));
78pub const UPPERCASE_CALLABLE_STRING_ATOMIC: &TAtomic =
79 &TAtomic::Scalar(TScalar::String(TString::callable_with_casing(TStringCasing::Uppercase)));
80pub const NUMERIC_STRING_ATOMIC: &TAtomic =
81 &TAtomic::Scalar(TScalar::String(TString::new(None, true, false, false, false, TStringCasing::Unspecified)));
82pub const NUMERIC_TRUTHY_STRING_ATOMIC: &TAtomic =
84 &TAtomic::Scalar(TScalar::String(TString::new(None, true, true, false, false, TStringCasing::Unspecified)));
85pub const CLASS_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::class_string());
87pub const INTERFACE_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::interface_string());
89pub const ENUM_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::enum_string());
91pub const TRAIT_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::trait_string());
93pub const FLOAT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::float());
95pub const UNSPECIFIED_LITERAL_FLOAT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::unspecified_literal_float());
97pub const MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::new());
99pub const ISSET_FROM_LOOP_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::isset_from_loop());
101pub const NEVER_ATOMIC: &TAtomic = &TAtomic::Never;
103pub const NON_NULL_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::non_null());
105pub const FALSY_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::falsy());
107pub const TRUTHY_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::truthy());
109pub const RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::new(None));
111pub const OPEN_RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::open());
113pub const CLOSED_RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::closed());
115pub const PLACEHOLDER_ATOMIC: &TAtomic = &TAtomic::Placeholder;
117pub const VOID_ATOMIC: &TAtomic = &TAtomic::Void;
119pub const NULL_ATOMIC: &TAtomic = &TAtomic::Null;
121pub const ARRAYKEY_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::ArrayKey);
123pub const BOOL_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::bool());
125pub const FALSE_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::r#false());
127pub const TRUE_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::r#true());
129pub const OBJECT_ATOMIC: &TAtomic = &TAtomic::Object(TObject::Any);
131pub const NUMERIC_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Numeric);
133pub static EMPTY_STRING_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
135 TAtomic::Scalar(TScalar::String(TString {
136 literal: Some(TStringLiteral::Value(empty_atom())),
137 is_numeric: false,
138 is_truthy: false,
139 is_non_empty: false,
140 is_callable: false,
141 casing: TStringCasing::Unspecified,
142 }))
143});
144pub const UNSPECIFIED_LITERAL_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::unspecified_literal_string(false));
146pub const NON_EMPTY_UNSPECIFIED_LITERAL_STRING_ATOMIC: &TAtomic =
148 &TAtomic::Scalar(TScalar::unspecified_literal_string(true));
149pub const SCALAR_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Generic);
151
152pub static MIXED_ITERABLE_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
154 TAtomic::Iterable(TIterable {
155 key_type: Arc::new(get_mixed()),
156 value_type: Arc::new(get_mixed()),
157 intersection_types: None,
158 })
159});
160
161pub static EMPTY_KEYED_ARRAY_ATOMIC: LazyLock<TAtomic> =
163 LazyLock::new(|| TAtomic::Array(TArray::Keyed(TKeyedArray::new())));
164pub static MIXED_KEYED_ARRAY_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
166 TAtomic::Array(TArray::Keyed(TKeyedArray::new_with_parameters(Arc::new(get_arraykey()), Arc::new(get_mixed()))))
167});
168pub static MIXED_CALLABLE_ATOMIC: LazyLock<TAtomic> =
170 LazyLock::new(|| TAtomic::Callable(TCallable::Signature(TCallableSignature::mixed(false))));
171pub static MIXED_CLOSURE_ATOMIC: LazyLock<TAtomic> =
173 LazyLock::new(|| TAtomic::Callable(TCallable::Signature(TCallableSignature::mixed(true))));
174
175pub const INT_FLOAT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Scalar(TScalar::int()), TAtomic::Scalar(TScalar::float())];
177pub const INT_STRING_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Scalar(TScalar::int()), TAtomic::Scalar(TScalar::string())];
179pub const NULL_SCALAR_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::Generic)];
181pub const NULL_STRING_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::string())];
183pub const NULL_INT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::int())];
185pub const NULL_FLOAT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::float())];
187pub const NULL_OBJECT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Object(TObject::Any)];
189
190pub const SIGNUM_RESULT_SLICE: &[TAtomic] = &[
193 TAtomic::Scalar(TScalar::literal_int(-1)),
194 TAtomic::Scalar(TScalar::literal_int(0)),
195 TAtomic::Scalar(TScalar::literal_int(1)),
196];