//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.Text;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using Microsoft.Basetypes;
// A translator from the Boogie AST to the VCExpr AST.
// This was previously realised in the methods AbsyExpr.VCView
namespace Microsoft.Boogie.VCExprAST {
using Microsoft.Boogie;
public class VCGenerationOptions {
private readonly List/*!*/ SupportedProverCommands;
[ContractInvariantMethod]
void ObjectInvariant() {
Contract.Invariant(cce.NonNullElements(SupportedProverCommands));
}
public bool IsProverCommandSupported(string kind) {
Contract.Requires(kind != null);
return SupportedProverCommands.Contains(kind);
}
public bool IsAnyProverCommandSupported(string kinds) {
Contract.Requires(kinds != null);
if (kinds.IndexOf(',') < 0) {
return IsProverCommandSupported(kinds);
} else {
return Contract.Exists(kinds.Split(',', ' '), k => IsProverCommandSupported(k));
}
}
public VCGenerationOptions(List/*!*/ supportedProverCommands) {
Contract.Requires(cce.NonNullElements(supportedProverCommands));
this.SupportedProverCommands = supportedProverCommands;
}
}
public delegate VCExpr/*!*/ CodeExprConverter(CodeExpr/*!*/ codeExpr, Hashtable/**//*!*/ blockVariables, List bindings);
public class Boogie2VCExprTranslator : StandardVisitor, ICloneable {
// Stack on which the various Visit-methods put the result of the translation
private readonly Stack/*!*/ SubExpressions = new Stack();
[ContractInvariantMethod]
void ObjectInvariant() {
Contract.Invariant(cce.NonNullElements(SubExpressions));
Contract.Invariant(Gen != null);
}
private void Push(VCExpr expr) {
Contract.Requires(expr != null);
SubExpressions.Push(expr);
}
private VCExpr Pop() {
Contract.Ensures(Contract.Result() != null);
return SubExpressions.Pop();
}
public VCExpr Translate(Expr expr) {
Contract.Requires(expr != null);
Contract.Ensures(Contract.Result() != null);
this.Visit(expr);
return Pop();
}
public List/*!*/ Translate(ExprSeq exprs) {
Contract.Requires(exprs != null);
Contract.Ensures(cce.NonNullElements(Contract.Result>()));
List/*!*/ res = new List();
foreach (Expr e in exprs)
res.Add(Translate(cce.NonNull(e)));
return res;
}
///////////////////////////////////////////////////////////////////////////////
internal readonly VCExpressionGenerator/*!*/ Gen;
public Boogie2VCExprTranslator(VCExpressionGenerator gen,
VCGenerationOptions genOptions) {
Contract.Requires(gen != null);
Contract.Requires(genOptions != null);
this.Gen = gen;
this.GenerationOptions = genOptions;
UnboundVariables = new VariableMapping();
BoundVariables = new VariableMapping();
Formals = new VariableMapping();
}
private Boogie2VCExprTranslator(Boogie2VCExprTranslator tl) {
Contract.Requires(tl != null);
this.Gen = tl.Gen;
this.GenerationOptions = tl.GenerationOptions;
UnboundVariables =
(VariableMapping)tl.UnboundVariables.Clone();
BoundVariables = new VariableMapping();
Formals = new VariableMapping();
}
public object Clone() {
Contract.Ensures(Contract.Result