Allow calling function pointers.
authorChristoph Mallon <christoph.mallon@gmx.de>
Sat, 17 Nov 2007 19:27:50 +0000 (19:27 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sat, 17 Nov 2007 19:27:50 +0000 (19:27 +0000)
[r18457]

parser.c

index dbc6630..61b2774 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2643,20 +2643,24 @@ static expression_t *parse_call_expression(unsigned precedence,
 
        function_type_t *function_type;
        type_t          *type = expression->datatype;
-       if(type->type != TYPE_FUNCTION) {
-               /* TODO calling pointers to functions is ok */
+       if (type->type == TYPE_FUNCTION) {
+               function_type             = (function_type_t*) type;
+               call->expression.datatype = function_type->result_type;
+       } else if (type->type == TYPE_POINTER &&
+                  ((pointer_type_t*)type)->points_to->type == TYPE_FUNCTION) {
+               pointer_type_t *const ptr_type = (pointer_type_t*)type;
+               function_type                  = (function_type_t*)ptr_type->points_to;
+               call->expression.datatype      = function_type->result_type;
+       } else {
                parser_print_error_prefix();
                fputs("called object '", stderr);
                print_expression(expression);
                fputs("' (type ", stderr);
                print_type_quoted(type);
-               fputs("is not a function\n", stderr);
+               fputs("is not a function\n", stderr);
 
                function_type             = NULL;
                call->expression.datatype = NULL;
-       } else {
-               function_type             = (function_type_t*) type;
-               call->expression.datatype = function_type->result_type;
        }
 
        /* parse arguments */