1use std::sync::Arc;
7use std::sync::LazyLock;
8
9use mago_word::empty_word;
10use mago_word::word;
11
12use crate::ttype::atomic::TAtomic;
13use crate::ttype::atomic::array::TArray;
14use crate::ttype::atomic::array::keyed::TKeyedArray;
15use crate::ttype::atomic::callable::TCallable;
16use crate::ttype::atomic::callable::TCallableSignature;
17use crate::ttype::atomic::iterable::TIterable;
18use crate::ttype::atomic::mixed::TMixed;
19use crate::ttype::atomic::object::TObject;
20use crate::ttype::atomic::resource::TResource;
21use crate::ttype::atomic::scalar::TScalar;
22use crate::ttype::atomic::scalar::int::TInteger;
23use crate::ttype::atomic::scalar::string::TString;
24use crate::ttype::atomic::scalar::string::TStringLiteral;
25use crate::ttype::get_arraykey;
26use crate::ttype::get_mixed;
27
28use super::atomic::scalar::string::TStringCasing;
29
30pub const ONE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::literal_int(1));
32pub const ZERO_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::literal_int(0));
34pub const MINUS_ONE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::literal_int(-1));
36pub const INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::int());
38pub const POSITIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::positive()));
40pub const NON_POSITIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::non_positive()));
42pub const NEGATIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::negative()));
44pub const NON_NEGATIVE_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::non_negative()));
46pub const UNSPECIFIED_LITERAL_INT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Integer(TInteger::UnspecifiedLiteral));
48pub const STRING_ATOMIC: &TAtomic =
50 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, false, TStringCasing::Unspecified)));
51pub const LOWERCASE_STRING_ATOMIC: &TAtomic =
53 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, false, TStringCasing::Lowercase)));
54pub const UPPERCASE_STRING_ATOMIC: &TAtomic =
56 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, false, false, TStringCasing::Uppercase)));
57pub const NON_EMPTY_STRING_ATOMIC: &TAtomic =
59 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, false, TStringCasing::Unspecified)));
60pub const NON_EMPTY_LOWERCASE_STRING_ATOMIC: &TAtomic =
62 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, false, TStringCasing::Lowercase)));
63pub const NON_EMPTY_UPPERCASE_STRING_ATOMIC: &TAtomic =
65 &TAtomic::Scalar(TScalar::String(TString::new(None, false, false, true, false, TStringCasing::Uppercase)));
66pub const TRUTHY_STRING_ATOMIC: &TAtomic =
68 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, false, TStringCasing::Unspecified)));
69pub const TRUTHY_LOWERCASE_STRING_ATOMIC: &TAtomic =
71 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, false, TStringCasing::Lowercase)));
72pub const TRUTHY_UPPERCASE_STRING_ATOMIC: &TAtomic =
74 &TAtomic::Scalar(TScalar::String(TString::new(None, false, true, false, false, TStringCasing::Uppercase)));
75pub const CALLABLE_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::String(TString::callable()));
77pub const LOWERCASE_CALLABLE_STRING_ATOMIC: &TAtomic =
78 &TAtomic::Scalar(TScalar::String(TString::callable_with_casing(TStringCasing::Lowercase)));
79pub const UPPERCASE_CALLABLE_STRING_ATOMIC: &TAtomic =
80 &TAtomic::Scalar(TScalar::String(TString::callable_with_casing(TStringCasing::Uppercase)));
81pub const NUMERIC_STRING_ATOMIC: &TAtomic =
82 &TAtomic::Scalar(TScalar::String(TString::new(None, true, false, false, false, TStringCasing::Unspecified)));
83pub const NUMERIC_TRUTHY_STRING_ATOMIC: &TAtomic =
85 &TAtomic::Scalar(TScalar::String(TString::new(None, true, true, false, false, TStringCasing::Unspecified)));
86pub const CLASS_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::class_string());
88pub const FLOAT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::float());
90pub const UNSPECIFIED_LITERAL_FLOAT_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::unspecified_literal_float());
92pub const MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::new());
94pub const ISSET_FROM_LOOP_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::isset_from_loop());
96pub const NEVER_ATOMIC: &TAtomic = &TAtomic::Never;
98pub const TRUTHY_MIXED_ATOMIC: &TAtomic = &TAtomic::Mixed(TMixed::truthy());
100pub const RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::new(None));
102pub const OPEN_RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::open());
104pub const CLOSED_RESOURCE_ATOMIC: &TAtomic = &TAtomic::Resource(TResource::closed());
106pub const PLACEHOLDER_ATOMIC: &TAtomic = &TAtomic::Placeholder;
108pub const VOID_ATOMIC: &TAtomic = &TAtomic::Void;
110pub const NULL_ATOMIC: &TAtomic = &TAtomic::Null;
112pub const ARRAYKEY_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::ArrayKey);
114pub const BOOL_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::bool());
116pub const FALSE_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::r#false());
118pub const TRUE_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::r#true());
120pub const OBJECT_ATOMIC: &TAtomic = &TAtomic::Object(TObject::Any);
122pub const NUMERIC_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Numeric);
124pub static EMPTY_STRING_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
126 TAtomic::Scalar(TScalar::String(TString {
127 literal: Some(TStringLiteral::Value(empty_word())),
128 is_numeric: false,
129 is_truthy: false,
130 is_non_empty: false,
131 is_callable: false,
132 casing: TStringCasing::Unspecified,
133 }))
134});
135pub const UNSPECIFIED_LITERAL_STRING_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::unspecified_literal_string(false));
137pub const NON_EMPTY_UNSPECIFIED_LITERAL_STRING_ATOMIC: &TAtomic =
139 &TAtomic::Scalar(TScalar::unspecified_literal_string(true));
140pub const SCALAR_ATOMIC: &TAtomic = &TAtomic::Scalar(TScalar::Generic);
142
143pub static MIXED_ITERABLE_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
145 TAtomic::Iterable(TIterable {
146 key_type: Arc::new(get_mixed()),
147 value_type: Arc::new(get_mixed()),
148 intersection_types: None,
149 })
150});
151
152pub static EMPTY_KEYED_ARRAY_ATOMIC: LazyLock<TAtomic> =
154 LazyLock::new(|| TAtomic::Array(TArray::Keyed(TKeyedArray::new())));
155pub static MIXED_KEYED_ARRAY_ATOMIC: LazyLock<TAtomic> = LazyLock::new(|| {
157 TAtomic::Array(TArray::Keyed(TKeyedArray::new_with_parameters(Arc::new(get_arraykey()), Arc::new(get_mixed()))))
158});
159pub static MIXED_CALLABLE_ATOMIC: LazyLock<TAtomic> =
161 LazyLock::new(|| TAtomic::Callable(TCallable::Signature(TCallableSignature::mixed(false))));
162pub static MIXED_CLOSURE_ATOMIC: LazyLock<TAtomic> =
164 LazyLock::new(|| TAtomic::Callable(TCallable::Signature(TCallableSignature::mixed(true))));
165
166pub const INT_FLOAT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Scalar(TScalar::int()), TAtomic::Scalar(TScalar::float())];
168pub const INT_STRING_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Scalar(TScalar::int()), TAtomic::Scalar(TScalar::string())];
170pub const NULL_SCALAR_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::Generic)];
172pub const NULL_STRING_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::string())];
174pub const NULL_INT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::int())];
176pub const NULL_FLOAT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Scalar(TScalar::float())];
178pub const NULL_OBJECT_ATOMIC_SLICE: &[TAtomic] = &[TAtomic::Null, TAtomic::Object(TObject::Any)];
180
181pub const SIGNUM_RESULT_SLICE: &[TAtomic] = &[
184 TAtomic::Scalar(TScalar::literal_int(-1)),
185 TAtomic::Scalar(TScalar::literal_int(0)),
186 TAtomic::Scalar(TScalar::literal_int(1)),
187];
188
189pub static EMPTY_SCALAR_ATOMIC_SLICE: LazyLock<[TAtomic; 5]> = LazyLock::new(|| {
190 [
191 TAtomic::Scalar(TScalar::literal_int(0)),
192 TAtomic::Scalar(TScalar::literal_float(0.0)),
193 TAtomic::Scalar(TScalar::literal_string(word("0"))),
194 EMPTY_STRING_ATOMIC.clone(),
195 TAtomic::Scalar(TScalar::r#false()),
196 ]
197});
198
199pub static EMPTY_ATOMIC_SLICE: LazyLock<[TAtomic; 7]> = LazyLock::new(|| {
200 [
201 TAtomic::Null,
202 TAtomic::Scalar(TScalar::literal_int(0)),
203 TAtomic::Scalar(TScalar::literal_float(0.0)),
204 TAtomic::Scalar(TScalar::literal_string(word("0"))),
205 EMPTY_STRING_ATOMIC.clone(),
206 TAtomic::Scalar(TScalar::r#false()),
207 EMPTY_KEYED_ARRAY_ATOMIC.clone(),
208 ]
209});