Skip to main content
summaryrefslogtreecommitdiffstats
blob: 172bee8c7d7ad18e2807bdf8e4376b283325c7b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.eclipse.xtend.backend.expr;

import java.util.List;

import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.SourcePos;
import org.eclipse.xtend.backend.functions.Closure;


/**
 * This expression creates an initialized closure. A closure needs to be initialized
 *  at runtime because it contains a snapshot of the local variables that are visible
 *  during its creation
 *  
 * @author Arno Haase (http://www.haase-consulting.com)
 */
public final class InitClosureExpression extends ExpressionBase {
    private final List<String> _paramNames;
    private final List<? extends BackendType> _paramTypes;
    private final ExpressionBase _def;

    public InitClosureExpression (List<String> paramNames, List<? extends BackendType> paramTypes, ExpressionBase def, SourcePos sourcePos) {
        super (sourcePos);
        
        _paramNames = paramNames;
        _paramTypes = paramTypes;
        _def = def;
    }

    @Override
    public Object evaluateInternal(ExecutionContext ctx) {
        return new Closure (ctx.getLocalVarContext(), ctx.getFunctionDefContext(), _paramNames, _paramTypes, _def);
    }
}

Back to the top