@@ -72,7 +72,6 @@ pub struct Symbol {
72
72
pub allow_unused : bool ,
73
73
pub public : bool ,
74
74
pub doc_comment : DocComment ,
75
- pub r#type : Option < Type > ,
76
75
}
77
76
78
77
impl Symbol {
@@ -95,7 +94,6 @@ impl Symbol {
95
94
allow_unused : false ,
96
95
public,
97
96
doc_comment,
98
- r#type : None ,
99
97
}
100
98
}
101
99
@@ -428,6 +426,32 @@ impl SymbolKind {
428
426
_ => None ,
429
427
}
430
428
}
429
+
430
+ pub fn get_type ( & self ) -> Option < & Type > {
431
+ match self {
432
+ SymbolKind :: Port ( x) => x. r#type . as_ref ( ) ,
433
+ SymbolKind :: Variable ( x) => Some ( & x. r#type ) ,
434
+ SymbolKind :: Function ( x) => x. ret . as_ref ( ) ,
435
+ SymbolKind :: Parameter ( x) => Some ( & x. r#type ) ,
436
+ SymbolKind :: StructMember ( x) => Some ( & x. r#type ) ,
437
+ SymbolKind :: UnionMember ( x) => Some ( & x. r#type ) ,
438
+ SymbolKind :: TypeDef ( x) => Some ( & x. r#type ) ,
439
+ _ => None ,
440
+ }
441
+ }
442
+
443
+ pub fn get_type_mut ( & mut self ) -> Option < & mut Type > {
444
+ match self {
445
+ SymbolKind :: Port ( x) => x. r#type . as_mut ( ) ,
446
+ SymbolKind :: Variable ( x) => Some ( & mut x. r#type ) ,
447
+ SymbolKind :: Function ( x) => x. ret . as_mut ( ) ,
448
+ SymbolKind :: Parameter ( x) => Some ( & mut x. r#type ) ,
449
+ SymbolKind :: StructMember ( x) => Some ( & mut x. r#type ) ,
450
+ SymbolKind :: UnionMember ( x) => Some ( & mut x. r#type ) ,
451
+ SymbolKind :: TypeDef ( x) => Some ( & mut x. r#type ) ,
452
+ _ => None ,
453
+ }
454
+ }
431
455
}
432
456
433
457
impl fmt:: Display for SymbolKind {
@@ -608,7 +632,7 @@ pub enum TypeKind {
608
632
F64 ,
609
633
Type ,
610
634
String ,
611
- UserDefined ( Vec < StrId > ) ,
635
+ UserDefined ( UserDefinedType ) ,
612
636
}
613
637
614
638
impl TypeKind {
@@ -631,6 +655,18 @@ impl TypeKind {
631
655
}
632
656
}
633
657
658
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
659
+ pub struct UserDefinedType {
660
+ pub path : Vec < StrId > ,
661
+ pub symbol : Option < SymbolId > ,
662
+ }
663
+
664
+ impl UserDefinedType {
665
+ fn new ( path : Vec < StrId > ) -> Self {
666
+ Self { path, symbol : None }
667
+ }
668
+ }
669
+
634
670
#[ derive( Debug , Clone , PartialEq , Eq ) ]
635
671
pub enum TypeModifier {
636
672
Tri ,
@@ -665,9 +701,9 @@ impl fmt::Display for Type {
665
701
TypeKind :: F64 => text. push_str ( "f64" ) ,
666
702
TypeKind :: Type => text. push_str ( "type" ) ,
667
703
TypeKind :: String => text. push_str ( "string" ) ,
668
- TypeKind :: UserDefined ( paths ) => {
669
- text. push_str ( & format ! ( "{}" , paths . first( ) . unwrap( ) ) ) ;
670
- for path in & paths [ 1 ..] {
704
+ TypeKind :: UserDefined ( x ) => {
705
+ text. push_str ( & format ! ( "{}" , x . path . first( ) . unwrap( ) ) ) ;
706
+ for path in & x . path [ 1 ..] {
671
707
text. push_str ( & format ! ( "::{path}" ) ) ;
672
708
}
673
709
}
@@ -801,7 +837,7 @@ impl TryFrom<&syntax_tree::Expression> for Type {
801
837
for x in & x. scoped_identifier . scoped_identifier_list {
802
838
name. push ( x. identifier . identifier_token . token . text ) ;
803
839
}
804
- let kind = TypeKind :: UserDefined ( name) ;
840
+ let kind = TypeKind :: UserDefined ( UserDefinedType :: new ( name) ) ;
805
841
let mut width = Vec :: new ( ) ;
806
842
if let Some ( ref x) = x. expression_identifier_opt {
807
843
let x = & x. width ;
@@ -902,7 +938,7 @@ impl From<&syntax_tree::ScalarType> for Type {
902
938
for x in & ident. scoped_identifier_list {
903
939
name. push ( x. identifier . identifier_token . token . text ) ;
904
940
}
905
- let kind = TypeKind :: UserDefined ( name) ;
941
+ let kind = TypeKind :: UserDefined ( UserDefinedType :: new ( name) ) ;
906
942
let mut width = Vec :: new ( ) ;
907
943
if let Some ( ref x) = x. scalar_type_opt {
908
944
let x = & x. width ;
0 commit comments