예제 #1
0
        public object VisitUnaryOp(Token op, INode node, object options) // добавление ветрки для унарной операции
        {
            LegacyData legacyData = (LegacyData)options;

            BranchOrientation legacyOrientation = legacyData.LegacyOrientation;
            string            legacyIndent      = legacyData.LegacyIndent;

            if (legacyOrientation == BranchOrientation.Left)
            {
                sb.AppendLine(ReplaceLastChar(legacyIndent, L_TURN) + H_PIPE + " (" + op.ToString() + ")");
            }
            else
            {
                sb.AppendLine(ReplaceLastChar(legacyIndent, R_TURN) + H_PIPE + " (" + op.ToString() + ")");
            }

            if (legacyOrientation == BranchOrientation.Right)
            {
                node.Accept(this, new LegacyData
                {
                    LegacyIndent      = ReplaceLastChar(legacyIndent, SPACE) + TAB + R_TURN,
                    LegacyOrientation = BranchOrientation.Right
                });
            }
            else
            {
                node.Accept(this, new LegacyData
                {
                    LegacyIndent      = ReplaceLastChar(legacyIndent, V_PIPE) + TAB + R_TURN,
                    LegacyOrientation = BranchOrientation.Right
                });
            }

            return(this.sb.ToString());
        }
예제 #2
0
        public object VisitUnaryOp(Token op, INode node)
        {
            switch (op.Type)
            {
            case TokenType.Plus:
                return((decimal)node.Accept(this));

            case TokenType.Minus:
                return(-(decimal)node.Accept(this));

            default:
                throw new Exception(string.Format("Token of type {0} cannot be evaluated.", op.Type.ToString()));
            }
        }
예제 #3
0
        public object VisitUnaryOp(Token op, INode node, object options) // вычисление результата выполнения унарных операций
        {
            switch (op.Type)
            {
            case TokenType.Plus:
                return((decimal)node.Accept(this, options));

            case TokenType.Minus:
                return(-(decimal)node.Accept(this, options));

            default:
                throw new Exception(string.Format("Операция типа {0} не может быть произведена.", op.Type.ToString()));
            }
        }
예제 #4
0
파일: Store.cs 프로젝트: zerouid/RQLite.Net
        /// <summary>
        /// Connect returns a new connection to the database. Changes made to the database
        /// through this connection are applied via the Raft consensus system. The Store
        /// must have been opened first. Must be called on the leader or an error will
        /// we returned.
        ///
        /// Any connection returned by this call are READ_COMMITTED isolated from all
        /// other connections, including the connection built-in to the Store itself.
        /// </summary>
        /// <param name="opt"></param>
        /// <returns></returns>
        public async Task <StoreConnection> Connect(StoreConnection.ConnectionOptions opt)
        {
            // Randomly-selected connection ID must be part of command so
            // that all nodes use the same value as connection ID.
            Func <ulong> newRandomId = () =>
            {
                var buf = new byte[8];
                randSrc.NextBytes(buf);
                return(BitConverter.ToUInt64(buf, 0));
            };
            ulong connID = newRandomId();

            connsMu.EnterWriteLock();
            try
            {
                while (conns.ContainsKey(connID))
                {
                    connID = newRandomId();
                }
                conns.Add(connID, null);
            }
            finally
            {
                connsMu.ExitWriteLock();
            }
            var cmd = new Command
            {
                Typ = CommandType.connect,
                Sub = new connectionSub
                {
                    ConnID      = connID,
                    IdleTimeout = opt?.IdleTimeout,
                    TxTimeout   = opt?.TxTimeout
                }
            };

            var f = await raft.Accept(cmd).ThrowOnError();

            connsMu.EnterReadLock();
            try
            {
                stats.NumConnects.WriteMetric(1);
                return(conns[connID]);
            }
            finally
            {
                connsMu.ExitReadLock();
            }
        }
예제 #5
0
        public static string Visit(INode node, NodeBuilder nodeBuilder)
        {
            var visitor = new XmlVisitor(nodeBuilder);

            node.Accept(visitor);
            return(visitor._builder.ToString());
        }
예제 #6
0
 public void Compile(INode moduleAst)
 {
     moduleAst.Accept(this);
     // Bake it
     typeBuilder.CreateType();
     assemblyBuilder.Save(moduleBuilder.ScopeName);
 }
예제 #7
0
        public static string Visit(INode node)
        {
            var visitor = new GeneratorVisitor();

            node.Accept(visitor);
            return(visitor._builder.ToString());
        }
예제 #8
0
        public async Task <IActionResult> Command()
        {
            try
            {
                using (var reader = new StreamReader(HttpContext.Request.Body))
                {
                    var json = await reader.ReadToEndAsync();

                    var command = JsonConvert.DeserializeObject <ICommand>(json, _jsonSerialiserSettings);

                    _logger.LogDebug($"{_baseSchemeUrlAndPort}/command called, my state is {_node.State.GetType().FullName}");

                    var commandResponse = await _node.Accept(command);

                    json = JsonConvert.SerializeObject(commandResponse, _jsonSerialiserSettings);

                    return(StatusCode(200, json));
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"THERE WAS A PROBLEM ON NODE {_node.State.CurrentState.Id}", e);
                throw;
            }
        }
        protected IEnumerable <String> ExtractIsoCodes(INode node)
        {
            var resolver = new TryExtractIsoCode_INodeResolver(this);

            node.Accept(resolver);
            return(resolver.Result);
        }
예제 #10
0
        public IBasket TryExtractBasketOnceResolved(INode node)
        {
            var resolver = new ExtractBasketsIdsOnceResolved_INodeResolver(this);

            node.Accept(resolver);
            return(resolver.ResultOpt);
        }
예제 #11
0
 public void Add(INode n)
 {
     AddItem(new CompletionItem
     {
         Label      = n.Name,
         Deprecated = n is DNode dNode && dNode.ContainsAnyAttribute(DTokens.Deprecated),
         TextEdit   = CalculateTextEdit(n.Name),
         Kind       = n.Accept(new CompletionItemKindVisitor())
     });
예제 #12
0
        public object VisitBinOp(Token op, INode left, INode right, object options) // вычисление результата выполнения бинарных операций
        {
            switch (op.Type)
            {
            case TokenType.Plus:
                return((decimal)left.Accept(this, options) + (decimal)right.Accept(this, options));    // сложение

            case TokenType.Minus:
                return((decimal)left.Accept(this, options) - (decimal)right.Accept(this, options));    // вычитание

            case TokenType.Multiply:
                return((decimal)left.Accept(this, options) * (decimal)right.Accept(this, options));    // умножение

            case TokenType.Divide:
                return((decimal)left.Accept(this, options) / (decimal)right.Accept(this, options));    // деление

            default:
                throw new Exception(string.Format("Операция типа {0} не может быть произведена.", op.Type.ToString()));
            }
        }
예제 #13
0
        public object VisitBinOp(Token op, INode left, INode right)
        {
            switch (op.Type)
            {
            case TokenType.Plus:
                return((decimal)left.Accept(this) + (decimal)right.Accept(this));

            case TokenType.Minus:
                return((decimal)left.Accept(this) - (decimal)right.Accept(this));

            case TokenType.Multiply:
                return((decimal)left.Accept(this) * (decimal)right.Accept(this));

            case TokenType.Divide:
                return((decimal)left.Accept(this) / (decimal)right.Accept(this));

            default:
                throw new Exception(string.Format("Token of type {0} cannot be evaluated.", op.Type.ToString()));
            }
        }
        public async Task <Responses.Response> Set(FileConfiguration fileConfiguration)
        {
            var result = await _node.Accept(new UpdateFileConfiguration(fileConfiguration));

            if (result.GetType() == typeof(ErrorResponse <UpdateFileConfiguration>))
            {
                return(new Responses.ErrorResponse(new UnableToSaveAcceptCommand($"unable to save file configuration to state machine")));
            }

            return(new Responses.OkResponse());
        }
        protected ICommandContext createCommandContext(String twoWaySql, String[] argNames, Type[] argTypes, Object[] args)
        {
            ICommandContext context;

            {
                InternalSqlParser             parser  = new InternalSqlParser(twoWaySql, true);
                INode                         node    = parser.Parse();
                InternalCommandContextCreator creator = new InternalCommandContextCreator(argNames, argTypes);
                context = creator.CreateCommandContext(args);
                node.Accept(context);
            }
            return(context);
        }
예제 #16
0
        public static String ConvertTwoWaySql2DisplaySql(String twoWaySql, String[] argNames, Type[] argTypes, Object[] args)
        {
            ICommandContext context;
            {
                InternalSqlParser             parser  = new InternalSqlParser(twoWaySql, false);
                INode                         node    = parser.Parse();
                InternalCommandContextCreator creator = new InternalCommandContextCreator(argNames, argTypes);
                context = creator.CreateCommandContext(args);
                node.Accept(context);
            }
            String preparedSql = context.Sql;

            return(InternalBindVariableUtil.GetCompleteSql(preparedSql, context.BindVariables));
        }
예제 #17
0
        //rendre intelligent cette methode pour pre process les instruction qui lui sont passé
        public void Emit(Op op, int val)
        {
            switch (op)
            {
            case Op.CONST:
                Current = new Const(val);
                break;

            case Op.STO:
                Console.Write("store: ");
                Current.Accept(new PrintVisitor());
                break;
            }
        }
예제 #18
0
        /// <summary>
        /// Adds a node to the completion data
        /// </summary>
        /// <param name="Node"></param>
        public void Add(INode Node)
        {
            if (Node.NameHash == 0)
            {
                return;
            }
            var name = Node.Name;

            if (!nameMatches(name))
            {
                return;
            }

            var sb = new StringBuilder(NodeToolTipContentGen.Instance.GenTooltipSignature(Node as DNode));

            GenerateNodeTooltipBody(Node as DNode, sb);

            addExpansion(name, Node.Accept(NodeTypeNameVisitor.Instance), sb.ToString());
        }
예제 #19
0
        /// <summary>
        /// Writes the buffered formula in infix notation, minimizing the number of parentheses written
        /// </summary>
        /// <exception cref="MissingMemberException">No valid formula is currently buffered.</exception>
        private void PrintSimpleInfix(INode formula)
        {
            if (isMinInfixBuffered)
            {
                Console.WriteLine(bufferedMinInfix);
                return;
            }

            if (formula == null)
            {
                throw new MissingMemberException("No valid formula specified");
            }

            string result = formula.Accept(_minInfixWriter);

            bufferedMinInfix   = result;
            isMinInfixBuffered = true;
            Console.WriteLine(bufferedMinInfix);
        }
예제 #20
0
        /// <summary>
        /// Evaluates the buffered formula as a floating point number and writes the result to <code>Console.Out</code>
        /// </summary>
        /// <exception cref="MissingMemberException">No valid formula is currently buffered.</exception>
        /// <exception cref="FormatException">Propagated exception from evaluation.</exception>
        private void EvalAsDouble(INode formula)
        {
            if (isDoubleBuffered)
            {
                Console.WriteLine(bufferedDoubleValue.ToString("f05"));
                return;
            }

            if (formula == null)
            {
                throw new MissingMemberException("Trying to evaluate formula, but none is specified.");
            }

            double result = formula.Accept(_doubleEvaler);

            bufferedDoubleValue = result;
            isDoubleBuffered    = true;
            Console.WriteLine(bufferedDoubleValue.ToString("f05"));
        }
예제 #21
0
        /// <summary>
        /// Evaluates the buffered formula in integer form and writes the result to <code>Console.Out</code>
        /// </summary>
        /// <exception cref="MissingMemberException">No valid formula is currently buffered.</exception>
        /// <exception cref="FormatException">Propagated exception from evaluation.</exception>
        /// <exception cref="DivideByZeroException">Propagated exception from evaluation.</exception>
        /// <exception cref="OverflowException">Propagated exception from evaluation.</exception>
        private void EvalAsInt(INode formula)
        {
            if (isIntBuffered)
            {
                Console.WriteLine(bufferedIntValue);
                return;
            }

            if (formula == null)
            {
                throw new MissingMemberException("Trying to evaluate formula, but none is specified.");
            }

            int result = formula.Accept(_intEvaler);

            bufferedIntValue = result;
            isIntBuffered    = true;
            Console.WriteLine(bufferedIntValue);
        }
예제 #22
0
        void SetTemplate(ElementTemplate dt, INode node)
        {
#pragma warning disable 0612
            ((IDataTemplate)dt).LoadTemplate = () =>
            {
#pragma warning restore 0612
                var context = new HydratationContext {
                    ParentContext = Context, RootElement = Context.RootElement
                };
                node.Accept(new ExpandMarkupsVisitor(context), null);
                node.Accept(new NamescopingVisitor(context), null);
                node.Accept(new CreateValuesVisitor(context), null);
                node.Accept(new RegisterXNamesVisitor(context), null);
                node.Accept(new FillResourceDictionariesVisitor(context), null);
                node.Accept(new ApplyPropertiesVisitor(context, true), null);
                return(context.Values[node]);
            };
        }
예제 #23
0
 public void Visit(INode node)
 {
     node.Accept(this);
 }
예제 #24
0
 public virtual TResult Visit(INode node)
 {
     return(node != null?node.Accept(this) : default(TResult));
 }
 protected TResult Visit(INode <AstNode> subject, bool throwOnError)
 {
     return(subject.Accept <TResult>(this, throwOnError));
 }
예제 #26
0
 public virtual void Visit(TContext context, INode node)
 {
     node.Accept(context, this);
 }
예제 #27
0
 public bool GetTime(INode source, INode target, MovementType movementType, out float time)
 {
     source.Accept(this, target, movementType);
     time = resTime;
     return(canPass);
 }
예제 #28
0
        /// <summary>
        /// The variable's or method's base type will be resolved (if auto type, the intializer's type will be taken).
        /// A class' base class will be searched.
        /// etc..
        /// </summary>
        public static AbstractType HandleNodeMatch(
            INode m,
            ResolutionContext ctxt,
            AbstractType resultBase    = null,
            ISyntaxRegion typeBase     = null,
            NodeMatchHandleVisitor vis = null)
        {
            // See https://github.com/aBothe/Mono-D/issues/161
            int stkC;

            if (stackCalls == null)
            {
                stackCalls    = new Dictionary <INode, int>();
                stackCalls[m] = 1;
            }
            else
            {
                stackCalls[m] = stackCalls.TryGetValue(m, out stkC) ? ++stkC : 1;
            }

            /*
             * Pushing a new scope is only required if current scope cannot be found in the handled node's hierarchy.
             * Edit: No, it is required nearly every time because of nested type declarations - then, we do need the
             * current block scope.
             */
            bool popAfterwards;

            {
                var newScope = m is IBlockNode ? (IBlockNode)m : m.Parent as IBlockNode;
                popAfterwards = ctxt.ScopedBlock != newScope && newScope != null;
                if (popAfterwards)
                {
                    var options      = ctxt.CurrentContext.ContextDependentOptions;
                    var applyOptions = ctxt.ScopedBlockIsInNodeHierarchy(m);
                    ctxt.PushNewScope(newScope);
                    if (applyOptions)
                    {
                        ctxt.CurrentContext.ContextDependentOptions = options;
                    }
                }
            }

            // To support resolving type parameters to concrete types if the context allows this, introduce all deduced parameters to the current context
            if (resultBase is DSymbol)
            {
                ctxt.CurrentContext.IntroduceTemplateParameterTypes((DSymbol)resultBase);
            }

            var ret = m.Accept(vis ?? new NodeMatchHandleVisitor {
                ctxt = ctxt, resultBase = resultBase, typeBase = typeBase
            });

            if (popAfterwards)
            {
                ctxt.Pop();
            }
            else if (resultBase is DSymbol)
            {
                ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals((DSymbol)resultBase);
            }

            stackCalls.TryGetValue(m, out stkC);
            if (stkC == 1)
            {
                stackCalls.Remove(m);
            }
            else
            {
                stackCalls[m] = stkC - 1;
            }

            return(ret);
        }
예제 #29
0
파일: TempNode.cs 프로젝트: MK4H/MHUrho
 public void Accept(INodeVisitor visitor, INode target, MovementType movementType)
 {
     target.Accept(visitor, this, movementType);
 }
예제 #30
0
 public static string Visit(INode node)
 {
     var visitor = new XmlVisitor();
     node.Accept(visitor);
     return visitor._builder.ToString();
 }
예제 #31
0
		void SetTemplate(ElementTemplate dt, INode node)
		{
#pragma warning disable 0612
			((IDataTemplate)dt).LoadTemplate = () =>
			{
#pragma warning restore 0612
				var context = new HydratationContext { ParentContext = Context, RootElement = Context.RootElement };
				node.Accept(new ExpandMarkupsVisitor(context), null);
				node.Accept(new NamescopingVisitor(context), null);
				node.Accept(new CreateValuesVisitor(context), null);
				node.Accept(new RegisterXNamesVisitor(context), null);
				node.Accept(new FillResourceDictionariesVisitor(context), null);
				node.Accept(new ApplyPropertiesVisitor(context, true), null);
				return context.Values[node];
			};
		}
예제 #32
0
 public void Accept(NodeVisitor visitor)
 {
     _node.Accept(visitor);
 }
예제 #33
0
		public void Visit(INode node)
		{
			node.Accept(this);
		}