translate-c: group LHS of array access if necessary

This commit is contained in:
Evan Haas
2021-04-18 20:56:00 -07:00
committed by Veikka Tuominen
parent 55e6bd10fe
commit 63304a871e
2 changed files with 10 additions and 1 deletions

View File

@@ -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, "]");

View File

@@ -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;
\\}
, "");
}