Beispiel #1
0
 public void Init(MemoryPool pool)
 {
     SymbolLink self = new SymbolLink(typeof(IContextProvider));
     pool.Bind(self);
     pool.SetData(self, this);
     SetValue(ID.Context, self);
 }
Beispiel #2
0
 public MemoryPool(MemoryPool src)
 {
     _id = src._id;
     _values = new object[src._values.Length];
     Array.Copy(src._values, 0, _values, 0, src._values.Length);
     _protected = true;
     src._protected = true;
 }
Beispiel #3
0
 public override void Bind(Executive.Parameter[] parameters, MemoryPool pool)
 {
     HashSet<SymbolLink> outerValues = new HashSet<SymbolLink>(QueryContext.Resolver.List());
     m_body.Bind(parameters, pool);            
     m_params = new List<SymbolLink>();
     m_body.GetValueDependences(null, parameters, false, (SymbolLink value) =>
     {
         if (!value.IsStatic && outerValues.Contains(value))
             m_params.Add(value);
     });
 }
Beispiel #4
0
 public override object Execute(IContextProvider provider, object[] args, MemoryPool pool)
 {
     XPathItem item = provider.Context;
     if (item == null)
         throw new XQueryException(Properties.Resources.XPDY0002);
     if (!item.IsNode)
         throw new XQueryException(Properties.Resources.XPTY0019, provider.Context.Value);
     XQueryNavigator nav = item as XQueryNavigator;
     if (nav == null || (nav.NodeType != XPathNodeType.Root && nav.NodeType != XPathNodeType.Element))
         return _shadowXPath.Execute(provider, args, pool);
     return new NodeIterator(Iterator((XQueryNavigator)nav.Clone()));
 }
Beispiel #5
0
 public override object Execute(IContextProvider provider, object[] args, MemoryPool pool)
 {
     XQueryNodeIterator iter = XQueryNodeIterator.Create(
         QueryContext.Engine.Apply(null, null, m_expr, args, m_compiledExpr, pool));
     if (m_root)
         return new XQueryMappingIterator(args, pool, iter, m_bodyExpr);
     else
     {
         ContextProvider contextProvider = new ContextProvider(iter);
         object res = Undefined.Value;
         while (iter.MoveNext())
             res = m_bodyExpr.Execute(contextProvider, args, pool);
         return res;
     }
 }
Beispiel #6
0
 public override object Execute(IContextProvider provider, object[] args, MemoryPool pool)
 {
     object value = QueryContext.Engine.Apply(null, null, m_expr, args, m_valueExpr, pool);
     if (value == null)
         value = DataEngine.CoreServices.Generation.RuntimeOps.False;
     if (m_varType != XQuerySequenceType.Item && m_convert)
         value = Core.TreatAs(QueryContext.Engine, value, m_varType);
     XQueryNodeIterator iter = value as XQueryNodeIterator;
     if (iter != null && !(iter is BufferedNodeIterator))
         value = iter.CreateBufferedIterator();
     pool.SetData(m_value, value);
     if (m_conditionExpr != null &&
         !Core.BooleanValue(QueryContext.Engine.Apply(null, null, ConditionExpr, args, m_conditionExpr, pool)))
         return EmptyIterator.Shared;
     return m_bodyExpr.Execute(provider, args, pool);
 }
Beispiel #7
0
        public object Invoke(MemoryPool pool, object[] args)
        {
            if (invoke == null)
                invoke = (InvokeLambda)dynamicMethod.CreateDelegate(typeof(InvokeLambda));
            if ((args == null && Arity == 0) || args.Length == Arity)
            {
                try
                {                    
                    return invoke(this, Consts, args, pool);
                }
                catch (Exception ex)
                {
                    Engine.HandleRuntimeException(ex);
                }

            }
            throw new InvalidOperationException("Invoke");
        }
Beispiel #8
0
 public override void Bind(Executive.Parameter[] parameters, MemoryPool pool)
 {
     value = QueryContext.Engine.TryGet(name, false, true);
     if (value == null)
     {
         if (parameters != null)
         {
             arg_index = 0;
             foreach (Executive.Parameter p in parameters)
             {
                 if (p.ID == name)
                     return;
                 arg_index++;
             }
         }
         value = QueryContext.Engine.TryGet(name, true, false);
         if (value == null)
             throw new ValueNotDefined(name.ToString());
     }
 }
Beispiel #9
0
 public override void Bind(Executive.Parameter[] parameters, MemoryPool pool)
 {
     m_context = new SymbolLink(typeof(IContextProvider));            
     pool.Bind(m_context);
     object data = QueryContext.Resolver.GetCurrentStack();
     QueryContext.Resolver.SetValue(ID.Context, m_context);
     m_compiledBody = new FunctionLink[m_expr.Length];
     for (int k = 0; k < m_expr.Length; k++)
     {
         m_compiledBody[k] = new FunctionLink();
         QueryContext.Engine.Compile(parameters, m_expr[k], m_compiledBody[k]);
     }
     if (Annotation != null)
     {
         m_compiledAnnotation = new FunctionLink[Annotation.Length];
         for (int k = 0; k < Annotation.Length; k++)
         {
             m_compiledAnnotation[k] = new FunctionLink();
             QueryContext.Engine.Compile(parameters, Annotation[k], m_compiledAnnotation[k]);
         }
     }
     QueryContext.Resolver.RevertToStack(data);
 }
Beispiel #10
0
 public override void Bind(Executive.Parameter[] parameters, MemoryPool pool)
 {
     m_valueExpr = new FunctionLink();
     QueryContext.Engine.Compile(parameters, m_expr, m_valueExpr);
     m_value.IsStatic = true;
     SymbolLink[] depends = QueryContext.Engine.GetValueDependences(null, parameters, m_expr, m_valueExpr, false);
     foreach (SymbolLink s in depends)
         if (!s.IsStatic)
         {
             m_value.IsStatic = false;
             break;
         }
     object data = QueryContext.Resolver.GetCurrentStack();
     pool.Bind(m_value);
     QueryContext.Resolver.SetValue(m_var, m_value);
     if (ConditionExpr != null)
     {
         m_conditionExpr = new FunctionLink();
         QueryContext.Engine.Compile(parameters, ConditionExpr, m_conditionExpr);
     }
     m_bodyExpr.Bind(parameters, pool);
     QueryContext.Resolver.RevertToStack(data);
 }
Beispiel #11
0
 public override object Execute(IContextProvider provider, object[] args, MemoryPool pool)
 {
     object[] keys = new object[m_params.Count + 1];
     keys[0] = provider.Context;
     for (int k = 0; k < m_params.Count; k++)
         keys[k + 1] = pool.GetData(m_params[k]);
     Key key = new Key(QueryContext.Engine, keys);
     object res;
     lock (m_cache)
     {
         if (m_cache.TryGetValue(key, out res))
             return res.CloneObject();
     }
     res = m_body.Execute(provider, args, pool);
     lock (m_cache)
     {
         if (!m_cache.ContainsKey(key))
         {
             key.CloneKeys();
             m_cache.Add(key, res);
         }
     }
     return res.CloneObject();
 }
Beispiel #12
0
 public void Init(MemoryPool pool)
 {
     return;
 }
Beispiel #13
0
 public abstract object Execute(IContextProvider provider, object[] args, MemoryPool pool);
Beispiel #14
0
 public virtual void Prepare()
 {
     m_defaultPool = new MemoryPool();
     m_value.Clear();
     Set(Lisp.T, Generation.RuntimeOps.True);
     Set(Lisp.NIL, null);
     Set(Lisp.UNKNOWN, Undefined.Value);
 }
Beispiel #15
0
 public object Apply(object id, Parameter[] parameters, object lval, object[] args, FunctionLink dynamicFunc, MemoryPool pool)
 {
     object res = Undefined.Value;            
     if (dynamicFunc != null && dynamicFunc.Value != null)
     {
         CompiledLambda lambda = dynamicFunc.Value;
         res = lambda.Invoke(pool, args);
         return res;
     }
     else
     {
         CompiledLambda lambda = Compile(parameters, lval);
         if (dynamicFunc != null)
             dynamicFunc.Value = lambda;
         res = lambda.Invoke(pool, args);
     }            
     return res;
 }
Beispiel #16
0
 public XQueryMappingIterator(object[] args, MemoryPool pool, XQueryNodeIterator iter, XQueryExprBase bodyExpr)
 {
     this.args = args;
     this.pool = pool;
     this.baseIter = iter.Clone();
     this.bodyExpr = bodyExpr;
     provider = new ContextProvider(baseIter);
 }
Beispiel #17
0
 public override void Bind(Executive.Parameter[] parameters, MemoryPool pool)
 {
     m_valueExpr = new FunctionLink();
     QueryContext.Engine.Compile(parameters, m_expr, m_valueExpr);
     object data = QueryContext.Resolver.GetCurrentStack();
     pool.Bind(m_value);
     QueryContext.Resolver.SetValue(m_var, m_value);
     if (m_pos != null)
     {
         pool.Bind(m_posValue);
         QueryContext.Resolver.SetValue(m_pos, m_posValue);
     }
     if (ConditionExpr != null)
     {
         m_conditionExpr = new FunctionLink();
         QueryContext.Engine.Compile(parameters, ConditionExpr, m_conditionExpr);
     }
     m_bodyExpr.Bind(parameters, pool);
     QueryContext.Resolver.RevertToStack(data);
 }
Beispiel #18
0
 public XQueryExprIterator(XQueryExpr owner, object[] args, object[] annotation, MemoryPool pool)
 {
     this.owner = owner;
     this.args = args;
     this.annotation = annotation;
     this.pool = pool;
 }
Beispiel #19
0
 public override void Bind(Executive.Parameter[] parameters, MemoryPool pool)
 {
     _shadowXPath.Bind(parameters, pool);
 }
Beispiel #20
0
 public abstract void Bind(Executive.Parameter[] parameters, MemoryPool pool);
Beispiel #21
0
 public XQueryFLWORIteratorHPC(XQueryFLWOR owner, IContextProvider provider, object[] args, MemoryPool pool, XQueryNodeIterator baseIter)
     : base(owner, provider, args, pool, baseIter)
 {
     tasks = new ConcurrentQueue<Task<object>>();
 }
Beispiel #22
0
 public XQueryFLWORIterator(XQueryFLWOR owner, IContextProvider provider, object[] args, MemoryPool pool, XQueryNodeIterator baseIter)
     : base(owner, provider, args, pool, baseIter)
 {
 }
Beispiel #23
0
 public override object Execute(IContextProvider provider, object[] args, MemoryPool pool)
 {
     if (provider.Context == null)
         throw new XQueryException(Properties.Resources.XPDY0002);
     if (!provider.Context.IsNode)
         throw new XQueryException(Properties.Resources.XPTY0019, provider.Context.Value);
     return new NodeIterator(m_iter(provider.Context));                
 }
Beispiel #24
0
 private IEnumerable<XPathItem> CreateEnumerator(object[] args,  MemoryPool pool,
     XQueryExprBase expr, XQueryNodeIterator baseIter)
 {
     XQueryNodeIterator iter = baseIter.Clone();
     XQueryExpr numexpr = expr as XQueryExpr;
     if (numexpr != null && numexpr.m_expr.Length == 1
         && numexpr.m_expr[0] is Integer)
     {
         Integer pos = (Integer)numexpr.m_expr[0];
         foreach (XPathItem item in iter)
         {
             if (pos == 1)
             {
                 yield return item;
                 break;
             }
             else
                 pos--;
         }
     }
     else
     {
         ContextProvider provider = new ContextProvider(iter);
         object res = Undefined.Value;
         while (iter.MoveNext())
         {
             if (m_contextSensitive || res == Undefined.Value)
                 res = expr.Execute(provider, args, pool);
             if (res == Undefined.Value)
             {
                 if (!m_contextSensitive)
                     break;
                 continue;
             }                            
             XQueryNodeIterator iter2 = res as XQueryNodeIterator;
             XPathItem item;
             if (iter2 != null)
             {
                 iter2 = iter2.Clone();
                 if (!iter2.MoveNext())
                     continue;
                 item = iter2.Current.Clone();
                 if (!item.IsNode && iter2.MoveNext())
                     throw new XQueryException(Properties.Resources.FORG0006, "fn:boolean()",
                         new XQuerySequenceType(XmlTypeCode.AnyAtomicType, XmlTypeCardinality.OneOrMore));
             }
             else
             {
                 item = res as XPathItem;
                 if (item == null)
                     item = new XQueryItem(res);
             }
             if (item.IsNode)
                 yield return iter.Current;
             else
             {
                 if (ValueProxy.IsNumeric(item.ValueType))
                 {
                     if (QueryContext.Engine.OperatorEq(iter.CurrentPosition + 1, item.TypedValue) != null)
                     {
                         yield return iter.Current;
                         if (!m_contextSensitive)
                             break;
                     }
                 }
                 else
                     if (Core.BooleanValue(item))
                         yield return iter.Current;
             }
         }                
     }
 }
Beispiel #25
0
 public override object Execute(IContextProvider provider, object[] args, MemoryPool pool)
 {
     if (Source == null)
         return EmptyIterator.Shared;
     XQueryNodeIterator iter = XQueryNodeIterator.Create(Source.Execute(provider, args, pool));
     for (int k = 0; k < m_filter.Length; k++)
         iter = new NodeIterator(CreateEnumerator(args, pool, m_filter[k], iter));
     return iter;
 }
Beispiel #26
0
 public override void Bind(Executive.Parameter[] parameters, MemoryPool pool)
 {
     Source.Bind(parameters, pool);
     m_contextSensitive = false;
     foreach (XQueryExprBase expr in m_filter)
     {
         expr.Bind(parameters, pool);
         if (!m_contextSensitive)
             m_contextSensitive = expr.IsContextSensitive(parameters);
     }
 }
Beispiel #27
0
 public override object Execute(IContextProvider provider, object[] args, MemoryPool pool)
 {
     pool.SetData(m_context, provider);
     if (Annotation != null)
     {
         object[] annotation = new object[Annotation.Length];
         for (int k = 0; k < Annotation.Length; k++)
         {
             object res = QueryContext.Engine.Apply(null, null,
                 Annotation[k], args, m_compiledAnnotation[k], pool);
             if (res != Undefined.Value)
                 if (res == null)
                     annotation[k] = false;
                 else
                     annotation[k] = Core.Atomize(res);
         }
         return new XQueryExprIterator(this, args, annotation, pool);
     }
     if (m_expr.Length == 1)
         return QueryContext.Engine.Apply(null, null, m_expr[0], args, m_compiledBody[0], pool);
     return new XQueryExprIterator(this, args, null, pool);
 }
Beispiel #28
0
 public override void Bind(Executive.Parameter[] parameters, MemoryPool pool)
 {
     m_compiledExpr = new FunctionLink();
     QueryContext.Engine.Compile(parameters, m_expr, m_compiledExpr);
     m_bodyExpr.Bind(parameters, pool);
 }
Beispiel #29
0
 public static object DynExecuteExpr(object obj, IContextProvider provider, object[] args, MemoryPool pool)
 {
     XQueryExprBase expr = (XQueryExprBase)obj;
     return expr.Execute(provider, args, pool);
 }               
Beispiel #30
0
 public override void Bind(Executive.Parameter[] parameters, MemoryPool pool)
 {
 }