summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/dist/s_function_with.py
blob: ff3438d2254e638c3d2df9c6376e3840978b5d34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Examine WT_WITH_* macros and complain if an early exit out of the
# macro is done.  These macros potentially restore state after they execute
# an expression, and an early exit, like a return/goto means the state
# will not be restored.
#
# Files appear verbatim, separated by a recognizable pattern.
import re, sys

def get_indent(line):
    return len(line) - len(line.lstrip())

filepat = re.compile('===(.*)===')
withpat = re.compile('WT_WITH_')
exitpat = re.compile('(WT_ERR|WT_RET|return\(|goto )')
filename = ''
linenum = 0
with_indent = -1
with_linenum = -1
with_line = None
for line in sys.stdin:
    m = filepat.search(line)
    if m != None:
        filename = m.group(1)
        linenum = 0
        with_indent = -1
        with_linenum = -1
        with_line = None
    linenum += 1

    # Are we within a WT_WITH?
    if with_indent >= 0:
        cur_indent = get_indent(line)
        # Have we "broken out" of the WT_WITH_.... macro?
        # Our enforced formatting ensures this happens when the indent finishes.
        if cur_indent <= with_indent:
            # Yes, broken out
            with_indent = -1
            with_linenum = -1
            with_line = None
        elif exitpat.search(line):
            print('{}: line {}: early exit: {}\n  from: {}: line {}: {}'.format(
                filename, linenum, line.strip(), filename, with_linenum,
                with_line.strip()))
    else:
        m = withpat.search(line)
        if m:
            with_indent = get_indent(line)
            with_linenum = linenum
            with_line = line