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.functions;
05:
06: import gnu.mapping.*;
07: import gnu.expr.*;
08:
09: /** A 0-argument function that returns a constant value.
10: * Used for false() and true() in XQuery. */
11:
12: public class ConstantFunction0 extends Procedure0 implements CanInline {
13: final Object value;
14: final QuoteExp constant;
15:
16: public ConstantFunction0(String name, Object value) {
17: super (name);
18: this .value = value;
19: this .constant = QuoteExp.getInstance(value);
20: }
21:
22: public ConstantFunction0(String name, QuoteExp constant) {
23: super (name);
24: this .value = constant.getValue();
25: this .constant = constant;
26: }
27:
28: public Object apply0() {
29: return value;
30: }
31:
32: public Expression inline(ApplyExp exp, ExpWalker walker) {
33: int nargs = exp.getArgCount();
34: if (nargs != 0 && walker != null) {
35: String message = WrongArguments.checkArgCount(this, nargs);
36: return walker.noteError(message);
37: }
38: return constant;
39: }
40: }
|