[clang-tools-extra] r370527 - Make add_new_check.py's insertion of registerCheck<> match the sort order
Daniel Sanders via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 30 13:47:02 PDT 2019
Author: dsanders
Date: Fri Aug 30 13:47:02 2019
New Revision: 370527
URL: http://llvm.org/viewvc/llvm-project?rev=370527&view=rev
Log:
Make add_new_check.py's insertion of registerCheck<> match the sort order
Summary:
Following on from review comments in D65919 about the ordering
of the registerCheck<> calls. Sort based on the check name which might
be on the line after the registerCheck<>
Reviewers: aaron.ballman
Subscribers: cfe-commits, llvm-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66505
Modified:
clang-tools-extra/trunk/clang-tidy/add_new_check.py
Modified: clang-tools-extra/trunk/clang-tidy/add_new_check.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/add_new_check.py?rev=370527&r1=370526&r2=370527&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py Fri Aug 30 13:47:02 2019
@@ -165,31 +165,50 @@ def adapt_module(module_path, module, ch
header_added = False
header_found = False
check_added = False
+ check_fq_name = module + '-' + check_name
check_decl = (' CheckFactories.registerCheck<' + check_name_camel +
- '>(\n "' + module + '-' + check_name + '");\n')
+ '>(\n "' + check_fq_name + '");\n')
- for line in lines:
- if not header_added:
- match = re.search('#include "(.*)"', line)
- if match:
- header_found = True
- if match.group(1) > check_name_camel:
+ lines = iter(lines)
+ try:
+ while True:
+ line = lines.next()
+ if not header_added:
+ match = re.search('#include "(.*)"', line)
+ if match:
+ header_found = True
+ if match.group(1) > check_name_camel:
+ header_added = True
+ f.write('#include "' + check_name_camel + '.h"\n')
+ elif header_found:
header_added = True
f.write('#include "' + check_name_camel + '.h"\n')
- elif header_found:
- header_added = True
- f.write('#include "' + check_name_camel + '.h"\n')
- if not check_added:
- if line.strip() == '}':
- check_added = True
- f.write(check_decl)
- else:
- match = re.search('registerCheck<(.*)>', line)
- if match and match.group(1) > check_name_camel:
+ if not check_added:
+ if line.strip() == '}':
check_added = True
f.write(check_decl)
- f.write(line)
+ else:
+ match = re.search('registerCheck<(.*)> *\( *(?:"([^"]*)")?', line)
+ prev_line = None
+ if match:
+ current_check_name = match.group(2)
+ if current_check_name is None:
+ # If we didn't find the check name on this line, look on the
+ # next one.
+ prev_line = line
+ line = lines.next()
+ match = re.search(' *"([^"]*)"', line)
+ if match:
+ current_check_name = match.group(1)
+ if current_check_name > check_fq_name:
+ check_added = True
+ f.write(check_decl)
+ if prev_line:
+ f.write(prev_line)
+ f.write(line)
+ except StopIteration:
+ pass
# Adds a release notes entry.
More information about the cfe-commits
mailing list