* contrib/ari/gdb_ari.sh (OP eol rule): Also check
[deliverable/binutils-gdb.git] / gdb / contrib / ari / gdb_ari.sh
1 #!/bin/sh
2
3 # GDB script to list of problems using awk.
4 #
5 # Copyright (C) 2002-2013 Free Software Foundation, Inc.
6 #
7 # This file is part of GDB.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22 # Make certain that the script is not running in an internationalized
23 # environment.
24
25 LANG=C ; export LANG
26 LC_ALL=C ; export LC_ALL
27
28 # Permanent checks take the form:
29
30 # Do not use XXXX, ISO C 90 implies YYYY
31 # Do not use XXXX, instead use YYYY''.
32
33 # and should never be removed.
34
35 # Temporary checks take the form:
36
37 # Replace XXXX with YYYY
38
39 # and once they reach zero, can be eliminated.
40
41 # FIXME: It should be able to override this on the command line
42 error="regression"
43 warning="regression"
44 ari="regression eol code comment deprecated legacy obsolete gettext"
45 all="regression eol code comment deprecated legacy obsolete gettext deprecate internal gdbarch macro"
46 print_doc=0
47 print_idx=0
48
49 usage ()
50 {
51 cat <<EOF 1>&2
52 Error: $1
53
54 Usage:
55 $0 --print-doc --print-idx -Wall -Werror -W<category> <file> ...
56 Options:
57 --print-doc Print a list of all potential problems, then exit.
58 --print-idx Include the problems IDX (index or key) in every message.
59 --src=file Write source lines to file.
60 -Werror Treat all problems as errors.
61 -Wall Report all problems.
62 -Wari Report problems that should be fixed in new code.
63 -W<category> Report problems in the specifed category. Vaid categories
64 are: ${all}
65 EOF
66 exit 1
67 }
68
69
70 # Parse the various options
71 Woptions=
72 srclines=""
73 while test $# -gt 0
74 do
75 case "$1" in
76 -Wall ) Woptions="${all}" ;;
77 -Wari ) Woptions="${ari}" ;;
78 -Werror ) Werror=1 ;;
79 -W* ) Woptions="${Woptions} `echo x$1 | sed -e 's/x-W//'`" ;;
80 --print-doc ) print_doc=1 ;;
81 --print-idx ) print_idx=1 ;;
82 --src=* ) srclines="`echo $1 | sed -e 's/--src=/srclines=\"/'`\"" ;;
83 -- ) shift ; break ;;
84 - ) break ;;
85 -* ) usage "$1: unknown option" ;;
86 * ) break ;;
87 esac
88 shift
89 done
90 if test -n "$Woptions" ; then
91 warning="$Woptions"
92 error=
93 fi
94
95
96 # -Werror implies treating all warnings as errors.
97 if test -n "${Werror}" ; then
98 error="${error} ${warning}"
99 fi
100
101
102 # Validate all errors and warnings.
103 for w in ${warning} ${error}
104 do
105 case " ${all} " in
106 *" ${w} "* ) ;;
107 * ) usage "Unknown option -W${w}" ;;
108 esac
109 done
110
111
112 # make certain that there is at least one file.
113 if test $# -eq 0 -a ${print_doc} = 0
114 then
115 usage "Missing file."
116 fi
117
118
119 # Convert the errors/warnings into corresponding array entries.
120 for a in ${all}
121 do
122 aris="${aris} ari_${a} = \"${a}\";"
123 done
124 for w in ${warning}
125 do
126 warnings="${warnings} warning[ari_${w}] = 1;"
127 done
128 for e in ${error}
129 do
130 errors="${errors} error[ari_${e}] = 1;"
131 done
132
133 if [ "$AWK" = "" ] ; then
134 AWK=awk
135 fi
136
137 ${AWK} -- '
138 BEGIN {
139 # NOTE, for a per-file begin use "FNR == 1".
140 '"${aris}"'
141 '"${errors}"'
142 '"${warnings}"'
143 '"${srclines}"'
144 print_doc = '$print_doc'
145 print_idx = '$print_idx'
146 PWD = "'`pwd`'"
147 }
148
149 # Print the error message for BUG. Append SUPLEMENT if non-empty.
150 function print_bug(file,line,prefix,category,bug,doc,supplement, suffix,idx) {
151 if (print_idx) {
152 idx = bug ": "
153 } else {
154 idx = ""
155 }
156 if (supplement) {
157 suffix = " (" supplement ")"
158 } else {
159 suffix = ""
160 }
161 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
162 print file ":" line ": " prefix category ": " idx doc suffix
163 if (srclines != "") {
164 print file ":" line ":" $0 >> srclines
165 }
166 }
167
168 function fix(bug,file,count) {
169 skip[bug, file] = count
170 skipped[bug, file] = 0
171 }
172
173 function fail(bug,supplement) {
174 if (doc[bug] == "") {
175 print_bug("", 0, "internal: ", "internal", "internal", "Missing doc for bug " bug)
176 exit
177 }
178 if (category[bug] == "") {
179 print_bug("", 0, "internal: ", "internal", "internal", "Missing category for bug " bug)
180 exit
181 }
182
183 if (ARI_OK == bug) {
184 return
185 }
186 # Trim the filename down to just DIRECTORY/FILE so that it can be
187 # robustly used by the FIX code.
188
189 if (FILENAME ~ /^\//) {
190 canonicalname = FILENAME
191 } else {
192 canonicalname = PWD "/" FILENAME
193 }
194 shortname = gensub (/^.*\/([^\\]*\/[^\\]*)$/, "\\1", 1, canonicalname)
195
196 skipped[bug, shortname]++
197 if (skip[bug, shortname] >= skipped[bug, shortname]) {
198 # print FILENAME, FNR, skip[bug, FILENAME], skipped[bug, FILENAME], bug
199 # Do nothing
200 } else if (error[category[bug]]) {
201 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
202 print_bug(FILENAME, FNR, "", category[bug], bug, doc[bug], supplement)
203 } else if (warning[category[bug]]) {
204 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
205 print_bug(FILENAME, FNR, "warning: ", category[bug], bug, doc[bug], supplement)
206 }
207 }
208
209 FNR == 1 {
210 seen[FILENAME] = 1
211 if (match(FILENAME, "\\.[ly]$")) {
212 # FILENAME is a lex or yacc source
213 is_yacc_or_lex = 1
214 }
215 else {
216 is_yacc_or_lex = 0
217 }
218 }
219 END {
220 if (print_idx) {
221 idx = bug ": "
222 } else {
223 idx = ""
224 }
225 # Did we do only a partial skip?
226 for (bug_n_file in skip) {
227 split (bug_n_file, a, SUBSEP)
228 bug = a[1]
229 file = a[2]
230 if (seen[file] && (skipped[bug_n_file] < skip[bug_n_file])) {
231 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
232 b = file " missing " bug
233 print_bug(file, 0, "", "internal", file " missing " bug, "Expecting " skip[bug_n_file] " occurances of bug " bug " in file " file ", only found " skipped[bug_n_file])
234 }
235 }
236 }
237
238
239 # Skip OBSOLETE lines
240 /(^|[^_[:alnum:]])OBSOLETE([^_[:alnum:]]|$)/ { next; }
241
242 # Skip ARI lines
243
244 BEGIN {
245 ARI_OK = ""
246 }
247
248 /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
249 ARI_OK = gensub(/^.*\/\* ARI:[[:space:]]*(.*[^[:space:]])[[:space:]]*\*\/.*$/, "\\1", 1, $0)
250 # print "ARI line found \"" $0 "\""
251 # print "ARI_OK \"" ARI_OK "\""
252 }
253 ! /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
254 ARI_OK = ""
255 }
256
257
258 # Things in comments
259
260 BEGIN { doc["ARGSUSED"] = "\
261 Do not use ARGSUSED, unnecessary"
262 category["ARGSUSED"] = ari_regression
263 }
264 /(^|[^_[:alnum:]])ARGSUSED([^_[:alnum:]]|$)/ {
265 fail("ARGSUSED")
266 }
267
268
269 # SNIP - Strip out comments - SNIP
270
271 FNR == 1 {
272 comment_p = 0
273 }
274 comment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; }
275 comment_p { next; }
276 !comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); }
277 !comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; }
278
279
280 BEGIN { doc["_ markup"] = "\
281 All messages should be marked up with _."
282 category["_ markup"] = ari_gettext
283 }
284 /^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ {
285 if (! /\("%s"/) {
286 fail("_ markup")
287 }
288 }
289
290 BEGIN { doc["trailing new line"] = "\
291 A message should not have a trailing new line"
292 category["trailing new line"] = ari_gettext
293 }
294 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ {
295 fail("trailing new line")
296 }
297
298 # Include files for which GDB has a custom version.
299
300 BEGIN { doc["assert.h"] = "\
301 Do not include assert.h, instead include \"gdb_assert.h\"";
302 category["assert.h"] = ari_regression
303 fix("assert.h", "gdb/gdb_assert.h", 0) # it does not use it
304 }
305 /^#[[:space:]]*include[[:space:]]+.assert\.h./ {
306 fail("assert.h")
307 }
308
309 BEGIN { doc["dirent.h"] = "\
310 Do not include dirent.h, instead include gdb_dirent.h"
311 category["dirent.h"] = ari_regression
312 }
313 /^#[[:space:]]*include[[:space:]]*.dirent\.h./ {
314 fail("dirent.h")
315 }
316
317 BEGIN { doc["regex.h"] = "\
318 Do not include regex.h, instead include gdb_regex.h"
319 category["regex.h"] = ari_regression
320 fix("regex.h", "gdb/gdb_regex.h", 1)
321 }
322 /^#[[:space:]]*include[[:space:]]*.regex\.h./ {
323 fail("regex.h")
324 }
325
326 BEGIN { doc["xregex.h"] = "\
327 Do not include xregex.h, instead include gdb_regex.h"
328 category["xregex.h"] = ari_regression
329 fix("xregex.h", "gdb/gdb_regex.h", 1)
330 }
331 /^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
332 fail("xregex.h")
333 }
334
335 BEGIN { doc["gnu-regex.h"] = "\
336 Do not include gnu-regex.h, instead include gdb_regex.h"
337 category["gnu-regex.h"] = ari_regression
338 }
339 /^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
340 fail("gnu regex.h")
341 }
342
343 BEGIN { doc["stat.h"] = "\
344 Do not include stat.h or sys/stat.h, instead include gdb_stat.h"
345 category["stat.h"] = ari_regression
346 fix("stat.h", "common/gdb_stat.h", 1)
347 }
348 /^#[[:space:]]*include[[:space:]]*.stat\.h./ \
349 || /^#[[:space:]]*include[[:space:]]*.sys\/stat\.h./ {
350 fail("stat.h")
351 }
352
353 BEGIN { doc["wait.h"] = "\
354 Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
355 fix("wait.h", "common/gdb_wait.h", 2);
356 category["wait.h"] = ari_regression
357 }
358 /^#[[:space:]]*include[[:space:]]*.wait\.h./ \
359 || /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
360 fail("wait.h")
361 }
362
363 BEGIN { doc["vfork.h"] = "\
364 Do not include vfork.h, instead include gdb_vfork.h"
365 fix("vfork.h", "gdb/gdb_vfork.h", 1);
366 category["vfork.h"] = ari_regression
367 }
368 /^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
369 fail("vfork.h")
370 }
371
372 BEGIN { doc["error not internal-warning"] = "\
373 Do not use error(\"internal-warning\"), instead use internal_warning"
374 category["error not internal-warning"] = ari_regression
375 }
376 /error.*\"[Ii]nternal.warning/ {
377 fail("error not internal-warning")
378 }
379
380 BEGIN { doc["%p"] = "\
381 Do not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \
382 target address, or host_address_to_string() for a host address"
383 category["%p"] = ari_code
384 }
385 /%p/ && !/%prec/ {
386 fail("%p")
387 }
388
389 BEGIN { doc["%ll"] = "\
390 Do not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \
391 `long long'\'' value"
392 category["%ll"] = ari_code
393 }
394 # Allow %ll in scanf
395 /%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
396 fail("%ll")
397 }
398
399
400 # SNIP - Strip out strings - SNIP
401
402 # Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
403 FNR == 1 {
404 string_p = 0
405 trace_string = 0
406 }
407 # Strip escaped characters.
408 { gsub(/\\./, "."); }
409 # Strip quoted quotes.
410 { gsub(/'\''.'\''/, "'\''.'\''"); }
411 # End of multi-line string
412 string_p && /\"/ {
413 if (trace_string) print "EOS:" FNR, $0;
414 gsub (/^[^\"]*\"/, "'\''");
415 string_p = 0;
416 }
417 # Middle of multi-line string, discard line.
418 string_p {
419 if (trace_string) print "MOS:" FNR, $0;
420 $0 = ""
421 }
422 # Strip complete strings from the middle of the line
423 !string_p && /\"[^\"]*\"/ {
424 if (trace_string) print "COS:" FNR, $0;
425 gsub (/\"[^\"]*\"/, "'\''");
426 }
427 # Start of multi-line string
428 BEGIN { doc["multi-line string"] = "\
429 Multi-line string must have the newline escaped"
430 category["multi-line string"] = ari_regression
431 }
432 !string_p && /\"/ {
433 if (trace_string) print "SOS:" FNR, $0;
434 if (/[^\\]$/) {
435 fail("multi-line string")
436 }
437 gsub (/\"[^\"]*$/, "'\''");
438 string_p = 1;
439 }
440 # { print }
441
442 # Multi-line string
443 string_p &&
444
445 # Accumulate continuation lines
446 FNR == 1 {
447 cont_p = 0
448 }
449 !cont_p { full_line = ""; }
450 /[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; }
451 cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }
452
453
454 # GDB uses ISO C 90. Check for any non pure ISO C 90 code
455
456 BEGIN { doc["PARAMS"] = "\
457 Do not use PARAMS(), ISO C 90 implies prototypes"
458 category["PARAMS"] = ari_regression
459 }
460 /(^|[^_[:alnum:]])PARAMS([^_[:alnum:]]|$)/ {
461 fail("PARAMS")
462 }
463
464 BEGIN { doc["__func__"] = "\
465 Do not use __func__, ISO C 90 does not support this macro"
466 category["__func__"] = ari_regression
467 fix("__func__", "common/gdb_assert.h", 1)
468 }
469 /(^|[^_[:alnum:]])__func__([^_[:alnum:]]|$)/ {
470 fail("__func__")
471 }
472
473 BEGIN { doc["__FUNCTION__"] = "\
474 Do not use __FUNCTION__, ISO C 90 does not support this macro"
475 category["__FUNCTION__"] = ari_regression
476 }
477 /(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
478 fail("__FUNCTION__")
479 }
480
481 BEGIN { doc["__CYGWIN32__"] = "\
482 Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
483 autoconf tests"
484 category["__CYGWIN32__"] = ari_regression
485 }
486 /(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
487 fail("__CYGWIN32__")
488 }
489
490 BEGIN { doc["PTR"] = "\
491 Do not use PTR, ISO C 90 implies `void *'\''"
492 category["PTR"] = ari_regression
493 #fix("PTR", "gdb/utils.c", 6)
494 }
495 /(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
496 fail("PTR")
497 }
498
499 BEGIN { doc["UCASE function"] = "\
500 Function name is uppercase."
501 category["UCASE function"] = ari_code
502 possible_UCASE = 0
503 UCASE_full_line = ""
504 }
505 (possible_UCASE) {
506 if (ARI_OK == "UCASE function") {
507 possible_UCASE = 0
508 }
509 # Closing brace found?
510 else if (UCASE_full_line ~ \
511 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) {
512 if ((UCASE_full_line ~ \
513 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
514 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
515 store_FNR = FNR
516 FNR = possible_FNR
517 store_0 = $0;
518 $0 = UCASE_full_line;
519 fail("UCASE function")
520 FNR = store_FNR
521 $0 = store_0;
522 }
523 possible_UCASE = 0
524 UCASE_full_line = ""
525 } else {
526 UCASE_full_line = UCASE_full_line $0;
527 }
528 }
529 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
530 possible_UCASE = 1
531 if (ARI_OK == "UCASE function") {
532 possible_UCASE = 0
533 }
534 possible_FNR = FNR
535 UCASE_full_line = $0
536 }
537
538
539 BEGIN { doc["editCase function"] = "\
540 Function name starts lower case but has uppercased letters."
541 category["editCase function"] = ari_code
542 possible_editCase = 0
543 editCase_full_line = ""
544 }
545 (possible_editCase) {
546 if (ARI_OK == "ediCase function") {
547 possible_editCase = 0
548 }
549 # Closing brace found?
550 else if (editCase_full_line ~ \
551 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) {
552 if ((editCase_full_line ~ \
553 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
554 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
555 store_FNR = FNR
556 FNR = possible_FNR
557 store_0 = $0;
558 $0 = editCase_full_line;
559 fail("editCase function")
560 FNR = store_FNR
561 $0 = store_0;
562 }
563 possible_editCase = 0
564 editCase_full_line = ""
565 } else {
566 editCase_full_line = editCase_full_line $0;
567 }
568 }
569 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
570 possible_editCase = 1
571 if (ARI_OK == "editCase function") {
572 possible_editCase = 0
573 }
574 possible_FNR = FNR
575 editCase_full_line = $0
576 }
577
578 # Only function implementation should be on first column
579 BEGIN { doc["function call in first column"] = "\
580 Function name in first column should be restricted to function implementation"
581 category["function call in first column"] = ari_code
582 }
583 /^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
584 fail("function call in first column")
585 }
586
587
588 # Functions without any parameter should have (void)
589 # after their name not simply ().
590 BEGIN { doc["no parameter function"] = "\
591 Function having no parameter should be declared with funcname (void)."
592 category["no parameter function"] = ari_code
593 }
594 /^[a-zA-Z][a-z0-9A-Z_]*[[:space:]]*\(\)/ {
595 fail("no parameter function")
596 }
597
598 BEGIN { doc["hash"] = "\
599 Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
600 parse a C preprocessor directive when `#'\'' is the first character on \
601 the line)"
602 category["hash"] = ari_regression
603 }
604 /^[[:space:]]+#/ {
605 fail("hash")
606 }
607
608 BEGIN { doc["OP eol"] = "\
609 Do not use &&, or || at the end of a line"
610 category["OP eol"] = ari_code
611 }
612 # * operator needs a special treatment as it can be a
613 # valid end of line for a pointer type definition
614 # Only catch case where an assignment or an opening brace is present
615 /(\|\||\&\&|==|!=|[[:space:]][+\-\/])[[:space:]]*$/ \
616 || /(\(|=)[[:space:]].*[[:space:]]\*[[:space:]]*$/ {
617 fail("OP eol")
618 }
619
620 BEGIN { doc["strerror"] = "\
621 Do not use strerror(), instead use safe_strerror()"
622 category["strerror"] = ari_regression
623 fix("strerror", "gdb/gdb_string.h", 1)
624 fix("strerror", "gdb/mingw-hdep.c", 1)
625 fix("strerror", "gdb/posix-hdep.c", 1)
626 }
627 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
628 fail("strerror")
629 }
630
631 BEGIN { doc["long long"] = "\
632 Do not use `long long'\'', instead use LONGEST"
633 category["long long"] = ari_code
634 # defs.h needs two such patterns for LONGEST and ULONGEST definitions
635 fix("long long", "gdb/defs.h", 2)
636 }
637 /(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
638 fail("long long")
639 }
640
641 BEGIN { doc["ATTRIBUTE_UNUSED"] = "\
642 Do not use ATTRIBUTE_UNUSED, do not bother (GDB is compiled with -Werror and, \
643 consequently, is not able to tolerate false warnings. Since -Wunused-param \
644 produces such warnings, neither that warning flag nor ATTRIBUTE_UNUSED \
645 are used by GDB"
646 category["ATTRIBUTE_UNUSED"] = ari_regression
647 }
648 /(^|[^_[:alnum:]])ATTRIBUTE_UNUSED([^_[:alnum:]]|$)/ {
649 fail("ATTRIBUTE_UNUSED")
650 }
651
652 BEGIN { doc["ATTR_FORMAT"] = "\
653 Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
654 category["ATTR_FORMAT"] = ari_regression
655 }
656 /(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
657 fail("ATTR_FORMAT")
658 }
659
660 BEGIN { doc["ATTR_NORETURN"] = "\
661 Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
662 category["ATTR_NORETURN"] = ari_regression
663 }
664 /(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
665 fail("ATTR_NORETURN")
666 }
667
668 BEGIN { doc["NORETURN"] = "\
669 Do not use NORETURN, use ATTRIBUTE_NORETURN instead"
670 category["NORETURN"] = ari_regression
671 }
672 /(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
673 fail("NORETURN")
674 }
675
676
677 # General problems
678
679 BEGIN { doc["multiple messages"] = "\
680 Do not use multiple calls to warning or error, instead use a single call"
681 category["multiple messages"] = ari_gettext
682 }
683 FNR == 1 {
684 warning_fnr = -1
685 }
686 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ {
687 if (FNR == warning_fnr + 1) {
688 fail("multiple messages")
689 } else {
690 warning_fnr = FNR
691 }
692 }
693
694 # Commented out, but left inside sources, just in case.
695 # BEGIN { doc["inline"] = "\
696 # Do not use the inline attribute; \
697 # since the compiler generally ignores this, better algorithm selection \
698 # is needed to improved performance"
699 # category["inline"] = ari_code
700 # }
701 # /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
702 # fail("inline")
703 # }
704
705 # This test is obsolete as this type
706 # has been deprecated and finally suppressed from GDB sources
707 #BEGIN { doc["obj_private"] = "\
708 #Replace obj_private with objfile_data"
709 # category["obj_private"] = ari_obsolete
710 #}
711 #/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
712 # fail("obj_private")
713 #}
714
715 BEGIN { doc["abort"] = "\
716 Do not use abort, instead use internal_error; GDB should never abort"
717 category["abort"] = ari_regression
718 fix("abort", "gdb/utils.c", 3)
719 }
720 /(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
721 fail("abort")
722 }
723
724 BEGIN { doc["basename"] = "\
725 Do not use basename, instead use lbasename"
726 category["basename"] = ari_regression
727 }
728 /(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
729 fail("basename")
730 }
731
732 BEGIN { doc["assert"] = "\
733 Do not use assert, instead use gdb_assert or internal_error; assert \
734 calls abort and GDB should never call abort"
735 category["assert"] = ari_regression
736 }
737 /(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
738 fail("assert")
739 }
740
741 BEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\
742 Replace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed"
743 category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression
744 }
745 /(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
746 fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
747 }
748
749 BEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\
750 Replace ADD_SHARED_SYMBOL_FILES with nothing, not needed?"
751 category["ADD_SHARED_SYMBOL_FILES"] = ari_regression
752 }
753 /(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
754 fail("ADD_SHARED_SYMBOL_FILES")
755 }
756
757 BEGIN { doc["SOLIB_ADD"] = "\
758 Replace SOLIB_ADD with nothing, not needed?"
759 category["SOLIB_ADD"] = ari_deprecate
760 }
761 /(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
762 fail("SOLIB_ADD")
763 }
764
765 BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
766 Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
767 category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_deprecate
768 }
769 /(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
770 fail("SOLIB_CREATE_INFERIOR_HOOK")
771 }
772
773 BEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\
774 Replace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?"
775 category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression
776 }
777 /(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
778 fail("SOLIB_LOADED_LIBRARY_PATHNAME")
779 }
780
781 BEGIN { doc["REGISTER_U_ADDR"] = "\
782 Replace REGISTER_U_ADDR with nothing, not needed?"
783 category["REGISTER_U_ADDR"] = ari_regression
784 }
785 /(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
786 fail("REGISTER_U_ADDR")
787 }
788
789 BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
790 Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
791 category["PROCESS_LINENUMBER_HOOK"] = ari_regression
792 }
793 /(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
794 fail("PROCESS_LINENUMBER_HOOK")
795 }
796
797 BEGIN { doc["PC_SOLIB"] = "\
798 Replace PC_SOLIB with nothing, not needed?"
799 category["PC_SOLIB"] = ari_deprecate
800 }
801 /(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
802 fail("PC_SOLIB")
803 }
804
805 BEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\
806 Replace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?"
807 category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression
808 }
809 /(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
810 fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
811 }
812
813 BEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\
814 Replace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?"
815 category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate
816 }
817 /(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
818 fail("GCC_COMPILED_FLAG_SYMBOL")
819 }
820
821 BEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\
822 Replace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?"
823 category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate
824 }
825 /(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
826 fail("GCC2_COMPILED_FLAG_SYMBOL")
827 }
828
829 BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
830 Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
831 category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
832 }
833 /(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
834 fail("FUNCTION_EPILOGUE_SIZE")
835 }
836
837 BEGIN { doc["HAVE_VFORK"] = "\
838 Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
839 unconditionally"
840 category["HAVE_VFORK"] = ari_regression
841 }
842 /(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
843 fail("HAVE_VFORK")
844 }
845
846 BEGIN { doc["bcmp"] = "\
847 Do not use bcmp(), ISO C 90 implies memcmp()"
848 category["bcmp"] = ari_regression
849 }
850 /(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
851 fail("bcmp")
852 }
853
854 BEGIN { doc["setlinebuf"] = "\
855 Do not use setlinebuf(), ISO C 90 implies setvbuf()"
856 category["setlinebuf"] = ari_regression
857 }
858 /(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
859 fail("setlinebuf")
860 }
861
862 BEGIN { doc["bcopy"] = "\
863 Do not use bcopy(), ISO C 90 implies memcpy() and memmove()"
864 category["bcopy"] = ari_regression
865 }
866 /(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
867 fail("bcopy")
868 }
869
870 BEGIN { doc["get_frame_base"] = "\
871 Replace get_frame_base with get_frame_id, get_frame_base_address, \
872 get_frame_locals_address, or get_frame_args_address."
873 category["get_frame_base"] = ari_obsolete
874 }
875 /(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
876 fail("get_frame_base")
877 }
878
879 BEGIN { doc["floatformat_to_double"] = "\
880 Do not use floatformat_to_double() from libierty, \
881 instead use floatformat_to_doublest()"
882 fix("floatformat_to_double", "gdb/doublest.c", 1)
883 category["floatformat_to_double"] = ari_regression
884 }
885 /(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
886 fail("floatformat_to_double")
887 }
888
889 BEGIN { doc["floatformat_from_double"] = "\
890 Do not use floatformat_from_double() from libierty, \
891 instead use floatformat_from_doublest()"
892 category["floatformat_from_double"] = ari_regression
893 }
894 /(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
895 fail("floatformat_from_double")
896 }
897
898 BEGIN { doc["BIG_ENDIAN"] = "\
899 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
900 category["BIG_ENDIAN"] = ari_regression
901 }
902 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
903 fail("BIG_ENDIAN")
904 }
905
906 BEGIN { doc["LITTLE_ENDIAN"] = "\
907 Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
908 category["LITTLE_ENDIAN"] = ari_regression
909 }
910 /(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
911 fail("LITTLE_ENDIAN")
912 }
913
914 BEGIN { doc["BIG_ENDIAN"] = "\
915 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
916 category["BIG_ENDIAN"] = ari_regression
917 }
918 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
919 fail("BIG_ENDIAN")
920 }
921
922 BEGIN { doc["sec_ptr"] = "\
923 Instead of sec_ptr, use struct bfd_section";
924 category["sec_ptr"] = ari_regression
925 }
926 /(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
927 fail("sec_ptr")
928 }
929
930 BEGIN { doc["frame_unwind_unsigned_register"] = "\
931 Replace frame_unwind_unsigned_register with frame_unwind_register_unsigned"
932 category["frame_unwind_unsigned_register"] = ari_regression
933 }
934 /(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
935 fail("frame_unwind_unsigned_register")
936 }
937
938 BEGIN { doc["frame_register_read"] = "\
939 Replace frame_register_read() with get_frame_register(), or \
940 possibly introduce a new method safe_get_frame_register()"
941 category["frame_register_read"] = ari_obsolete
942 }
943 /(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
944 fail("frame_register_read")
945 }
946
947 BEGIN { doc["read_register"] = "\
948 Replace read_register() with regcache_read() et.al."
949 category["read_register"] = ari_regression
950 }
951 /(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
952 fail("read_register")
953 }
954
955 BEGIN { doc["write_register"] = "\
956 Replace write_register() with regcache_read() et.al."
957 category["write_register"] = ari_regression
958 }
959 /(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
960 fail("write_register")
961 }
962
963 function report(name) {
964 # Drop any trailing _P.
965 name = gensub(/(_P|_p)$/, "", 1, name)
966 # Convert to lower case
967 name = tolower(name)
968 # Split into category and bug
969 cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
970 bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
971 # Report it
972 name = cat " " bug
973 doc[name] = "Do not use " cat " " bug ", see declaration for details"
974 category[name] = cat
975 fail(name)
976 }
977
978 /(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
979 line = $0
980 # print "0 =", $0
981 while (1) {
982 name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line)
983 line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line)
984 # print "name =", name, "line =", line
985 if (name == line) break;
986 report(name)
987 }
988 }
989
990 # Count the number of times each architecture method is set
991 /(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ {
992 name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0)
993 doc["set " name] = "\
994 Call to set_gdbarch_" name
995 category["set " name] = ari_gdbarch
996 fail("set " name)
997 }
998
999 # Count the number of times each tm/xm/nm macro is defined or undefined
1000 /^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \
1001 && !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \
1002 && FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ {
1003 basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME)
1004 type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename)
1005 name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0)
1006 if (type == basename) {
1007 type = "macro"
1008 }
1009 doc[type " " name] = "\
1010 Do not define macros such as " name " in a tm, nm or xm file, \
1011 in fact do not provide a tm, nm or xm file"
1012 category[type " " name] = ari_macro
1013 fail(type " " name)
1014 }
1015
1016 BEGIN { doc["deprecated_registers"] = "\
1017 Replace deprecated_registers with nothing, they have reached \
1018 end-of-life"
1019 category["deprecated_registers"] = ari_eol
1020 }
1021 /(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
1022 fail("deprecated_registers")
1023 }
1024
1025 BEGIN { doc["read_pc"] = "\
1026 Replace READ_PC() with frame_pc_unwind; \
1027 at present the inferior function call code still uses this"
1028 category["read_pc"] = ari_deprecate
1029 }
1030 /(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
1031 /(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
1032 /(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
1033 fail("read_pc")
1034 }
1035
1036 BEGIN { doc["write_pc"] = "\
1037 Replace write_pc() with get_frame_base_address or get_frame_id; \
1038 at present the inferior function call code still uses this when doing \
1039 a DECR_PC_AFTER_BREAK"
1040 category["write_pc"] = ari_deprecate
1041 }
1042 /(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
1043 /(^|[^_[:alnum:]])set_gdbarch_write_pc[[:space:]]*\(/ || \
1044 /(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
1045 fail("write_pc")
1046 }
1047
1048 BEGIN { doc["generic_target_write_pc"] = "\
1049 Replace generic_target_write_pc with a per-architecture implementation, \
1050 this relies on PC_REGNUM which is being eliminated"
1051 category["generic_target_write_pc"] = ari_regression
1052 }
1053 /(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
1054 fail("generic_target_write_pc")
1055 }
1056
1057 BEGIN { doc["read_sp"] = "\
1058 Replace read_sp() with frame_sp_unwind"
1059 category["read_sp"] = ari_regression
1060 }
1061 /(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
1062 /(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
1063 /(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
1064 fail("read_sp")
1065 }
1066
1067 BEGIN { doc["register_cached"] = "\
1068 Replace register_cached() with nothing, does not have a regcache parameter"
1069 category["register_cached"] = ari_regression
1070 }
1071 /(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
1072 fail("register_cached")
1073 }
1074
1075 BEGIN { doc["set_register_cached"] = "\
1076 Replace set_register_cached() with nothing, does not have a regcache parameter"
1077 category["set_register_cached"] = ari_regression
1078 }
1079 /(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
1080 fail("set_register_cached")
1081 }
1082
1083 # Print functions: Use versions that either check for buffer overflow
1084 # or safely allocate a fresh buffer.
1085
1086 BEGIN { doc["sprintf"] = "\
1087 Do not use sprintf, instead use xsnprintf or xstrprintf"
1088 category["sprintf"] = ari_code
1089 }
1090 /(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
1091 fail("sprintf")
1092 }
1093
1094 BEGIN { doc["vsprintf"] = "\
1095 Do not use vsprintf(), instead use xstrvprintf"
1096 category["vsprintf"] = ari_regression
1097 }
1098 /(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
1099 fail("vsprintf")
1100 }
1101
1102 BEGIN { doc["asprintf"] = "\
1103 Do not use asprintf(), instead use xstrprintf()"
1104 category["asprintf"] = ari_regression
1105 }
1106 /(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
1107 fail("asprintf")
1108 }
1109
1110 BEGIN { doc["vasprintf"] = "\
1111 Do not use vasprintf(), instead use xstrvprintf"
1112 fix("vasprintf", "common/common-utils.c", 1)
1113 category["vasprintf"] = ari_regression
1114 }
1115 /(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
1116 fail("vasprintf")
1117 }
1118
1119 # More generic memory operations
1120
1121 BEGIN { doc["bzero"] = "\
1122 Do not use bzero(), instead use memset()"
1123 category["bzero"] = ari_regression
1124 }
1125 /(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
1126 fail("bzero")
1127 }
1128
1129 BEGIN { doc["strdup"] = "\
1130 Do not use strdup(), instead use xstrdup()";
1131 category["strdup"] = ari_regression
1132 }
1133 /(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
1134 fail("strdup")
1135 }
1136
1137 BEGIN { doc["strsave"] = "\
1138 Do not use strsave(), instead use xstrdup() et.al."
1139 category["strsave"] = ari_regression
1140 }
1141 /(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
1142 fail("strsave")
1143 }
1144
1145 # String compare functions
1146
1147 BEGIN { doc["strnicmp"] = "\
1148 Do not use strnicmp(), instead use strncasecmp()"
1149 category["strnicmp"] = ari_regression
1150 }
1151 /(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
1152 fail("strnicmp")
1153 }
1154
1155 # Boolean expressions and conditionals
1156
1157 BEGIN { doc["boolean"] = "\
1158 Do not use `boolean'\'', use `int'\'' instead"
1159 category["boolean"] = ari_regression
1160 }
1161 /(^|[^_[:alnum:]])boolean([^_[:alnum:]]|$)/ {
1162 if (is_yacc_or_lex == 0) {
1163 fail("boolean")
1164 }
1165 }
1166
1167 BEGIN { doc["false"] = "\
1168 Definitely do not use `false'\'' in boolean expressions"
1169 category["false"] = ari_regression
1170 }
1171 /(^|[^_[:alnum:]])false([^_[:alnum:]]|$)/ {
1172 if (is_yacc_or_lex == 0) {
1173 fail("false")
1174 }
1175 }
1176
1177 BEGIN { doc["true"] = "\
1178 Do not try to use `true'\'' in boolean expressions"
1179 category["true"] = ari_regression
1180 }
1181 /(^|[^_[:alnum:]])true([^_[:alnum:]]|$)/ {
1182 if (is_yacc_or_lex == 0) {
1183 fail("true")
1184 }
1185 }
1186
1187 # Typedefs that are either redundant or can be reduced to `struct
1188 # type *''.
1189 # Must be placed before if assignment otherwise ARI exceptions
1190 # are not handled correctly.
1191
1192 BEGIN { doc["d_namelen"] = "\
1193 Do not use dirent.d_namelen, instead use NAMELEN"
1194 category["d_namelen"] = ari_regression
1195 }
1196 /(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
1197 fail("d_namelen")
1198 }
1199
1200 BEGIN { doc["strlen d_name"] = "\
1201 Do not use strlen dirent.d_name, instead use NAMELEN"
1202 category["strlen d_name"] = ari_regression
1203 }
1204 /(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
1205 fail("strlen d_name")
1206 }
1207
1208 BEGIN { doc["var_boolean"] = "\
1209 Replace var_boolean with add_setshow_boolean_cmd"
1210 category["var_boolean"] = ari_regression
1211 fix("var_boolean", "gdb/command.h", 1)
1212 # fix only uses the last directory level
1213 fix("var_boolean", "cli/cli-decode.c", 2)
1214 }
1215 /(^|[^_[:alnum:]])var_boolean([^_[:alnum:]]|$)/ {
1216 if (($0 !~ /(^|[^_[:alnum:]])case *var_boolean:/) \
1217 && ($0 !~ /(^|[^_[:alnum:]])[=!]= *var_boolean/)) {
1218 fail("var_boolean")
1219 }
1220 }
1221
1222 BEGIN { doc["generic_use_struct_convention"] = "\
1223 Replace generic_use_struct_convention with nothing, \
1224 EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
1225 category["generic_use_struct_convention"] = ari_regression
1226 }
1227 /(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
1228 fail("generic_use_struct_convention")
1229 }
1230
1231 BEGIN { doc["if assignment"] = "\
1232 An IF statement'\''s expression contains an assignment (the GNU coding \
1233 standard discourages this)"
1234 category["if assignment"] = ari_code
1235 }
1236 BEGIN { doc["if clause more than 50 lines"] = "\
1237 An IF statement'\''s expression expands over 50 lines"
1238 category["if clause more than 50 lines"] = ari_code
1239 }
1240 #
1241 # Accumulate continuation lines
1242 FNR == 1 {
1243 in_if = 0
1244 }
1245
1246 /(^|[^_[:alnum:]])if / {
1247 in_if = 1;
1248 if_brace_level = 0;
1249 if_cont_p = 0;
1250 if_count = 0;
1251 if_brace_end_pos = 0;
1252 if_full_line = "";
1253 }
1254 (in_if) {
1255 # We want everything up to closing brace of same level
1256 if_count++;
1257 if (if_count > 50) {
1258 print "multiline if: " if_full_line $0
1259 fail("if clause more than 50 lines")
1260 if_brace_level = 0;
1261 if_full_line = "";
1262 } else {
1263 if (if_count == 1) {
1264 i = index($0,"if ");
1265 } else {
1266 i = 1;
1267 }
1268 for (i=i; i <= length($0); i++) {
1269 char = substr($0,i,1);
1270 if (char == "(") { if_brace_level++; }
1271 if (char == ")") {
1272 if_brace_level--;
1273 if (!if_brace_level) {
1274 if_brace_end_pos = i;
1275 after_if = substr($0,i+1,length($0));
1276 # Do not parse what is following
1277 break;
1278 }
1279 }
1280 }
1281 if (if_brace_level == 0) {
1282 $0 = substr($0,1,i);
1283 in_if = 0;
1284 } else {
1285 if_full_line = if_full_line $0;
1286 if_cont_p = 1;
1287 next;
1288 }
1289 }
1290 }
1291 # if we arrive here, we need to concatenate, but we are at brace level 0
1292
1293 (if_brace_end_pos) {
1294 $0 = if_full_line substr($0,1,if_brace_end_pos);
1295 if (if_count > 1) {
1296 # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
1297 }
1298 if_cont_p = 0;
1299 if_full_line = "";
1300 }
1301 /(^|[^_[:alnum:]])if .* = / {
1302 # print "fail in if " $0
1303 fail("if assignment")
1304 }
1305 (if_brace_end_pos) {
1306 $0 = $0 after_if;
1307 if_brace_end_pos = 0;
1308 in_if = 0;
1309 }
1310
1311 # Printout of all found bug
1312
1313 BEGIN {
1314 if (print_doc) {
1315 for (bug in doc) {
1316 fail(bug)
1317 }
1318 exit
1319 }
1320 }' "$@"
1321
This page took 0.083259 seconds and 5 git commands to generate.