These changes add support for choice item types per XQuery 4.
A choice item type is repesented by an instance of class ChoiceItemType, which holds the alternatives in a list of SeqTypes. The parser ensures that there are no nested ChoiceItemTypes by flattening out.
ChoiceItemType has specific implementations of some methods, e.g. instanceOf, union, and intersect. The implementations of those three are also reused by all other derivations of Type. Most of the properties of ChoiceItemType are based on the single type calculated by the union of all alternatives.
A choice item type may be an atomic type, but cannot derive from enum AtomType. Thus there now is an atomic type that is not covered by that and some occurrences of AtomType needed to be changed, most notably MapType.keyType. As a consequence, SeqType.mapTypes had to change from an EnumMap to a HashMap. This also required the implementation of SeqType.hashCode.
In SeqType.coerce, alternatives of a choice item type are tried sequentially until a matching one is found. Here a possible optimization might be to calculate the atomization just once, and reuse it in subsequent attempts. Not sure whether it is worth implementing it this way.
With respect to QT4 tests, these changes make all but three tests cases with prefixes union-type and choice-type succeed, the remaining three fail for unrelated reasons. Also there are more test cases that now succeed, e.g. with prefixes DynamicFunctionCall, enum, and Keywords-fn-in-scope-namespaces.
If you see anything that I might have missed, please let me know. I will gladly continue to work on this.
These changes add support for choice item types per XQuery 4.
A choice item type is repesented by an instance of class
ChoiceItemType
, which holds the alternatives in a list ofSeqTypes
. The parser ensures that there are no nestedChoiceItemTypes
by flattening out.ChoiceItemType
has specific implementations of some methods, e.g.instanceOf
,union
, andintersect
. The implementations of those three are also reused by all other derivations ofType
. Most of the properties ofChoiceItemType
are based on the single type calculated by the union of all alternatives.A choice item type may be an atomic type, but cannot derive from
enum AtomType
. Thus there now is an atomic type that is not covered by that and some occurrences ofAtomType
needed to be changed, most notablyMapType.keyType
. As a consequence,SeqType.mapTypes
had to change from anEnumMap
to aHashMap
. This also required the implementation ofSeqType.hashCode
.In
SeqType.coerce
, alternatives of a choice item type are tried sequentially until a matching one is found. Here a possible optimization might be to calculate the atomization just once, and reuse it in subsequent attempts. Not sure whether it is worth implementing it this way.With respect to QT4 tests, these changes make all but three tests cases with prefixes
union-type
andchoice-type
succeed, the remaining three fail for unrelated reasons. Also there are more test cases that now succeed, e.g. with prefixesDynamicFunctionCall
,enum
, andKeywords-fn-in-scope-namespaces
.If you see anything that I might have missed, please let me know. I will gladly continue to work on this.