more work on local variable support
[cparser] / write_fluffy.c
index ce28c55..e8ccbd7 100644 (file)
@@ -3,6 +3,7 @@
 #include <errno.h>
 #include <string.h>
 
+#include "write_fluffy.h"
 #include "ast_t.h"
 #include "type_t.h"
 #include "type.h"
@@ -102,12 +103,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 +151,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");
@@ -246,7 +247,7 @@ static void write_enum(const symbol_t *symbol, const enum_type_t *type)
 {
        fprintf(out, "enum %s:\n", symbol->string);
 
-       declaration_t *entry = type->declaration->context_next;
+       declaration_t *entry = type->declaration->next;
        for ( ; entry != NULL && entry->storage_class == STORAGE_CLASS_ENUM_ENTRY;
                        entry = entry->next) {
                fprintf(out, "\t%s", entry->symbol->string);
@@ -278,7 +279,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 +297,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 +307,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 +355,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 +369,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);