rename method to function
authorMatthias Braun <matze@braunis.de>
Mon, 12 Nov 2007 19:48:01 +0000 (19:48 +0000)
committerMatthias Braun <matze@braunis.de>
Mon, 12 Nov 2007 19:48:01 +0000 (19:48 +0000)
[r18375]

ast.c
ast.h
ast2firm.c
ast_t.h
parser.c
type.c
type.h
type_hash.c
type_t.h
write_fluffy.c

diff --git a/ast.c b/ast.c
index f70f743..d8b34d8 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -70,7 +70,7 @@ static void print_string_literal(const string_literal_t *string_literal)
 
 static void print_call_expression(const call_expression_t *call)
 {
-       print_expression(call->method);
+       print_expression(call->function);
        fprintf(out, "(");
        call_argument_t *argument = call->arguments;
        int              first    = 1;
@@ -517,7 +517,7 @@ static void print_normal_declaration(const declaration_t *declaration)
        print_storage_class(declaration->storage_class);
        print_type_ext(declaration->type, declaration->symbol,
                       &declaration->context);
-       if(declaration->type->type == TYPE_METHOD) {
+       if(declaration->type->type == TYPE_FUNCTION) {
                if(declaration->init.statement != NULL) {
                        fputs("\n", out);
                        print_statement(declaration->init.statement);
diff --git a/ast.h b/ast.h
index 2ec6b19..76c7a51 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -45,8 +45,6 @@ typedef struct do_while_statement_t         do_while_statement_t;
 typedef struct for_statement_t              for_statement_t;
 
 typedef struct translation_unit_t           translation_unit_t;
-typedef struct method_t                     method_t;
-typedef struct global_variable_t            global_variable_t;
 
 void  init_ast(void);
 void  exit_ast(void);
index 5f6d81e..7039327 100644 (file)
@@ -3,6 +3,8 @@
 #define _GNU_SOURCE
 
 #include <assert.h>
+#include <string.h>
+
 #include <libfirm/firm.h>
 #include <libfirm/adt/obst.h>
 
@@ -248,8 +250,8 @@ static unsigned get_type_size(type_t *type)
        case TYPE_COMPOUND_UNION:
        case TYPE_COMPOUND_STRUCT:
                return get_compound_type_size((compound_type_t*) type);
-       case TYPE_METHOD:
-               /* just a pointer to the method */
+       case TYPE_FUNCTION:
+               /* just a pointer to the function */
                return get_mode_size_bytes(mode_P_code);
        case TYPE_POINTER:
                return get_mode_size_bytes(mode_P_data);
@@ -264,11 +266,11 @@ static unsigned get_type_size(type_t *type)
        panic("Trying to determine size of invalid type");
 }
 
-static unsigned count_parameters(const method_type_t *method_type)
+static unsigned count_parameters(const function_type_t *function_type)
 {
        unsigned count = 0;
 
-       method_parameter_t *parameter = method_type->parameters;
+       function_parameter_t *parameter = function_type->parameters;
        for ( ; parameter != NULL; parameter = parameter->next) {
                ++count;
        }
@@ -290,12 +292,12 @@ static ir_type *get_atomic_type(type2firm_env_t *env, const atomic_type_t *type)
 }
 
 static ir_type *get_method_type(type2firm_env_t *env,
-                                const method_type_t *method_type)
+                                const function_type_t *function_type)
 {
-       type_t  *result_type  = method_type->result_type;
+       type_t  *result_type  = function_type->result_type;
 
-       ident   *id           = unique_ident("methodtype");
-       int      n_parameters = count_parameters(method_type);
+       ident   *id           = unique_ident("functiontype");
+       int      n_parameters = count_parameters(function_type);
        int      n_results    = result_type == type_void ? 0 : 1;
        ir_type *irtype       = new_type_method(id, n_parameters, n_results);
 
@@ -304,15 +306,15 @@ static ir_type *get_method_type(type2firm_env_t *env,
                set_method_res_type(irtype, 0, restype);
        }
 
-       method_parameter_t *parameter = method_type->parameters;
-       int                 n         = 0;
+       function_parameter_t *parameter = function_type->parameters;
+       int                   n         = 0;
        for( ; parameter != NULL; parameter = parameter->next) {
                ir_type *p_irtype = _get_ir_type(env, parameter->type);
                set_method_param_type(irtype, n, p_irtype);
                ++n;
        }
 
-       if(method_type->variadic) {
+       if(function_type->variadic) {
                set_method_variadicity(irtype, variadicity_variadic);
        }
 
@@ -475,8 +477,8 @@ static ir_type *_get_ir_type(type2firm_env_t *env, type_t *type)
        case TYPE_ATOMIC:
                firm_type = get_atomic_type(env, (atomic_type_t*) type);
                break;
-       case TYPE_METHOD:
-               firm_type = get_method_type(env, (method_type_t*) type);
+       case TYPE_FUNCTION:
+               firm_type = get_method_type(env, (function_type_t*) type);
                break;
        case TYPE_POINTER:
                firm_type = get_pointer_type(env, (pointer_type_t*) type);
@@ -553,11 +555,201 @@ static ir_entity* get_entity_function(declaration_t *declaration)
        return entity;
 }
 
+
+
+static dbg_info *get_dbg_info(const source_position_t *pos)
+{
+       return (dbg_info*) pos;
+}
+
+static ir_node *const_to_firm(const const_t *cnst)
+{
+       dbg_info *dbgi = get_dbg_info(&cnst->expression.source_position);
+       ir_mode  *mode = get_ir_mode(cnst->expression.datatype);
+
+       tarval   *tv;
+       if(mode_is_float(mode)) {
+               tv = new_tarval_from_double(cnst->v.float_value, mode);
+       } else {
+               tv = new_tarval_from_long(cnst->v.int_value, mode);
+       }
+
+       return new_d_Const(dbgi, mode, tv);
+}
+
+static ir_node *string_literal_to_firm(const string_literal_t* literal)
+{
+       ir_type   *global_type = get_glob_type();
+       ir_type   *type        = new_type_array(unique_ident("strtype"), 1,
+                                               ir_type_const_char);
+
+       ir_entity *ent = new_entity(global_type, unique_ident("Lstr"), type);
+       set_entity_variability(ent, variability_constant);
+
+       ir_type    *elem_type = ir_type_const_char;
+       ir_mode    *mode      = get_type_mode(elem_type);
+
+       const char *string = literal->value;
+       size_t      slen   = strlen(string) + 1;
+
+       set_array_lower_bound_int(type, 0, 0);
+       set_array_upper_bound_int(type, 0, slen);
+       set_type_size_bytes(type, slen);
+       set_type_state(type, layout_fixed);
+
+       tarval **tvs = xmalloc(slen * sizeof(tvs[0]));
+       for(size_t i = 0; i < slen; ++i) {
+               tvs[i] = new_tarval_from_long(string[i], mode);
+       }
+
+       set_array_entity_values(ent, tvs, slen);
+       free(tvs);
+
+       dbg_info *dbgi = get_dbg_info(&literal->expression.source_position);
+
+       union symconst_symbol sym;
+       sym.entity_p = ent;
+       return new_d_SymConst(dbgi, sym, symconst_addr_ent);
+}
+
+#if 0
+static ir_node *call_expression_to_firm(const call_expression_t *call)
+{
+       expression_t  *function = call->function;
+       ir_node       *callee   = expression_to_firm(function);
+
+       assert(function->datatype->type == TYPE_FUNCTION);
+       pointer_type_t *pointer_type = (pointer_type_t*) function->datatype;
+       type_t         *points_to    = pointer_type->points_to;
+
+       assert(points_to->type == TYPE_FUNCTION);
+       method_type_t *method_type     = (method_type_t*) points_to;
+       ir_type       *ir_method_type  = get_ir_type((type_t*) method_type);
+       ir_type       *new_method_type = NULL;
+
+       int              n_parameters = 0;
+       call_argument_t *argument     = call->arguments;
+       while(argument != NULL) {
+               n_parameters++;
+               argument = argument->next;
+       }
+
+       if(method_type->variable_arguments) {
+               /* we need to construct a new method type matching the call
+                * arguments... */
+               new_method_type = new_type_method(unique_ident("calltype"),
+                                                 n_parameters,
+                                                 get_method_n_ress(ir_method_type));
+               set_method_calling_convention(new_method_type,
+                              get_method_calling_convention(ir_method_type));
+               set_method_additional_properties(new_method_type,
+                              get_method_additional_properties(ir_method_type));
+
+               for(int i = 0; i < get_method_n_ress(ir_method_type); ++i) {
+                       set_method_res_type(new_method_type, i,
+                                           get_method_res_type(ir_method_type, i));
+               }
+       }
+       ir_node *in[n_parameters];
+
+       argument = call->arguments;
+       int n = 0;
+       while(argument != NULL) {
+               expression_t *expression = argument->expression;
+
+               ir_node *arg_node = expression_to_firm(expression);
+
+               in[n] = arg_node;
+               if(new_method_type != NULL) {
+                       ir_type *irtype = get_ir_type(expression->datatype);
+                       set_method_param_type(new_method_type, n, irtype);
+               }
+
+               argument = argument->next;
+               n++;
+       }
+
+       if(new_method_type != NULL)
+               ir_method_type = new_method_type;
+
+       dbg_info *dbgi  = get_dbg_info(&call->expression.source_position);
+       ir_node  *store = get_store();
+       ir_node  *node  = new_d_Call(dbgi, store, callee, n_parameters, in,
+                                    ir_method_type);
+       ir_node  *mem   = new_d_Proj(dbgi, node, mode_M, pn_Call_M_regular);
+       set_store(mem);
+
+       type_t  *result_type = method_type->result_type;
+       ir_node *result      = NULL;
+       if(result_type->type != TYPE_VOID) {
+               ir_mode *mode    = get_ir_mode(result_type);
+               ir_node *resproj = new_d_Proj(dbgi, node, mode_T, pn_Call_T_result);
+               result           = new_d_Proj(dbgi, resproj, mode, 0);
+       }
+
+       return result;
+}
+#endif
+
+static ir_node *expression_to_firm(expression_t *expression)
+{
+       switch(expression->type) {
+       case EXPR_CONST:
+               return const_to_firm((const const_t*) expression);
+       case EXPR_STRING_LITERAL:
+               return string_literal_to_firm((const string_literal_t*) expression);
+       default:
+               break;
+       }
+       panic("unsupported expression found");
+}
+
+
+
+static void statement_to_firm(statement_t *statement);
+
+static void return_statement_to_firm(return_statement_t *statement)
+{
+       dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
+       ir_node  *ret;
+
+       if(statement->return_value != NULL) {
+               ir_node *retval = expression_to_firm(statement->return_value);
+               ir_node *in[1];
+
+               in[0] = retval;
+               ret   = new_d_Return(dbgi, get_store(), 1, in);
+       } else {
+               ret   = new_d_Return(dbgi, get_store(), 0, NULL);
+       }
+       ir_node *end_block = get_irg_end_block(current_ir_graph);
+       add_immBlock_pred(end_block, ret);
+
+       set_cur_block(NULL);
+}
+
+static void compound_statement_to_firm(compound_statement_t *compound)
+{
+       statement_t *statement = compound->statements;
+       for( ; statement != NULL; statement = statement->next) {
+               //context2firm(&statement->context);
+               statement_to_firm(statement);
+       }
+}
+
 static void statement_to_firm(statement_t *statement)
 {
-       (void) statement;
-       (void) get_type_size;
-       /* TODO */
+       switch(statement->type) {
+       case STATEMENT_COMPOUND:
+               compound_statement_to_firm((compound_statement_t*) statement);
+               return;
+       case STATEMENT_RETURN:
+               return_statement_to_firm((return_statement_t*) statement);
+               return;
+       default:
+               break;
+       }
+       panic("Statement not implemented\n");
 }
 
 static int get_function_n_local_vars(declaration_t *declaration)
@@ -573,24 +765,54 @@ static void create_function(declaration_t *declaration)
 
        //context2firm(declaration->context);
 
-       if(declaration->init.statement) {
-               int        n_local_vars = get_function_n_local_vars(declaration);
-               ir_graph  *irg          = new_ir_graph(entity, n_local_vars);
-               ir_node   *first_block  = get_cur_block();
+       if(declaration->init.statement == NULL)
+               return;
+
+       int        n_local_vars = get_function_n_local_vars(declaration);
+       ir_graph  *irg          = new_ir_graph(entity, n_local_vars);
+       ir_node   *first_block  = get_cur_block();
 
-               statement_to_firm(declaration->init.statement);
+       statement_to_firm(declaration->init.statement);
 
-               ir_node *end_block = get_irg_end_block(irg);
+       ir_node *end_block = get_irg_end_block(irg);
+
+       /* do we have a return statement yet? */
+       if(get_cur_block() != NULL) {
+               ir_node *ret = new_Return(get_store(), 0, NULL);
+               add_immBlock_pred(end_block, ret);
+       }
 
-               /* do we have a return statement yet? */
-               if(get_cur_block() != NULL) {
-                       ir_node *ret = new_Return(get_store(), 0, NULL);
-                       add_immBlock_pred(end_block, ret);
+       mature_immBlock(first_block);
+       mature_immBlock(end_block);
+
+       irg_finalize_cons(irg);
+
+       /* finalize the frame type */
+       ir_type *frame_type = get_irg_frame_type(irg);
+       int      n          = get_compound_n_members(frame_type);
+       int      align_all  = 4;
+       int      offset     = 0;
+       for(int i = 0; i < n; ++i) {
+               ir_entity *entity      = get_compound_member(frame_type, i);
+               ir_type   *entity_type = get_entity_type(entity);
+
+               int align = get_type_alignment_bytes(entity_type);
+               if(align > align_all)
+                       align_all = align;
+               int misalign = 0;
+               if(align > 0) {
+                       misalign  = offset % align;
+                       offset   += misalign;
                }
 
-               mature_immBlock(first_block);
-               mature_immBlock(end_block);
+               set_entity_offset(entity, offset);
+               offset += get_type_size_bytes(entity_type);
        }
+       set_type_size_bytes(frame_type, offset);
+       set_type_alignment_bytes(frame_type, align_all);
+       set_type_state(frame_type, layout_fixed);
+
+       irg_vrfy(irg);
 }
 
 static void context_to_firm(context_t *context)
@@ -598,7 +820,7 @@ static void context_to_firm(context_t *context)
        declaration_t *declaration = context->declarations;
        for( ; declaration != NULL; declaration = declaration->next) {
                type_t *type = declaration->type;
-               if(type->type == TYPE_METHOD) {
+               if(type->type == TYPE_FUNCTION) {
                        create_function(declaration);
                } else {
                        /* TODO... */
@@ -608,5 +830,8 @@ static void context_to_firm(context_t *context)
 
 void translation_unit_to_firm(translation_unit_t *unit)
 {
+       /* remove me later TODO FIXME */
+       (void) get_type_size;
+
        context_to_firm(& unit->context);
 }
diff --git a/ast_t.h b/ast_t.h
index 5d40c57..3a090c4 100644 (file)
--- a/ast_t.h
+++ b/ast_t.h
@@ -73,7 +73,7 @@ struct call_argument_t {
 
 struct call_expression_t {
        expression_t     expression;
-       expression_t    *method;
+       expression_t    *function;
        call_argument_t *arguments;
 };
 
index 2c46311..44b5dc6 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1230,7 +1230,7 @@ static declaration_t *parse_parameter(void)
        return declaration;
 }
 
-static declaration_t *parse_parameters(method_type_t *type)
+static declaration_t *parse_parameters(function_type_t *type)
 {
        if(token.type == T_IDENTIFIER) {
                symbol_t      *symbol = token.v.symbol;
@@ -1250,11 +1250,11 @@ static declaration_t *parse_parameters(method_type_t *type)
                return NULL;
        }
 
-       declaration_t      *declarations = NULL;
-       declaration_t      *declaration;
-       declaration_t      *last_declaration = NULL;
-       method_parameter_t *parameter;
-       method_parameter_t *last_parameter = NULL;
+       declaration_t        *declarations = NULL;
+       declaration_t        *declaration;
+       declaration_t        *last_declaration = NULL;
+       function_parameter_t *parameter;
+       function_parameter_t *last_parameter = NULL;
 
        while(true) {
                switch(token.type) {
@@ -1293,7 +1293,7 @@ static declaration_t *parse_parameters(method_type_t *type)
 
 typedef enum {
        CONSTRUCT_POINTER,
-       CONSTRUCT_METHOD,
+       CONSTRUCT_FUNCTION,
        CONSTRUCT_ARRAY
 } construct_type_type_t;
 
@@ -1309,10 +1309,10 @@ struct parsed_pointer_t {
        type_qualifier_t  type_qualifiers;
 };
 
-typedef struct construct_method_type_t construct_method_type_t;
-struct construct_method_type_t {
-       construct_type_t  construct_type;
-       method_type_t    *method_type;
+typedef struct construct_function_type_t construct_function_type_t;
+struct construct_function_type_t {
+       construct_type_t    construct_type;
+       function_type_t    *function_type;
 };
 
 typedef struct parsed_array_t parsed_array_t;
@@ -1374,28 +1374,27 @@ static construct_type_t *parse_array_declarator(void)
        return (construct_type_t*) array;
 }
 
-static construct_type_t *parse_method_declarator(declaration_t *declaration)
+static construct_type_t *parse_function_declarator(declaration_t *declaration)
 {
        eat('(');
 
-       method_type_t *method_type
-               = allocate_type_zero(sizeof(method_type[0]));
-       method_type->type.type   = TYPE_METHOD;
+       function_type_t *type = allocate_type_zero(sizeof(type[0]));
+       type->type.type       = TYPE_FUNCTION;
 
-       declaration_t *parameters = parse_parameters(method_type);
+       declaration_t *parameters = parse_parameters(type);
        if(declaration != NULL) {
                declaration->context.declarations = parameters;
        }
 
-       construct_method_type_t *construct_method_type =
-               obstack_alloc(&temp_obst, sizeof(construct_method_type[0]));
-       memset(construct_method_type, 0, sizeof(construct_method_type[0]));
-       construct_method_type->construct_type.type = CONSTRUCT_METHOD;
-       construct_method_type->method_type         = method_type;
+       construct_function_type_t *construct_function_type =
+               obstack_alloc(&temp_obst, sizeof(construct_function_type[0]));
+       memset(construct_function_type, 0, sizeof(construct_function_type[0]));
+       construct_function_type->construct_type.type = CONSTRUCT_FUNCTION;
+       construct_function_type->function_type       = type;
 
        expect(')');
 
-       return (construct_type_t*) construct_method_type;
+       return (construct_type_t*) construct_function_type;
 }
 
 static construct_type_t *parse_inner_declarator(declaration_t *declaration,
@@ -1445,7 +1444,7 @@ static construct_type_t *parse_inner_declarator(declaration_t *declaration,
                construct_type_t *type;
                switch(token.type) {
                case '(':
-                       type = parse_method_declarator(declaration);
+                       type = parse_function_declarator(declaration);
                        break;
                case '[':
                        type = parse_array_declarator();
@@ -1482,20 +1481,20 @@ static type_t *construct_declarator_type(construct_type_t *construct_list,
 {
        construct_type_t *iter = construct_list;
        for( ; iter != NULL; iter = iter->next) {
-               parsed_pointer_t        *parsed_pointer;
-               parsed_array_t          *parsed_array;
-               construct_method_type_t *construct_method_type;
-               method_type_t           *method_type;
-               pointer_type_t          *pointer_type;
-               array_type_t            *array_type;
+               parsed_pointer_t          *parsed_pointer;
+               parsed_array_t            *parsed_array;
+               construct_function_type_t *construct_function_type;
+               function_type_t           *function_type;
+               pointer_type_t            *pointer_type;
+               array_type_t              *array_type;
 
                switch(iter->type) {
-               case CONSTRUCT_METHOD:
-                       construct_method_type = (construct_method_type_t*) iter;
-                       method_type           = construct_method_type->method_type;
+               case CONSTRUCT_FUNCTION:
+                       construct_function_type = (construct_function_type_t*) iter;
+                       function_type           = construct_function_type->function_type;
 
-                       method_type->result_type = type;
-                       type                     = (type_t*) method_type;
+                       function_type->result_type = type;
+                       type                       = (type_t*) function_type;
                        break;
 
                case CONSTRUCT_POINTER:
@@ -1606,7 +1605,7 @@ static void parse_init_declarators(const declaration_specifiers_t *specifiers)
                if(token.type == '=') {
                        next_token();
 
-                       /* TODO: check that this is an allowed type (esp. no method type) */
+                       /* TODO: check that this is an allowed type (no function type) */
 
                        if(declaration->init.initializer != NULL) {
                                parser_error_multiple_definition(declaration, ndeclaration);
@@ -1614,11 +1613,11 @@ static void parse_init_declarators(const declaration_specifiers_t *specifiers)
 
                        ndeclaration->init.initializer = parse_initializer();
                } else if(token.type == '{') {
-                       if(declaration->type->type != TYPE_METHOD) {
+                       if(declaration->type->type != TYPE_FUNCTION) {
                                parser_print_error_prefix();
                                fprintf(stderr, "Declarator ");
                                print_type_ext(declaration->type, declaration->symbol, NULL);
-                               fprintf(stderr, " is not a method type.\n");
+                               fprintf(stderr, " has a body but is not a function type.\n");
                                eat_block();
                                continue;
                        }
@@ -1815,15 +1814,15 @@ static expression_t *parse_float_const(void)
 static declaration_t *create_implicit_function(symbol_t *symbol,
                const source_position_t source_position)
 {
-       method_type_t *method_type = allocate_type_zero(sizeof(method_type));
+       function_type_t *function_type = allocate_type_zero(sizeof(function_type));
 
-       method_type->type.type              = TYPE_METHOD;
-       method_type->result_type            = type_int;
-       method_type->unspecified_parameters = true;
+       function_type->type.type              = TYPE_FUNCTION;
+       function_type->result_type            = type_int;
+       function_type->unspecified_parameters = true;
 
-       type_t *type = typehash_insert((type_t*) method_type);
-       if(type != (type_t*) method_type) {
-               free_type(method_type);
+       type_t *type = typehash_insert((type_t*) function_type);
+       if(type != (type_t*) function_type) {
+               free_type(function_type);
        }
 
        declaration_t *declaration = allocate_ast_zero(sizeof(declaration[0]));
@@ -2243,7 +2242,7 @@ static expression_t *parse_call_expression(unsigned precedence,
        call_expression_t *call = allocate_ast_zero(sizeof(call[0]));
 
        call->expression.type     = EXPR_CALL;
-       call->method              = expression;
+       call->function            = expression;
 
        /* parse arguments */
        eat('(');
@@ -2277,14 +2276,15 @@ static expression_t *parse_call_expression(unsigned precedence,
                        type = pointer->points_to;
                }
 
-               if(type == NULL || type->type != TYPE_METHOD) {
+               if(type == NULL || type->type != TYPE_FUNCTION) {
                        parser_print_error_prefix();
-                       fprintf(stderr, "expected a method type for call but found type ");
+                       fprintf(stderr, "expected a function type for call but found "
+                               "type ");
                        print_type(expression->datatype);
                        fprintf(stderr, "\n");
                } else {
-                       method_type_t *method_type = (method_type_t*) type;
-                       call->expression.datatype  = method_type->result_type;
+                       function_type_t *function_type = (function_type_t*) type;
+                       call->expression.datatype      = function_type->result_type;
                }
        }
 
diff --git a/type.c b/type.c
index 4c1612c..3531655 100644 (file)
--- a/type.c
+++ b/type.c
@@ -78,8 +78,7 @@ void print_atomic_type(const atomic_type_t *type)
        fputs(s, out);
 }
 
-static
-void print_method_type_pre(const method_type_t *type)
+static void print_function_type_pre(const function_type_t *type)
 {
        print_type_qualifiers(type->type.qualifiers);
 
@@ -89,8 +88,8 @@ void print_method_type_pre(const method_type_t *type)
        fputc('(', out);
 }
 
-static
-void print_method_type_post(const method_type_t *type, const context_t *context)
+static void print_function_type_post(const function_type_t *type,
+                                     const context_t *context)
 {
        /* TODO: don't emit braces if we're the toplevel type... */
        intern_print_type_post(type->result_type);
@@ -100,7 +99,7 @@ void print_method_type_post(const method_type_t *type, const context_t *context)
 
        int                 first     = 1;
        if(context == NULL) {
-               method_parameter_t *parameter = type->parameters;
+               function_parameter_t *parameter = type->parameters;
                for( ; parameter != NULL; parameter = parameter->next) {
                        if(first) {
                                first = 0;
@@ -272,8 +271,8 @@ static void intern_print_type_pre(type_t *type)
        case TYPE_BUILTIN:
                fputs(((builtin_type_t*) type)->symbol->string, out);
                return;
-       case TYPE_METHOD:
-               print_method_type_pre((method_type_t*) type);
+       case TYPE_FUNCTION:
+               print_function_type_pre((function_type_t*) type);
                return;
        case TYPE_POINTER:
                print_pointer_type_pre((pointer_type_t*) type);
@@ -294,8 +293,8 @@ static
 void intern_print_type_post(type_t *type)
 {
        switch(type->type) {
-       case TYPE_METHOD:
-               print_method_type_post((const method_type_t*) type, NULL);
+       case TYPE_FUNCTION:
+               print_function_type_post((const function_type_t*) type, NULL);
                return;
        case TYPE_POINTER:
                print_pointer_type_post((const pointer_type_t*) type);
@@ -333,8 +332,8 @@ void print_type_ext(type_t *type, const symbol_t *symbol,
                fputc(' ', out);
                fputs(symbol->string, out);
        }
-       if(type->type == TYPE_METHOD) {
-               print_method_type_post((const method_type_t*) type, context);
+       if(type->type == TYPE_FUNCTION) {
+               print_function_type_post((const function_type_t*) type, context);
        } else {
                intern_print_type_post(type);
        }
diff --git a/type.h b/type.h
index 98c2ba1..23f3d2c 100644 (file)
--- a/type.h
+++ b/type.h
@@ -5,17 +5,17 @@
 #include <stdbool.h>
 #include "symbol.h"
 
-typedef struct type_t              type_t;
-typedef struct atomic_type_t       atomic_type_t;
-typedef struct pointer_type_t      pointer_type_t;
-typedef struct method_parameter_t  method_parameter_t;
-typedef struct method_type_t       method_type_t;
-typedef struct compound_type_t     compound_type_t;
-typedef struct enum_type_t         enum_type_t;
-typedef struct builtin_type_t      builtin_type_t;
-typedef struct array_type_t        array_type_t;
-typedef struct typedef_type_t      typedef_type_t;
-typedef struct typeof_type_t       typeof_type_t;
+typedef struct type_t                type_t;
+typedef struct atomic_type_t         atomic_type_t;
+typedef struct pointer_type_t        pointer_type_t;
+typedef struct function_parameter_t  function_parameter_t;
+typedef struct function_type_t       function_type_t;
+typedef struct compound_type_t       compound_type_t;
+typedef struct enum_type_t           enum_type_t;
+typedef struct builtin_type_t        builtin_type_t;
+typedef struct array_type_t          array_type_t;
+typedef struct typedef_type_t        typedef_type_t;
+typedef struct typeof_type_t         typeof_type_t;
 
 void init_types(void);
 void exit_types(void);
index fa93540..1e07c1f 100644 (file)
@@ -51,11 +51,11 @@ static unsigned hash_compound_type(const compound_type_t *type)
 
 static unsigned hash_type(const type_t *type);
 
-static unsigned hash_method_type(const method_type_t *type)
+static unsigned hash_function_type(const function_type_t *type)
 {
        unsigned result = hash_ptr(type->result_type);
 
-       method_parameter_t *parameter = type->parameters;
+       function_parameter_t *parameter = type->parameters;
        while(parameter != NULL) {
                result   ^= hash_ptr(parameter->type);
                parameter = parameter->next;
@@ -95,8 +95,8 @@ static unsigned hash_type(const type_t *type)
        case TYPE_COMPOUND_UNION:
                hash = hash_compound_type((const compound_type_t*) type);
                break;
-       case TYPE_METHOD:
-               hash = hash_method_type((const method_type_t*) type);
+       case TYPE_FUNCTION:
+               hash = hash_function_type((const function_type_t*) type);
                break;
        case TYPE_POINTER:
                hash = hash_pointer_type((const pointer_type_t*) type);
@@ -127,8 +127,8 @@ static bool atomic_types_equal(const atomic_type_t *type1,
        return type1->atype == type2->atype;
 }
 
-static bool method_types_equal(const method_type_t *type1,
-                               const method_type_t *type2)
+static bool function_types_equal(const function_type_t *type1,
+                                 const function_type_t *type2)
 {
        if(type1->result_type != type2->result_type)
                return false;
@@ -137,8 +137,8 @@ static bool method_types_equal(const method_type_t *type1,
        if(type1->unspecified_parameters != type2->unspecified_parameters)
                return false;
 
-       method_parameter_t *param1 = type1->parameters;
-       method_parameter_t *param2 = type2->parameters;
+       function_parameter_t *param1 = type1->parameters;
+       function_parameter_t *param2 = type2->parameters;
        while(param1 != NULL && param2 != NULL) {
                if(param1->type != param2->type)
                        return false;
@@ -230,9 +230,9 @@ static bool types_equal(const type_t *type1, const type_t *type2)
        case TYPE_COMPOUND_UNION:
                return compound_types_equal((const compound_type_t*) type1,
                                            (const compound_type_t*) type2);
-       case TYPE_METHOD:
-               return method_types_equal((const method_type_t*) type1,
-                                         (const method_type_t*) type2);
+       case TYPE_FUNCTION:
+               return function_types_equal((const function_type_t*) type1,
+                                           (const function_type_t*) type2);
        case TYPE_POINTER:
                return pointer_types_equal((const pointer_type_t*) type1,
                                           (const pointer_type_t*) type2);
index eb072e6..efc97b6 100644 (file)
--- a/type_t.h
+++ b/type_t.h
@@ -19,7 +19,7 @@ typedef enum {
        TYPE_COMPOUND_STRUCT,
        TYPE_COMPOUND_UNION,
        TYPE_ENUM,
-       TYPE_METHOD,
+       TYPE_FUNCTION,
        TYPE_POINTER,
        TYPE_ARRAY,
        TYPE_BUILTIN,
@@ -95,17 +95,17 @@ struct array_type_t {
        expression_t *size;
 };
 
-struct method_parameter_t {
-       type_t             *type;
-       method_parameter_t *next;
+struct function_parameter_t {
+       type_t               *type;
+       function_parameter_t *next;
 };
 
-struct method_type_t {
-       type_t              type;
-       type_t             *result_type;
-       method_parameter_t *parameters;
-       bool                variadic;
-       bool                unspecified_parameters;
+struct function_type_t {
+       type_t               type;
+       type_t              *result_type;
+       function_parameter_t *parameters;
+       bool                 variadic;
+       bool                 unspecified_parameters;
 };
 
 struct compound_type_t {
index ce28c55..78a41fe 100644 (file)
@@ -102,12 +102,12 @@ static void write_enum_type(const enum_type_t *type)
        fprintf(out, "/* TODO anonymous enum */byte");
 }
 
-static void write_method_type(const method_type_t *type)
+static void write_function_type(const function_type_t *type)
 {
        fprintf(out, "(func(");
 
-       method_parameter_t *parameter = type->parameters;
-       int                 first     = 1;
+       function_parameter_t *parameter = type->parameters;
+       int                   first     = 1;
        while(parameter != NULL) {
                if(!first) {
                        fprintf(out, ", ");
@@ -150,8 +150,8 @@ static void write_type(const type_t *type)
        case TYPE_ENUM:
                write_enum_type((const enum_type_t*) type);
                return;
-       case TYPE_METHOD:
-               write_method_type((const method_type_t*) type);
+       case TYPE_FUNCTION:
+               write_function_type((const function_type_t*) type);
                return;
        case TYPE_INVALID:
                panic("invalid type found");
@@ -278,7 +278,8 @@ static void write_function(const declaration_t *declaration)
        fprintf(out, "func extern %s(",
                declaration->symbol->string);
 
-       const method_type_t *method_type = (const method_type_t*) declaration->type;
+       const function_type_t *function_type
+               = (const function_type_t*) declaration->type;
 
        declaration_t *parameter = declaration->context.declarations;
        int            first     = 1;
@@ -295,7 +296,7 @@ static void write_function(const declaration_t *declaration)
                }
                write_type(parameter->type);
        }
-       if(method_type->variadic) {
+       if(function_type->variadic) {
                if(!first) {
                        fprintf(out, ", ");
                } else {
@@ -305,7 +306,7 @@ static void write_function(const declaration_t *declaration)
        }
        fprintf(out, ")");
 
-       const type_t        *result_type = method_type->result_type;
+       const type_t *result_type = function_type->result_type;
        if(result_type->type != TYPE_ATOMIC ||
                        ((const atomic_type_t*) result_type)->atype != ATOMIC_TYPE_VOID) {
                fprintf(out, " : ");
@@ -353,7 +354,7 @@ void write_fluffy_decls(const translation_unit_t *unit)
                        continue;
 
                type_t *type = declaration->type;
-               if(type->type == TYPE_METHOD)
+               if(type->type == TYPE_FUNCTION)
                        continue;
 
                write_variable(declaration);
@@ -367,7 +368,7 @@ void write_fluffy_decls(const translation_unit_t *unit)
                        continue;
 
                type_t *type = declaration->type;
-               if(type->type != TYPE_METHOD)
+               if(type->type != TYPE_FUNCTION)
                        continue;
 
                write_function(declaration);