Debian Codegraph @

clang/utils/make-ast-dump-check.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # This script is intended as a FileCheck replacement to update the test
4 # expectations in a -ast-dump test.
5 #
6 # Usage (to generate normal AST dump tests):
7 #
8 # $ lit -DFileCheck=$PWD/utils/make-ast-dump-check.sh test/AST/ast-dump-openmp-*
9 #
10 # Usage (to generate serialization AST dump tests):
11 #
12 # $ lit -DFileCheck="generate_serialization_test=1 $PWD/utils/make-ast-dump-check.sh"
13 # test/AST/ast-dump-openmp-*
14
15 prefix=CHECK
16
17 if [ -z ${generate_serialization_test+x} ];
18 then generate_serialization_test=0;
19 fi
20
21 while [[ "$#" -ne 0 ]]; do
22 case "$1" in
23 --check-prefix)
24 shift
25 prefix="$1"
26 ;;
27 --implicit-check-not)
28 shift
29 ;;
30 -*)
31 ;;
32 *)
33 file="$1"
34 ;;
35 esac
36 shift
37 done
38
39 testdir="$(dirname "$file")"
40
41 read -r -d '' script <<REWRITE
42 BEGIN {
43 skipping_builtins = 0
44 matched_last_line = 0
45 }
46
47 /^[\`|].* line:/ {
48 skipping_builtins = 0
49 }
50
51 /^[\`|].* col:/ {
52 skipping_builtins = 0
53 }
54
55 {
56 if (skipping_builtins == 1) {
57 matched_last_line = 0
58 next
59 }
60 }
61
62 /TranslationUnitDecl/ {
63 skipping_builtins = 1
64 }
65
66 {
67 s = \$0
68 gsub("0x[0-9a-fA-F]+", "{{.*}}", s)
69 gsub("$testdir/", "{{.*}}", s)
70 if ($generate_serialization_test == 1) {
71 gsub(" imported", "{{( imported)?}}", s)
72 gsub(" <undeserialized declarations>", "{{( <undeserialized declarations>)?}}", s)
73 gsub("line:[0-9]+:[0-9]+", "line:{{.*}}", s)
74 gsub("line:[0-9]+", "line:{{.*}}", s)
75 gsub("col:[0-9]+", "col:{{.*}}", s)
76 gsub(":[0-9]+:[0-9]+", "{{.*}}", s)
77 }
78 }
79
80 matched_last_line == 0 {
81 print "// ${prefix}:" s
82 }
83
84 matched_last_line == 1 {
85 print "// ${prefix}-NEXT:" s
86 }
87
88 {
89 matched_last_line = 1
90 }
91 REWRITE
92
93 echo "$script"
94
95 {
96 cat "$file" | grep -v "$prefix"
97 awk "$script"
98 } > "$file.new"
99
100 mv "$file.new" "$file"