/// <summary>
 /// Initializes a new instance of the <see cref="Artefacts.Service.ClientQueryProvider`1"/> class.
 /// </summary>
 /// <param name="repository">Repository.</param>
 /// <param name="visitor">Visitor.</param>
 public ClientQueryProvider(IRepository repository, ExpressionVisitor visitor = null)
 {
     if (repository == null)
         throw new ArgumentNullException("repository");
     Repository = repository;
     _clientProxy = new RepositoryClientProxy(new NetTcpBinding(SecurityMode.None), "net.tcp://localhost:3334/ArtefactRepository");
 }
Exemple #2
0
        public static Dictionary<string, FNode> BuildParameters(ExpressionVisitor Evaluator, HScriptParser.Bind_element_setContext context)
        {

            Dictionary<string, FNode> parameters = new Dictionary<string, FNode>();
            if (context == null)
                return parameters;
            
            foreach (HScriptParser.Bind_elementContext ctx in context.bind_element())
            {

                string key = ctx.SCALAR().GetText();
                bool is_dynamic = 
                    (ctx.K_STATIC() == null) 
                    ? true 
                    : false;
                FNode value = 
                    (is_dynamic) 
                    ? Evaluator.ToNode(ctx.expression()) 
                    : new FNodeValue(null, new Cell(ctx.expression().GetText(), false));
                parameters.Add(key, value);

            }
            return parameters;

        }
        private static Expression ParseTokens(CommonTokenStream input)
        {
            ExpressionParser.ExpressionContext startContext = new ExpressionParser(input).expression();

            ExpressionVisitor visit = new ExpressionVisitor();
            Expression expr = visit.Visit(startContext);
            return expr;
        }
Exemple #4
0
        // Reads //
        public static StagedReadName RenderStagedReadPlan(Workspace Home, HScriptParser.Crudam_readContext context)
        {

            // Get the data source //
            DataSet data = VisitorHelper.GetData(Home, context.full_table_name());
            string alias =
                (context.K_AS() != null)
                ? context.IDENTIFIER().GetText()
                : data.Name;

            // Create a local heap to work off of //
            MemoryStruct local_heap = new MemoryStruct(true);

            // Create a record register //
            StreamRegister memory = new StreamRegister(null);

            // Create expression visitor //
            ExpressionVisitor exp_vis = new ExpressionVisitor(local_heap, Home, alias, data.Columns, memory);

            // Where clause //
            Predicate where = VisitorHelper.GetWhere(exp_vis, context.where_clause());

            // Create a reader //
            RecordReader reader = data.OpenReader(where);

            // Attach the reader to the register //
            memory.BaseStream = reader;

            // Create the action visitor //
            ActionVisitor act_vis = new ActionVisitor(Home, local_heap, exp_vis);

            // Get the declarations //
            if (context.crudam_declare_many() != null)
            {
                VisitorHelper.AllocateMemory(Home, local_heap, exp_vis, context.crudam_declare_many());
            }

            // Get the initial actionset //
            TNode pre_run =
                (context.init_action() != null)
                ? act_vis.ToNode(context.init_action().query_action())
                : new TNodeNothing(null);

            // Get the main actionset //
            TNode run = act_vis.ToNode(context.main_action().query_action());

            // Get the final actionset //
            TNode post_run =
                (context.final_action() != null)
                ? act_vis.ToNode(context.final_action().query_action())
                : new TNodeNothing(null);

            return new StagedReadName(reader, pre_run, run, post_run);

        }
Exemple #5
0
 protected override Expression Accept(ExpressionVisitor visitor)
 {
     return(base.Accept(visitor));
 }
 /// <summary>
 /// Dispatches to the specific visit method for this node type.
 /// </summary>
 protected internal override Expression Accept(ExpressionVisitor visitor) {
     return visitor.VisitMethodCall(this);
 }
 /// <summary>
 /// Dispatches to the specific visit method for this node type.
 /// </summary>
 protected internal override Expression Accept(ExpressionVisitor visitor) {
     return visitor.VisitNewArray(this);
 }
Exemple #8
0
        // Partitions //
        public static int GetPartitions(ExpressionVisitor Evaluator, HScriptParser.PartitionsContext context)
        {

            // Null then assume 1 partition //
            if (context == null)
                return 1;

            // If the expression is null, then max out cores //
            if (context.expression() == null)
                return Environment.ProcessorCount;

            // Otherwise, get the value //
            int cnt = (int)Evaluator.ToNode(context.expression()).Evaluate().valueINT;

            // Bound it //
            cnt = Math.Min(cnt, Environment.ProcessorCount * 2);
            cnt = Math.Max(cnt, 1);

            return cnt;

        }
Exemple #9
0
        private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.EOW_table_starContext context)
        {

            string alias = context.IDENTIFIER()[0].GetText();
            if (!Evaluator.Columns.ContainsKey(alias))
                throw new Exception(string.Format("Alias '{0}' does not exist", alias));

            FNodeSet nodes = new FNodeSet(Evaluator.Columns[alias]);
            nodes.AssignRegister(Evaluator.Registers[alias]);

            string suffix = (context.K_AS() == null) ? null : context.IDENTIFIER()[1].GetText();

            for (int i = 0; i < nodes.Count; i++)
            {
                Fields.Add((suffix == null) ? nodes.Alias(i) : suffix + nodes.Alias(i), nodes[i]);
            }

        }
Exemple #10
0
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.Crudam_declare_manyContext context)
        {

            foreach (HScriptParser.Declare_genericContext ctx in context.declare_generic())
            {
                AllocateMemory(Home, Heap, Evaluator, ctx);
            }

        }
 protected override Expression VisitChildren(ExpressionVisitor visitor)
 => Update((SqlExpression)visitor.Visit(Expression));
Exemple #12
0
 public override T Accept <T>(ExpressionVisitor <T> v)
 {
     return(v.VisitPointerAddition(this));
 }
Exemple #13
0
 public override T Accept <T, C>(ExpressionVisitor <T, C> v, C context)
 {
     return(v.VisitPointerAddition(this, context));
 }
Exemple #14
0
 public override T Accept <T>(ExpressionVisitor <T> v)
 {
     return(v.VisitProcedureConstant(this));
 }
Exemple #15
0
 public override T Accept <T, C>(ExpressionVisitor <T, C> v, C context)
 {
     return(v.VisitProcedureConstant(this, context));
 }
Exemple #16
0
 public override T Accept <T>(ExpressionVisitor <T> v)
 {
     return(v.VisitApplication(this));
 }
Exemple #17
0
 public override T Accept <T, C>(ExpressionVisitor <T, C> v, C context)
 {
     return(v.VisitApplication(this, context));
 }
Exemple #18
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected override Expression VisitChildren(ExpressionVisitor visitor)
        {
            Check.NotNull(visitor, nameof(visitor));

            var changed = false;

            var projections = new List <ProjectionExpression>();
            IDictionary <ProjectionMember, Expression> projectionMapping;

            if (Projection.Any())
            {
                projectionMapping = _projectionMapping;
                foreach (var item in Projection)
                {
                    var projection = (ProjectionExpression)visitor.Visit(item);
                    projections.Add(projection);

                    changed |= projection != item;
                }
            }
            else
            {
                projectionMapping = new Dictionary <ProjectionMember, Expression>();
                foreach (var mapping in _projectionMapping)
                {
                    var newProjection = visitor.Visit(mapping.Value);
                    changed |= newProjection != mapping.Value;

                    projectionMapping[mapping.Key] = newProjection;
                }
            }

            var fromExpression = (RootReferenceExpression)visitor.Visit(FromExpression);

            changed |= fromExpression != FromExpression;

            var predicate = (SqlExpression)visitor.Visit(Predicate);

            changed |= predicate != Predicate;

            var orderings = new List <OrderingExpression>();

            foreach (var ordering in _orderings)
            {
                var orderingExpression = (SqlExpression)visitor.Visit(ordering.Expression);
                changed |= orderingExpression != ordering.Expression;
                orderings.Add(ordering.Update(orderingExpression));
            }

            var offset = (SqlExpression)visitor.Visit(Offset);

            changed |= offset != Offset;

            var limit = (SqlExpression)visitor.Visit(Limit);

            changed |= limit != Limit;

            if (changed)
            {
                var newSelectExpression = new SelectExpression(projections, fromExpression, orderings)
                {
                    _projectionMapping = projectionMapping,
                    Predicate          = predicate,
                    Offset             = offset,
                    Limit      = limit,
                    IsDistinct = IsDistinct
                };

                return(newSelectExpression);
            }

            return(this);
        }
Exemple #19
0
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrixLiteralContext context)
        {

            string name = context.IDENTIFIER().GetText();
            CellAffinity type = GetAffinity(context.type());
            MatrixVisitor vis = new MatrixVisitor(Home, Heap, Evaluator);
            CellMatrix mat = vis.ToMatrix(context.matrix_expression()).Evaluate();
            Heap.Arrays.Reallocate(name, mat);

        }
        //////////////////////////////////////////////

        #region BoundVariableExpression Members

        public override Expression visit(ExpressionVisitor v)
        {
            return(v.visit(this));
        }
Exemple #21
0
        // Expression or wildcard handelers //
        private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.EOW_expressionContext context)
        {

            FNode node = Evaluator.ToNode(context.expression_alias().expression());
            string alias = ("F" + Fields.Count.ToString());
            if (node.Name != null)
                alias = node.Name;
            if (context.expression_alias().K_AS() != null)
                alias = context.expression_alias().IDENTIFIER().GetText();
            Fields.Add(alias, node);

        }
Exemple #22
0
 /// <inheritdoc />
 protected override Expression Accept(ExpressionVisitor visitor)
 => visitor is NpgsqlQuerySqlGenerator npgsqlGenerator
Exemple #23
0
        private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.Expression_or_wildcardContext context)
        {

            if (context is HScriptParser.EOW_expressionContext)
            {
                AppendSet(Evaluator, Fields, context as HScriptParser.EOW_expressionContext);
                return;
            }

            if (context is HScriptParser.EOW_local_starContext)
            {
                AppendSet(Evaluator, Fields, context as HScriptParser.EOW_local_starContext);
                return;
            }

            if (context is HScriptParser.EOW_global_starContext)
            {
                AppendSet(Evaluator, Fields, context as HScriptParser.EOW_global_starContext);
                return;
            }

            if (context is HScriptParser.EOW_table_starContext)
            {
                AppendSet(Evaluator, Fields, context as HScriptParser.EOW_table_starContext);
                return;
            }

            if (context is HScriptParser.EOW_tables_starContext)
            {
                AppendSet(Evaluator, Fields, context as HScriptParser.EOW_tables_starContext);
                return;
            }

        }
Exemple #24
0
 public override void Accept(ExpressionVisitor vis)
 {
     vis.Visit(this);
 }
 public override void OnAfterCall(Identifier stackReg, ProcedureSignature sigCallee, ExpressionVisitor<Expression> eval)
 {
     throw new NotImplementedException();
 }
 public override void Accept(ExpressionVisitor expressionVisitor)
 {
     expressionVisitor.Visit(this);
 }
Exemple #27
0
 public override void Visit(ExpressionVisitor visitor)
 {
     visitor.Visit(this);
 }
Exemple #28
0
 /// <summary>
 ///     Reduces the node and then calls the visitor delegate on the reduced expression.
 ///     The method throws an exception if the node is not
 ///     reducible.
 /// </summary>
 /// <returns>
 ///     The expression being visited, or an expression which should replace it in the tree.
 /// </returns>
 /// <param name="visitor">An instance of <see cref="T:System.Func`2" />.</param>
 protected override Expression VisitChildren(ExpressionVisitor visitor)
 => Update(visitor.Visit(Caller), visitor.Visit(AccessOperation));
Exemple #29
0
 public override Expression Accept(ExpressionVisitor visitor)
 {
     return visitor.VisitParameter(this);
 }
Exemple #30
0
        public override void OnAfterCall(Identifier sp, ProcedureSignature sigCallee, ExpressionVisitor <Expression> eval)
        {
            var spReg       = (RegisterStorage)sp.Storage;
            var spVal       = GetValue(spReg);
            var stackOffset = SetValue(
                spReg,
                new BinaryExpression(
                    Operator.IAdd,
                    spVal.DataType,
                    sp,
                    Constant.Create(
                        PrimitiveType.CreateWord(spReg.DataType.Size),
                        sigCallee.StackDelta)).Accept(eval));

            if (stackOffset.IsValid)
            {
                if (stackOffset.ToInt32() > 0)
                {
                    ErrorListener("Possible stack underflow detected.");
                }
            }
        }
 /// <summary>
 /// Dispatches to the specific visit method for this node type.
 /// </summary>
 protected internal override Expression Accept(ExpressionVisitor visitor) {
     return visitor.VisitInvocation(this);
 }
Exemple #32
0
        // Heap allocations //
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareScalarContext context)
        {

            string name = context.IDENTIFIER().GetText();
            CellAffinity type = GetAffinity(context.type());
            Cell value = (context.ASSIGN() != null) ? Evaluator.ToNode(context.expression()).Evaluate() : new Cell(type);

            Heap.Scalars.Reallocate(name, value);

        }
Exemple #33
0
        protected override Expression VisitChildren(ExpressionVisitor visitor)
        {
            QueryExpression = visitor.Visit(QueryExpression);

            return(this);
        }
Exemple #34
0
 /// <inheritdoc />
 protected override Expression VisitChildren(ExpressionVisitor visitor)
 => Update((SqlExpression)visitor.Visit(Array), (SqlExpression)visitor.Visit(Index));
Exemple #35
0
 public override void OnAfterCall(Identifier sp, ProcedureSignature sigCallee, ExpressionVisitor<Expression> eval)
 {
 }
 public void Accept(ExpressionVisitor vis)
 {
     vis.Visit(this);
 }
Exemple #37
0
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.DeclareMatrix2DContext context)
        {

            string name = context.IDENTIFIER().GetText();
            CellAffinity type = GetAffinity(context.type());
            int rows = (int)Evaluator.ToNode(context.expression()[0]).Evaluate().valueINT;
            int cols = (int)Evaluator.ToNode(context.expression()[1]).Evaluate().valueINT;
            CellMatrix mat = new CellMatrix(rows, cols, type);
            Heap.Arrays.Reallocate(name, mat);

        }
 public R Accept <R>(ExpressionVisitor <R> vis)
 {
     return(vis.Visit(this));
 }
Exemple #39
0
        public static void AllocateMemory(Workspace Home, MemoryStruct Heap, ExpressionVisitor Evaluator, HScriptParser.Declare_genericContext context)
        {

            if (context is HScriptParser.DeclareScalarContext)
            {
                VisitorHelper.AllocateMemory(Home, Heap, Evaluator, context as HScriptParser.DeclareScalarContext);
                return;
            }

            if (context is HScriptParser.DeclareMatrix1DContext)
            {
                VisitorHelper.AllocateMemory(Home, Heap, Evaluator, context as HScriptParser.DeclareMatrix1DContext);
                return;
            }

            if (context is HScriptParser.DeclareMatrix2DContext)
            {
                VisitorHelper.AllocateMemory(Home, Heap, Evaluator, context as HScriptParser.DeclareMatrix2DContext);
                return;
            }

            if (context is HScriptParser.DeclareMatrixLiteralContext)
            {
                VisitorHelper.AllocateMemory(Home, Heap, Evaluator, context as HScriptParser.DeclareMatrixLiteralContext);
                return;
            }

        }
Exemple #40
0
 public override TResult Accept <TResult, TContext>(ExpressionVisitor <TResult, TContext> visitor, TContext ctx)
 {
     return(visitor.VisitVariable(ctx, this));
 }
Exemple #41
0
 // Where clause //
 public static Predicate GetWhere(ExpressionVisitor Evaluator, HScriptParser.Where_clauseContext context)
 {
     if (context == null)
         return Predicate.TrueForAll;
     return Evaluator.ToPredicate(context.expression());
 }
Exemple #42
0
 public override T Accept <T, C>(ExpressionVisitor <T, C> v, C context)
 {
     return(v.VisitOutArgument(this, context));
 }
Exemple #43
0
        private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.EOW_global_starContext context)
        {

            string suffix =
                (context.K_AS() == null)
                ? null
                : context.IDENTIFIER().GetText();

            for (int i = 0; i < Evaluator.GlobalHeap.Scalars.Count; i++)
            {
                string alias =
                    (suffix == null)
                    ? Evaluator.LocalHeap.Scalars.Name(i)
                    : suffix + Evaluator.LocalHeap.Scalars.Name(i);
                FNode node = new FNodeHeapRef(null, Evaluator.GlobalHeap, i);
                Fields.Add(alias, node);
            }

        }
Exemple #44
0
 public override T Accept <T>(ExpressionVisitor <T> visitor)
 {
     return(visitor.VisitOutArgument(this));
 }
Exemple #45
0
        private static void AppendSet(ExpressionVisitor Evaluator, FNodeSet Fields, HScriptParser.EOW_tables_starContext context)
        {

            if (Evaluator.Columns.Count == 0)
                return; // no need to toss an exception

            string alias = Evaluator.Columns.Keys.First();
            FNodeSet nodes = new FNodeSet(Evaluator.Columns[alias]);
            nodes.AssignRegister(Evaluator.Registers[alias]);

            string suffix = (context.K_AS() == null) ? null : context.IDENTIFIER().GetText();

            for (int i = 0; i < nodes.Count; i++)
            {
                Fields.Add((suffix == null) ? nodes.Alias(i) : suffix + nodes.Alias(i), nodes[i]);
            }

        }
Exemple #46
0
        /// <summary>
        ///     Reduces the node and then calls the <see cref="ExpressionVisitor.Visit(System.Linq.Expressions.Expression)" /> method passing the
        ///     reduced expression.
        ///     Throws an exception if the node isn't reducible.
        /// </summary>
        /// <param name="visitor"> An instance of <see cref="ExpressionVisitor" />. </param>
        /// <returns> The expression being visited, or an expression which should replace it in the tree. </returns>
        /// <remarks>
        ///     Override this method to provide logic to walk the node's children.
        ///     A typical implementation will call visitor.Visit on each of its
        ///     children, and if any of them change, should return a new copy of
        ///     itself with the modified children.
        /// </remarks>
        protected override Expression VisitChildren(ExpressionVisitor visitor)
        {
            visitor.Visit(_tableExpression);

            return(this);
        }
Exemple #47
0
        public static FNodeSet GetReturnStatement(ExpressionVisitor Evaluator, HScriptParser.Expression_or_wildcard_setContext context)
        {

            FNodeSet nodes = new FNodeSet();

            foreach (HScriptParser.Expression_or_wildcardContext ctx in context.expression_or_wildcard())
                AppendSet(Evaluator, nodes, ctx);

            return nodes;

        }
Exemple #48
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected override Expression VisitChildren(ExpressionVisitor visitor)
        {
            Check.NotNull(visitor, nameof(visitor));

            return(Update((SqlExpression)visitor.Visit(Expression)));
        }
 /// <summary>
 /// Dispatches to the specific visit method for this node type.
 /// </summary>
 protected internal override Expression Accept(ExpressionVisitor visitor) {
     return visitor.VisitConstant(this);
 }
Exemple #50
0
 protected override Expression VisitChildren(ExpressionVisitor visitor)
 {
     return(this);
 }
 /// <summary>
 /// Dispatches to the specific visit method for this node type.
 /// </summary>
 protected internal override Expression Accept(ExpressionVisitor visitor) {
     return visitor.VisitRuntimeVariables(this);
 }
Exemple #52
0
 /// <summary>
 /// Dispatches to the specific visit method for this node type.
 /// </summary>
 protected internal override Expression Accept(ExpressionVisitor visitor)
 {
     return(visitor.VisitLambda(this));
 }
Exemple #53
0
 public abstract void Visit(ExpressionVisitor visitor);
 protected override Expression VisitChildren(ExpressionVisitor visitor) => this;
 protected internal override Expression Accept(ExpressionVisitor visitor) {
     return visitor.VisitDebugInfo(this);
 }
Exemple #56
0
 /// <inheritdoc />
 protected override Expression VisitChildren(ExpressionVisitor visitor)
 => throw new InvalidOperationException(
           CoreStrings.VisitIsNotAllowed($"{nameof(ShapedQueryExpression)}.{nameof(VisitChildren)}"));
Exemple #57
0
 public override void OnAfterCall(Identifier sp, ProcedureSignature sigCallee, ExpressionVisitor<Expression> eval)
 {
     var spReg = (RegisterStorage) sp.Storage;
     var spVal = GetValue(spReg);
     var stackOffset = SetValue(
         spReg,
         new BinaryExpression(
             Operator.IAdd,
             spVal.DataType,
             sp,
             Constant.Create(
                 PrimitiveType.CreateWord(spReg.DataType.Size),
                 sigCallee.StackDelta)).Accept(eval));
     if (stackOffset.IsValid)
     {
         if (stackOffset.ToInt32() > 0)
             ErrorListener("Possible stack underflow detected.");
     }
 }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected override Expression VisitChildren(ExpressionVisitor visitor)
        {
            Check.NotNull(visitor, nameof(visitor));

            return(this);
        }
 /// <summary>
 /// Dispatches to the specific visit method for this node type.
 /// </summary>
 protected internal override Expression Accept(ExpressionVisitor visitor) {
     return visitor.VisitTypeBinary(this);
 }
Exemple #60
0
 protected override Expression Accept(ExpressionVisitor visitor)
 {
     return(visitor.Visit(Constant(_blockParam, typeof(BlockParam))));
 }