commit 13f9a5c5bd6ca668673cc9130cb6ac0413a70747
parent d6950c4621ce890915cc56439fa7683c6cacfeaf
Author: Tomas Hlavaty <tom@logand.com>
Date: Sun, 25 Mar 2012 21:07:16 +0200
more 2java fixes to match existing jar generation
Diffstat:
M | unoidl2java.c | | | 87 | +++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- |
1 file changed, 52 insertions(+), 35 deletions(-)
diff --git a/unoidl2java.c b/unoidl2java.c
@@ -42,10 +42,10 @@ static void pi(int x) {printf("%d", x);}
static Any pp(Any x);
-static void pp_list(Any x, char *sep) {
+static void pp_list(Any x, char *sep, Fn1 fn) {
for(int i = 0; NIL != x; x = cdr(x), i++) {
if(sep && 0 < i) pr(sep);
- pp(car(x));
+ fn(car(x));
}
}
@@ -136,11 +136,10 @@ static void pr_args2(Any x) { // for in, out, inout
}
}
-static Any resolve_typedef(Any x) {
+static Any resolve_typedef(Any x, int val) {
Any v;
- while(TYPEDEF == kind(car(v = get2(x))))
- x = cadddr(v);
- return x;
+ while(TYPEDEF == kind(car(v = get2(x)))) x = cadddr(v);
+ return val ? v : x;
}
static Any pr_default_slot(Any slot) { // (sName (string))
@@ -151,8 +150,7 @@ static Any pr_default_slot(Any slot) { // (sName (string))
switch(kind(car(t))) {
case RELATIVE:
case ABSOLUTE:
- t = resolve_typedef(cadr(t));
- if(!consp(t)) t = get2(t); // TODO only if t is not sym2
+ t = resolve_typedef(cadr(t), 1);
}
switch(kind(car(t))) {
case STRING: pr(" this."); pp(n); pl(" = \"\";"); break;
@@ -160,9 +158,9 @@ static Any pr_default_slot(Any slot) { // (sName (string))
case TYPE: pr(" this."); pp(n); pl(" = com.sun.star.uno.Type.VOID;"); break;
case SEQUENCE:
pr(" this."); pp(n); pr(" = new ");
- seq0 = 1;
+ seq0++;
pp(t);
- seq0 = 0;
+ seq0--;
pl(";");
break;
case TEMPLATE: //(template (absolute com.sun.star.beans.Optional) ((string)))
@@ -186,7 +184,7 @@ 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(resolve_typedef(cadr(super)))); // TODO only if t is sym2
+ Any s = cdddr(resolve_typedef(cadr(super), 1));
if(pr_slots_rec1(car(s))) pr(", ");
pr_args(cdr(s));
return 1;
@@ -194,7 +192,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(resolve_typedef(cadr(super)))); // TODO only if t is sym2
+ Any s = cdddr(resolve_typedef(cadr(super), 1));
int z = pr_slots_rec2(car(s));
for(Any y = cdr(s); NIL != y; y = cdr(y)) {
if(0 < z++) pr(", ");
@@ -235,17 +233,33 @@ static void pr_slots(Any slots, Any name, Any super) {
static Any method;
static int k;
-static void pr_TypeInfo2(char *kind, Any name, Any type, int flags, int *i, int j) {
+typedef enum {_ATTRIBUTE, _METHOD, _MEMBER, _PARAMETER} _Kind;
+
+static char *__kind[] = {"Attribute", "Method", "Member", "Parameter"};
+
+static Any pr_TypeInfo2_internal(Any x) {
+ if(consp(x)) pp_list(x, " ", print);
+ else print(x);
+}
+
+static void pr_TypeInfo2(_Kind _kind, Any name, Any type, int flags, int *i, int j) {
pl(*i < 0 && j < 0 ? "" : ",");
- pr(" new com.sun.star.lib.uno.typeinfo."); pr(kind); pr("TypeInfo(\"");
- pp(name); pr("\", ");
- if(!j) {
- pr("\""); pp(method); pr("\", ");
- }
+ pr(" new com.sun.star.lib.uno.typeinfo."); pr(__kind[_kind]);
+ pr("TypeInfo(\""); pp(name); pr("\", ");
+ if(!j) {pr("\""); pp(method); pr("\", ");}
pi(++*i); pr(", ");
pi(flags);
- if(!consp(type)) {
- pr(", null, "); pi(++k);
+ switch(_kind) {
+ case _MEMBER: if(!consp(type)) {pr(", null, "); pi(++k);} break;
+ case _METHOD:
+ if(consp(type)) {
+ switch(kind(car(type))) {
+ case TEMPLATE:
+ pr(", new com.sun.star.uno.Type(\""); pp(cadr(type)); pr("<");
+ pp_list(caddr(type), ",", pr_TypeInfo2_internal);
+ pr(">\", com.sun.star.uno.TypeClass.STRUCT)");
+ }
+ }
}
pr(")");
}
@@ -270,7 +284,8 @@ static int type_flags(Any x) {
case SEQUENCE: return type_flags(cadr(x));
case RELATIVE:
case ABSOLUTE:
- return equal_(com_sun_star_uno_XInterface, cdr(x)) ? _INTERFACE : 0;
+ x = resolve_typedef(cadr(x), 0);
+ return com_sun_star_uno_XInterface == x ? _INTERFACE : type_flags(x);
}
}
return 0;
@@ -279,6 +294,7 @@ static int type_flags(Any x) {
static Any kindeq(Kind k, Any a) {return k == kind(a) ? T : NIL;}
static Any readonlyp(Any a) {return kindeq(READONLY, a);}
+static Any boundp(Any a) {return kindeq(BOUND, a);}
static Any pr_TypeInfo1(void *env, Any x) {
int f = 0;
@@ -288,19 +304,20 @@ static Any pr_TypeInfo1(void *env, Any x) {
t = cadr(x);
f |= type_flags(t);
if(NIL != some(readonlyp, cadddr(x))) f |= _READONLY;
- pr_TypeInfo2("Attribute", caddr(x), t, f, env, -1);
+ if(NIL != some(boundp, cadddr(x))) f |= _BOUND;
+ pr_TypeInfo2(_ATTRIBUTE, caddr(x), t, f, env, -1);
break;
case ID: // (NewValue (any))
t = cadr(x);
f |= type_flags(t);
- pr_TypeInfo2("Member", car(x), t, f, env, -1);
+ pr_TypeInfo2(_MEMBER, car(x), t, f, env, -1);
break;
case METHOD: // (method queryInterface NIL (any) ((in aType (type))))
method = cadr(x);
t = cadddr(x);
f |= type_flags(t);
if(NIL != caddr(x)) f |= _ONEWAY;
- pr_TypeInfo2("Method", method, t, f, env, -1);
+ pr_TypeInfo2(_METHOD, method, t, f, env, -1);
int i = -1;
mapcx(&i, pr_TypeInfo1, caddddr(x));
break;
@@ -308,19 +325,19 @@ static Any pr_TypeInfo1(void *env, Any x) {
t = caddr(x);
f |= _IN | type_flags(t);
if(f != _IN && f != (_IN | _ANY))
- pr_TypeInfo2("Parameter", cadr(x), t, f, env, 0);
+ pr_TypeInfo2(_PARAMETER, cadr(x), t, f, env, 0);
else
++*((int *) env);
break;
case OUT:
t = caddr(x);
f |= _OUT | type_flags(t);
- pr_TypeInfo2("Parameter", cadr(x), t, f, env, 0);
+ pr_TypeInfo2(_PARAMETER, cadr(x), t, f, env, 0);
break;
case INOUT:
t = caddr(x);
f |= _IN | _OUT | type_flags(t);
- pr_TypeInfo2("Parameter", cadr(x), t, f, env, 0);
+ pr_TypeInfo2(_PARAMETER, cadr(x), t, f, env, 0);
}
return NIL;
}
@@ -500,7 +517,7 @@ static void pr_method(Any x) {
Any body = cdddddr(x);
pr(" public abstract "); pp(type); pr(" "); pp(name); pr("("); pr_args2(args); pr(")");
if(NIL != body) {
- pr(" throws "); pp_list(body, ", ");
+ pr(" throws "); pp_list(body, ", ", pp);
}
pl(";");
}
@@ -508,14 +525,14 @@ static void pr_method(Any x) {
static Any pr_attribute_get(Any e) {
if(GET == kind(car(e))) {
pr(" throws ");
- pp_list(cadr(e), ", ");
+ pp_list(cadr(e), ", ", pp);
}
}
static Any pr_attribute_set(Any e) {
if(SET == kind(car(e))) {
pr(" throws ");
- pp_list(cadr(e), ", ");
+ pp_list(cadr(e), ", ", pp);
}
}
@@ -624,7 +641,7 @@ static void pr_const(Any x) {
Any type = caddr(x);
Any exp = cadddr(x);
pr(" public static final ");
- type = resolve_typedef(type);
+ type = resolve_typedef(type, 0);
pp(type);
pr(" "); pp(sym2k(name)); pr(" = ");
Kind k = kind(car(type));
@@ -640,7 +657,7 @@ static void pr_const(Any x) {
}
static void pr_absolute(Any x) { // (absolute|relative com.sun...)
- x = resolve_typedef(cadr(x));
+ x = resolve_typedef(cadr(x), 0);
if(!use_XInterface && x == com_sun_star_uno_XInterface)
pr("java.lang.Object");
else
@@ -667,7 +684,7 @@ static void pr_deftemplate(Any x) { // (deftemplate com.sun.star.beans.Optional
pr_package(x);
Any k = sym2k(name);
pr("public class "); pp(k);
- pr("<"); pp_list(args, ", "); pr(">"); pl(" {");
+ pr("<"); pp_list(args, ", ", pp); pr(">"); pl(" {");
pr_slots(slots, k, NIL);
pr_TypeInfo(slots);
pl("}");
@@ -702,7 +719,7 @@ static void pr_primitive(Any x) {
static void pr_template(Any x) {
template = 1;
- pp(cadr(x)); pr("<"); pp_list(caddr(x), ", "); pr(">");
+ pp(cadr(x)); pr("<"); pp_list(caddr(x), ", ", pp); pr(">");
template = 0;
}
@@ -779,7 +796,7 @@ int main() {
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);
+ //pp_list(ast, NULL, pp);
mapc(build2, ast);
walk2_fn = pp;
walk2(root2);