No, it isn't fine:
A control flow graph is an abstraction of the your code in which the control is represented by arrows and commands are represented by nodes.
Control include branching (if), loops (while, for) or terminations (break, return).
Commands include assignment (a=b), operations on data (-x, x+y, x==y...), function calls (which can also introduce an edge if you are doing inter-procedural building) and whichever other constructs your language may have (in your example, Java has type annotations).
It is important to note that values shouldn't be nodes. So in a = b + 1
, the node is the whole expression, and b
and 1
aren't nodes. This may vary depending on your internal representation, but I think that it's a good guideline.
In your example, you are missing the nodes for:
leng = A.length;
n = 0;
res = true;
in the node 4, it should be the comparison (n < leng
) instead of the while (while is control, it is already encoded as edges).
in the node 5, it should be the expression A[n] <= 0 && !boo[n]
instead of if.
in node 7, there shouldn't be an arrow to node 8 (after the end of the while body, the control goes to the condition again)
in node 8, you are missing what you are returning (and return is also control, so it shouldn't be in the node)
Also, you should include the parameters of the function as local declarations.
Basic blocks are an optimization, you can build a perfectly fine CFG with just one command per node.