X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=wrappergen%2Fwrite_jna.c;h=228520625e2cccc5428581bddbe3d4fc6cb0656b;hb=2d4a842e50718fa66d8d13aac18871c090de6b31;hp=5ab41fe05882063d1b5f0a979bbbbe031cfb6e9b;hpb=1b580cf22ca849edc62afa24304ff0432954877a;p=cparser diff --git a/wrappergen/write_jna.c b/wrappergen/write_jna.c index 5ab41fe..2285206 100644 --- a/wrappergen/write_jna.c +++ b/wrappergen/write_jna.c @@ -40,7 +40,11 @@ static void write_type(type_t *type); static bool is_system_header(const char *fname) { - return strncmp(fname, "/usr/include", 12) == 0; + if (strncmp(fname, "/usr/include", 12) == 0) + return true; + if (fname == builtin_source_position.input_name) + return true; + return false; } static const char *fix_builtin_names(const char *name) @@ -99,7 +103,7 @@ static void write_pointer_type(const pointer_type_t *type) } if (is_type_pointer(points_to)) { /* hack... */ - fputs("Pointer[]", out); + fputs("java.nio.Buffer", out); return; } fputs("Pointer", out); @@ -298,16 +302,14 @@ static void write_binary_expression(const binary_expression_t *expression) static void write_expression(const expression_t *expression) { - const const_expression_t *constant; /* TODO */ switch(expression->kind) { - case EXPR_CONST: - constant = &expression->conste; - if(is_type_integer(expression->base.type)) { - fprintf(out, "%lld", constant->v.int_value); - } else { - fprintf(out, "%Lf", constant->v.float_value); - } + 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: { /* UHOH... hacking */ @@ -399,7 +401,7 @@ static void write_function(const entity_t *entity) const function_type_t *function_type = (const function_type_t*) entity->declaration.type; - fputc('\t', out); + fprintf(out, "\tpublic static native "); type_t *return_type = skip_typeref(function_type->return_type); write_type(return_type); fprintf(out, " %s(", entity->base.symbol->string); @@ -442,24 +444,28 @@ void write_jna_decls(FILE *output, const translation_unit_t *unit) print_to_file(out); fprintf(out, "/* WARNING: Automatically generated file */\n"); - fputs("import com.sun.jna.Library;\n", out); + fputs("import com.sun.jna.Native;\n", out); fputs("import com.sun.jna.Pointer;\n", out); fputs("\n\n", out); /* TODO: where to get the name from? */ - fputs("public interface binding extends Library {\n", out); + fputs("public class binding {\n", out); + fputs("\tstatic { Native.register(\"firm\"); }\n", out); /* read the avoid list */ FILE *avoid = fopen("avoid.config", "r"); if (avoid != NULL) { while (!feof(avoid)) { char buf[1024]; - fgets(buf, sizeof(buf), avoid); + char *res = fgets(buf, sizeof(buf), avoid); + if (res == NULL) + break; + if (buf[0] == 0) + continue; + size_t len = strlen(buf); if (buf[len-1] == '\n') buf[len-1] = 0; - if (buf[0] == 0) - continue; char *str = malloc(len+1); memcpy(str, buf, len+1);