commit 932be5d6e199bd8f2bd3cd7e14524a99b76f851f
parent 96776cac56755f6e26b8ac7ab15e124605bd685e
Author: Tomas Hlavaty <tom@logand.com>
Date: Wed, 14 Dec 2011 01:47:00 +0100
more 2java improvements
Diffstat:
2 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/parse.y b/parse.y
@@ -127,7 +127,7 @@ method_params: method_param {$$ = list1($1);}
method_param: LSQUARE direction RSQUARE type identifier {$$ = list3($2, $5, $4);};
exception_spec_opt: nil | exception_spec;
direction: IN | OUT | INOUT;
-deftype: published TYPEDEF type identifier SEMICOLON {$$ = list4($2, $3, $1, $4);};
+deftype: published TYPEDEF type identifier SEMICOLON {$$ = list4($2, $4, $1, $3);};
constant: published const_decl {$$ = list2($1, $2);};
const_decl: CONST type identifier EQ exp SEMICOLON {$$ = list4($1, $2, $3, $5);};
constants: published CONSTANTS identifier LCURLY const_decls RCURLY SEMICOLON
diff --git a/unoidl2java.c b/unoidl2java.c
@@ -31,6 +31,9 @@ extern int yyparse();
extern const Any ast;
extern const Any NIL;
+static Any module;
+static Any typedefs;
+
static inline void pr(char *x) {printf("%s", x);}
static inline void pl(char *x) {printf("%s\n", x);}
@@ -46,8 +49,6 @@ static void pp_list(Any x, char *sep) {
}
}
-static Any module;
-
static void pr_module(Any x, char *sep, int dot) {
if(!null(x)) {
pr_module(cdr(x), sep, 1);
@@ -110,7 +111,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));
}
}
@@ -118,7 +119,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));
}
}
@@ -176,12 +177,12 @@ static void pr_exception(Any x) {
pl(" { // exception");
for(Any y = body; !null(y); y = cdr(y)) {
Any slot = car(y);
- pr(" "); pp(cadr(slot)); pr(" "); pp(car(slot)); pl(";");
+ pr(" "); pp(cadr(slot)); pr(" _"); pp(car(slot)); pl(";");
}
pr(" public "); pp(name); pr("("); pr_args(body); pl(") {");
for(Any y = body; !null(y); y = cdr(y)) {
Any slot = car(y);
- pr(" this."); pp(car(slot)); pr(" = "); pp(car(slot)); pl(";");
+ pr(" this._"); pp(car(slot)); pr(" = _"); pp(car(slot)); pl(";");
}
pl(" }");
pl("}");
@@ -255,8 +256,12 @@ static void pr_const(Any x) {
pp(exp); pl(HYPER == kind(car(type)) ? "L;" : ";");
}
-static void pr_typedef(Any x) { // TODO (typedef (unsigned long) T ObjectSystemID)
- // TODO remember and replace ObjectSystemID with (unsigned long) when printing type
+static void pr_typedef(Any x) {
+ typedefs = cons(x, typedefs);
+}
+
+static void pr_type(Any x) { // TODO substitute typedef
+ pp_list(cdr(x), ".");
}
static void pr_property(Any x) {
@@ -278,7 +283,7 @@ static void pp(Any x) {
switch(kind(a)) {
case MODULE:
module = cons(cadr(x), module);
- pp(caddr(x));
+ pp_list(cddr(x), "");
module = cdr(module);
break;
case ENUM: pr_enum(x); break;
@@ -289,7 +294,7 @@ static void pp(Any x) {
//case OUT:
//case INOUT: pr_arg(x); break;
case RELATIVE:
- case ABSOLUTE: pp_list(cdr(x), "."); break;
+ case ABSOLUTE: pr_type(x); break;
case CONSTANTS: pr_constants(x); break;
case CONST: pr_const(x); break;
case SEQUENCE: pp(cadr(x)); pr("[]"); break;
@@ -297,6 +302,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 TYPEDEF: pr_typedef(x); break;
case VOID:
case BOOLEAN:
case BYTE:
@@ -340,6 +346,7 @@ static void pp(Any x) {
int main() {
yyparse();
module = NIL;
+ typedefs = NIL;
pp_list(ast, NULL);
return 0;
}