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 13<br />

2.2 Forward Symbolic Execution in the Theorema System<br />

We integrated in the Theorema system a new verification environment based on symbolic execution<br />

([Cow88, Kin76, HK76]), forward reasoning ([Dro90, LSS84]) <strong>and</strong> functional semantics<br />

[McC63] for imperative program verification.<br />

2.2.1 Basic Notions<br />

A state σ is a set <strong>of</strong> replacements <strong>of</strong> the form {var → expr} with the meaning that every program<br />

variable is initialized. We call the initialized variables – active variables. We also write sometimes<br />

{var → expr} instead <strong>of</strong> {var 1 → expr 1 , var 2 → expr 2 , ...}.<br />

Statements are used for building up programs. We use the following programming language<br />

constructs: the abrupt statement Return, assignments (including recursive calls) <strong>and</strong> conditionals<br />

(If with one <strong>and</strong> two branches). Recursive calls <strong>and</strong> conditionals insure the universality <strong>of</strong> the<br />

programming language.<br />

The specification <strong>of</strong> a program P is the tuple 〈I P , O P 〉, where I P is a first-order logic input<br />

condition predicate <strong>and</strong> O P is a first-order logic output condition predicate. The program<br />

correctness is proved relatively to its specification.<br />

Forward reasoning was chosen in conjunction with symbolic execution for program analysis<br />

because it follows naturally the execution <strong>of</strong> programs. The principle is as follows: we start from<br />

the precondition <strong>of</strong> the program <strong>and</strong> apply a set <strong>of</strong> inference rules, depending on the type <strong>of</strong> the<br />

program statement currently analyzed, <strong>and</strong> obtain a conjunction <strong>of</strong> formulae. The postcondition<br />

<strong>of</strong> the program must be a logical consequence <strong>of</strong> the modified input condition.<br />

In the program verification approaches using functional semantics, the flowchart <strong>of</strong> a program<br />

is transformed into a function from its input state to its output state. We use this approach for<br />

computing the program function which helps in defining the program semantics.<br />

The approach that we integrated in the Theorema system is purely logical. We assume that the<br />

properties <strong>of</strong> the constants, functions <strong>and</strong> predicates which are used in the program are specified<br />

in an object theory Υ. (By a theory we underst<strong>and</strong> a set <strong>of</strong> formulae in the language <strong>of</strong> predicate<br />

logic with equality.) For the purpose <strong>of</strong> reasoning about imperative programs we construct a<br />

certain meta–theory containing the properties <strong>of</strong> the meta–predicate Π (which checks a program<br />

for syntactical correctness) <strong>and</strong> the meta–functions Σ (which defines the semantics <strong>of</strong> a program),<br />

Γ (which generates the verification conditions) <strong>and</strong> Θ (which generates the termination condition).<br />

The programming language constructs (statements), the program itself, as well as the terms <strong>and</strong><br />

the formulae from the object theory are meta–terms from the point <strong>of</strong> view <strong>of</strong> the meta-theory,<br />

<strong>and</strong> they behave like quoted (because the meta–theory does not contain any equalities between<br />

programming constructs, <strong>and</strong> also does not include the object theory).<br />

2.2.2 A Meta-Logic for Reasoning about Imperative Programs<br />

2.2.2.1 Syntax<br />

We define the meta–level predicate Π for checking the appropriate syntax for the programs <strong>and</strong>,<br />

additionally, if every variable used in the program is active <strong>and</strong> if every branch <strong>of</strong> the program has<br />

a Return statement.

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

Saved successfully!

Ooh no, something went wrong!