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