Exemplo n.º 1
0
        public PqlCompilerState(
            IExpressionEvaluatorRuntime parentRuntime,
            ParsedRequest parsedRequest,
            DataRequestParams requestParams,
            DataContainerDescriptor containerDescriptor,
            Type contextType,
            Type returnType)
            : base(parentRuntime, contextType, returnType, null)
        {
            if (parsedRequest == null)
            {
                throw new ArgumentNullException("parsedRequest");
            }

            if (containerDescriptor == null)
            {
                throw new ArgumentNullException("containerDescriptor");
            }

            if (requestParams == null)
            {
                throw new ArgumentNullException("requestParams");
            }

            ParsedRequest = parsedRequest;
            RequestParameters = requestParams;
            ContainerDescriptor = containerDescriptor;
            FieldRefs = new Dictionary<int, Tuple<ParameterExpression, Expression>>();
            ParamRefs = new Dictionary<int, Tuple<ParameterExpression, Expression>>();
        }
Exemplo n.º 2
0
        public PqlCompilerState(
            IExpressionEvaluatorRuntime parentRuntime,
            ParsedRequest parsedRequest,
            DataRequestParams requestParams,
            DataContainerDescriptor containerDescriptor,
            Type contextType,
            Type returnType)
            : base(parentRuntime, contextType, returnType, null)
        {
            if (parsedRequest == null)
            {
                throw new ArgumentNullException("parsedRequest");
            }

            if (containerDescriptor == null)
            {
                throw new ArgumentNullException("containerDescriptor");
            }

            if (requestParams == null)
            {
                throw new ArgumentNullException("requestParams");
            }

            ParsedRequest       = parsedRequest;
            RequestParameters   = requestParams;
            ContainerDescriptor = containerDescriptor;
            FieldRefs           = new Dictionary <int, Tuple <ParameterExpression, Expression> >();
            ParamRefs           = new Dictionary <int, Tuple <ParameterExpression, Expression> >();
        }
Exemplo n.º 3
0
 static QueryParser()
 {
     Grammar             = new GrammarPql();
     LangData            = new LanguageData(Grammar);
     PqlNonTerminal      = LangData.GrammarData.NonTerminals.Single(x => x.Name == "stmtList");
     s_expressionRuntime = new ExpressionEvaluatorRuntime();
     InitPqlExpressionRuntime(s_expressionRuntime);
 }
Exemplo n.º 4
0
        private static void InitPqlExpressionRuntime(IExpressionEvaluatorRuntime runtime)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            runtime.RegisterDynamicAtomHandler(new AtomMetadata(AtomType.Identifier, "Pql top-level fields", TopLevelAtomExpressionGeneratorForFields));
            runtime.RegisterDynamicAtomHandler(new AtomMetadata(AtomType.Identifier, "Pql parameters", TopLevelAtomExpressionGeneratorForParameters));
            runtime.RegisterAtom(new AtomMetadata(AtomType.Function, "rownum", PredefinedAtom_RowNumber));
            runtime.RegisterAtom(new AtomMetadata(AtomType.Function, "rownumoutput", PredefinedAtom_RowNumberInPage));
        }
        /// <summary>
        /// DO NOT REMOVE! Used implicitly, via generic method instantiation.
        /// </summary>
        public static HashSet <T> EnumerateValues <T>(IExpressionEvaluatorRuntime runtime, ParseTreeNode root, CompilerState state)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            var isString = ReferenceEquals(typeof(T), typeof(string));
            var result   = isString ? new HashSet <T>((IEqualityComparer <T>)StringComparer.OrdinalIgnoreCase) : new HashSet <T>();

            foreach (var childNode in root.ChildNodes)
            {
                var item = runtime.Analyze(childNode, state);
                item.RequireNonVoid(childNode);

                try
                {
                    result.Add((T)Convert.ChangeType(((ConstantExpression)item).Value, typeof(T)));
                }
                catch
                {
                    throw new CompilationException(
                              String.Format(
                                  "All items in the IN arguments list must be constants of type compatible with {0}. Actual expression found: {1}, of type {2}",
                                  typeof(T).FullName, item.NodeType, item.Type), childNode);
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Ctr.
        /// </summary>
        /// <param name="parentRuntime">Reference to the runtime which created this state object</param>
        /// <param name="contextType">Optional, type of the default @Context argument</param>
        /// <param name="returnType">Optional return type, supply null to compile to Action</param>
        /// <param name="args">Ordered list of types of arguments</param>
        public CompilerState(IExpressionEvaluatorRuntime parentRuntime, Type contextType, Type returnType, params Tuple <string, Type>[] args)
        {
            if (parentRuntime == null)
            {
                throw new ArgumentNullException("parentRuntime");
            }

            var arguments = new List <ParameterExpression>();

            if (contextType != null)
            {
                arguments.Add(Expression.Parameter(contextType, "@Context"));
            }

            if (args != null && args.Length > 0)
            {
                for (var i = 0; i < args.Length; i++)
                {
                    var name = args[i].Item1;
                    var type = args[i].Item2;

                    if (string.IsNullOrEmpty(name))
                    {
                        throw new ArgumentException("Empty argument name at position " + i);
                    }

                    if (arguments.Any(x => 0 == StringComparer.OrdinalIgnoreCase.Compare(x.Name, name)))
                    {
                        throw new ArgumentException("Duplicate argument name: " + name);
                    }

                    arguments.Add(Expression.Parameter(type, name));
                }
            }

            ParentRuntime = parentRuntime;
            ReturnType    = returnType;
            Arguments     = arguments;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Ctr.
        /// </summary>
        /// <param name="parentRuntime">Reference to the runtime which created this state object</param>
        /// <param name="contextType">Optional, type of the default @Context argument</param>
        /// <param name="returnType">Optional return type, supply null to compile to Action</param>
        /// <param name="args">Ordered list of types of arguments</param>
        public CompilerState(IExpressionEvaluatorRuntime parentRuntime, Type contextType, Type returnType, params Tuple<string, Type>[] args)
        {
            if (parentRuntime == null)
            {
                throw new ArgumentNullException("parentRuntime");
            }

            var arguments = new List<ParameterExpression>();

            if (contextType != null)
            {
                arguments.Add(Expression.Parameter(contextType, "@Context"));
            }

            if (args != null && args.Length > 0)
            {
                for (var i = 0; i < args.Length; i++)
                {
                    var name = args[i].Item1;
                    var type = args[i].Item2;

                    if (string.IsNullOrEmpty(name))
                    {
                        throw new ArgumentException("Empty argument name at position " + i);
                    }

                    if (arguments.Any(x => 0 == StringComparer.OrdinalIgnoreCase.Compare(x.Name, name)))
                    {
                        throw new ArgumentException("Duplicate argument name: " + name);
                    }

                    arguments.Add(Expression.Parameter(type, name));
                }
            }

            ParentRuntime = parentRuntime;
            ReturnType = returnType;
            Arguments = arguments;
        }
Exemplo n.º 8
0
 static QueryParser()
 {
     Grammar = new GrammarPql();
     LangData = new LanguageData(Grammar);
     PqlNonTerminal = LangData.GrammarData.NonTerminals.Single(x => x.Name == "stmtList");
     s_expressionRuntime = new ExpressionEvaluatorRuntime();
     InitPqlExpressionRuntime(s_expressionRuntime);
 }
Exemplo n.º 9
0
        private static void InitPqlExpressionRuntime(IExpressionEvaluatorRuntime runtime)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            runtime.RegisterDynamicAtomHandler(new AtomMetadata(AtomType.Identifier, "Pql top-level fields", TopLevelAtomExpressionGeneratorForFields));
            runtime.RegisterDynamicAtomHandler(new AtomMetadata(AtomType.Identifier, "Pql parameters", TopLevelAtomExpressionGeneratorForParameters));
            runtime.RegisterAtom(new AtomMetadata(AtomType.Function, "rownum", PredefinedAtom_RowNumber));
            runtime.RegisterAtom(new AtomMetadata(AtomType.Function, "rownumoutput", PredefinedAtom_RowNumberInPage));
        }