| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Tokstyle.Cimple.Analysis.Functions
Description
Function definitions with their success conventions, and helpers for analysing function bodies.
Synopsis
- data Function = Function {}
- data Shape
- data Outcome
- definitions :: [(FilePath, [Node (Lexeme Text)])] -> [Function]
- callees :: Function -> [Text]
- bottomUp :: Eq k => (Function -> [Text]) -> (s -> Function -> s) -> (s -> Function -> k) -> [Function] -> s -> s
- freers :: Map Text Int
- allocators :: Map Text Int
- bare :: Node (Lexeme Text) -> Node (Lexeme Text)
- accessPath :: Node (Lexeme Text) -> Maybe AccessPath
- mapRoot :: (String -> String) -> AccessPath -> AccessPath
- valuesUsed :: Node (Lexeme Text) -> [Text]
- returnOutcomes :: Shape -> Maybe (Node (Lexeme Text)) -> [Outcome]
- branchOn :: Map Text Shape -> Node (Lexeme Text) -> Maybe (Lexeme Text, Outcome)
- calleeLexeme :: Node (Lexeme Text) -> Lexeme Text
- universe :: Node (Lexeme Text) -> [Node (Lexeme Text)]
- strip :: Node (Lexeme Text) -> Node (Lexeme Text)
- unFix' :: Node (Lexeme Text) -> NodeF (Lexeme Text) (Node (Lexeme Text))
- intLit :: Node (Lexeme Text) -> Maybe Integer
- constName :: Node (Lexeme Text) -> Maybe Text
- isNullLit :: Node (Lexeme Text) -> Bool
- nullTest :: (Node (Lexeme Text) -> Maybe a) -> Node (Lexeme Text) -> Maybe (a, EdgeType)
- isEnumConst :: Text -> Bool
- flagHolds :: Map String Text -> Node (Lexeme Text) -> EdgeType -> Bool
- localDecls :: Node (Lexeme Text) -> [(String, Maybe (Node (Lexeme Text)))]
- assignments :: Node (Lexeme Text) -> Map String [Node (Lexeme Text)]
- nodeExprs :: Node -> [Node (Lexeme Text)]
- rootOf :: AccessPath -> Maybe String
- throughPointer :: AccessPath -> Bool
- render :: AccessPath -> Doc ann
Documentation
The convention a function's return value uses to report success.
Instances
| Bounded Outcome Source # | |
| Enum Outcome Source # | |
| Show Outcome Source # | |
| Eq Outcome Source # | |
| Ord Outcome Source # | |
Defined in Tokstyle.Cimple.Analysis.Functions | |
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.
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.
mapRoot :: (String -> String) -> AccessPath -> AccessPath Source #
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.
isEnumConst :: Text -> Bool Source #
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.
render :: AccessPath -> Doc ann Source #