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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Here f is a new (second order) symbol – a name for the function defined by the program. In<br />

the case <strong>of</strong> recursive programs, f may occur in some p i ’s <strong>and</strong> g i ’s.<br />

Each <strong>of</strong> the n paths <strong>of</strong> the program has associated a object–level formula p i [x] – the accumulated<br />

If–conditions on that path, <strong>and</strong> the object–level term g i [x] – the symbolic expression <strong>of</strong> the<br />

return value obtained by composing all the assignments (symbolic execution). Note that p i [x] <strong>and</strong><br />

g i [x] do not contain other free variables than x.<br />

The computing idea for the program semantics Σ is as follows: Σ works by forward symbolic<br />

execution on all branches <strong>of</strong> the program, using as state the current substitution for the active<br />

variables. Σ produces a conjunction <strong>of</strong> clauses – conditional definitions for f[x]. Each clause depends<br />

on the accumulated [negated] conditions <strong>of</strong> the If statements leading to a certain Return<br />

statement, whose argument (symbolically evaluated) represents the corresponding value <strong>of</strong> f[x].<br />

Definition 2.2.2.<br />

( )<br />

1. Σ[P ] = Σ[{¯x → ¯x0 }, P ] { ¯x0 →¯x}<br />

∀¯x<br />

2. Σ[σ, 〈Return[t]〉 ⌣ P ] = (f[ ¯x 0 ] = tσ)<br />

3. Σ[σ, 〈v := t〉 ⌣ P ] = Σ[σ ◦ {v → tσ}, P ]<br />

4. Σ[σ, 〈If[ϕ, P T , P F ]〉 ⌣ P ] = ∧ { ϕσ =⇒ Σ[σ, P T ⌣ P ]<br />

¬ϕσ =⇒ Σ[σ, P F ⌣ P ]<br />

When the execution <strong>of</strong> the program starts, all the input variables become active by instantiating<br />

them with corresponding symbolic values. After the program is processed all the input variables<br />

become universally quantified (Definition 2.2.2.1).<br />

A Return statement (Definition 2.2.2.2) determines the computation <strong>of</strong> the output state. From<br />

this state we are interested in the program function <strong>and</strong> its computed values (the argument t <strong>of</strong> the<br />

Return statement).<br />

The assignment statement (Definition 2.2.2.3) updates the current state.<br />

For a conditional (Definition 2.2.2.4), there are two different expressions for the program<br />

function to be computed: one when the symbolic formula ϕσ might hold <strong>and</strong> one in the opposite<br />

case.<br />

Remarks.<br />

1. The way Σ h<strong>and</strong>les the If statement ensures:<br />

covered) <strong>and</strong> ∀<br />

i≠j<br />

p i ∧ p j = F (branches are mutually disjoint).<br />

∨<br />

i=1,n<br />

p i = I f (all branches are<br />

2. The program function Σ effectively translates an imperative program into a functional program.<br />

From this point on, one could reason about the program using the Scott fixpoint<br />

theory ([LSS84], pag. 86), however we prefer a purely logical approach.

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

Saved successfully!

Ooh no, something went wrong!