[PATCH] D66505: Make add_new_check.py's insertion of registerCheck<> more closely match the sort order
Daniel Sanders via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 19:14:14 PDT 2019
dsanders updated this revision to Diff 218010.
dsanders added a comment.
Sort on the check name string
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66505/new/
https://reviews.llvm.org/D66505
Files:
clang-tools-extra/clang-tidy/add_new_check.py
Index: clang-tools-extra/clang-tidy/add_new_check.py
===================================================================
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -165,31 +165,50 @@
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')
-
- 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:
+ '>(\n "' + check_fq_name + '");\n')
+
+ 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)
+ last_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
+ last_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 last_line:
+ f.write(last_line)
+ f.write(line)
+ except StopIteration:
+ pass
# Adds a release notes entry.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66505.218010.patch
Type: text/x-patch
Size: 2665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190830/f9029258/attachment.bin>
More information about the llvm-commits
mailing list