summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/test/AST/gen_ast_dump_json_test.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/clang/test/AST/gen_ast_dump_json_test.py b/clang/test/AST/gen_ast_dump_json_test.py
index b03e3cb2377..464987b2217 100644
--- a/clang/test/AST/gen_ast_dump_json_test.py
+++ b/clang/test/AST/gen_ast_dump_json_test.py
@@ -68,7 +68,6 @@ def main():
update_or_generate_group.add_argument("--update", help="Update the file in-place", action="store_true")
update_or_generate_group.add_argument("--opts", help="other options",
action="store", default='', type=str)
-
args = parser.parse_args()
if not args.source:
@@ -80,19 +79,31 @@ def main():
print("clang binary specified not present.")
return -1
- filters = set(args.filters.split(',')) if args.filters else set()
-
- note = "// NOTE: CHECK lines have been autogenerated by " \
- "gen_ast_dump_json_test.py"
-
- if (args.filters):
- note += "\n// using --filters=" + args.filters
-
+ note_firstline = "// NOTE: CHECK lines have been autogenerated by " \
+ "gen_ast_dump_json_test.py"
+ filters_line_prefix = "// using --filters="
+ note = note_firstline
+
cmd = [clang_binary, "-cc1"]
if args.update:
# When updating the first line of the test must be a RUN: line
with open(args.source, "r") as srcf:
first_line = srcf.readline()
+ filters_line_next = False
+ filters_line = None
+ for i, line in enumerate(srcf.readlines()):
+ if filters_line_next:
+ # print("Filters line: '", line.rstrip(), "'", sep="")
+ if line.startswith(filters_line_prefix):
+ filters_line = line[len(filters_line_prefix):].rstrip()
+ break
+ if line.startswith(note_firstline):
+ filters_line_next = True
+ # print("Found autogenerated disclaimer at line", i + 1)
+ if not args.filters and filters_line:
+ args.filters = filters_line
+ print("Inferred filters as '" + args.filters + "'")
+
if "RUN: %clang_cc1 " not in first_line:
sys.exit("When using --update the first line of the input file must contain RUN: %clang_cc1")
clang_start = first_line.find("%clang_cc1") + len("%clang_cc1")
@@ -115,6 +126,12 @@ def main():
using_ast_dump_filter = any('ast-dump-filter' in arg for arg in cmd)
cmd.append(args.source)
print("Will run", cmd)
+ filters = set()
+ if args.filters:
+ note += "\n" + filters_line_prefix + args.filters
+ filters = set(args.filters.split(','))
+ print("Will use the following filters:", filters)
+
try:
json_str = subprocess.check_output(cmd)
@@ -147,7 +164,7 @@ def main():
with open(args.source, "r") as srcf:
for line in srcf.readlines():
# copy up to the note:
- if line.rstrip() == note:
+ if line.rstrip() == note_firstline:
break
f.write(line)
f.write(note + "\n")
OpenPOWER on IntegriCloud