01: package kawa.standard;
02:
03: import gnu.expr.*;
04: import gnu.lists.*;
05: import kawa.lang.*;
06: import gnu.bytecode.Type;
07:
08: public class this Ref extends Syntax {
09: public static final thisRef this Syntax = new thisRef();
10: static {
11: this Syntax.setName("this");
12: }
13:
14: public Expression rewriteForm(Pair form, Translator tr) {
15: if (form.cdr == LList.Empty) {
16: LambdaExp method = tr.curMethodLambda;
17: Declaration firstParam = method == null ? null : method
18: .firstDecl();
19: if (firstParam == null || !firstParam.isThisParameter()) {
20: firstParam = null;
21: if (method == null || method.nameDecl == null)
22: tr
23: .error('e',
24: "use of 'this' not in a named method");
25: else if (method.nameDecl.isStatic())
26: tr.error('e', "use of 'this' in a static method");
27: else {
28: firstParam = new Declaration(ThisExp.THIS_NAME,
29: (Type) null);
30: method.add(null, firstParam);
31: method.nameDecl
32: .setFlag(Declaration.NONSTATIC_SPECIFIED);
33: }
34: }
35: return new ThisExp(firstParam);
36: } else
37: return tr
38: .syntaxError("this with parameter not implemented");
39: }
40: }
|