provide our own hashset implementation
[cparser] / wrappergen / write_jna.c
index 1f180d2..b209042 100644 (file)
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <string.h>
 
+#include "adt/strutil.h"
 #include "write_jna.h"
 #include "symbol_t.h"
 #include "ast_t.h"
@@ -31,7 +32,7 @@
 #include "printer.h"
 #include "adt/error.h"
 #include "adt/xmalloc.h"
-#include <libfirm/adt/pset_new.h>
+#include "adt/pset_new.h"
 
 typedef struct output_limit {
        const char          *filename;
@@ -46,7 +47,7 @@ static const char    *libname;
 
 static bool is_system_header(const char *fname)
 {
-       if (strncmp(fname, "/usr/include", 12) == 0)
+       if (strstart(fname, "/usr/include"))
                return true;
        if (fname == builtin_source_position.input_name)
                return true;
@@ -55,17 +56,17 @@ static bool is_system_header(const char *fname)
 
 static const char *fix_builtin_names(const char *name)
 {
-       if (strcmp(name, "class") == 0) {
+       if (streq(name, "class")) {
                return "_class";
-       } else if(strcmp(name, "this") == 0) {
+       } else if (streq(name, "this")) {
                return "_this";
-       } else if(strcmp(name, "public") == 0) {
+       } else if (streq(name, "public")) {
                return "_public";
-       } else if(strcmp(name, "protected") == 0) {
+       } else if (streq(name, "protected")) {
                return "_protected";
-       } else if(strcmp(name, "private") == 0) {
+       } else if (streq(name, "private")) {
                return "_private";
-       } else if(strcmp(name, "final") == 0) {
+       } else if (streq(name, "final")) {
                return "_final";
        }
        /* TODO put all reserved names here */
@@ -223,12 +224,10 @@ static void write_type(type_t *type)
                write_enum_type(&type->enumt);
                return;
        case TYPE_ERROR:
-       case TYPE_INVALID:
        case TYPE_TYPEOF:
        case TYPE_TYPEDEF:
                panic("invalid type found");
        case TYPE_ARRAY:
-       case TYPE_BITFIELD:
        case TYPE_REFERENCE:
        case TYPE_FUNCTION:
        case TYPE_COMPLEX:
@@ -272,7 +271,7 @@ static void write_unary_expression(const unary_expression_t *expression)
        case EXPR_UNARY_NOT:
                fputc('!', out);
                break;
-       case EXPR_UNARY_CAST_IMPLICIT:
+       case EXPR_UNARY_CAST:
                write_expression(expression->value);
                return;
        default:
@@ -309,23 +308,20 @@ static void write_expression(const expression_t *expression)
        /* TODO */
        switch(expression->kind) {
        case EXPR_LITERAL_INTEGER:
-       case EXPR_LITERAL_INTEGER_OCTAL:
                fprintf(out, "%s", expression->literal.value.begin);
                break;
-       case EXPR_LITERAL_INTEGER_HEXADECIMAL:
-               fprintf(out, "0x%s", expression->literal.value.begin);
-               break;
-       case EXPR_REFERENCE_ENUM_VALUE: {
+
+       case EXPR_ENUM_CONSTANT: {
                /* UHOH... hacking */
                entity_t *entity = expression->reference.entity;
                write_enum_name(& entity->enum_value.enum_type->enumt);
                fprintf(out, ".%s.val", entity->base.symbol->string);
                break;
        }
-       EXPR_UNARY_CASES
+       case EXPR_UNARY_CASES:
                write_unary_expression(&expression->unary);
                break;
-       EXPR_BINARY_CASES
+       case EXPR_BINARY_CASES:
                write_binary_expression(&expression->binary);
                break;
        default:
@@ -521,8 +517,7 @@ void write_jna_decls(FILE *output, const translation_unit_t *unit)
                }
 
 #if 0
-               if(type->kind == TYPE_COMPOUND_STRUCT
-                               || type->kind == TYPE_COMPOUND_UNION) {
+               if (is_type_compound(type)) {
                        write_compound(entity->base.symbol, &type->compound);
                }
 #endif
@@ -542,7 +537,7 @@ void write_jna_decls(FILE *output, const translation_unit_t *unit)
                        bool in_limits = false;
                        for (output_limit *limit = output_limits; limit != NULL;
                             limit = limit->next) {
-                           if (strcmp(limit->filename, input_name) == 0) {
+                           if (streq(limit->filename, input_name)) {
                                        in_limits = true;
                                        break;
                                }