mago_codex/ttype/
shared.rs1use std::sync::LazyLock;
7
8use mago_atom::empty_atom;
9
10use crate::ttype::atomic::TAtomic;
11use crate::ttype::atomic::array::TArray;
12use crate::ttype::atomic::array::keyed::TKeyedArray;
13use crate::ttype::atomic::callable::TCallable;
14use crate::ttype::atomic::callable::TCallableSignature;
15use crate::ttype::atomic::iterable::TIterable;
16use crate::ttype::atomic::mixed::TMixed;
17use crate::ttype::atomic::object::TObject;
18use crate::ttype::atomic::resource::TResource;
19use crate::ttype::atomic::scalar::TScalar;
20use crate::ttype::atomic::scalar::int::TInteger;
21use crate::ttype::atomic::scalar::string::TString;
22use crate::ttype::atomic::scalar::string::TStringLiteral;
23use crate::ttype::get_arraykey;
24use crate::ttype::get_mixed;
25
26pub const ONE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::literal_int(1));
28pub const ZERO_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::literal_int(0));
30pub const MINUS_ONE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::literal_int(-1));
32pub const INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::int());
34pub const POSITIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::positive()));
36pub const NON_POSITIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::non_positive()));
38pub const NEGATIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::negative()));
40pub const NON_NEGATIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::non_negative()));
42pub const STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, false)));
44pub const LOWERCASE_STRING_ATOMIC: &TAtomic =
46 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, true)));
47pub const NON_EMPTY_STRING_ATOMIC: &TAtomic =
49 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, false)));
50pub const NON_EMPTY_LOWERCASE_STRING_ATOMIC: &TAtomic =
52 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, true)));
53pub const TRUTHY_STRING_ATOMIC: &TAtomic =
55 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, false)));
56pub const TRUTHY_LOWERCASE_STRING_ATOMIC: &TAtomic =
58 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, true)));
59pub const NUMERIC_STRING_ATOMIC: &TAtomic =
61 &TAtomic::Scalar(TScalar::String(TString::new(None, true, false, false, false)));
62pub const NUMERIC_TRUTHY_STRING_ATOMIC: &TAtomic =
64 &TAtomic::Scalar(TScalar::String(TString::new(None, true, true, false, false)));
65pub const CLASS_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::class_string());
67pub const INTERFACE_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::interface_string());
69pub const ENUM_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::enum_string());
71pub const TRAIT_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::trait_string());
73pub const FLOAT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::float());
75pub const MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::new());
77pub const ISSET_FROM_LOOP_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::isset_from_loop());
79pub const NEVER_ATOMIC: &TAtomic = &TAtomic::Never;
81pub const NON_NULL_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::non_null());
83pub const FALSY_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::falsy());
85pub const TRUTHY_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::truthy());
87pub const RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::new(None));
89pub const OPEN_RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::open());
91pub const CLOSED_RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::closed());
93pub const PLACEHOLDER_ATOMIC: &TAtomic = &TAtomic::Placeholder;
95pub const VOID_ATOMIC: &TAtomic = &TAtomic::Void;
97pub const NULL_ATOMIC: &TAtomic = &TAtomic::Null;
99pub const ARRAYKEY_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::ArrayKey);
101pub const BOOL_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::bool());
103pub const FALSE_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::r#false());
105pub const TRUE_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::r#true());
107pub const OBJECT_ATOMIC: &TAtomic = &TAtomic::Object(TObject::Any);
109pub const NUMERIC_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Numeric);
111pub static EMPTY_STRING_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
113 TAtomic::Scalar(TScalar::String(TString {
114 literal: Some(TStringLiteral::Value(empty_atom())),
115 is_numeric: false,
116 is_truthy: false,
117 is_non_empty: false,
118 is_lowercase: false,
119 }))
120});
121pub const UNSPECIFIED_LITERAL_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::unspecified_literal_string(false));
123pub const NON_EMPTY_UNSPECIFIED_LITERAL_STRING_ATOMIC: &TAtomic =
125 &TAtomic::Scalar(TScalar::unspecified_literal_string(true));
126pub const SCALAR_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Generic);
128
129pub static MIXED_ITERABLE_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
131 TAtomic::Iterable(TIterable {
132 key_type: Box::new(get_mixed()),
133 value_type: Box::new(get_mixed()),
134 intersection_types: None,
135 })
136});
137
138pub static EMPTY_KEYED_ARRAY_ATOMIC: LazyLock<TAtomic> =
140 LazyLock::new(|| TAtomic::Array(TArray::Keyed(TKeyedArray::new())));
141pub static MIXED_KEYED_ARRAY_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
143 TAtomic::Array(TArray::Keyed(TKeyedArray::new_with_parameters(Box::new(get_arraykey()), Box::new(get_mixed()))))
144});
145pub static MIXED_CALLABLE_ATOMIC: LazyLock<TAtomic> =
147 LazyLock::new(|| TAtomic::Callable(TCallable::Signature(TCallableSignature::mixed(false))));
148pub static MIXED_CLOSURE_ATOMIC: LazyLock<TAtomic> =
150 LazyLock::new(|| TAtomic::Callable(TCallable::Signature(TCallableSignature::mixed(true))));
151
152pub const INT_FLOAT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Scalar(TScalar::int()), TAtomic::Scalar(TScalar::float())];
154pub const INT_STRING_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Scalar(TScalar::int()), TAtomic::Scalar(TScalar::string())];
156pub const NULL_SCALAR_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::Generic)];
158pub const NULL_STRING_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::string())];
160pub const NULL_INT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::int())];
162pub const NULL_FLOAT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::float())];
164pub const NULL_OBJECT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Object(TObject::Any)];
166
167pub const SIGNUM_RESULT_SLICE: &[TAtomic] = &[
170 TAtomic::Scalar(TScalar::literal_int(-1)),
171 TAtomic::Scalar(TScalar::literal_int(0)),
172 TAtomic::Scalar(TScalar::literal_int(1)),
173];