unoidl2

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

commit 3353df4826168b36c710041a15b50d011f7ca794
parent 1943e5387593f25f8f6c8ea1cd0e932307822554
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sat, 17 Dec 2011 16:18:50 +0100

many 2java improvements

Diffstat:
Munoidl2java.c | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 63 insertions(+), 16 deletions(-)

diff --git a/unoidl2java.c b/unoidl2java.c @@ -15,11 +15,6 @@ 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" @@ -34,6 +29,10 @@ extern const Any NIL; static Any module; static Any typedefs; static Any rel_package; +static Any uno_star_sun_com; +static Any Exception; + +static int template = 0; static inline void pr(char *x) {printf("%s", x);} static inline void pl(char *x) {printf("%s\n", x);} @@ -184,17 +183,22 @@ static void pr_exception(Any x) { if(!null(super)) { pr(" extends "); pp(super); } + int root = equal(name, Exception) && equal(module, uno_star_sun_com); + if(root) + pr(" extends java.lang.Exception"); 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(" 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(";"); + if(root) { // TODO + 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(";"); + } + pl(" }"); } - pl(" }"); pl("}"); } @@ -263,7 +267,16 @@ static void pr_const(Any x) { Any name = caddr(x); Any exp = cadddr(x); pr(" public static final "); pp(type); pr(" "); pp(name); pr(" = "); - pp(exp); pl(HYPER == kind(car(type)) ? "L;" : ";"); + Kind k = kind(car(type)); + if(BYTE == k) + pr(" (byte) "); + pp(exp); + switch(k) { + case HYPER: pr("L"); break; + case FLOAT: pr("f"); break; + //case BYTE: pr("y"); break; // java7 + } + pl(";"); } static void pr_typedef(Any x) { @@ -343,6 +356,38 @@ static void pr_deftemplate(Any x) { pl("}"); } +static void pr_primitive(Any x) { + if(template) { + switch(kind(car(x))) { + case BOOLEAN: pr("java.lang.Boolean"); break; + case BYTE: pr("java.lang.Byte"); break; + case SHORT: pr("java.lang.Short"); break; + case FLOAT: pr("java.lang.Float"); break; + case DOUBLE: pr("java.lang.Double"); break; + case CHAR: pr("java.lang.Character"); break; + case LONG: pr("java.lang.Integer"); break; + case HYPER: pr("java.lang.Long"); break; + } + } else { + switch(kind(car(x))) { + case BOOLEAN: + case BYTE: + case SHORT: + case FLOAT: + case DOUBLE: + case CHAR: print(car(x)); break; + case LONG: pr("int"); break; + case HYPER: pr("long"); break; + } + } +} + +static void pr_template(Any x) { + template = 1; + pp(cadr(x)); pr("<"); pp_list(caddr(x), ", "); pr(">"); + template = 0; +} + static void pp(Any x) { if(x) { if(consp(x)) { @@ -371,15 +416,15 @@ static void pp(Any x) { //case SERVICE: pr_service(x); break; case PROPERTY: pr_property(x); break; case TYPEDEF: pr_typedef(x); break; - case VOID: + case VOID: print(car(x)); break; case BOOLEAN: case BYTE: case SHORT: case FLOAT: case DOUBLE: - case CHAR: print(car(x)); break; - case LONG: pr("int"); break; - case HYPER: pr("long"); break; + case CHAR: + case LONG: + case HYPER: pr_primitive(x); break; case UNSIGNED: pp(cdr(x)); break; case STRING: pr("java.lang.String"); break; case TYPE: pr("com.sun.star.uno.Type"); break; @@ -402,7 +447,7 @@ static void pp(Any x) { } break; case NOT: pr("!"); pp(cadr(x)); break; - case TEMPLATE: pp(cadr(x)); pr("<"); pp_list(caddr(x), ", "); pr(">"); break; + case TEMPLATE: pr_template(x); break; //default: pr("###"); print(x); } } else @@ -416,6 +461,8 @@ int main() { module = NIL; typedefs = NIL; rel_package = NIL; + uno_star_sun_com = list4(mk(ID, "uno"), mk(ID, "star"), mk(ID, "sun"), mk(ID, "com")); + Exception = mk(ID, "Exception"); pp_list(ast, NULL); //print(typedefs); return 0;