FlowControl.pxd 2.88 KB
Newer Older
1 2
from __future__ import absolute_import

3 4
cimport cython

5
from .Visitor cimport CythonTransform, TreeVisitor
6

7 8 9 10 11 12 13 14
cdef class ControlBlock:
     cdef public set children
     cdef public set parents
     cdef public set positions
     cdef public list stats
     cdef public dict gen
     cdef public set bounded

15
     # Big integer bitsets
16 17 18 19 20 21
     cdef public object i_input
     cdef public object i_output
     cdef public object i_gen
     cdef public object i_kill
     cdef public object i_state

22 23 24 25 26 27 28
     cpdef bint empty(self)
     cpdef detach(self)
     cpdef add_child(self, block)

cdef class ExitBlock(ControlBlock):
     cpdef bint empty(self)

29 30
cdef class NameAssignment:
    cdef public bint is_arg
31
    cdef public bint is_deletion
32 33 34 35 36 37
    cdef public object lhs
    cdef public object rhs
    cdef public object entry
    cdef public object pos
    cdef public set refs
    cdef public object bit
38
    cdef public object inferred_type
39 40 41 42 43 44

cdef class AssignmentList:
    cdef public object bit
    cdef public object mask
    cdef public list stats

45 46 47
cdef class AssignmentCollector(TreeVisitor):
    cdef list assignments

48
@cython.final
49 50 51 52 53 54 55 56 57 58
cdef class ControlFlow:
     cdef public set blocks
     cdef public set entries
     cdef public list loops
     cdef public list exceptions

     cdef public ControlBlock entry_point
     cdef public ExitBlock exit_point
     cdef public ControlBlock block

59 60
     cdef public dict assmts

61 62
     cpdef newblock(self, ControlBlock parent=*)
     cpdef nextblock(self, ControlBlock parent=*)
63
     cpdef bint is_tracked(self, entry)
64
     cpdef bint is_statically_assigned(self, entry)
65
     cpdef mark_position(self, node)
66
     cpdef mark_assignment(self, lhs, rhs, entry)
67 68 69
     cpdef mark_argument(self, lhs, rhs, entry)
     cpdef mark_deletion(self, node, entry)
     cpdef mark_reference(self, node, entry)
70 71

     @cython.locals(block=ControlBlock, parent=ControlBlock, unreachable=set)
72 73
     cpdef normalize(self)

74
     @cython.locals(bit=object, assmts=AssignmentList,
75 76 77 78 79 80 81 82 83
                    block=ControlBlock)
     cpdef initialize(self)

     @cython.locals(assmts=AssignmentList, assmt=NameAssignment)
     cpdef set map_one(self, istate, entry)

     @cython.locals(block=ControlBlock, parent=ControlBlock)
     cdef reaching_definitions(self)

84 85 86
cdef class Uninitialized:
     pass

87 88 89
cdef class Unknown:
    pass

90 91 92 93 94

cdef class MessageCollection:
    cdef set messages


Stefan Behnel's avatar
Stefan Behnel committed
95 96
@cython.locals(dirty=bint, block=ControlBlock, parent=ControlBlock,
               assmt=NameAssignment)
97
cdef check_definitions(ControlFlow flow, dict compiler_directives)
98

99
@cython.final
100 101
cdef class ControlFlowAnalysis(CythonTransform):
    cdef object gv_ctx
102
    cdef object constant_folder
103 104 105 106 107
    cdef set reductions
    cdef list env_stack
    cdef list stack
    cdef object env
    cdef ControlFlow flow
108
    cdef object object_expr
109 110 111 112
    cdef bint in_inplace_assignment

    cpdef mark_assignment(self, lhs, rhs=*)
    cpdef mark_position(self, node)