Skip to content

Commit 38c022f

Browse files
committed
AST: add prettyprinter support for baseptr array expr
1 parent ef75640 commit 38c022f

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

chb/ast/ASTCPrettyPrinter.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,21 @@ def visit_variable(self, var: AST.ASTVariable) -> None:
495495

496496
def visit_memref(self, memref: AST.ASTMemRef) -> None:
497497
if memref.memexp.is_ast_addressof:
498-
memexp = cast(AST.ASTAddressOf, memref.memexp)
499-
memexp.lval.accept(self)
498+
memexpa = cast(AST.ASTAddressOf, memref.memexp)
499+
memexpa.lval.accept(self)
500+
elif memref.memexp.is_ast_binary_op:
501+
memexpb = cast(AST.ASTBinaryOp, memref.memexp)
502+
exp1 = memexpb.exp1
503+
exp2 = memexpb.exp2
504+
if exp1.is_ast_lval_expr:
505+
exp1.accept(self)
506+
self.ccode.write("[")
507+
exp2.accept(self)
508+
self.ccode.write("]")
509+
else:
510+
self.ccode.write("(*(")
511+
memref.memexp.accept(self)
512+
self.ccode.write("))")
500513
else:
501514
self.ccode.write("(*(")
502515
memref.memexp.accept(self)

chb/invariants/XXprUtil.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,9 @@ def memory_variable_to_lval_expression(
468468
offset = cast("VMemoryOffsetBasePtrArrayIndexOffset", offset)
469469
(ptroffset, astoffset) = base_ptr_array_offset_to_ast_offset(
470470
offset, xdata, iaddr, astree, anonymous=anonymous)
471-
if ptroffset.is_integer_constant_zero:
472-
return astree.mk_memref_expr(
473-
astlval, offset=astoffset, anonymous=anonymous)
474-
else:
475-
ptrexpr = astree.mk_binary_op("plus", ptroffset, astlval)
476-
return astree.mk_memref_expr(
477-
ptrexpr, offset=astoffset, anonymous=anonymous)
471+
ptrexpr = astree.mk_binary_op("plus", astlval, ptroffset)
472+
return astree.mk_memref_expr(
473+
ptrexpr, offset=astoffset, anonymous=anonymous)
478474

479475
name = str(base)
480476

0 commit comments

Comments
 (0)