Beispiel #1
0
 private void CompileXsltFunction(XPathXsltFunctionExpr expr)
 {
     if (expr.SubExprCount > 0)
     {
         XPathExprList subExpr = expr.SubExpr;
         for (int i = subExpr.Count - 1; i >= 0; i--)
         {
             XPathExpr expr2 = subExpr[i];
             this.CompileExpression(expr2);
             ValueDataType destType = XPathXsltFunctionExpr.ConvertTypeFromXslt(expr.Function.ArgTypes[i]);
             if ((destType != ValueDataType.None) && (expr2.ReturnType != destType))
             {
                 this.CompileTypecast(destType);
             }
         }
     }
     if (expr.Function is XPathMessageFunction)
     {
         this.codeBlock.Append(new XPathMessageFunctionCallOpcode((XPathMessageFunction)expr.Function, expr.SubExprCount));
         if (this.IsSpecialInternalFunction(expr))
         {
             this.codeBlock.Append(new PopSequenceToValueStackOpcode());
         }
     }
     else
     {
         this.codeBlock.Append(new XsltFunctionCallOpcode(expr.Context, expr.Function, expr.SubExprCount));
     }
 }
Beispiel #2
0
 internal XPathXsltVariableExpr(XsltContext context, IXsltContextVariable variable)
     : base(XPathExprType.XsltVariable, XPathXsltFunctionExpr.ConvertTypeFromXslt(variable.VariableType))
 {
     Fx.Assert(null != variable, "");
     this.variable = variable;
     this.context  = context;
 }
Beispiel #3
0
            void CompileXsltFunction(XPathXsltFunctionExpr expr)
            {
                // Compile each argument expression first, introducing a typecast where appropriate
                // Arguments are pushed C style - right to left
                if (expr.SubExprCount > 0)
                {
                    XPathExprList paramList = expr.SubExpr;
                    for (int i = paramList.Count - 1; i >= 0; --i)
                    {
                        XPathExpr param = paramList[i];
                        this.CompileExpression(param);
                        ValueDataType paramType = XPathXsltFunctionExpr.ConvertTypeFromXslt(expr.Function.ArgTypes[i]);
                        if (ValueDataType.None != paramType)
                        {
                            if (param.ReturnType != paramType)
                            {
                                this.CompileTypecast(paramType);
                            }
                        }
                    }
                }

                if (expr.Function is XPathMessageFunction)
                {
                    this.codeBlock.Append(new XPathMessageFunctionCallOpcode((XPathMessageFunction)expr.Function, expr.SubExprCount));
                    if (IsSpecialInternalFunction(expr))
                    {
                        this.codeBlock.Append(new PopSequenceToValueStackOpcode());
                    }
                }
                else
                {
                    this.codeBlock.Append(new XsltFunctionCallOpcode(expr.Context, expr.Function, expr.SubExprCount));
                }
            }
        private XPathExpr ParseFunctionExpression()
        {
            XPathExpr  expr;
            XPathToken token = this.NextToken(XPathTokenID.Function);

            if (token == null)
            {
                return(null);
            }
            NodeQName name = this.QualifyName(token.Prefix, token.Name);

            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);
            XPathExprList args = new XPathExprList();

            while ((expr = this.ParseExpression()) != null)
            {
                args.Add(expr);
                if (this.NextToken(XPathTokenID.Comma) == null)
                {
                    break;
                }
            }
            XPathExpr expr2 = null;

            if (this.functionLibraries != null)
            {
                QueryFunction function = null;
                for (int i = 0; i < this.functionLibraries.Length; i++)
                {
                    function = this.functionLibraries[i].Bind(name.Name, name.Namespace, args);
                    if (function != null)
                    {
                        expr2 = new XPathFunctionExpr(function, args);
                        break;
                    }
                }
            }
            if ((expr2 == null) && (this.context != null))
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int j = 0; j < args.Count; j++)
                {
                    argTypes[j] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[j].ReturnType);
                }
                string prefix = this.context.LookupPrefix(name.Namespace);
                IXsltContextFunction function2 = this.context.ResolveFunction(prefix, name.Name, argTypes);
                if (function2 != null)
                {
                    expr2 = new XPathXsltFunctionExpr(this.context, function2, args);
                }
            }
            if (expr2 == null)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }
            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return(expr2);
        }
 internal PushXsltVariableOpcode(XsltContext context, IXsltContextVariable variable) : base(OpcodeID.PushXsltVariable)
 {
     this.xsltContext = context;
     this.variable    = variable;
     this.type        = XPathXsltFunctionExpr.ConvertTypeFromXslt(variable.VariableType);
     switch (this.type)
     {
     case ValueDataType.Boolean:
     case ValueDataType.Double:
     case ValueDataType.Sequence:
     case ValueDataType.String:
         return;
     }
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidType, System.ServiceModel.SR.GetString("QueryVariableTypeNotSupported", new object[] { this.variable.VariableType.ToString() })));
 }
Beispiel #6
0
        internal PushXsltVariableOpcode(XsltContext context, IXsltContextVariable variable)
            : base(OpcodeID.PushXsltVariable)
        {
            Fx.Assert(null != context && null != variable, "");

            this.xsltContext = context;
            this.variable    = variable;
            this.type        = XPathXsltFunctionExpr.ConvertTypeFromXslt(variable.VariableType);

            // Make sure the type is supported
            switch (this.type)
            {
            case ValueDataType.Boolean:
            case ValueDataType.Double:
            case ValueDataType.String:
            case ValueDataType.Sequence:
                break;

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidType, SR.GetString(SR.QueryVariableTypeNotSupported, this.variable.VariableType.ToString())));
            }
        }
Beispiel #7
0
        XPathExpr ParseFunctionExpression()
        {
            XPathToken functionToken = this.NextToken(XPathTokenID.Function);

            if (null == functionToken)
            {
                return(null);
            }

            NodeQName functionName = this.QualifyName(functionToken.Prefix, functionToken.Name);

            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);

            XPathExprList args = new XPathExprList();

            // Read in arguments
            XPathExpr arg;

            while (null != (arg = this.ParseExpression()))
            {
                args.Add(arg);
                if (null == this.NextToken(XPathTokenID.Comma))
                {
                    break;
                }
            }

            // Bind to the function
            // Try each library until we can bind the function
            XPathExpr functionImpl = null;

            if (null != this.functionLibraries)
            {
                QueryFunction fun = null;
                for (int i = 0; i < this.functionLibraries.Length; ++i)
                {
                    if (null != (fun = this.functionLibraries[i].Bind(functionName.Name, functionName.Namespace, args)))
                    {
                        functionImpl = new XPathFunctionExpr(fun, args);
                        break;
                    }
                }
            }

            // Try to bind using the XsltContext
            if (null == functionImpl && this.context != null)
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int i = 0; i < args.Count; ++i)
                {
                    argTypes[i] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[i].ReturnType);
                }
                string prefix = this.context.LookupPrefix(functionName.Namespace);
                IXsltContextFunction xsltFun = this.context.ResolveFunction(prefix, functionName.Name, argTypes);
                if (xsltFun != null)
                {
                    functionImpl = new XPathXsltFunctionExpr(this.context, xsltFun, args);
                }
            }

            if (null == functionImpl)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }

            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return(functionImpl);
        }
            void CompileXsltFunction(XPathXsltFunctionExpr expr)
            {
                // Compile each argument expression first, introducing a typecast where appropriate
                // Arguments are pushed C style - right to left
                if (expr.SubExprCount > 0)
                {
                    XPathExprList paramList = expr.SubExpr;
                    for (int i = paramList.Count - 1; i >= 0; --i)
                    {
                        XPathExpr param = paramList[i];
                        this.CompileExpression(param);
                        ValueDataType paramType = XPathXsltFunctionExpr.ConvertTypeFromXslt(expr.Function.ArgTypes[i]);
                        if (ValueDataType.None != paramType)
                        {
                            if (param.ReturnType != paramType)
                            {
                                this.CompileTypecast(paramType);
                            }
                        }
                    }
                }

                if (expr.Function is XPathMessageFunction)
                {
                    this.codeBlock.Append(new XPathMessageFunctionCallOpcode((XPathMessageFunction)expr.Function, expr.SubExprCount));
                    if (IsSpecialInternalFunction(expr))
                    {
                        this.codeBlock.Append(new PopSequenceToValueStackOpcode());
                    }
                }
                else
                {
                    this.codeBlock.Append(new XsltFunctionCallOpcode(expr.Context, expr.Function, expr.SubExprCount));
                }
            }
        XPathExpr ParseFunctionExpression()
        {
            XPathToken functionToken = this.NextToken(XPathTokenID.Function);

            if (null == functionToken)
            {
                return null;
            }

            NodeQName functionName = this.QualifyName(functionToken.Prefix, functionToken.Name);
            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);

            XPathExprList args = new XPathExprList();

            // Read in arguments
            XPathExpr arg;

            while (null != (arg = this.ParseExpression()))
            {
                args.Add(arg);
                if (null == this.NextToken(XPathTokenID.Comma))
                {
                    break;
                }
            }

            // Bind to the function
            // Try each library until we can bind the function
            XPathExpr functionImpl = null;
            if (null != this.functionLibraries)
            {
                QueryFunction fun = null;
                for (int i = 0; i < this.functionLibraries.Length; ++i)
                {
                    if (null != (fun = this.functionLibraries[i].Bind(functionName.Name, functionName.Namespace, args)))
                    {
                        functionImpl = new XPathFunctionExpr(fun, args);
                        break;
                    }
                }
            }

            // Try to bind using the XsltContext
            if (null == functionImpl && this.context != null)
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int i = 0; i < args.Count; ++i)
                {
                    argTypes[i] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[i].ReturnType);
                }
                string prefix = this.context.LookupPrefix(functionName.Namespace);
                IXsltContextFunction xsltFun = this.context.ResolveFunction(prefix, functionName.Name, argTypes);
                if (xsltFun != null)
                {
                    functionImpl = new XPathXsltFunctionExpr(this.context, xsltFun, args);
                }
            }

            if (null == functionImpl)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }

            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return functionImpl;
        }
 private void CompileXsltFunction(XPathXsltFunctionExpr expr)
 {
     if (expr.SubExprCount > 0)
     {
         XPathExprList subExpr = expr.SubExpr;
         for (int i = subExpr.Count - 1; i >= 0; i--)
         {
             XPathExpr expr2 = subExpr[i];
             this.CompileExpression(expr2);
             ValueDataType destType = XPathXsltFunctionExpr.ConvertTypeFromXslt(expr.Function.ArgTypes[i]);
             if ((destType != ValueDataType.None) && (expr2.ReturnType != destType))
             {
                 this.CompileTypecast(destType);
             }
         }
     }
     if (expr.Function is XPathMessageFunction)
     {
         this.codeBlock.Append(new XPathMessageFunctionCallOpcode((XPathMessageFunction) expr.Function, expr.SubExprCount));
         if (this.IsSpecialInternalFunction(expr))
         {
             this.codeBlock.Append(new PopSequenceToValueStackOpcode());
         }
     }
     else
     {
         this.codeBlock.Append(new XsltFunctionCallOpcode(expr.Context, expr.Function, expr.SubExprCount));
     }
 }
 private XPathExpr ParseFunctionExpression()
 {
     XPathExpr expr;
     XPathToken token = this.NextToken(XPathTokenID.Function);
     if (token == null)
     {
         return null;
     }
     NodeQName name = this.QualifyName(token.Prefix, token.Name);
     this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);
     XPathExprList args = new XPathExprList();
     while ((expr = this.ParseExpression()) != null)
     {
         args.Add(expr);
         if (this.NextToken(XPathTokenID.Comma) == null)
         {
             break;
         }
     }
     XPathExpr expr2 = null;
     if (this.functionLibraries != null)
     {
         QueryFunction function = null;
         for (int i = 0; i < this.functionLibraries.Length; i++)
         {
             function = this.functionLibraries[i].Bind(name.Name, name.Namespace, args);
             if (function != null)
             {
                 expr2 = new XPathFunctionExpr(function, args);
                 break;
             }
         }
     }
     if ((expr2 == null) && (this.context != null))
     {
         XPathResultType[] argTypes = new XPathResultType[args.Count];
         for (int j = 0; j < args.Count; j++)
         {
             argTypes[j] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[j].ReturnType);
         }
         string prefix = this.context.LookupPrefix(name.Namespace);
         IXsltContextFunction function2 = this.context.ResolveFunction(prefix, name.Name, argTypes);
         if (function2 != null)
         {
             expr2 = new XPathXsltFunctionExpr(this.context, function2, args);
         }
     }
     if (expr2 == null)
     {
         this.ThrowError(QueryCompileError.UnsupportedFunction);
     }
     this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
     return expr2;
 }