Ejemplo n.º 1
0
            void CompileFunction(XPathFunctionExpr expr)
            {
                // In some scenarios, some functions are handled in a special way
                if (this.CompileFunctionSpecial(expr))
                {
                    return;
                }

                // Generic function compilation
                QueryFunction function = expr.Function;

                // 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)
                    {
                        this.CompileFunctionParam(function, expr.SubExpr, i);
                    }
                }
                this.codeBlock.Append(new FunctionCallOpcode(function));
                if (1 == this.compiler.nestingLevel && function.TestFlag(QueryFunctionFlag.UsesContextNode))
                {
                    this.compiler.SetPushInitialContext(true);
                }
            }
        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);
        }
Ejemplo n.º 3
0
        internal override bool Equals(QueryFunction function)
        {
            XPathFunction function2 = function as XPathFunction;

            if (function2 == null)
            {
                return(false);
            }
            return(function2.ID == this.ID);
        }
Ejemplo n.º 4
0
        internal override bool Equals(QueryFunction function)
        {
            ConcatFunction f = function as ConcatFunction;

            if (f != null && this.argCount == f.argCount)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        internal override bool Equals(QueryFunction function)
        {
            XPathFunction xpathFunction = function as XPathFunction;

            if (null == xpathFunction)
            {
                return(false);
            }

            return(xpathFunction.ID == this.ID);
        }
Ejemplo n.º 6
0
            private void CompileFunctionParam(QueryFunction function, XPathExprList paramList, int index)
            {
                XPathExpr expr = paramList[index];

                this.CompileExpression(expr);
                if ((function.ParamTypes[index] != ValueDataType.None) && (expr.ReturnType != function.ParamTypes[index]))
                {
                    if (function.ParamTypes[index] == ValueDataType.Sequence)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidTypeConversion));
                    }
                    this.CompileTypecast(function.ParamTypes[index]);
                }
            }
Ejemplo n.º 7
0
 private void CompileFunction(XPathFunctionExpr expr)
 {
     if (!this.CompileFunctionSpecial(expr))
     {
         QueryFunction function = expr.Function;
         if (expr.SubExprCount > 0)
         {
             for (int i = expr.SubExpr.Count - 1; i >= 0; i--)
             {
                 this.CompileFunctionParam(function, expr.SubExpr, i);
             }
         }
         this.codeBlock.Append(new FunctionCallOpcode(function));
         if ((1 == this.compiler.nestingLevel) && function.TestFlag(QueryFunctionFlag.UsesContextNode))
         {
             this.compiler.SetPushInitialContext(true);
         }
     }
 }
Ejemplo n.º 8
0
            void CompileFunctionParam(QueryFunction function, XPathExprList paramList, int index)
            {
                XPathExpr param = paramList[index];
                this.CompileExpression(param);
                if (ValueDataType.None != function.ParamTypes[index])
                {
                    if (param.ReturnType != function.ParamTypes[index])
                    {
                        if (function.ParamTypes[index] == ValueDataType.Sequence)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.InvalidTypeConversion));
                        }

                        this.CompileTypecast(function.ParamTypes[index]);
                    }
                }
            }
 internal FunctionCallOpcode(QueryFunction function) : base(OpcodeID.Function)
 {
     this.function = function;
 }
Ejemplo n.º 10
0
        internal override bool Equals(QueryFunction function)
        {
            XPathFunction xpathFunction = function as XPathFunction;
            if (null == xpathFunction)
            {
                return false;
            }

            return (xpathFunction.ID == this.ID);
        }
Ejemplo n.º 11
0
 internal abstract bool Equals(QueryFunction function);
Ejemplo n.º 12
0
 internal override bool Equals(QueryFunction function)
 {
     ConcatFunction f = function as ConcatFunction;
     if (f != null && this.argCount == f.argCount)
     {
         return true;
     }
     return false;
 }
 internal override bool Equals(QueryFunction function)
 {
     ConcatFunction function2 = function as ConcatFunction;
     return ((function2 != null) && (this.argCount == function2.argCount));
 }
Ejemplo n.º 14
0
 internal FunctionCallOpcode(QueryFunction function)
     : base(OpcodeID.Function)
 {
     Fx.Assert(null != function, "");
     this.function = function;
 }
 internal XPathFunctionExpr(QueryFunction function, XPathExprList subExpr) : base(XPathExprType.Function, function.ReturnType, subExpr)
 {
     this.function = function;
 }
Ejemplo n.º 16
0
 internal XPathFunctionExpr(QueryFunction function, XPathExprList subExpr) : base(XPathExprType.Function, function.ReturnType, subExpr)
 {
     this.function = function;
 }
Ejemplo n.º 17
0
 internal abstract bool Equals(QueryFunction function);
Ejemplo n.º 18
0
 internal FunctionCallOpcode(QueryFunction function)
     : base(OpcodeID.Function)
 {
     Fx.Assert(null != function, "");
     this.function = function;
 }
Ejemplo n.º 19
0
 internal XPathFunctionExpr(QueryFunction function, XPathExprList subExpr)
     : base(XPathExprType.Function, function.ReturnType, subExpr)
 {
     Fx.Assert(null != function, "");
     this.function = function;
 }
 internal override bool Equals(QueryFunction function)
 {
     XPathFunction function2 = function as XPathFunction;
     if (function2 == null)
     {
         return false;
     }
     return (function2.ID == this.ID);
 }
Ejemplo n.º 21
0
 internal XPathFunctionExpr(QueryFunction function, XPathExprList subExpr)
     : base(XPathExprType.Function, function.ReturnType, subExpr)
 {
     Fx.Assert(null != function, "");
     this.function = function;
 }
Ejemplo n.º 22
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);
        }
        internal override bool Equals(QueryFunction function)
        {
            ConcatFunction function2 = function as ConcatFunction;

            return((function2 != null) && (this.argCount == function2.argCount));
        }