/// <summary> /// A copy constructor that allocates an instance that is the same as the given template, except for its containing block. /// </summary> /// <param name="containingBlock">The containing block of the copied type invariant. This should be different from the containing block of the template.</param> /// <param name="template">The statement to copy.</param> protected TypeInvariant(BlockStatement containingBlock, TypeInvariant template) : base(containingBlock, template) { if (template.Name != null) this.name = template.Name.MakeCopyFor(containingBlock.Compilation); this.isAxiom = template.isAxiom; }
/// <summary> /// Visits the specified type invariant. /// </summary> /// <param name="typeInvariant">The type invariant.</param> protected virtual ITypeInvariant DeepCopy(TypeInvariant typeInvariant) { typeInvariant.Condition = this.Substitute(typeInvariant.Condition); if (typeInvariant.Description != null) typeInvariant.Description = this.Substitute(typeInvariant.Description); return typeInvariant; }
/// <summary> /// Get the mutable copy of a type invariant. /// </summary> /// <param name="typeInvariant"></param> /// <returns></returns> public virtual TypeInvariant GetMutableCopy(ITypeInvariant typeInvariant) { object cachedValue; if (this.cache.TryGetValue(typeInvariant, out cachedValue)) return (TypeInvariant)cachedValue; var result = new TypeInvariant(typeInvariant); // Probably not necessary, no two thrown exceptions are shared. this.cache.Add(typeInvariant, result); this.cache.Add(result, result); return result; }
/// <summary> /// Rewrites the children of the given type invariant. /// </summary> public virtual void RewriteChildren(TypeInvariant typeInvariant) { this.RewriteChildren((ContractElement)typeInvariant); }
/// <summary> /// Visits the specified type invariant. /// </summary> /// <param name="typeInvariant">The type invariant.</param> public virtual ITypeInvariant Visit(TypeInvariant typeInvariant) { typeInvariant.Condition = this.Visit(typeInvariant.Condition); if (typeInvariant.Description != null) typeInvariant.Description = this.Visit(typeInvariant.Description); return typeInvariant; }
/// <summary> /// Visits the specified type invariant. /// </summary> /// <param name="typeInvariant">The type invariant.</param> public virtual ITypeInvariant Visit(ITypeInvariant typeInvariant) { TypeInvariant mutableTypeInvariant = typeInvariant as TypeInvariant; if (!this.copyOnlyIfNotAlreadyMutable || mutableTypeInvariant == null) mutableTypeInvariant = new TypeInvariant(typeInvariant); return this.Visit(mutableTypeInvariant); }