Skip to content

Commit

Permalink
2004-10-05 Atsushi Enomoto <atsushi@ximian.com>
Browse files Browse the repository at this point in the history
	* XPathSequence.cs, XQueryTokenizer.cs :
	  removed commented && unused code.
	* XQueryContext.cs, XQueryCliFunction.cs, XQueryFunction.cs,
	  XQueryFunctionCliImpl.cs :
	  Now that position() requires current sequence that is not managed by
	  XQueryContextManager (that is for FLWOR), it need to support
	  XPathSequence input as the current node information.

svn path=/trunk/mcs/; revision=34741
  • Loading branch information
atsushieno committed Oct 6, 2004
1 parent 096ce41 commit 55f818a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 59 deletions.
10 changes: 10 additions & 0 deletions mcs/class/System.XML/System.Xml.Query/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2004-10-05 Atsushi Enomoto <atsushi@ximian.com>

* XPathSequence.cs, XQueryTokenizer.cs :
removed commented && unused code.
* XQueryContext.cs, XQueryCliFunction.cs, XQueryFunction.cs,
XQueryFunctionCliImpl.cs :
Now that position() requires current sequence that is not managed by
XQueryContextManager (that is for FLWOR), it need to support
XPathSequence input as the current node information.

2004-10-05 Atsushi Enomoto <atsushi@ximian.com>

* XQueryParser.jay, XQueryTokenizer.cs :
Expand Down
18 changes: 0 additions & 18 deletions mcs/class/System.XML/System.Xml.Query/XPathSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,24 +589,6 @@ public NodeIterator (XPathNavigator nav, XQueryContext ctx)
this.node = nav.Clone ();
}

/*
public NodeIterator (XPathSequence iter)
: base (iter.Context)
{
if (iter.Position == 0) {
if (!iter.MoveNext ()) {
emptyInput = true;
return;
}
}
XPathItem item = iter.Current;
node = item as XPathNavigator;
if (node == null)
throw new XmlQueryException (String.Format ("Current item is expected to be a node, but it is {0} ({1}).", item.XmlType.QualifiedName, item.XmlType.TypeCode));
node = node.Clone ();
}
*/

internal NodeIterator (NodeIterator other, bool cloneFlag)
: base (other)
{
Expand Down
27 changes: 19 additions & 8 deletions mcs/class/System.XML/System.Xml.Query/XQueryCliFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using System.Collections;
using System.Reflection;
using System.Security;
using System.Security.Policy;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Query;
Expand Down Expand Up @@ -92,7 +93,8 @@ internal static XQueryCliFunction CreateFromMethodInfo (XmlQualifiedName name, M
int args = prms.Length;

// Whether it takes "current context" or not.
bool hasContextArg = (args > 0 && prms [0].ParameterType == typeof (XQueryContext));
Type t = args > 0 ? prms [0].ParameterType : null;
bool hasContextArg = (t != null && (t == typeof (XQueryContext)) || t == typeof (XPathSequence));
if (hasContextArg)
args--;
if (methods [args] != null)
Expand All @@ -108,10 +110,12 @@ internal static XQueryCliFunction CreateFromMethodInfo (XmlQualifiedName name, M
if (m == null)
throw new SystemException ("Should not happen: maxArgs is " + maxArgs);
ParameterInfo [] pl = m.GetParameters ();
for (int i = 0; i < pl.Length; i++)
if (pl [i].ParameterType != typeof (XQueryContext))
for (int i = 0; i < pl.Length; i++) {
Type t = pl [i].ParameterType;
if (t != typeof (XQueryContext) && t != typeof (XPathSequence))
arguments.Add (
new XQueryFunctionArgument (new XmlQualifiedName (pl [i].Name), SequenceType.Create (pl [i].ParameterType)));
}

return new XQueryCliFunction (name,
arguments.ToArray (typeof (XQueryFunctionArgument)) as XQueryFunctionArgument [],
Expand Down Expand Up @@ -152,7 +156,7 @@ public override int MaxArgs {
get { return maxArgs; }
}

public override object Invoke (XQueryContext context, object [] args)
public override object Invoke (XPathSequence current, object [] args)
{
MethodInfo mi = methods [args.Length] as MethodInfo;
if (mi == null)
Expand All @@ -161,12 +165,19 @@ public override object Invoke (XQueryContext context, object [] args)

// Use Evidence and PermissionSet.Demand() here
// before invoking external function.
if (context.StaticContext.Evidence != null)
SecurityManager.ResolvePolicy (context.StaticContext.Evidence).Demand ();
Evidence e = current.Context.StaticContext.Evidence;
if (e != null)
SecurityManager.ResolvePolicy (e).Demand ();

if (prms.Length > 0 && prms [0].ParameterType == typeof (XQueryContext)) {
Type t = prms.Length > 0 ? prms [0].ParameterType : null;
if (t == typeof (XQueryContext)) {
ArrayList pl = new ArrayList (args);
pl.Insert (0, current.Context);
return mi.Invoke (null, pl.ToArray ());
}
else if (t == typeof (XPathSequence)) {
ArrayList pl = new ArrayList (args);
pl.Insert (0, context);
pl.Insert (0, current);
return mi.Invoke (null, pl.ToArray ());
}
else
Expand Down
8 changes: 6 additions & 2 deletions mcs/class/System.XML/System.Xml.Query/XQueryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void PushCurrentSequence (XPathSequence sequence)
{
if (sequence == null)
throw new ArgumentNullException ();
sequence = sequence.Clone ();
// sequence = sequence.Clone ();
#if SEEMS_CONTEXT_FOR_CURRENT_REQURED
contextStack.Push (currentContext);
currentsequence = sequence;
Expand Down Expand Up @@ -168,6 +168,10 @@ internal void PopVariable ()
internal XmlNamespaceManager NSManager {
get { return namespaceManager; }
}

internal XPathSequence CurrentSequence {
get { return currentSequence; }
}
}

public class XQueryContext : IXmlNamespaceResolver
Expand All @@ -178,7 +182,7 @@ public class XQueryContext : IXmlNamespaceResolver

internal XQueryContext (XQueryContextManager manager)
: this (manager,
manager.CurrentContext.currentSequence,
manager.CurrentSequence,
(Hashtable) manager.CurrentContext.currentVariables.Clone ())
{
}
Expand Down
12 changes: 7 additions & 5 deletions mcs/class/System.XML/System.Xml.Query/XQueryFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,16 @@ public SequenceType ReturnType {
get { return returnType; }
}

public abstract object Invoke (XQueryContext context, object [] args);
public abstract object Invoke (XPathSequence current, object [] args);

public virtual XPathSequence Evaluate (XPathSequence iter, ExprSequence args)
{
object [] instParams = new object [args.Count];
for (int i = 0; i < args.Count; i++)
instParams [i] = Args [i].Type.ToRuntimeType (args [i].Evaluate (iter));
object o = Invoke (iter.Context, instParams);
for (int i = 0; i < args.Count; i++) {
XPathSequence val = args [i].Evaluate (iter);
instParams [i] = Args [i].Type.ToRuntimeType (val);
}
object o = Invoke (iter, instParams);
if (o == null)
return new XPathEmptySequence (iter.Context);
if (o is XPathSequence)
Expand Down Expand Up @@ -300,7 +302,7 @@ public override int MaxArgs {
get { return Args.Length; }
}

public override object Invoke (XQueryContext context, object [] args)
public override object Invoke (XPathSequence current, object [] args)
{
throw new SystemException ("XQuery internal error: should not happen.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,12 @@ public static IEnumerable FnCollection (XQueryContext ctx, string name)
return ctx.ResolveCollection (name);
}

public static int FnPosition (XQueryContext ctx)
// FIXME: It does not point to the expected sequence.
// Either the argument must be XPathSequence, or context
// must always have the expected CurrentSequence.
public static int FnPosition (XPathSequence current)
{
return ctx.CurrentSequence.Position;
return current.Position;
}

public static int FnLast (XQueryContext ctx)
Expand Down
24 changes: 0 additions & 24 deletions mcs/class/System.XML/System.Xml.Query/XQueryTokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,33 +556,9 @@ private int ParseDefault ()
case '$':
return Token.DOLLAR;
case '\'':
// FIXME: consider in the future
/*
if (state == ParseState.StartTag) {
if (PeekChar () == '\'') {
// FIXME: this code is VERY inefficient
ReadChar ();
tokenValue = "'";
return Token.STRING_LITERAL;
}
return Token.APOS;
}
*/
tokenValue = ReadQuoted ('\'');
return Token.STRING_LITERAL;
case '"':
// FIXME: consider in the future
/*
if (state == ParseState.StartTag) {
if (PeekChar () == '"') {
// FIXME: this code is VERY inefficient
ReadChar ();
tokenValue = "\"";
return Token.STRING_LITERAL;
}
return Token.QUOT;
}
*/
tokenValue = ReadQuoted ('"');
return Token.STRING_LITERAL;
case '=':
Expand Down

0 comments on commit 55f818a

Please sign in to comment.