support functions declared in local scope
[cparser] / ast2firm.c
index 714e013..d063329 100644 (file)
@@ -3244,7 +3244,11 @@ static void create_local_declaration(declaration_t *declaration)
        case STORAGE_CLASS_AUTO:
        case STORAGE_CLASS_REGISTER:
                if(is_type_function(type)) {
-                       panic("nested functions not supported yet");
+                       if(declaration->init.statement != NULL) {
+                               panic("nested functions not supported yet");
+                       } else {
+                               get_function_entity(declaration);
+                       }
                } else {
                        create_local_variable(declaration);
                }
@@ -3841,6 +3845,14 @@ static int count_decls_in_expression(const expression_t *expression) {
        }
        EXPR_UNARY_CASES
                return count_decls_in_expression(expression->unary.value);
+       case EXPR_CALL: {
+               int count = 0;
+               call_argument_t *argument = expression->call.arguments;
+               for( ; argument != NULL; argument = argument->next) {
+                       count += count_decls_in_expression(argument->expression);
+               }
+               return count;
+       }
 
        default:
                break;
@@ -4188,8 +4200,6 @@ create_var:
                                                  var_type);
                        set_entity_visibility(declaration->v.entity, vis);
 
-                       current_ir_graph = get_const_code_irg();
-                       create_initializer(declaration);
                        return;
 
                case STORAGE_CLASS_TYPEDEF:
@@ -4222,7 +4232,7 @@ static void scope_to_firm(scope_t *scope)
                }
        }
 
-       /* second pass: create code */
+       /* second pass: create code/initializers */
        declaration = scope->declarations;
        for( ; declaration != NULL; declaration = declaration->next) {
                if(declaration->namespc != NAMESPACE_NORMAL)
@@ -4234,10 +4244,14 @@ static void scope_to_firm(scope_t *scope)
                        continue;
 
                type_t *type = declaration->type;
-               if(type->kind != TYPE_FUNCTION)
-                       continue;
-
-               create_function(declaration);
+               if(type->kind == TYPE_FUNCTION) {
+                       create_function(declaration);
+               } else {
+                       assert(declaration->declaration_kind
+                                       == DECLARATION_KIND_GLOBAL_VARIABLE);
+                       current_ir_graph = get_const_code_irg();
+                       create_initializer(declaration);
+               }
        }
 }