示例#1
0
            public void Execute(CodeGenerationInfo cgInfo)
            {
                Debug.WriteLine("Begun TI for function {0}", cgInfo.FuncMetadata.Declaration);
                _cgInfo = cgInfo;
                _worklist.Clear();
                ++_passNumber;

                InitializeSymbolTypes();

                _typeCalculator = new TypeCalculator();
                _typeCalculator.Execute(cgInfo);

                while (_worklist.Count > 0)
                {
                    var exp = _worklist.Dequeue();
                    VisitNode(exp);
                }

                ///It may happen that even after TI, still some symbol.ValueType==Unknown
                ///In these cases, we just assign a default type to them and see if any types change
                foreach (var symbol in _cgInfo.FuncMetadata.Scope.Symbols)
                {
                    if (GetType(symbol) == mdr.ValueTypes.Unknown)
                    {
                        SetType(symbol, mdr.ValueTypes.DValueRef);
                    }
                }
                while (_worklist.Count > 0)
                {
                    var exp = _worklist.Dequeue();
                    VisitNode(exp);
                }
                Debug.WriteLine("Ended TI for function {0}", cgInfo.FuncMetadata.Declaration);
            }
示例#2
0
            public override void Visit(GuardedCast node)
            {
                //UpdateType(node, TypeCalculator.GetType(node, _cgInfo.FuncCode.Profiler));
                Profiler profile;

                _typeCalculator.GuardedCastProfile.TryGetValue(node, out profile);
                UpdateType(node, TypeCalculator.GetType(node, profile));
            }
        public void TestgetTypesImmuneToItWith1Type()
        {
            Type           type1check = Type.Flying;
            String         Expected   = "                  ";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getTypesImmuneToIt(type1check);

            Assert.AreEqual(Expected, check);
        }
        public void TestGetTypesSuperEffectiveAgainstWith1Type()
        {
            Type           type1check = Type.Fighting;
            String         Expected   = "Flying Psychic Fairy";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getTypesSuperEffectiveAgainst(type1check);

            Assert.AreEqual(Expected, check);
        }
        public void TestGetNotVeryEffectiveAgainstWith1Type()
        {
            Type           type1check = Type.Fire;
            String         Expected   = "Rock Fire Water Dragon";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getNotVeryEffectiveAgainst(type1check);

            Assert.AreEqual(Expected, check);
        }
        public void TestgetTypesNotVeryEffectiveAgainstWith1Type()
        {
            Type           type1check = Type.Ice;
            String         Expected   = "Steel Fire Water Ice";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getTypesNotVeryEffectiveAgainst(type1check);

            Assert.AreEqual(Expected, check);
        }
        public void TestgetSuperEffectiveAgainstWith1Type()
        {
            Type           type1check = Type.Fighting;
            String         Expected   = "Normal Rock Steel Ice Dark";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getSuperEffectiveAgainst(type1check);

            Assert.AreEqual(Expected, check);
        }
        public void TestgetImmuneToWith1Type()
        {
            Type           type1check = Type.Steel;
            String         Expected   = "Poison";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getImmuneTo(type1check);

            Assert.AreEqual(Expected, check);
        }
        public void TestGetTypesSuperEffectiveAgainstWith2Type()
        {
            Type           type1check = Type.Dragon;
            Type           type2check = Type.Dark;
            String         Expected   = "Fighting Bug Ice Dragon Fairy";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getTypesSuperEffectiveAgainst(type1check, type2check);

            Assert.AreEqual(Expected, check);
        }
        public void TestgetTypesNotVeryEffectiveAgainstWith2Type()
        {
            Type           type1check = Type.Grass;
            Type           type2check = Type.Water;
            String         Expected   = "Ground Steel Water";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getTypesNotVeryEffectiveAgainst(type1check, type2check);

            Assert.AreEqual(Expected, check);
        }
        public void TestGetNotVeryEffectiveAgainstWith2Type()
        {
            Type           type1check = Type.Poison;
            Type           type2check = Type.Water;
            String         Expected   = "Poison Ghost Steel Water Dragon";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getNotVeryEffectiveAgainst(type1check, type2check);

            Assert.AreEqual(Expected, check);
        }
        public void TestgetTypesImmuneToItWith2Type()
        {
            Type           type1check = Type.Psychic;
            Type           type2check = Type.Ground;
            String         Expected   = "  Flying              Dark ";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getTypesImmuneToIt(type1check, type2check);

            Assert.AreEqual(Expected, check);
        }
        public void TestgetEffectivenessAgainstWith1Type()
        {
            Type           type1check = Type.Ghost;
            Type           Against    = Type.Normal;
            float          Expected   = 0.0f;
            TypeCalculator tc         = new TypeCalculator();
            float          check      = tc.getEffectivenessAgainst(type1check, Against);

            Assert.AreEqual(Expected, check);
        }
        public void TestgetImmuneToWith2Type()
        {
            Type           type1check = Type.Ghost;
            Type           type2check = Type.Rock;
            String         Expected   = "Normal Fighting";
            TypeCalculator tc         = new TypeCalculator();
            string         check      = tc.getImmuneTo(type1check, type2check);

            Assert.AreEqual(Expected, check);
        }
示例#15
0
            public override void Visit(WriteTemporaryExpression node)
            {
                var oldType = GetType(node);

                UpdateType(node, TypeCalculator.GetType(node));
                if (HasTypeChanged(node, oldType))
                {
                    VisitNodes(node.Users);
                }
            }
        public void TestCombineEffectivenesswith2EffectsAgainst()
        {
            Type type1check = Type.Ice;
            Type Type2check = Type.Rock;

            float[]        Expected = { 1.0f, 0.5f, 4.0f, 1.0f, 1.0f, 1.0f, 2.0f, 1.0f, 0.25f, 1.0f, 0.5f, 2.0f, 1.0f, 1.0f, 1.0f, 2.0f, 1.0f, 1.0f };
            TypeCalculator tc       = new TypeCalculator();

            float[] check = tc.CombineEffectiveness(type1check, Type2check);
            Assert.AreEqual(Expected, check);
        }
        public void TestgetDualTypeEffectivenessAgainstwith2EffectsAgainst()
        {
            Type           type1check = Type.Steel;
            Type           Type2check = Type.Psychic;
            Type           Against1   = Type.Normal;
            float          Expected   = 1.0f;
            TypeCalculator tc         = new TypeCalculator();
            float          check      = tc.getDualTypeEffectivenessAgainst(type1check, Type2check, Against1);

            Assert.AreEqual(Expected, check);
        }
        public void TestgetEffectivenessAgainstDualTypewith2EffectsAgainst()
        {
            Type           type1check = Type.Poison;
            Type           Against1   = Type.Normal;
            Type           Against2   = Type.Grass;
            float          Expected   = 2.0f;
            TypeCalculator tc         = new TypeCalculator();
            float          check      = tc.getEffectivenessAgainstDualType(type1check, Against1, Against2);

            Assert.AreEqual(Expected, check);
        }
示例#19
0
        private void BtnNatCalculator_Click(object sender, EventArgs e)
        {
            if (MsText.Text != "")
            {
                value2 = Convert.ToDouble(MsText.Text);
                switch (tc)
                {
                case TypeCalculator.jam:
                    MsText.Text = (value1 + value2).ToString();
                    ClaerValues();
                    break;

                case TypeCalculator.menha:
                    MsText.Text = (value1 - value2).ToString();
                    ClaerValues();
                    break;

                case TypeCalculator.zarb:
                    MsText.Text = (value1 * value2).ToString();
                    ClaerValues();
                    break;

                case TypeCalculator.taghsim:
                    if (value2 == 0)
                    {
                        MessageBox.Show("عدد بر صفر تقسیم نمیشود");
                        ClaerValues();
                    }
                    else
                    {
                        MsText.Text = (value1 / value2).ToString();
                        ClaerValues();
                    }
                    break;

                case TypeCalculator.nu:
                    break;

                case TypeCalculator.pow:
                    MsText.Text = (Math.Pow(value1, value2)).ToString();
                    ClaerValues();
                    break;

                default:
                    break;
                }
                tc = TypeCalculator.nu;
            }
            else
            {
                ClaerValues(); tc = TypeCalculator.nu;
            }
        }
        public void TestgetEffectivenessAgainstwith2EffectsAgainst()
        {
            Type           type1check = Type.Flying;
            Type           Type2check = Type.Ghost;
            Type           Against1   = Type.Ground;
            Type           Against2   = Type.Poison;
            float          Expected   = 1.0f;
            TypeCalculator tc         = new TypeCalculator();
            float          check      = tc.getEffectivenessAgainst(type1check, Type2check, Against1, Against2);

            Assert.AreEqual(Expected, check);
        }
示例#21
0
            public override void Visit(WriteIdentifierExpression node)
            {
                //TODO: Double check the alg
                var oldType = GetType(node);

                UpdateType(node, TypeCalculator.GetType(node));
                var newType = GetType(node);

                if (HasTypeChanged(node, oldType) || (GetType(node.Symbol) != newType))
                {
                    UpdateType(node.Symbol, GetType(node));
                }
            }
示例#22
0
            void UpdateType(Expression expression, mdr.ValueTypes type)
            {
                var oldType = GetType(expression);
                var newType = TypeCalculator.ResolveType(oldType, type);

                if (oldType != newType)
                {
                    m.Util.Diagnose.Debug.WriteLine("---->> Type of the expression {0} changed to {1}", expression.ToString(), newType.ToString());
                    SetType(expression, newType);
                    if (type == mdr.ValueTypes.Unknown)
                    {
                        Enqueue(expression);
                    }
                    else
                    {
                        VisitUser(expression);
                    }
                }
            }
示例#23
0
        public void SetTypeToUnknown()
        {
            //arrange
            TypeCalculator  calculator = new TypeCalculator();
            CelestialObject celestial  = new CelestialObject()
            {
                Name = "Z0 CVSO 30",
                Mass = 1.2e30,
                EquatorialDiameter = 90000000,
                SurfaceTemperature = 1000,
                DiscoveryDate      = new DateTime(2017 - 12 - 10),
                DiscoverySourceId  = 1
            };

            //act
            calculator.SetCelestialObjectType(celestial);

            //asert
            Assert.That(celestial.Type, Is.EqualTo("Unknown"));
        }
示例#24
0
        public void SetTypeToStar()
        {
            //arrange
            TypeCalculator  calculator = new TypeCalculator();
            CelestialObject celestial  = new CelestialObject()
            {
                Name = "V774 Sagittarii",
                Mass = 7.634e31,
                EquatorialDiameter = 1.6710622e10,
                SurfaceTemperature = 5800,
                DiscoveryDate      = new DateTime(2017 - 12 - 10),
                DiscoverySourceId  = 1
            };

            //act
            calculator.SetCelestialObjectType(celestial);

            //asert
            Assert.That(celestial.Type, Is.EqualTo("Star"));
        }
示例#25
0
        public void SetTypeToPlanet()
        {
            //arrange
            TypeCalculator  calculator = new TypeCalculator();
            CelestialObject celestial  = new CelestialObject()
            {
                Name = "OGLE-2005-BLG-390Lb",
                Mass = 3.17237e25,
                EquatorialDiameter = 21557978,
                SurfaceTemperature = 200,
                DiscoveryDate      = new DateTime(2017 - 12 - 10),
                DiscoverySourceId  = 1
            };

            //act
            calculator.SetCelestialObjectType(celestial);

            //asert
            Assert.That(celestial.Type, Is.EqualTo("Planet"));
        }
示例#26
0
        public void SetTypeToBlackhole()
        {
            //arrange
            TypeCalculator  calculator = new TypeCalculator();
            CelestialObject celestial  = new CelestialObject()
            {
                Name = "X1 Messier 87",
                Mass = 1.3e40,
                EquatorialDiameter = 11600000,
                SurfaceTemperature = 2000,
                DiscoveryDate      = new DateTime(2017 - 12 - 10),
                DiscoverySourceId  = 1
            };

            //act
            calculator.SetCelestialObjectType(celestial);

            //asert
            Assert.That(celestial.Type, Is.EqualTo("Blackhole"));
        }
示例#27
0
        private void BtnMainCalc_Click(object sender, EventArgs e)
        {
            string Oprator = sender.ToString().Substring(sender.ToString().Length - 1, 1);

            if (MsText.Text == "" && Oprator == "-")
            {
                MsText.Text = "-";
            }
            else
            {
                switch (Oprator)
                {
                case "/":
                    tc     = TypeCalculator.taghsim;
                    value1 = Convert.ToDouble(MsText.Text);
                    Tcn    = true;
                    break;

                case "*":
                    tc     = TypeCalculator.zarb;
                    value1 = Convert.ToDouble(MsText.Text);
                    Tcn    = true;
                    break;

                case "-":
                    tc     = TypeCalculator.menha;
                    value1 = Convert.ToDouble(MsText.Text);
                    Tcn    = true;
                    break;

                case "+":
                    tc     = TypeCalculator.jam;
                    value1 = Convert.ToDouble(MsText.Text);
                    Tcn    = true;
                    break;

                default:
                    break;
                }
            }
        }
示例#28
0
            void UpdateType(JSSymbol symbol, mdr.ValueTypes type)
            {
                if (type == mdr.ValueTypes.Unknown)
                {
                    return;
                }

                var oldType = GetType(symbol);
                var newType = TypeCalculator.ResolveType(oldType, type);

                switch (newType)
                {
                case mdr.ValueTypes.Undefined:
                case mdr.ValueTypes.Null:
                case mdr.ValueTypes.Unknown:
                    newType = mdr.ValueTypes.DValueRef; //All of these cases are handled by a DValue
                    break;

                case mdr.ValueTypes.DValue:
                    if (symbol.IsParameter)
                    {
                        //We already have a DValue as argument, so just need to point to that and use its storage
                        newType = mdr.ValueTypes.DValueRef;
                    }
                    break;
                }

                if (oldType != newType)
                {
                    m.Util.Diagnose.Debug.WriteLine("---->> Type of the symbol {0} changed to {1}", symbol.Name.ToString(), newType.ToString());
                    SetType(symbol, newType);
                    //symbol.Types.Add(type);
                    foreach (var r in symbol.Readers)
                    {
                        Enqueue(r);
                    }
                }
            }
示例#29
0
 private void BtnPow_Click(object sender, EventArgs e)
 {
     value1 = double.Parse(MsText.Text);
     tc     = TypeCalculator.pow; Tcn = true;
 }
 public CelestialObjectController(IMapper mapper, ICatalogRepository catalogRepository, TypeCalculator typeCalculator)
 {
     _mapper            = mapper;
     _catalogRepository = catalogRepository;
     _typeCalculator    = typeCalculator;
 }