public class VerificationConditionGenerator extends Object
Responsible for generating verification conditions from a given WyIL file. A verification condition is a logical condition which must be shown to hold in order for the underlying WyIL program to considered "correct". The Verification Condition Generator (VCG) examines in turn each function or method in a given WyIL file. The VCG traverses each control-flow graph emitting verification conditions as it discovers them. The following illustrates:
function abs(int x) -> (int r)
ensures r >= 0:
//
if x >= 0:
return x
else:
return -x
The above function can be viewed in a slightly more precise fashion as follows, where the block structure is indicated:
+-----------------------------+ (1) |function abs(int x) -> (int r) |ensures r >= 0: | +--------------------------+ (2) | | // | | if x >= 0: | | +----------------------+ (3) | | | return x | | +----------------------+ | | else: | | +----------------------+ (4) | | | return -x | | +----------------------+ | +--------------------------+ +-----------------------------+
The VCG will generate exactly two verification conditions from this function corresponding to the paths "1,2,3" and "1,2,4". These verification conditions are required to ensure that, given the information know at the point of each return, we can establish the post-condition holds. The two verification conditions are:
x >= 0 ==> x >= 0. This verification
corresponds to the case where the if condition is known to be true.x < 0 ==> -x >= 0. This verification
corresponds to the case where the if condition is known to be false.The VCG attempts to generate verification conditions which are easier to read by making use of macros as much as possible. For example, each clause of a function/method's precondition or postcondition is turned into a distinct (named) macro.
| Constructor and Description |
|---|
VerificationConditionGenerator(wyal.lang.WyalFile wyalFile,
Wyil2WyalBuilder builder) |
| Modifier and Type | Method and Description |
|---|---|
wyal.lang.WyalFile.Stmt.Block |
buildVerificationCondition(WyilFile.FunctionOrMethod declaration,
wyil.builders.VerificationConditionGenerator.GlobalEnvironment environment,
wyil.builders.VerificationConditionGenerator.VerificationCondition vc)
Construct a fully typed and quantified expression for representing a
verification condition.
|
static int[] |
flattern(int[][] groups) |
void |
freeVariables(wyal.lang.SyntacticItem e,
Set<wyal.lang.WyalFile.VariableDeclaration> freeVars)
Determine all free variables which are used within the given expression.
|
SyntaxTree.Location<Bytecode.VariableDeclaration> |
getVariableDeclaration(SyntaxTree.Location<?> decl) |
wyal.lang.WyalFile.Expr |
invertCondition(wyal.lang.WyalFile.Expr expr,
SyntaxTree.Location<?> elem)
Generate the logically inverted expression corresponding to a given
comparator.
|
wyal.lang.WyalFile.Expr[] |
invertConditions(wyal.lang.WyalFile.Expr[] expr,
SyntaxTree.Location<?> elem) |
WyilFile.FunctionOrMethodOrProperty |
lookupFunctionOrMethodOrProperty(wybs.lang.NameID name,
Type.FunctionOrMethod fun,
SyntaxTree.Location<?> stmt)
Lookup a given function or method.
|
wyal.lang.WyalFile |
translate(WyilFile wyilFile)
Translate a WyilFile into a WyalFile which contains the verification
conditions necessary to establish that all functions and methods in the
WyilFile meet their specifications, and that no array-out-of-bounds or
division-by-zero exceptions are possible (amongst other things).
|
public VerificationConditionGenerator(wyal.lang.WyalFile wyalFile,
Wyil2WyalBuilder builder)
public wyal.lang.WyalFile translate(WyilFile wyilFile)
wyilFile - The input file to be translatedpublic wyal.lang.WyalFile.Stmt.Block buildVerificationCondition(WyilFile.FunctionOrMethod declaration, wyil.builders.VerificationConditionGenerator.GlobalEnvironment environment, wyil.builders.VerificationConditionGenerator.VerificationCondition vc)
vc - environment - public void freeVariables(wyal.lang.SyntacticItem e,
Set<wyal.lang.WyalFile.VariableDeclaration> freeVars)
e - freeVars - public WyilFile.FunctionOrMethodOrProperty lookupFunctionOrMethodOrProperty(wybs.lang.NameID name, Type.FunctionOrMethod fun, SyntaxTree.Location<?> stmt) throws Exception
name - --- Fully qualified name of functionfun - --- Type of fucntion.block - --- Enclosing block (for debugging purposes).branch - --- Enclosing branch (for debugging purposes).Exceptionpublic wyal.lang.WyalFile.Expr invertCondition(wyal.lang.WyalFile.Expr expr,
SyntaxTree.Location<?> elem)
test - --- the binary comparator being inverted.public wyal.lang.WyalFile.Expr[] invertConditions(wyal.lang.WyalFile.Expr[] expr,
SyntaxTree.Location<?> elem)
public static int[] flattern(int[][] groups)
public SyntaxTree.Location<Bytecode.VariableDeclaration> getVariableDeclaration(SyntaxTree.Location<?> decl)
Copyright © 2017. All rights reserved.