use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class DMNDTAnalyser method toIntervals.
private List<Interval> toIntervals(List<BaseNode> elements, boolean isNegated, Interval minMax, List discreteValues, int rule, int col) {
List<Interval> results = new ArrayList<>();
if (elements.size() == 1 && elements.get(0) instanceof UnaryTestNode && ((UnaryTestNode) elements.get(0)).getValue() instanceof NullNode) {
return Collections.emptyList();
}
if (discreteValues != null && !discreteValues.isEmpty() && areAllEQUnaryTest(elements) && elements.size() > 1) {
// JDK BitSet size will always be larger.
int bitsetLogicalSize = discreteValues.size();
BitSet hitValues = new BitSet(bitsetLogicalSize);
for (BaseNode n : elements) {
Comparable<?> thisValue = valueFromNode(((UnaryTestNode) n).getValue());
int indexOf = discreteValues.indexOf(thisValue);
if (indexOf < 0) {
throw new IllegalStateException("Unable to determine discreteValue index for: " + n);
}
hitValues.set(indexOf);
}
if (isNegated) {
hitValues.flip(0, bitsetLogicalSize);
}
int lowerBoundIdx = -1;
int upperBoundIdx = -1;
for (int i = 0; i < hitValues.length(); i++) {
boolean curValue = hitValues.get(i);
if (curValue) {
if (lowerBoundIdx < 0) {
lowerBoundIdx = i;
upperBoundIdx = i;
} else {
upperBoundIdx = i;
}
} else {
if (lowerBoundIdx >= 0 && upperBoundIdx >= 0) {
results.add(createIntervalOfRule(discreteValues, rule, col, lowerBoundIdx, upperBoundIdx));
lowerBoundIdx = -1;
upperBoundIdx = -1;
}
}
}
if (lowerBoundIdx >= 0 && upperBoundIdx >= 0) {
results.add(createIntervalOfRule(discreteValues, rule, col, lowerBoundIdx, upperBoundIdx));
}
} else {
for (BaseNode n : elements) {
if (n instanceof DashNode) {
results.add(new Interval(minMax.getLowerBound().getBoundaryType(), minMax.getLowerBound().getValue(), minMax.getUpperBound().getValue(), minMax.getUpperBound().getBoundaryType(), rule, col));
continue;
}
UnaryTestNode ut = (UnaryTestNode) n;
Interval interval = utnToInterval(ut, minMax, discreteValues, rule, col);
if (isNegated) {
results.addAll(Interval.invertOverDomain(interval, minMax));
} else {
results.add(interval);
}
}
}
return results;
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class ASTCompilerVisitor method visit.
@Override
public DirectCompilerResult visit(UnaryTestListNode n) {
MethodCallExpr expr = Expressions.list();
HashSet<FieldDeclaration> fds = new HashSet<>();
for (BaseNode e : n.getElements()) {
DirectCompilerResult r = e.accept(this);
fds.addAll(r.getFieldDeclarations());
expr.addArgument(r.getExpression());
}
if (n.isNegated()) {
Expressions.NamedLambda negated = Expressions.namedUnaryLambda(Expressions.notExists(expr), n.getText());
fds.add(negated.field());
return DirectCompilerResult.of(Expressions.list(negated.name()), BuiltInType.LIST, fds);
} else {
return DirectCompilerResult.of(expr, BuiltInType.LIST, fds);
}
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class ASTCompilerVisitor method visit.
@Override
public DirectCompilerResult visit(PathExpressionNode n) {
DirectCompilerResult expr = n.getExpression().accept(this);
BaseNode nameNode = n.getName();
if (nameNode instanceof QualifiedNameNode) {
QualifiedNameNode qualifiedNameNode = (QualifiedNameNode) n.getName();
List<Expression> exprs = qualifiedNameNode.getParts().stream().map(name -> new StringLiteralExpr(name.getText())).collect(Collectors.toList());
return DirectCompilerResult.of(Expressions.path(expr.getExpression(), exprs), // here we could still try to infer the result type, but presently use ANY
BuiltInType.UNKNOWN).withFD(expr);
} else {
return DirectCompilerResult.of(Expressions.path(expr.getExpression(), new StringLiteralExpr(nameNode.getText())), // here we could still try to infer the result type, but presently use ANY
BuiltInType.UNKNOWN).withFD(expr);
}
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELImpl method parseTest.
@Override
public String parseTest(final String value) {
final FEEL_1_1Parser parser = FEELParser.parse(null, value, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), Collections.emptyList(), null);
final ParseTree tree = parser.expression();
final ASTBuilderVisitor v = new ASTBuilderVisitor(Collections.emptyMap(), null);
final BaseNode expr = v.visit(tree);
return expr.getText() + " - " + expr.getResultType() + " - " + expr.toString();
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class ASTBuilderVisitor method visitQuantExprSome.
@Override
public BaseNode visitQuantExprSome(FEEL_1_1Parser.QuantExprSomeContext ctx) {
ListNode list = (ListNode) visit(ctx.iterationContexts());
BaseNode expr = visit(ctx.expression());
return ASTBuilderFactory.newQuantifiedExpression(ctx, QuantifiedExpressionNode.Quantifier.SOME, list, expr);
}
Aggregations