This commit is contained in:
Carlos Galindo 2019-12-14 15:27:01 +01:00
parent f6c407e074
commit 6e2ab8afd1
8 changed files with 488 additions and 23 deletions

22
figs/problem1.dot Normal file
View file

@ -0,0 +1,22 @@
digraph pdf {
entry [label="enter f()",style=filled];
entry -> {while; D};
while [label="while (X)",style=filled];
C [style="bold,filled"]
"if (Y)" [style=filled]
"if (Z)" [style=filled]
while -> {"if (Y)" C};
break2 [style=filled]
break1 [style=filled]
"if (Y)" -> {"if (Z)"};
"if (Z)" -> {A break1};
break1 -> B;
break1 -> break2;
break2 -> {C while};
{rank=same; A break1 B break2}
{rank=same; "if (Z)" C}
{rank=same; while D}
{edge [style=invis];
A -> break1 -> B -> break2;
}
}

29
figs/problem2.dot Normal file
View file

@ -0,0 +1,29 @@
digraph g {
"f()" [shape=box, rank=min, style = filled];
// Rank adjustment
{ node [style=filled]
{ rank = same; "int a = 1"; "while (a > 0)"; }
"if (a > 10)"; break;
}
{ rank = same; "print(a)"; "a++"; }
{ rank = max; "a++"; "print(a)"; }
"a++" [style="filled,bold"];
// Control flow
"f()" -> "while (a > 0)";
"f()" -> "int a = 1";
"while (a > 0)" -> "if (a > 10)";
"if (a > 10)" -> "break";
"break" -> "print(a)";
"break" -> "a++";
"break" -> "while (a > 0)";
// Data flow
{ edge [color = red];
"int a = 1" -> "while (a > 0)";
"int a = 1" -> "if (a > 10)";
"int a = 1" -> "print(a)";
"a++" -> "a++";
"a++" -> "while (a > 0)";
"a++" -> "if (a > 10)";
"a++" -> "print(a)" [constraint = true];
}
}

40
figs/problem3.dot Normal file
View file

@ -0,0 +1,40 @@
digraph g {
enter [style = filled];
mxin [label = "x = x_in", style = filled];
try [style = filled];
x_in [label = "x_in = x", style = filled];
f [label = "f()", style = filled];
nr [label = "normal return"];
x_out_nr [label = "x = x_out"];
er [label = "error return"];
catch [label = "catch (Exception e)"];
x_out_catch [label = "x = x_out"];
log [label = "log(\"error\")"];
x_0 [label = "x = 0", style = filled];
x_in2 [label = "x_in = x", style = filled];
f2 [label = "f()", style = filled];
nr2 [label = "normal return"];
er2 [label = "error return"];
ee [label = "error exit"];
x_out_nr2 [label = "x = x_out"];
x_out_ee [label = "x = x_out"];
enter -> {mxin try};
try -> f -> {x_in nr er}
nr -> x_out_nr
er -> catch -> {x_out_catch log}
enter -> {x_0 f2}
f2 -> {x_in2 nr2 er2}
nr2 -> x_out_nr2
er2 -> ee -> x_out_ee;
{edge [color = red, constraint = false];
mxin -> x_in;
x_0 -> x_in2;
}
{edge [color = blue, constraint = false];
x_in -> {x_out_nr x_out_catch}
x_in2 -> {x_out_nr2 x_out_ee}
}
}