From 201ee44277be6e62bea563626c5654f977f01cfb Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Thu, 19 Dec 2019 13:03:04 +0100 Subject: [PATCH] Final version --- .gitignore | 2 +- beamertheme-bjeldbak | 1 + figs/problem1-sliced.dot | 24 + figs/problem1-solution-sliced.dot | 25 + figs/problem1-solution.dot | 23 + figs/problem1.dot | 21 +- figs/problem2-sol1.dot | 30 + figs/problem2-sol2.dot | 29 + figs/problem2-sol3.dot | 29 + figs/problem2-sol4.dot | 29 + figs/problem2.dot | 11 +- figs/problem3-color-x0.dot | 40 ++ figs/problem3-color.dot | 40 ++ figs/problem3-data-edge-color-f1-error.dot | 42 ++ figs/problem3-data-edge-color-f1.dot | 42 ++ figs/problem3-data-edge-color-f2-error.dot | 42 ++ figs/problem3-data-edge-color-f2.dot | 42 ++ figs/problem3-data-edge-sliced.dot | 42 ++ figs/problem3-data-edge.dot | 42 ++ figs/problem3-sliced.dot | 40 ++ figs/problem3-sol-color.dot | 40 ++ figs/problem3-sol-sliced.dot | 40 ++ figs/problem3-sol.dot | 40 ++ figs/problem3.dot | 16 +- slides.tex | 611 ++++++++++++--------- 25 files changed, 1058 insertions(+), 285 deletions(-) create mode 160000 beamertheme-bjeldbak create mode 100644 figs/problem1-sliced.dot create mode 100644 figs/problem1-solution-sliced.dot create mode 100644 figs/problem1-solution.dot create mode 100644 figs/problem2-sol1.dot create mode 100644 figs/problem2-sol2.dot create mode 100644 figs/problem2-sol3.dot create mode 100644 figs/problem2-sol4.dot create mode 100644 figs/problem3-color-x0.dot create mode 100644 figs/problem3-color.dot create mode 100644 figs/problem3-data-edge-color-f1-error.dot create mode 100644 figs/problem3-data-edge-color-f1.dot create mode 100644 figs/problem3-data-edge-color-f2-error.dot create mode 100644 figs/problem3-data-edge-color-f2.dot create mode 100644 figs/problem3-data-edge-sliced.dot create mode 100644 figs/problem3-data-edge.dot create mode 100644 figs/problem3-sliced.dot create mode 100644 figs/problem3-sol-color.dot create mode 100644 figs/problem3-sol-sliced.dot create mode 100644 figs/problem3-sol.dot diff --git a/.gitignore b/.gitignore index 6bbd79b..15518e6 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,4 @@ *.bib *.vrb figs/*.pdf -beamer.pdf +slides.pdf diff --git a/beamertheme-bjeldbak b/beamertheme-bjeldbak new file mode 160000 index 0000000..e2cea55 --- /dev/null +++ b/beamertheme-bjeldbak @@ -0,0 +1 @@ +Subproject commit e2cea55a3837e29f92324b2f18d98482474b99e1 diff --git a/figs/problem1-sliced.dot b/figs/problem1-sliced.dot new file mode 100644 index 0000000..92dbfd7 --- /dev/null +++ b/figs/problem1-sliced.dot @@ -0,0 +1,24 @@ +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)"} -> while; + break2 [style=filled] + break1 [style=filled] + "if (Y)" -> {"if (Z)" C}; + "if (Y)" -> break2 [constraint = false]; + + "if (Z)" -> {A break1 B break2}; + 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; + } +} diff --git a/figs/problem1-solution-sliced.dot b/figs/problem1-solution-sliced.dot new file mode 100644 index 0000000..1f1e421 --- /dev/null +++ b/figs/problem1-solution-sliced.dot @@ -0,0 +1,25 @@ +digraph pdf { + entry [label="enter f()", style = filled]; + entry -> while [style = bold]; + entry -> D [color = grey]; + while [label="while (X)", style = filled]; + C [style="bold,filled"] + "if (Y)" [style = filled]; + "if (Z)" + while -> {"if (Y)"} -> while [style = bold]; + break2 [style = filled]; + break1 + "if (Y)" -> {"if (Z)"} [color = grey]; + "if (Y)" -> C [style = bold]; + "if (Y)" -> break2 [constraint = false, style = bold]; + "if (Z)" -> {A break1 B} [color = grey]; + {break1 "if (Z)"} -> break2 [color = lightgrey, style = dashed]; + break1 -> B [color = grey]; + break2 -> {C while} [style = bold]; + {rank=same; A break1 B break2} + {rank=same; "if (Z)" C} + {rank=same; while D} + {edge [style=invis]; + A -> break1 -> B -> break2; + } +} diff --git a/figs/problem1-solution.dot b/figs/problem1-solution.dot new file mode 100644 index 0000000..07c2434 --- /dev/null +++ b/figs/problem1-solution.dot @@ -0,0 +1,23 @@ +digraph pdf { + entry [label="enter f()"]; + entry -> {while; D}; + while [label="while (X)"]; + C [style="bold"] + "if (Y)" + "if (Z)" + while -> {"if (Y)"} -> while; + break2 + break1 + "if (Y)" -> {"if (Z)" C}; + "if (Y)" -> break2 [constraint = false]; + "if (Z)" -> {A break1 B}; + {break1 "if (Z)"} -> break2 [color = lightgrey, style = dashed]; + break1 -> B; + 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; + } +} diff --git a/figs/problem1.dot b/figs/problem1.dot index 062fb32..68811a8 100644 --- a/figs/problem1.dot +++ b/figs/problem1.dot @@ -1,15 +1,16 @@ digraph pdf { - entry [label="enter f()",style=filled]; + entry [label="enter f()"]; 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}; + while [label="while (X)"]; + C [style="bold"] + "if (Y)" + "if (Z)" + while -> "if (Y)" -> while; + break2 + break1 + "if (Y)" -> {"if (Z)" C}; + "if (Y)" -> break2 [constraint = false]; + "if (Z)" -> {A break1 B break2}; break1 -> B; break1 -> break2; break2 -> {C while}; diff --git a/figs/problem2-sol1.dot b/figs/problem2-sol1.dot new file mode 100644 index 0000000..1d0c5ae --- /dev/null +++ b/figs/problem2-sol1.dot @@ -0,0 +1,30 @@ +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; "log(a)"; "a++"; } + { rank = max; "a++"; "log(a)"; } + "a++" [style="bold"]; + // Control flow + "f()" -> "while (a > 0)"; + "f()" -> "int a = 1"; + "while (a > 0)" -> "if (a > 10)"; + "if (a > 10)" -> "break"; + "break" -> "log(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" -> "log(a)"; + "int a = 1" -> "a++"; + "a++" -> "a++"; + "a++" -> "while (a > 0)"; + "a++" -> "if (a > 10)"; + "a++" -> "log(a)" [constraint = true]; + } + } \ No newline at end of file diff --git a/figs/problem2-sol2.dot b/figs/problem2-sol2.dot new file mode 100644 index 0000000..10e22a6 --- /dev/null +++ b/figs/problem2-sol2.dot @@ -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 [style = invis]; + } + { rank = same; "log(a)"; "a++"; } + { rank = max; "a++"; "log(a)"; } + "a++" [style="bold"]; + // Control flow + "f()" -> "while (a > 0)"; + "f()" -> "int a = 1"; + "while (a > 0)" -> "if (a > 10)"; + "if (a > 10)" -> "break"; + break -> {"log(a)" "a++" "while (a > 0)"} [color = grey] + // Data flow + { edge [color = red]; + "int a = 1" -> "while (a > 0)"; + "int a = 1" -> "if (a > 10)"; + "int a = 1" -> "log(a)"; + "int a = 1" -> "a++"; + "a++" -> "a++"; + "a++" -> "while (a > 0)"; + "a++" -> "if (a > 10)"; + "a++" -> "log(a)" [constraint = true]; + } + } \ No newline at end of file diff --git a/figs/problem2-sol3.dot b/figs/problem2-sol3.dot new file mode 100644 index 0000000..d47617f --- /dev/null +++ b/figs/problem2-sol3.dot @@ -0,0 +1,29 @@ +digraph g { + "f()" [shape=box, rank=min, style = filled]; + // Rank adjustment + { node []; // [style=filled] + { rank = same; "int a = 1" [style = filled]; "while (a > 0)"; } + "if (a > 10)"; + break [style = invis]; + } + { rank = same; "log(a)"; "a++"; } + { rank = max; "a++"; "log(a)"; } + "a++" [style="bold,filled"]; + // Control flow + "f()" -> "while (a > 0)"; + "f()" -> "int a = 1"; + "while (a > 0)" -> "if (a > 10)"; + "if (a > 10)" -> "break"; + break -> {"log(a)" "a++" "while (a > 0)"} [color = grey] + // Data flow + { edge [color = red]; + "int a = 1" -> "while (a > 0)"; + "int a = 1" -> "if (a > 10)"; + "int a = 1" -> "log(a)"; + "int a = 1" -> "a++"; + "a++" -> "a++"; + "a++" -> "while (a > 0)"; + "a++" -> "if (a > 10)"; + "a++" -> "log(a)" [constraint = true]; + } + } \ No newline at end of file diff --git a/figs/problem2-sol4.dot b/figs/problem2-sol4.dot new file mode 100644 index 0000000..a259a94 --- /dev/null +++ b/figs/problem2-sol4.dot @@ -0,0 +1,29 @@ +digraph g { + "f()" [shape=box, rank=min, style = filled]; + // Rank adjustment + { node []; // [style=filled] + { rank = same; "int a = 1" [style = filled]; "while (a > 0)"; } + "if (a > 10)"; + break; + } + { rank = same; "log(a)"; "a++"; } + { rank = max; "a++"; "log(a)"; } + "a++" [style="bold,filled"]; + // Control flow + "f()" -> "while (a > 0)"; + "f()" -> "int a = 1"; + "while (a > 0)" -> "if (a > 10)"; + "if (a > 10)" -> "break"; + break -> {"log(a)" "a++" "while (a > 0)"} + // Data flow + { edge [color = red]; + "int a = 1" -> "while (a > 0)"; + "int a = 1" -> "if (a > 10)"; + "int a = 1" -> "log(a)"; + "int a = 1" -> "a++"; + "a++" -> "a++"; + "a++" -> "while (a > 0)"; + "a++" -> "if (a > 10)"; + "a++" -> "log(a)" [constraint = true]; + } + } \ No newline at end of file diff --git a/figs/problem2.dot b/figs/problem2.dot index 635d227..b6918c5 100644 --- a/figs/problem2.dot +++ b/figs/problem2.dot @@ -5,25 +5,26 @@ digraph g { { rank = same; "int a = 1"; "while (a > 0)"; } "if (a > 10)"; break; } - { rank = same; "print(a)"; "a++"; } - { rank = max; "a++"; "print(a)"; } + { rank = same; "log(a)"; "a++"; } + { rank = max; "a++"; "log(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" -> "log(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)"; + "int a = 1" -> "log(a)"; + "int a = 1" -> "a++"; "a++" -> "a++"; "a++" -> "while (a > 0)"; "a++" -> "if (a > 10)"; - "a++" -> "print(a)" [constraint = true]; + "a++" -> "log(a)" [constraint = true]; } } \ No newline at end of file diff --git a/figs/problem3-color-x0.dot b/figs/problem3-color-x0.dot new file mode 100644 index 0000000..06d0330 --- /dev/null +++ b/figs/problem3-color-x0.dot @@ -0,0 +1,40 @@ +digraph g { + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", ]; + f [label = "f()", ]; + 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, fillcolor = lightgreen]; + x_in2 [label = "x_in = x", ]; + f2 [label = "f()", ]; + 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} + } +} \ No newline at end of file diff --git a/figs/problem3-color.dot b/figs/problem3-color.dot new file mode 100644 index 0000000..9355688 --- /dev/null +++ b/figs/problem3-color.dot @@ -0,0 +1,40 @@ +digraph g { + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", ]; + f [label = "f()", ]; + 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", fillcolor = lightgreen, style = filled]; + x_in2 [label = "x_in = x", fillcolor = lightgreen, style = filled]; + f2 [label = "f()", fillcolor = lightgreen, style = filled]; + nr2 [label = "normal return", fillcolor = lightgreen, style = filled]; + er2 [label = "error return", fillcolor = lightgreen, style = filled]; + ee [label = "error exit", fillcolor = lightgreen, style = filled]; + x_out_nr2 [label = "x = x_out", fillcolor = lightgreen, style = filled]; + x_out_ee [label = "x = x_out", fillcolor = lightgreen, style = filled]; + + 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} + } +} \ No newline at end of file diff --git a/figs/problem3-data-edge-color-f1-error.dot b/figs/problem3-data-edge-color-f1-error.dot new file mode 100644 index 0000000..719b2f2 --- /dev/null +++ b/figs/problem3-data-edge-color-f1-error.dot @@ -0,0 +1,42 @@ +digraph g { + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", style = filled, fillcolor = lightgreen]; + f [label = "f()", style = filled, fillcolor = lightgreen]; + nr [label = "normal return", style = filled, fillcolor = lightgreen]; + x_out_nr [label = "x = x_out", style = filled, fillcolor = lightgreen]; + er [label = "error return", style = filled, fillcolor = lightgreen]; + catch [label = "catch (Exception e)", style = filled, fillcolor = pink]; + x_out_catch [label = "x = x_out", style = filled, fillcolor = lightgreen]; + log [label = "log(\"error\")", style = filled, fillcolor = pink]; + x_0 [label = "x = 0", style = invis]; + x_in2 [label = "x_in = x", ]; + f2 [label = "f()", ]; + 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}; + enter -> x_0 [style = invis]; + try -> f -> {x_in nr er} + nr -> x_out_nr + er -> catch -> {x_out_catch log} + enter -> {f2} + f2 -> {x_in2 nr2 er2} + nr2 -> x_out_nr2 + er2 -> ee -> x_out_ee; + + {edge [color = red, constraint = false]; + mxin -> x_in; + {x_out_catch x_out_nr} -> x_in2; + x_0 -> x_in2 [style = invis]; + } + + {edge [color = blue, constraint = false]; + x_in -> {x_out_nr x_out_catch} + x_in2 -> {x_out_nr2 x_out_ee} + } +} \ No newline at end of file diff --git a/figs/problem3-data-edge-color-f1.dot b/figs/problem3-data-edge-color-f1.dot new file mode 100644 index 0000000..c093163 --- /dev/null +++ b/figs/problem3-data-edge-color-f1.dot @@ -0,0 +1,42 @@ +digraph g { + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", style = filled, fillcolor = lightgreen]; + f [label = "f()", style = filled, fillcolor = lightgreen]; + nr [label = "normal return", style = filled, fillcolor = lightgreen]; + x_out_nr [label = "x = x_out", style = filled, fillcolor = lightgreen]; + er [label = "error return", style = filled, fillcolor = lightgreen]; + catch [label = "catch (Exception e)"]; + x_out_catch [label = "x = x_out", style = filled, fillcolor = lightgreen]; + log [label = "log(\"error\")"]; + x_0 [label = "x = 0", style = invis]; + x_in2 [label = "x_in = x", ]; + f2 [label = "f()", ]; + 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}; + enter -> x_0 [style = invis]; + try -> f -> {x_in nr er} + nr -> x_out_nr + er -> catch -> {x_out_catch log} + enter -> {f2} + f2 -> {x_in2 nr2 er2} + nr2 -> x_out_nr2 + er2 -> ee -> x_out_ee; + + {edge [color = red, constraint = false]; + mxin -> x_in; + {x_out_catch x_out_nr} -> x_in2; + x_0 -> x_in2 [style = invis]; + } + + {edge [color = blue, constraint = false]; + x_in -> {x_out_nr x_out_catch} + x_in2 -> {x_out_nr2 x_out_ee} + } +} \ No newline at end of file diff --git a/figs/problem3-data-edge-color-f2-error.dot b/figs/problem3-data-edge-color-f2-error.dot new file mode 100644 index 0000000..10e240a --- /dev/null +++ b/figs/problem3-data-edge-color-f2-error.dot @@ -0,0 +1,42 @@ +digraph g { + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", ]; + f [label = "f()", ]; + 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 = invis]; + x_in2 [label = "x_in = x", style = filled, fillcolor = lightgreen]; + f2 [label = "f()", style = filled, fillcolor = lightgreen]; + nr2 [label = "normal return", style = filled, fillcolor = lightgreen]; + er2 [label = "error return", style = filled, fillcolor = lightgreen]; + ee [label = "error exit", style = filled, fillcolor = pink]; + x_out_nr2 [label = "x = x_out", style = filled, fillcolor = lightgreen]; + x_out_ee [label = "x = x_out", style = filled, fillcolor = lightgreen]; + + enter -> {mxin try}; + enter -> x_0 [style = invis]; + try -> f -> {x_in nr er} + nr -> x_out_nr + er -> catch -> {x_out_catch log} + enter -> {f2} + f2 -> {x_in2 nr2 er2} + nr2 -> x_out_nr2 + er2 -> ee -> x_out_ee; + + {edge [color = red, constraint = false]; + mxin -> x_in; + {x_out_catch x_out_nr} -> x_in2; + x_0 -> x_in2 [style = invis]; + } + + {edge [color = blue, constraint = false]; + x_in -> {x_out_nr x_out_catch} + x_in2 -> {x_out_nr2 x_out_ee} + } +} \ No newline at end of file diff --git a/figs/problem3-data-edge-color-f2.dot b/figs/problem3-data-edge-color-f2.dot new file mode 100644 index 0000000..4142dd3 --- /dev/null +++ b/figs/problem3-data-edge-color-f2.dot @@ -0,0 +1,42 @@ +digraph g { + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", ]; + f [label = "f()", ]; + 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 = invis]; + x_in2 [label = "x_in = x", style = filled, fillcolor = lightgreen]; + f2 [label = "f()", style = filled, fillcolor = lightgreen]; + nr2 [label = "normal return", style = filled, fillcolor = lightgreen]; + er2 [label = "error return", style = filled, fillcolor = lightgreen]; + ee [label = "error exit"]; + x_out_nr2 [label = "x = x_out", style = filled, fillcolor = lightgreen]; + x_out_ee [label = "x = x_out", style = filled, fillcolor = lightgreen]; + + enter -> {mxin try}; + enter -> x_0 [style = invis]; + try -> f -> {x_in nr er} + nr -> x_out_nr + er -> catch -> {x_out_catch log} + enter -> {f2} + f2 -> {x_in2 nr2 er2} + nr2 -> x_out_nr2 + er2 -> ee -> x_out_ee; + + {edge [color = red, constraint = false]; + mxin -> x_in; + {x_out_catch x_out_nr} -> x_in2; + x_0 -> x_in2 [style = invis]; + } + + {edge [color = blue, constraint = false]; + x_in -> {x_out_nr x_out_catch} + x_in2 -> {x_out_nr2 x_out_ee} + } +} \ No newline at end of file diff --git a/figs/problem3-data-edge-sliced.dot b/figs/problem3-data-edge-sliced.dot new file mode 100644 index 0000000..e189986 --- /dev/null +++ b/figs/problem3-data-edge-sliced.dot @@ -0,0 +1,42 @@ +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", style = filled]; + x_out_nr [label = "x = x_out", style = filled]; + er [label = "error return", style = filled]; + catch [label = "catch (Exception e)", style = filled]; + x_out_catch [label = "x = x_out", style = filled]; + log [label = "log(\"error\")"]; + x_0 [label = "x = 0", style = invis]; + 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}; + enter -> x_0 [style = invis]; + try -> f -> {x_in nr er} + nr -> x_out_nr + er -> catch -> {x_out_catch log} + enter -> {f2} + f2 -> {x_in2 nr2 er2} + nr2 -> x_out_nr2 + er2 -> ee -> x_out_ee; + + {edge [color = red, constraint = false]; + mxin -> x_in; + {x_out_catch x_out_nr} -> x_in2; + x_0 -> x_in2 [style = invis] + } + + {edge [color = blue, constraint = false]; + x_in -> {x_out_nr x_out_catch} + x_in2 -> {x_out_nr2 x_out_ee} + } +} \ No newline at end of file diff --git a/figs/problem3-data-edge.dot b/figs/problem3-data-edge.dot new file mode 100644 index 0000000..d0c20a3 --- /dev/null +++ b/figs/problem3-data-edge.dot @@ -0,0 +1,42 @@ +digraph g { + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", ]; + f [label = "f()", ]; + 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 = invis]; + x_in2 [label = "x_in = x", ]; + f2 [label = "f()", ]; + 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}; + enter -> x_0 [style = invis]; + try -> f -> {x_in nr er} + nr -> x_out_nr + er -> catch -> {x_out_catch log} + enter -> {f2} + f2 -> {x_in2 nr2 er2} + nr2 -> x_out_nr2 + er2 -> ee -> x_out_ee; + + {edge [color = red, constraint = false]; + mxin -> x_in; + {x_out_catch x_out_nr} -> x_in2; + x_0 -> x_in2 [style = invis]; + } + + {edge [color = blue, constraint = false]; + x_in -> {x_out_nr x_out_catch} + x_in2 -> {x_out_nr2 x_out_ee} + } +} \ No newline at end of file diff --git a/figs/problem3-sliced.dot b/figs/problem3-sliced.dot new file mode 100644 index 0000000..0223270 --- /dev/null +++ b/figs/problem3-sliced.dot @@ -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} + } +} \ No newline at end of file diff --git a/figs/problem3-sol-color.dot b/figs/problem3-sol-color.dot new file mode 100644 index 0000000..5993b55 --- /dev/null +++ b/figs/problem3-sol-color.dot @@ -0,0 +1,40 @@ +digraph g { + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", ]; + f [label = "f()", ]; + 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", fillcolor = lightgreen, style = filled]; + x_in2 [label = "x_in = x", fillcolor = lightgreen, style = filled]; + f2 [label = "f()", fillcolor = lightgreen, style = filled]; + nr2 [label = "normal return", fillcolor = lightgreen, style = filled]; + er2 [label = "error return", fillcolor = lightgreen, style = filled]; + ee [label = "error exit", fillcolor = lightgreen, style = filled]; + x_out_nr2 [label = "x = x_out", fillcolor = lightgreen, style = filled]; + x_out_ee [label = "x = x_out", fillcolor = lightgreen, style = filled]; + + enter -> {mxin try}; + try -> f -> {x_in nr er} + nr -> x_out_nr + er -> catch -> {x_out_catch log} + {catch} -> {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} + } +} \ No newline at end of file diff --git a/figs/problem3-sol-sliced.dot b/figs/problem3-sol-sliced.dot new file mode 100644 index 0000000..8972697 --- /dev/null +++ b/figs/problem3-sol-sliced.dot @@ -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", style = filled]; + catch [label = "catch (Exception e)", style = filled]; + 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} + {catch} -> {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} + } +} \ No newline at end of file diff --git a/figs/problem3-sol.dot b/figs/problem3-sol.dot new file mode 100644 index 0000000..e9fee61 --- /dev/null +++ b/figs/problem3-sol.dot @@ -0,0 +1,40 @@ +digraph g { + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", ]; + f [label = "f()", ]; + 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"]; + x_in2 [label = "x_in = x"]; + f2 [label = "f()"]; + 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} + {catch} -> {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} + } +} \ No newline at end of file diff --git a/figs/problem3.dot b/figs/problem3.dot index 0223270..5683469 100644 --- a/figs/problem3.dot +++ b/figs/problem3.dot @@ -1,18 +1,18 @@ 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]; + enter []; + mxin [label = "x = x_in", ]; + try []; + x_in [label = "x_in = x", ]; + f [label = "f()", ]; 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]; + x_0 [label = "x = 0", ]; + x_in2 [label = "x_in = x", ]; + f2 [label = "f()", ]; nr2 [label = "normal return"]; er2 [label = "error return"]; ee [label = "error exit"]; diff --git a/slides.tex b/slides.tex index 22d7dd2..681cf1f 100644 --- a/slides.tex +++ b/slides.tex @@ -3,6 +3,8 @@ \documentclass[aspectratio=169,compress]{beamer} +% TODO: Titles Must Be Titlecase. + % Basic packages \usepackage{pgfpages} \usepackage{listings} @@ -12,6 +14,14 @@ \usepackage{xcolor} \usepackage{soul} +% Color definitions +\definecolor{criterion}{rgb}{1,0,0} +\definecolor{light-gray}{gray}{0.8} +\definecolor{color1}{rgb}{1,0.5,0} +\definecolor{color2}{rgb}{0.9,0.2,0} +\definecolor{hasExcClr}{rgb}{0,0.5,0} +\definecolor{lightgreen}{RGB}{144,238,144} + % Bibliography settings \usepackage[backend=bibtex,style=alphabetic,citestyle=alphabetic-verb]{biblatex} \bibliography{biblio.bib} @@ -38,9 +48,8 @@ } % Escapable listing environment -\lstnewenvironment{java}[1][] -{\lstset{ - language=[LaTeX]TeX}\lstset{escapeinside={(*@}{@*)}, +\lstnewenvironment{java}[1][]{ + \lstset{language=[LaTeX]TeX}\lstset{escapeinside={(*@}{@*)}, numbers=left, numberstyle=\tiny, stepnumber=1, @@ -68,17 +77,7 @@ \maketitle -\begin{frame} - \frametitle{TODO} - - \begin{itemize} - \item Proposal no, solution o proposed solution. - \item \ul{test} - \end{itemize} -\end{frame} - -\begin{frame} - \frametitle{Table of Contents} +\begin{frame}{Table of Contents} \tableofcontents \end{frame} @@ -87,58 +86,72 @@ \subsection{Program slicing} \begin{frame}[fragile]{Program slicing} - \begin{columns} \column{0.5\textwidth} - \begin{java} -void f(int x) { - int sum = 0; - int prod = 0; - while (x > 0) { - sum += x; - prod *= x; - x--; - } - log("sum: " + sum); - log("prod: " + (*@\textcolor<2->{blue}{prod}@*)); -} + \begin{java}[gobble=16] + void f(int x) { + int sum = 0; + int prod = 0; + while (x > 0) { + sum += x; + prod *= x; + x--; + } + log("sum: " + sum); + log("prod: " + (*@\textcolor<2->{criterion}{prod}@*)); + } \end{java} \column<3->{0.5\textwidth} - \begin{java} -void f(int x) { - (*@\invisible<4->{int sum = 0;}@*) - int prod = 0; - while (x > 0) { - (*@\invisible<4->{sum += x;}@*) - prod *= x; - x--; - } - (*@\invisible<4->{log("sum: " + sum);}@*) - log("prod: " + prod); -} + \begin{java}[gobble=16] + void f(int x) { + (*@\textcolor<4->{light-gray}{int sum = 0;}@*) + int prod = 0; + while (x > 0) { + (*@\textcolor<4->{light-gray}{sum += x;}@*) + prod *= x; + x--; + } + (*@\textcolor<4->{light-gray}{log("sum: " + sum);}@*) + log("prod: " + prod); + } \end{java} \end{columns} {\hfill Example adapted from \cite{Tip95}.} \end{frame} -% TODO: posible addition of examples on the right side. -\begin{frame}{Program slicing}{Applications} - \begin{itemize} - \item Debugging - \item Program specialization - \item Software maintenance - \item Code obfuscation - \item Dead code removal - \item Program parallelization - \end{itemize} +\begin{frame}[containsverbatim]{Program slicing}{Applications} + \begin{columns} + \column{0.5\linewidth} + \begin{itemize} + \item Debugging + \item Program specialization + \item Software maintenance + \item Code obfuscation + \item Dead code removal + \item Program parallelization + \end{itemize} + \column{0.5\linewidth} + \begin{java}[gobble=12] + void f(int x) { + (*@\textcolor{light-gray}{int sum = 0;}@*) + int prod = 0; + while (x > 0) { + (*@\textcolor{light-gray}{sum += x;}@*) + prod *= x; + x--; + } + (*@\textcolor{light-gray}{log("sum: " + sum);}@*) + log("prod: " + prod); + } + \end{java} + \end{columns} + % Clone detection (examenes, copyright) \end{frame} -% TODO: remove one of the notations in the examples. -% TODO: maybe use example 'block'? \begin{frame}{Program slicing}{Metrics} \begin{description} \item[\textbf{Completeness.}] The slice includes all instructions that are necessary. - \item[\textbf{Correctness.}] The slice excludes all instructions that are not necessary. + \item[\textbf{Correctness.}] The statements included affect the slicing criterion. \end{description} \vfill @@ -155,8 +168,6 @@ void f(int x) { \draw [line width=2pt,color=minimalcolor,fill=minimalcolor,fill opacity=0.4] (0,0) circle (2em); \visible<3->{\draw [line width=1pt,dotted,color=slicecolor,fill=slicecolor,fill opacity=0.2] (0, 0) circle (2em);} \end{tikzpicture} - $$c_m \wedge c_r$$ - % \includegraphics[width=\textwidth]{} \column{0.25\textwidth} Correct and incomplete: \\ \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45] @@ -164,7 +175,6 @@ void f(int x) { \draw [line width=2pt,color=minimalcolor,fill=minimalcolor,fill opacity=0.4] (0,0) circle (2em); \visible<4->{\draw [line width=1pt,dotted,color=slicecolor,fill=slicecolor,fill opacity=0.2] (0, 0) circle (1.5em);} \end{tikzpicture} - $$\neg c_m \wedge c_r$$ % \includegraphics[width=\textwidth]{} \column{0.25\textwidth} Incorrect and complete: \\ @@ -173,7 +183,6 @@ void f(int x) { \draw [line width=2pt,color=minimalcolor,fill=minimalcolor,fill opacity=0.4] (0,0) circle (2em); \visible<5->{\draw [line width=1pt,dotted,color=slicecolor,fill=slicecolor,fill opacity=0.2] (0, 0) circle (2.5em);} \end{tikzpicture} - $$c_m \wedge \neg c_r$$ % \includegraphics[width=\textwidth]{} \column{0.25\textwidth} Incorrect and incomplete: \\ @@ -182,98 +191,10 @@ void f(int x) { \draw [line width=2pt,color=minimalcolor,fill=minimalcolor,fill opacity=0.4] (0,0) circle (2em); \visible<6->{\draw [line width=1pt,dotted,color=slicecolor,fill=slicecolor,fill opacity=0.2] (1em, 1em) circle (2em);} \end{tikzpicture} - $$\neg c_m \wedge \neg c_r$$ % \includegraphics[width=\textwidth]{} \end{columns} \end{frame} -\subsection{Exception handling} - -\begin{frame}[fragile]{Exception handling systems}{Java} - \begin{columns} - \column{0.5\textwidth} - \begin{java}[tabsize=2] -void main() { - (*@\textcolor<4->{blue}{try}@*) { - f(); - } (*@\textcolor<5->{blue}{catch}@*) ((*@\textcolor<6>{blue}{Exception e}@*)) { - log("caught exception"); - } (*@\textcolor<5->{blue}{catch}@*) ((*@\textcolor<6>{blue}{Throwable e}@*)) { - log("caught throwable"); - } -} - \end{java} - \column{0.5\textwidth} - \begin{java}[firstnumber=10,tabsize=2] -void f() throws Exception { - switch(x) { - case A: - log("no error"); - break; - case B: - (*@\textcolor<2-3>{blue}{throw}@*) (*@\textcolor<3>{blue}{new Exception()}@*); - default: - (*@\textcolor<2-3>{blue}{throw}@*) (*@\textcolor<3>{blue}{new Throwable()}@*); - } -} - \end{java} - \end{columns} -\end{frame} - -% TODO: extend with examples or replace by Exception hierarchy -\begin{frame}{Exception handling systems}{Java} - \begin{columns} - \column{0.5\textwidth} - \begin{center} - \includegraphics[height=0.85\textheight]{figs/exception-hierarchy} - \end{center} - \column{0.5\textwidth} - \begin{itemize} - \item \textit{Checked} (solid): must be caught (\texttt{try-catch}) or declared (\texttt{f() throws T}). - \item \textit{Unchecked} (dashed). - \end{itemize} - \end{columns} -\end{frame} - -\begin{frame}{Exception handling systems}{Other programming languages} - \begin{table} - \begin{minipage}{0.6\linewidth} - \centering - \begin{tabular}{r | r } - \textbf{Language} & $\%$ usage \\ \hline - JavaScript & 69.7 \\ \hline - \textcolor<2->{blue}{HTML/CSS} & 63.1 \\ \hline - \textcolor<2->{blue}{SQL} & 56.5 \\ \hline - Python & 39.4 \\ \hline - Java & 39.2 \\ \hline - \textcolor<2->{blue}{Bash/Shell}/PowerShell & 37.9 \\ \hline - C\# & 31.9 \\ \hline - PHP & 25.8 \\ \hline - TypeScript & 23.5 \\ \hline - C++ & 20.4 \\ \hline - \end{tabular} - \end{minipage} - \begin{minipage}{0.39\linewidth} - \begin{tabular}{r | r } - \textbf{Language} & $\%$ usage \\ \hline - \textcolor<2->{blue}{C} & 17.3 \\ \hline - Ruby & 8.9 \\ \hline - \textcolor<2->{blue}{Go} & 8.8 \\ \hline - Swift & 6.8 \\ \hline - Kotlin & 6.6 \\ \hline - R & 5.6 \\ \hline - \textcolor<2->{blue}{VBA} & 5.5 \\ \hline - Objective-C & 5.2 \\ \hline - \textcolor<2->{blue}{Assembly} & 5.0 \\ \hline - \end{tabular} - \end{minipage} - % The caption has a weird structure due to the fact that there's a footnote - % inside of it. - \caption[Commonly used programming languages]{Programming language by usage in the software industry (StackOverflow's 2019 Developer Survey)} - \label{tab:popular-languages} - \end{table} -\end{frame} - \subsection{The System Dependence Graph} \begin{frame}[fragile]{The System Dependence Graph}{Creation} @@ -297,45 +218,34 @@ void f(int x) { log(prod); } \end{java} - \column{0.8\textwidth} + \column{0.8\textwidth}<+-> \centering - \includegraphics<1>[width=1.1\linewidth]{figs/example-sdg-1} - \includegraphics<2>[width=1.1\linewidth]{figs/example-sdg-2} - \includegraphics<3>[width=1.1\linewidth]{figs/example-sdg-3} - \includegraphics<4>[width=1.1\linewidth]{figs/example-sdg-4} - \includegraphics<5>[width=1.1\linewidth]{figs/example-sdg-5} - \includegraphics<6>[width=1.1\linewidth]{figs/example-sdg-6} + % TODO: leyenda de data dependence + \includegraphics<+>[width=1.1\linewidth]{figs/example-sdg-1} + \includegraphics<+>[width=1.1\linewidth]{figs/example-sdg-2} + \includegraphics<+>[width=1.1\linewidth]{figs/example-sdg-3} + \includegraphics<+>[width=1.1\linewidth]{figs/example-sdg-4} + \includegraphics<+>[width=1.1\linewidth]{figs/example-sdg-5} + \includegraphics<+>[width=1.1\linewidth]{figs/example-sdg-6} \end{columns} \end{frame} \begin{frame}[fragile]{The System Dependence Graph}{Traversal} \begin{columns} \column{0.20\textwidth} - \definecolor{light-gray}{gray}{0.8} - \begin{java}[basicstyle=\scriptsize\ttfamily\color<2->{light-gray},numberstyle=\tiny\color{black}] -(*@\textcolor<4->{black}{void f(}@*)(*@\textcolor<8->{black}{int x}@*)(*@\textcolor<4->{black}{) \{}@*) - int sum = 0; - (*@\textcolor<4->{black}{int prod = 0;}@*) - (*@\textcolor<6->{black}{while (x>0) \{}@*) - sum += sum; - (*@\textcolor<4->{black}{prod*=prod;}@*) - (*@\textcolor<8->{black}{x--;}@*) - (*@\textcolor<6->{black}{\}}@*) - log(sum); - (*@\textcolor<2->{black}{log(prod);}@*) -(*@\textcolor<4->{black}{\}}@*) + \begin{java}[basicstyle=\scriptsize\ttfamily\color<2->{light-gray},numberstyle=\tiny\color{black},gobble=12] + (*@\textcolor<4->{black}{void f(}@*)(*@\textcolor<8->{black}{int x}@*)(*@\textcolor<4->{black}{) \{}@*) + int sum = 0; + (*@\textcolor<4->{black}{int prod = 0;}@*) + (*@\textcolor<6->{black}{while (x>0) \{}@*) + sum += sum; + (*@\textcolor<4->{black}{prod*=prod;}@*) + (*@\textcolor<8->{black}{x--;}@*) + (*@\textcolor<6->{black}{\}}@*) + log(sum); + (*@\textcolor<2->{black}{log(\textcolor<1>{criterion}{prod});}@*) + (*@\textcolor<4->{black}{\}}@*) \end{java} -% (*@\only<-11>{int sum = 0;}@*) -% (*@\textcolor<4-10>{blue}{int prod = 0;}@*) -% (*@\textcolor<6-10>{blue}{while (x>0) \{}@*) -% (*@\only<-11>sum += sum;}@*) -% (*@\textcolor<4-10>{blue}{prod*=prod;}@*) -% (*@\textcolor<8-10>{blue}{x--;}@*) -% (*@\textcolor<6-10>{blue}{\}}@*) -% (*@\only<-11>{log(sum);}@*) -% (*@\textcolor<2-10>{blue}{log(prod);}@*) -% } -% \end{java} \column{0.8\textwidth} \centering \includegraphics<1>[width=1.1\linewidth]{figs/example-sdg} % original graph @@ -351,152 +261,331 @@ void f(int x) { \end{columns} \end{frame} +\subsection{Exception handling} + +\begin{frame}[fragile]{Exception Handling Systems}{Java} + \begin{columns} + \column{0.5\textwidth} + \begin{java}[tabsize=2,gobble=12] + void main() { + (*@\textcolor<5->{color1}{try}@*) { + f(); + } (*@\textcolor<5->{color1}{catch}@*) ((*@\textcolor<6>{color1}{Exception e}@*)) { + log("caught exception"); + } (*@\textcolor<5->{color1}{catch}@*) ((*@\textcolor<6>{color1}{Throwable e}@*)) { + log("caught throwable"); + } + } + \end{java} + \column{0.5\textwidth} + \begin{java}[firstnumber=10,tabsize=2,gobble=12] + void f() (*@\textcolor<4>{color1}{throws Throwable}@*) { + switch(x) { + case A: + log("no error"); + break; + case B: + (*@\textcolor<2-4>{color1}{throw}@*) (*@\textcolor<3-4>{color1}{new Exception()}@*); + default: + (*@\textcolor<2-4>{color1}{throw}@*) (*@\textcolor<3-4>{color1}{new Throwable()}@*); + } + } + \end{java} + \end{columns} +\end{frame} + +% TODO: possible animation; selecting each named exception and explaining its contents, then splitting into checked/unchecked. +% TODO: título: jerarquía de herencia +\begin{frame}{Exception Handling Systems}{Java} + \begin{columns} + \column{0.5\textwidth} + \begin{center} + \includegraphics[height=0.85\textheight]{figs/exception-hierarchy} + \end{center} + \column{0.5\textwidth} + \begin{itemize} + \item \textit{Checked} (solid): must be caught (\texttt{try-catch}) or declared (\texttt{f() throws T}). + \item \textit{Unchecked} (dashed). + \end{itemize} + \end{columns} +\end{frame} + +% TODO: iluminar las que si en otro color +\begin{frame}{Exception Handling Systems}{Other programming languages} + \begin{table} + \begin{columns} + \column{0.6\linewidth} + \centering + \begin{tabular}{r | r } + \textbf{Language} & $\%$ usage \\ \hline + \textcolor<2->{hasExcClr}{JavaScript} & 69.7 \\ \hline + \textcolor<3->{color2}{HTML/CSS} & 63.1 \\ \hline + \textcolor<3->{color2}{SQL} & 56.5 \\ \hline + \textcolor<2->{hasExcClr}{Python} & 39.4 \\ \hline + \textcolor<2->{hasExcClr}{Java} & 39.2 \\ \hline + \textcolor<3->{color2}{Bash/Shell}/\textcolor<2->{hasExcClr}{PowerShell} & 37.9 \\ \hline + \textcolor<2->{hasExcClr}{C\#} & 31.9 \\ \hline + \textcolor<2->{hasExcClr}{PHP} & 25.8 \\ \hline + \textcolor<2->{hasExcClr}{TypeScript} & 23.5 \\ \hline + \textcolor<2->{hasExcClr}{C++} & 20.4 \\ \hline + \end{tabular} + + \column{0.4\linewidth} + \begin{tabular}{r | r } + \textbf{Language} & $\%$ usage \\ \hline + \textcolor<3->{color2}{C} & 17.3 \\ \hline + \textcolor<2->{hasExcClr}{Ruby} & 8.9 \\ \hline + \textcolor<3->{color2}{Go} & 8.8 \\ \hline + \textcolor<2->{hasExcClr}{Swift} & 6.8 \\ \hline + \textcolor<2->{hasExcClr}{Kotlin} & 6.6 \\ \hline + \textcolor<2->{hasExcClr}{R} & 5.6 \\ \hline + \textcolor<3->{color2}{VBA} & 5.5 \\ \hline + \textcolor<2->{hasExcClr}{Objective-C} & 5.2 \\ \hline + \textcolor<3->{color2}{Assembly} & 5.0 \\ \hline + \end{tabular} + \end{columns} + \caption[Commonly used programming languages]{Programming language by usage in the software industry (StackOverflow's 2019 Developer Survey)} + \label{tab:popular-languages} + \end{table} +\end{frame} + \section{Problems and proposals} \subsection{Problem 1: incorrect slices with nested unconditional jumps} -% TODO añadir nombres a los problemas \begin{frame}[fragile]{Problem 1}{The subsumption correctness error} \begin{minipage}{0.39\linewidth} - \begin{lstlisting} -public void f() { - while (X) { - if (Y) { - if (Z) { - A; - break; + \begin{java}[gobble=8] + public void f() { + while (X) { + if (Y) { + (*@\textcolor<4->{light-gray}{if (Z) \{}@*) + (*@\textcolor<3->{light-gray}{A;}@*) + (*@\textcolor<4->{light-gray}{break;}@*) + (*@\textcolor<4->{light-gray}{\}}@*) + (*@\textcolor<3->{light-gray}{B;}@*) + break; } - B; - break; + (*@\textcolor<2->{criterion}{C}@*); + } + (*@\textcolor<3->{light-gray}{D;}@*) } - C; - } - D; -} - \end{lstlisting} + \end{java} \end{minipage} \begin{minipage}{0.59\linewidth} - \includegraphics[width=0.8\linewidth]{figs/problem1} + \includegraphics<2>[width=0.9\linewidth]{figs/problem1} + \includegraphics<3->[width=0.9\linewidth]{figs/problem1-sliced} \end{minipage} \end{frame} \begin{frame}{Problem 1: proposed solution}{The subsumption correctness error} - TODO: show graph here, label the edges caused by each jump and then remove some. + \begin{columns} + \column{0.5\textwidth} + \begin{enumerate} + \item Identify edges caused by unconditional jumps. \pause + \item Remove from $E_c$ all $(a, b)$ such that $(a', b) \in E_c \wedge a', b \in J \wedge (a', b), (a, b) \in E_{a'}$ + \\ $J$: unconditional jumps + \\ $E_c$: control edges + \\ $E_{a'}$: edges caused by $a'$ + \end{enumerate} + \column{0.5\textwidth} + \includegraphics<3>[width=0.9\linewidth]{figs/problem1-solution} + \includegraphics<4->[width=0.9\linewidth]{figs/problem1-solution-sliced} + \end{columns} \end{frame} \subsection{Problem 2: incorrect weak slices} \begin{frame}[fragile]{Problem 2}{Unnecessary instructions in weak slicing} \begin{minipage}{0.33\linewidth} - \begin{lstlisting} -void g() { - int x = 0; - while (x > 0) { - if (x > 10) - break; - x++; - } - log(x); -} - \end{lstlisting} + \begin{java}[gobble=12] + void g() { + int a = 1; + while (a > 0) { + (*@\textcolor<3->{light-gray}{if (a > 10)}@*) + (*@\textcolor<3->{light-gray}{break;}@*) + (*@\textcolor{red}{a}@*)++; + } + (*@\textcolor<2->{light-gray}{log(a);}@*) + } + \end{java} \end{minipage} - \begin{minipage}{0.66\linewidth} + \begin{minipage}{0.66\textwidth} \centering - \includegraphics[width=0.6\linewidth]{figs/problem2} + \includegraphics<2->[width=0.5\textwidth]{figs/problem2} \end{minipage} \end{frame} \begin{frame}{Problem 2: proposed solution}{Unnecessary instructions in weak slicing} - TODO: animate the multi-pass solution. - \begin{enumerate} - \item Remove all forward-jumping unconditional jump's nodes. - \item Traverse the graph. - \item Re-add all nodes that fulfil the condition of having something selected after them. - \item Goto 2. - \end{enumerate} + \begin{columns} + \column{0.5\textwidth} + \begin{enumerate} + \item Remove all forward-jumping unconditional jump's nodes. + \pause[3] \item Traverse the graph. + \pause \item Re-add all nodes removed if there is any statement in the slice after their destination. + \pause \item If (3) changed the graph, goto (2). + \end{enumerate} + + \column{0.5\textwidth} + \includegraphics<1>[width=0.7\linewidth]{figs/problem2-sol1} + \includegraphics<2>[width=0.7\linewidth]{figs/problem2-sol2} + \includegraphics<3-5>[width=0.7\linewidth]{figs/problem2-sol3} + \includegraphics<6>[width=0.7\linewidth]{figs/problem2-sol4} + \end{columns} \end{frame} \subsection{Problem 3: incomplete \texttt{catch} treatment} -\begin{frame}[fragile]{Problem 3}{The lack of dependencies of \texttt{catch} statements} -\begin{minipage}{0.29\linewidth} - \begin{lstlisting} -void main() throws Exception { - try { - f(); - } catch (Exception e) { - log("error"); - } - x = 0; - f(); -} - \end{lstlisting} -\end{minipage} -\begin{minipage}{0.7\linewidth} - \includegraphics[width=\linewidth]{figs/problem3} -\end{minipage} +\begin{frame}[fragile]{Problem 3}{The Lack of Dependencies of \texttt{catch} Statements} + \begin{columns} + \column{0.4\textwidth} + \begin{java}[gobble=12,basicstyle=\scriptsize\ttfamily] + int x; + + void main() (*@\alt<6>{\fcolorbox{black}{pink}{throws Exception}}{throws Exception}@*) { + try { + (*@\alt<3-4>{\fcolorbox{black}{lightgreen}{f()}}{f()}@*); + } (*@\textcolor<11->{light-gray}{\alt<4>{\fcolorbox{black}{pink}{catch (Exception e)}}{catch (Exception e)} \{}@*) + (*@\textcolor<8,11->{light-gray}{log("error");}@*) + (*@\textcolor<11->{light-gray}{\}}@*) + (*@\visible<9->{\alt<9>{\fcolorbox{black}{lightgreen}{x = 0;}}{x = 0;}}@*) + (*@\alt<5-6>{\fcolorbox{black}{lightgreen}{f()}}{f()}@*); + } + + void f() throws Exception { + x++; + if (x > 0) + throw new Exception(); + log((*@\textcolor{criterion}{x}@*)); + } + \end{java} + \column<+->{0.6\textwidth} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3-data-edge} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3-data-edge-color-f1} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3-data-edge-color-f1-error} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3-data-edge-color-f2} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3-data-edge-color-f2-error} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3-data-edge} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3-data-edge-sliced} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3-color-x0} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3} + \includegraphics<+>[width=1.1\textwidth]{figs/problem3-sliced} + \end{columns} \end{frame} +% \begin{frame}[fragile,label=p3]{Problem 3}{The lack of dependencies of \texttt{catch} statements} +% \begin{columns} +% \column{0.4\textwidth} +% \begin{java}[gobble=12,basicstyle=\scriptsize\ttfamily] +% void main() throws Exception { +% try { +% f(); +% } (*@\textcolor<2->{light-gray}{catch (Exception e) \{}@*) +% (*@\textcolor<2->{light-gray}{log("error");}@*) +% (*@\textcolor<2->{light-gray}{\}}@*) +% x = 0; +% f(); +% } + +% void f() throws Exception { +% x++; +% if (x < 0) +% throw new Exception(); +% log((*@\textcolor{criterion}{x}@*)); +% } +% \end{java} + +% % TODO: highlight each section of the graph. +% \column{0.6\textwidth} +% \includegraphics<1>[height=0.9\textheight]{figs/problem3} +% \includegraphics<2>[height=0.9\textheight]{figs/problem3-sliced} +% \end{columns} +% \end{frame} + +% % TODO: reorder, good approach, error, solution +% \begin{frame}{Problem 3}{The lack of dependencies of \texttt{catch} statements} +% \centering +% \includegraphics<+>[height=0.9\textheight]{figs/problem3} +% \includegraphics<+>[height=0.9\textheight]{figs/problem3-data-edge} +% \includegraphics<+>[height=0.9\textheight]{figs/problem3-data-edge-sliced} +% \end{frame} + +% \againframe<1>{p3} + \begin{frame}{Problem 3: proposed solution}{The lack of dependencies of \texttt{catch} statements} - TODO: animate the conversion to the new dependencies and a slice. - \begin{enumerate} - \item Organize \texttt{catch} statements in a tree. - \item Add a path to the exit on the root. - \item Maybe reference parallelism with the treatment of unconditional statements. - \end{enumerate} + \centering + \includegraphics<+>[height=0.9\textheight]{figs/problem3} + \includegraphics<+>[height=0.9\textheight]{figs/problem3-color} + \includegraphics<+>[height=0.9\textheight]{figs/problem3-sol-color} + \includegraphics<+>[height=0.9\textheight]{figs/problem3-sol} + \includegraphics<+>[height=0.9\textheight]{figs/problem3-sol-sliced} \end{frame} \section{Conclusions} \begin{frame}{Conclusions} \begin{itemize} - \item Program slicing: a powerful technique, not yet complete for commonly used programming languages. - \item Any proposal exchanges efficiency for completeness/correctness. - \item Complete is required, correct is nice. - \item Unconditional jumps are complete: let's correct them. - \item Results - \begin{itemize} - \item 3 problems and proposed solutions. - \item NOMBRE PAPER, submitted to BLA BLA. - \item OTHER WORK, to be submitted to BLA BLA. - \end{itemize} + \item<+-> Program slicing: a powerful technique, not yet complete for commonly used programming languages. + \item Efficiency vs. completeness and correctness. + \item<+-> Results: 3 problems and proposed solutions. + % \begin{itemize} + % \item + % \item Problem 1: submitted to LCTES 2020 (ACM SIGPLAN Languages, Compilers and Tools for Embedded Systems). + % \end{itemize} \end{itemize} \end{frame} \begin{frame}{Future work} \begin{itemize} + % \item Publish Problem 2 and Problem 3. \item Improve correctness of \texttt{try-catch}. \item Implement into existing software tools, benchmark against state of the art. \item Adapt to other variants of program slicing. - \item Redefine control dependence: Danicic TODO (nº cita) tried, \textit{execution dependence} vs. \textit{presence dependence}. + \item Redefine control dependence (extend Danicic's work \cite{DanBHHKL11}), \textit{execution dependence} vs. \textit{presence dependence}. \end{itemize} \end{frame} -\begin{frame}{The End} -\end{frame} - - \appendix % \section*{Extra slides} \begin{frame}[noframenumbering]{Related work} Change to state of the art and move to introduction \begin{itemize} - \item SinH98 and SinH99 introduce the field slicing + exceptions - \item AllH03 improves the existing techniques - \item HorwitzRB88 introduces the current handling of unconditional jumps - \item JoC04 presents an alternative way to compute the CFG, but does not demonstrate the effects for program slicing. - \item JiaZSJ06 propose a solution in C++, ... TODO - \item PraMB11 also work in C++, no notable improvement TODO - \item JieS11 introduces OO + Exception SDG, but treats exceptions similar to Horwitz, leaving the original problems unresolved. + \item 1988: Horwitz, Reps and Ball \cite{HorwitzRB88} present the SDG. + \item 1993: Ball and Horwitz \cite{BalH93} present SDG with unconditional jumps + \item 1998: Sinha and Harrold \cite{SinH98,SinHR99} present SDG with exceptions. + \item 2003: Allen and Horwitz \cite{AllH03} improves \cite{SinH98}. + \pause + \item 2004: Jo and Chang \cite{JoC04} present an alternative construction of the graph (not demonstrated, not an improvement). + \item 2006: Jiang et al. \cite{JiaZSJ06} propose a solution for C++, not applicable. + \item 2011: Prabhy, Maeda and Blakrishnan \cite{PraMB11} propose another solution for C++, no notable improvement. + \item 2011: Jie and Shu-juan \cite{JieS11} introduce Object-Oriented + Exception SDG, same errors as \cite{AllH03}. \end{itemize} \end{frame} -\begin{frame}[noframenumbering]{Program slicing}{Strong and weak slices} - Slide with definitions + examples (code and table w/ sequences). +\begin{frame}[noframenumbering]{Program slicing}{Strong and Weak Slices} + \begin{definition}[Strong slice \cite{Wei81}] + Given a program $P$, its slice $S$ w.r.t. a slicing criterion $SC$ is a subset of the statements ($S \subseteq P$) such that the execution of $S$ yields the same sequence of values on $SC$ as the execution of $P$. + \end{definition} + \begin{definition}[Weak slice \cite{BinG96}] + Given a program $P$, its slice $S$ w.r.t. a slicing criterion $SC$ is a subset of the statements ($S \subseteq P$) such that the execution of $S$ yields a sequence of values on $SC$ ($\textit{seq}_S$), the execution of $P$ yields a sequence of values on $SC$ ($\textit{seq}_P$), and $\textit{seq}_P$ is a prefix of $\textit{seq}_S$. + \end{definition} \end{frame} -\begin{frame} - \frametitle{Bibliography} +\begin{frame}[noframenumbering]{Program Slicing}{Strong and Weak Slices: Example} + \begin{table} + \centering + \label{tab:slice-weak} + \begin{tabular}{r | r | r | r | r | r } + Original program & 1 & 2 & 6 & - & - \\ \hline + Slice A & 1 & 2 & 6 & - & - \\ \hline + Slice B & 1 & 2 & 6 & 24 & 120 \\ \hline + Slice C & 1 & 1 & 1 & 1 & 1 \\ + \end{tabular} + \caption{Sequences of values produced on the slicing criterion.} + \end{table} +\end{frame} + +\begin{frame}[noframenumbering,allowframebreaks]{Bibliography} \printbibliography \end{frame}