Package net.hydromatic.morel.ast
Class FromBuilder
java.lang.Object
net.hydromatic.morel.ast.FromBuilder
Builds a
Core.From.
Simplifies the following patterns:
- Converts "from v in list" to "list" (only works in
buildSimplify(), notbuild()); - Removes "where true" steps;
- Removes empty "order" steps;
- Removes trivial
yield, e.g. "from v in list where condition yield v" becomes "from v in list where condition"; - Inlines
fromexpressions, e.g. "from v in (from w in list)" becomes "from w in list yield {v = w}".
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classCalls the method to re-register a step.private static enumCategory of expression passed to "yield". -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final @Nullable Environmentprivate intIf non-negative, flags that particular step should be removed if it is the last step.private intIf non-negative, flags that particular step should be removed if it is not the last step.private final List<Core.FromStep> private final TypeSystem -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAll(Iterable<? extends Core.FromStep> steps) private FromBuilderaddStep(Core.FromStep step) build()private Core.Expbuild(boolean simplify) Asbuild(boolean), but also simplifies "from x in list" to "list".voidclear()Resets state as if thisFromBuilderhad just been created.private static booleancontainsOrdinal(Core.Exp exp) Returns whether a expression callsordinal.distinct()group(SortedMap<Core.IdPat, Core.Exp> groupExps, SortedMap<Core.IdPat, Core.Aggregate> aggregates) private static booleanisSimplePat(Core.Pat pat, Core.From exp) private static booleanisTrivial(Core.Tuple tuple, Core.StepEnv env, @Nullable Core.StepEnv env2) Returns whether tuple is something like "{i = i, j = j}".Creates an unbounded scan, "from pat".Creates a bounded scan, "from pat in exp".stepEnv()Returns the environment available after the most recent step.toString()private static FromBuilder.TupleTypetupleType(Core.Tuple tuple, Core.StepEnv env, @Nullable Core.StepEnv env2) Returns whether tuple is something like "{i = i, j = j}".unorder()yield_(boolean uselessIfLast, @Nullable Core.StepEnv env2, Core.Exp exp, boolean atom) Creates a "yield" step.
-
Field Details
-
typeSystem
-
env
-
steps
-
bindings
-
atom
private boolean atom -
removeIfNotLastIndex
private int removeIfNotLastIndexIf non-negative, flags that particular step should be removed if it is not the last step. (For example, "yield {i = i}", which changes the result shape if the last step but is otherwise a no-op.) -
removeIfLastIndex
private int removeIfLastIndexIf non-negative, flags that particular step should be removed if it is the last step. (For example, we flatten "from p in (from q in list)", to "from q in list yield {p = q}" but we want to remove "yield {p = q}" if it turns out to be the last step.)
-
-
Constructor Details
-
FromBuilder
FromBuilder(TypeSystem typeSystem, @Nullable Environment env)
-
-
Method Details
-
clear
public void clear()Resets state as if thisFromBuilderhad just been created. -
toString
-
stepEnv
Returns the environment available after the most recent step. -
addStep
-
scan
Creates an unbounded scan, "from pat". -
scan
Creates a bounded scan, "from pat in exp". -
scan
-
containsOrdinal
Returns whether a expression callsordinal. -
isSimplePat
-
addAll
-
where
-
skip
-
take
-
except
-
intersect
-
union
-
unorder
-
distinct
-
group
public FromBuilder group(SortedMap<Core.IdPat, Core.Exp> groupExps, SortedMap<Core.IdPat, Core.Aggregate> aggregates) -
order
-
yield_
-
yield_
-
yield_
public FromBuilder yield_(boolean uselessIfLast, @Nullable Core.StepEnv env2, Core.Exp exp, boolean atom) Creates a "yield" step.When copying, the
env2parameter is theCore.FromStep.envvalue of the current Yield, so that we don't generate new variables (with different ordinals). Later steps are relying on the variables remaining the same. For example, infrom ... yield {a = b} where a > 5the
aina > 5referencesIdPat('a', 0)and we don't want yield to generate anIdPat('a', 1).- Parameters:
uselessIfLast- Whether this Yield will be useless if it is the last step. The expression{x = y}is an example of thisenv2- Desired step environment, or nullexp- Expression to yieldatom- Whether the expression is an atom (as opposed to a record); all atoms have just one binding, but records may also have one binding- Returns:
- This FromBuilder, with a Yield added to the list of steps
-
isTrivial
Returns whether tuple is something like "{i = i, j = j}". -
tupleType
private static FromBuilder.TupleType tupleType(Core.Tuple tuple, Core.StepEnv env, @Nullable Core.StepEnv env2) Returns whether tuple is something like "{i = i, j = j}". -
build
-
build
-
buildSimplify
Asbuild(boolean), but also simplifies "from x in list" to "list".
-