forked from AlexeyKupershtokh/xdebugtoolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgparsermx.py
142 lines (120 loc) · 4.28 KB
/
cgparsermx.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from mx.TextTools import *
from cgparser import *
class Context:
def __init__(self):
self.entries = []
self._last_entry = None
self._last_raw_call = None
self._fl_cache = {}
self._fn_cache = {}
def set_version(self, taglist, text, l, r, subtags):
self.version = text[l:r]
def set_fl(self, taglist, text, l, r, subtags):
self._last_entry = RawEntry()
self.entries.append(self._last_entry)
fl = text[l:r]
try:
self._last_entry.fl = self._fl_cache[fl]
except KeyError:
self._last_entry.fl = self._fl_cache[fl] = FileName(fl)
def set_fn(self, taglist, text, l, r, subtags):
fn = text[l:r]
try:
self._last_entry.fn = self._fn_cache[fn]
except KeyError:
self._last_entry.fn = self._fn_cache[fn] = FunctionName(fn)
def set_summary(self, taglist, text, l, r, subtags):
pass
def set_position(self, taglist, text, l, r, subtags):
self._last_entry.position = int(text[l:r])
def set_time(self, taglist, text, l, r, subtags):
self._last_entry.self_time = int(text[l:r])
def set_subcall_cfn(self, taglist, text, l, r, subtags):
self._last_raw_call = RawCall()
self._last_entry.add_subcall(self._last_raw_call)
cfn = text[l:r]
try:
self._last_raw_call.cfn = self._fn_cache[cfn]
except KeyError:
self._last_raw_call.cfn = self._fn_cache[cfn] = FunctionName(cfn)
def set_subcall_position(self, taglist, text, l, r, subtags):
self._last_raw_call.position = int(text[l:r])
def set_subcall_time(self, taglist, text, l, r, subtags):
self._last_raw_call.inclusive_time = int(text[l:r])
contextobj = Context()
header_table = (
# version
(None, Word, 'version: ', MatchFail),
(contextobj.set_version, AllNotIn+CallTag, newline, MatchFail),
(None, AllIn, newline, MatchFail),
# cmd
(None, Word, 'cmd: ', MatchFail),
('cmd', AllNotIn, newline, MatchFail),
(None, AllIn, newline, MatchFail),
# part
(None, Word, 'part: ', MatchFail),
('part', AllNotIn, newline, MatchFail),
(None, AllIn, newline, MatchFail),
# events
(None, Word, 'events: ', MatchFail),
('events', AllNotIn, newline, MatchFail),
(None, AllIn, newline, MatchFail),
)
subcall_table = (
# cfn
(None, Word, 'cfn=', MatchFail),
(contextobj.set_subcall_cfn, AllNotIn + CallTag, newline, MatchFail),
(None, AllIn, newline, MatchFail),
# calls
(None, Word, 'calls=1 0 0', MatchFail),
(None, AllIn, newline, MatchFail),
# position
(contextobj.set_subcall_position, AllIn + CallTag, number, MatchFail),
(None, Word, ' ', MatchFail),
# time
(contextobj.set_subcall_time, AllIn + CallTag, number, MatchFail),
(None, AllIn, newline, MatchFail),
)
entry_table = (
# fl
(None, Word, 'fl=', MatchFail),
#('fl', AllNotIn, newline, MatchFail),
#('fl', AllNotIn, newline, MatchFail),
(contextobj.set_fl, AllNotIn + CallTag, newline, MatchFail),
(None, AllIn, newline, MatchFail),
# fn
(None, Word, 'fn=', MatchFail),
#('fn', AllNotIn, newline, MatchFail),
(contextobj.set_fn, AllNotIn + CallTag, newline, MatchFail),
(None, AllIn, newline, MatchFail),
# summary
(None, Word, 'summary: ', +3),
(contextobj.set_summary, AllNotIn + CallTag, newline, MatchFail),
(None, AllIn, newline, MatchFail),
# position
(contextobj.set_position, AllIn + CallTag, number, MatchFail),
(None, AllIn, ' ', MatchFail),
# time
(contextobj.set_time, AllIn + CallTag, number, MatchFail),
(None, AllIn, newline, MatchFail),
# subcalls
(None, Word + LookAhead, 'cfn=', MatchOk),
(None, Table, subcall_table, MatchFail, -1),
)
cg_table = (
# header
(None, Table, header_table, MatchFail),
# body
(None, Word + LookAhead, 'fl=', MatchOk),
(None, Table, entry_table, MatchFail, -1),
)
if __name__ == '__main__':
import sys
import time
contents = open(sys.argv[1]).read()
timer = time.time()
result, taglist, nextindex = tag(contents, cg_table, 0)
if result != 1:
raise Exception('finished with an error')
print time.time() - timer
#print_tags(text,taglist)