Skip to content

Commit 50b89c6

Browse files
committed
CAPP: add types realign declarations
1 parent 50ad5ee commit 50b89c6

39 files changed

+2096
-2254
lines changed

chc/app/AssignDictionaryRecord.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2023 Aarno Labs LLC
7+
# Copyright (c) 2023-2024 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
@@ -40,7 +40,7 @@
4040

4141

4242
class AssignDictionaryRecord(IT.IndexedTableValue):
43-
"""Base class for all objects kep in the CFileAssignmentDictionary."""
43+
"""Base class for all objects kept in the CFileAssignmentDictionary."""
4444

4545
def __init__(
4646
self,

chc/app/CApplication.py

Lines changed: 330 additions & 376 deletions
Large diffs are not rendered by default.

chc/app/CAttributes.py

Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# The MIT License (MIT)
66
#
77
# Copyright (c) 2017-2020 Kestrel Technology LLC
8-
# Copyright (c) 2020-2022 Henny Sipma
9-
# Copyright (c) 2023 Aarno Labs
8+
# Copyright (c) 2020-2022 Henny B. Sipma
9+
# Copyright (c) 2023-2024 Aarno Labs LLC
1010
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a copy
1212
# of this software and associated documentation files (the "Software"), to deal
@@ -26,44 +26,15 @@
2626
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727
# SOFTWARE.
2828
# ------------------------------------------------------------------------------
29-
"""Object representation of CIL attrparam sum type
30-
31-
32-
cchlib/CCHBasicTypes.attrparam = predicate properties
33-
------------------------------
34-
| AInt of int is_int intvalue: int
35-
| AStr of string is_str stringvalue: str
36-
| ACons of string * attrparam list is_cons name: str
37-
params: List[CAttr]
38-
| ASizeOf of typ is_sizeof typ: CTyp
39-
| ASizeOfE of attrparam is_sizeofe param: CAttr
40-
| ASizeOfS of typsig is_sizeofs typsig: CTypsig
41-
| AAlignOf of typ is_alignof typ: CTyp
42-
| AAlignOfE of attrparam is_alignofe param: CAttr
43-
| AAlignOfS of typsig is_alignofs typsig: CTypsig
44-
| AUnOp of unop * attrparam is_unop op: str
45-
param: CAttr
46-
| ABinOp of binop * attrparam * attrparam is_binop binop: str
47-
param1: CAttr
48-
param2: CAttr
49-
| ADot of attrparam * string is_dot suffix: str
50-
param: CAttr
51-
| AStar of attrparam is_star param: CAttr
52-
| AAddrOf of attrparam is_addrof param: CAttr
53-
| AIndex of attrparam * attrparam is_index param1: CAttr
54-
param2: CAttr
55-
| AQuestion of attrparam * attrparam * attrparam is_question param1: CAttr
56-
param2: CAttr
57-
param3: CAttr
58-
59-
"""
29+
"""Object representation of CIL attrparam sum type."""
6030

6131
from typing import List, Tuple, TYPE_CHECKING
6232

6333
from chc.app.CDictionaryRecord import CDictionaryRecord, cdregistry
6434

6535
import chc.util.fileutil as UF
6636
import chc.util.IndexedTable as IT
37+
from chc.util.loggingutil import chklogger
6738

6839
if TYPE_CHECKING:
6940
from chc.app.CDictionary import CDictionary
@@ -171,7 +142,7 @@ def __str__(self) -> str:
171142
class CAttrStr(CAttr):
172143
"""String attribute.
173144
174-
args[0]: index in string table of string attribute
145+
* args[0]: index in string table of string attribute
175146
"""
176147

177148
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -193,8 +164,8 @@ def __str__(self) -> str:
193164
class CAttrCons(CAttr):
194165
"""Constructed attributes.
195166
196-
tags[1]: name
197-
args[0..]: indices of attribute parameters in cdictionary.
167+
* tags[1]: name
168+
* args[0..]: indices of attribute parameters in cdictionary.
198169
"""
199170

200171
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -220,7 +191,7 @@ def __str__(self) -> str:
220191
class CAttrSizeOf(CAttr):
221192
"""Attribute that describes the size of a type.
222193
223-
args[0]: index of target type in cdictionary
194+
* args[0]: index of target type in cdictionary
224195
"""
225196

226197
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -242,7 +213,7 @@ def __str__(self) -> str:
242213
class CAttrSizeOfE(CAttr):
243214
"""Size of an attribute parameter.
244215
245-
args[0]: index of argument parameter in cdictionary
216+
* args[0]: index of argument parameter in cdictionary
246217
"""
247218

248219
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -264,7 +235,7 @@ def __str__(self) -> str:
264235
class CAttrSizeOfS(CAttr):
265236
"""Replacement ASizeOf in type signatures.
266237
267-
args[0]: index of target typsig in cdictionary
238+
* args[0]: index of target typsig in cdictionary
268239
"""
269240

270241
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -286,7 +257,7 @@ def __str__(self) -> str:
286257
class CAttrAlignOf(CAttr):
287258
"""Alignment of a type.
288259
289-
args[0]: index of target type in cdictionary
260+
* args[0]: index of target type in cdictionary
290261
"""
291262

292263
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -308,7 +279,7 @@ def __str__(self) -> str:
308279
class CAttrAlignOfE(CAttr):
309280
"""Alignment of an attribute parameter.
310281
311-
args[0]: index of attribute parameter in cdictionary
282+
* args[0]: index of attribute parameter in cdictionary
312283
"""
313284

314285
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -330,7 +301,7 @@ def __str__(self) -> str:
330301
class CAttrAlignOfS(CAttr):
331302
"""Alignment of a type signature.
332303
333-
args[0]: target type signature
304+
* args[0]: target type signature
334305
"""
335306

336307
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -352,8 +323,8 @@ def __str__(self) -> str:
352323
class CAttrUnOp(CAttr):
353324
"""Unary attribute parameter operation.
354325
355-
tags[1]: operator
356-
args[0]: index of attribute parameter in cdictionary
326+
* tags[1]: operator
327+
* args[0]: index of attribute parameter in cdictionary
357328
"""
358329

359330
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -379,9 +350,9 @@ def __str__(self) -> str:
379350
class CAttrBinOp(CAttr):
380351
"""Binary attribute parameter operation.
381352
382-
tags[1]: operator
383-
args[0]: index of first attribute parameter in cdictionary
384-
args[1]: index of second attribute parameter in cdictionary
353+
* tags[1]: operator
354+
* args[0]: index of first attribute parameter in cdictionary
355+
* args[1]: index of second attribute parameter in cdictionary
385356
"""
386357

387358
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -419,8 +390,8 @@ def __str__(self) -> str:
419390
class CAttrDot(CAttr):
420391
"""Dot operator on attributes.
421392
422-
tags[1]: string suffix
423-
args[0]: index of attribute parameter in cdictionary
393+
* tags[1]: string suffix
394+
* args[0]: index of attribute parameter in cdictionary
424395
"""
425396

426397
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -446,29 +417,36 @@ def __str__(self) -> str:
446417
class CAttrStar(CAttr):
447418
"""Star operation on attribute.
448419
449-
args[0]: index of attribute parameter in cdictionary
420+
* args[0]: index of attribute parameter in cdictionary
450421
"""
451422

452423
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
453424
CAttr.__init__(self, cd, ixval)
454425

455426
@property
456427
def param(self) -> CAttr:
457-
return self.cd.get_attrparam(int(self.args[0]))
428+
chklogger.logger.info("Self-referential attribute (*)")
429+
if self.index == int(self.args[0]):
430+
return self
431+
else:
432+
return self.cd.get_attrparam(int(self.args[0]))
458433

459434
@property
460435
def is_star(self) -> bool:
461436
return True
462437

463438
def __str__(self) -> str:
464-
return "astar(" + str(self.param) + ")"
439+
if self.index == self.args[0]:
440+
return "astar()"
441+
else:
442+
return "astar(" + str(self.param) + ")"
465443

466444

467445
@cdregistry.register_tag("aaddrof", CAttr)
468446
class CAttrAddrOf(CAttr):
469447
"""Addressof operator on attribute.
470448
471-
args[0]: index of attribute parameter in cdictionary
449+
* args[0]: index of attribute parameter in cdictionary
472450
"""
473451

474452
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -490,8 +468,8 @@ def __str__(self) -> str:
490468
class CAttrIndex(CAttr):
491469
"""Index operation on attributes
492470
493-
args[0]: index of first attribute parameter in cdictionary
494-
args[1]: index of second attribute parameter in cdictionary
471+
* args[0]: index of first attribute parameter in cdictionary
472+
* args[1]: index of second attribute parameter in cdictionary
495473
"""
496474

497475
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:
@@ -517,9 +495,9 @@ def __str__(self) -> str:
517495
class CAttrQuestion(CAttr):
518496
"""Question operator on attributes
519497
520-
args[0]: index of first attribute paramter in cdictionary
521-
args[1]: index of second attribute parameter in cdictionary
522-
args[2]: index of third attribute parameter in cdictionary
498+
* args[0]: index of first attribute paramter in cdictionary
499+
* args[1]: index of second attribute parameter in cdictionary
500+
* args[2]: index of third attribute parameter in cdictionary
523501
"""
524502

525503
def __init__(self, cd: "CDictionary", ixval: IT.IndexedTableValue) -> None:

chc/app/CCompInfo.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# The MIT License (MIT)
66
#
77
# Copyright (c) 2017-2020 Kestrel Technology LLC
8-
# Copyright (c) 2020-2022 Henny Sipma
9-
# Copyright (c) 2023 Aarno Labs LLC
8+
# Copyright (c) 2020-2022 Henny B. Sipma
9+
# Copyright (c) 2023-2024 Aarno Labs LLC
1010
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a copy
1212
# of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,7 @@
2626
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727
# SOFTWARE.
2828
# ------------------------------------------------------------------------------
29+
"""Definition of a struct/union."""
2930

3031
from typing import cast, List, TYPE_CHECKING
3132

@@ -41,14 +42,14 @@
4142

4243

4344
class CCompInfo(CDeclarationsRecord):
44-
"""Struct definition.
45+
"""Struct/union definition.
4546
46-
tags[0]: cname ('?' for global struct)
47+
* tags[0]: cname ('?' for global struct)
4748
48-
args[0]: ckey (-1 for global struct)
49-
args[1]: isstruct
50-
args[2]: iattr (-1 for global struct)
51-
args[3..]: field indices
49+
* args[0]: ckey (-1 for global struct)
50+
* args[1]: isstruct
51+
* args[2]: iattr (-1 for global struct)
52+
* args[3..]: field indices
5253
"""
5354

5455
def __init__(
@@ -59,6 +60,14 @@ def __init__(
5960
def fields(self) -> List["CFieldInfo"]:
6061
return [self.decls.get_fieldinfo(i) for i in self.args[3:]]
6162

63+
@property
64+
def fieldcount(self) -> int:
65+
return len(self.fields)
66+
67+
@property
68+
def fieldnames(self) -> List[str]:
69+
return [f.fname for f in self.fields]
70+
6271
@property
6372
def is_struct(self) -> bool:
6473
return self.args[1] == 1

0 commit comments

Comments
 (0)