Debian Codegraph @

python/coccilib/output.py

raw
1 from copy import deepcopy
2
3 class Output:
4 """In order to implement an output class for use with Coccinelle,
5 one can inherit from this class and overload register_match with
6 the same number of arguments.
7
8 include_match will be overwritten by inheriting from your actual
9 class, and thus if your class is a.b.C then Coccinelle will create
10 a Python class "class Coccinelle(a.b.C)" that hooks include_match
11 into the O'Caml internals.
12 """
13 def include_match(self, b):
14 pass
15
16 def register_match(self, include, messages):
17 pass
18
19 def combine(self, meta_variable, locations):
20 nmv = deepcopy(meta_variable)
21 nloc = [deepcopy(loc) for loc in locations]
22 nmv.location = nloc[0]
23 nmv.locations = nloc
24
25 return nmv
26
27 def finalise(self):
28 pass
29
30 def print_main (self, *args):
31 from coccilib.org import print_main
32 print_main(*args)
33
34 def print_sec (self, *args):
35 from coccilib.org import print_sec
36 print_sec(*args)
37
38 def print_secs (self, *args):
39 from coccilib.org import print_secs
40 print_secs(*args)
41
42 class Console(Output):
43 def __init__(self):
44 pass
45
46 def register_match(self, include, messages):
47 self.include_match(include)
48 if include:
49 for variable, message in messages:
50 print("%s:%s:%s: %s - %s" % (variable.location.file, variable.location.line, variable.location.column, message, variable))