Beispiel #1
0
 public XQueryMapping(XQueryContext context, object expr, XQueryExprBase bodyExpr, bool root)
     : base(context)
 {
     m_root = root;
     m_expr = expr;
     m_bodyExpr = bodyExpr;
 }
Beispiel #2
0
 public XQueryFLWORBase(XQueryContext context, object var, XQuerySequenceType varType, object expr, XQueryExprBase bodyExpr)
     : base(context)
 {
     m_var = var;
     m_varType = varType;
     m_expr = expr;
     m_bodyExpr = bodyExpr;
 }
Beispiel #3
0
 public XQueryPathExpr(XQueryContext context, XQueryExprBase[] path, bool isOrdered)
     : base(context)
 {
     _path = path;
     _isOrderedSet = IsOrderedSet();
     _isOrdered = isOrdered;
     _cache = new SymbolLink();
     EnableCaching = true;
 }
Beispiel #4
0
 public DirectAccessPathExpr(XQueryContext context, XQueryExprBase[] path, bool isOrdered)
     : base(context)
 {
     XQueryExprBase[] tmp = new XQueryExprBase[path.Length + 1];
     tmp[0] = new XQueryStepExpr(XQueryPathExprType.Self, context);
     for (int k = 0; k < path.Length; k++)
         tmp[k + 1] = path[k];
     _shadowXPath = new XQueryPathExpr(context, tmp, isOrdered);
     _path = path;
 }
Beispiel #5
0
 public XQueryFLWOR(XQueryContext context, object var, XQuerySequenceType varType, object pos, object expr, XQueryExprBase bodyExpr, bool convert)
     : base(context, var, varType, expr, bodyExpr)
 {
     m_var = var;
     m_varType = varType;            
     m_pos = pos;
     m_value = new SymbolLink(varType.ValueType);
     m_itemType = varType.ItemType;
     if (m_pos != null)
         m_posValue = new SymbolLink(typeof(Integer));
     m_convert = convert;
 }
Beispiel #6
0
 public XQueryLET(XQueryContext context, object var, XQuerySequenceType varType, object expr, XQueryExprBase bodyExpr, bool convert)
     : base(context, var, varType, expr, bodyExpr)
 {
     m_value = new SymbolLink(varType.ValueType);
     m_convert = convert;
 }
Beispiel #7
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 #8
0
 private XQueryExprBase ProcessPredicateList(Notation notation, Symbol sym, XQueryExprBase ancestor)
 {       
     Notation.Record[] recs = notation.Select(sym, Descriptor.PredicateList, 1);
     if (recs.Length > 0)
     {
         Symbol[] arr = Lisp.ToArray<Symbol>(recs[0].args[0]);
         List<XQueryExprBase> filter = new List<XQueryExprBase>();
         for (int k = 0; k < arr.Length; k++)
         {
             Notation.Record[] recs1 = notation.Select(arr[k], Descriptor.Predicate, 1);
             if (recs1.Length > 0)
                 filter.Add(ProcessExpr(notation, recs1[0].args[0]));
         }
         XQueryFilterExpr filterExpr = new XQueryFilterExpr(_context, filter.ToArray());
         filterExpr.Source = ancestor;
         return filterExpr;
     }
     return ancestor;
 }
Beispiel #9
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 #10
0
 public XQueryFilterExpr(XQueryContext queryContext, XQueryExprBase[] filter)
     : base(queryContext)
 {
     m_filter = filter;
 }
Beispiel #11
0
 public void Compile()
 {
     CheckDisposed();
     if (String.IsNullOrEmpty(CommandText))
         throw new XQueryException("CommandText is empty string");
     TokenizerBase tok = new Tokenizer(CommandText);
     Notation notation = new Notation();
     YYParser parser = new YYParser(notation);
     parser.yyparseSafe(tok);
     if (BaseUri != null)
         m_context.BaseUri = BaseUri;
     if (SearchPath != null)
         m_context.SearchPath = SearchPath;
     m_context.SchemaProcessing = SchemaProcessing;
     m_context.Engine.Prepare();
     SymbolLink contextLink = new SymbolLink(typeof(IContextProvider));
     m_context.Engine.DefaultPool.Bind(contextLink);
     m_context.Engine.DefaultPool.SetData(contextLink, this);
     m_context.Resolver.SetValue(ID.Context, contextLink);
     Translator translator = new Translator(m_context);
     translator.PreProcess(notation);
     if (OnPreProcess != null) // Chance to process custom declare option statement
         OnPreProcess(this, EventArgs.Empty);
     m_res = translator.Process(notation);
     if (m_res == null)
         throw new XQueryException("Can't run XQuery function module");
     m_res.Bind(null, m_context.Engine.DefaultPool);
     // Compile variables and check it for XQST0054
     m_vars = new FunctionLink[m_context.variables.Count];
     Dictionary<SymbolLink, SymbolLink[]> dependences = new Dictionary<SymbolLink, SymbolLink[]>();
     for (int k = 0; k < m_context.variables.Count; k++)
     {
         XQueryContext.VariableRecord rec = m_context.variables[k];
         m_vars[k] = new FunctionLink();
         HashSet<Object> hs = new HashSet<object>();
         dependences.Add(rec.link, m_context.Engine.GetValueDependences(hs, null, rec.expr, m_vars[k], true));
     }
     int i = 0;
     foreach (KeyValuePair<SymbolLink, SymbolLink[]> kvp in dependences)
     {
         List<SymbolLink> closure = new List<SymbolLink>();
         HashSet<SymbolLink> hs = new HashSet<SymbolLink>();
         hs.Add(kvp.Key);
         closure.AddRange(kvp.Value);
         bool expand;
         do
         {
             expand = false;
             for (int k = 0; k < closure.Count; k++)
             {
                 SymbolLink[] values;
                 if (dependences.TryGetValue(closure[k], out values))
                 {
                     if (hs.Contains(closure[k]))
                         throw new XQueryException(Properties.Resources.XQST0054, m_context.variables[i].id);
                     hs.Add(closure[k]);
                     closure.RemoveAt(k);
                     closure.AddRange(values);
                     expand = true;
                     break;
                 }
             }
         }
         while (expand);
         i++;
     }
     m_compiled = true;
 }