01: package kawa.standard;
02:
03: import kawa.lang.*;
04: import gnu.lists.*;
05: import gnu.expr.*;
06: import gnu.kawa.reflect.*;
07: import gnu.bytecode.*;
08:
09: public class define_member_alias extends Syntax {
10: public static final define_member_alias define_member_alias = new define_member_alias();
11: static {
12: define_member_alias.setName("define-member-alias");
13: }
14:
15: public boolean scanForDefinitions(Pair st, java.util.Vector forms,
16: ScopeExp defs, Translator tr) {
17: Pair p;
18: if (!(st.cdr instanceof Pair)
19: || (tr.currentScope() instanceof ModuleExp)
20: || !((p = (Pair) st.cdr).car instanceof String))
21: return super .scanForDefinitions(st, forms, defs, tr);
22: Object name = p.car;
23: Declaration decl = defs.addDeclaration((String) name,
24: Compilation.typeSymbol);
25: decl.setIndirectBinding(true);
26: st = Translator.makePair(st, this , Translator.makePair(p, decl,
27: p.cdr));
28: forms.addElement(st);
29: return true;
30: }
31:
32: public Expression rewriteForm(Pair form, Translator tr) {
33: Object obj = form.cdr;
34: Pair p1;
35: if (!(obj instanceof Pair)
36: || !((p1 = (Pair) obj).car instanceof String || p1.car instanceof Declaration))
37: return tr.syntaxError("missing name in " + getName());
38: if (p1.cdr instanceof Pair) {
39: String name;
40: Declaration decl;
41: if (p1.car instanceof Declaration) {
42: decl = (Declaration) p1.car;
43: name = decl.getName();
44: } else {
45: name = (String) p1.car;
46: decl = null;
47: }
48: Pair p2 = (Pair) p1.cdr;
49: Expression fname = null;
50: Expression arg = tr.rewrite(p2.car);
51: if (p2.cdr == LList.Empty)
52: fname = new QuoteExp(gnu.expr.Compilation
53: .mangleName(name));
54: else if (p2.cdr instanceof Pair) {
55: Pair p3 = (Pair) p2.cdr;
56: if (p3.cdr == LList.Empty)
57: fname = tr.rewrite(p3.car);
58: }
59: if (fname != null) {
60: ClassType t = ClassType
61: .make("gnu.kawa.reflect.ClassMemberConstraint");
62: Expression[] args = new Expression[3];
63: args[0] = new QuoteExp(name);
64: args[1] = arg;
65: args[2] = fname;
66: return Invoke.makeInvokeStatic(t, "define", args);
67: }
68: }
69: return tr.syntaxError("invalid syntax for " + getName());
70: }
71: }
|