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 UNSPECIFIED_LITERAL_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::UnspecifiedLiteral));
44pub const STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, false)));
46pub const LOWERCASE_STRING_ATOMIC: &TAtomic =
48 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, true)));
49pub const NON_EMPTY_STRING_ATOMIC: &TAtomic =
51 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, false)));
52pub const NON_EMPTY_LOWERCASE_STRING_ATOMIC: &TAtomic =
54 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, true)));
55pub const TRUTHY_STRING_ATOMIC: &TAtomic =
57 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, false)));
58pub const TRUTHY_LOWERCASE_STRING_ATOMIC: &TAtomic =
60 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, true)));
61pub const NUMERIC_STRING_ATOMIC: &TAtomic =
63 &TAtomic::Scalar(TScalar::String(TString::new(None, true, false, false, false)));
64pub const NUMERIC_TRUTHY_STRING_ATOMIC: &TAtomic =
66 &TAtomic::Scalar(TScalar::String(TString::new(None, true, true, false, false)));
67pub const CLASS_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::class_string());
69pub const INTERFACE_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::interface_string());
71pub const ENUM_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::enum_string());
73pub const TRAIT_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::trait_string());
75pub const FLOAT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::float());
77pub const UNSPECIFIED_LITERAL_FLOAT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::unspecified_literal_float());
79pub const MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::new());
81pub const ISSET_FROM_LOOP_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::isset_from_loop());
83pub const NEVER_ATOMIC: &TAtomic = &TAtomic::Never;
85pub const NON_NULL_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::non_null());
87pub const FALSY_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::falsy());
89pub const TRUTHY_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::truthy());
91pub const RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::new(None));
93pub const OPEN_RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::open());
95pub const CLOSED_RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::closed());
97pub const PLACEHOLDER_ATOMIC: &TAtomic = &TAtomic::Placeholder;
99pub const VOID_ATOMIC: &TAtomic = &TAtomic::Void;
101pub const NULL_ATOMIC: &TAtomic = &TAtomic::Null;
103pub const ARRAYKEY_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::ArrayKey);
105pub const BOOL_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::bool());
107pub const FALSE_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::r#false());
109pub const TRUE_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::r#true());
111pub const OBJECT_ATOMIC: &TAtomic = &TAtomic::Object(TObject::Any);
113pub const NUMERIC_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Numeric);
115pub static EMPTY_STRING_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
117 TAtomic::Scalar(TScalar::String(TString {
118 literal: Some(TStringLiteral::Value(empty_atom())),
119 is_numeric: false,
120 is_truthy: false,
121 is_non_empty: false,
122 is_lowercase: false,
123 }))
124});
125pub const UNSPECIFIED_LITERAL_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::unspecified_literal_string(false));
127pub const NON_EMPTY_UNSPECIFIED_LITERAL_STRING_ATOMIC: &TAtomic =
129 &TAtomic::Scalar(TScalar::unspecified_literal_string(true));
130pub const SCALAR_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Generic);
132
133pub static MIXED_ITERABLE_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
135 TAtomic::Iterable(TIterable {
136 key_type: Box::new(get_mixed()),
137 value_type: Box::new(get_mixed()),
138 intersection_types: None,
139 })
140});
141
142pub static EMPTY_KEYED_ARRAY_ATOMIC: LazyLock<TAtomic> =
144 LazyLock::new(|| TAtomic::Array(TArray::Keyed(TKeyedArray::new())));
145pub static MIXED_KEYED_ARRAY_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
147 TAtomic::Array(TArray::Keyed(TKeyedArray::new_with_parameters(Box::new(get_arraykey()), Box::new(get_mixed()))))
148});
149pub static MIXED_CALLABLE_ATOMIC: LazyLock<TAtomic> =
151 LazyLock::new(|| TAtomic::Callable(TCallable::Signature(TCallableSignature::mixed(false))));
152pub static MIXED_CLOSURE_ATOMIC: LazyLock<TAtomic> =
154 LazyLock::new(|| TAtomic::Callable(TCallable::Signature(TCallableSignature::mixed(true))));
155
156pub const INT_FLOAT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Scalar(TScalar::int()), TAtomic::Scalar(TScalar::float())];
158pub const INT_STRING_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Scalar(TScalar::int()), TAtomic::Scalar(TScalar::string())];
160pub const NULL_SCALAR_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::Generic)];
162pub const NULL_STRING_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::string())];
164pub const NULL_INT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::int())];
166pub const NULL_FLOAT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::float())];
168pub const NULL_OBJECT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Object(TObject::Any)];
170
171pub const SIGNUM_RESULT_SLICE: &[TAtomic] = &[
174 TAtomic::Scalar(TScalar::literal_int(-1)),
175 TAtomic::Scalar(TScalar::literal_int(0)),
176 TAtomic::Scalar(TScalar::literal_int(1)),
177];