gitql_ast/types/
float.rs

1use std::any::Any;
2
3use crate::types::{array::ArrayType, integer::IntType};
4
5use super::base::DataType;
6
7#[derive(Clone)]
8pub struct FloatType;
9
10impl DataType for FloatType {
11    fn literal(&self) -> String {
12        "Float".to_string()
13    }
14
15    fn equals(&self, other: &Box<dyn DataType>) -> bool {
16        other.is_any() || other.is_float() || other.is_variant_with(|t| t.is_float())
17    }
18
19    fn as_any(&self) -> &dyn Any {
20        self
21    }
22
23    fn can_perform_add_op_with(&self) -> Vec<Box<dyn DataType>> {
24        vec![Box::new(FloatType)]
25    }
26
27    fn add_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
28        Box::new(FloatType)
29    }
30
31    fn can_perform_sub_op_with(&self) -> Vec<Box<dyn DataType>> {
32        vec![Box::new(FloatType)]
33    }
34
35    fn sub_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
36        Box::new(FloatType)
37    }
38
39    fn can_perform_mul_op_with(&self) -> Vec<Box<dyn DataType>> {
40        vec![Box::new(FloatType)]
41    }
42
43    fn mul_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
44        Box::new(FloatType)
45    }
46
47    fn can_perform_div_op_with(&self) -> Vec<Box<dyn DataType>> {
48        vec![Box::new(FloatType)]
49    }
50
51    fn div_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
52        Box::new(FloatType)
53    }
54
55    fn can_perform_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
56        vec![Box::new(FloatType)]
57    }
58
59    fn can_perform_group_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
60        vec![Box::new(ArrayType::new(Box::new(FloatType)))]
61    }
62
63    fn can_perform_bang_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
64        vec![Box::new(FloatType)]
65    }
66
67    fn can_perform_group_bang_eq_op_with(&self) -> Vec<Box<dyn DataType>> {
68        vec![Box::new(ArrayType::new(Box::new(FloatType)))]
69    }
70
71    fn can_perform_gt_op_with(&self) -> Vec<Box<dyn DataType>> {
72        vec![Box::new(FloatType)]
73    }
74
75    fn can_perform_group_gt_op_with(&self) -> Vec<Box<dyn DataType>> {
76        vec![Box::new(ArrayType::new(Box::new(FloatType)))]
77    }
78
79    fn can_perform_gte_op_with(&self) -> Vec<Box<dyn DataType>> {
80        vec![Box::new(FloatType)]
81    }
82
83    fn can_perform_group_gte_op_with(&self) -> Vec<Box<dyn DataType>> {
84        vec![Box::new(ArrayType::new(Box::new(FloatType)))]
85    }
86
87    fn can_perform_lt_op_with(&self) -> Vec<Box<dyn DataType>> {
88        vec![Box::new(FloatType)]
89    }
90
91    fn can_perform_group_lt_op_with(&self) -> Vec<Box<dyn DataType>> {
92        vec![Box::new(ArrayType::new(Box::new(FloatType)))]
93    }
94
95    fn can_perform_lte_op_with(&self) -> Vec<Box<dyn DataType>> {
96        vec![Box::new(FloatType)]
97    }
98
99    fn can_perform_group_lte_op_with(&self) -> Vec<Box<dyn DataType>> {
100        vec![Box::new(ArrayType::new(Box::new(FloatType)))]
101    }
102
103    fn can_perform_neg_op(&self) -> bool {
104        true
105    }
106
107    fn neg_op_result_type(&self) -> Box<dyn DataType> {
108        Box::new(self.clone())
109    }
110
111    fn can_perform_explicit_cast_op_to(&self) -> Vec<Box<dyn DataType>> {
112        vec![Box::new(IntType)]
113    }
114}