These model all executions of a method by describing control structures where nodes are statements or sequences or statements and edges transfer control.
Components
- Basic block
- A sequence of statements such that if the first statement is executed, all statements will be. I.E statements that always execute together. This always has one entry and exit point.
- Intermediate statements in a sequence of statements are not shown, as a simplification as long as there are no branches.
- If statements
- Nodes corresponding to branching should not contain any assignments
- This is important for the identification of data flow information
- Returns from the branches of an if statement must be distinct
- While and for loops
- While and for loops look like if statements with a loop returning to the condition node
- Do loops, break and continues
- A do loop executes a statement first and then loops from that statement to itself for a condition
- Breaks and continues just redirect the flow of the program based on a condition
- Cases
- Cases without breaks fall through to the next case
- Try-catch
- These are essentially also conditions based on where possible errors could occur, how we handle them, and where we explicitly throw errors
These CFGs are sometimes annotated with extra information like what is actually happening inside a node (the statement predicate). Look at the lecture slides for examples as this will become more self explanatory.