commit eac08ff414d53e4d57739661f1ba9f94fc2e4f22
parent a8e1db1155c461ec7ff09fa36796b340974c4a88
Author: Tomas Hlavaty <tom@logand.com>
Date: Sun, 18 Mar 2012 17:09:13 +0100
s/run1/build2 with configurable subst2 for different backends
Diffstat:
4 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/unoidl2.c b/unoidl2.c
@@ -292,49 +292,43 @@ static Any intern2abs(Any x) {
static Any get2(Any x) {return cddr(car(x));}
static Any set2(Any x, Any v) {return con(cdr(car(x)), v);}
-static Any module2;
-static void run1_module(Any x) {
- Any p = module2;
- module2 = intern2rel(sym1(cadr(x)), p);
- Any v = get2(module2);
- if(NIL == v)
- set2(module2, car(x));
- mapc(run1, cddr(x));
- module2 = p;
-}
+static Any module2;
+Any subst2_x;
-static Any subst2(Any x) {
- Any y;
- if(consp(x)) {
- switch(kind(car(x))) {
+Any subst2_rel_abs(Any v) {
+ Any w;
+ if(consp(v)) {
+ switch(kind(car(v))) {
case RELATIVE: //(relative XInterface)
- y = cdr(x);
- set(y, intern2rel(sym1(car(y)), module2));
+ w = cdr(v);
+ set(w, intern2rel(sym1(car(w)), module2));
break;
case ABSOLUTE: //(absolute com sun star uno XInterface)
- y = cdr(x);
- set(y, intern2abs(y));
- con(y, NIL);
+ w = cdr(v);
+ set(w, intern2abs(w));
+ con(w, NIL);
break;
default:
- mapc(subst2, x);
+ mapc(subst2_rel_abs, v);
}
}
- return x;
+ return v;
}
-static void run1_leave(Any x) {
- Any s = intern2rel(sym1(cadr(x)), module2);
- if(NIL != get2(s))
- printf("@@@ run1_leave error: duplicate ");
- set(cdr(x), s);
- set2(s, subst2(x));
-}
+Any (*build2_fn)(Any x) = id;
-Any run1(Any x) {
+Any build2(Any x) {
+ Any p, s;
switch(kind(car(x))) {
- case MODULE: run1_module(x); break;
+ case MODULE:
+ p = module2;
+ module2 = intern2rel(sym1(cadr(x)), p);
+ Any v = get2(module2);
+ if(NIL == v) set2(module2, car(x));
+ mapc(build2, cddr(x));
+ module2 = p;
+ break;
case DEFINTERFACE:
case EXCEPTION:
case ENUM:
@@ -343,10 +337,16 @@ Any run1(Any x) {
case CONSTANTS:
case SINGLETON:
case TYPEDEF:
- case DEFTEMPLATE: run1_leave(x); break;
+ 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));
+ break;
case INTERFACE: break; // TODO eg XMultiComponentFactory?
default:
- printf("@@@ run1 error: ");
+ printf("@@@ build2 error: ");
print(x);
printf("\n");
}
diff --git a/unoidl2.h b/unoidl2.h
@@ -65,7 +65,10 @@ Any mapc(Fn1 fn, Any x);
Any find(Any elt, Any lst, Fn2 cmp, Fn1 key);
Any reverse(Any x, Any a);
Any id(Any x);
-Any run1(Any x);
+extern Any subst2_x;
+Any subst2_rel_abs(Any v);
+extern Any (*build2_fn)(Any v);
+Any build2(Any x);
extern void (*walk2_fn)(Any x, Any c, Any k, Any p, Any v);
Any walk2(Any x);
void init();
diff --git a/unoidl2ast.c b/unoidl2ast.c
@@ -34,7 +34,8 @@ int main() {
init();
yyparse();
//mapc(pr1, ast);
- mapc(run1, ast);
+ build2_fn = subst2_rel_abs;
+ mapc(build2, ast);
walk2_fn = cell2ast;
walk2(root2);
return 0;
diff --git a/unoidl2java.c b/unoidl2java.c
@@ -830,6 +830,16 @@ static void pp(Any x) {
printf("NIL");
}
+static Any subst2java(Any v) {
+ v = subst2_rel_abs(v);
+ switch(kind(car(v))) {
+ case ENUM: enums = cons(subst2_x, enums);
+ case STRUCT: structs = cons(subst2_x, structs);
+ case TYPEDEF: typedefs = cons(subst2_x, typedefs);
+ }
+ return v;
+}
+
int main() {
init();
yyparse();
@@ -847,5 +857,7 @@ int main() {
pp_list(ast, NULL);
//print(typedefs);
//print(enums);
+ build2_fn = subst2java;
+ mapc(build2, ast);
return 0;
}