1313from ..template import Template , TemplateList
1414from ..utils import qualify_type_str
1515from .base_scope_kind import ScopeKind
16+ from .extendable import Extendable
1617
1718if TYPE_CHECKING :
1819 from .scope import Scope
1920
2021
21- class StructLikeScopeKind (ScopeKind ):
22- class Base :
23- def __init__ (
24- self , name : str , protection : str , virtual : bool , refid : str
25- ) -> None :
26- self .name : str = name
27- self .protection : str = protection
28- self .virtual : bool = virtual
29- self .refid : str = refid
30-
22+ class StructLikeScopeKind (ScopeKind , Extendable ):
3123 class Type (Enum ):
3224 CLASS = "class"
3325 STRUCT = "struct"
3426 UNION = "union"
3527
3628 def __init__ (self , type : Type ) -> None :
37- super ().__init__ (type .value )
29+ ScopeKind .__init__ (self , type .value )
30+ Extendable .__init__ (self )
3831
39- self .base_classes : [StructLikeScopeKind .Base ] = []
4032 self .template_list : TemplateList | None = None
4133
42- def add_base (
43- self , base : StructLikeScopeKind .Base | [StructLikeScopeKind .Base ]
44- ) -> None :
45- if isinstance (base , list ):
46- for b in base :
47- self .base_classes .append (b )
48- else :
49- self .base_classes .append (base )
50-
5134 def add_template (self , template : Template | [Template ]) -> None :
5235 if template and self .template_list is None :
5336 self .template_list = TemplateList ()
@@ -66,18 +49,10 @@ def close(self, scope: Scope) -> None:
6649 def to_string (self , scope : Scope ) -> str :
6750 result = ""
6851
69- bases = []
70- for base in self .base_classes :
71- base_text = [base .protection ]
72- if base .virtual :
73- base_text .append ("virtual" )
74- base_text .append (base .name )
75- bases .append (" " .join (base_text ))
76-
77- inheritance_string = " : " + ", " .join (bases ) if bases else ""
78-
7952 if self .template_list is not None :
8053 result += "\n " + self .template_list .to_string () + "\n "
54+
55+ inheritance_string = self .get_inheritance_string ()
8156 result += f"{ self .name } { scope .get_qualified_name ()} { inheritance_string } {{"
8257
8358 stringified_members = []
0 commit comments