diff --git a/compiler/error.c b/compiler/error.c index a39b212..1335d4b 100644 --- a/compiler/error.c +++ b/compiler/error.c @@ -129,7 +129,8 @@ static ErrorDefinition dkc_error_message_format[] = { {"字符字面量中包含了2个以上的字符。"}, {"类型转换不匹配。"}, {"函数调用类型不匹配。"}, - {"返回值类型不匹配."}, + {"返回值类型不匹配。"}, + {"表达式的值没有被使用到。"}, {"dummy"}}; typedef struct diff --git a/compiler/error.h b/compiler/error.h index 89853a9..865f99c 100644 --- a/compiler/error.h +++ b/compiler/error.h @@ -133,6 +133,7 @@ typedef enum TYPE_CAST_MISMATCH_ERR, FUNCTION_CALL_TYPE_MISMATCH_ERR, RETURN_TYPE_MISMATCH_ERR, + EXPR_EVALUATED_BUT_NOT_USED, COMPILE_ERROR_COUNT_PLUS_1, } CompileError; diff --git a/compiler/fix_tree.c b/compiler/fix_tree.c index c136a42..f8d758b 100644 --- a/compiler/fix_tree.c +++ b/compiler/fix_tree.c @@ -797,6 +797,18 @@ fix_assign_stmt(Block *current_block, Statement *stmt) } } +static void +fix_expression_stmt(Block *current_block, Statement *stmt) +{ + stmt->u.expr_s = fix_expression(current_block, stmt->u.expr_s); + if (stmt->u.expr_s->kind != FUNC_CALL_EXPRESSION) + { + compile_error(stmt->line_number, + EXPR_EVALUATED_BUT_NOT_USED, + MESSAGE_ARGUMENT_END); + } +} + static void fix_statement(Block *current_block, Statement *statement, FuncDefinition *fd) { @@ -814,6 +826,9 @@ fix_statement(Block *current_block, Statement *statement, FuncDefinition *fd) case ASSIGN_STATEMENT: fix_assign_stmt(current_block, statement); break; + case EXPRESSION_STATEMENT: + fix_expression_stmt(current_block, statement); + break; default: DBG_assert(0, ("bad case. kind..%d\n", statement->kind)); }