Skip to content
Snippets Groups Projects
Commit d2fec907 authored by Manos Koukoutos's avatar Manos Koukoutos
Browse files

Fix GrammarDataGen for empty inputs

parent 29a4582a
Branches
Tags
No related merge requests found
...@@ -59,8 +59,20 @@ class GrammarDataGen(evaluator: Evaluator, grammar: ExpressionGrammar = ValueGra ...@@ -59,8 +59,20 @@ class GrammarDataGen(evaluator: Evaluator, grammar: ExpressionGrammar = ValueGra
} }
def generateFor(ins: Seq[Identifier], satisfying: Expr, maxValid: Int, maxEnumerated: Int): Iterator[Seq[Expr]] = { def generateFor(ins: Seq[Identifier], satisfying: Expr, maxValid: Int, maxEnumerated: Int): Iterator[Seq[Expr]] = {
def filterCond(vs: Seq[Expr]): Boolean = satisfying match {
case BooleanLiteral(true) =>
true
case e =>
// in -> e should be enough. We shouldn't find any subexpressions of in.
evaluator.eval(e, (ins zip vs).toMap) match {
case EvaluationResults.Successful(BooleanLiteral(true)) => true
case _ => false
}
}
if (ins.isEmpty) { if (ins.isEmpty) {
Iterator.empty Iterator(Seq[Expr]()).filter(filterCond)
} else { } else {
val values = generate(tupleTypeWrap(ins.map{ _.getType })) val values = generate(tupleTypeWrap(ins.map{ _.getType }))
...@@ -68,17 +80,6 @@ class GrammarDataGen(evaluator: Evaluator, grammar: ExpressionGrammar = ValueGra ...@@ -68,17 +80,6 @@ class GrammarDataGen(evaluator: Evaluator, grammar: ExpressionGrammar = ValueGra
v => unwrapTuple(v, ins.size) v => unwrapTuple(v, ins.size)
} }
def filterCond(vs: Seq[Expr]): Boolean = satisfying match {
case BooleanLiteral(true) =>
true
case e =>
// in -> e should be enough. We shouldn't find any subexpressions of in.
evaluator.eval(e, (ins zip vs).toMap) match {
case EvaluationResults.Successful(BooleanLiteral(true)) => true
case _ => false
}
}
detupled.take(maxEnumerated) detupled.take(maxEnumerated)
.filter(filterCond) .filter(filterCond)
.take(maxValid) .take(maxValid)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment