thisRef.java 1.2 KB

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