private void VisitSortKey(QilSortKey ndKey, LocalBuilder locKeys) {
Label lblOnEndKey;
Debug.Assert(ndKey.Key.XmlType.IsAtomicValue, "Sort key must be an atomic value.");
// Push collation onto the stack
this.helper.Emit(OpCodes.Ldloca, locKeys);
if (ndKey.Collation.NodeType == QilNodeType.LiteralString) {
// collation = runtime.GetCollation(idx);
this.helper.CallGetCollation(this.helper.StaticData.DeclareCollation((string) (QilLiteral) ndKey.Collation));
}
else {
// collation = runtime.CreateCollation(str);
this.helper.LoadQueryRuntime();
NestedVisitEnsureStack(ndKey.Collation);
this.helper.Call(XmlILMethods.CreateCollation);
}
if (ndKey.XmlType.IsSingleton) {
NestedVisitEnsureStack(ndKey.Key);
// keys.AddSortKey(collation, value);
this.helper.AddSortKey(ndKey.Key.XmlType);
}
else {
lblOnEndKey = this.helper.DefineLabel();
StartNestedIterator(ndKey.Key, lblOnEndKey);
Visit(ndKey.Key);
this.iterCurr.EnsureStackNoCache();
this.iterCurr.EnsureItemStorageType(ndKey.Key.XmlType, GetItemStorageType(ndKey.Key));
// Non-empty sort key
// keys.AddSortKey(collation, value);
this.helper.AddSortKey(ndKey.Key.XmlType);
// goto LabelDone;
// LabelOnEnd:
Label lblDone = this.helper.DefineLabel();
this.helper.EmitUnconditionalBranch(OpCodes.Br_S, lblDone);
this.helper.MarkLabel(lblOnEndKey);
// Empty sequence key
// keys.AddSortKey(collation);
this.helper.AddSortKey(null);
this.helper.MarkLabel(lblDone);
EndNestedIterator(ndKey.Key);
}
}