Пример #1
0
 internal DafnyModelVariable(DafnyModelState state, Model.Element element,
                             string name, DafnyModelVariable parent)
 {
     this.state = state;
     Element    = element;
     Type       = state.Model.GetDafnyType(element);
     children   = new Dictionary <string, HashSet <DafnyModelVariable> >();
     state.AddVar(element, this);
     if (parent == null)
     {
         Name = name;
     }
     else
     {
         // TODO: a case can be made for refactoring this so that the indices
         // are model-wide rather than state-wide
         Name = "@" + state.VarIndex++;
         parent.AddChild(name, this);
     }
     state.AddVarName(ShortName);
 }
Пример #2
0
 /// <summary>
 /// Create a new variable to be associated with the given model element in
 /// a given counterexample state or return such a variable if one already
 /// exists.
 /// </summary>
 /// <param name="state"></param>
 /// <param name="element"></param>
 /// <param name="name">the name to be assigned to the variable OR,
 /// if parent != null, the name of the field associated with it. In the later
 /// case, Name is set to some unique id.</param>
 /// <param name="parent">if not null, this variable represents the field of
 /// some parent object</param>
 /// <param name="duplicate">forces the creation of a new variable even if
 /// one already exists </param>
 /// <returns></returns>
 public static DafnyModelVariable Get(DafnyModelState state,
                                      Model.Element element, string name, DafnyModelVariable parent = null,
                                      bool duplicate = false)
 {
     if (state.ExistsVar(element))
     {
         parent?.AddChild(name, state.GetVar(element));
         if (!duplicate)
         {
             return(state.GetVar(element));
         }
         return(new DuplicateVariable(state, state.GetVar(element), name, parent));
     }
     if (state.Model.GetDafnyType(element).Name == "seq")
     {
         return(new SeqVariable(state, element, name, parent));
     }
     if (state.Model.GetDafnyType(element).Name == "map")
     {
         return(new MapVariable(state, element, name, parent));
     }
     return(new DafnyModelVariable(state, element, name, parent));
 }
Пример #3
0
 internal SeqVariable(DafnyModelState state, Model.Element element, string name, DafnyModelVariable parent)
     : base(state, element, name, parent)
 {
     seqLength   = null;
     seqElements = new Dictionary <int, DafnyModelVariable>();
 }
Пример #4
0
 internal DuplicateVariable(DafnyModelState state, DafnyModelVariable original, string newName, DafnyModelVariable parent)
     : base(state, original.Element, newName, parent)
 {
     Original = original;
 }