tokstyle
Safe HaskellNone
LanguageHaskell2010

Tokstyle.Cimple.Analysis.Functions

Description

Function definitions with their success conventions, and helpers for analysing function bodies.

Synopsis

Documentation

data Function Source #

Constructors

Function 

data Shape Source #

The convention a function's return value uses to report success.

Constructors

BoolShape

Returns true on success and false on failure.

ZeroShape

Returns 0 on success and a negative number on failure.

IdShape

Returns a negative number on failure and anything else on success.

PtrShape

Returns nullptr on failure.

NoShape 

callees :: Function -> [Text] Source #

Get the functions a function calls directly by name.

bottomUp :: Eq k => (Function -> [Text]) -> (s -> Function -> s) -> (s -> Function -> k) -> [Function] -> s -> s Source #

Compute function summaries bottom-up over the strongly connected components of the call graph. add adds a function's summary, and each cycle is iterated until look stops changing, at most length + 2 times.

freers :: Map Text Int Source #

Deallocation functions, with the position of the argument they free.

allocators :: Map Text Int Source #

Allocation functions returning fresh memory, with the position of their element count or size argument.

accessPath :: Node (Lexeme Text) -> Maybe AccessPath Source #

Get the access path of an expression naming a variable, field, element or pointee.

valuesUsed :: Node (Lexeme Text) -> [Text] Source #

Get the names used other than as callees, e.g. a function passed or stored as a value.

branchOn :: Map Text Shape -> Node (Lexeme Text) -> Maybe (Lexeme Text, Outcome) Source #

For a condition on a call's return value, get the call and the outcome it reported on the true branch.

intLit :: Node (Lexeme Text) -> Maybe Integer Source #

Get the value of an integer literal, including negative ones.

constName :: Node (Lexeme Text) -> Maybe Text Source #

Get the name of a named constant, e.g. true, nullptr or TOX_OK.

nullTest :: (Node (Lexeme Text) -> Maybe a) -> Node (Lexeme Text) -> Maybe (a, EdgeType) Source #

Find the expression a condition tests for null, mapped through view, and the branch on which it is null.

flagHolds :: Map String Text -> Node (Lexeme Text) -> EdgeType -> Bool Source #

Whether a branch on an error flag can be taken with the enum constants the flags hold.

localDecls :: Node (Lexeme Text) -> [(String, Maybe (Node (Lexeme Text)))] Source #

Get the local variables of a function with their initialisers.

assignments :: Node (Lexeme Text) -> Map String [Node (Lexeme Text)] Source #

Get the values assigned to each local variable after its declaration.

throughPointer :: AccessPath -> Bool Source #

Check if a path goes through a pointer, i.e. names memory that outlives the function.