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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « iteratively-fix.sh ('k') | tools/clang/scripts/plugin_flags.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/scripts/apply-fixits.py
diff --git a/tools/clang/scripts/apply-fixits.py b/tools/clang/scripts/apply-fixits.py
new file mode 100755
index 0000000000000000000000000000000000000000..0f4231f9818403d3941f341f85f10bb472c0c8b2
--- /dev/null
+++ b/tools/clang/scripts/apply-fixits.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env/python
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+import collections
+import fileinput
+import os
+import re
+import sys
+
+
+# fix-it:"../../base/threading/sequenced_worker_pool.h":{341:3-341:11}:""
+_FIXIT_RE = re.compile(r'^fix-it:"(?P<file>.+?)":'
+ r'{(?P<start_line>\d+?):(?P<start_col>\d+?)-'
+ r'(?P<end_line>\d+?):(?P<end_col>\d+?)}:'
+ r'"(?P<text>.*?)"$')
+
+
+FixIt = collections.namedtuple('FixIt',
+ ('start_line', 'start_col', 'end_line', 'end_col', 'text'))
+
+
+def main():
+ os.chdir('out/Debug')
+ fixits = collections.defaultdict(list)
+ for line in fileinput.input():
+ if not line.startswith('fix-it:'):
+ continue
+ m = _FIXIT_RE.match(line)
+ if not m:
+ continue
+ # The negative line numbers are a cheap hack so we can sort things in line
+ # order but reverse column order.
+ fixits[m.group('file')].append(FixIt(
+ int(m.group('start_line')),
+ -int(m.group('start_col')),
+ int(m.group('end_line')),
+ -int(m.group('end_col')),
+ m.group('text')))
+ for k, v in fixits.iteritems():
+ v.sort()
+ with open(k, 'rb+') as f:
+ lines = f.readlines()
+ last_fixit = None
+ for fixit in v:
+ if fixit.start_line != fixit.end_line:
+ print 'error: multiline fixits not supported! file: %s, fixit: %s' % (
+ k, fixit)
+ sys.exit(1)
+ if fixit == last_fixit:
+ continue
+ last_fixit = fixit
+ # Zero-based indexing is the one true way!
+ line = lines[fixit.start_line - 1]
+ lines[fixit.start_line - 1] = line[:-fixit.start_col - 1] + fixit.text + line[-fixit.end_col - 1:]
+ f.seek(0)
+ f.truncate()
+ f.writelines(lines)
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« 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