public QilList FormalParameterList(QilNode arg1, QilNode arg2)
        {
            QilList result = _f.FormalParameterList();

            result.Add(arg1);
            result.Add(arg2);
            return(result);
        }
Exemple #2
0
        public QilList ActualParameterList(QilNode arg1, QilNode arg2)
        {
            QilList result = f.ActualParameterList();

            result.Add(arg1);
            result.Add(arg2);
            return(result);
        }
        public QilNode Sequence(QilNode child1, QilNode child2)
        {
            QilList res = _f.Sequence();

            res.Add(child1);
            res.Add(child2);
            return(res);
        }
Exemple #4
0
        public QilList GlobalVariableList(IList <QilNode> values)
        {
            QilList seq = GlobalVariableList();

            seq.Add(values);
            return(seq);
        }
        public QilNode XsltInvokeLateBound(QilNode name, IList <QilNode> args)
        {
            QilList list = _f.ActualParameterList();

            list.Add(args);
            return(_f.XsltInvokeLateBound(name, list));
        }
Exemple #6
0
        public QilList BranchList(IList <QilNode> values)
        {
            QilList seq = BranchList();

            seq.Add(values);
            return(seq);
        }
        public QilNode XsltInvokeEarlyBound(QilNode name, MethodInfo d, XmlQueryType t, IList <QilNode> args)
        {
            QilList list = _f.ActualParameterList();

            list.Add(args);
            return(_f.XsltInvokeEarlyBound(name, _f.LiteralObject(d), list, t));
        }
Exemple #8
0
        public QilList FormalParameterList(IList <QilNode> values)
        {
            QilList seq = FormalParameterList();

            seq.Add(values);
            return(seq);
        }
Exemple #9
0
        public QilList SortKeyList(IList <QilNode> values)
        {
            QilList seq = SortKeyList();

            seq.Add(values);
            return(seq);
        }
Exemple #10
0
        public QilList FunctionList(IList <QilNode> values)
        {
            QilList seq = FunctionList();

            seq.Add(values);
            return(seq);
        }
Exemple #11
0
        public QilList Sequence(IList <QilNode> values)
        {
            QilList seq = Sequence();

            seq.Add(values);
            return(seq);
        }
Exemple #12
0
        public QilList SortKeyList(QilSortKey key)
        {
            QilList list = f.SortKeyList();

            list.Add(key);
            return(list);
        }
        public QilNode Sequence(QilNode child)
        {
            if (!_debug)
            {
                return(child);
            }
            QilList res = _f.Sequence();

            res.Add(child);
            return(res);
        }
        public QilNode GenerateInvoke(QilFunction func, IList<XslNode> actualArgs) {
            iterStack.Clear();
            formalArgs = func.Arguments;
            invokeArgs = fac.ActualParameterList();

            // curArg is an instance variable used in Clone() method
            for (curArg = 0; curArg < formalArgs.Count; curArg ++) {
                // Find actual value for a given formal arg
                QilParameter formalArg = (QilParameter)formalArgs[curArg];
                QilNode      invokeArg = FindActualArg(formalArg, actualArgs);

                // If actual value was not specified, use the default value and copy its debug comment
                if (invokeArg == null) {
                    if (debug) {
                        if (formalArg.Name.NamespaceUri == XmlReservedNs.NsXslDebug) {
                            Debug.Assert(formalArg.Name.LocalName == "namespaces", "Cur,Pos,Last don't have default values and should be always added to by caller in AddImplicitArgs()");
                            Debug.Assert(formalArg.DefaultValue != null, "PrecompileProtoTemplatesHeaders() set it");
                            invokeArg = Clone(formalArg.DefaultValue);
                        } else {
                            invokeArg = fac.DefaultValueMarker();
                        }
                    } else {
                        Debug.Assert(formalArg.Name.NamespaceUri != XmlReservedNs.NsXslDebug, "Cur,Pos,Last don't have default values and should be always added to by caller in AddImplicitArgs(). We don't have $namespaces in !debug.");
                        invokeArg = Clone(formalArg.DefaultValue);
                    }
                }

                XmlQueryType formalType = formalArg.XmlType;
                XmlQueryType invokeType = invokeArg.XmlType;

                // Possible arg types: anyType, node-set, string, boolean, and number
                fac.CheckXsltType(formalArg);
                fac.CheckXsltType(invokeArg);

                if (!invokeType.IsSubtypeOf(formalType)) {
                    // This may occur only if inferred type of invokeArg is XslFlags.None
                    Debug.Assert(invokeType == T.ItemS, "Actual argument type is not a subtype of formal argument type");
                    invokeArg = fac.TypeAssert(invokeArg, formalType);
                }

                invokeArgs.Add(invokeArg);
            }

            // Create Invoke node and wrap it with previous parameter declarations
            QilNode invoke = fac.Invoke(func, invokeArgs);
            while (iterStack.Count != 0)
                invoke = fac.Loop(iterStack.Pop(), invoke);

            return invoke;
        }
        public QilNode Sequence(params QilNode[] args)
        {
            if (!_debug)
            {
                switch (args.Length)
                {
                case 0: return(_f.Sequence());

                case 1: return(args[0]);
                }
            }
            QilList res = _f.Sequence();

            foreach (QilNode n in args)
            {
                res.Add(n);
            }
            return(res);
        }
Exemple #16
0
 // Fills invokeArgs with values from actualArgs in order given by formalArgs
 // Returns true if formalArgs maps 1:1 with actual args.
 // Formaly this is n*n algorithm. We can optimize it by calculationg "signature"
 // of the function as sum of all hashes of its args names.
 private bool FillupInvokeArgs(IList<QilNode> formalArgs, IList<XslNode> actualArgs, QilList invokeArgs)
 {
     if (actualArgs.Count != formalArgs.Count)
     {
         return false;
     }
     invokeArgs.Clear();
     for (int invArg = 0; invArg < formalArgs.Count; invArg++)
     {
         QilName formalArgName = ((QilParameter)formalArgs[invArg]).Name;
         XmlQueryType paramType = formalArgs[invArg].XmlType;
         QilNode arg = null;
         {
             for (int actArg = 0; actArg < actualArgs.Count; actArg++)
             {
                 Debug.Assert(actualArgs[actArg].NodeType == XslNodeType.WithParam, "All Sorts was removed in CompileSorts()");
                 VarPar withParam = (VarPar)actualArgs[actArg];
                 if (formalArgName.Equals(withParam.Name))
                 {
                     QilNode value = withParam.Value;
                     XmlQueryType valueType = value.XmlType;
                     if (valueType != paramType)
                     {
                         if (valueType.IsNode && paramType.IsNode && valueType.IsSubtypeOf(paramType))
                         {
                             // We can pass it
                         }
                         else
                         {
                             // Formal argument has the same name but a different type
                             return false;
                         }
                     }
                     arg = value;
                     break;
                 }
             }
         }
         if (arg == null)
         {
             // Formal argument has not been found among actual arguments
             return false;
         }
         invokeArgs.Add(arg);
     }
     // All arguments have been found
     return true;
 }
Exemple #17
0
        private QilNode CompileInstructions(IList<XslNode> instructions, int from, QilList content)
        {
            Debug.Assert(instructions != null);
            for (int i = from; i < instructions.Count; i++)
            {
                XslNode node = instructions[i];
                XslNodeType nodeType = node.NodeType;
                if (nodeType == XslNodeType.Param)
                {
                    continue; // already compiled by CompileProtoTemplate()
                }
                QilList nsList = EnterScope(node);
                QilNode result;

                switch (nodeType)
                {
                    case XslNodeType.ApplyImports: result = CompileApplyImports(node); break;
                    case XslNodeType.ApplyTemplates: result = CompileApplyTemplates((XslNodeEx)node); break;
                    case XslNodeType.Attribute: result = CompileAttribute((NodeCtor)node); break;
                    case XslNodeType.CallTemplate: result = CompileCallTemplate((XslNodeEx)node); break;
                    case XslNodeType.Choose: result = CompileChoose(node); break;
                    case XslNodeType.Comment: result = CompileComment(node); break;
                    case XslNodeType.Copy: result = CompileCopy(node); break;
                    case XslNodeType.CopyOf: result = CompileCopyOf(node); break;
                    case XslNodeType.Element: result = CompileElement((NodeCtor)node); break;
                    case XslNodeType.Error: result = CompileError(node); break;
                    case XslNodeType.ForEach: result = CompileForEach((XslNodeEx)node); break;
                    case XslNodeType.If: result = CompileIf(node); break;
                    case XslNodeType.List: result = CompileList(node); break;
                    case XslNodeType.LiteralAttribute: result = CompileLiteralAttribute(node); break;
                    case XslNodeType.LiteralElement: result = CompileLiteralElement(node); break;
                    case XslNodeType.Message: result = CompileMessage(node); break;
                    case XslNodeType.Nop: result = CompileNop(node); break;
                    case XslNodeType.Number: result = CompileNumber((Number)node); break;
                    //              case XslNodeType.Otherwise:         wrapped by Choose
                    //              case XslNodeType.Param:             already compiled by CompileProtoTemplate()
                    case XslNodeType.PI: result = CompilePI(node); break;
                    //              case XslNodeType.Sort:              wrapped by ForEach or ApplyTemplates, see CompileSorts()
                    //              case XslNodeType.Template:          global level element
                    case XslNodeType.Text: result = CompileText((Text)node); break;
                    case XslNodeType.UseAttributeSet: result = CompileUseAttributeSet(node); break;
                    case XslNodeType.ValueOf: result = CompileValueOf(node); break;
                    case XslNodeType.ValueOfDoe: result = CompileValueOfDoe(node); break;
                    case XslNodeType.Variable: result = CompileVariable(node); break;
                    //              case XslNodeType.WithParam:         wrapped by CallTemplate or ApplyTemplates, see CompileWithParam()
                    default: Debug.Fail("Unexpected type of AST node: " + nodeType.ToString()); result = null; break;
                }

                ExitScope();
                Debug.Assert(result != null, "Result of compilation should not be null");
                if (result.NodeType == QilNodeType.Sequence && result.Count == 0)
                {
                    continue;
                }

                // Do not create sequence points for literal attributes and use-attribute-sets
                if (nodeType != XslNodeType.LiteralAttribute && nodeType != XslNodeType.UseAttributeSet)
                {
                    SetLineInfoCheck(result, node.SourceLine);
                }

                result = SetDebugNs(result, nsList);
                if (nodeType == XslNodeType.Variable)
                {
                    QilIterator var = _f.Let(result);
                    var.DebugName = node.Name.ToString();
                    _scope.AddVariable(node.Name, var);
                    // Process all remaining instructions in the recursive call
                    result = _f.Loop(var, CompileInstructions(instructions, i + 1));
                    i = instructions.Count;
                }

                content.Add(result);
            }
            if (!IsDebug && content.Count == 1)
            {
                return content[0];
            }
            return content;
        }
Exemple #18
0
        private void CompileSort(Sort sort, QilList keyList, ref LoopFocus parentLoop)
        {
            Debug.Assert(sort.NodeType == XslNodeType.Sort);
            QilNode select, select2, lang, order, caseOrder;
            bool fwdCompat;

            EnterScope(sort);
            fwdCompat = sort.ForwardsCompatible;

            select = CompileXPathExpression(sort.Select);

            if (sort.Lang != null || sort.DataType != null || sort.Order != null || sort.CaseOrder != null)
            {
                // Calculate these attributes in the context of the parent loop
                LoopFocus curLoopSaved = _curLoop;
                _curLoop = parentLoop;

                lang = CompileLangAttribute(sort.Lang, fwdCompat);

                CompileDataTypeAttribute(sort.DataType, fwdCompat, ref select, out select2);

                order = CompileOrderAttribute(
                    /*attName:  */  "order",
                    /*attValue: */  sort.Order,
                    /*value0:   */  "ascending",
                    /*value1:   */  "descending",
                    /*fwdCompat:*/  fwdCompat
                );

                caseOrder = CompileOrderAttribute(
                    /*attName:  */  "case-order",
                    /*attValue: */  sort.CaseOrder,
                    /*value0:   */  "lower-first",
                    /*value1:   */  "upper-first",
                    /*fwdCompat:*/  fwdCompat
                );

                // Restore loop context
                _curLoop = curLoopSaved;
            }
            else
            {
                select = _f.ConvertToString(select);
                select2 = lang = order = caseOrder = null;
            }

            _strConcat.Reset();
            _strConcat.Append(XmlReservedNs.NsCollationBase);
            _strConcat.Append('/');
            _strConcat.Append(lang);

            char separator = '?';
            if (order != null)
            {
                _strConcat.Append(separator);
                _strConcat.Append("descendingOrder=");
                _strConcat.Append(order);
                separator = '&';
            }
            if (caseOrder != null)
            {
                _strConcat.Append(separator);
                _strConcat.Append("upperFirst=");
                _strConcat.Append(caseOrder);
                separator = '&';
            }

            QilNode collation = _strConcat.ToQil();

            QilSortKey result = _f.SortKey(select, collation);
            // Line information is not copied
            keyList.Add(result);

            if (select2 != null)
            {
                result = _f.SortKey(select2, collation.DeepClone(_f.BaseFactory));
                // Line information is not copied
                keyList.Add(result);
            }

            ExitScope();
        }
Exemple #19
0
 private void AddNsDecl(QilList content, string prefix, string nsUri)
 {
     if (_outputScope.LookupNamespace(prefix) == nsUri)
     {
         return; // This prefix is already bound to required namespace. Nothing to do.
     }
     _outputScope.AddNamespace(prefix, nsUri);
     content.Add(_f.NamespaceDecl(_f.String(prefix), _f.String(nsUri)));
 }