translate-c: group LHS of array access if necessary
This commit is contained in:
committed by
Veikka Tuominen
parent
55e6bd10fe
commit
63304a871e
@@ -1665,7 +1665,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
|
||||
},
|
||||
.array_access => {
|
||||
const payload = node.castTag(.array_access).?.data;
|
||||
const lhs = try renderNode(c, payload.lhs);
|
||||
const lhs = try renderNodeGrouped(c, payload.lhs);
|
||||
const l_bracket = try c.addToken(.l_bracket, "[");
|
||||
const index_expr = try renderNode(c, payload.rhs);
|
||||
_ = try c.addToken(.r_bracket, "]");
|
||||
|
||||
@@ -1467,4 +1467,13 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
|
||||
cases.add("Render array LHS as grouped node if necessary",
|
||||
\\#include <stdlib.h>
|
||||
\\int main(void) {
|
||||
\\ int arr[] = {40, 41, 42, 43};
|
||||
\\ if ((arr + 1)[1] != 42) abort();
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user