11use crate :: specific:: {
22 ArrayDimensions , BareNamePos , BuiltInStyle , Expression , ExpressionPos , ExpressionType ,
3- HasExpressionType , TypeQualifier , VarTypeIsExtended , VarTypeNewBuiltInCompact ,
4- VarTypeNewBuiltInExtended , VarTypeNewUserDefined , VarTypeQualifier , VarTypeToArray ,
5- VarTypeToUserDefinedRecursively ,
3+ HasExpressionType , TypeQualifier , VarType ,
64} ;
75use rusty_common:: { AtPos , Position } ;
86
@@ -16,53 +14,36 @@ pub enum DimType {
1614 Array ( ArrayDimensions , Box < Self > ) ,
1715}
1816
19- impl VarTypeNewBuiltInCompact for DimType {
17+ impl VarType for DimType {
2018 fn new_built_in_compact ( q : TypeQualifier ) -> Self {
2119 Self :: BuiltIn ( q, BuiltInStyle :: Compact )
2220 }
23- }
2421
25- impl VarTypeNewBuiltInExtended for DimType {
2622 fn new_built_in_extended ( q : TypeQualifier ) -> Self {
2723 Self :: BuiltIn ( q, BuiltInStyle :: Extended )
2824 }
29- }
30-
31- impl VarTypeToArray for DimType {
32- type ArrayType = ArrayDimensions ;
3325
34- fn to_array ( self , array_type : Self :: ArrayType ) -> Self {
35- if array_type. is_empty ( ) {
36- self
37- } else {
38- Self :: Array ( array_type, Box :: new ( self ) )
39- }
40- }
41- }
42-
43- impl VarTypeNewUserDefined for DimType {
4426 fn new_user_defined ( bare_name_pos : BareNamePos ) -> Self {
4527 Self :: UserDefined ( bare_name_pos)
4628 }
47- }
4829
49- impl VarTypeToUserDefinedRecursively for DimType {
5030 fn as_user_defined_recursively ( & self ) -> Option < & BareNamePos > {
5131 match self {
5232 Self :: UserDefined ( n) => Some ( n) ,
5333 Self :: Array ( _, e) => e. as_user_defined_recursively ( ) ,
5434 _ => None ,
5535 }
5636 }
57- }
5837
59- impl DimType {
60- pub fn fixed_length_string ( len : u16 , pos : Position ) -> Self {
61- Self :: FixedLengthString ( Expression :: IntegerLiteral ( len as i32 ) . at_pos ( pos) , len)
38+ fn to_qualifier_recursively ( & self ) -> Option < TypeQualifier > {
39+ match self {
40+ Self :: BuiltIn ( q, _) => Some ( * q) ,
41+ Self :: FixedLengthString ( _, _) => Some ( TypeQualifier :: DollarString ) ,
42+ Self :: Array ( _, e) => e. to_qualifier_recursively ( ) ,
43+ _ => None ,
44+ }
6245 }
63- }
6446
65- impl VarTypeIsExtended for DimType {
6647 fn is_extended ( & self ) -> bool {
6748 match self {
6849 Self :: BuiltIn ( _, BuiltInStyle :: Extended )
@@ -74,6 +55,12 @@ impl VarTypeIsExtended for DimType {
7455 }
7556}
7657
58+ impl DimType {
59+ pub fn fixed_length_string ( len : u16 , pos : Position ) -> Self {
60+ Self :: FixedLengthString ( Expression :: IntegerLiteral ( len as i32 ) . at_pos ( pos) , len)
61+ }
62+ }
63+
7764impl HasExpressionType for DimType {
7865 fn expression_type ( & self ) -> ExpressionType {
7966 match self {
@@ -87,14 +74,3 @@ impl HasExpressionType for DimType {
8774 }
8875 }
8976}
90-
91- impl VarTypeQualifier for DimType {
92- fn to_qualifier_recursively ( & self ) -> Option < TypeQualifier > {
93- match self {
94- Self :: BuiltIn ( q, _) => Some ( * q) ,
95- Self :: FixedLengthString ( _, _) => Some ( TypeQualifier :: DollarString ) ,
96- Self :: Array ( _, e) => e. to_qualifier_recursively ( ) ,
97- _ => None ,
98- }
99- }
100- }
0 commit comments