X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=wrappergen%2Fwrite_jna.c;h=228520625e2cccc5428581bddbe3d4fc6cb0656b;hb=2d4a842e50718fa66d8d13aac18871c090de6b31;hp=78f63090d4f42a01bf2e714dd304a1e188b7dcc3;hpb=7ec860c6f6249c38a2a5deae145258a4b3e63bf6;p=cparser diff --git a/wrappergen/write_jna.c b/wrappergen/write_jna.c index 78f6309..2285206 100644 --- a/wrappergen/write_jna.c +++ b/wrappergen/write_jna.c @@ -28,6 +28,7 @@ #include "type_t.h" #include "entity_t.h" #include "type.h" +#include "printer.h" #include "adt/error.h" #include @@ -39,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) @@ -98,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); @@ -297,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 */ @@ -398,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); @@ -439,27 +442,30 @@ void write_jna_decls(FILE *output, const translation_unit_t *unit) pset_new_init(&avoid_symbols); - ast_set_output(out); - type_set_output(out); + 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);