unoidl2

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

commit 9de4be96b15c2ddc3c6bb8ecc54bf271f8321763
parent 2e8f7573e893753795bfaec41ebd67bc80d2de58
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sun, 18 Dec 2011 01:53:35 +0100

2java improvements

Diffstat:
Munoidl2java.c | 117+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 76 insertions(+), 41 deletions(-)

diff --git a/unoidl2java.c b/unoidl2java.c @@ -37,6 +37,7 @@ static int template = 0; static inline void pr(char *x) {printf("%s", x);} static inline void pl(char *x) {printf("%s\n", x);} +static inline void pi(int x) {printf("%d", x);} static void pp(Any x); @@ -68,6 +69,7 @@ static Any last(Any x) { static void pr_package(Any class) { pr("///--- "); pr_module(module, "/", 0); pr(" "); pp(last(class)); pl(".java"); // TODO only toplevel + pl("// Generated by unoidl2java, do not edit!"); pr("package "); pr_module(module, ".", 0); pl(";"); for(Any x = cdr(module); !null(x); x = cdr(x)) { pr("import "); pr_module(x, ".", 0); pl(".*;"); @@ -121,7 +123,7 @@ static void pr_args(Any x) { for(int i = 0; !null(x); x = cdr(x), i++) { Any a = car(x); if(0 < i) pr(", "); - pp(cadr(a)); pr(" _"); pp(car(a)); + pp(cadr(a)); pr(" "); pp(car(a)); } } @@ -129,7 +131,7 @@ static void pr_args2(Any x) { // for in, out, inout for(int i = 0; !null(x); x = cdr(x), i++) { Any a = car(x); if(0 < i) pr(", "); - pp(caddr(a)); pr(" _"); pp(cadr(a)); + pp(caddr(a)); pr(" "); pp(cadr(a)); } } @@ -138,31 +140,29 @@ static void pr_slots(Any slots, Any name) { Any slot = car(y); Any n = car(slot); Any t = cadr(slot); - pr(" public "); pp(t); pr(" _"); pp(n); pl(";"); + pr(" public "); pp(t); pr(" "); pp(n); pl(";"); } pr(" public "); pp(name); pl("() {"); // TODO init enum to default - pl(" }"); - pr(" public "); pp(name); pr("("); pr_args(slots); pl(") {"); for(Any y = slots; !null(y); y = cdr(y)) { Any slot = car(y); Any n = car(slot); Any t = cadr(slot); - // TODO if Object => super(slot); - pr(" this._"); pp(n); pr(" = _"); pp(n); pl(";"); + switch(kind(t)) { + case STRING: pr(" this."); pp(n); pr(" = \"\";"); break; + case ANY: pr(" this."); pp(n); pr(" = Any.VOID;"); break; + } } pl(" }"); + pr(" public "); pp(name); pr("("); pr_args(slots); pl(") {"); for(Any y = slots; !null(y); y = cdr(y)) { Any slot = car(y); Any n = car(slot); Any t = cadr(slot); - pr(" public "); pp(t); pr(" get"); pp(n); pl("() {"); - pr(" return this._"); pp(n); pl(";"); - pl(" }"); - pr(" public void set"); pp(n); pr("("); pp(t); pr(" _"); pp(n); pl(") {"); - pr(" this._"); pp(n); pr(" = _"); pp(n); pl(";"); - pl(" }"); + // TODO if Object => super(slot); + pr(" this."); pp(n); pr(" = "); pp(n); pl(";"); } + pl(" }"); } static void pr_struct(Any x) { @@ -175,6 +175,13 @@ static void pr_struct(Any x) { if(!null(super)) {pr(" extends "); pp(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(" new com.sun.star.lib.uno.typeinfo.MemberTypeInfo(\""); pp(car(slot)); pr("\", "); pi(i++); pr(", 4)"); pl(null(y) ? "" : ","); + } + pl(" };"); pl("}"); } @@ -186,45 +193,49 @@ static void pr_exception(Any x) { pr_package(name); pr("public class "); pp(name); int e = equal(name, Exception) && equal(module, uno_star_sun_com); + int r = equal(name, RuntimeException) && equal(module, uno_star_sun_com); if(e) pr(" extends java.lang.Exception"); - int r = equal(name, RuntimeException) && equal(module, uno_star_sun_com); - if(r) + else if(r) pr(" extends java.lang.RuntimeException"); - if(!e && !r && !null(super)) { + else if(!null(super)) { pr(" extends "); pp(super); } pl(" { // exception"); - for(Any y = body; !null(y); y = cdr(y)) { - Any slot = car(y); - pr(" "); pp(cadr(slot)); pr(" _"); pp(car(slot)); pl(";"); - } - if(e) { - pl(" public Exception() {"); + if(e || r) { + pl(" public java.lang.Object Context;"); + pr(" public "); pp(name); pl("() {"); pl(" }"); - pl(" public Exception(java.lang.String _Message) {"); - pl(" this._Message = _Message;"); + pr(" public "); pp(name); pl("(java.lang.String Message) {"); + pl(" super(Message);"); pl(" }"); - pr(" public "); pp(name); pr("("); pr_args(body); pl(") {"); + pr(" public "); pp(name); pl("(java.lang.String Message, java.lang.Object Context) {"); + pl(" super(Message);"); + pl(" this.Context = Context;"); + pl(" }"); + pl(" public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[] = {"); + pl(" new com.sun.star.lib.uno.typeinfo.MemberTypeInfo(\"Context\", 0, 128)"); + pl(" };"); + } else { for(Any y = body; !null(y); y = cdr(y)) { Any slot = car(y); - pr(" this._"); pp(car(slot)); pr(" = _"); pp(car(slot)); pl(";"); + pr(" "); pp(cadr(slot)); pr(" "); pp(car(slot)); pl(";"); } - pl(" }"); - } else if(r) { - pl(" java.lang.String _Message;"); - pl(" public RuntimeException() {"); - pl(" }"); - pl(" public RuntimeException(java.lang.String _Message) {"); - pl(" this._Message = _Message;"); - pl(" }"); - } else { pr(" public "); pp(name); pl("() {"); - pl(" super();"); pl(" }"); - pl(" public "); pp(name); pl("(java.lang.String _Message) {"); - pl(" super(_Message);"); + pr(" public "); pp(name); pl("(java.lang.String Message) {"); + pl(" super(Message);"); pl(" }"); + pr(" public "); pp(name); pl("(java.lang.String Message, java.lang.Object Object) {"); + pl(" super(Message, Object);"); + pl(" }"); + 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(" new com.sun.star.lib.uno.typeinfo.MemberTypeInfo(\""); pp(cadr(slot)); pr("\", "); pi(i++); pr(", 128)"); pl(null(y) ? "" : ","); + } + pl(" };"); } pl("}"); } @@ -239,6 +250,13 @@ static void pr_definterface(Any x) { if(!null(super)) {pr(" extends "); pp(super);} pl(" {"); pp_list(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(" new com.sun.star.lib.uno.typeinfo.MemberTypeInfo(\""); pp(cadr(slot)); pr("\", "); pi(i++); pr(", 0)"); pl(null(y) ? "" : ","); + } + pl(" };"); pl("}"); } @@ -248,7 +266,7 @@ static void pr_method(Any x) { Any type = cadddr(x); Any args = caddddr(x); Any body = cdddddr(x); - pr(" "); pp(type); pr(" "); pp(name); pr("("); pr_args2(args); pr(")"); + pr(" public abstract "); pp(type); pr(" "); pp(name); pr("("); pr_args2(args); pr(")"); if(!null(body)) { pr(" throws "); pp_list(body, ", "); } @@ -276,7 +294,23 @@ static void pr_service(Any x) { pl("}"); } -static void pr_singleton(Any x) { // TODO (singleton theMacroExpander T (relative MacroExpander) T) +static void pr_singleton(Any x) { + /* Any name = cadr(x); */ + /* Any published = caddr(x); */ + /* Any type = cadddr(x); */ + /* int iface = !null(caddddr(x)); */ + /* pr_package(name); */ + /* pr("public class "); pp(name); */ + /* if(iface) {pr(" extends "); pp(type);} */ + /* pr(" { // "); pr(iface ? "interface" : "service"); pl(" singleton"); */ + /* pr(" private "); pp(name); pl("() {}"); */ + /* pl(" private static class Holder {"); */ + /* pr(" public static final "); pp(name); pr(" instance = new "); pp(name); pl("();"); */ + /* pl(" }"); */ + /* pr(" public static "); pp(name); pl(" getInstance() {"); */ + /* pl(" return Holder.instance;"); */ + /* pl(" }"); */ + /* pl("}"); */ } static void pr_constants(Any x) { @@ -284,7 +318,7 @@ static void pr_constants(Any x) { Any published = caddr(x); Any body = cdddr(x); pr_package(name); - pr("public final class "); pp(name); pl(" { // constants"); + pr("public interface "); pp(name); pl(" { // constants"); pp_list(body, ""); pl("}"); } @@ -439,6 +473,7 @@ static void pp(Any x) { case EXCEPTION: pr_exception(x); break; //case SERVICE: pr_service(x); break; case PROPERTY: pr_property(x); break; + case SINGLETON: pr_singleton(x); break; case TYPEDEF: pr_typedef(x); break; case VOID: print(car(x)); break; case BOOLEAN: