Skip to content

Commit 6bf1cc2

Browse files
committed
USER: add option to enable/disable typing rules to userdata
1 parent 9fda727 commit 6bf1cc2

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

chb/app/CHVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
chbversion: str = "0.3.0-20250721"
1+
chbversion: str = "0.3.0-20250722"

chb/userdata/UserHints.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,53 @@ def __str__(self) -> str:
591591
+ (("; typename: " + self.typename) if self.typename else ""))
592592

593593

594+
class TypingRule:
595+
596+
def __init__(self, d: Dict[str, Any]) -> None:
597+
self._d = d
598+
599+
@property
600+
def typingrule(self) -> Dict[str, Any]:
601+
return self._d
602+
603+
@property
604+
def action(self) -> str:
605+
a = self.typingrule.get("action", "?")
606+
if a in ["enable", "disable"]:
607+
return a
608+
else:
609+
raise UF.CHBError("Action in typing rule not recognized: " + a)
610+
611+
@property
612+
def locs(self) -> List[str]:
613+
locs = self.typingrule.get("locs", [])
614+
if len(locs) == 0:
615+
raise UF.CHBError("No locations specified in typing rule")
616+
else:
617+
return locs
618+
619+
@property
620+
def name(self) -> str:
621+
if "name" in self.typingrule:
622+
return self.typingrule["name"]
623+
else:
624+
raise UF.CHBError("Name is missing in typing rule")
625+
626+
def to_xml(self, node: ET.Element) -> None:
627+
xtyrule = ET.Element("typingrule")
628+
node.append(xtyrule)
629+
xtyrule.set("name", self.name)
630+
xtyrule.set("action", self.action)
631+
xtyrule.set("locs", ",".join(self.locs))
632+
633+
def __str__(self) -> str:
634+
return (
635+
"action: " + self.action
636+
+ "; locs: [" + ", ".join(self.locs) + "]"
637+
+ "; name: " + self.name)
638+
639+
640+
594641
class FunctionAnnotation:
595642

596643
def __init__(self, fnannotation: Dict[str, Any]) -> None:
@@ -623,6 +670,14 @@ def register_variable_introductions(self) -> Dict[str, RegisterVarIntro]:
623670
result[rvi.iaddr] = rvi
624671
return result
625672

673+
@property
674+
def typingrules(self) -> List[TypingRule]:
675+
result: List[TypingRule] = []
676+
for d in self.fnannotation.get("typing-rules", []):
677+
tr = TypingRule(d)
678+
result.append(tr)
679+
return result
680+
626681
def has_register_variable_introduction(self, iaddr: str) -> bool:
627682
return iaddr in self.register_variable_introductions
628683

@@ -654,6 +709,11 @@ def to_xml(self, node: ET.Element) -> None:
654709
node.append(xregintros)
655710
for rvintro in self.register_variable_introductions.values():
656711
rvintro.to_xml(xregintros)
712+
if len(self.typingrules) > 0:
713+
xtypingrules = ET.Element("typing-rules")
714+
node.append(xtypingrules)
715+
for tr in self.typingrules:
716+
tr.to_xml(xtypingrules)
657717

658718
def __str__(self) -> str:
659719
lines: List[str] = []

0 commit comments

Comments
 (0)