]> git.draconx.ca Git - cdecl99.git/commitdiff
tests: Don't pull output routines into normalize testcase.
authorNick Bowler <nbowler@draconx.ca>
Fri, 7 Jul 2023 00:57:41 +0000 (20:57 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 7 Jul 2023 00:57:41 +0000 (20:57 -0400)
This program isn't about testing the output routines, and it's simple
enough to just have the test program do its own printing, so linking
in the output routines to this testcase is just causing more trouble
than it's worth.

Makefile.am
t/normalize.c

index 507fc67cf1bd56b6287c93a8afd22a8d4695911b..031c0a83ec9629ad74060a637bd2fea29f723abe 100644 (file)
@@ -93,7 +93,7 @@ $(t_randomdecl_OBJECTS): $(gnulib_headers)
 t_crossparse_LDADD = $(TEST_LIBS)
 $(t_crossparse_OBJECTS): $(gnulib_headers)
 
-t_normalize_LDADD = src/output.lo src/normalize.lo $(TEST_LIBS)
+t_normalize_LDADD = src/normalize.lo $(TEST_LIBS)
 $(t_normalize_OBJECTS): $(gnulib_headers)
 
 t_rng_test_LDADD = $(TEST_LIBS)
index dc4cd53d3ed8966836efe672389b2f3af4952f5b..558f5562414c358d9079ba2906539c47a863bb4a 100644 (file)
@@ -80,9 +80,53 @@ static unsigned to_spectype(const char *tok)
        return CDECL_TYPE_IDENT;
 }
 
+static const char *to_specstring(unsigned type)
+{
+       switch (type) {
+       case CDECL_STOR_TYPEDEF: return "typedef";
+       case CDECL_STOR_EXTERN: return "extern";
+       case CDECL_STOR_STATIC: return "static";
+       case CDECL_STOR_AUTO: return "auto";
+       case CDECL_STOR_REGISTER: return "register";
+       case CDECL_FUNC_INLINE: return "inline";
+       case CDECL_QUAL_RESTRICT: return "restrict";
+       case CDECL_QUAL_VOLATILE: return "volatile";
+       case CDECL_QUAL_CONST: return "const";
+       case CDECL_TYPE_VOID: return "void";
+       case CDECL_TYPE_SIGNED: return "signed";
+       case CDECL_TYPE_UNSIGNED: return "unsigned";
+       case CDECL_TYPE_CHAR: return "char";
+       case CDECL_TYPE_SHORT: return "short";
+       case CDECL_TYPE_LONG: return "long";
+       case CDECL_TYPE_INT: return "int";
+       case CDECL_TYPE_FLOAT: return "float";
+       case CDECL_TYPE_DOUBLE: return "double";
+       case CDECL_TYPE_COMPLEX: return "_Complex";
+       case CDECL_TYPE_IMAGINARY: return "_Imaginary";
+       case CDECL_TYPE_BOOL: return "_Bool";
+       case CDECL_TYPE_STRUCT: return "struct";
+       case CDECL_TYPE_UNION: return "union";
+       case CDECL_TYPE_ENUM: return "enum";
+       }
+
+       return "";
+}
+
+static void print_spec(struct cdecl_declspec *spec)
+{
+       const char *s = to_specstring(spec->type);
+
+       printf("%s", s);
+       if (spec->ident) {
+               if (s[0])
+                       putchar(' ');
+               printf("%s", spec->ident);
+       }
+}
+
 int do_normalize(char *line, size_t n)
 {
-       struct cdecl_declspec *specs = NULL, **newspec = &specs;
+       struct cdecl_declspec *s, *specs = NULL, **newspec = &specs;
        char *tok = NULL;
 
        while ((tok = strtok(tok ? NULL : line, " "))) {
@@ -105,16 +149,13 @@ int do_normalize(char *line, size_t n)
                newspec = &spec->next;
        }
 
-       line = malloc_nofail(n);
-       line[0] = 0;
-       if (specs) {
-               struct output_state dst = { line, n };
-
-               specs = cdecl__normalize_specs(specs);
-               cdecl__emit_specs(&dst, specs, -1);
+       specs = cdecl__normalize_specs(specs);
+       for (s = specs; s; s = s->next) {
+               print_spec(s);
+               if (s->next)
+                       putchar(' ');
        }
-       printf("%s\n", line);
-       free(line);
+       putchar('\n');
 
        while (specs) {
                struct cdecl_declspec *c = specs;