Move local variable declaration closer to its use.
[cparser] / mangle.c
index 42a5745..1098307 100644 (file)
--- a/mangle.c
+++ b/mangle.c
@@ -70,6 +70,26 @@ static void mangle_pointer_type(const pointer_type_t *type)
        mangle_type(type->points_to);
 }
 
+static void mangle_parameters(const function_type_t *type)
+{
+       if (type->unspecified_parameters)
+               panic("can't mangle unspecified parameter types");
+       if (type->kr_style_parameters)
+               panic("can't mangle kr_style_parameters type");
+
+       const function_parameter_t *parameter = type->parameters;
+       if (parameter != NULL) {
+               for ( ; parameter != NULL; parameter = parameter->next) {
+                       mangle_type(parameter->type);
+               }
+               if (type->variadic) {
+                       obstack_1grow(&obst, 'z');
+               }
+       } else {
+               obstack_1grow(&obst, 'v');
+       }
+}
+
 static void mangle_function_type(const function_type_t *type)
 {
        obstack_1grow(&obst, 'F');
@@ -78,30 +98,19 @@ static void mangle_function_type(const function_type_t *type)
        }
 
        mangle_type(type->return_type);
-
-       function_parameter_t *parameter = type->parameters;
-       for ( ; parameter != NULL; parameter = parameter->next) {
-               mangle_type(parameter->type);
-       }
-       if (type->variadic) {
-               obstack_1grow(&obst, 'z');
-       }
-       if (type->unspecified_parameters)
-               panic("can't mangle unspecified parameter types");
-       if (type->kr_style_parameters)
-               panic("can't mangle kr_style_parameters type");
+       mangle_parameters(type);
 
        obstack_1grow(&obst, 'E');
 }
 
 static void mangle_qualifiers(type_qualifiers_t qualifiers)
 {
-       if (qualifiers & TYPE_QUALIFIER_CONST)
-               obstack_1grow(&obst, 'K');
-       if (qualifiers & TYPE_QUALIFIER_VOLATILE)
-               obstack_1grow(&obst, 'V');
        if (qualifiers & TYPE_QUALIFIER_RESTRICT)
                obstack_1grow(&obst, 'r');
+       if (qualifiers & TYPE_QUALIFIER_VOLATILE)
+               obstack_1grow(&obst, 'V');
+       if (qualifiers & TYPE_QUALIFIER_CONST)
+               obstack_1grow(&obst, 'K');
 
        /* handle MS extended qualifiers? */
 }
@@ -151,11 +160,11 @@ static void mangle_entity(entity_t *entity)
 
        /* TODO: mangle scope */
 
-       symbol_t *symbol = entity->base.symbol;
-       obstack_printf(&obst, "%u%s", strlen(symbol->string), symbol->string);
+       const char *name = entity->base.symbol->string;
+       obstack_printf(&obst, "%zu%s", strlen(name), name);
 
        if (entity->kind == ENTITY_FUNCTION) {
-               mangle_type(entity->declaration.type);
+               mangle_parameters(&entity->declaration.type->function);
        }
 }