Class SymTypeNormalizeVisitor
- java.lang.Object
-
- de.monticore.types3.util.SymTypeDeepCloneVisitor
-
- de.monticore.types3.util.SymTypeNormalizeVisitor
-
- All Implemented Interfaces:
ISymTypeVisitor
public class SymTypeNormalizeVisitor extends SymTypeDeepCloneVisitor
tries to normalize SymTypeExpressions, including, but not limited to, unions and intersections e.g.,(A|A|B) -> A, if A extends BUsage: calculate(symType)normalization of regular expressions are not supported
note, this visitor does not box/unbox, boxing/unboxing should be done before this visitor if required
-
-
Field Summary
-
Fields inherited from class de.monticore.types3.util.SymTypeDeepCloneVisitor
transformedSymTypes
-
-
Constructor Summary
Constructors Constructor Description SymTypeNormalizeVisitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiderrorIfEmpty(java.util.Collection<? extends SymTypeExpression> types)protected SymTypeExpressionintersect(java.util.Collection<SymTypeExpression> uniqueTypes)Intersects types and removes any redundant information (for normalized types without unions or intersections)protected SymTypeExpressionintersectArrayTypes(java.util.Collection<SymTypeArray> arrays)protected SymTypeExpressionintersectFunctionTypes(java.util.Collection<SymTypeOfFunction> functions)calculates the intersection of function types.protected java.util.Set<SymTypeOfIntersection>intersectionOfUnions2UnionOfIntersections(java.util.Set<SymTypeExpression> intersectedTypes)takes an intersection, which may contain unions and creates a union which contains intersectionsA&B&(C|D) -> (A&B&C)|(A&B&D)Note that this only calculates the given intersection, not the intersection contained within the given intersection.protected SymTypeExpressionintersectObjectTypes(java.util.Collection<? extends SymTypeExpression> objects)Objects, Genericsprotected SymTypeExpressionintersectRegExTypes(java.util.Collection<SymTypeOfRegEx> regExs)protected SymTypeExpressionintersectSimpleTypes(java.util.Collection<SymTypeExpression> simpleTypes)primitives, SIUnitsprotected SymTypeExpressionintersectTupleTypes(java.util.Collection<SymTypeOfTuple> tuples)protected SymTypeExpressionnormalizeIntersectionWithoutUnions(SymTypeOfIntersection intersection)normalizes an intersection the contained expressions are expected to be normalized and not unions s.protected SymTypeExpressionnormalizeUnionWithNormalizedTypes(SymTypeOfUnion union)protected java.util.Set<SymTypeExpression>splitIntersections(java.util.Set<SymTypeExpression> types)splits up intersections e.g.,{(A&(B&C)),D} -> {A,B,C,D}used for normalizationprotected java.util.List<SymTypeOfTuple>splitTupleByIntersection(SymTypeOfTuple tuple)Split tuples by intersections.protected java.util.List<SymTypeOfTuple>splitTupleByIntersection(SymTypeOfTuple tuple, int idx)protected java.util.List<SymTypeOfTuple>splitTupleByUnion(SymTypeOfTuple tuple)Split tuples by unions.protected java.util.List<SymTypeOfTuple>splitTupleByUnion(SymTypeOfTuple tuple, int idx)protected java.util.Set<SymTypeExpression>splitUnions(java.util.Set<SymTypeExpression> types)splits up unions e.g.,{(A|(B|C)),D} -> {A,B,C,D}used for normalizationvoidvisit(SymTypeArray array)voidvisit(SymTypeOfFunction function)voidvisit(SymTypeOfIntersection intersection)voidvisit(SymTypeOfNumericWithSIUnit numericWithSIUnit)voidvisit(SymTypeOfSIUnit siUnit)voidvisit(SymTypeOfTuple tuple)voidvisit(SymTypeOfUnion union)-
Methods inherited from class de.monticore.types3.util.SymTypeDeepCloneVisitor
applyToCollection, applyToCollection, calculate, getTransformedSymType, getTransformedSymTypes, popTransformedSubSymType, pushTransformedSymType, reset, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
-
-
-
-
Method Detail
-
visit
public void visit(SymTypeOfUnion union)
- Specified by:
visitin interfaceISymTypeVisitor- Overrides:
visitin classSymTypeDeepCloneVisitor
-
normalizeUnionWithNormalizedTypes
protected SymTypeExpression normalizeUnionWithNormalizedTypes(SymTypeOfUnion union)
-
visit
public void visit(SymTypeOfIntersection intersection)
- Specified by:
visitin interfaceISymTypeVisitor- Overrides:
visitin classSymTypeDeepCloneVisitor
-
normalizeIntersectionWithoutUnions
protected SymTypeExpression normalizeIntersectionWithoutUnions(SymTypeOfIntersection intersection)
normalizes an intersection the contained expressions are expected to be normalized and not unions s. visit(SymTypeOfIntersection)
-
intersect
protected SymTypeExpression intersect(java.util.Collection<SymTypeExpression> uniqueTypes)
Intersects types and removes any redundant information (for normalized types without unions or intersections)
-
intersectSimpleTypes
protected SymTypeExpression intersectSimpleTypes(java.util.Collection<SymTypeExpression> simpleTypes)
primitives, SIUnits
-
intersectTupleTypes
protected SymTypeExpression intersectTupleTypes(java.util.Collection<SymTypeOfTuple> tuples)
-
intersectFunctionTypes
protected SymTypeExpression intersectFunctionTypes(java.util.Collection<SymTypeOfFunction> functions)
calculates the intersection of function types.IMPORTANT: This does filter out cases that can occur for overloaded functions, e.g.,
intersect(A -> B, (A, A) -> B) = bottomThis is relevant if no type inference is used, and within type inference itself; With this version, resolved intersections MUST be split before normalization. An alternativ would be to allow the aforementioned kind of intersection, But that would lead to allowing values that are multiple function references at once. This is highly unintuitive and not supported by (most?) major languages.TODO FDr: Figure out if for the non-type-inference version the intersection has to be calculated differently (to allow for overloads), or if another representation for overloads would be better suited (which in turn would probably be turned into an intersection for the non-inference version anyway).
-
intersectRegExTypes
protected SymTypeExpression intersectRegExTypes(java.util.Collection<SymTypeOfRegEx> regExs)
-
intersectArrayTypes
protected SymTypeExpression intersectArrayTypes(java.util.Collection<SymTypeArray> arrays)
-
intersectObjectTypes
protected SymTypeExpression intersectObjectTypes(java.util.Collection<? extends SymTypeExpression> objects)
Objects, Generics
-
visit
public void visit(SymTypeArray array)
- Specified by:
visitin interfaceISymTypeVisitor- Overrides:
visitin classSymTypeDeepCloneVisitor
-
visit
public void visit(SymTypeOfTuple tuple)
- Specified by:
visitin interfaceISymTypeVisitor- Overrides:
visitin classSymTypeDeepCloneVisitor
-
visit
public void visit(SymTypeOfFunction function)
- Specified by:
visitin interfaceISymTypeVisitor- Overrides:
visitin classSymTypeDeepCloneVisitor
-
visit
public void visit(SymTypeOfNumericWithSIUnit numericWithSIUnit)
- Specified by:
visitin interfaceISymTypeVisitor- Overrides:
visitin classSymTypeDeepCloneVisitor
-
visit
public void visit(SymTypeOfSIUnit siUnit)
- Specified by:
visitin interfaceISymTypeVisitor- Overrides:
visitin classSymTypeDeepCloneVisitor
-
splitUnions
protected java.util.Set<SymTypeExpression> splitUnions(java.util.Set<SymTypeExpression> types)
splits up unions e.g.,{(A|(B|C)),D} -> {A,B,C,D}used for normalization
-
splitIntersections
protected java.util.Set<SymTypeExpression> splitIntersections(java.util.Set<SymTypeExpression> types)
splits up intersections e.g.,{(A&(B&C)),D} -> {A,B,C,D}used for normalization
-
intersectionOfUnions2UnionOfIntersections
protected java.util.Set<SymTypeOfIntersection> intersectionOfUnions2UnionOfIntersections(java.util.Set<SymTypeExpression> intersectedTypes)
takes an intersection, which may contain unions and creates a union which contains intersectionsA&B&(C|D) -> (A&B&C)|(A&B&D)Note that this only calculates the given intersection, not the intersection contained within the given intersection. An additional characteristic to mention is that NO empty intersections / unions are created if there have been none to begin with
-
splitTupleByUnion
protected java.util.List<SymTypeOfTuple> splitTupleByUnion(SymTypeOfTuple tuple)
Split tuples by unions.(A|B,C&D) -> (A,C&D), (B, C&D)does not create deep copies.
-
splitTupleByUnion
protected java.util.List<SymTypeOfTuple> splitTupleByUnion(SymTypeOfTuple tuple, int idx)
-
splitTupleByIntersection
protected java.util.List<SymTypeOfTuple> splitTupleByIntersection(SymTypeOfTuple tuple)
Split tuples by intersections.(A|B,C&D) -> (A|B,C), (A|B, D)does not create deep copies.
-
splitTupleByIntersection
protected java.util.List<SymTypeOfTuple> splitTupleByIntersection(SymTypeOfTuple tuple, int idx)
-
errorIfEmpty
protected void errorIfEmpty(java.util.Collection<? extends SymTypeExpression> types)
-
-