* SequenceType.cs : moved type inference method to XPathAtomicValue.
Use IsArray in runtime type inference. Initialize fields completely.
Handle collection to runtime type for functions that takes array.
* XPath2Expression.cs : Add whitespaces on serializing XPath items.
EBV != atomized boolean value. Add Atomize() for XPathItem (Atomize()
for XPathSequence should be removed in the future).
Replaced some ExprSequence to ExprSingle for optimization.
* XQueryFunctionCliImpl.cs : Fixed some return types.
* XQueryTokenizer.cs : Fixed weird ReadDecimal().
svn path=/trunk/mcs/; revision=32812
+2004-08-25 Atsushi Enomoto <atsushi@ximian.com>
+
+ * SequenceType.cs : moved type inference method to XPathAtomicValue.
+ Use IsArray in runtime type inference. Initialize fields completely.
+ Handle collection to runtime type for functions that takes array.
+ * XPath2Expression.cs : Add whitespaces on serializing XPath items.
+ EBV != atomized boolean value. Add Atomize() for XPathItem (Atomize()
+ for XPathSequence should be removed in the future).
+ Replaced some ExprSequence to ExprSingle for optimization.
+ * XQueryFunctionCliImpl.cs : Fixed some return types.
+ * XQueryTokenizer.cs : Fixed weird ReadDecimal().
+
2004-08-24 Atsushi Enomoto <atsushi@ximian.com>
* SequenceType.cs : added ToRuntimeType().
internal static SequenceType Create (Type cliType)
{
- switch (Type.GetTypeCode (cliType)) {
- case TypeCode.Int32:
- return Int;
- case TypeCode.Decimal:
- return Decimal;
- case TypeCode.Double:
- return Double;
- case TypeCode.Single:
- return Single;
- case TypeCode.Int64:
- return Integer;
- case TypeCode.Int16:
- return Short;
- case TypeCode.UInt16:
- return UnsignedShort;
- case TypeCode.UInt32:
- return UnsignedInt;
- case TypeCode.String:
- return AtomicString;
- case TypeCode.DateTime:
- return DateTime;
- case TypeCode.Boolean:
- return Boolean;
- case TypeCode.Object:
- return AnyType;
- }
+ // typed Array
+ if (cliType.IsArray)
+ return Create (XPathAtomicValue.XmlTypeCodeFromRuntimeType (cliType.GetElementType (), true), Occurence.ZeroOrMore);
if (cliType == typeof (XmlQualifiedName))
return QName;
if (cliType == typeof (XPathNavigator) || cliType.IsSubclassOf (typeof (XPathNavigator)))
return SingleAnyAtomic;
if (cliType == typeof (XPathItem))
return SingleItem;
- // FIXME: typed Array
- if (cliType.IsSubclassOf (typeof (ICollection)))
- return AnyType;
- throw new NotSupportedException (String.Format ("Specified type is not supported for {0}", cliType));
+ return Create (XPathAtomicValue.XmlTypeCodeFromRuntimeType (cliType, true), Occurence.One);
}
internal static SequenceType Create (XmlTypeCode typeCode, Occurence occurence)
private SequenceType (XmlSchemaType schemaType, Occurence occurence)
{
this.schemaType = schemaType;
+ this.itemType = ItemType.AnyItem;
this.occurence = occurence;
}
internal SequenceType (ItemType itemType, Occurence occurence)
{
+ this.schemaType = XmlSchemaComplexType.AnyType;
this.itemType = itemType;
this.occurence = occurence;
}
public object ToRuntimeType (XPathSequence seq)
{
// FIXME: handle ZeroOrMore|OneOrMore
-// switch (occurence) {
-// case Occurence.One:
-// case Occurence.Optional:
+ switch (occurence) {
+ case Occurence.One:
+ case Occurence.Optional:
XPathAtomicValue av = ExprSingle.Atomize (seq);
return av != null ? av.TypedValue : null;
-// }
+ }
+ ArrayList al = new ArrayList ();
+ while (seq.MoveNext ())
+ al.Add (seq.Current.TypedValue);
+ return al.ToArray (XPathAtomicValue.RuntimeTypeFromXmlTypeCode (schemaType.TypeCode));
// return seq;
}
}
{
XmlWriter w = iter.Context.Writer;
XPathSequence result = Evaluate (iter);
- foreach (XPathItem item in result)
+ bool initial = true;
+ foreach (XPathItem item in result) {
+ if (initial)
+ initial = false;
+ else
+ w.WriteWhitespace (" ");
WriteXPathItem (item, w);
+ }
}
private void WriteXPathItem (XPathItem item, XmlWriter w)
w.WriteValue (item.Value);
}
- // get EBV
+ // get EBV (fn:boolean())
public virtual bool EvaluateAsBoolean (XPathSequence iter)
{
- XPathAtomicValue v = Atomize (Evaluate (iter));
- return v != null ? v.ValueAsBoolean : false;
+ XPathSequence result = Evaluate (iter);
+ if (!result.MoveNext ())
+ return false;
+ XPathAtomicValue v = Atomize (result.Current);
+ if (result.MoveNext ())
+ return true;
+ switch (v.XmlType.TypeCode) {
+ case XmlTypeCode.Boolean:
+ return v.ValueAsBoolean;
+ case XmlTypeCode.String:
+ case XmlTypeCode.UntypedAtomic:
+ return v.Value != String.Empty;
+ case XmlTypeCode.Float:
+ return v.ValueAsSingle != Single.NaN && v.ValueAsSingle != 0.0;
+ case XmlTypeCode.Double:
+ return v.ValueAsDouble != Double.NaN && v.ValueAsSingle != 0.0;
+ case XmlTypeCode.Integer:
+ case XmlTypeCode.NonPositiveInteger:
+ case XmlTypeCode.NegativeInteger:
+ case XmlTypeCode.Long:
+ case XmlTypeCode.Int:
+ case XmlTypeCode.Short:
+ case XmlTypeCode.Byte:
+ case XmlTypeCode.UnsignedInt:
+ case XmlTypeCode.UnsignedShort:
+ case XmlTypeCode.UnsignedByte:
+ return v.ValueAsInt64 != 0;
+ case XmlTypeCode.NonNegativeInteger:
+ case XmlTypeCode.UnsignedLong:
+ case XmlTypeCode.PositiveInteger:
+ return (ulong) (v.ValueAs (typeof (ulong))) != 0;
+ }
+ // otherwise, return true
+ return true;
}
public virtual int EvaluateAsInt (XPathSequence iter)
return v != null ? v.Value : String.Empty;
}
+ public static XPathAtomicValue Atomize (XPathItem item)
+ {
+ XPathNavigator nav = item as XPathNavigator;
+ if (nav != null)
+ return new XPathAtomicValue (nav.TypedValue, nav.SchemaInfo.SchemaType);
+ else
+ return (XPathAtomicValue) item;
+ }
+
// FIXME: What if iter contains list value?
public static XPathAtomicValue Atomize (XPathSequence iter)
{
public FLWORExpr (ForLetClauseCollection forlet, ExprSequence whereClause, OrderSpecList orderBy, ExprSingle ret)
{
this.fl = forlet;
- this.whereClause = whereClause;
+ this.whereClause = new ParenthesizedExpr (whereClause);
this.orderBy = orderBy;
this.ret = ret;
}
ForLetClauseCollection fl;
- ExprSequence whereClause;
+ ExprSingle whereClause;
OrderSpecList orderBy;
ExprSingle ret;
get { return fl; }
}
- public ExprSequence WhereClause {
+ public ExprSingle WhereClause {
get { return whereClause; }
}
}
}
if (WhereClause != null)
- for (int i = 0; i < WhereClause.Count; i++)
- WhereClause [i] = WhereClause [i].Compile (compiler);
+// for (int i = 0; i < WhereClause.Count; i++)
+// WhereClause [i] = WhereClause [i].Compile (compiler);
+ whereClause = whereClause.Compile (compiler);
if (OrderBy != null)
foreach (OrderSpec os in OrderBy)
os.Expression = os.Expression.Compile (compiler);
public TypeswitchExpr (ExprSequence switchExpr, CaseClauseList caseList, XmlQualifiedName defaultVarName, ExprSingle defaultReturn)
{
+ this.switchExpr = switchExpr;
+ this.caseList = caseList;
+ this.defaultVarName = defaultVarName;
+ this.defaultReturn = defaultReturn;
}
public ExprSequence SwitchExpr {
{
public IfExpr (ExprSequence condition, ExprSingle trueExpr, ExprSingle falseExpr)
{
- this.condition = condition;
+ this.condition = new ParenthesizedExpr (condition);
this.trueExpr = trueExpr;
this.falseExpr = falseExpr;
}
- ExprSequence condition;
+ ExprSingle condition;
ExprSingle trueExpr;
ExprSingle falseExpr;
- public ExprSequence Condition {
+ public ExprSingle Condition {
get { return condition; }
set { condition = value; }
}
internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
{
- for (int i = 0; i < Condition.Count; i++)
- Condition [i] = Condition [i].Compile (compiler);
+// for (int i = 0; i < Condition.Count; i++)
+// Condition [i] = Condition [i].Compile (compiler);
+ condition = condition.Compile (compiler);
// FIXME: check if condition is constant, and returns trueExpr or falseExpr
TrueExpr = TrueExpr.Compile (compiler);
FalseExpr = FalseExpr.Compile (compiler);
public override XPathSequence Evaluate (XPathSequence iter)
{
- foreach (ExprSingle expr in Condition) {
- if (expr.EvaluateAsBoolean (iter))
- return TrueExpr.Evaluate (iter);
- }
+// foreach (ExprSingle expr in Condition) {
+// if (expr.EvaluateAsBoolean (iter))
+// return TrueExpr.Evaluate (iter);
+// }
+ if (condition.EvaluateAsBoolean (iter))
+ return TrueExpr.Evaluate (iter);
return FalseExpr.Evaluate (iter);
}
#endregion
public class XQueryCompileOptions
{
public XQueryCompileOptions ()
- : this (new NameTable (), CultureInfo.InvariantCulture)
+ : this (new NameTable (), null)
{
}
{
this.nameTable = nameTable;
this.defaultCollation = defaultCollation;
+ if (this.defaultCollation == null)
+ this.defaultCollation = CultureInfo.InvariantCulture;
knownCollections = new Hashtable ();
}
throw new NotImplementedException ();
}
- public static object FnCompare (string s1, string s2)
+ public static int FnCompare (XQueryContext ctx, string s1, string s2)
{
- return string.Compare (s1, s2);
+ return FnCompare (s1, s2, ctx.DefaultCollation);
}
- public static object FnCompare (string s1, string s2, string collation)
+ public static int FnCompare (XQueryContext ctx, string s1, string s2, string collation)
{
- throw new NotImplementedException ();
+ return FnCompare (s1, s2, ctx.GetCulture (collation));
+ }
+
+ private static int FnCompare (string s1, string s2, CultureInfo ci)
+ {
+ return ci.CompareInfo.Compare (s1, s2);
}
- public static object FnConcat (object o1, object o2)
+ public static string FnConcat (object o1, object o2)
{
return String.Concat (o1, o2);
}
- public static object FnStringJoin (string [] strings, string separator)
+ public static string FnStringJoin (string [] strings, string separator)
{
return String.Join (separator, strings);
}
- public static object FnSubstring (string src, double loc)
+ public static string FnSubstring (string src, double loc)
{
return src.Substring ((int) loc);
}
- public static object FnSubstring (string src, double loc, double length)
+ public static string FnSubstring (string src, double loc, double length)
{
return src.Substring ((int) loc, (int) length);
}
return s.Length;
}
- public static object FnNormalizeSpace (XQueryContext ctx)
+ public static string FnNormalizeSpace (XQueryContext ctx)
{
return FnNormalizeSpace (FnString (ctx));
}
[MonoTODO]
- public static object FnNormalizeSpace (string s)
+ public static string FnNormalizeSpace (string s)
{
throw new NotImplementedException ();
}
- public static object FnNormalizeUnicode (string arg)
+ public static string FnNormalizeUnicode (string arg)
{
return FnNormalizeUnicode (arg, "NFC");
}
[MonoTODO]
- public static object FnNormalizeUnicode (string arg, string normalizationForm)
+ public static string FnNormalizeUnicode (string arg, string normalizationForm)
{
throw new NotImplementedException ();
}
- public static object FnUpperCase (string arg)
+ public static string FnUpperCase (string arg)
{
// FIXME: supply culture
return arg.ToUpper ();
}
- public static object FnLowerCase (string arg)
+ public static string FnLowerCase (string arg)
{
// FIXME: supply culture
return arg.ToLower ();
}
- public static object FnTranslate (string arg, string mapString, string transString)
+ public static string FnTranslate (string arg, string mapString, string transString)
{
return arg == null ? null : arg.Replace (mapString, transString);
}
[MonoTODO]
- public static object FnEscapeUri (string uriPart, bool escapeReserved)
+ public static string FnEscapeUri (string uriPart, bool escapeReserved)
{
throw new NotImplementedException ();
}
- public static object FnContains (XQueryContext ctx, string arg1, string arg2)
+ public static bool FnContains (XQueryContext ctx, string arg1, string arg2)
{
return FnContains (arg1, arg2, ctx.DefaultCollation);
}
- public static object FnContains (XQueryContext ctx, string arg1, string arg2, string collation)
+ public static bool FnContains (XQueryContext ctx, string arg1, string arg2, string collation)
{
return FnContains (arg1, arg2, ctx.GetCulture (collation));
}
- private static object FnContains (string arg1, string arg2, CultureInfo ci)
+ private static bool FnContains (string arg1, string arg2, CultureInfo ci)
{
if (arg1 == null)
arg1 = String.Empty;
private decimal ReadDecimal (bool floatingPoint)
{
bufferIndex = 0;
+ bool cond = true;
do {
int c = PeekChar ();
if (c < 0) {
- ReadChar ();
- break;
+ cond = false;
}
// FIXME: more complex
- if (Char.IsNumber ((char) c)) {
+ else if (Char.IsNumber ((char) c) || c == '.') {
ReadChar ();
AddValueChar ((char) c);
continue;
}
else
- break;
- } while (true);
- string s = (floatingPoint ? "" : ".") + CreateValueString ();
+ cond = false;
+ } while (cond);
+ string s = (floatingPoint ? "." : "") + CreateValueString ();
return decimal.Parse (s);
}