unoidl2

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

commit b8fd8630bb9ce64569261513fbacac7fbc675e4d
parent 8840f4666ca070e04e7a13b5e9f7b7c00a7a20e2
Author: Tomas Hlavaty <tom@logand.com>
Date:   Fri, 13 Jan 2012 01:27:13 +0100

roughly implemented pr_TypeInfo

Diffstat:
Munoidl2java.c | 147++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 104 insertions(+), 43 deletions(-)

diff --git a/unoidl2java.c b/unoidl2java.c @@ -183,10 +183,106 @@ static void pr_slots(Any slots, Any name) { pl(" }"); } -static void pr_TypeInfo(char *kind, Any name, int n, int type, Any rest) { +static int some(void *env, int (*fn)(void *env, Any e), Any x) { + for(Any y = x; !null(y); y = cdr(y)) { + int z = fn(env, car(y)); + if(z) return z; + } + return 0; +} + +static Any mapc(void *env, Any (*fn)(void *env, Any e), Any x) { + Any z = NIL; + for(Any y = x; !null(y); y = cdr(y)) + z = fn(env, car(y)); + return z; +} + +static Any method; + +static void pr_TypeInfo2(char *kind, Any name, 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("\", "); pi(n); pr(", "); pi(type); pr(")"); - pl(null(rest) ? "" : ","); + pp(name); pr("\", "); + if(!j) { + pr("\""); pp(method); pr("\", "); + } + pi(++*i); pr(", "); + pi(flags); pr(")"); +} + +enum flags { // ridljar/com/sun/star/lib/uno/typeinfo.TypeInfo.java + _IN = 0x001, + _OUT = 0x002, + _UNSIGNED = 0x004, + _READONLY = 0x008, + _ONEWAY = 0x010, + _CONST = 0x020, + _ANY = 0x040, + _INTERFACE = 0x080, + _BOUND = 0x100 +}; + +static int type_flags(Any x) { + if(consp(x)) { + switch(kind(car(x))) { + case UNSIGNED: return _UNSIGNED; + case ANY: return _ANY; + case SEQUENCE: return type_flags(cadr(x)); + } + } + return 0; +} + +static Any pr_TypeInfo1(void *env, Any x) { + int f = 0; + switch(kind(car(x))) { + case ATTRIBUTE: // (attribute (string) KeyName (readonly)) + // TODO BOUND + f |= type_flags(cadr(x)); + // TODO if(some(READONLY, cadddr(x))) f |= _READONLY; + pr_TypeInfo2("Attribute", caddr(x), f, env, -1); + break; + case ID: // (NewValue (any)) + f |= type_flags(cadr(x)); + // TODO TYPE_PARAMETER + pr_TypeInfo2("Member", car(x), f, env, -1); + break; + case METHOD: // (method queryInterface NIL (any) ((in aType (type)))) + method = cadr(x); + // TODO ONEWAY + f |= type_flags(cadddr(x)); + pr_TypeInfo2("Method", method, f, env, -1); + int i = -1; + mapc(&i, pr_TypeInfo1, caddddr(x)); + break; + case IN: // (in aType (type)) + f |= _IN | type_flags(caddr(x)); + if(f != _IN && f != (_IN | _ANY)) + pr_TypeInfo2("Parameter", cadr(x), f, env, 0); + else + ++*((int *) env); + break; + case OUT: + f |= _OUT | type_flags(caddr(x)); + pr_TypeInfo2("Parameter", cadr(x), f, env, 0); + break; + case INOUT: + f |= _IN | _OUT | type_flags(caddr(x)); + pr_TypeInfo2("Parameter", cadr(x), f, env, 0); + } +} + +static int pr_TypeInfo_p(void *env, Any x) {return INTERFACE != kind(car(x));} + +static void pr_TypeInfo(Any body) { + if(some(NULL, pr_TypeInfo_p, body)) { + pr(" public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[] = {"); + int i = -1; + mapc(&i, pr_TypeInfo1, body); + pl(""); + pl(" };"); + } } static void pr_extends(Any x) { @@ -209,13 +305,7 @@ static void pr_struct(Any x) { pr_extends(super); pl(" { // struct"); pr_slots(slots, name); - pl(" public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[] = {"); - int i = 0; - for(Any y = slots; !null(y); y = cdr(y)) { - Any slot = car(y); - pr_TypeInfo("Member", car(slot), i++, 0, cdr(y)); - } - pl(" };"); + pr_TypeInfo(slots); pl("}"); } } @@ -248,7 +338,7 @@ static void pr_exception(Any x) { pl(" this.Context = Context;"); pl(" }"); pl(" public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[] = {"); - pr_TypeInfo("Member", Context, 0, 128, NIL); + pl(" new com.sun.star.lib.uno.typeinfo.MemberTypeInfo(\"Context\", 0, 128)"); pl(" };"); } else { for(Any y = body; !null(y); y = cdr(y)) { @@ -265,15 +355,7 @@ static void pr_exception(Any x) { pr(" public "); pp(name); pr("(java.lang.String Message, java.lang.Object Object"); /* TODO additional slot args see CannotConvertException */ pl(") {"); pl(" super(Message, Object);"); pl(" }"); - if(!null(body)) { - pl(" public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[] = {"); - int i = 0; - for(Any y = body; !null(y); y = cdr(y)) { - Any slot = car(y); - pr_TypeInfo("Method", cadr(slot), i++, 0, cdr(y)); - } - pl(" };"); - } + pr_TypeInfo(body); } pl("}"); } @@ -304,22 +386,7 @@ static void pr_definterface(Any x) { pl(" {"); if(!(equal(name, XInterface) && equal(module, uno_star_sun_com))) { pp_list(body, ""); - int info = 0; - for(Any y = body; !null(y); y = cdr(y)) { - Any slot = car(y); - if(INTERFACE != kind(car(slot))) - info = 1; - } - if(info) { - pl(" public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[] = {"); - int i = 0; - for(Any y = body; !null(y); y = cdr(y)) { - Any slot = car(y); - if(INTERFACE != kind(car(slot))) - pr_TypeInfo("Method", cadr(slot), i++, 0, cdr(y)); // INTERFACE 128 - } - pl(" };"); - } + pr_TypeInfo(body); } pl("}"); } @@ -487,13 +554,7 @@ static void pr_deftemplate(Any x) { pr("public class "); pp(name); pr("<"); pp_list(args, ", "); pr(">"); pl(" { // deftemplate"); pr_slots(slots, name); - pl(" public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[] = {"); - int i = 0; - for(Any y = slots; !null(y); y = cdr(y)) { - Any slot = car(y); - pr_TypeInfo("Member", car(slot), i++, 0, cdr(y)); - } - pl(" };"); + pr_TypeInfo(slots); pl("}"); } }