From 1c5968beb66fc631e74fd2ddacaf4c4da52b90cc Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 25 Mar 2003 12:24:00 -0700 Subject: [PATCH] Evaluate pre-op expression types. --- evaluate.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/evaluate.c b/evaluate.c index c9c16a45..c962d961 100644 --- a/evaluate.c +++ b/evaluate.c @@ -160,7 +160,36 @@ static int evaluate_binop(struct expression *expr) static int evaluate_preop(struct expression *expr) { - return 0; + struct symbol *ctype = expr->unop->ctype; + + switch (expr->op) { + case '(': + expr->ctype = ctype; + return 1; + + case '*': + if (ctype->type != SYM_PTR) { + warn(expr->token, "cannot derefence this type"); + return 0; + } + expr->ctype = ctype->ctype.base_type; + return 1; + + case '&': { + struct symbol *symbol = alloc_symbol(expr->token, SYM_PTR); + symbol->ctype.base_type = ctype; + expr->ctype = symbol; + return 1; + } + + case '!': + expr->ctype = &bool_ctype; + return 1; + + default: + expr->ctype = ctype; + return 1; + } } static int evaluate_postop(struct expression *expr) -- 2.11.4.GIT