unoidl2

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

commit 9fe59f505ed7465a186a0e7a11f112fa2255d892
parent ae7968a00962d96175320d8e351ed73db3d6fad4
Author: Tomas Hlavaty <tom@logand.com>
Date:   Fri, 23 Mar 2012 00:30:30 +0100

resolve_typedef and simplify thanks to sym2

Diffstat:
Munoidl2.c | 12+++++-------
Munoidl2.h | 2--
Munoidl2ast.c | 1-
Munoidl2java.c | 83++++++++++++++++++++++++++-----------------------------------------------------
4 files changed, 32 insertions(+), 66 deletions(-)

diff --git a/unoidl2.c b/unoidl2.c @@ -310,16 +310,16 @@ Any sym2k(Any x) {return caar(x);} static Any module2; Any subst2_x; -Any subst2_rel_abs(Any v) { +static Any subst2(Any v) { Any w; if(consp(v)) { switch(kind(car(v))) { case CONST: w = module2; module2 = sym2p(module2); - subst2_rel_abs(caddr(v)); + subst2(caddr(v)); module2 = w; - mapc(subst2_rel_abs, cdddr(v)); + mapc(subst2, cdddr(v)); break; case RELATIVE: //(relative XInterface) w = cdr(v); @@ -331,14 +331,12 @@ Any subst2_rel_abs(Any v) { con(w, NIL); break; default: - mapc(subst2_rel_abs, v); + mapc(subst2, v); } } return v; } -Fn1 build2_fn = id; - Any build2(Any x) { Any p, z; switch(kind(car(x))) { @@ -374,7 +372,7 @@ Any build2(Any x) { if(NIL != get2(z)) printf("@@@ build2 error: duplicate "); set(cdr(x), z); subst2_x = z; - set2(z, build2_fn(x)); + set2(z, subst2(x)); break; case INTERFACE: break; // TODO eg XMultiComponentFactory? default: diff --git a/unoidl2.h b/unoidl2.h @@ -72,8 +72,6 @@ Any get2(Any x); Any sym2p(Any x); Any sym2k(Any x); extern Any subst2_x; -Any subst2_rel_abs(Any v); -extern Fn1 build2_fn; Any build2(Any x); extern Fn1 walk2_fn; Any walk2(Any x); diff --git a/unoidl2ast.c b/unoidl2ast.c @@ -33,7 +33,6 @@ int main() { init(); yyparse(); //mapc(pr1, ast); - build2_fn = subst2_rel_abs; mapc(build2, ast); walk2_fn = pr1; walk2(root2); diff --git a/unoidl2java.c b/unoidl2java.c @@ -28,10 +28,6 @@ extern const Any T; extern const Any ast; extern const Any root2; -static Any typedefs; -static Any enums; -static Any structs; -static Any rel_package; static Any com_sun_star_uno_XInterface; static Any com_sun_star_uno_Exception; static Any com_sun_star_uno_RuntimeException; @@ -140,10 +136,17 @@ static void pr_args2(Any x) { // for in, out, inout } } -static Any pr_default_slot(Any slot) { +static Any resolve_typedef(Any x) { + Any v; + while(TYPEDEF == kind(car(v = get2(x)))) + x = cadddr(v); + return x; +} + +static Any pr_default_slot(Any slot) { // (sName (string)) Any n = car(slot); Any t = cadr(slot); - Any e; + Any v; switch(kind(consp(t) ? car(t) : t)) { case STRING: pr(" this."); pp(n); pl(" = \"\";"); break; case ANY: pr(" this."); pp(n); pl(" = com.sun.star.uno.Any.VOID;"); break; @@ -157,35 +160,28 @@ static Any pr_default_slot(Any slot) { break; case RELATIVE: case ABSOLUTE: - if(NIL != (e = find(t, enums, equal, id))) { - Any d = cadr(e); - pr(" this."); pp(n); pl(" = "); pp(t); pr("."); - pp(consp(d) ? car(d) : d); pr(";"); - } else if(NIL != (e = find(t, structs, equal, id))) { + t = resolve_typedef(cadr(t)); + switch(kind(car(v = get2(t)))) { // TODO only if t is sym2 + case ENUM: + v = cadddr(v); + pr(" this."); pp(n); pr(" = "); pp(t); pr("."); + pp(consp(v) ? car(v) : v); + pl(";"); + break; + case STRUCT: pr(" this."); pp(n); pr(" = new "); pp(t); pl("();"); - } else if(NIL == cddr(t)) { - Any y = resolve_typedef(cons(cadr(t), module)); - if(NIL != y) pr_default_slot(NULL, list2(n, cdr(y))); // local typedef - } else { - Any y = resolve_typedef(reverse(cdr(t), NIL)); - if(NIL != y) { // non-local typedef - rel_package = cons(cdr(car(y)), rel_package); - pr_default_slot(NULL, list2(n, cdr(y))); - rel_package = cdr(rel_package); - } + break; } //default: pr("@@@"); print(t); pp(t); } return slot; } -static void pr_default_slots(Any slots) { - mapc(pr_default_slot, slots); -} +static void pr_default_slots(Any slots) {mapc(pr_default_slot, slots);} static int pr_slots_rec1(Any super) { // (absolute|relative com.sun...) if(NIL == super) return 0; - Any s = cdddr(get2(find(cadr(super), structs, equal, id))); + Any s = cdddr(get2(resolve_typedef(cadr(super)))); // TODO only if t is sym2 if(pr_slots_rec1(car(s))) pr(", "); pr_args(cdr(s)); return 1; @@ -193,7 +189,7 @@ static int pr_slots_rec1(Any super) { // (absolute|relative com.sun...) static int pr_slots_rec2(Any super) { if(NIL == super) return 0; - Any s = cdddr(get2(find(cadr(super), structs, equal, id))); + Any s = cdddr(get2(resolve_typedef(cadr(super)))); // TODO only if t is sym2 int z = pr_slots_rec2(car(s)); for(Any y = cdr(s); NIL != y; y = cdr(y)) { if(0 < z++) pr(", "); @@ -623,8 +619,7 @@ static void pr_const(Any x) { Any type = caddr(x); Any exp = cadddr(x); pr(" public static final "); - Any y = find(type, typedefs, equal, id); - if(NIL != y) type = y; + type = resolve_typedef(type); pp(type); pr(" "); pp(sym2k(name)); pr(" = "); Kind k = kind(car(type)); @@ -640,13 +635,11 @@ static void pr_const(Any x) { } static void pr_absolute(Any x) { // (absolute|relative com.sun...) - Any s = cadr(x); - if(!use_XInterface && s == com_sun_star_uno_XInterface) + x = resolve_typedef(cadr(x)); + if(!use_XInterface && x == com_sun_star_uno_XInterface) pr("java.lang.Object"); - else { - Any y = cadddr(get2(find(s, typedefs, equal, id))); - pp(NIL == y ? cadr(x) : y); - } + else + pp(x); } static void pr_property(Any x) { @@ -774,37 +767,15 @@ static Any pp(Any x) { return x; } -static Any subst2java(Any v) { - v = subst2_rel_abs(v); - switch(kind(car(v))) { - case ENUM: enums = cons(subst2_x, enums); break; - case STRUCT: structs = cons(subst2_x, structs); break; - case TYPEDEF: typedefs = cons(subst2_x, typedefs); break; - } - return v; -} - int main() { init(); yyparse(); - - typedefs = NIL; - enums = NIL; - structs = NIL; - rel_package = NIL; Any p = intern2abs(list4(mk(ID, "com"), mk(ID, "sun"), mk(ID, "star"), mk(ID, "uno"))); com_sun_star_uno_XInterface = intern2rel(sym1(mk(ID, "XInterface")), p); com_sun_star_uno_Exception = intern2rel(sym1(mk(ID, "Exception")), p); com_sun_star_uno_RuntimeException = intern2rel(sym1(mk(ID, "RuntimeException")), p); //pp_list(ast, NULL); - - build2_fn = subst2java; mapc(build2, ast); - - //print(typedefs); - //print(enums); - //print(structs); - walk2_fn = pp; walk2(root2); return 0;