Beispiel #1
0
            public FieldName(Model.Element elt, DafnyModel dm)
            {
                Field    = elt;
                NameArgs = new Model.Element[Dims];
                var tpl = dm.f_dim.AppWithArg(0, elt);

                if (tpl != null)
                {
                    Dims     = tpl.Result.AsInt();
                    NameArgs = new Model.Element[Dims];
                    for (int i = Dims; 0 <= --i;)
                    {
                        if (i == 0)
                        {
                            tpl         = dm.f_index_field.AppWithResult(elt);
                            NameArgs[i] = tpl.Args[0];
                        }
                        else
                        {
                            tpl         = dm.f_multi_index_field.AppWithResult(elt);
                            NameArgs[i] = tpl.Args[1];
                            elt         = tpl.Args[0];
                        }
                    }
                }
                // now for the name
                if (Dims == 0)
                {
                    NameFormat = Field.ToString();
                    foreach (var n in Field.Names)
                    {
                        NameFormat = n.Func.Name;
                        int dot = NameFormat.LastIndexOf('.');
                        if (0 <= dot)
                        {
                            NameFormat = NameFormat.Substring(dot + 1);
                        }
                        break;
                    }
                }
                else
                {
                    NameFormat = "[";
                    string sep = "";
                    for (int i = 0; i < Dims; i++)
                    {
                        NameFormat += sep + "%" + i;
                        sep         = ",";
                    }
                    NameFormat += "]";
                }
            }
Beispiel #2
0
 private static string ExtractValueFromModelElement(Model.Element Element)
 {
     if (Element is Model.BitVector)
     {
         return(((Model.BitVector)Element).Numeral);
     }
     else if (Element is Model.Uninterpreted)
     {
         return("<irrelevant>");
     }
     else if (Element == null)
     {
         return("<null>");
     }
     return(Element.ToString()); //"<unknown>";
 }
Beispiel #3
0
        // Elements (other than integers and Booleans) get canonical names of the form
        // "<base>'<idx>", where <base> is returned by this function, and <idx> is given
        // starting with 0, and incrementing when there are conflicts between bases.
        //
        // This function needs to return an appropriate base name for the element. It is given
        // the element.
        //
        // A reasonable strategy is to check if it's a name of the local, and if so return it,
        // and otherwise use the type of element (e.g., return "seq" for elements representing
        // sequences). It is also possible to return "" in such cases.
        //
        // The suff output parameter specifies whether the number sequence suffix should be
        // always added, only when it's non-zero, or never.
        protected virtual string CanonicalBaseName(Model.Element elt, out NameSeqSuffix suff)
        {
            string res;

            if (elt is Model.Integer || elt is Model.Boolean)
            {
                suff = NameSeqSuffix.None;
                return(elt.ToString());
            }
            suff = NameSeqSuffix.Always;
            if (UseLocalsForCanonicalNames)
            {
                if (localValue.TryGetValue(elt, out res))
                {
                    return(res);
                }
            }
            return("");
        }
Beispiel #4
0
 public FieldName(Model.Element elt, DafnyModel dm) {
   Field = elt;
   NameArgs = new Model.Element[Dims];
   var tpl = dm.f_dim.AppWithArg(0, elt);
   if (tpl != null) {
     Dims = tpl.Result.AsInt();
     NameArgs = new Model.Element[Dims];
     for (int i = Dims; 0 <= --i; ) {
       if (i == 0) {
         tpl = dm.f_index_field.AppWithResult(elt);
         NameArgs[i] = tpl.Args[0];
       } else {
         tpl = dm.f_multi_index_field.AppWithResult(elt);
         NameArgs[i] = tpl.Args[1];
         elt = tpl.Args[0];
       }
     }
   }
   // now for the name
   if (Dims == 0) {
     NameFormat = Field.ToString();
     foreach (var n in Field.Names) {
       NameFormat = n.Func.Name;
       int dot = NameFormat.LastIndexOf('.');
       if (0 <= dot)
         NameFormat = NameFormat.Substring(dot + 1);
       break;
     }
   } else {
     NameFormat = "[";
     string sep = "";
     for (int i = 0; i < Dims; i++) {
       NameFormat += sep + "%" + i;
       sep = ",";
     }
     NameFormat += "]";
   }
 }