Skip to content

Commit 7ceb078

Browse files
committed
BCTYPES: support for printing header file
1 parent 9e2374f commit 7ceb078

File tree

14 files changed

+180
-24
lines changed

14 files changed

+180
-24
lines changed

chb/app/CHVersion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
chbversion: str = "0.3.0-20260324"
1+
chbversion: str = "0.3.0-20260329"
22

3-
minimum_required_chb_version = "0.6.0_20260324"
3+
minimum_required_chb_version = "0.6.0_20260329"

chb/bctypes/BCAttrParam.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2022 Aarno Labs LLC
7+
# Copyright (c) 2022-2026 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -60,6 +60,7 @@
6060
from chb.bctypes.BCDictionary import BCDictionary
6161
from chb.bctypes.BCTyp import BCTyp
6262
from chb.bctypes.BCTypSig import BCTypSig
63+
from chb.bctypes.BCVisitor import BCVisitor
6364

6465

6566
class BCAttrParam(BCDictionaryRecord):
@@ -104,6 +105,9 @@ def is_int(self) -> bool:
104105
def to_c_string(self) -> str:
105106
return str(self.intvalue)
106107

108+
def accept(self, visitor: "BCVisitor") -> None:
109+
visitor.visit_attr_param_int(self)
110+
107111
def __str__(self) -> str:
108112
return "aint(" + str(self.intvalue) + ")"
109113

@@ -126,6 +130,9 @@ def strvalue(self) -> str:
126130
def to_c_string(self) -> str:
127131
return self.strvalue
128132

133+
def accept(self, visitor: "BCVisitor") -> None:
134+
visitor.visit_attr_param_str(self)
135+
129136
def __str__(self) -> str:
130137
return "astr(" + self.strvalue + ")"
131138

@@ -158,6 +165,9 @@ def to_c_string(self) -> str:
158165
+ ", ".join(p.to_c_string for p in self.params)
159166
+ ")")
160167

168+
def accept(self, visitor: "BCVisitor") -> None:
169+
visitor.visit_attr_param_cons(self)
170+
161171
def __str__(self) -> str:
162172
return (
163173
"acons("

chb/bctypes/BCAttribute.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2022-2023 Aarno Labs LLC
7+
# Copyright (c) 2022-2026 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -35,6 +35,7 @@
3535
if TYPE_CHECKING:
3636
from chb.bctypes.BCDictionary import BCDictionary
3737
from chb.bctypes.BCAttrParam import BCAttrParam
38+
from chb.bctypes.BCVisitor import BCVisitor
3839

3940

4041
class BCAttribute(BCDictionaryRecord):
@@ -61,6 +62,9 @@ def is_volatile(self) -> bool:
6162
def to_c_string(self) -> str:
6263
return self.name + "(" + ", ".join(p.to_c_string for p in self.params) + ")"
6364

65+
def accept(self, visitor: "BCVisitor") -> None:
66+
visitor.visit_attribute(self)
67+
6468
def __str__(self) -> str:
6569
return self.name + "(" + ", ".join(str(p) for p in self.params) + ")"
6670

@@ -81,6 +85,9 @@ def attrs(self) -> List[BCAttribute]:
8185
def is_empty(self) -> bool:
8286
return len(self.attrs) == 0
8387

88+
def accept(self, visitor: "BCVisitor") -> None:
89+
visitor.visit_attributes(self)
90+
8491
@property
8592
def to_c_string(self) -> str:
8693
return (

chb/bctypes/BCCompInfo.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2021-2023 Aarno Labs LLC
7+
# Copyright (c) 2021-2026 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -29,16 +29,17 @@
2929

3030
import chb.ast.ASTNode as AST
3131

32-
from chb.bctypes.BCConverter import BCConverter
3332
from chb.bctypes.BCDictionaryRecord import BCDictionaryRecord
3433

3534
import chb.util.fileutil as UF
3635
import chb.util.IndexedTable as IT
3736

3837
if TYPE_CHECKING:
38+
from chb.bctypes.BCConverter import BCConverter
3939
from chb.bctypes.BCDictionary import BCDictionary
4040
from chb.bctypes.BCFieldInfo import BCFieldInfo
4141
from chb.bctypes.BCTyp import BCTyp
42+
from chb.bctypes.BCVisitor import BCVisitor
4243

4344

4445
class OffsetAccumulator:
@@ -209,7 +210,10 @@ def field_at_offset(self, offset: int) -> Tuple["BCFieldInfo", int]:
209210
+ str(self.alignment())
210211
+ ")")
211212

212-
def convert(self, converter: BCConverter) -> AST.ASTCompInfo:
213+
def accept(self, visitor: "BCVisitor") -> None:
214+
visitor.visit_compinfo(self)
215+
216+
def convert(self, converter: "BCConverter") -> AST.ASTCompInfo:
213217
return converter.convert_compinfo(self)
214218

215219
def __str__(self) -> str:

chb/bctypes/BCDictionary.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2021-2024 Aarno Labs LLC
7+
# Copyright (c) 2021-2026 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -263,6 +263,17 @@ def initialize(self, xnode: Optional[ET.Element]) -> None:
263263
cinfo = self.compinfo(ix)
264264
self.compinfo_keys[cinfo.ckey] = cinfo
265265

266+
# ------------------ Values ------------------------------------------------
267+
268+
def typeinfos(self) -> List["BCTypeInfo"]:
269+
return [self.typeinfo(ix) for ix in self.typeinfo_table.keys()]
270+
271+
def varinfos(self) -> List["BCVarInfo"]:
272+
return [self.varinfo(ix) for ix in self.varinfo_table.keys()]
273+
274+
def compinfos(self) -> List["BCCompInfo"]:
275+
return [self.compinfo(ix) for ix in self.compinfo_table.keys()]
276+
266277
# ------------------ Printing ----------------------------------------------
267278

268279
def typ_table_to_string(self) -> str:

chb/bctypes/BCEnumInfo.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2022 Aarno Labs LLC
7+
# Copyright (c) 2022-2026 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -29,16 +29,17 @@
2929

3030
import chb.ast.ASTNode as AST
3131

32-
from chb.bctypes.BCConverter import BCConverter
3332
from chb.bctypes.BCDictionaryRecord import BCDictionaryRecord
3433

3534
import chb.util.fileutil as UF
3635
import chb.util.IndexedTable as IT
3736

3837
if TYPE_CHECKING:
38+
from chb.bctypes.BCConverter import BCConverter
3939
from chb.bctypes.BCDictionary import BCDictionary
4040
from chb.bctypes.BCEnumItem import BCEnumItem
4141
from chb.bctypes.BCTyp import BCTyp
42+
from chb.bctypes.BCVisitor import BCVisitor
4243

4344

4445
class BCEnumInfo(BCDictionaryRecord):
@@ -61,7 +62,10 @@ def ekind(self) -> str:
6162
def enumitems(self) -> List["BCEnumItem"]:
6263
return [self.bcd.enumitem(i) for i in self.args[1:]]
6364

64-
def convert(self, converter: BCConverter) -> AST.ASTEnumInfo:
65+
def accept(self, visitor: "BCVisitor") -> None:
66+
visitor.visit_enuminfo(self)
67+
68+
def convert(self, converter: "BCConverter") -> AST.ASTEnumInfo:
6569
return converter.convert_enuminfo(self)
6670

6771
def __str__(self) -> str:

chb/bctypes/BCEnumItem.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2022 Aarno Labs LLC
7+
# Copyright (c) 2022-2026 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -29,16 +29,17 @@
2929

3030
import chb.ast.ASTNode as AST
3131

32-
from chb.bctypes.BCConverter import BCConverter
3332
from chb.bctypes.BCDictionaryRecord import BCDictionaryRecord
3433

3534
import chb.util.fileutil as UF
3635
import chb.util.IndexedTable as IT
3736

3837
if TYPE_CHECKING:
38+
from chb.bctypes.BCConverter import BCConverter
3939
from chb.bctypes.BCDictionary import BCDictionary
40-
from chb.bctypes.BCTyp import BCTyp, BCTypArray, BCTypComp
4140
from chb.bctypes.BCExp import BCExp
41+
from chb.bctypes.BCTyp import BCTyp, BCTypArray, BCTypComp
42+
from chb.bctypes.BCVisitor import BCVisitor
4243

4344

4445
class BCEnumItem(BCDictionaryRecord):
@@ -57,7 +58,10 @@ def itemname(self) -> str:
5758
def itemexpr(self) -> "BCExp":
5859
return self.bcd.exp(self.args[0])
5960

60-
def convert(self, converter: BCConverter) -> AST.ASTEnumItem:
61+
def accept(self, visitor: "BCVisitor") -> None:
62+
return visitor.visit_enumitem(self)
63+
64+
def convert(self, converter: "BCConverter") -> AST.ASTEnumItem:
6165
return converter.convert_enumitem(self)
6266

6367
def __str__(self) -> str:

chb/bctypes/BCFieldInfo.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2021-2023 Aarno Labs LLC
7+
# Copyright (c) 2021-2026 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,6 @@
2929

3030
import chb.ast.ASTNode as AST
3131

32-
from chb.bctypes.BCConverter import BCConverter
3332
from chb.bctypes.BCDictionaryRecord import BCDictionaryRecord
3433

3534
import chb.util.fileutil as UF
@@ -38,8 +37,10 @@
3837
if TYPE_CHECKING:
3938
from chb.bctypes.BCAttribute import BCAttribute
4039
from chb.bctypes.BCAttrParam import BCAttrParam, BCAttrParamInt
40+
from chb.bctypes.BCConverter import BCConverter
4141
from chb.bctypes.BCDictionary import BCDictionary
4242
from chb.bctypes.BCTyp import BCTyp, BCTypArray, BCTypComp
43+
from chb.bctypes.BCVisitor import BCVisitor
4344

4445

4546
class BCFieldInfo(BCDictionaryRecord):
@@ -90,7 +91,10 @@ def alignment(self) -> int:
9091

9192
return self.fieldtype.alignment()
9293

93-
def convert(self, converter: BCConverter) -> AST.ASTFieldInfo:
94+
def accept(self, visitor: "BCVisitor") -> None:
95+
visitor.visit_fieldinfo(self)
96+
97+
def convert(self, converter: "BCConverter") -> AST.ASTFieldInfo:
9498
return converter.convert_fieldinfo(self)
9599

96100
def __str__(self) -> str:

chb/bctypes/BCFiles.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2021-2024 Aarno Labs LLC
7+
# Copyright (c) 2021-2026 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -49,6 +49,7 @@ class BCFiles:
4949

5050
def __init__(self, app: "AppAccess", xnode: ET.Element) -> None:
5151
self._app = app
52+
self._typeinfos: List[BCTypeInfo] = []
5253
self._gtypes: List[BCTyp] = []
5354
self._gcomptags: List[BCCompInfo] = []
5455
self._genumtags: List[BCEnumInfo] = []
@@ -66,6 +67,10 @@ def app(self) -> "AppAccess":
6667
def bcd(self) -> BCDictionary:
6768
return self.app.bcdictionary
6869

70+
@property
71+
def typeinfos(self) -> List[BCTypeInfo]:
72+
return self._typeinfos
73+
6974
@property
7075
def gtypes(self) -> List[BCTyp]:
7176
return self._gtypes

chb/bctypes/BCFunArgs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2021-2022 Aarno Labs LLC
7+
# Copyright (c) 2021-2026 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -60,6 +60,9 @@ def typ(self) -> "BCTyp":
6060
def is_leq(self, other: "BCFunArg") -> bool:
6161
return self.typ.is_leq(other.typ)
6262

63+
def accept(self, visitor: "BCVisitor") -> None:
64+
visitor.visit_funarg(self)
65+
6366
def convert(self, converter: "BCConverter") -> AST.ASTFunArg:
6467
return converter.convert_funarg(self)
6568

@@ -115,6 +118,9 @@ def is_scalar_argtypes(self) -> bool:
115118
def is_leq(self, other: "BCFunArgs") -> bool:
116119
return all(a.is_leq(o) for (a, o) in zip(self.funargs, other.funargs))
117120

121+
def accept(self, visitor: "BCVisitor") -> None:
122+
visitor.visit_funargs(self)
123+
118124
def convert(self, converter: "BCConverter") -> AST.ASTFunArgs:
119125
return converter.convert_funargs(self)
120126

0 commit comments

Comments
 (0)