Directed Graphs
https://softwareengineering.stackexchange.com/questions/401905
题
Conisder the following piece of code :
cin >> a >> b;
int x,y,z;
x=0; y=1; z=1;
if (a > b){
x = a*b;
while (10 > a){
y=y+z;
a=a+5;
}
else {
x=x+b;
}
Its Directed graph is shown below :
Now the next figure is Annotated tokens showing the slices on which the tokens occur
Now from the above figure we can calculate many cohesion metrics ( for example weak functional cohesion) . My question is how did we transform the directed graph to this annotated diagram . In other words I can't understand this statement "Annotated tokens showing the slices on which the tokens occur" ?
解决方案
Take a look at the output X
(its on the bottom). The notation states that the X
relies only on itself. Which makes sense: evaluate(X) == X
.
One step up and you have the statement x = x b
. Again evaluate(X) == X
so the x
on the left hand side of the assignment is self-explanatory. The x
and b
on the right of the assignment only influence x
though, hence they influence the output token X
. b
is the input token B
, so the input token also affects the outcome of X
.
Now the input token B
can also influence to output token Y
. It does this by the (a > b)
comparison being true. This executes extra code that modifies y
. You can see this by the arrows. So while it does not appear in the expressions concerning y
it none the less has an effect. Similarly for a
and the output token A
.
What this leaves us with is each symbol being annotated with the outputs it influences.
note: I've capitalised the input/output variables to differentiate for the intermediates as lower-case.