commit ae7968a00962d96175320d8e351ed73db3d6fad4
parent e2b612e7d23c2e25782e2d27c1139d5477897d17
Author: Tomas Hlavaty <tom@logand.com>
Date: Wed, 21 Mar 2012 02:07:14 +0100
2java fix constants
Diffstat:
3 files changed, 44 insertions(+), 18 deletions(-)
diff --git a/parse.y b/parse.y
@@ -130,7 +130,7 @@ exception_spec_opt: nil | exception_spec;
direction: IN | OUT | INOUT;
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);};
+const_decl: CONST type identifier EQ exp SEMICOLON {$$ = list4($1, $3, $2, $5);};
constants: published CONSTANTS identifier LCURLY const_decls RCURLY SEMICOLON
{$$ = cons4($2, $3, $1, $5);};
const_decls: nil | const_decl const_decls {$$ = cons($1, $2);};
diff --git a/unoidl2.c b/unoidl2.c
@@ -314,6 +314,13 @@ Any subst2_rel_abs(Any v) {
Any w;
if(consp(v)) {
switch(kind(car(v))) {
+ case CONST:
+ w = module2;
+ module2 = sym2p(module2);
+ subst2_rel_abs(caddr(v));
+ module2 = w;
+ mapc(subst2_rel_abs, cdddr(v));
+ break;
case RELATIVE: //(relative XInterface)
w = cdr(v);
set(w, intern2rel(sym1(car(w)), module2));
@@ -333,30 +340,41 @@ Any subst2_rel_abs(Any v) {
Fn1 build2_fn = id;
Any build2(Any x) {
- Any p, s;
+ Any p, z;
switch(kind(car(x))) {
case MODULE:
p = module2;
- module2 = intern2rel(sym1(cadr(x)), p);
- Any v = get2(module2);
- if(NIL == v) set2(module2, car(x));
+ z = intern2rel(sym1(cadr(x)), p);
+ module2 = z;
+ Any v = get2(z);
+ if(NIL == v) set2(z, car(x));
mapc(build2, cddr(x));
module2 = p;
break;
+ case CONSTANTS:
+ p = module2;
+ z = intern2rel(sym1(cadr(x)), p);
+ module2 = z;
+ if(NIL != get2(z)) printf("@@@ build2 error: duplicate ");
+ set(cdr(x), z);
+ set2(z, x);
+ mapc(build2, cdddr(x));
+ module2 = p;
+ break;
case DEFINTERFACE:
case EXCEPTION:
case ENUM:
case SERVICE:
case STRUCT:
- case CONSTANTS:
+ case CONST:
case SINGLETON:
case TYPEDEF:
case DEFTEMPLATE:
- s = intern2rel(sym1(cadr(x)), module2);
- if(NIL != get2(s)) printf("@@@ build2 error: duplicate ");
- set(cdr(x), s);
- subst2_x = s;
- set2(s, build2_fn(x));
+ z = intern2rel(sym1(cadr(x)), module2);
+ if(NIL != get2(z)) printf("@@@ build2 error: duplicate ");
+ set(cdr(x), z);
+ subst2_x = z;
+ set2(z, build2_fn(x));
break;
case INTERFACE: break; // TODO eg XMultiComponentFactory?
default:
@@ -364,7 +382,7 @@ Any build2(Any x) {
print(x);
printf("\n");
}
- return x;
+ return z;
}
Fn1 walk2_fn;
@@ -382,8 +400,12 @@ Any walk2(Any x) {
} else if(NIL == c) {
walk2_fn(v);
} else {
- printf("@@@ walk2 error: unexpected children\n");
- print(x);
+ if(CONSTANTS != kind(car(v))) {
+ printf("@@@ walk2 error: unexpected children ");
+ print(x);
+ printf("\n");
+ }
+ walk2_fn(v);
}
return x;
}
diff --git a/unoidl2java.c b/unoidl2java.c
@@ -613,16 +613,20 @@ static void pr_constants(Any x) {
Any body = cdddr(x);
pr_package(x);
pr("public interface "); pp(sym2k(name)); pl(" {");
- pp_list(body, "");
+ mapc(pp, body);
pl("}");
}
}
static void pr_const(Any x) {
- Any type = cadr(x);
- Any name = caddr(x);
+ Any name = cadr(x);
+ Any type = caddr(x);
Any exp = cadddr(x);
- pr(" public static final "); pp(type); pr(" "); pp(name); pr(" = ");
+ pr(" public static final ");
+ Any y = find(type, typedefs, equal, id);
+ if(NIL != y) type = y;
+ pp(type);
+ pr(" "); pp(sym2k(name)); pr(" = ");
Kind k = kind(car(type));
if(BYTE == k)
pr(" (byte) ");