Ejemplo n.º 1
0
            //index指定の配列からIPane取得。インデックスなければnull
            public IPane GetPaneByIndices(int[] indices, int position)
            {
                int          index = indices[position];
                DivisionNode node  = _first;

                for (int i = 0; i < index; i++)
                {
                    node = node.Next;
                    if (node == null)
                    {
                        return(null); //out of index
                    }
                }

                bool is_last = position == indices.Length - 1;

                if (is_last)
                {
                    return(node.Pane); //nodeがさらにリストだったらnullが返ることに注意
                }
                else
                {
                    return(node.ChildList.GetPaneByIndices(indices, position + 1)); //子の配列
                }
            }
        // Make calls to the classes that does the final calculation
        public override double Evaluate()
        {
            switch (this.Operator)
            {
            case '+':
                AdditionNode add = new AdditionNode('+');
                add.Left  = this.Left;
                add.Right = this.Right;
                return(add.Evaluate());

            case '-':
                SubtractionNode sub = new SubtractionNode('-');
                sub.Left  = this.Left;
                sub.Right = this.Right;
                return(sub.Evaluate());

            case '*':
                MultiplicationNode mul = new MultiplicationNode('*');
                mul.Left  = this.Left;
                mul.Right = this.Right;
                return(mul.Evaluate());

            case '/':
                DivisionNode div = new DivisionNode('/');
                div.Left  = this.Left;
                div.Right = this.Right;
                return(div.Evaluate());

            default:
                break;
            }

            return(0.0);
        }
Ejemplo n.º 3
0
        private ExpressionNode ParseTerm()
        {
            var lhs = ParseUnary();

            while (true)
            {
                if (_reader.Peek() is Asterisk)
                {
                    Match <Asterisk>();
                    lhs = new MultiplicationNode(lhs, ParseUnary());
                }
                else if (_reader.Peek() is Slash)
                {
                    Match <Slash>();
                    lhs = new DivisionNode(lhs, ParseUnary());
                }
                else if (_reader.Peek() is Percent)
                {
                    Match <Percent>();
                    lhs = new ModNode(lhs, ParseUnary());
                }
                else
                {
                    break;
                }
            }

            return(lhs);
        }
Ejemplo n.º 4
0
        public override Node VisitInfixValueExpr(ML4DParser.InfixValueExprContext context)
        {
            InfixExpressionNode node;

            switch (context.op.Type)
            {
            case ML4DLexer.PLUS:
                node = new AdditionNode("+");
                break;

            case ML4DLexer.MINUS:
                node = new SubtractionNode("-");
                break;

            case ML4DLexer.MUL:
                node = new MultiplicationNode("*");
                break;

            case ML4DLexer.DIV:
                node = new DivisionNode("/");
                break;

            case ML4DLexer.POW:
                node = new PowerNode("**");
                break;

            default:
                throw new NotSupportedException(
                          $"The operator {context.op.Text}, is not a valid arithmetic operator.");
            }
            node.Left  = (ExpressionNode)Visit(context.left);
            node.Right = (ExpressionNode)Visit(context.right);
            return(node);
        }
Ejemplo n.º 5
0
            //ノードの削除 これはややこしいのでドキュメントも参照
            public DivisionNode Remove(DivisionNode target)
            {
                DivisionNode result;
                bool         equally_divided = this.IsEquallyDivided;

                if (target == _first)
                {
                    result = _first.Next;
                    _first = result;
                }
                else
                {
                    DivisionNode node = FindPrevOf(target);
                    Debug.Assert(node != null);

                    node.Next = target.Next;
                    result    = node;
                }

                result.HostingControl.Size = AddSize(result.HostingControl.Size, target.HostingControl.Size);
                result.Ratio += target.Ratio;

                if (equally_divided)
                {
                    AdjustRatioEqually();
                }

                //この時点では残りが一つの可能性もある。呼び出した側で適切に対処
                return(result);
            }
Ejemplo n.º 6
0
            //隣へ挿入
            public void InsertNext(IPane newpane)
            {
                _ratio /= 2;
                DivisionNode newnode = new DivisionNode(_parent, newpane, _ratio); //等分に

                newnode._next = _next;
                _next         = newnode;
            }
        public override Expression Visit(DivisionNode node)
        {
            var left  = Visit(node.Left);
            var right = Visit(node.Right);

            var term = new Term().Multiply(left);

            return(new Expression(term.Divide(right)));
        }
        private Value Division(DivisionNode exp)
        {
            try
            {
                Constant      left      = Eval(exp.Left).GetRValue();
                Constant      right     = Eval(exp.Right).GetRValue();
                Constant.Type leftType  = left.ConstantType;
                Constant.Type rightType = right.ConstantType;
                Constant.Type bt        = Max(leftType, rightType);
                switch (bt)
                {
                case Constant.Type.Complex:
                {
                    ComplexValue l = (ComplexValue)Convert(left, bt);
                    ComplexValue r = (ComplexValue)Convert(right, bt);
                    return(ComplexValue.OpDiv(l, r));
                }

                case Constant.Type.Int:
                {
                    IntValue l = (IntValue)Convert(left, bt);
                    IntValue r = (IntValue)Convert(right, bt);
                    return(IntValue.OpDiv(l, r));
                }

                case Constant.Type.Float:
                {
                    FloatValue l = (FloatValue)Convert(left, bt);
                    FloatValue r = (FloatValue)Convert(right, bt);
                    return(FloatValue.OpDiv(l, r));
                }
                }
                throw new ModelInterpreterException("Деление не определено для типа \"" + bt.ToString() + "\".")
                      {
                          Line     = exp.Line,
                          Position = exp.Position
                      };
            }
            catch (TypeConversionError exc)
            {
                throw new ModelInterpreterException($"Не удалось преобразование из \"{exc.Src}\" в \"{exc.Dst}\"")
                      {
                          Line     = exp.Line,
                          Position = exp.Position
                      };
            }
            catch (Exception exc)
            {
                throw new ModelInterpreterException(exc.Message)
                      {
                          Line     = exp.Line,
                          Position = exp.Position
                      };
            }
        }
Ejemplo n.º 9
0
        private object DivisionNode(DivisionNode dn)
        {
            var l = Evaluate(dn.l);
            var r = Evaluate(dn.r);

            if (l is decimal && r is decimal)
            {
                return((decimal)l / (decimal)r);
            }
            throw(new Exception($"Can't divide {l.GetType()} and {r.GetType()}"));
        }
Ejemplo n.º 10
0
            // nodeから末尾までで_ratioを合計する
            private static double SumRatio(DivisionNode node)
            {
                double sum = 0;

                while (node != null)
                {
                    sum += node._ratio;
                    node = node._next;
                }
                return(sum);
            }
Ejemplo n.º 11
0
            internal void Dispose()
            {
                _hostingControl.Dispose();
                DivisionNode node = _first;

                while (node != null)
                {
                    node.Dispose();
                    node = node.Next;
                }
            }
Ejemplo n.º 12
0
            //等分に分ける
            public void AdjustRatioEqually()
            {
                double       ratio = 1.0 / this.NodeCount;
                DivisionNode n     = _first;

                while (n != null)
                {
                    n.Ratio = ratio;
                    n       = n.Next;
                }
            }
Ejemplo n.º 13
0
            public DivisionNode FindPrevOf(DivisionNode target)
            {
                Debug.Assert(target != null);
                //Nextがtargetであるものを探す
                DivisionNode node = _first;

                while (node != null && node.Next != target)
                {
                    node = node.Next;
                }
                return(node);
            }
Ejemplo n.º 14
0
        //ペインの分割
        public SplitResult SplitPane(IPane target, IPane newpane, Direction direction)
        {
            Debug.Assert(newpane.AsDotNet().Parent == null);

            //分割可能かどうかのチェック1 総数
            if (_count >= _countLimit)
            {
                return(SplitResult.F_TooManyPanes);
            }

            //分割可能かどうかのチェック2 分割対象が最小サイズを満たしているか
            if (SizeToLength(target.Size, direction) < _minimumEdgeLength * 2 + PaneSplitter.SPLITTER_WIDTH)
            {
                return(SplitResult.F_TooSmallToSplit);
            }

            Control parent         = target.AsDotNet().Parent;
            bool    splitting_root = _rootList == null;

            if (splitting_root)   //空の状態からの構築
            {
                _rootList = new DivisionList(this, null, direction, target, newpane, target.Size, target.Dock);
                UIUtil.ReplaceControl(parent, target.AsDotNet(), _rootList.HostingControl);
            }
            else
            {
                DivisionNode node = _rootList.FirstNode.FindNode(target);
                Debug.Assert(node != null);
                if (direction == node.ParentList.Direction)   //同方向分割
                {
                    bool eq = node.ParentList.IsEquallyDivided;
                    node.InsertNext(newpane);
                    if (eq)
                    {
                        node.ParentList.AdjustRatioEqually();
                    }
                }
                else   //異方向分割
                {
                    DivisionList newlist = new DivisionList(this, node, direction, target, newpane, target.Size, target.Dock);
                    node.ReplacePaneByChildList(newlist);
                }
            }

            Rebuild();
            DoLayout();
            FindForm().MinimumSize = _rootList.FirstNode.RequiredMinimumSize; //!!TODO これはコントロールのサイズであり、フォームボーダーとは別の話

            _count++;
            return(SplitResult.Success);
        }
Ejemplo n.º 15
0
            //初期状態で2個作成
            public DivisionList(PaneDivision division, DivisionNode parent, Direction direction, IPane pane1, IPane pane2, Size host_size, DockStyle host_dock)
            {
                _parentDivision = division;
                _parentNode     = parent;
                _direction      = direction;

                pane1.Dock = DockStyle.Fill;
                pane2.Dock = _direction == Direction.TB ? DockStyle.Bottom : DockStyle.Right;
                _first     = new DivisionNode(this, pane1, 1.0);
                _first.InsertNext(pane2);

                _hostingControl      = new IntermediateContainer(division);
                _hostingControl.Size = host_size;
                _hostingControl.Dock = host_dock;
            }
Ejemplo n.º 16
0
        public void Visit_DivisionNode_EmitsCorrectCode()
        {
            // Arrange
            DivisionNode   divisionNode = new DivisionNode(DummySrcPos);
            IntegerLiteral left         = new IntegerLiteral("8", DummySrcPos);
            IntegerLiteral right        = new IntegerLiteral("2", DummySrcPos);

            divisionNode.Left  = left;
            divisionNode.Right = right;

            string expectedResult = "8 / 2";

            // Act
            string actualResult = CodeGenerator.Visit(divisionNode);

            // Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
Ejemplo n.º 17
0
            //splitterのMinSize, MinExtra設定
            public void AdjustSplitMinSize()
            {
                if (!this.IsPreLast)
                {
                    _next.AdjustSplitMinSize();
                }
                if (!this.IsLeaf)
                {
                    _childList.FirstNode.AdjustSplitMinSize();
                }

                //「次の次」が持っている現状の長さは、_splitterによって影響を受けることはないようにする。この長さに_nextの最小長さを足したものがMinSizeということになる
                DivisionNode nn            = _next._next;
                int          current_fixed = nn == null ? 0 : nn.TotalLength + PaneSplitter.SPLITTER_WIDTH;

                _splitter.MinSize  = current_fixed + _next.RequiredMinimumHostingLength;
                _splitter.MinExtra = this.RequiredMinimumHostingLength;
            }
Ejemplo n.º 18
0
            public int GetDivisionCount()
            {
                int          c = 0;
                DivisionNode n = _first;

                while (n != null)
                {
                    if (n.IsLeaf)
                    {
                        c++;
                    }
                    else
                    {
                        c += n.ChildList.GetDivisionCount();
                    }
                    n = n.Next;
                }
                return(c);
            }
Ejemplo n.º 19
0
            private void ReplaceNode(DivisionNode src, DivisionNode dest)
            {
                Debug.Assert(src.ParentList == this);
                dest.SetParentList(this);

                if (_first == src)
                {
                    _first = dest;
                }
                else
                {
                    DivisionNode n = _first;
                    while (n.Next != src)
                    {
                        n = n.Next;
                        Debug.Assert(n != null);
                    }
                    n.Next = dest;
                }
            }
Ejemplo n.º 20
0
        private DivisionNode CreateDivisionNodeList(DivisionList list, SplitFormat info, PaneCreationDelegate creation)
        {
            SplitFormat.Node tag       = info.FirstTag;
            DivisionNode     firstnode = null;
            DivisionNode     prev      = null;
            double           remain    = 1.0;

            while (tag != null)
            {
                DivisionNode node = null;

                if (tag.Content != null)
                {
                    DockStyle dock = tag.Next == null ? (info.Direction == Direction.TB ? DockStyle.Bottom : DockStyle.Right) : DockStyle.Fill;
                    node = new DivisionNode(list, CreateDivisionList(tag.Content, creation, dock), tag.GetActualRatio(remain));
                }
                else
                {
                    node = new DivisionNode(list, creation(tag.Label), tag.GetActualRatio(remain));
                }
                remain -= tag.Ratio;

                if (firstnode == null)
                {
                    firstnode = node;
                }
                else
                {
                    prev.Next = node;
                }

                Debug.Assert(node.ParentList == list);
                prev = node;
                tag  = tag.Next;
            }

            return(firstnode);
        }
Ejemplo n.º 21
0
            //srcの位置を、listの中身で置き換える。ratio調整に注意
            public void ReplaceNodeByList(DivisionNode src, DivisionList list)
            {
                Debug.Assert(src.ParentList == this);
                int    oldcount   = this.NodeCount;
                int    addedcount = list.NodeCount;
                double r          = src.Ratio;

                DivisionNode t    = list.FirstNode;
                DivisionNode last = null;

                while (t != null)
                {
                    t.Ratio *= r;
                    t.SetParentList(this);
                    last = t;
                    t    = t.Next;
                }
                Debug.Assert(last.Next == null); //これを見つけた
                ReplaceNode(src, list.FirstNode);
                last.Next = src.Next;

                Debug.Assert(oldcount + addedcount - 1 == this.NodeCount);
            }
Ejemplo n.º 22
0
            //子孫からターゲットを探す
            public DivisionNode FindNode(IPane t)
            {
                DivisionNode n = null;

                if (_pane != null && _pane.Equals(t))
                {
                    return(this); //structのこともあるのでEqualsを使う
                }
                if (_next != null)
                {
                    n = _next.FindNode(t);
                }
                if (n != null)
                {
                    return(n);
                }

                if (_childList != null)
                {
                    n = _childList.FirstNode.FindNode(t);
                }
                return(n);
            }
Ejemplo n.º 23
0
            public DivisionNode FindChildList(DivisionList list)
            {
                if (_childList != null && _childList == list)
                {
                    return(this);
                }

                DivisionNode n = null;

                if (_next != null)
                {
                    n = _next.FindChildList(list);
                }
                if (n != null)
                {
                    return(n);
                }

                if (_childList != null)
                {
                    n = _childList.FirstNode.FindChildList(list);
                }
                return(n);
            }
Ejemplo n.º 24
0
 /// <summary>
 /// 除算ノードの評価
 /// </summary>
 /// <param name="node">除算ノード</param>
 /// <returns>演算後の数値(Double)</returns>
 public override object Visit(DivisionNode node)
 {
     return((double)Visit(node.Left) / (double)Visit(node.Right));
 }
Ejemplo n.º 25
0
        private DivisionNode CreateDivisionNodeList(DivisionList list, SplitFormat info, PaneCreationDelegate creation)
        {
            SplitFormat.Node tag = info.FirstTag;
            DivisionNode firstnode = null;
            DivisionNode prev = null;
            double remain = 1.0;
            while (tag != null) {
                DivisionNode node = null;

                if (tag.Content != null) {
                    DockStyle dock = tag.Next == null ? (info.Direction == Direction.TB ? DockStyle.Bottom : DockStyle.Right) : DockStyle.Fill;
                    node = new DivisionNode(list, CreateDivisionList(tag.Content, creation, dock), tag.GetActualRatio(remain));
                }
                else {
                    node = new DivisionNode(list, creation(tag.Label), tag.GetActualRatio(remain));
                }
                remain -= tag.Ratio;

                if (firstnode == null)
                    firstnode = node;
                else
                    prev.Next = node;

                Debug.Assert(node.ParentList == list);
                prev = node;
                tag = tag.Next;
            }

            return firstnode;
        }
Ejemplo n.º 26
0
            //�m�[�h�̍폜�@����͂�₱�����̂Ńh�L�������g��Q��
            public DivisionNode Remove(DivisionNode target)
            {
                DivisionNode result;
                bool equally_divided = this.IsEquallyDivided;

                if (target == _first) {
                    result = _first.Next;
                    _first = result;
                }
                else {
                    DivisionNode node = FindPrevOf(target);
                    Debug.Assert(node != null);

                    node.Next = target.Next;
                    result = node;
                }

                result.HostingControl.Size = AddSize(result.HostingControl.Size, target.HostingControl.Size);
                result.Ratio += target.Ratio;

                if (equally_divided)
                    AdjustRatioEqually();

                //���̎��_�ł͎c�肪��‚̉”\�������B�Ăяo�������œK�؂ɑΏ�
                return result;
            }
 public override int Visit(DivisionNode node)
 => Visit(node.Left) / Visit(node.Right);
Ejemplo n.º 28
0
 public DivisionNode FindPrevOf(DivisionNode target)
 {
     Debug.Assert(target != null);
     //Next��target�ł����̂�T��
     DivisionNode node = _first;
     while (node != null && node.Next != target) {
         node = node.Next;
     }
     return node;
 }
Ejemplo n.º 29
0
        protected SyntaxNode buildSyntaxTree(List <ISyntaxUnit> postfixForm)
        {
            Queue <ISyntaxUnit> inputQueue   = new Queue <ISyntaxUnit>(postfixForm);
            Stack <SyntaxNode>  operandStack = new Stack <SyntaxNode>();

            while (inputQueue.Count > 0)
            {
                ISyntaxUnit input = inputQueue.Dequeue();
                if (input is Lexeme)
                {
                    Lexeme            token = input as Lexeme;
                    Lexeme.LexemeType ttype = token.Type;
                    if (properties.IsVariable(token.Value))
                    {
                        VariableIdentifierNode variable = new VariableIdentifierNode(token.Value);
                        operandStack.Push(variable);
                    }
                    else if (properties.IsConstant(token.Value))
                    {
                        double constantValue            = properties.getConstantValue(token.Value);
                        ConstantIdentifierNode constant = new ConstantIdentifierNode(token.Value, constantValue);
                        operandStack.Push(constant);
                    }
                    else if (properties.IsFunctionName(token.Value))
                    {
                        int nArguments = properties.getFunctionArgumentsCount(token.Value);
                        FunctionApplyNode.FunctionBody funcBody = properties.getFunctionDefinition(token.Value);
                        ArgumentListNode argumentList           = new ArgumentListNode();
                        try
                        {
                            for (int i = 0; i < nArguments; i++)
                            {
                                argumentList.addArgument(operandStack.Pop());
                            }
                        }
                        catch (InvalidOperationException ex)
                        {
                            throw new ParseException("Not enough operands on operand stack for function call.");
                        }

                        FunctionApplyNode functionCall = new FunctionApplyNode(argumentList, funcBody, token.Value);
                        operandStack.Push(functionCall);
                    }
                    else if (ttype == Lexeme.LexemeType.REAL_VALUE)
                    {
                        double value;
                        if (!double.TryParse(token.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                        {
                            throw new ParseException("Couldn't parse literal value: " + token.Value);
                        }
                        LiteralNode literal = new LiteralNode(value);
                        operandStack.Push(literal);
                    }
                    else if (ttype == Lexeme.LexemeType.OP_PLUS)
                    {
                        try
                        {
                            SyntaxNode   right    = operandStack.Pop();
                            SyntaxNode   left     = operandStack.Pop();
                            AdditionNode addition = new AdditionNode(left, right);
                            operandStack.Push(addition);
                        }
                        catch (InvalidOperationException ex)
                        {
                            throw new ParseException("Missing operand(s) for addition.");
                        }
                    }
                    else if (ttype == Lexeme.LexemeType.OP_MINUS)
                    {
                        try
                        {
                            SyntaxNode      right       = operandStack.Pop();
                            SyntaxNode      left        = operandStack.Pop();
                            SubtractionNode subtraction = new SubtractionNode(left, right);
                            operandStack.Push(subtraction);
                        }
                        catch (InvalidOperationException ex)
                        {
                            throw new ParseException("Missing operand(s) for subtraction.");
                        }
                    }
                    else if (ttype == Lexeme.LexemeType.OP_MUL)
                    {
                        try
                        {
                            SyntaxNode         right          = operandStack.Pop();
                            SyntaxNode         left           = operandStack.Pop();
                            MultiplicationNode multiplication = new MultiplicationNode(left, right);
                            operandStack.Push(multiplication);
                        }
                        catch (InvalidOperationException ex)
                        {
                            throw new ParseException("Missing operand(s) for multiplication.");
                        }
                    }
                    else if (ttype == Lexeme.LexemeType.OP_DIV)
                    {
                        try
                        {
                            SyntaxNode   right    = operandStack.Pop();
                            SyntaxNode   left     = operandStack.Pop();
                            DivisionNode division = new DivisionNode(left, right);
                            operandStack.Push(division);
                        }
                        catch (InvalidOperationException ex)
                        {
                            throw new ParseException("Missing operand(s) for division.");
                        }
                    }
                    else if (ttype == Lexeme.LexemeType.OP_POW)
                    {
                        try
                        {
                            SyntaxNode exponent = operandStack.Pop();
                            SyntaxNode baseNode = operandStack.Pop();
                            PowerNode  power    = new PowerNode(baseNode, exponent);
                            operandStack.Push(power);
                        }
                        catch (InvalidOperationException ex)
                        {
                            throw new ParseException("Missing operand(s) for exponentiation.");
                        }
                    }
                    else if (ttype == Lexeme.LexemeType.EQ_SIGN)
                    {
                        try
                        {
                            SyntaxNode right  = operandStack.Pop();
                            SyntaxNode left   = operandStack.Pop();
                            EqualsNode eqNode = new EqualsNode(left, right);
                            operandStack.Push(eqNode);
                        }
                        catch (InvalidOperationException ex)
                        {
                            throw new ParseException("Missing operand(s) for assignment.");
                        }
                    }
                    else if (ttype == Lexeme.LexemeType.OP_PLUS_UNARY)
                    {
                        try
                        {
                            SyntaxNode    child     = operandStack.Pop();
                            UnaryPlusNode unaryPlus = new UnaryPlusNode(child);
                            operandStack.Push(unaryPlus);
                        }
                        catch (InvalidOperationException ex)
                        {
                            throw new ParseException("Missing operand for unary plus.");
                        }
                    }
                    else if (ttype == Lexeme.LexemeType.OP_MINUS_UNARY)
                    {
                        try
                        {
                            SyntaxNode     child      = operandStack.Pop();
                            UnaryMinusNode unaryMinus = new UnaryMinusNode(child);
                            operandStack.Push(unaryMinus);
                        }
                        catch (InvalidOperationException ex)
                        {
                            throw new ParseException("Missing operand for unary minus.");
                        }
                    }
                    else
                    {
                        throw new ParseException("Unexpected token in postfix expression: " + token.simpleRepresentation());
                    }
                }
                else if (input is SyntaxNode)
                {
                    operandStack.Push(input as SyntaxNode);
                }
                else
                {
                    throw new ParseException("Unexpected object type in postfix expression.");
                }
            }

            if (operandStack.Count == 1)
            {
                return(operandStack.Pop());
            }
            else
            {
                throw new ParseException("Too many operands in postfix expression.");
            }
        }
Ejemplo n.º 30
0
            private void ReplaceNode(DivisionNode src, DivisionNode dest)
            {
                Debug.Assert(src.ParentList == this);
                dest.SetParentList(this);

                if (_first == src) {
                    _first = dest;
                }
                else {
                    DivisionNode n = _first;
                    while (n.Next != src) {
                        n = n.Next;
                        Debug.Assert(n != null);
                    }
                    n.Next = dest;
                }
            }
Ejemplo n.º 31
0
        //ペインを閉じて結合する。outの引数は次にフォーカスを与えるべきペイン
        public SplitResult UnifyPane(IPane target, out IPane nextfocus)
        {
            nextfocus = null; //失敗時にはクリアできるように
            Debug.Assert(_rootList != null);

            DivisionNode node          = _rootList.FirstNode.FindNode(target);
            bool         unifying_root = node.ParentList == _rootList && _rootList.NodeCount == 2; //結合の結果RootListが入れ替わる予定のとき
            Control      parent        = _rootList.HostingControl.Parent;

            if (unifying_root && _rootList.FirstNode.IsLast)
            {
                return(SplitResult.F_UnifySingle);
            }

            DivisionList list   = node.ParentList;
            DivisionNode active = list.Remove(node);

            if (list.NodeCount == 1) //こうなったときに面倒が発生
            {
                if (active.IsLeaf)   // (1) ペインであるとき
                {
                    IPane newpane = active.Pane;
                    Debug.Assert(newpane != null);
                    if (list.ParentNode == null)   //1-1
                    {
                        UIUtil.ReplaceControl(parent, list.HostingControl, newpane.AsDotNet());
                        _rootList = null;
                    }
                    else   //1-2
                    {
                        list.ParentNode.ReplaceChildListByPane(newpane);
                    }
                }
                else   // (2) ノードであるとき
                {
                    DivisionList newlist = active.ChildList;
                    if (list.ParentNode == null)   //2-1
                    {
                        _rootList = newlist;
                        newlist.ClearParentNode();
                        UIUtil.ReplaceControl(parent, list.HostingControl, newlist.HostingControl);
                    }
                    else                                              //2-2
                    {
                        DivisionList pp = list.ParentNode.ParentList; //長くなる方のリスト
                        Debug.Assert(pp.Direction == newlist.Direction);
                        pp.ReplaceNodeByList(list.ParentNode, newlist);
                    }
                }
            }

            if (_rootList != null)
            {
                Rebuild();
                DoLayout();
                FindForm().MinimumSize = _rootList.FirstNode.RequiredMinimumSize; //!!TODO Splitterだけで構成されていないフォームでアウト
            }

            _count--;
            nextfocus = active.IsLeaf ? active.Pane : active.ChildList.FirstPane;
            return(SplitResult.Success);
        }
Ejemplo n.º 32
0
            //ノードの削除 これはややこしいのでドキュメントも参照
            public DivisionNode Remove(DivisionNode target) {
                DivisionNode result;
                bool equally_divided = this.IsEquallyDivided;

                if (target == _first) {
                    result = _first.Next;
                    _first = result;
                }
                else {
                    DivisionNode node = FindPrevOf(target);
                    Debug.Assert(node != null);

                    node.Next = target.Next;
                    result = node;
                }

                result.HostingControl.Size = AddSize(result.HostingControl.Size, target.HostingControl.Size);
                result.Ratio += target.Ratio;

                if (equally_divided)
                    AdjustRatioEqually();

                //この時点では残りが一つの可能性もある。呼び出した側で適切に対処
                return result;
            }
Ejemplo n.º 33
0
 // node���疖���܂ł�_ratio����v����
 private static double SumRatio(DivisionNode node)
 {
     double sum = 0;
     while (node != null) {
         sum += node._ratio;
         node = node._next;
     }
     return sum;
 }
Ejemplo n.º 34
0
 //�ׂ֑}��
 public void InsertNext(IPane newpane)
 {
     _ratio /= 2;
     DivisionNode newnode = new DivisionNode(_parent, newpane, _ratio); //������
     newnode._next = _next;
     _next = newnode;
 }
Ejemplo n.º 35
0
            //src�̈ʒu��Alist�̒��g�Œu��������Bratio�����ɒ���
            public void ReplaceNodeByList(DivisionNode src, DivisionList list)
            {
                Debug.Assert(src.ParentList == this);
                int oldcount = this.NodeCount;
                int addedcount = list.NodeCount;
                double r = src.Ratio;

                DivisionNode t = list.FirstNode;
                DivisionNode last = null;
                while (t != null) {
                    t.Ratio *= r;
                    t.SetParentList(this);
                    last = t;
                    t = t.Next;
                }
                Debug.Assert(last.Next == null); //�������‚���
                ReplaceNode(src, list.FirstNode);
                last.Next = src.Next;

                Debug.Assert(oldcount + addedcount - 1 == this.NodeCount);
            }
Ejemplo n.º 36
0
        public BinaryExpressionNode ParseBinaryExpresssion(Token operatorToken, AstNode leftOperand, AstNode rightOperand)
        {
            BinaryExpressionNode expression = null;

            switch (operatorToken.Type)
            {
            case TokenType.Plus:
                expression = new AdditionNode(operatorToken.SourceLine);
                break;

            case TokenType.Minus:
                expression = new SubstractionNode(operatorToken.SourceLine);
                break;

            case TokenType.Asterisk:
                expression = new MultiplicationNode(operatorToken.SourceLine);
                break;

            case TokenType.Slash:
                expression = new DivisionNode(operatorToken.SourceLine);
                break;

            case TokenType.Equals:
                expression = new EqualsComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.NotEquals:
                expression = new NotEqualsComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.Less:
                expression = new LessComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.EqualsOrLess:
                expression = new EqualsOrLessComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.Greater:
                expression = new GreaterComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.EqualsOrGreater:
                expression = new EqualsOrGreaterComparisonNode(operatorToken.SourceLine);
                break;

            case TokenType.And:
                expression = new LogicalAndNode(operatorToken.SourceLine);
                break;

            case TokenType.Or:
                expression = new LogicalOrNode(operatorToken.SourceLine);
                break;

            default:
                throw new CompilerException($"`{MethodBase.GetCurrentMethod().Name}` called with a bad token. Expected a binary operator, token has type `{operatorToken.Type}` instead.");
            }
            expression.LeftOperand  = leftOperand;
            expression.RightOperand = rightOperand;
            return(expression);
        }
Ejemplo n.º 37
0
 public void ClearParentNode()
 {
     _parentNode = null;
 }
Ejemplo n.º 38
0
 public abstract T Visit(DivisionNode node);
Ejemplo n.º 39
0
            //������ԂłQ�쐬
            public DivisionList(PaneDivision division, DivisionNode parent, Direction direction, IPane pane1, IPane pane2, Size host_size, DockStyle host_dock)
            {
                _parentDivision = division;
                _parentNode = parent;
                _direction = direction;

                pane1.Dock = DockStyle.Fill;
                pane2.Dock = _direction == Direction.TB ? DockStyle.Bottom : DockStyle.Right;
                _first = new DivisionNode(this, pane1, 1.0);
                _first.InsertNext(pane2);

                _hostingControl = new IntermediateContainer(division);
                _hostingControl.Size = host_size;
                _hostingControl.Dock = host_dock;
            }
Ejemplo n.º 40
0
 public DivisionNode FindPrevOf(DivisionNode target) {
     Debug.Assert(target != null);
     //Nextがtargetであるものを探す
     DivisionNode node = _first;
     while (node != null && node.Next != target) {
         node = node.Next;
     }
     return node;
 }
Ejemplo n.º 41
0
 public void ClearParentNode()
 {
     _parentNode = null;
 }