01: // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.kawa.servlet;
05:
06: import gnu.lists.*;
07: import gnu.mapping.*;
08: import gnu.bytecode.*;
09: import gnu.expr.*;
10:
11: /** A 0-argument function that returns the current ServletResponse. */
12:
13: public class GetResponse extends MethodProc implements Inlineable {
14: public static final GetResponse getResponse = new GetResponse();
15:
16: public static javax.servlet.http.HttpServletResponse getResponse(
17: CallContext ctx) {
18: return ((ServletCallContext) ctx).response;
19: }
20:
21: public int numArgs() {
22: return 0;
23: }
24:
25: public void apply(CallContext ctx) {
26: ctx.lastArg();
27: ctx.consumer.writeObject(((ServletCallContext) ctx).response);
28: }
29:
30: public void compile(ApplyExp exp, Compilation comp, Target target) {
31: Expression[] args = exp.getArgs();
32: if (args.length != 0 || !comp.curLambda.isHandlingTailCalls()) {
33: ApplyExp.compile(exp, comp, target);
34: return;
35: }
36:
37: CodeAttr code = comp.getCode();
38: comp.loadCallContext();
39: code.emitInvokeStatic(typeGetResponse.getDeclaredMethod(
40: "getResponse", 1));
41: target.compileFromStack(comp, typeHttpServletResponse);
42: }
43:
44: public Type getReturnType(Expression[] args) {
45: return typeHttpServletResponse;
46: }
47:
48: public static final ClassType typeGetResponse = ClassType
49: .make("gnu.kawa.servlet.GetResponse");
50:
51: public static final ClassType typeHttpServletResponse = ClassType
52: .make("javax.servlet.http.HttpServletResponse");
53: }
|