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 ServletRequest. */
12:
13: public class GetRequest extends MethodProc implements Inlineable {
14: public static final GetRequest getRequest = new GetRequest();
15:
16: public int numArgs() {
17: return 0;
18: }
19:
20: public static javax.servlet.http.HttpServletRequest getRequest(
21: CallContext ctx) {
22: return ((ServletCallContext) ctx).request;
23: }
24:
25: public void apply(CallContext ctx) {
26: ctx.lastArg();
27: ctx.consumer.writeObject(((ServletCallContext) ctx).request);
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(typeGetRequest.getDeclaredMethod(
40: "getRequest", 1));
41: target.compileFromStack(comp, typeHttpServletRequest);
42: }
43:
44: public Type getReturnType(Expression[] args) {
45: return typeHttpServletRequest;
46: }
47:
48: public static final ClassType typeGetRequest = ClassType
49: .make("gnu.kawa.servlet.GetRequest");
50:
51: public static final ClassType typeHttpServletRequest = ClassType
52: .make("javax.servlet.http.HttpServletRequest");
53: }
|