Exemplo n.º 1
0
        public string ShortName()
        {
            if (shortName != null)
            {
                return(shortName);
            }

            FunApp best = BestApp();

            shortName = Id;
            shortName = best.ShortName();

            return(shortName);
        }
Exemplo n.º 2
0
        public FunApp BestApp()
        {
            if (bestApp != null)
            {
                return(bestApp);
            }

            int cntMin     = 0;
            int minBadness = 0;

            foreach (var f in Values)
            {
                int cur = model.FunAppBadness(f);
                if (bestApp == null || cur <= minBadness)
                {
                    if (minBadness < cur)
                    {
                        cntMin = 0;
                    }
                    cntMin++;
                    minBadness = cur;
                    bestApp    = f;
                }
            }

            if (cntMin > 1)
            {
                string prevName = bestApp.ShortName();
                foreach (var f in Values)
                {
                    int cur = model.FunAppBadness(f);
                    if (cur == minBadness)
                    {
                        string curName = f.ShortName();
                        if (curName.Length < prevName.Length ||
                            (curName.Length == prevName.Length && string.CompareOrdinal(curName, prevName) < 0))
                        {
                            prevName = curName;
                            bestApp  = f;
                        }
                    }
                }
            }

            return(bestApp);
        }
Exemplo n.º 3
0
        public Partition PartitionByName(string name)
        {
            Partition part;

            if (modelPartsByName.TryGetValue(name, out part))
            {
                return(part);
            }
            part       = new Partition();
            part.Id    = name;
            part.model = this;
            modelPartsByName.Add(name, part);

            FunSymbol consts = FunSymbolByName(name);
            FunApp    fapp   = new FunApp();

            fapp.Fun   = consts;
            fapp.Args  = new Partition[0];
            fapp.Value = part;
            consts.Apps.Add(fapp);
            part.Values.Add(fapp);

            return(part);
        }
Exemplo n.º 4
0
        public virtual int FunAppBadness(FunApp f)
        {
            // TODO read rules from file

            string fn = f.Fun.Name;

            switch (fn)
            {
            case "$ghost_emb":
            case "$int_to_ptrset":
            case "$int_to_ptr":
                return(100);

            case "$array":
            case "$ptr":
                return(40);

            case "$phys_ptr_cast":
            case "$spec_ptr_cast":
            case "$field_plus":
                return(35);

            case "$idx_prim":
            case "$dot":
                return(30);

            case "$read_ptr_m":
                return(35);

            default:
                if (fn.StartsWith("#distTp"))
                {
                    return(100);
                }
                if (fn.StartsWith("$st_"))
                {
                    return(60);
                }

                // general
                if (fn.StartsWith("unique-value!"))
                {
                    return(100);
                }
                if (fn.StartsWith("val!") || IsV1Part(fn))
                {
                    return(200);
                }
                if (fn.StartsWith("call") && (fn.Contains("formal@") || fn.Contains("formal_")))
                {
                    return(100);
                }

                if (f.Args.Length == 0)
                {
                    return(20);
                }

                return(f.Args.Length + 50);
            }
        }