|
| 1 | +package bsh; |
| 2 | + |
| 3 | +class BSHLambdaExpression extends SimpleNode { |
| 4 | + |
| 5 | + String singleParamName; |
| 6 | + |
| 7 | + private boolean initializedValues = false; |
| 8 | + private Modifiers[] paramsModifiers; |
| 9 | + private Class<?>[] paramsTypes; |
| 10 | + private String[] paramsNames; |
| 11 | + private Node body; |
| 12 | + |
| 13 | + public BSHLambdaExpression(int i) { |
| 14 | + super(i); |
| 15 | + } |
| 16 | + |
| 17 | + private void initValues(CallStack callstack, Interpreter interpreter) throws EvalError { |
| 18 | + if (this.initializedValues) return; |
| 19 | + if (this.jjtGetNumChildren() == 2) { |
| 20 | + BSHFormalParameters parameters = (BSHFormalParameters) this.jjtGetChild(0); |
| 21 | + this.paramsTypes = parameters.eval(callstack, interpreter); |
| 22 | + this.paramsModifiers = parameters.getParamModifiers(); |
| 23 | + this.paramsNames = parameters.getParamNames(); |
| 24 | + this.body = this.jjtGetChild(1); |
| 25 | + } else { |
| 26 | + this.paramsTypes = new Class[] { null }; |
| 27 | + this.paramsModifiers = new Modifiers[] { null }; |
| 28 | + this.paramsNames = new String[] { this.singleParamName }; |
| 29 | + this.body = this.jjtGetChild(0); |
| 30 | + } |
| 31 | + this.initializedValues = true; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public Object eval(CallStack callstack, Interpreter interpreter) throws EvalError { |
| 36 | + this.initValues(callstack, interpreter); |
| 37 | + return BshLambda.fromLambdaExpression(this, callstack.top(), this.paramsModifiers, this.paramsTypes, this.paramsNames, this.body); |
| 38 | + } |
| 39 | + |
| 40 | +} |
0 commit comments