[dir] Zum Verzeichnisinhalt     [exercise] Zum Aufgabenblatt     [download] (SHIFT + Linke Maustaste)
@=~
~p maximum_input_line_length = infinity

~A~<Variable Usage~>

The style guide requires that a program must not have variables
which are never used. 
Furthermore programs must not rely upon default initialisation. 
Hence each variable must be assigned to before it is used. 

You decide to suggest to your manager that the programmers 
should use lint before they release their programs. 
Inspite of that you try to let your analysis tool check these 
requirements, and compare the results with those of lint. 

For the program

~O~<vars.in~>~{~-
{ int a, b, c, d, e;
  int f;
  int a;

  a = read (x);
  b = a + c;
  c = a * c;
  e = d + a;
  print (e);
}
~}

your analysis tool shall produce messages like

~O~<vars.out~>~{~-
"vars.in", line 5:13 ERROR: variable is not defined
"vars.in", line 1:7 ERROR: variable is multiply defined
"vars.in", line 2:7 WARNING: variable is never used
"vars.in", line 3:7 ERROR: variable is multiply defined
"vars.in", line 5:13 WARNING: variable is used before set
"vars.in", line 6:11 WARNING: variable is used before set
"vars.in", line 7:11 WARNING: variable is used before set
"vars.in", line 8:7 WARNING: variable is used before set
~}

The following questions may help to focus your attention on the
significant aspects of this problem:

1. Decompose the whole task into subproblems: a name analysis
task and several single tasks which need to compute a property
of variables each. Solve the tasks separately.

2. How do you solve the name analysis task?

3. For each property subtask answer the following questions:
What are the property values? 
In which contexts is the property to be set?
In which contexts is the property to be read?
What is the sequencing relation between setting and reading
the property.

4. Discuss the write before read subproblem for the
statement ~{c = a * c;~}.

~B~<Solution~>

Name Analysis:

Fill in the description of your solution here.

~$~<Name analysis module instance~>~{
/* Fill in your module instantiation here. */
~}

~$~<Name analysis module roles~>~{

/* Fill in your Lido specification here. */

~}

Check Variable Definitions:

Fill in the description of your solution here.

~$~<Undefined variables~>~{

/* Fill in your Lido specification here. */

~}

~$~<Multiple definitions property~>~{

/* Fill in your PDL specification here. */

~}

~$~<Definition state macros~>~{

/* Fill in cpp macro definitions here */

~}


~$~<Multiple definitions~>~{

/* Fill in your Lido specification here. */

~}

Used Variables:

Fill in the description of your solution here.

~$~<Used property~>~{

/* Fill in your PDL specification here. */

~}

~$~<Uses of variables~>~{

/* Fill in your Lido specification here. */

~}

Read before Write:

Fill in the description of your solution here.

~$~<Is written property~>~{

/* Fill in your PDL specification here. */

~}

~$~<Variable access computation~>~{

/* Fill in your Lido specification here. */

~}

~B~<Further Questions~>

1. Do you know a library module role that supports the check
for undefind variables?

2. Do you know a library module that supports the check
for multiple definitions?

3. How did you solve the problem that a variable use in the
right-hand side of an assignment has to be considered
before the left-hand side? Do you see alternative solutions?

~B~<Output files~>

~O~<vars.specs~>~{
~<Name analysis module instance~>
~}

~O~<vars.lido~>~{
~<Name analysis module roles~>
~<Undefined variables~>
~<Multiple definitions~>
~<Uses of variables~>
~<Variable access computation~>
~}

~O~<vars.pdl~>~{
~<Multiple definitions property~>
~<Used property~>
~<Is written property~>
~}

~O~<vars.head~>~{
~<Definition state macros~>
~}