commit 932a1b028c12d76474892d9e8d5d9bf095b48d34
parent 8bc8965c5eb6f58af551b073ec022a3a54b3df4d
Author: Eyal Sawady <ecs@d2evs.net>
Date: Mon, 22 Feb 2021 09:48:08 -0500
parse_scope_expression: implement indirect non-assignments
Diffstat:
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/parse.c b/src/parse.c
@@ -2042,8 +2042,6 @@ parse_scope_expression(struct lexer *lexer)
bool indirect = false;
switch (lex(lexer, &tok)) {
case T_TIMES: // *ptr = value (or unary-expression)
- // TODO: indirect access is untested (pending support for
- // dereferencing in unary-expression)
indirect = true;
break;
default:
@@ -2078,14 +2076,22 @@ parse_scope_expression(struct lexer *lexer)
unlex(lexer, &tok);
value = parse_complex_expression(lexer);
if (indirect) {
- assert(0); // TODO: Wrap value in unary dereference
+ struct ast_expression *deref = mkexpr(&value->loc);
+ deref->type = EXPR_UNARITHM;
+ deref->unarithm.op = UN_DEREF;
+ deref->unarithm.operand = value;
+ return deref;
}
return value;
case T_LBRACE:
unlex(lexer, &tok);
value = parse_expression_list(lexer);
if (indirect) {
- assert(0); // TODO: Wrap value in unary dereference
+ struct ast_expression *deref = mkexpr(&value->loc);
+ deref->type = EXPR_UNARITHM;
+ deref->unarithm.op = UN_DEREF;
+ deref->unarithm.operand = value;
+ return deref;
}
return value;
case T_DEFER:
@@ -2129,7 +2135,11 @@ parse_scope_expression(struct lexer *lexer)
unlex(lexer, &tok);
value = parse_bin_expression(lexer, value, 0);
if (indirect) {
- assert(0); // TODO: Wrap value in unary dereference
+ struct ast_expression *deref = mkexpr(&value->loc);
+ deref->type = EXPR_UNARITHM;
+ deref->unarithm.op = UN_DEREF;
+ deref->unarithm.operand = value;
+ return deref;
}
return value;
}