try_catch.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package kawa.standard;
  2. import kawa.lang.*;
  3. import gnu.lists.*;
  4. import gnu.expr.*;
  5. /**
  6. * Utility method for try-catch.
  7. */
  8. public class try_catch
  9. {
  10. public static Expression rewrite (Pair try_part_pair, Object clauses)
  11. {
  12. Translator tr = (Translator) Compilation.getCurrent();
  13. Expression try_part_exp = tr.rewrite_car(try_part_pair, false);
  14. CatchClause prev = null;
  15. CatchClause chain = null;
  16. FVector vec = (FVector) clauses;
  17. int n = vec.size();
  18. for (int i = 0; i < n; i++)
  19. {
  20. Expression cl = SchemeCompilation.lambda.rewrite(vec.get(i), tr);
  21. if (cl instanceof ErrorExp)
  22. return cl;
  23. if (! (cl instanceof LambdaExp))
  24. return tr.syntaxError("internal error with try-catch");
  25. CatchClause ccl = new CatchClause((LambdaExp) cl);
  26. if (prev == null)
  27. chain = ccl;
  28. else
  29. prev.setNext(ccl);
  30. prev = ccl;
  31. }
  32. if (try_part_exp instanceof ErrorExp)
  33. return try_part_exp;
  34. TryExp texp = new TryExp(try_part_exp, null);
  35. texp.setCatchClauses(chain);
  36. return texp;
  37. }
  38. }