Exemple #1
0
 void AddWriteTuple(TupleType tuple, StatementList statements, TypeNode referringType, Expression src, Identifier writer) {
   TypeNode singleton = UnwrapSingletonTuple(tuple, true);
   if (singleton != null && singleton == SystemTypes.String) {
     // special case which looks like mixed content.
     // happens a lot when XML Schema contains SimpleTypes that extend xsd:string.
     AddWriteSimpleType(singleton, statements, referringType, writer, src, null, null);
   } else {
     for (int i = 0, n = tuple.Members.Length; i < n; i++) {
       Member child = tuple.Members[i];          
       if (child is Field) {
         Field f = (Field)child;
         if (f.Type == null) continue; // type resolution error.
         // bugbug - what about [XmlElement] custom attributes?
         AddWriteMember(f, f.Name, statements, referringType, src, writer, true);
       }
     }
   }
 }
        /// <summary>
        /// update score table
        /// </summary>
        /// <param name="scoreTable"></param>
        /// <param name="col">columnIndex of new joined chess</param>
        /// <param name="row">rowIndex of new joined chess</param>
        private void UpdateScoreTable(ref IChessBoard chessBoard, Position pos,PieceTypeEnum pieceType)
        {
            //could not happen
            /*            if (chessBoard.GetPointState(pos.Col,pos.Row)!=PointStateEnum.Blank)
            {
                return;
            }
            */
            #region ---partial board

            //get all the 32 piece states surrounding this position
            ExtendedPointStateEnum[,] pointState=new ExtendedPointStateEnum[4,9];

            int row,col;
            //horizontal
            for (col = pos.Col - 4; col < pos.Col + 5;col++)
            {
                if (col<0||col>14)
                {
                    pointState[0,col-pos.Col+4]=ExtendedPointStateEnum.Virtual;
                }
                else
                {
                    pointState[0, col - pos.Col + 4] = (ExtendedPointStateEnum)chessBoard.GetPointState(pos.Row,col);
                }
            }
            //vertical
            for (row = pos.Row - 4; row < pos.Row + 5;row++ )
            {
                if (row<0||row>14)
                {
                    pointState[1, row - pos.Row + 4] = ExtendedPointStateEnum.Virtual;
                }
                else
                {
                    pointState[1, row - pos.Row + 4] = (ExtendedPointStateEnum)chessBoard.GetPointState(row,pos.Col);
                }
            }
            //backslash
            for (row = pos.Row - 4, col = pos.Col - 4; row < pos.Row + 5;row++,col++ )
            {
                if (row < 0 || row > 14 || col < 0 || col > 14)
                {
                    pointState[2, row - pos.Row + 4] = ExtendedPointStateEnum.Virtual;
                }
                else
                {
                    pointState[2, row - pos.Row + 4] = (ExtendedPointStateEnum)chessBoard.GetPointState(row, col);
                }
            }
            //slash
            for (row = pos.Row + 4, col = pos.Col - 4; row > pos.Row - 5; row--, col++)
            {
                if (row < 0 || row > 14 || col < 0 || col > 14)
                {
                    pointState[3, col - pos.Col + 4] = ExtendedPointStateEnum.Virtual;
                }
                else
                {
                    pointState[3, col - pos.Col + 4] = (ExtendedPointStateEnum)chessBoard.GetPointState(col, col);
                }
            }
            //assume the center of partial board is empty
            for (int m = 0; m < 4;m++ )
            {
                pointState[m, 4] = ExtendedPointStateEnum.Blank;
            }

            #endregion

            #region ---recognize formerTuples
            //recognize types of all the 20 Tuples .
            TupleType[,] formerTuples = new TupleType[4, 5];
            TupleType[,] changedTuples = new TupleType[4, 5];

            int white, black, blank;
            for (int i = 0; i < 4;i++ )
            {
                int start=0;
                int finish = 0;
                //deal with virtual tuples from front
                for (int j = 0; j < 4;j++ )
                {
                    if (pointState[i,j]==ExtendedPointStateEnum.Virtual)
                    {
                        changedTuples[i,j] = formerTuples[i, j] = TupleType.Virtual;
                    }
                    else
                    {
                        start = j;
                        break;//jump inner layer loop
                    }

                }
                //deal with virtual tuples from back
                for (int j = 8; j >= 5;j-- )
                {
                    if (pointState[i, j] == ExtendedPointStateEnum.Virtual)
                    {
                        changedTuples[i, j-4] = formerTuples[i, j - 4] = TupleType.Virtual;
                    }
                    else
                    {
                        finish = j;
                        break;//jump inner layer loop
                    }
                }

                white = black = blank = 0;
                //start recognize general tuples,deal with first four points
                for (int j = start; j <start+4;j++ )
                {
                    if (pointState[i, j] == ExtendedPointStateEnum.Blank)
                    {
                        blank++;
                    }
                    else if (pointState[i, j] == ExtendedPointStateEnum.Black)
                    {
                        black++;
                    }
                    else if (pointState[i, j] == ExtendedPointStateEnum.White)
                    {
                        white++;
                    }
                }
                //tuples recognition sliding
                for (int j = start + 4; j <= finish;j++ )
                {
                    if (pointState[i, j] == ExtendedPointStateEnum.Blank)
                    {
                        blank++;
                    }
                    else if (pointState[i, j] == ExtendedPointStateEnum.Black)
                    {
                        black++;
                    }
                    else if (pointState[i, j] == ExtendedPointStateEnum.White)
                    {
                        white++;
                    }
                    //deal with formerTuples
                    if (black > 0 && white > 0)
                    {
                        formerTuples[i, j - 4] = TupleType.Polluted;
                    }
                    else if (black == 0 && white == 0)
                    {
                        formerTuples[i, j - 4] = TupleType.Blank;
                    }
                    else if (black == 0)
                    {
                        formerTuples[i, j - 4] = (TupleType)(white + 4);
                    }
                    else
                    {
                        formerTuples[i, j - 4] = (TupleType)black;
                    }
                    //deal with changedTuples,increase for change
                    if (pieceType==PieceTypeEnum.Black)
                    {
                        black++;
                    }
                    else
                    {
                        white++;
                    }
                    //recognize
                    if (black > 0 && white > 0)
                    {
                        changedTuples[i, j - 4] = TupleType.Polluted;
                    }
                    else if (black == 0 && white == 0)
                    {
                        changedTuples[i, j - 4] = TupleType.Blank;
                    }
                    else if (black == 0)
                    {
                        changedTuples[i, j - 4] = (TupleType)(white + 4);
                    }
                    else
                    {
                        changedTuples[i, j - 4] = (TupleType)black;
                    }
                    //deal with changedTuples,decrease
                    if (pieceType == PieceTypeEnum.Black)
                    {
                        black--;
                    }
                    else
                    {
                        white--;
                    }

                    //slide to next tuple ,so the first of current tuple should be dropped
                    if (pointState[i, j-4] == ExtendedPointStateEnum.Blank)
                    {
                        blank--;
                    }
                    else if (pointState[i, j-4] == ExtendedPointStateEnum.Black)
                    {
                        black--;
                    }
                    else if (pointState[i, j-4] == ExtendedPointStateEnum.White)
                    {
                        white--;
                    }
                }
            }
            #endregion

            #region ---update scores of correlative points

            //score changed caused by this chess
            int[,] changedScore = new int[4, 5];
            for (int i = 0; i < 4;i++ )
            {
                for (int j = 0; j < 5;j++ )
                {
                    int score=tupleScoreTable[(int)changedTuples[i,j]]-tupleScoreTable[(int)formerTuples[i,j]];
                    changedScore[i, j] = score;
                }
            }

            //internal calculation
            int[,] changedScoreSum = new int[4, 9];
            for (int i = 0; i < 4;i++ )
            {
                for (int j = 0; j < 4;j++ )
                {
                    int sum=0;
                    for (int m=0;m<=j;m++)
                    {
                        sum+=changedScore[i,m];
                    }
                    changedScoreSum[i,j]=sum;
                }
                for (int j = 8; j > 4;j-- )
                {
                    int sum = 0;
                    for (int m=8;m>=j;m--)
                    {
                        sum += changedScore[i, m-4];
                    }
                    changedScoreSum[i, j] = sum;
                }
            }
            //update center point,occupied point's score is 0
            scoreTable[pos.Col, pos.Row] = 0;
            //update general points
            //horizontal
            for (col = (pos.Col >= 4?pos.Col-4:0);
                col <= (pos.Col <=10?pos.Col+4:14);
                col++)
            {
                if (scoreTable[col,pos.Row]!=0)//not occupied
                {
                    scoreTable[col, pos.Row] += changedScoreSum[0, col - pos.Col + 4];
                    if (scoreTable[col, pos.Row] < 0)
                    {
                        scoreTable[col, pos.Row] = 0;
                    }
                }
            }
            //vertical
            for (row = (pos.Row >= 4 ? pos.Row - 4 : 0);
                row <= (pos.Row <= 10 ? pos.Row + 4 : 14);
                row++)
            {
                if (scoreTable[pos.Col, row] != 0)//not occupied
                {
                    scoreTable[pos.Col, row] += changedScoreSum[1, row - pos.Row + 4];
                    if (scoreTable[pos.Col, row] < 0)
                    {
                        scoreTable[pos.Col, row] = 0;
                    }
                }
            }
            //backslash
            for (col = (pos.Col >= 4 ? pos.Col - 4 : 0),
                row = (pos.Row >= 4 ? pos.Row - 4 : 0);
                col <= (pos.Col <= 10 ? pos.Col + 4 : 14) &&
                row <= (pos.Row <= 10 ? pos.Row + 4 : 14);
                col++,row++)
            {
                if (scoreTable[col, row] != 0)//not occupied
                {
                    scoreTable[col, row] += changedScoreSum[2, row - pos.Row + 4];
                    if (scoreTable[col, row]<0)
                    {
                        scoreTable[col, row] = 0;
                    }
                }
            }
            //slash
            for (col = (pos.Col >= 4 ? pos.Col - 4 : 0),
                row = (pos.Row <= 10 ? pos.Row + 4 : 14);
                col <= (pos.Col <= 10 ? pos.Col + 4 : 14) &&
                row >= (pos.Row >= 4 ? pos.Row - 4 : 0);
                col++, row--)
            {
                if (scoreTable[col, row] != 0)//not occupied
                {
                    scoreTable[col, row] += changedScoreSum[3, col - pos.Col + 4];
                    if (scoreTable[col, row] < 0)
                    {
                        scoreTable[col, row] = 0;
                    }
                }
            }

            #endregion
        }
 public virtual Differences VisitTupleType(TupleType tuple1, TupleType tuple2){
   return this.VisitTypeNode(tuple1, tuple2);
 }
Exemple #4
0
 public virtual void VisitTupleType(TupleType tuple){
   this.VisitTypeNode(tuple);
 }
 protected AbstractConditionItem(string name, MatchMode matchMode, TupleType tupleType)
 {
     Name = name;
     MatchMode = matchMode;
     TupleType = tupleType;
 }
Exemple #6
0
 public override IEntity VisitNamedType(INamedTypeSymbol type) =>
 type.IsTupleType ? TupleType.Create(cx, type) : (IEntity)NamedType.Create(cx, type);
Exemple #7
0
 private TupleType Register(TupleType tuple)
 {
     tuple.Table.addSuper(analyzer.Builtins.BaseTuple.Table);
     tuple.Table.Path = analyzer.Builtins.BaseTuple.Table.Path;
     return tuple;
 }
Exemple #8
0
        public ChessBoardPoint GetNextStep(IChessBoard chessBoard, PieceTypeEnum pieceType, int stepIndex, PlayStep?prevStep)
        {
            int[] tupleScoreTable = new int[11] {
                7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            //initialize tuple score table
            if (stepIndex % 2 == 0)//even step is first hand,i.e. the black side
            {
                if (stepIndex == 0)
                {
                    return(ChessBoardPoint.TENGEN);
                }
                tupleScoreTable[1] = 35;
                tupleScoreTable[2] = 800;
                tupleScoreTable[3] = 15000;
                tupleScoreTable[4] = 800000;
                tupleScoreTable[5] = 15;
                tupleScoreTable[6] = 400;
                tupleScoreTable[7] = 1800;
                tupleScoreTable[8] = 100000;
            }
            else//odd step is back hand,i.e. the white side
            {
                tupleScoreTable[1] = 15;
                tupleScoreTable[2] = 400;
                tupleScoreTable[3] = 1800;
                tupleScoreTable[4] = 100000;
                tupleScoreTable[5] = 35;
                tupleScoreTable[6] = 800;
                tupleScoreTable[7] = 15000;
                tupleScoreTable[8] = 800000;
            }

            //extended board,with virtual points
            ExtendedPointStateEnum[,] exPointStates = new ExtendedPointStateEnum[23, 23];
            for (int row = 0; row < 23; row++)
            {
                for (int col = 0; col < 23; col++)
                {
                    if (row < 4 || row > 18 || col < 4 || col > 18)
                    {
                        exPointStates[row, col] = ExtendedPointStateEnum.Virtual;
                    }
                    else
                    {
                        exPointStates[row, col] = (ExtendedPointStateEnum)chessBoard.GetPointState(14 - (row - 4), col - 4);
                    }
                }
            }

            int[,] scoreTable = new int[15, 15];

            /// <summary>calculate type of every tuple</summary>
            /// <description>In order to give a clear train of thought,
            /// I used an intuitionistic method to do this work.
            /// But this results in not efficient.
            /// Every tuple is calculated for twice.
            /// But it's easy to modify it:two ends of a tuple own the same tuple
            /// I'll modify it in next version ,where efficiency becomes bottleneck.
            /// </description>
            //every point indexs 8 tuples around it
            TupleType[, ,] tupleTable = new TupleType[15, 15, 8];
            for (int row = 4; row < 19; row++)
            {
                for (int col = 4; col < 19; col++)
                {
                    int[] white = new int[8]; //white points in a tuple
                    int[] black = new int[8]; //black points in a tuple
                    #region ---check tuples of every direction
                    //left ,index 0
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 0] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[0]++;
                        }
                        else if (exPointStates[row, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[0]++;
                        }
                    }
                    //top left,index 1
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 1] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[1]++;
                        }
                        else if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[1]++;
                        }
                    }
                    //up ,index 2
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 2] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col] == ExtendedPointStateEnum.Black)
                        {
                            black[2]++;
                        }
                        else if (exPointStates[row - i, col] == ExtendedPointStateEnum.White)
                        {
                            white[2]++;
                        }
                    }
                    //top right,index 3
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 3] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[3]++;
                        }
                        else if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[3]++;
                        }
                    }
                    //right,index 4
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 4] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[4]++;
                        }
                        else if (exPointStates[row, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[4]++;
                        }
                    }
                    //bottom right,index 5
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 5] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[5]++;
                        }
                        else if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[5]++;
                        }
                    }
                    //bottom,index 6
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 6] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col] == ExtendedPointStateEnum.Black)
                        {
                            black[6]++;
                        }
                        else if (exPointStates[row + i, col] == ExtendedPointStateEnum.White)
                        {
                            white[6]++;
                        }
                    }
                    //bottom left,index 7
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 7] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[7]++;
                        }
                        else if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[7]++;
                        }
                    }
                    #endregion //check tuples of every direction

                    //decide tuple type
                    for (int i = 0; i < 8; i++)
                    {
                        //already assigned
                        if (tupleTable[row - 4, col - 4, i] == TupleType.Virtual)
                        {
                            continue;
                        }
                        if (white[i] > 0 && black[i] > 0)
                        {
                            tupleTable[row - 4, col - 4, i] = TupleType.Polluted;
                        }
                        else if (white[i] == 0 && black[i] == 0)
                        {
                            tupleTable[row - 4, col - 4, i] = TupleType.Blank;
                        }
                        else if (white[i] == 0)
                        {
                            tupleTable[row - 4, col - 4, i] = (TupleType)black[i];
                        }
                        else
                        {
                            tupleTable[row - 4, col - 4, i] = (TupleType)(white[i] + 4);
                        }
                    }
                }
            }
            #region ---scoreTable calculate
            //calculate score table . using symmetry
            //top left corner
            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row >= m)//top right
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col + m, 7]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col, 2]];     //bottom
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col + m, 1]]; //bottom right
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col + m, 0]];     //right
                    }
                }
            }
            //top right corner
            for (int row = 0; row < 8; row++)
            {
                for (int col = 8; col < 15; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row >= m)//top left
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col - m, 5]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col, 2]];     //bottom
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col - m, 3]]; //bottom left
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col - m, 4]];     //left
                    }
                }
            }
            //bottom left corner
            for (int row = 8; row < 15; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row + m < 15)//bottom right
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col + m, 1]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col, 6]];     //top
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col + m, 7]]; //top right
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col + m, 0]];     //right
                    }
                }
            }
            //bottom right corner
            for (int row = 8; row < 15; row++)
            {
                for (int col = 8; col < 15; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row + m < 15)//bottom left
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col - m, 3]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col, 6]];     //top
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col - m, 5]]; //top left
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col - m, 4]];     //left
                    }
                }
            }
            #endregion             //scoreTable

            //select best position
            List <Position> bestList = new List <Position>();

            //select first valid point
            Position first = new Position(0, 0);
            //all the point is forbidden.connot happen
            //while (IsFobidden(first))
            //{
            //    while (IsFobidden(first))
            //    {
            //        if (first.Col<14)
            //        {
            //            first.Col++;
            //        }
            //        else
            //        {
            //            break;
            //        }
            //    }
            //    if (first.Row<14)
            //    {
            //        first.Row++;
            //    }
            //    else
            //    {
            //        break;
            //    }
            //}
            while (IsFobidden(ref chessBoard, first, pieceType))
            {
                if (first.Col < 14)
                {
                    first.Col++;
                }
                else if (first.Row < 14)
                {
                    first.Row++;
                    first.Col = 0;
                }
                else
                {
                    return(new ChessBoardPoint(-1, -1));
                }
            }
            bestList.Add(first);

            Referee checkWin = new Referee();
            //select best points
            for (int row = 0; row < 15; row++)
            {
                for (int col = 0; col < 15; col++)
                {
                    if (scoreTable[row, col] > scoreTable[bestList[0].Row, bestList[0].Col])
                    {
                        Position best = new Position(row, col);
                        if (!IsFobidden(ref chessBoard, best, pieceType))
                        {
                            bestList.Clear();
                            bestList.Add(best);
                        }
                    }
                    else if (scoreTable[row, col] == scoreTable[bestList[0].Row, bestList[0].Col])
                    {
                        Position best = new Position(row, col);
                        if (!IsFobidden(ref chessBoard, best, pieceType))
                        {
                            bestList.Add(best);
                        }
                    }
                }
            }
            //there is no best .connot happen
            if (bestList.Count == 0)
            {
                return(new ChessBoardPoint(-1, -1));
            }
            Position ret = bestList[(new Random()).Next(bestList.Count)];
            return(new ChessBoardPoint(14 - ret.Row, ret.Col));
        }
Exemple #9
0
        public void CommonSuperTypeTest()
        {
            TypesTable             typesTable = new TypesTable();
            StandardLibraryCreator sl         = new StandardLibraryCreator();

            sl.CreateStandardLibrary(typesTable);

            Classifier integerType = typesTable.Library.Integer;
            Classifier realType    = typesTable.Library.Real;
            Classifier anyType     = typesTable.Library.Any;


            Classifier unlimitedType = typesTable.Library.UnlimitedNatural;
            Classifier stringType    = typesTable.Library.String;



            Assert.AreEqual(integerType.CommonSuperType(realType), realType);         //real,integer -> real
            Assert.AreEqual(realType.CommonSuperType(realType), realType);            //real,real -> real
            Assert.AreEqual(realType.CommonSuperType(integerType), realType);         //integer,real -> real
            Assert.AreEqual(unlimitedType.CommonSuperType(realType), realType);       //unlimited,real -> real
            Assert.AreEqual(integerType.CommonSuperType(unlimitedType), integerType); //integer,unlimited -> integer
            Assert.AreEqual(stringType.CommonSuperType(integerType), anyType);        // string,integer -> anytype


            //Collection
            BagType        bagIntegerType  = (BagType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);
            BagType        bagRealType     = (BagType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, realType);
            SetType        setType         = (SetType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Set, integerType);
            SequenceType   seqType         = (SequenceType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Sequence, integerType);
            OrderedSetType ordType         = (OrderedSetType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.OrderedSet, integerType);
            CollectionType collIntegerType = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Collection, integerType);
            CollectionType collRealType    = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Collection, realType);;


            Assert.AreEqual(setType.CommonSuperType(setType), setType);                         //set(integer),set(integer) -> set(integer)
            Assert.AreEqual(setType.CommonSuperType(ordType), collIntegerType);                 //set(integer),ord(integer) -> coll(integer)
            Assert.AreEqual(setType.CommonSuperType(collIntegerType), collIntegerType);         //set(integer),coll(Integer) -> coll(integer)
            Assert.AreEqual(collIntegerType.CommonSuperType(collIntegerType), collIntegerType); //coll(integer),coll(integer) -> coll(integer)
            Assert.AreEqual(collIntegerType.CommonSuperType(bagIntegerType), collIntegerType);  //coll(integer),bag(integer) -> coll(integer)
            Assert.AreEqual(collIntegerType.CommonSuperType(bagRealType), collRealType);        // coll(Integer),bag(real) -> coll(real)
            Assert.AreEqual(setType.CommonSuperType(bagRealType), collRealType);                // set(integer),bag(real) ->col(real)
            Assert.AreEqual(ordType.CommonSuperType(ordType), ordType);                         // ord(integer),ord(integer) -> ord(integer)
            Assert.AreEqual(seqType.CommonSuperType(seqType), seqType);                         // seq(integer),seq(integer) -> seq(integer)

            Assert.AreEqual(setType.CommonSuperType(realType), anyType);                        //set(integer),real -> any

            //void test
            Classifier voidType = typesTable.Library.Void;

            Assert.AreEqual(voidType.CommonSuperType(integerType), integerType);
            Assert.AreEqual(realType.CommonSuperType(voidType), realType);
            Assert.AreEqual(voidType.CommonSuperType(seqType), seqType);
            Assert.AreEqual(collIntegerType.CommonSuperType(voidType), collIntegerType);
            Assert.AreEqual(voidType.CommonSuperType(anyType), anyType);

            //any test
            Assert.AreEqual(integerType.CommonSuperType(anyType), anyType);
            Assert.AreEqual(anyType.CommonSuperType(stringType), anyType);
            Assert.AreEqual(anyType.CommonSuperType(setType), anyType);
            Assert.AreEqual(setType.CommonSuperType(anyType), anyType);

            //tuple test
            List <Property> tupleParts1 = new List <Property>();

            tupleParts1.Add(new Property("prop1", PropertyType.Many, integerType));
            tupleParts1.Add(new Property("prop2", PropertyType.Many, integerType));
            tupleParts1.Add(new Property("prop3", PropertyType.Many, realType));
            TupleType tuple1 = new TupleType(typesTable, tupleParts1);


            typesTable.RegisterType(tuple1);

            List <Property> tupleParts2 = new List <Property>();

            tupleParts2.Add(new Property("prop1", PropertyType.Many, integerType));
            tupleParts2.Add(new Property("prop4", PropertyType.Many, integerType));
            tupleParts2.Add(new Property("prop3", PropertyType.One, anyType));
            TupleType tuple2 = new TupleType(typesTable, tupleParts2);


            typesTable.RegisterType(tuple2);

            TupleType tupleCommon = (TupleType)tuple1.CommonSuperType(tuple2);

            Assert.AreEqual(tupleCommon.TupleParts.Count, 2);
            Assert.AreEqual(tupleCommon["prop1"].PropertyType, tuple1["prop1"].PropertyType);
            Assert.AreEqual(tupleCommon["prop1"].Type, tuple1["prop1"].Type);


            Assert.AreEqual(tupleCommon["prop3"].PropertyType, tuple1["prop3"].PropertyType);
            Assert.AreEqual(tupleCommon["prop3"].Type, tuple2["prop3"].Type);

            Assert.AreEqual(tuple1.CommonSuperType(voidType), tuple1);
            Assert.AreEqual(tuple1.CommonSuperType(anyType), anyType);

            Assert.AreEqual(voidType.CommonSuperType(tuple1), tuple1);
            Assert.AreEqual(anyType.CommonSuperType(tuple1), anyType);

            Assert.AreEqual(tuple2.CommonSuperType(integerType), anyType);
            Assert.AreEqual(realType.CommonSuperType(tuple2), anyType);
        }
Exemple #10
0
        public static Doc Print(SyntaxNode syntaxNode)
        {
            if (syntaxNode == null)
            {
                return(Doc.Null);
            }

            // TODO 0 kill? runtime repo has files that will fail on deep recursion
            if (depth > 200)
            {
                throw new InTooDeepException();
            }

            depth++;
            try
            {
                switch (syntaxNode)
                {
                case AliasQualifiedNameSyntax aliasQualifiedNameSyntax:
                    return(AliasQualifiedName.Print(aliasQualifiedNameSyntax));

                case AnonymousMethodExpressionSyntax anonymousMethodExpressionSyntax:
                    return(AnonymousMethodExpression.Print(anonymousMethodExpressionSyntax));

                case AnonymousObjectCreationExpressionSyntax anonymousObjectCreationExpressionSyntax:
                    return(AnonymousObjectCreationExpression.Print(
                               anonymousObjectCreationExpressionSyntax
                               ));

                case AnonymousObjectMemberDeclaratorSyntax anonymousObjectMemberDeclaratorSyntax:
                    return(AnonymousObjectMemberDeclarator.Print(
                               anonymousObjectMemberDeclaratorSyntax
                               ));

                case ArgumentListSyntax argumentListSyntax:
                    return(ArgumentList.Print(argumentListSyntax));

                case ArgumentSyntax argumentSyntax:
                    return(Argument.Print(argumentSyntax));

                case ArrayCreationExpressionSyntax arrayCreationExpressionSyntax:
                    return(ArrayCreationExpression.Print(arrayCreationExpressionSyntax));

                case ArrayRankSpecifierSyntax arrayRankSpecifierSyntax:
                    return(ArrayRankSpecifier.Print(arrayRankSpecifierSyntax));

                case ArrayTypeSyntax arrayTypeSyntax:
                    return(ArrayType.Print(arrayTypeSyntax));

                case ArrowExpressionClauseSyntax arrowExpressionClauseSyntax:
                    return(ArrowExpressionClause.Print(arrowExpressionClauseSyntax));

                case AssignmentExpressionSyntax assignmentExpressionSyntax:
                    return(AssignmentExpression.Print(assignmentExpressionSyntax));

                case AttributeListSyntax attributeListSyntax:
                    return(AttributeList.Print(attributeListSyntax));

                case AwaitExpressionSyntax awaitExpressionSyntax:
                    return(AwaitExpression.Print(awaitExpressionSyntax));

                case BaseExpressionSyntax baseExpressionSyntax:
                    return(BaseExpression.Print(baseExpressionSyntax));

                case BaseFieldDeclarationSyntax baseFieldDeclarationSyntax:
                    return(BaseFieldDeclaration.Print(baseFieldDeclarationSyntax));

                case BaseListSyntax baseListSyntax:
                    return(BaseList.Print(baseListSyntax));

                case BaseMethodDeclarationSyntax baseMethodDeclarationSyntax:
                    return(BaseMethodDeclaration.Print(baseMethodDeclarationSyntax));

                case BasePropertyDeclarationSyntax basePropertyDeclarationSyntax:
                    return(BasePropertyDeclaration.Print(basePropertyDeclarationSyntax));

                case BaseTypeDeclarationSyntax baseTypeDeclarationSyntax:
                    return(BaseTypeDeclaration.Print(baseTypeDeclarationSyntax));

                case BinaryExpressionSyntax binaryExpressionSyntax:
                    return(BinaryExpression.Print(binaryExpressionSyntax));

                case BinaryPatternSyntax binaryPatternSyntax:
                    return(BinaryPattern.Print(binaryPatternSyntax));

                case BlockSyntax blockSyntax:
                    return(Block.Print(blockSyntax));

                case BracketedArgumentListSyntax bracketedArgumentListSyntax:
                    return(BracketedArgumentList.Print(bracketedArgumentListSyntax));

                case BracketedParameterListSyntax bracketedParameterListSyntax:
                    return(BracketedParameterList.Print(bracketedParameterListSyntax));

                case BreakStatementSyntax breakStatementSyntax:
                    return(BreakStatement.Print(breakStatementSyntax));

                case CasePatternSwitchLabelSyntax casePatternSwitchLabelSyntax:
                    return(CasePatternSwitchLabel.Print(casePatternSwitchLabelSyntax));

                case CaseSwitchLabelSyntax caseSwitchLabelSyntax:
                    return(CaseSwitchLabel.Print(caseSwitchLabelSyntax));

                case CastExpressionSyntax castExpressionSyntax:
                    return(CastExpression.Print(castExpressionSyntax));

                case CatchClauseSyntax catchClauseSyntax:
                    return(CatchClause.Print(catchClauseSyntax));

                case CheckedExpressionSyntax checkedExpressionSyntax:
                    return(CheckedExpression.Print(checkedExpressionSyntax));

                case CheckedStatementSyntax checkedStatementSyntax:
                    return(CheckedStatement.Print(checkedStatementSyntax));

                case ClassOrStructConstraintSyntax classOrStructConstraintSyntax:
                    return(ClassOrStructConstraint.Print(classOrStructConstraintSyntax));

                case CompilationUnitSyntax compilationUnitSyntax:
                    return(CompilationUnit.Print(compilationUnitSyntax));

                case ConditionalAccessExpressionSyntax conditionalAccessExpressionSyntax:
                    return(ConditionalAccessExpression.Print(conditionalAccessExpressionSyntax));

                case ConditionalExpressionSyntax conditionalExpressionSyntax:
                    return(ConditionalExpression.Print(conditionalExpressionSyntax));

                case ConstantPatternSyntax constantPatternSyntax:
                    return(ConstantPattern.Print(constantPatternSyntax));

                case ConstructorConstraintSyntax constructorConstraintSyntax:
                    return(ConstructorConstraint.Print(constructorConstraintSyntax));

                case ConstructorInitializerSyntax constructorInitializerSyntax:
                    return(ConstructorInitializer.Print(constructorInitializerSyntax));

                case ContinueStatementSyntax continueStatementSyntax:
                    return(ContinueStatement.Print(continueStatementSyntax));

                case DeclarationExpressionSyntax declarationExpressionSyntax:
                    return(DeclarationExpression.Print(declarationExpressionSyntax));

                case DeclarationPatternSyntax declarationPatternSyntax:
                    return(DeclarationPattern.Print(declarationPatternSyntax));

                case DefaultConstraintSyntax defaultConstraintSyntax:
                    return(DefaultConstraint.Print(defaultConstraintSyntax));

                case DefaultExpressionSyntax defaultExpressionSyntax:
                    return(DefaultExpression.Print(defaultExpressionSyntax));

                case DefaultSwitchLabelSyntax defaultSwitchLabelSyntax:
                    return(DefaultSwitchLabel.Print(defaultSwitchLabelSyntax));

                case DelegateDeclarationSyntax delegateDeclarationSyntax:
                    return(DelegateDeclaration.Print(delegateDeclarationSyntax));

                case DiscardDesignationSyntax discardDesignationSyntax:
                    return(DiscardDesignation.Print(discardDesignationSyntax));

                case DiscardPatternSyntax discardPatternSyntax:
                    return(DiscardPattern.Print(discardPatternSyntax));

                case DoStatementSyntax doStatementSyntax:
                    return(DoStatement.Print(doStatementSyntax));

                case ElementAccessExpressionSyntax elementAccessExpressionSyntax:
                    return(ElementAccessExpression.Print(elementAccessExpressionSyntax));

                case ElementBindingExpressionSyntax elementBindingExpressionSyntax:
                    return(ElementBindingExpression.Print(elementBindingExpressionSyntax));

                case ElseClauseSyntax elseClauseSyntax:
                    return(ElseClause.Print(elseClauseSyntax));

                case EmptyStatementSyntax emptyStatementSyntax:
                    return(EmptyStatement.Print(emptyStatementSyntax));

                case EnumMemberDeclarationSyntax enumMemberDeclarationSyntax:
                    return(EnumMemberDeclaration.Print(enumMemberDeclarationSyntax));

                case EqualsValueClauseSyntax equalsValueClauseSyntax:
                    return(EqualsValueClause.Print(equalsValueClauseSyntax));

                case ExpressionStatementSyntax expressionStatementSyntax:
                    return(ExpressionStatement.Print(expressionStatementSyntax));

                case ExternAliasDirectiveSyntax externAliasDirectiveSyntax:
                    return(ExternAliasDirective.Print(externAliasDirectiveSyntax));

                case FinallyClauseSyntax finallyClauseSyntax:
                    return(FinallyClause.Print(finallyClauseSyntax));

                case FixedStatementSyntax fixedStatementSyntax:
                    return(FixedStatement.Print(fixedStatementSyntax));

                case ForEachStatementSyntax forEachStatementSyntax:
                    return(ForEachStatement.Print(forEachStatementSyntax));

                case ForEachVariableStatementSyntax forEachVariableStatementSyntax:
                    return(ForEachVariableStatement.Print(forEachVariableStatementSyntax));

                case ForStatementSyntax forStatementSyntax:
                    return(ForStatement.Print(forStatementSyntax));

                case FromClauseSyntax fromClauseSyntax:
                    return(FromClause.Print(fromClauseSyntax));

                case FunctionPointerTypeSyntax functionPointerTypeSyntax:
                    return(FunctionPointerType.Print(functionPointerTypeSyntax));

                case GenericNameSyntax genericNameSyntax:
                    return(GenericName.Print(genericNameSyntax));

                case GlobalStatementSyntax globalStatementSyntax:
                    return(GlobalStatement.Print(globalStatementSyntax));

                case GotoStatementSyntax gotoStatementSyntax:
                    return(GotoStatement.Print(gotoStatementSyntax));

                case GroupClauseSyntax groupClauseSyntax:
                    return(GroupClause.Print(groupClauseSyntax));

                case IdentifierNameSyntax identifierNameSyntax:
                    return(IdentifierName.Print(identifierNameSyntax));

                case IfStatementSyntax ifStatementSyntax:
                    return(IfStatement.Print(ifStatementSyntax));

                case ImplicitArrayCreationExpressionSyntax implicitArrayCreationExpressionSyntax:
                    return(ImplicitArrayCreationExpression.Print(
                               implicitArrayCreationExpressionSyntax
                               ));

                case ImplicitElementAccessSyntax implicitElementAccessSyntax:
                    return(ImplicitElementAccess.Print(implicitElementAccessSyntax));

                case ImplicitObjectCreationExpressionSyntax implicitObjectCreationExpressionSyntax:
                    return(ImplicitObjectCreationExpression.Print(
                               implicitObjectCreationExpressionSyntax
                               ));

                case ImplicitStackAllocArrayCreationExpressionSyntax implicitStackAllocArrayCreationExpressionSyntax:
                    return(ImplicitStackAllocArrayCreationExpression.Print(
                               implicitStackAllocArrayCreationExpressionSyntax
                               ));

                case IncompleteMemberSyntax incompleteMemberSyntax:
                    return(IncompleteMember.Print(incompleteMemberSyntax));

                case InitializerExpressionSyntax initializerExpressionSyntax:
                    return(InitializerExpression.Print(initializerExpressionSyntax));

                case InterpolatedStringExpressionSyntax interpolatedStringExpressionSyntax:
                    return(InterpolatedStringExpression.Print(
                               interpolatedStringExpressionSyntax
                               ));

                case InterpolatedStringTextSyntax interpolatedStringTextSyntax:
                    return(InterpolatedStringText.Print(interpolatedStringTextSyntax));

                case InterpolationSyntax interpolationSyntax:
                    return(Interpolation.Print(interpolationSyntax));

                case InvocationExpressionSyntax invocationExpressionSyntax:
                    return(InvocationExpression.Print(invocationExpressionSyntax));

                case IsPatternExpressionSyntax isPatternExpressionSyntax:
                    return(IsPatternExpression.Print(isPatternExpressionSyntax));

                case JoinClauseSyntax joinClauseSyntax:
                    return(JoinClause.Print(joinClauseSyntax));

                case LabeledStatementSyntax labeledStatementSyntax:
                    return(LabeledStatement.Print(labeledStatementSyntax));

                case LetClauseSyntax letClauseSyntax:
                    return(LetClause.Print(letClauseSyntax));

                case LiteralExpressionSyntax literalExpressionSyntax:
                    return(LiteralExpression.Print(literalExpressionSyntax));

                case LocalDeclarationStatementSyntax localDeclarationStatementSyntax:
                    return(LocalDeclarationStatement.Print(localDeclarationStatementSyntax));

                case LocalFunctionStatementSyntax localFunctionStatementSyntax:
                    return(LocalFunctionStatement.Print(localFunctionStatementSyntax));

                case LockStatementSyntax lockStatementSyntax:
                    return(LockStatement.Print(lockStatementSyntax));

                case MakeRefExpressionSyntax makeRefExpressionSyntax:
                    return(MakeRefExpression.Print(makeRefExpressionSyntax));

                case MemberAccessExpressionSyntax memberAccessExpressionSyntax:
                    return(MemberAccessExpression.Print(memberAccessExpressionSyntax));

                case MemberBindingExpressionSyntax memberBindingExpressionSyntax:
                    return(MemberBindingExpression.Print(memberBindingExpressionSyntax));

                case NameColonSyntax nameColonSyntax:
                    return(NameColon.Print(nameColonSyntax));

                case NameEqualsSyntax nameEqualsSyntax:
                    return(NameEquals.Print(nameEqualsSyntax));

                case NamespaceDeclarationSyntax namespaceDeclarationSyntax:
                    return(NamespaceDeclaration.Print(namespaceDeclarationSyntax));

                case NullableTypeSyntax nullableTypeSyntax:
                    return(NullableType.Print(nullableTypeSyntax));

                case ObjectCreationExpressionSyntax objectCreationExpressionSyntax:
                    return(ObjectCreationExpression.Print(objectCreationExpressionSyntax));

                case OmittedArraySizeExpressionSyntax omittedArraySizeExpressionSyntax:
                    return(OmittedArraySizeExpression.Print(omittedArraySizeExpressionSyntax));

                case OmittedTypeArgumentSyntax omittedTypeArgumentSyntax:
                    return(OmittedTypeArgument.Print(omittedTypeArgumentSyntax));

                case OrderByClauseSyntax orderByClauseSyntax:
                    return(OrderByClause.Print(orderByClauseSyntax));

                case ParameterListSyntax parameterListSyntax:
                    return(ParameterList.Print(parameterListSyntax));

                case ParameterSyntax parameterSyntax:
                    return(Parameter.Print(parameterSyntax));

                case ParenthesizedExpressionSyntax parenthesizedExpressionSyntax:
                    return(ParenthesizedExpression.Print(parenthesizedExpressionSyntax));

                case ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpressionSyntax:
                    return(ParenthesizedLambdaExpression.Print(
                               parenthesizedLambdaExpressionSyntax
                               ));

                case ParenthesizedPatternSyntax parenthesizedPatternSyntax:
                    return(ParenthesizedPattern.Print(parenthesizedPatternSyntax));

                case ParenthesizedVariableDesignationSyntax parenthesizedVariableDesignationSyntax:
                    return(ParenthesizedVariableDesignation.Print(
                               parenthesizedVariableDesignationSyntax
                               ));

                case PointerTypeSyntax pointerTypeSyntax:
                    return(PointerType.Print(pointerTypeSyntax));

                case PostfixUnaryExpressionSyntax postfixUnaryExpressionSyntax:
                    return(PostfixUnaryExpression.Print(postfixUnaryExpressionSyntax));

                case PredefinedTypeSyntax predefinedTypeSyntax:
                    return(PredefinedType.Print(predefinedTypeSyntax));

                case PrefixUnaryExpressionSyntax prefixUnaryExpressionSyntax:
                    return(PrefixUnaryExpression.Print(prefixUnaryExpressionSyntax));

                case PrimaryConstructorBaseTypeSyntax primaryConstructorBaseTypeSyntax:
                    return(PrimaryConstructorBaseType.Print(primaryConstructorBaseTypeSyntax));

                case QualifiedNameSyntax qualifiedNameSyntax:
                    return(QualifiedName.Print(qualifiedNameSyntax));

                case QueryBodySyntax queryBodySyntax:
                    return(QueryBody.Print(queryBodySyntax));

                case QueryContinuationSyntax queryContinuationSyntax:
                    return(QueryContinuation.Print(queryContinuationSyntax));

                case QueryExpressionSyntax queryExpressionSyntax:
                    return(QueryExpression.Print(queryExpressionSyntax));

                case RangeExpressionSyntax rangeExpressionSyntax:
                    return(RangeExpression.Print(rangeExpressionSyntax));

                case RecursivePatternSyntax recursivePatternSyntax:
                    return(RecursivePattern.Print(recursivePatternSyntax));

                case RefExpressionSyntax refExpressionSyntax:
                    return(RefExpression.Print(refExpressionSyntax));

                case RefTypeExpressionSyntax refTypeExpressionSyntax:
                    return(RefTypeExpression.Print(refTypeExpressionSyntax));

                case RefTypeSyntax refTypeSyntax:
                    return(RefType.Print(refTypeSyntax));

                case RefValueExpressionSyntax refValueExpressionSyntax:
                    return(RefValueExpression.Print(refValueExpressionSyntax));

                case RelationalPatternSyntax relationalPatternSyntax:
                    return(RelationalPattern.Print(relationalPatternSyntax));

                case ReturnStatementSyntax returnStatementSyntax:
                    return(ReturnStatement.Print(returnStatementSyntax));

                case SelectClauseSyntax selectClauseSyntax:
                    return(SelectClause.Print(selectClauseSyntax));

                case SimpleBaseTypeSyntax simpleBaseTypeSyntax:
                    return(SimpleBaseType.Print(simpleBaseTypeSyntax));

                case SimpleLambdaExpressionSyntax simpleLambdaExpressionSyntax:
                    return(SimpleLambdaExpression.Print(simpleLambdaExpressionSyntax));

                case SingleVariableDesignationSyntax singleVariableDesignationSyntax:
                    return(SingleVariableDesignation.Print(singleVariableDesignationSyntax));

                case SizeOfExpressionSyntax sizeOfExpressionSyntax:
                    return(SizeOfExpression.Print(sizeOfExpressionSyntax));

                case StackAllocArrayCreationExpressionSyntax stackAllocArrayCreationExpressionSyntax:
                    return(StackAllocArrayCreationExpression.Print(
                               stackAllocArrayCreationExpressionSyntax
                               ));

                case SwitchExpressionSyntax switchExpressionSyntax:
                    return(SwitchExpression.Print(switchExpressionSyntax));

                case SwitchSectionSyntax switchSectionSyntax:
                    return(SwitchSection.Print(switchSectionSyntax));

                case SwitchStatementSyntax switchStatementSyntax:
                    return(SwitchStatement.Print(switchStatementSyntax));

                case ThisExpressionSyntax thisExpressionSyntax:
                    return(ThisExpression.Print(thisExpressionSyntax));

                case ThrowExpressionSyntax throwExpressionSyntax:
                    return(ThrowExpression.Print(throwExpressionSyntax));

                case ThrowStatementSyntax throwStatementSyntax:
                    return(ThrowStatement.Print(throwStatementSyntax));

                case TryStatementSyntax tryStatementSyntax:
                    return(TryStatement.Print(tryStatementSyntax));

                case TupleElementSyntax tupleElementSyntax:
                    return(TupleElement.Print(tupleElementSyntax));

                case TupleExpressionSyntax tupleExpressionSyntax:
                    return(TupleExpression.Print(tupleExpressionSyntax));

                case TupleTypeSyntax tupleTypeSyntax:
                    return(TupleType.Print(tupleTypeSyntax));

                case TypeArgumentListSyntax typeArgumentListSyntax:
                    return(TypeArgumentList.Print(typeArgumentListSyntax));

                case TypeConstraintSyntax typeConstraintSyntax:
                    return(TypeConstraint.Print(typeConstraintSyntax));

                case TypeOfExpressionSyntax typeOfExpressionSyntax:
                    return(TypeOfExpression.Print(typeOfExpressionSyntax));

                case TypeParameterConstraintClauseSyntax typeParameterConstraintClauseSyntax:
                    return(TypeParameterConstraintClause.Print(
                               typeParameterConstraintClauseSyntax
                               ));

                case TypeParameterListSyntax typeParameterListSyntax:
                    return(TypeParameterList.Print(typeParameterListSyntax));

                case TypeParameterSyntax typeParameterSyntax:
                    return(TypeParameter.Print(typeParameterSyntax));

                case TypePatternSyntax typePatternSyntax:
                    return(TypePattern.Print(typePatternSyntax));

                case UnaryPatternSyntax unaryPatternSyntax:
                    return(UnaryPattern.Print(unaryPatternSyntax));

                case UnsafeStatementSyntax unsafeStatementSyntax:
                    return(UnsafeStatement.Print(unsafeStatementSyntax));

                case UsingDirectiveSyntax usingDirectiveSyntax:
                    return(UsingDirective.Print(usingDirectiveSyntax));

                case UsingStatementSyntax usingStatementSyntax:
                    return(UsingStatement.Print(usingStatementSyntax));

                case VariableDeclarationSyntax variableDeclarationSyntax:
                    return(VariableDeclaration.Print(variableDeclarationSyntax));

                case VariableDeclaratorSyntax variableDeclaratorSyntax:
                    return(VariableDeclarator.Print(variableDeclaratorSyntax));

                case VarPatternSyntax varPatternSyntax:
                    return(VarPattern.Print(varPatternSyntax));

                case WhenClauseSyntax whenClauseSyntax:
                    return(WhenClause.Print(whenClauseSyntax));

                case WhereClauseSyntax whereClauseSyntax:
                    return(WhereClause.Print(whereClauseSyntax));

                case WhileStatementSyntax whileStatementSyntax:
                    return(WhileStatement.Print(whileStatementSyntax));

                case WithExpressionSyntax withExpressionSyntax:
                    return(WithExpression.Print(withExpressionSyntax));

                case YieldStatementSyntax yieldStatementSyntax:
                    return(YieldStatement.Print(yieldStatementSyntax));

                default:
                    throw new Exception("Can't handle " + syntaxNode.GetType().Name);
                }
            }

            finally
            {
                depth--;
            }
        }
        private void Setup()
        {
            int iDx = GlobalDataAccessor.Instance.DesktopSession.PawnLoans.FindIndex(p => p.TicketNumber == pawnLoan.TicketNumber);

            if (iDx < 0)
            {
                iDx = GlobalDataAccessor.Instance.DesktopSession.PawnLoans_Auxillary.FindIndex(p => p.TicketNumber == pawnLoan.TicketNumber);
                if (iDx < 0)
                {
                    MessageBox.Show(
                        "Ticket Number is not associated to a Loan.",
                        "Ticket Number Lookup",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    Close();
                }
            }
            rolloverLoanHeaderLabel.Text = "Fees For Pawn Loan " + pawnLoan.TicketNumber;

            foreach (var fee in pawnLoan.OriginalFees)
            {
                feeTypes.Add(new TupleType <FeeTypes, string, string>(fee.FeeType, fee.Value.ToString(), "N/A"));
            }

            // populate Panel
            var label = new Label
            {
                Text = ""
            };

            AddToLayoutPanel(label);
            label = new Label
            {
                TextAlign = ContentAlignment.MiddleRight,
                Text      = "Current Loan"
            };
            AddToLayoutPanel(label);
            label = new Label
            {
                TextAlign = ContentAlignment.MiddleRight,
                Text      = "New Loan"
            };
            AddToLayoutPanel(label);

            //SR 01/18/2009
            //The fees are already calculated for the loan when this form
            //is invoked so no need to recalculate

            /*  var underwritePawnLoanVO = new UnderwritePawnLoanVO();
             *
             * newPawnLoan.Fees = new List<Fee>();
             * newPawnLoan.InterestAmount = 0;
             * newPawnLoan.ServiceCharge = 0;
             *
             * var siteId = Utilities.CloneObject(GlobalDataAccessor.Instance.CurrentSiteId);
             * siteId.Date = ShopDateTime.Instance.ShopDate;
             * siteId.LoanAmount = pawnLoan.Amount;
             *
             * PawnLoan currentPawnLoan = StoreLoans.GetCurrentLoanFees(siteId, newPawnLoan, out underwritePawnLoanVO);
             */
            if (newPawnLoan.Fees == null)
            {
                return;
            }
            foreach (var fee in newPawnLoan.Fees)
            {
                var fee1 = fee;
                iDx = feeTypes.FindIndex(k => k.Left == fee1.FeeType);
                if (iDx >= 0)
                {
                    var curFee = feeTypes[iDx];
                    var newFee = new TupleType <FeeTypes, string, string>(curFee.Left, curFee.Mid, fee1.Value.ToString());
                    feeTypes.RemoveAt(iDx);
                    feeTypes.Insert(iDx, newFee);
                }
                else
                {
                    var newFee = new TupleType <FeeTypes, string, string>(fee1.FeeType, "N/A", fee1.Value.ToString());
                    feeTypes.Add(newFee);
                }
            }

            var iFeeCnt      = 0;
            var currFeeTypes = from feetypes in feeTypes
                               where feetypes.Left != FeeTypes.INTEREST
                               select feetypes;

            foreach (var fee in currFeeTypes)
            {
                if (Utilities.GetDecimalValue(fee.Right, -1) >= 0 || Utilities.GetStringValue(fee.Right, "") == "N/A")
                {
                    iFeeCnt++;
                    label = new Label
                    {
                        TextAlign = ContentAlignment.MiddleLeft,
                        Text      = GetFeeTypeText(fee.Left)
                    };
                    AddToLayoutPanel(label);
                    label = new Label
                    {
                        TextAlign = ContentAlignment.MiddleRight,
                        Text      = String.Format("{0:C}", Utilities.GetDecimalValue(fee.Mid, 0))
                    };
                    AddToLayoutPanel(label);
                    label = new Label
                    {
                        TextAlign = ContentAlignment.MiddleRight,
                        Text      =
                            String.Format("{0:C}", Utilities.GetDecimalValue(fee.Right, 0))
                    };
                    AddToLayoutPanel(label);
                }
            }

            if (iFeeCnt == 0)
            {
                label = new Label
                {
                    TextAlign = ContentAlignment.MiddleLeft,
                    Text      = "None"
                };
                AddToLayoutPanel(label);
                label = new Label
                {
                    TextAlign = ContentAlignment.MiddleRight,
                    Text      = String.Format("{0:C}", 0)
                };
                AddToLayoutPanel(label);
                label = new Label
                {
                    TextAlign = ContentAlignment.MiddleRight,
                    Text      = String.Format("{0:C}", 0)
                };
                AddToLayoutPanel(label);
            }
        }
Exemple #12
0
 public EqualConditionItem(string name, string value, TupleType tupleType)
     : base(name, MatchMode.Exact, tupleType)
 {
     Value = value;
 }
Exemple #13
0
 protected AbstractConditionItem(string name, MatchMode matchMode, TupleType tupleType)
 {
     Name      = name;
     MatchMode = matchMode;
     TupleType = tupleType;
 }
Exemple #14
0
 public virtual IType VisitTupleType(TupleType type)
 {
     return(type.VisitChildren(this));
 }
 public EventingVisitor(Action<TupleType> visitTupleType) { VisitedTupleType += visitTupleType; } public event Action<TupleType> VisitedTupleType; public override TupleType VisitTupleType(TupleType tuple) { if (VisitedTupleType != null) VisitedTupleType(tuple); return base.VisitTupleType(tuple); }
Exemple #16
0
        public void ReflexivityConformsToTest()
        {
            TypesTable             typesTable = new TypesTable();
            StandardLibraryCreator sl         = new StandardLibraryCreator();

            sl.CreateStandardLibrary(typesTable);

            Classifier integerType = typesTable.Library.Integer;

            Assert.IsTrue(integerType.ConformsTo(integerType));

            Classifier realType = typesTable.Library.Real;

            Assert.IsTrue(realType.ConformsTo(realType));

            CollectionType collType  = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);
            CollectionType collType2 = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);

            typesTable.RegisterType(collType);
            typesTable.RegisterType(collType2);

            Assert.IsTrue(collType.ConformsTo(collType));
            Assert.IsTrue(collType.ConformsTo(collType2));

            List <Property> tupleParts1 = new List <Property>();

            tupleParts1.Add(new Property("ahoj", PropertyType.One, integerType));
            TupleType tuple = new TupleType(typesTable, tupleParts1);

            typesTable.RegisterType(tuple);

            List <Property> tupleParts2 = new List <Property>();

            tupleParts2.Add(new Property("ahoj", PropertyType.One, integerType));
            TupleType tuple2 = new TupleType(typesTable, tupleParts2);

            typesTable.RegisterType(tuple2);

            Assert.IsTrue(tuple.ConformsTo(tuple));
            Assert.IsTrue(tuple.ConformsTo(tuple2));

            CollectionType bagType  = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);
            CollectionType bagType2 = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);

            Assert.IsTrue(bagType.ConformsTo(bagType));
            Assert.IsTrue(bagType.ConformsTo(bagType2));


            CollectionType setType  = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Set, integerType);
            CollectionType setType2 = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Set, integerType);

            Assert.IsTrue(setType.ConformsTo(setType));
            Assert.IsTrue(setType.ConformsTo(setType2));

            Classifier voidType = typesTable.Library.Void;

            typesTable.RegisterType(voidType);
            Assert.IsTrue(voidType.ConformsTo(voidType));

            Classifier anyType = typesTable.Library.Any;

            typesTable.RegisterType(anyType);
            Assert.IsTrue(anyType.ConformsTo(anyType));

            Classifier invalidType = typesTable.Library.Invalid;

            typesTable.RegisterType(invalidType);
            Assert.IsTrue(invalidType.ConformsTo(invalidType));
            //pridat class
        }
Exemple #17
0
 public override IType VisitTupleType(TupleType type)
 {
     type.UnderlyingType.AcceptVisitor(this);
     return(type);
 }
 public Bucket(TupleType item)
 {
     Item      = item;
     Subrel    = null;
     ItemValid = true;
 }
Exemple #19
0
        // <-- FN ((Name | Operator) TupleType)
        //      | (LPAREN ParamDecl RPAREN)
        private IUnboundExpr FuncExpr()
        {
            Position position = Consume(TokenType.Fn).Position;

            if (CurrentIs(TokenType.LeftParen))
            {
                // local function
                var paramNames = new List<string>();
                var funcType = FnArgsDecl(paramNames);
                var body = Block();

                return new LocalFuncExpr(position, paramNames, funcType, body);
            }
            else
            {
                // function reference
                NameExpr name;
                if (CurrentIs(TokenType.Operator))
                {
                    Token op = Consume(TokenType.Operator);
                    name = new NameExpr(op.Position, op.StringValue);
                }
                else
                {
                    var token = Consume(TokenType.Name);
                    name = new NameExpr(token.Position, token.StringValue, TypeArgs());
                }

                var parameters = TupleType().ToArray();
                IUnboundDecl parameter;
                if (parameters.Length == 0)
                {
                    parameter = Decl.Unit;
                }
                else if (parameters.Length == 1)
                {
                    parameter = parameters[0];
                }
                else
                {
                    parameter = new TupleType(parameters);
                }

                return new FuncRefExpr(position, name, parameter);
            }
        }
 public Bucket(ImmutableRelation <TupleType> subrel)
 {
     Item      = default;
     Subrel    = subrel;
     ItemValid = false;
 }
Exemple #21
0
    void CompileTuple(TupleType tuple, Member member) {
      bool hasSequence = false;
      this.builder.OpenGroup();

      // Now walk all our members, and look for custom attributes that indicate
      // whether those members are elements or attributes (the default is
      // to make it an element).
      MemberList members = tuple.Members;
      for (int i = 0, n = members == null ? 0 : members.Length; i < n; i++) {
        Member mem = members[i];
        Field f = mem as Field;
        if (f == null || f.Type == null)  continue; // type was not resolved.

        TypeNode fType = Unwrap(f.Type);
        if (fType == null) continue;

        if (builder.HasTerminal) {
          builder.AddSequence(member, tuple);
          hasSequence = true;
        }

        if (f.IsAnonymous) {
          // This is an un-named member, meaning we have to drill into it to
          // extract it's content model also.
          if (fType is TupleType) {
            CompileTuple(fType as TupleType, mem);
          } else if (fType.Template == SystemTypes.GenericList || 
                     fType.Template == SystemTypes.GenericIList ||
                     fType.Template == SystemTypes.GenericList ||
                     fType.Template == SystemTypes.GenericIEnumerable) {
            CompileGenericList(fType, 0, Int32.MaxValue, mem);
          } else if (fType.Template == SystemTypes.GenericNonEmptyIEnumerable) {
            CompileGenericList(fType,1, Int32.MaxValue, mem);
          } else if (fType is TypeUnion) {
            CompileTypeUnion(fType as TypeUnion, mem);
          } else if (fType.Template == SystemTypes.GenericBoxed) {
            CompileGenericList(fType, 0, 1, mem);
          } else {
            if (f.Type is TypeAlias) {
              TypeAlias alias = f.Type as TypeAlias;
              builder.AddNamedTerminal(alias.Name, mem, alias.AliasedType);
            } else {
              builder.AddNamedTerminal(Checker.GetDefaultElementName(fType), mem, fType);
            }
          }
        } else if (fType.Template == SystemTypes.GenericBoxed) {
          CompileGenericList(fType, 0, 1, mem);
        } else {
          builder.AddNamedTerminal(mem.Name, mem, f.Type);
        }
      }
      if (!hasSequence && builder.HasTerminal) builder.AddNop(member, tuple);
      this.builder.CloseGroup();
    }
 public Bucket(TupleType item, ImmutableRelation <TupleType> subrel)
 {
     Item      = item;
     Subrel    = subrel;
     ItemValid = true;
 }
Exemple #23
0
        public ChessBoardPoint GetNextStep(IChessBoard chessBoard, PieceTypeEnum pieceType, int stepIndex, PlayStep? prevStep)
        {
            int[] tupleScoreTable = new int[11] { 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            //initialize tuple score table
            if (stepIndex % 2 == 0)//even step is first hand,i.e. the black side
            {
                if (stepIndex == 0)
                {
                    return ChessBoardPoint.TENGEN;
                }
                else if(stepIndex==2)
                {
                    Position[][] classicalOpen = new Position[8][];
                    //0:white is on left side of Tengen
                    classicalOpen[0]=new Position[21]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //1:white is on up side of Tengen
                    classicalOpen[1]=new Position[21]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //2:white is on right side of Tengen
                    classicalOpen[2]=new Position[21]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //3:white is on bottom side of Tengen
                    classicalOpen[3]=new Position[21]{
                        new Position(8,8),new Position(9,7),new Position(7,8),new Position(7,9),
                        new Position(8,9),new Position(6,9),new Position(5,8),new Position(6,8),
                        new Position(6,7),new Position(5,7),new Position(9,9),new Position(5,5),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //4:white is on topleft corner of Tengen
                    classicalOpen[4]=new Position[25]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //5:white is on topright corner of Tengen
                    classicalOpen[5]=new Position[25]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //6:white is on bottomright corner of Tengen
                    classicalOpen[6]=new Position[25]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //7:white is on bottomleft corner of Tengen
                    classicalOpen[7] = new Position[25]{
                        new Position(6,6),new Position(7,5),new Position(7,6),new Position(6,5),
                        new Position(8,5),new Position(6,8),new Position(9,5),new Position(7,9),
                        new Position(5,5),new Position(5,6),new Position(7,8),new Position(5,8),
                        new Position(5,9),new Position(8,5),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};

                    Position whiteFirst = new Position(14-prevStep.Value.Location.RowIndex, prevStep.Value.Location.ColumnIndex);
                    switch ()
                    {
                    case :
                        break;
                    }
                }
                tupleScoreTable[1] = 35;
                tupleScoreTable[2] = 800;
                tupleScoreTable[3] = 15000;
                tupleScoreTable[4] = 800000;
                tupleScoreTable[5] = 15;
                tupleScoreTable[6] = 400;
                tupleScoreTable[7] = 1800;
                tupleScoreTable[8] = 100000;
            }
            else//odd step is back hand,i.e. the white side
            {
                tupleScoreTable[1] = 15;
                tupleScoreTable[2] = 400;
                tupleScoreTable[3] = 1800;
                tupleScoreTable[4] = 100000;
                tupleScoreTable[5] = 35;
                tupleScoreTable[6] = 800;
                tupleScoreTable[7] = 15000;
                tupleScoreTable[8] = 800000;
            }

            //extended board,with virtual points
            ExtendedPointStateEnum[,] exPointStates = new ExtendedPointStateEnum[23, 23];
            for (int row = 0; row < 23; row++)
            {
                for (int col = 0; col < 23; col++)
                {
                    if (row < 4 || row > 18 || col < 4 || col > 18)
                    {
                        exPointStates[row, col] = ExtendedPointStateEnum.Virtual;
                    }
                    else
                    {
                        exPointStates[row, col] = (ExtendedPointStateEnum)chessBoard.GetPointState(14 - (row - 4), col - 4);
                    }
                }
            }

            int[,] scoreTable = new int[15, 15];

            /// <summary>calculate type of every tuple</summary>
            /// <description>In order to give a clear train of thought,
            /// I used an intuitionistic method to do this work.
            /// But this results in not efficient.
            /// Every tuple is calculated for twice.
            /// But it's easy to modify it:two ends of a tuple own the same tuple
            /// I'll modify it in next version ,where efficiency becomes bottleneck.
            /// </description>
            //every point indexs 8 tuples around it
            TupleType[, ,] tupleTable = new TupleType[15, 15, 8];
            for (int row = 4; row < 19; row++)
            {
                for (int col = 4; col < 19; col++)
                {
                    int[] white = new int[8];//white points in a tuple
                    int[] black = new int[8];//black points in a tuple
                    #region ---check tuples of every direction
                    //left ,index 0
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 0] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[0]++;
                        }
                        else if (exPointStates[row, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[0]++;
                        }
                    }
                    //top left,index 1
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 1] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[1]++;
                        }
                        else if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[1]++;
                        }
                    }
                    //up ,index 2
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 2] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col] == ExtendedPointStateEnum.Black)
                        {
                            black[2]++;
                        }
                        else if (exPointStates[row - i, col] == ExtendedPointStateEnum.White)
                        {
                            white[2]++;
                        }
                    }
                    //top right,index 3
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 3] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[3]++;
                        }
                        else if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[3]++;
                        }
                    }
                    //right,index 4
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 4] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[4]++;
                        }
                        else if (exPointStates[row, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[4]++;
                        }
                    }
                    //bottom right,index 5
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 5] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[5]++;
                        }
                        else if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[5]++;
                        }
                    }
                    //bottom,index 6
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 6] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col] == ExtendedPointStateEnum.Black)
                        {
                            black[6]++;
                        }
                        else if (exPointStates[row + i, col] == ExtendedPointStateEnum.White)
                        {
                            white[6]++;
                        }
                    }
                    //bottom left,index 7
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 7] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[7]++;
                        }
                        else if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[7]++;
                        }
                    }
                    #endregion //check tuples of every direction

                    //decide tuple type
                    for (int i = 0; i < 8; i++)
                    {
                        //already assigned
                        if (tupleTable[row - 4, col - 4, i] == TupleType.Virtual)
                        {
                            continue;
                        }
                        if (white[i] > 0 && black[i] > 0)
                        {
                            tupleTable[row - 4, col - 4, i] = TupleType.Polluted;
                        }
                        else if (white[i] == 0 && black[i] == 0)
                        {
                            tupleTable[row - 4, col - 4, i] = TupleType.Blank;
                        }
                        else if (white[i] == 0)
                        {
                            tupleTable[row - 4, col - 4, i] = (TupleType)black[i];
                        }
                        else
                        {
                            tupleTable[row - 4, col - 4, i] = (TupleType)(white[i] + 4);
                        }
                    }
                }
            }
            #region ---scoreTable calculate
            //calculate score table . using symmetry
            //top left corner
            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row >= m)//top right
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col + m, 7]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col, 2]];//bottom
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col + m, 1]];//bottom right
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col + m, 0]];//right
                    }
                }
            }
            //top right corner
            for (int row = 0; row < 8; row++)
            {
                for (int col = 8; col < 15; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row >= m)//top left
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col - m, 5]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col, 2]];//bottom
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col - m, 3]];//bottom left
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col - m, 4]];//left
                    }
                }
            }
            //bottom left corner
            for (int row = 8; row < 15; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row + m < 15)//bottom right
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col + m, 1]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col, 6]];//top
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col + m, 7]];//top right
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col + m, 0]];//right
                    }
                }
            }
            //bottom right corner
            for (int row = 8; row < 15; row++)
            {
                for (int col = 8; col < 15; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row + m < 15)//bottom left
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col - m, 3]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col, 6]];//top
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col - m, 5]];//top left
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col - m, 4]];//left
                    }
                }
            }
            #endregion //scoreTable

            //select best position
            List<Position> bestList = new List<Position>();

            //select first valid point
            Position first = new Position(0, 0);
            //all the point is forbidden.connot happen
            //while (IsFobidden(first))
            //{
            //    while (IsFobidden(first))
            //    {
            //        if (first.Col<14)
            //        {
            //            first.Col++;
            //        }
            //        else
            //        {
            //            break;
            //        }
            //    }
            //    if (first.Row<14)
            //    {
            //        first.Row++;
            //    }
            //    else
            //    {
            //        break;
            //    }
            //}
            while (IsFobidden(ref chessBoard, first, pieceType))
            {
                if (first.Col < 14)
                {
                    first.Col++;
                }
                else if (first.Row < 14)
                {
                    first.Row++;
                    first.Col = 0;
                }
                else
                {
                    return new ChessBoardPoint(-1, -1);
                }
            }
            bestList.Add(first);

            Referee checkWin = new Referee();
            //select best points
            for (int row = 0; row < 15; row++)
            {
                for (int col = 0; col < 15; col++)
                {
                    if (scoreTable[row, col] > scoreTable[bestList[0].Row, bestList[0].Col])
                    {
                        Position best = new Position(row, col);
                        if (!IsFobidden(ref chessBoard, best, pieceType))
                        {
                            bestList.Clear();
                            bestList.Add(best);
                        }

                    }
                    else if (scoreTable[row, col] == scoreTable[bestList[0].Row, bestList[0].Col])
                    {
                        Position best = new Position(row, col);
                        if (!IsFobidden(ref chessBoard, best, pieceType))
                        {
                            bestList.Add(best);
                        }
                    }
                }
            }
            //there is no best .connot happen
            if (bestList.Count == 0)
            {
                return new ChessBoardPoint(-1, -1);
            }
            Position ret = bestList[(new Random()).Next(bestList.Count)];
            return new ChessBoardPoint(14 - ret.Row, ret.Col);
        }
Exemple #24
0
 public Exception OutOfBoundsTupleAccess(PParser.IntContext location, TupleType tuple)
 {
     return(IssueError(
                location, $"tuple type {tuple.OriginalRepresentation} has no '{location.GetText()}' field"));
 }
 public EqualConditionItem(string name, string value, TupleType tupleType)
     : base(name, MatchMode.Exact, tupleType)
 {
     Value = value;
 }
Exemple #26
0
 public UnnamedTupleExpr(ParserRuleContext sourceLocation, IReadOnlyList <IPExpr> tupleFields)
 {
     SourceLocation = sourceLocation;
     TupleFields    = tupleFields;
     Type           = new TupleType(tupleFields.Select(f => f.Type).ToArray());
 }
Exemple #27
0
 public virtual TupleType VisitTupleType(TupleType tuple){
   return (TupleType)this.VisitTypeNode(tuple);
 }
Exemple #28
0
        /// <summary>
        /// Binds the parameters of a call to the called function.
        /// </summary>
        /// <param name="analyzer"></param>
        /// <param name="call"></param>
        /// <param name="func"></param>
        /// <param name="funcTable"></param>
        /// <param name="parameters"></param>
        /// <param name="rest"></param>
        /// <param name="restKw"></param>
        /// <param name="pTypes"></param>
        /// <param name="dTypes"></param>
        /// <param name="hash"></param>
        /// <param name="kw"></param>
        /// <param name="star"></param>
        /// <returns></returns>
        private static DataType BindParameters(
            Analyzer analyzer,
            Node call,
            FunctionDef func,
            State funcTable,
            List <Parameter> parameters,
            Identifier rest,
            Identifier restKw,
            List <DataType> pTypes,
            List <DataType> dTypes,
            IDictionary <string, DataType> hash,
            DataType kw,
            DataType star)
        {
            TupleType fromType = analyzer.TypeFactory.CreateTuple();
            int       pSize    = parameters == null ? 0 : parameters.Count;
            int       aSize    = pTypes == null ? 0 : pTypes.Count;
            int       dSize    = dTypes == null ? 0 : dTypes.Count;
            int       nPos     = pSize - dSize;

            if (star != null && star is ListType list)
            {
                star = list.toTupleType();
            }

            for (int i = 0, j = 0; i < pSize; i++)
            {
                Parameter param = parameters[i];
                DataType  aType;
                if (i < aSize)
                {
                    aType = pTypes[i];
                }
                else if (i - nPos >= 0 && i - nPos < dSize)
                {
                    aType = dTypes[i - nPos];
                }
                else
                {
                    if (hash != null && hash.ContainsKey(parameters[i].Id.Name))
                    {
                        aType = hash[parameters[i].Id.Name];
                        hash.Remove(parameters[i].Id.Name);
                    }
                    else
                    {
                        if (star != null && star is TupleType &&
                            j < ((TupleType)star).eltTypes.Count)
                        {
                            aType = ((TupleType)star).get(j++);
                        }
                        else
                        {
                            aType = DataType.Unknown;
                            if (call != null)
                            {
                                analyzer.putProblem(parameters[i].Id, //$REVIEW: should be using identifiers
                                                    "unable to bind argument:" + parameters[i]);
                            }
                        }
                    }
                }
                funcTable.Bind(analyzer, param.Id, aType, BindingKind.PARAMETER);
                fromType.add(aType);
            }

            if (restKw != null)
            {
                DataType dt;
                if (hash != null && hash.Count > 0)
                {
                    DataType hashType = UnionType.newUnion(hash.Values);
                    dt = analyzer.TypeFactory.CreateDict(DataType.Str, hashType);
                }
                else
                {
                    dt = DataType.Unknown;
                }
                funcTable.Bind(
                    analyzer,
                    restKw,
                    dt,
                    BindingKind.PARAMETER);
            }

            if (rest != null)
            {
                if (pTypes.Count > pSize)
                {
                    DataType restType = analyzer.TypeFactory.CreateTuple(pTypes.subList(pSize, pTypes.Count).ToArray());
                    funcTable.Bind(analyzer, rest, restType, BindingKind.PARAMETER);
                }
                else
                {
                    funcTable.Bind(
                        analyzer,
                        rest,
                        DataType.Unknown,
                        BindingKind.PARAMETER);
                }
            }
            return(fromType);
        }
Exemple #29
0
    void AddReadTuple(Block block, TupleType tuple, StatementList statements, Identifier reader, 
      Expression target, Expression required, Expression result){

      Local lt = new Local(Identifier.Empty, tuple, block);

      StatementList currentBlock = statements;

      for(int i = 0, n = tuple.Members.Length; i < n; i++) {
        Member mem = tuple.Members[i];
        if (mem is Field) {
          Field f = (Field)mem;
          TypeNode mt = f.Type;
          if (mt == null) continue; // type resolution error.
          Expression mb = GetMemberBinding(target, f, mt);
          if (mt.Template == SystemTypes.GenericBoxed){
            AddReadOptional(block, statements, f, mb, reader, result);
          }          
          else if (mem.IsAnonymous) {
            if (mt is TupleType || mt is TypeUnion || IsStream(mt)) {
              AddCallDeserializer(mt, statements, reader, mb, required, result);        
            } else  {
              Identifier name = Checker.GetDefaultElementName(mt);
              AddReadRequiredChild(block, statements, name, mt, mb, reader, result, Literal.True, true, true);
            }            
          } else {
            // could reduce a bit of code if we could assign currentName and pass the local to AddReadChild...
            AddReadRequiredChild(block, statements, mem.Name, mt, mb, reader, result, required, false, true);
          }
        }
      }
    }
Exemple #30
0
 internal void ReadOpMem_VSIB_m32(ref Instruction instruction, Register vsibIndex, TupleType tupleType)
 {
     Debug.Assert(!is64Mode);
     Debug.Assert(state.addressSize == OpSize.Size16 || state.addressSize == OpSize.Size32);
     if (state.addressSize == OpSize.Size32)
     {
         if (!ReadOpMem32Or64(ref instruction, Register.EAX, vsibIndex, tupleType, true))
         {
             SetInvalidInstruction();
         }
     }
     else
     {
         SetInvalidInstruction();
     }
 }
Exemple #31
0
 public virtual TupleType VisitTupleType(TupleType tuple, TupleType changes, TupleType deletions, TupleType insertions){
   return (TupleType)this.VisitTypeNode(tuple, changes, deletions, insertions);
 }
 public static bool TryTupleType(string value, out TupleType tupleType) => tupleTypeDict.TryGetValue(value, out tupleType);