unoidl2

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

commit e3d6411fcbf70f92473ff3d6ae464e445acc3227
parent 389d0bbd3c9586137b780c61cc2ea30029fc9f58
Author: Tomas Hlavaty <tom@logand.com>
Date:   Thu,  8 Dec 2011 00:01:29 +0100

unoidl2java: print package properly

Diffstat:
Munoidl2java.c | 56+++++++++++++++++++++++++-------------------------------
1 file changed, 25 insertions(+), 31 deletions(-)

diff --git a/unoidl2java.c b/unoidl2java.c @@ -13,32 +13,28 @@ static inline void pl(char *x) {printf("%s\n", x);} static void pp(Any x); -static void pp_list(Any x) { - for(; !null(x); x = cdr(x)) { - pr("#"); print(car(x)); pl(""); - pp(car(x)); - } -} - -static void pp_clist(Any x) { +static void pp_list(Any x, char *sep) { for(int i = 0; !null(x); x = cdr(x), i++) { - if(0 < i) pr(", "); + if(!sep) { + pr("###"); print(car(x)); pl(""); + } + if(0 < i) pr(sep); pp(car(x)); } } -static void pr_relative(Any x) { - pp(cadr(x)); - x = cddr(x); - for(; !null(x); x = cdr(x)) { - pr("."); +Any module; + +static void pr_module(Any x, int dot) { + if(!null(x)) { + pr_module(cdr(x), 1); pp(car(x)); + if(dot) pr("."); } } -static void pr_module() { // TODO - char *name = "PACKAGE"; - pl("package "); pr(name); pl(";"); +static void pr_package() { + pr("package "); pr_module(module, 0); pl(";"); } // http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Professional_UNO @@ -49,7 +45,7 @@ static void pr_enum(Any x) { Any values = cdddr(x); Any v0 = car(values); Any v0k = consp(v0) ? car(v0) : v0; - pr_module(); + pr_package(); pr("public final class "); pp(name); pl(" extends com.sun.star.uno.Enum {"); pr(" private "); pp(name); pl("(int value) {"); pl(" super(value);"); @@ -99,7 +95,7 @@ static void pr_struct(Any x) { Any published = caddr(x); Any super = cadddr(x); Any slots = cddddr(x); - pr_module(); + pr_package(); pr("public class "); pp(name); if(!null(super)) {pr(" extends "); pp(super);} pl(" {"); @@ -124,7 +120,7 @@ static void pr_exception(Any x) { Any published = caddr(x); Any super = cadddr(x); Any body = cddddr(x); - pr_module(); + pr_package(); pr("public class "); pp(name); if(!null(super)) { pr(" extends "); pp(super); @@ -148,11 +144,11 @@ static void pr_interface(Any x) { Any published = caddr(x); Any super = cadddr(x); Any body = cddddr(x); - pr_module(); + pr_package(); pr("public interface "); pp(name); if(!null(super)) {pr(" extends "); pp(super);} pl(" {"); - pp_list(body); + pp_list(body, ""); pl("}"); } @@ -164,7 +160,7 @@ static void pr_method(Any x) { Any body = cdddddr(x); // TODO throws pr(" "); pp(type); pr(" "); pp(name); pr("("); pr_args2(args); pr(")"); if(!null(body)) { - pr(" throws "); pp_clist(body); + pr(" throws "); pp_list(body, ", "); } pl(";"); } @@ -187,9 +183,9 @@ static void pr_constants(Any x) { Any name = cadr(x); Any published = caddr(x); Any body = cdddr(x); - pr_module(); + pr_package(); pr("public final class "); pp(name); pl(" {"); - pp_list(body); + pp_list(body, ""); pl("}"); } @@ -201,17 +197,15 @@ static void pr_const(Any x) { static void pr_typedef(Any x) { } -Any module; - static void pp(Any x) { if(x) { if(consp(x)) { Any a = car(x); switch(kind(a)) { case MODULE: - //module = cons(cadr(x), module); - print(module); + module = cons(cadr(x), module); pp(caddr(x)); + module = cdr(module); break; case ENUM: pr_enum(x); break; case STRUCT: pr_struct(x); break; @@ -221,7 +215,7 @@ static void pp(Any x) { //case OUT: //case INOUT: pr_arg(x); break; case RELATIVE: - case ABSOLUTE: 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; @@ -262,6 +256,6 @@ static void pp(Any x) { int main() { yyparse(); module = NIL; - pp_list(ast); + pp_list(ast, NULL); return 0; }