13.06.2014 Views

Automated Formal Static Analysis and Retrieval of Source Code - JKU

Automated Formal Static Analysis and Retrieval of Source Code - JKU

Automated Formal Static Analysis and Retrieval of Source Code - JKU

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.2. FORWARD SYMBOLIC EXECUTION IN THE THEOREMA SYSTEM 17<br />

8. Γ[σ, Φ, 〈If[ϕ τ←u[γ] , P T , P F ]〉 ⌣ P ] =<br />

Γ[σ, Φ, 〈w := u[γ], If[ϕ τ←w , P T , P F ]〉 ⌣ P ]<br />

9. Γ[σ, Φ, 〈If[ϕ, P T , P F ]〉 ⌣ P ] = ∧ { Γ[σ, Φ ∧ ϕσ, P T ⌣ P ]<br />

Γ[σ, Φ ∧ ¬ϕσ, P F ⌣ P ]<br />

The verification conditions corresponding to the program P are generated as follows: we<br />

start analyzing the program P <strong>and</strong>, in the first step (Definition 2.2.3.1), we create the substitution<br />

{¯x → ¯x 0 } (all the input variables are initialized in the initial state) <strong>and</strong> the path condition I P [ ¯x 0 ]<br />

(the input condition has to be fulfilled before the program analysis).<br />

The meta-level function Γ analyzes each statement <strong>of</strong> the program as follows:<br />

• a composed term (definitions 2.2.3.3, 2.2.3.7 <strong>and</strong> 2.2.3.8) is first decomposed such that no<br />

nested functions are present. After the decomposition, we analyze its parts separately.<br />

• a Return statement (Definition 2.2.3.2) finishes the execution <strong>of</strong> the program on the current<br />

path <strong>and</strong> a functional verification condition is generated. The formula representing the<br />

postcondition depends on the input variable <strong>and</strong> the term returned by the Return statement.<br />

The statements after the Return statement are ignored;<br />

• a constant or variable assignment (Definition 2.2.3.4) updates the substitution σ, while a<br />

function (definitions 2.2.3.5 <strong>and</strong> 2.2.3.6) <strong>and</strong> term assignments (Definition 2.2.3.7), have to<br />

be treated in the following way: safety verification conditions have to be generated for every<br />

function (including f): the arguments <strong>of</strong> them must satisfy the respective input condition<br />

<strong>and</strong> afterwards the analysis <strong>of</strong> the program continues with the input condition <strong>of</strong> the function<br />

as new assumption ;<br />

• a conditional analysis determines the forking <strong>of</strong> the program into two branches: one when<br />

ϕ evaluates to T rue <strong>and</strong> one in the opposite case. The branch P F <strong>of</strong> the program might be<br />

also the empty tuple, case which corresponds to the If statement with one branch.<br />

The order <strong>of</strong> the above clauses <strong>of</strong> Γ has a semantic meaning. Namely, we use this as an<br />

abbreviation for additional conditions which should be added to the clauses <strong>of</strong> the definition in<br />

order to specify that, for instance, the equality from the Definition 2.2.3.9 is applied only if no<br />

subterm <strong>of</strong> ϕ is <strong>of</strong> the form u[γ] – as specified in the clause from the Definition 2.2.3.7.<br />

2.2.2.4 Termination<br />

We want to generate verification conditions which insure that a program is correct with respect<br />

to a specification composed <strong>of</strong> two object–level formulae: the input condition I f [x] <strong>and</strong> the<br />

output condition O f [x, y]. Apparently, the correctness could be expressed as: “The formula<br />

∀<br />

x<br />

I f [x] ⇒ O f [x, P [x]] is a logical consequence <strong>of</strong> the theory Υ augmented with Σ[P ] <strong>and</strong> with<br />

the verification conditions.” However, this always holds in the case that Σ[P ] is contradictory to<br />

Υ, which may happen when the program is recursive. Therefore, it is crucial that the existence<br />

(<strong>and</strong> possibly the uniqueness) <strong>of</strong> a f satisfying Σ[P ] is a logical consequence <strong>of</strong> the object theory<br />

augmented with the verification conditions. More concretely, before using Σ[P ] as an assumption,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!