commit 5aa7d2fedcfdae3aae590f7dab582feb9e86d1cf
parent ea3487c3966083843986f5a6bc563cb26a5b3bab
Author: Tomas Hlavaty <tom@logand.com>
Date: Wed, 14 Dec 2011 00:52:02 +0100
uniodl2java improvements
Diffstat:
3 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/Makefile b/Makefile
@@ -44,7 +44,8 @@ allpp.idl: all.idl
java.list: allpp.idl
rm -rf java
mkdir -p java/src java/build
- cat allpp.idl | ./unoidl2java | (cd java/src ; ../../javasplit)
+ cat allpp.idl | ./unoidl2java > allpp.java
+ cat allpp.java | (cd java/src ; ../../javasplit)
(cd java/src ; find com -name '*.java') >java.list
(cd java/src ; javac -cp $(LIBO)/ridljar:. -d ../build @../../java.list)
diff --git a/parse.y b/parse.y
@@ -57,6 +57,7 @@ Any ast;
%token REMOVABLE
%token METHOD CONSTRUCTOR RELATIVE ABSOLUTE TEMPLATE EXP DEFTEMPLATE
+%token DEFINTERFACE
%%
@@ -94,7 +95,8 @@ defexception: published EXCEPTION identifier single_inheritance
struct_members_opt: nil | struct_members;
interface_forward: published INTERFACE name SEMICOLON {$$ = list3($2, $3, $1);};
definterface: published INTERFACE identifier single_inheritance
- LCURLY interface_members RCURLY SEMICOLON {$$ = cons5($2, $3, $1, $4, $6);};
+ LCURLY interface_members RCURLY SEMICOLON
+ {$$ = cons5(mk(DEFINTERFACE, "definterface"), $3, $1, $4, $6);};
interface_members: nil | interface_member interface_members {$$ = cons($1, $2);};
interface_member: interface_inheritance | attribute | interface_forward | defmethod;
interface_inheritance: optional INTERFACE name SEMICOLON {$$ = list3($2, $3, $1);};
diff --git a/unoidl2java.c b/unoidl2java.c
@@ -15,6 +15,11 @@
You should have received a copy of the GNU General Public License
along with unoidl2. If not, see <http://www.gnu.org/licenses/>.
*/
+/*
+ See also:
+ http://wiki.services.openoffice.org/wiki/Uno/Java/Specifications/Type_Mapping
+ http://udk.openoffice.org/common/man/typesystem.html
+ */
#include "unoidl2.h"
#include "parse.c.h"
@@ -71,19 +76,20 @@ static void pr_enum(Any x) {
Any v0 = car(values);
Any v0k = consp(v0) ? car(v0) : v0;
pr_package(name);
- pr("public final class "); pp(name); pl(" extends com.sun.star.uno.Enum {");
+ pr("public final class "); pp(name); pl(" extends com.sun.star.uno.Enum { // enum");
pr(" private "); pp(name); pl("(int value) {");
pl(" super(value);");
pl(" }");
pr(" public static "); pp(name); pl(" getDefault() {");
pr(" return "); pp(v0k); pl(";");
pl(" }");
- int n = 0;
+ int n = 0; // TODO inc the last explicit value
for(Any y = values; !null(y); y = cdr(y)) {
Any value = car(y);
char *k = token(consp(value) ? car(value) : value);
- Any v = consp(value) ? cdr(value) : mkinum(n++);
- pr(" public static final "); pp(name); pr(" "); pr(k); pr(" = new "); pp(name); pr("("); pp(v); pl(");");
+ Any v = consp(value) ? cadr(value) : mkinum(n++);
+ pr(" public static final "); pp(name); pr(" "); pr(k); pr(" = new ");
+ pp(name); pr("("); pp(v); pl(");");
}
pr(" public static "); pp(name); pl(" fromInt(int value) {");
pl(" switch(value) {");
@@ -91,7 +97,7 @@ static void pr_enum(Any x) {
for(Any y = values; !null(y); y = cdr(y)) {
Any value = car(y);
char *k = token(consp(value) ? car(value) : value);
- Any v = consp(value) ? cdr(value) : mkinum(n++);
+ Any v = consp(value) ? cadr(value) : mkinum(n++);
pr(" case "); pp(v); pr(": return "); pr(k); pl(";");
}
pl(" }");
@@ -124,7 +130,7 @@ static void pr_struct(Any x) {
pr_package(name);
pr("public class "); pp(name);
if(!null(super)) {pr(" extends "); pp(super);}
- pl(" {");
+ pl(" { // struct");
for(Any y = slots; !null(y); y = cdr(y)) {
Any slot = car(y);
Any n = car(slot);
@@ -167,7 +173,7 @@ static void pr_exception(Any x) {
if(!null(super)) {
pr(" extends "); pp(super);
}
- pl(" {");
+ pl(" { // exception");
for(Any y = body; !null(y); y = cdr(y)) {
Any slot = car(y);
pr(" "); pp(cadr(slot)); pr(" "); pp(car(slot)); pl(";");
@@ -181,7 +187,7 @@ static void pr_exception(Any x) {
pl("}");
}
-static void pr_interface(Any x) { // TODO nesting
+static void pr_definterface(Any x) {
Any name = cadr(x);
Any published = caddr(x);
Any super = cadddr(x);
@@ -221,11 +227,11 @@ static void pr_service(Any x) {
Any super = cadddr(x);
Any body = caddddr(x);
pr_package(name);
- pr("public class "); pp(name);
+ pr("public class "); pp(last(name));
if(!null(super)) {pr(" extends "); pp(super);}
- pl(" {");
+ pl(" { // service");
pp_list(body, "");
- pl(" }");
+ pl("}");
}
static void pr_singleton(Any x) { // TODO (singleton theMacroExpander T (relative MacroExpander) T)
@@ -236,14 +242,17 @@ static void pr_constants(Any x) {
Any published = caddr(x);
Any body = cdddr(x);
pr_package(name);
- pr("public final class "); pp(name); pl(" {");
+ pr("public final class "); pp(name); pl(" { // constants");
pp_list(body, "");
pl("}");
}
static void pr_const(Any x) {
- pr(" public static final "); pp(cadr(x)); pr(" ");
- pp(caddr(x)); pr(" = "); pp(cadddr(x)); pl(";");
+ Any type = cadr(x);
+ Any name = caddr(x);
+ Any exp = cadddr(x);
+ pr(" public static final "); pp(type); pr(" "); pp(name); pr(" = ");
+ pp(exp); pl(";");
}
static void pr_typedef(Any x) { // TODO (typedef (unsigned long) T ObjectSystemID)
@@ -254,14 +263,9 @@ static void pr_property(Any x) {
Any name = cadr(x);
Any type = caddr(x);
Any options = cadddr(x);
- //pr_package();
- //pr("public class "); pp(name); pl(" {");
pr(" protected "); pp(type); pr(" "); pp(name); pl(";");
- //pr(" public "); pp(name); pl("();");
- //pr(" public "); pp(name); pr("("); pp(type); pr(" "); pp(name); pl(");");
pr(" public "); pp(type); pr(" get"); pp(name); pl("();");
pr(" public void set"); pp(name); pr("("); pp(type); pr(" "); pp(name); pl(");");
- pl("}");
}
static void pr_deftemplate(Any x) { // TODO (deftemplate Pair T (T U) (T First) U Second)
@@ -279,7 +283,7 @@ static void pp(Any x) {
break;
case ENUM: pr_enum(x); break;
case STRUCT: pr_struct(x); break;
- case INTERFACE: pr_interface(x); break;
+ case DEFINTERFACE: pr_definterface(x); break;
case METHOD: pr_method(x); break;
//case IN:
//case OUT:
@@ -289,9 +293,9 @@ static void pp(Any x) {
case CONSTANTS: pr_constants(x); break;
case CONST: pr_const(x); break;
case SEQUENCE: pp(cadr(x)); pr("[]"); break;
- case ATTRIBUTE: pr_attribute(x); break;
+ //case ATTRIBUTE: pr_attribute(x); break;
case EXCEPTION: pr_exception(x); break;
- case SERVICE: pr_service(x); break;
+ //case SERVICE: pr_service(x); break;
case PROPERTY: pr_property(x); break;
case VOID:
case BOOLEAN:
@@ -314,10 +318,16 @@ static void pp(Any x) {
case MUL:
case DIV:
case MOD: pp(cadr(x)); pp(car(x)); pp(caddr(x)); break;
- //case PLUS: unary?
- //case MINUS:
+ case PLUS:
+ case MINUS:
+ if(null(cddr(x))) { // unary
+ pp(car(x)); pp(cadr(x));
+ } else { // binary
+ pp(cadr(x)); pp(car(x)); pp(caddr(x));
+ }
+ break;
case NOT: pr("!"); pp(cadr(x)); break;
- default: pr("###"); print(x);
+ //default: pr("###"); print(x);
}
} else
print(x);