commit 23e8559d07bba59d07dd06b7812975b1a2349135
parent d609a79b0db040cba5415e3355d951bede95b38e
Author: Tomas Hlavaty <tom@logand.com>
Date: Thu, 15 Dec 2011 23:28:17 +0100
deftemplate improved
Diffstat:
2 files changed, 33 insertions(+), 20 deletions(-)
diff --git a/parse.y b/parse.y
@@ -80,16 +80,15 @@ single_inheritance: nil | COLON name {$$ = $2};
struct_members: struct_member {$$ = list1($1);}
| struct_member struct_members {$$ = cons($1, $2);};
struct_member: type identifier SEMICOLON {$$ = list2($2, $1);};
-deftemplate: published STRUCT identifier struct_params
+deftemplate: published STRUCT identifier LT identifiers GT
LCURLY template_members RCURLY SEMICOLON
- {$$ = cons5(mk(DEFTEMPLATE, "deftemplate"), $3, $1, $4, $6);};
-struct_params: LT identifiers GT {$$ = $2;};
+ {$$ = cons5(mk(DEFTEMPLATE, "deftemplate"), $3, $1, $5, $8);};
identifiers: identifier {$$ = list1($1);}
| identifier COMMA identifiers {$$ = cons($1, $3)};
-template_members: template_member
+template_members: template_member {$$ = list1($1);}
| template_member template_members {$$ = cons($1, $2);};
template_member: struct_member | parametric_member;
-parametric_member: identifier identifier SEMICOLON {$$ = list2($1, $2);};
+parametric_member: identifier identifier SEMICOLON {$$ = list2($2, $1);};
defexception: published EXCEPTION identifier single_inheritance
LCURLY struct_members_opt RCURLY SEMICOLON {$$ = cons5($2, $3, $1, $4, $6);};
struct_members_opt: nil | struct_members;
diff --git a/unoidl2java.c b/unoidl2java.c
@@ -127,20 +127,12 @@ static void pr_args2(Any x) { // for in, out, inout
}
}
-static void pr_struct(Any x) {
- Any name = cadr(x);
- Any published = caddr(x);
- Any super = cadddr(x);
- Any slots = cddddr(x);
- pr_package(name);
- pr("public class "); pp(name);
- if(!null(super)) {pr(" extends "); pp(super);}
- pl(" { // struct");
+static void pr_slots(Any slots, Any name) {
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(" "); pp(n); pl(";");
+ pr(" public "); pp(t); pr(" _"); pp(n); pl(";");
}
pr(" public "); pp(name); pl("() {");
// TODO init enum to default
@@ -151,7 +143,7 @@ static void pr_struct(Any x) {
Any n = car(slot);
Any t = cadr(slot);
// TODO if Object => super(slot);
- pr(" this."); pp(n); pr(" = "); pp(n); pl(";");
+ pr(" this._"); pp(n); pr(" = _"); pp(n); pl(";");
}
pl(" }");
for(Any y = slots; !null(y); y = cdr(y)) {
@@ -159,12 +151,24 @@ static void pr_struct(Any x) {
Any n = car(slot);
Any t = cadr(slot);
pr(" public "); pp(t); pr(" get"); pp(n); pl("() {");
- pr(" return this."); 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(";");
+ pr(" public void set"); pp(n); pr("("); pp(t); pr(" _"); pp(n); pl(") {");
+ pr(" this._"); pp(n); pr(" = _"); pp(n); pl(";");
pl(" }");
}
+}
+
+static void pr_struct(Any x) {
+ Any name = cadr(x);
+ Any published = caddr(x);
+ Any super = cadddr(x);
+ Any slots = cddddr(x);
+ pr_package(name);
+ pr("public class "); pp(name);
+ if(!null(super)) {pr(" extends "); pp(super);}
+ pl(" { // struct");
+ pr_slots(slots, name);
pl("}");
}
@@ -312,7 +316,16 @@ static void pr_property(Any x) {
pr(" public void set"); pp(name); pr("("); pp(type); pr(" "); pp(name); pl(");");
}
-static void pr_deftemplate(Any x) { // TODO (deftemplate Pair T (T U) (T First) U Second)
+static void pr_deftemplate(Any x) {
+ Any name = cadr(x);
+ Any published = caddr(x);
+ Any args = cadddr(x);
+ Any slots = cddddr(x);
+ pr_package(name);
+ pr("public class "); pp(name);
+ pr("<"); pp_list(args, ", "); pr(">"); pl(" { // deftemplate");
+ pr_slots(slots, name);
+ pl("}");
}
static void pp(Any x) {
@@ -328,6 +341,7 @@ static void pp(Any x) {
case ENUM: pr_enum(x); break;
case STRUCT: pr_struct(x); break;
case DEFINTERFACE: pr_definterface(x); break;
+ case DEFTEMPLATE: pr_deftemplate(x); break;
case METHOD: pr_method(x); break;
//case IN:
//case OUT: