-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.py
82 lines (77 loc) · 1.84 KB
/
compile.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys, re
allocs_i = 0
allocs = {}
funcs = []
for line in sys.stdin:
line = line.strip()
if line == "" or line[0] == "#":
continue
m = re.match('^alloc(\[(.*)\])?:$', line)
if m:
allocs_i += 1
key = 'alloc'
if m.group(2):
if m.group(2) not in allocs:
allocs[m.group(2)] = {}
current = m.group(2)
else:
current = str(allocs_i)
allocs[current] = {}
elif line == 'dealloc:':
key = 'dealloc'
elif line == 'use:':
key = 'use'
elif line == 'functions:':
key = 'functions'
else:
if key == 'functions':
funcs.append(line)
else:
if not key in allocs[current]:
allocs[current][key] = []
allocs[current][key].append(line)
print "<?xml version=\"1.0\"?>"
print "<!-- THIS FILE IS GENERATED AUTOMATICALLY. See https://github.com/scriptum/cppcheck-libs -->"
print "<def>"
if len(sys.argv) > 1:
for i in sys.argv[1:]:
with open(i, 'r') as f:
import re
pattern = re.compile("^#define\s+([^\s()]+\s*(?:\([^)]*\))?)\s+(.*)$")
for line in f:
match = pattern.match(line.strip())
if match:
print " <define name=\""+match.group(1)+"\" value=\""+match.group(2)+"\"/>"
for key in allocs:
print " <memory>";
for k in allocs[key]:
for vv in allocs[key][k]:
init = ''
name = vv
if k == "alloc":
try:
name, init = vv.split()
if init == 'noinit':
init = ''
else:
init = ' init="true"'
except:
init = ' init="true"'
print " <"+k+init+">"+name+"</"+k+">"
print " </memory>"
for v in funcs:
opts = v.split()
print " <function name=\""+opts[0]+"\">"
noret = False
for vv in opts[1:]:
if vv == "leak-ignore":
print " <leak-ignore/>"
elif vv == "noreturn":
noret = True
print " <noreturn>true</noreturn>"
if not noret:
print " <noreturn>false</noreturn>"
print " </function>"
print "</def>"