gitql_ast/types/
integer.rs1use std::any::Any;
2
3use crate::types::array::ArrayType;
4use crate::types::boolean::BoolType;
5use crate::types::float::FloatType;
6
7use super::base::DataType;
8
9#[derive(Clone)]
10pub struct IntType;
11
12impl DataType for IntType {
13 fn literal(&self) -> String {
14 "Int".to_string()
15 }
16
17 fn equals(&self, other: &Box<dyn DataType>) -> bool {
18 other.is_any() || other.is_int() || other.is_variant_with(|t| t.is_int())
19 }
20
21 fn as_any(&self) -> &dyn Any {
22 self
23 }
24
25 fn can_perform_add_op_with(&self) -> Vec<Box<dyn DataType>> {
26 vec![Box::new(IntType)]
27 }
28
29 fn add_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
30 Box::new(IntType)
31 }
32
33 fn can_perform_sub_op_with(&self) -> Vec<Box<dyn DataType>> {
34 vec![Box::new(IntType)]
35 }
36
37 fn sub_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
38 Box::new(IntType)
39 }
40
41 fn can_perform_mul_op_with(&self) -> Vec<Box<dyn DataType>> {
42 vec![Box::new(IntType)]
43 }
44
45 fn mul_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
46 Box::new(IntType)
47 }
48
49 fn can_perform_div_op_with(&self) -> Vec<Box<dyn DataType>> {
50 vec![Box::new(IntType)]
51 }
52
53 fn div_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
54 Box::new(IntType)
55 }
56
57 fn can_perform_rem_op_with(&self) -> Vec<Box<dyn DataType>> {
58 vec![Box::new(IntType)]
59 }
60
61 fn rem_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
62 Box::new(IntType)
63 }
64
65 fn can_perform_caret_op_with(&self) -> Vec<Box<dyn DataType>> {
66 vec![Box::new(IntType)]
67 }
68
69 fn caret_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
70 Box::new(IntType)
71 }
72
73 fn can_perform_or_op_with(&self) -> Vec<Box<dyn DataType>> {
74 vec![Box::new(IntType)]
75 }
76
77 fn or_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
78 Box::new(self.clone())
79 }
80
81 fn can_perform_and_op_with(&self) -> Vec<Box<dyn DataType>> {
82 vec![Box::new(IntType)]
83 }
84
85 fn and_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
86 Box::new(self.clone())
87 }
88
89 fn can_perform_xor_op_with(&self) -> Vec<Box<dyn DataType>> {
90 vec![Box::new(IntType)]
91 }
92
93 fn xor_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
94 Box::new(self.clone())
95 }
96
97 fn can_perform_shl_op_with(&self) -> Vec<Box<dyn DataType>> {
98 vec![Box::new(IntType)]
99 }
100
101 fn shl_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
102 Box::new(self.clone())
103 }
104
105 fn can_perform_shr_op_with(&self) -> Vec<Box<dyn DataType>> {
106 vec![Box::new(IntType)]
107 }
108
109 fn shr_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
110 Box::new(self.clone())
111 }
112
113 fn can_perform_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
114 vec![Box::new(IntType)]
115 }
116
117 fn can_perform_group_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
118 vec![Box::new(ArrayType::new(Box::new(IntType)))]
119 }
120
121 fn can_perform_bang_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
122 vec![Box::new(IntType)]
123 }
124
125 fn can_perform_group_bang_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
126 vec![Box::new(ArrayType::new(Box::new(IntType)))]
127 }
128
129 fn can_perform_gt_op_with(&self) -> Vec<Box<dyn DataType>> {
130 vec![Box::new(IntType)]
131 }
132
133 fn can_perform_group_gt_op_with(&self) -> Vec<Box<dyn DataType>> {
134 vec![Box::new(ArrayType::new(Box::new(IntType)))]
135 }
136
137 fn can_perform_gte_op_with(&self) -> Vec<Box<dyn DataType>> {
138 vec![Box::new(IntType)]
139 }
140
141 fn can_perform_group_gte_op_with(&self) -> Vec<Box<dyn DataType>> {
142 vec![Box::new(ArrayType::new(Box::new(IntType)))]
143 }
144
145 fn can_perform_lt_op_with(&self) -> Vec<Box<dyn DataType>> {
146 vec![Box::new(IntType)]
147 }
148
149 fn can_perform_group_lt_op_with(&self) -> Vec<Box<dyn DataType>> {
150 vec![Box::new(ArrayType::new(Box::new(IntType)))]
151 }
152
153 fn can_perform_lte_op_with(&self) -> Vec<Box<dyn DataType>> {
154 vec![Box::new(IntType)]
155 }
156
157 fn can_perform_group_lte_op_with(&self) -> Vec<Box<dyn DataType>> {
158 vec![Box::new(ArrayType::new(Box::new(IntType)))]
159 }
160
161 fn can_perform_neg_op(&self) -> bool {
162 true
163 }
164
165 fn neg_op_result_type(&self) -> Box<dyn DataType> {
166 Box::new(self.clone())
167 }
168
169 fn can_perform_explicit_cast_op_to(&self) -> Vec<Box<dyn DataType>> {
170 vec![Box::new(FloatType), Box::new(BoolType)]
171 }
172}