unoidl2

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/unoidl2.git/
Log | Files | Refs

commit d609a79b0db040cba5415e3355d951bede95b38e
parent 332fe7c0cb5144d9bf7e616d56aa3d4ddc29f3b3
Author: Tomas Hlavaty <tom@logand.com>
Date:   Thu, 15 Dec 2011 01:03:12 +0100

more 2java improvements

Diffstat:
Munoidl2.c | 19++++++++++++++++++-
Munoidl2.h | 3++-
Munoidl2java.c | 52+++++++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 65 insertions(+), 9 deletions(-)

diff --git a/unoidl2.c b/unoidl2.c @@ -20,6 +20,7 @@ #include <stdlib.h> #include <stdio.h> +#include <string.h> struct any { enum {CONS, TOKEN, INUM} tag; @@ -114,7 +115,22 @@ Any cddddr(Any x) {return cdr(cdr(cdr(cdr(x))));} Any caddddr(Any x) {return car(cdr(cdr(cdr(cdr(x)))));} Any cdddddr(Any x) {return cdr(cdr(cdr(cdr(cdr(x)))));} -void print(Any x) { +int equal(Any x, Any y) { + if(null(x)) return null(y); + switch(x->tag) { + case CONS: + for(; !null(x) && !null(y); x = cdr(x), y = cdr(y)) + if(!equal(car(x), car(y))) return 0; + return null(x) && null(y); + case TOKEN: + return TOKEN == y->tag && kind(x) == kind(y) && 0 == strcmp(token(x), token(y)); + case INUM: + return INUM == y->tag && inum(x) == inum(y); + } + return 0; +} + +Any print(Any x) { if(null(x)) printf("NIL"); else @@ -142,4 +158,5 @@ void print(Any x) { break; /* default: error? */ } + return x; } diff --git a/unoidl2.h b/unoidl2.h @@ -51,4 +51,5 @@ Any cadddr(Any x); Any cddddr(Any x); Any caddddr(Any x); Any cdddddr(Any x); -void print(Any x); +int equal(Any x, Any y); +Any print(Any x); diff --git a/unoidl2java.c b/unoidl2java.c @@ -33,6 +33,7 @@ extern const Any NIL; static Any module; static Any typedefs; +static Any rel_package; static inline void pr(char *x) {printf("%s", x);} static inline void pl(char *x) {printf("%s\n", x);} @@ -106,7 +107,7 @@ static void pr_enum(Any x) { } pl(" }"); pr(" return "); pp(v0k); pl(";"); - pl(" }"); + pl(" }"); pl("}"); } @@ -260,11 +261,46 @@ static void pr_const(Any x) { } static void pr_typedef(Any x) { - typedefs = cons(x, typedefs); + typedefs = cons(cons(cons(cadr(x), module), cadddr(x)), typedefs); +} + +static Any find(Any e, Any l, int (*eq)(Any e, Any x)) { + for(; !null(l); l = cdr(l)) { + Any a = car(l); + if(eq(e, car(a))) return a; + } + return NIL; +} + +static Any reverse(Any x, Any a) { + return null(x) ? a : reverse(cdr(x), cons(car(x), a)); } -static void pr_type(Any x) { // TODO substitute typedef - pp_list(cdr(x), "."); +static void pr_relative(Any x) { + if(null(cddr(x))) { // local typedef + Any y = find(cons(cadr(x), module), typedefs, equal); + if(!null(y)) { + pp(cdr(y)); + return; + } + } + Any y = find(reverse(cdr(x), NIL), typedefs, equal); + if(!null(y)) { // non-local typedef + Any a = car(y); // (ServiceContextList iop corba star sun com) + Any d = cdr(y); // (sequence (relative ServiceContext)) + rel_package = cons(cdr(a), rel_package); + pp(d); + rel_package = cdr(rel_package); + return; + } + Any p = car(rel_package); + if(null(p) || !null(cddr(x))) + pp_list(cdr(x), "."); + else { // x => (relative ServiceContext) p => (iop corba star sun com) + Any a = car(x); + Any d = cdr(x); + pp_list(reverse(cons(cadr(x), p), NIL), "."); + } } static void pr_property(Any x) { @@ -296,8 +332,8 @@ static void pp(Any x) { //case IN: //case OUT: //case INOUT: pr_arg(x); break; - case RELATIVE: - case ABSOLUTE: pr_type(x); break; + case RELATIVE: pr_relative(x); break; + case ABSOLUTE: pp_list(cdr(x), "."); break; case CONSTANTS: pr_constants(x); break; case CONST: pr_const(x); break; case SEQUENCE: pp(cadr(x)); pr("[]"); break; @@ -315,7 +351,7 @@ static void pp(Any x) { case CHAR: print(car(x)); break; case LONG: pr("int"); break; case HYPER: pr("long"); break; - case UNSIGNED: pp(cadr(x)); break; + case UNSIGNED: pp(cdr(x)); break; case STRING: pr("java.lang.String"); break; case TYPE: pr("com.sun.star.uno.Type"); break; case ANY: pr("com.sun.star.uno.Any"); break; @@ -350,6 +386,8 @@ int main() { yyparse(); module = NIL; typedefs = NIL; + rel_package = NIL; pp_list(ast, NULL); + //print(typedefs); return 0; }