Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: tools/clang/scripts/apply-fixits.py

Issue 598073004: Proof of concept fixit rewriting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@virt-annotations
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « iteratively-fix.sh ('k') | tools/clang/scripts/plugin_flags.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env/python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6
7 import collections
8 import fileinput
9 import os
10 import re
11 import sys
12
13
14 # fix-it:"../../base/threading/sequenced_worker_pool.h":{341:3-341:11}:""
15 _FIXIT_RE = re.compile(r'^fix-it:"(?P<file>.+?)":'
16 r'{(?P<start_line>\d+?):(?P<start_col>\d+?)-'
17 r'(?P<end_line>\d+?):(?P<end_col>\d+?)}:'
18 r'"(?P<text>.*?)"$')
19
20
21 FixIt = collections.namedtuple('FixIt',
22 ('start_line', 'start_col', 'end_line', 'end_col', 'text'))
23
24
25 def main():
26 os.chdir('out/Debug')
27 fixits = collections.defaultdict(list)
28 for line in fileinput.input():
29 if not line.startswith('fix-it:'):
30 continue
31 m = _FIXIT_RE.match(line)
32 if not m:
33 continue
34 # The negative line numbers are a cheap hack so we can sort things in line
35 # order but reverse column order.
36 fixits[m.group('file')].append(FixIt(
37 int(m.group('start_line')),
38 -int(m.group('start_col')),
39 int(m.group('end_line')),
40 -int(m.group('end_col')),
41 m.group('text')))
42 for k, v in fixits.iteritems():
43 v.sort()
44 with open(k, 'rb+') as f:
45 lines = f.readlines()
46 last_fixit = None
47 for fixit in v:
48 if fixit.start_line != fixit.end_line:
49 print 'error: multiline fixits not supported! file: %s, fixit: %s' % (
50 k, fixit)
51 sys.exit(1)
52 if fixit == last_fixit:
53 continue
54 last_fixit = fixit
55 # Zero-based indexing is the one true way!
56 line = lines[fixit.start_line - 1]
57 lines[fixit.start_line - 1] = line[:-fixit.start_col - 1] + fixit.text + line[-fixit.end_col - 1:]
58 f.seek(0)
59 f.truncate()
60 f.writelines(lines)
61
62
63 if __name__ == '__main__':
64 sys.exit(main())
OLDNEW
« no previous file with comments | « iteratively-fix.sh ('k') | tools/clang/scripts/plugin_flags.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698