Search in sources :

Example 1 with TemporalConstantNode

use of org.kie.dmn.feel.lang.ast.TemporalConstantNode in project drools by kiegroup.

the class ASTCompilerVisitor method visit.

@Override
public DirectCompilerResult visit(FunctionInvocationNode n) {
    TemporalConstantNode tcFolded = n.getTcFolded();
    if (tcFolded != null) {
        return replaceWithTemporalConstant(n, tcFolded);
    }
    DirectCompilerResult functionName = n.getName().accept(this);
    DirectCompilerResult params = n.getParams().accept(this);
    return DirectCompilerResult.of(Expressions.invoke(functionName.getExpression(), params.getExpression()), functionName.resultType).withFD(functionName).withFD(params);
}
Also used : TemporalConstantNode(org.kie.dmn.feel.lang.ast.TemporalConstantNode)

Example 2 with TemporalConstantNode

use of org.kie.dmn.feel.lang.ast.TemporalConstantNode in project drools by kiegroup.

the class ASTTemporalConstantVisitor method visit.

@Override
public ASTNode visit(FunctionInvocationNode n) {
    Optional<FEELFunction> fnOpt = Optional.empty();
    if (n.getName() instanceof NameRefNode) {
        // simple name
        fnOpt = scopeHelper.resolve(n.getName().getText());
    } else if (n.getName() instanceof QualifiedNameNode) {
        QualifiedNameNode qnn = (QualifiedNameNode) n.getName();
        String[] qns = qnn.getPartsAsStringArray();
        String qn = Stream.of(qns).collect(Collectors.joining(" "));
        fnOpt = scopeHelper.resolve(qn);
    }
    if (fnOpt.isPresent()) {
        FEELFunction fn = fnOpt.get();
        if (TEMPORAL_FNS.contains(fn)) {
            try {
                TemporalConstantNode tcNode = buildTemporalConstantNode(n, fn);
                n.setTcFolded(tcNode);
            } catch (Exception e) {
            // temporal constant inlining failed, not an issue, simply not memoized.
            }
        }
    }
    return super.visit(n);
}
Also used : FEELFunction(org.kie.dmn.feel.runtime.FEELFunction) TemporalConstantNode(org.kie.dmn.feel.lang.ast.TemporalConstantNode) QualifiedNameNode(org.kie.dmn.feel.lang.ast.QualifiedNameNode) NameRefNode(org.kie.dmn.feel.lang.ast.NameRefNode)

Aggregations

TemporalConstantNode (org.kie.dmn.feel.lang.ast.TemporalConstantNode)2 NameRefNode (org.kie.dmn.feel.lang.ast.NameRefNode)1 QualifiedNameNode (org.kie.dmn.feel.lang.ast.QualifiedNameNode)1 FEELFunction (org.kie.dmn.feel.runtime.FEELFunction)1