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
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
6131from typing import List , Tuple , TYPE_CHECKING
6232
6333from chc .app .CDictionaryRecord import CDictionaryRecord , cdregistry
6434
6535import chc .util .fileutil as UF
6636import chc .util .IndexedTable as IT
37+ from chc .util .loggingutil import chklogger
6738
6839if TYPE_CHECKING :
6940 from chc .app .CDictionary import CDictionary
@@ -171,7 +142,7 @@ def __str__(self) -> str:
171142class 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:
193164class 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:
220191class 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:
242213class 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:
264235class 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:
286257class 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:
308279class 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:
330301class 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:
352323class 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:
379350class 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:
419390class 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:
446417class 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 )
468446class 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:
490468class 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:
517495class 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 :
0 commit comments