The Understand Python API gives scripts access to everything Understand knows about your code — entities, references, metrics, and dependencies — and powers custom checks, graphs, and reports.

CFGraph#

class understand.CFGraph#

Bases: object

A control flow graph

Control flow graphs are returned from applicable entities with understand.Ent.control_flow_graph(). The graph contains control flow nodes which can be retrieved with nodes. The edges out of each node are given with the children method. Some nodes may be unreachable from the start node.

Methods Summary

is_trivial

Return True if the graph is trivial.

nodes

Return a list of all nodes in the graph

start

Return the start node of the graph.

Classes Summary

Methods Documentation

is_trivial() → bool#

Return True if the graph is trivial.

Return type:

bool

Returns:

True if the graph is trivial

nodes() → list[understand.CFNode]#

Return a list of all nodes in the graph

Return type:

list[understand.CFNode]

Returns:

all nodes in the graph

start() → understand.CFNode#

Return the start node of the graph.

Return type:

understand.CFNode

Returns:

the start node

CFNode#

class understand.CFNode#

Bases: object

A node in a control flow graph

Node line and column numbers are 1-based, and both the beginning and the end are inclusive.

Methods Summary

child_label

Return the label from this node to child.

children

Return the children of this node.

column_begin

Return the column of the first character of the node.

column_end

Return the column of the last character of the node.

end_node

Return the end node if applicable

kind

Return the kind of the node.

line_begin

Return the line of the first character of the node.

line_end

Return the line of the last character of the node.

Methods Documentation

child_label(child) → str#

Return the label from this node to child.

Parameters:

child (understand.CFNode) – a child node

Return type:

str

Returns:

the label or None if none. Most nodes do not have labelled children.

Possible labels are:

  • “yes”: conditionals/loops

  • “no”: conditionals/loops

  • “<0”: arith-if

  • “=0”: arith-if

  • “>0”: arith-if

  • “default”: computed-goto, io-control

  • “end” : io-control

  • “eor” : io-control

  • “err” : io-control

  • “0”,”1”,etc: computed-goto

children(flags=understand.CFNode_Normal) → list[understand.CFNode]#

Return the children of this node.

Parameters:

flags (int) – optional, a combination of node flags

Return type:

list[understand.CFNode]

Returns:

a list of children

Flags control the type of children. The available flags are:

  • understand.CFNode_Normal

  • understand.CFNode_Deferred

If flags are not provided, normal children are returned.

column_begin() → int#

Return the column of the first character of the node.

Columns are 1-based and the beginning is inclusive.

Return type:

int

Returns:

the beginning column number if available. Nodes without location information will return None

column_end() → int#

Return the column of the last character of the node.

Columns are 1-based and the end is inclusive.

Return type:

int

Returns:

the ending column number if available. Nodes without location information will return None

end_node() → understand.CFNode#

Return the end node if applicable

Return type:

understand.CFNode

Returns:

the end node or None if there is none. Structures such as loops and conditionals have an end node.

kind() → str#

Return the kind of the node.

Return type:

str

Returns:

the kind of the node

Possible kinds are:

accept-block-begin

end-do-while

loop

arith-if

end-if

loop-expr

assigned-goto

end-loop

next

block-begin

end-repeat-until

next-when

break

end-select

passive

call-alt-return

end-select

raise

case

end-switch

repeat-until

case-default

end-try

return

case-fallthru

end-where

select

case-when

end-with-do

select-case

computed-goto

exception-when

select-else

conditional-goto

exit

select-or

continue

exit-do

select-then-abort

continue-do

exit-do-if

start

continue-for

exit-for

stop

continue-while

exit-for-if

switch

cycle

exit-if

switch-case

do

exit-if-if

switch-default

do-infinite

exit-loop

terminate

do-until

exit-loop-if

throw

do-while

exit-select

try

else

exit-try

try-catch

else-where

exit-when

try-else

else-where-cond

exit-while

try-finally

elsif

exit-while-if

until

end

for

where

end-block

goto

while

end-case

if

while-for

end-do

io-control

while-for-else

end-do-until

jovial3-goto

with-do

line_begin() → int#

Return the line of the first character of the node.

Lines are 1-based and the beginning is inclusive.

Return type:

int

Returns:

the beginning line number if available. Nodes without location information will return None

line_end() → int#

Return the line of the last character of the node.

Lines are 1-based and the end is inclusive.

Return type:

int

Returns:

the ending line number if available. Nodes without location information will return None