public class FilterHomomorphism extends Homomorphism
fhom[list,op,id](filter,f) = if isEmpty(list)
then id
else let elt = head(list)
in if filter(elt)
then op(f(elt),fhom[tail(list),op,id](filter,f))
else fhom[tail(list),op,id](filter,f)
This class is defined to enable an optimization of monoid comprehensions where a boolean
qualifier can be integrated directly into the homomorphism preceding it, thus doing away
with the generation of a larger set than necessary. When this is used after normalizing
monoid comprehension with unnesting of conditions to the uppermost scope they control
together with gathering them into a single logical and, the net effect is a
drastic reduction of the size of loops. Recall that a monoid comprehension
is an expression of the form:
[op,id] { e | q1, ..., qn }
where [op,id] define a monoid, e is an expression, and the
qi's are qualifiers. A qualifier is either a
(boolean) expression or a pair x <- e, where x is
a variable and e is a (collection) expression. After normalization,
there may be at most one boolean qualifier in the sequence (which may
also be empty). Such a normalized monoid comprehension can then be translated
as follows:
[op,id]{e | } = op(e,id);
[op,id]{e | c} = if c then op(e,id) else id;
[op,id]{e | x <- e', c, Q} = f_hom(e', lambda x.[op,id]{e | Q}, op, id, lambda x.c);
[op,id]{e | x <- e', y <- e'', Q} = hom(e', lambda x.[op,id]{e | y <- e'', Q}, op, id);
DEFAULT_IN_PLACE, DISABLED_IN_PLACE, ENABLED_IN_PLACEVOID_ASSIGNMENTS| Constructor and Description |
|---|
FilterHomomorphism(Tables tables,
Expression collection,
Expression function,
Expression operation,
Expression identity,
Expression filter) |
| Modifier and Type | Method and Description |
|---|---|
void |
compile(Compiler compiler)
This method compiles this expression in the context of the specified
Compiler.
|
Expression |
copy()
Returns a deep copy of this expression.
|
int |
numberOfSubexpressions()
Returns the number of subexpressions
|
void |
setCheckedType()
This method sets the final unambiguously checked type of this expression, possibly
along with other final information that may be needed by the compiler for
generating code.
|
Expression |
setSubexpression(int n,
Expression expression)
Returns this expression after setting its n-th subexpression to the specified
expression; if there is no subexpression at the given position, this throws a
NoSuchSubexpressionException
|
Expression |
subexpression(int n)
Returns the n-th subexpression of this expression; if there is no subexpression
at the given position, this throws a NoSuchSubexpressionException
|
java.lang.String |
toString() |
void |
typeCheck(TypeChecker typeChecker)
|
Expression |
typedCopy()
Returns a deep copy of this expression this and all its subexpressions share the
same type as their copy's counterparts.
|
disableInPlace, enableInPlace, setSlicings, setSlicingscheckedType, setCheckedType, setType, type, typeRefaddType, addTypes, boxSort, containsFreeName, enclosingScope, extent, getEnd, getStart, isConstant, isEquality, isFalse, isHiddenSlicing, isNull, isSelector, isSlicing, isTrue, isVoid, locationString, otherTypes, parameters, sanitizeNames, sanitizeSorts, setCheckedTypeLocked, setEnd, setExtent, setOtherTypes, setStart, shiftOffsets, shiftOffsets, sort, substitute, typeCheck, typeCheck, typeCheckLockedpublic FilterHomomorphism(Tables tables, Expression collection, Expression function, Expression operation, Expression identity, Expression filter)
public final Expression copy()
Expressioncopy in class Homomorphismpublic final Expression typedCopy()
ExpressiontypedCopy in class Homomorphismpublic int numberOfSubexpressions()
numberOfSubexpressions in class Homomorphismpublic final Expression subexpression(int n) throws NoSuchSubexpressionException
subexpression in class HomomorphismNoSuchSubexpressionExceptionpublic final Expression setSubexpression(int n, Expression expression) throws NoSuchSubexpressionException
ExpressionsetSubexpression in class HomomorphismNoSuchSubexpressionExceptionpublic final void typeCheck(TypeChecker typeChecker) throws TypingErrorException
Homomorphism
Primitive: OR Collection:
_collection : from_collection(A) _collection : from_collection(A)
_function : A -> B _function : A -> to_collection(B)
_operation : B,B -> B _operation : B, to_collection(B) -> to_collection(B)
_identity : B _identity : to_collection(B)
this : B this : to_collection(B)
Also, if slicing expressions are present, they must be typed as booleans.
NB: In order to accommodate primitive homomorphisms whose monoid operation is not strictly-speaking internal but may involve subtyping, we use a work-around that consists of unifying the shadow types of the operation's arguments rather than the types themselves. The changes from the lines needed for typing such "loose" monoids are marked explicitly and the original lines they replace are commented out. Unifying shadow types is done using a special goal: a ShadowUnifyGoal.
typeCheck in class HomomorphismTypingErrorExceptionpublic final void setCheckedType()
ExpressionsetCheckedType in class Homomorphismpublic final void compile(Compiler compiler)
Expressioncompile in class Homomorphismpublic final java.lang.String toString()
toString in class Homomorphism