Skip to content

Commit cf7e02f

Browse files
committed
AST: prettyprint &a[0] as a
1 parent 31ea133 commit cf7e02f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

chb/ast/ASTCPrettyPrinter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,18 @@ def visit_question_expression(self, qexpr: AST.ASTQuestion) -> None:
555555
self.ccode.write(")")
556556

557557
def visit_address_of_expression(self, addressof: AST.ASTAddressOf) -> None:
558+
lval = addressof.lval
559+
560+
# print &a[0] as a
561+
if lval.offset.is_index_offset:
562+
lvaloffset = cast(AST.ASTIndexOffset, lval.offset)
563+
if lvaloffset.offset.is_no_offset:
564+
if lvaloffset.index_expr.is_integer_constant:
565+
ioffset = cast(AST.ASTIntegerConstant, lvaloffset.index_expr)
566+
if ioffset.cvalue == 0:
567+
lval.lhost.accept(self)
568+
return
569+
558570
self.ccode.write("&(")
559571
addressof.lval.accept(self)
560572
self.ccode.write(")")

0 commit comments

Comments
 (0)