Пример #1
0
        public static Expression CompileFieldValueExtractorClause(PqlCompilerState compilerState, FieldMetadata field, DataContainerDescriptor containerDescriptor, RequestExecutionContextCacheInfo cacheInfo, Type returnType)
        {
            var ordinal = GetFieldOrdinalInDriverFetchFields(cacheInfo.ParsedRequest, field);
            var rowData = Expression.Field(compilerState.Context, "InputRow");

            return(s_expressionRuntime.AdjustReturnType(DriverRowData.CreateReadAccessor(rowData, field.DbType, ordinal), returnType));
        }
Пример #2
0
        public static Expression CompileClause(PqlCompilerState compilerState, ParseTreeNode parseTreeNode, DataContainerDescriptor containerDescriptor, RequestExecutionContextCacheInfo cacheInfo, Type returnType)
        {
            var exprBody = s_expressionRuntime.Analyze(parseTreeNode, compilerState);

            // now add our field references to the expression
            if (compilerState.FieldRefs.Count > 0 || compilerState.ParamRefs.Count > 0)
            {
                // variable declarations
                var localVariables = new ParameterExpression[compilerState.FieldRefs.Count + compilerState.ParamRefs.Count];
                var exprList       = new Expression[1 + localVariables.Length];

                var ix = 0;
                foreach (var pair in compilerState.FieldRefs)
                {
                    localVariables[ix] = pair.Value.Item1;
                    exprList[ix]       = Expression.Assign(pair.Value.Item1, pair.Value.Item2);
                    ix++;
                }
                foreach (var pair in compilerState.ParamRefs)
                {
                    localVariables[ix] = pair.Value.Item1;
                    exprList[ix]       = Expression.Assign(pair.Value.Item1, pair.Value.Item2);
                    ix++;
                }

                // and the expression code itself
                exprList[ix] = exprBody;
                // ready to go
                exprBody = Expression.Block(localVariables, exprList);
            }

            return(s_expressionRuntime.AdjustReturnType(exprBody, returnType));
        }
Пример #3
0
 public static object CompileClause(Expression expression, PqlCompilerState compilerState)
 {
     return(s_expressionRuntime.Compile(expression, compilerState));
 }
Пример #4
0
        private static Expression GetOrAddFieldRefToCompilationContext(ParsedRequest parsedRequest, PqlCompilerState compilerState, FieldMetadata field)
        {
            Tuple <ParameterExpression, Expression> refTuple;

            if (compilerState.FieldRefs.TryGetValue(field.FieldId, out refTuple))
            {
                return(refTuple.Item1);
            }

            var ordinal = GetFieldOrdinalInDriverFetchFields(parsedRequest, field);
            var rowData = Expression.Field(compilerState.Context, "InputRow");

            var fieldAccessor = DriverRowData.CreateReadAccessor(rowData, field.DbType, ordinal);
            var fieldRef      = Expression.Variable(fieldAccessor.Type);

            compilerState.FieldRefs.Add(
                field.FieldId, new Tuple <ParameterExpression, Expression>(fieldRef, fieldAccessor));
            return(fieldRef);
        }
Пример #5
0
        private static Expression GetOrAddParameterRefToCompilationContext(ParsedRequest parsedRequest, PqlCompilerState compilerState, int parameterOrdinal)
        {
            Tuple <ParameterExpression, Expression> refTuple;

            if (compilerState.ParamRefs.TryGetValue(parameterOrdinal, out refTuple))
            {
                return(refTuple.Item1);
            }

            ParameterExpression paramRef;
            Expression          paramExtractor;
            var localOrdinal = parsedRequest.Params.OrdinalToLocalOrdinal[parameterOrdinal];
            var dbType       = parsedRequest.Params.DataTypes[parameterOrdinal];

            if (BitVector.Get(compilerState.RequestParameters.IsCollectionFlags, parameterOrdinal))
            {
                var rowData     = Expression.Field(compilerState.Context, "InputParametersCollections");
                var hashsetType = typeof(HashSet <>).MakeGenericType(DriverRowData.DeriveSystemType(dbType));
                paramExtractor = Expression.Convert(Expression.ArrayIndex(rowData, Expression.Constant(localOrdinal, typeof(int))), hashsetType);
                paramRef       = Expression.Variable(paramExtractor.Type);
            }
            else
            {
                var rowData = Expression.Field(compilerState.Context, "InputParametersRow");
                paramExtractor = DriverRowData.CreateReadAccessor(rowData, dbType, localOrdinal);
                paramRef       = Expression.Variable(paramExtractor.Type);
            }

            compilerState.ParamRefs.Add(
                parameterOrdinal, new Tuple <ParameterExpression, Expression>(paramRef, paramExtractor));
            return(paramRef);
        }
Пример #6
0
        private static Expression GetOrAddParameterRefToCompilationContext(ParsedRequest parsedRequest, PqlCompilerState compilerState, int parameterOrdinal)
        {
            Tuple<ParameterExpression, Expression> refTuple;
            if (compilerState.ParamRefs.TryGetValue(parameterOrdinal, out refTuple))
            {
                return refTuple.Item1;
            }

            ParameterExpression paramRef;
            Expression paramExtractor;
            var localOrdinal = parsedRequest.Params.OrdinalToLocalOrdinal[parameterOrdinal];
            var dbType = parsedRequest.Params.DataTypes[parameterOrdinal];

            if (BitVector.Get(compilerState.RequestParameters.IsCollectionFlags, parameterOrdinal))
            {
                var rowData = Expression.Field(compilerState.Context, "InputParametersCollections");
                var hashsetType = typeof (HashSet<>).MakeGenericType(DriverRowData.DeriveSystemType(dbType));
                paramExtractor = Expression.Convert(Expression.ArrayIndex(rowData, Expression.Constant(localOrdinal, typeof(int))), hashsetType);
                paramRef = Expression.Variable(paramExtractor.Type);
            }
            else
            {
                var rowData = Expression.Field(compilerState.Context, "InputParametersRow");
                paramExtractor = DriverRowData.CreateReadAccessor(rowData, dbType, localOrdinal);
                paramRef = Expression.Variable(paramExtractor.Type);
            }

            compilerState.ParamRefs.Add(
                parameterOrdinal, new Tuple<ParameterExpression, Expression>(paramRef, paramExtractor));
            return paramRef;
        }
Пример #7
0
        private static Expression GetOrAddFieldRefToCompilationContext(ParsedRequest parsedRequest, PqlCompilerState compilerState, FieldMetadata field)
        {
            Tuple<ParameterExpression, Expression> refTuple;
            if (compilerState.FieldRefs.TryGetValue(field.FieldId, out refTuple))
            {
                return refTuple.Item1;
            }

            var ordinal = GetFieldOrdinalInDriverFetchFields(parsedRequest, field);
            var rowData = Expression.Field(compilerState.Context, "InputRow");

            var fieldAccessor = DriverRowData.CreateReadAccessor(rowData, field.DbType, ordinal);
            var fieldRef = Expression.Variable(fieldAccessor.Type);

            compilerState.FieldRefs.Add(
                field.FieldId, new Tuple<ParameterExpression, Expression>(fieldRef, fieldAccessor));
            return fieldRef;
        }
Пример #8
0
 public static Expression CompileFieldValueExtractorClause(PqlCompilerState compilerState, FieldMetadata field, DataContainerDescriptor containerDescriptor, RequestExecutionContextCacheInfo cacheInfo, Type returnType)
 {
     var ordinal = GetFieldOrdinalInDriverFetchFields(cacheInfo.ParsedRequest, field);
     var rowData = Expression.Field(compilerState.Context, "InputRow");
     return s_expressionRuntime.AdjustReturnType(DriverRowData.CreateReadAccessor(rowData, field.DbType, ordinal), returnType);
 }
Пример #9
0
        public static Expression CompileClause(PqlCompilerState compilerState, ParseTreeNode parseTreeNode, DataContainerDescriptor containerDescriptor, RequestExecutionContextCacheInfo cacheInfo, Type returnType)
        {
            var exprBody = s_expressionRuntime.Analyze(parseTreeNode, compilerState);

            // now add our field references to the expression
            if (compilerState.FieldRefs.Count > 0 || compilerState.ParamRefs.Count > 0)
            {
                // variable declarations
                var localVariables = new ParameterExpression[compilerState.FieldRefs.Count + compilerState.ParamRefs.Count];
                var exprList = new Expression[1 + localVariables.Length];

                var ix = 0;
                foreach (var pair in compilerState.FieldRefs)
                {
                    localVariables[ix] = pair.Value.Item1;
                    exprList[ix] = Expression.Assign(pair.Value.Item1, pair.Value.Item2);
                    ix++;
                }
                foreach (var pair in compilerState.ParamRefs)
                {
                    localVariables[ix] = pair.Value.Item1;
                    exprList[ix] = Expression.Assign(pair.Value.Item1, pair.Value.Item2);
                    ix++;
                }

                // and the expression code itself
                exprList[ix] = exprBody;
                // ready to go
                exprBody = Expression.Block(localVariables, exprList);
            }

            return s_expressionRuntime.AdjustReturnType(exprBody, returnType);
        }
Пример #10
0
 public static object CompileClause(Expression expression, PqlCompilerState compilerState)
 {
     return s_expressionRuntime.Compile(expression, compilerState);
 }