Skip to content

Commit d0ac15e

Browse files
committed
AST: extend variables used to switch stmt
1 parent e611a6c commit d0ac15e

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
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-20251021"
1+
chbversion: str = "0.3.0-20251022"

chb/ast/ASTNode.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,24 +494,24 @@ def ctype(self, ctyper: "ASTCTyper") -> Optional["ASTTyp"]:
494494
return ctyper.ctype_block_stmt(self)
495495

496496
def is_empty(self) -> bool:
497-
return all(s.is_empty() for s in self.stmts)
497+
return self.is_stmt_label or all(s.is_empty() for s in self.stmts)
498498

499499
def address_taken(self) -> Set[str]:
500-
if self.is_empty():
500+
if self.is_stmt_label or self.is_empty():
501501
return set([])
502502
else:
503503
return self.stmts[0].address_taken().union(
504504
*(s.address_taken() for s in self.stmts[1:]))
505505

506506
def variables_used(self) -> Set[str]:
507-
if self.is_empty():
507+
if self.is_stmt_label or self.is_empty():
508508
return set([])
509509
else:
510510
return self.stmts[0].variables_used().union(
511511
*(s.variables_used() for s in self.stmts[1:]))
512512

513513
def callees(self) -> Set[str]:
514-
if self.is_empty():
514+
if self.is_stmt_label or self.is_empty():
515515
return set([])
516516
else:
517517
return self.stmts[0].callees().union(
@@ -749,6 +749,9 @@ def cases(self) -> "ASTStmt":
749749
def merge_address(self) -> Optional[str]:
750750
return self._mergeaddress
751751

752+
def variables_used(self) -> Set[str]:
753+
return self.cases.variables_used().union(self.switchexpr.variables_used())
754+
752755
def accept(self, visitor: "ASTVisitor") -> None:
753756
visitor.visit_switch_stmt(self)
754757

@@ -772,6 +775,9 @@ def __init__(self, locationid: int, tag: str) -> None:
772775
def is_stmt_label(self) -> bool:
773776
return True
774777

778+
def is_empty(self) -> bool:
779+
return True
780+
775781
@property
776782
def locationid(self) -> int:
777783
return self._locationid

chb/astinterface/ASTICodeTransformer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def __init__(
5151
variablesused: List[str] = []) -> None:
5252
self._astinterface = astinterface
5353
self._variablesused = variablesused
54+
chklogger.logger.info(
55+
"ASTICodeTransformer: variables used: [%s]",
56+
", ".join(self._variablesused))
5457

5558
@property
5659
def astinterface(self) -> "ASTInterface":
@@ -103,7 +106,8 @@ def transform_instruction_sequence_stmt(
103106
self.astinterface.has_ssa_value(str(instr.lhs))
104107
and not self.provenance.has_expose_instruction(instr.instrid)):
105108
chklogger.logger.info(
106-
"Remove [%s]: has ssa value", str(instr))
109+
"Remove [%s]: has ssa value: %s",
110+
str(instr), str(self.astinterface.get_ssa_value(str(instr.lhs))))
107111
elif self.provenance.has_lval_store(instr.lhs.lvalid):
108112
chklogger.logger.info(
109113
"Transform [%s]: lval_store", str(instr))
@@ -118,15 +122,15 @@ def transform_instruction_sequence_stmt(
118122
instrs.append(instr)
119123
elif str(instr.lhs) not in self.variables_used:
120124
chklogger.logger.info(
121-
"Remove [%s]: lhs is not used")
125+
"Remove [%s]: lhs is not used: %s", str(instr), str(instr.lhs))
122126
elif self.provenance.has_active_lval_defuse_high(instr.lhs.lvalid):
123127
chklogger.logger.info(
124128
"Transform [%s]: active lval_defuse_high: %s",
125129
str(instr),
126130
self.provenance.active_lval_defuse_high(instr.lhs.lvalid))
127131
instrs.append(instr)
128132
else:
129-
chklogger.logger.info("Transform [%s]: remove", str(instr))
133+
chklogger.logger.info("Transform [%s]: remove (by default)", str(instr))
130134
else:
131135
chklogger.logger.info(
132136
"Transform [%s]: include by default", str(instr))

0 commit comments

Comments
 (0)