aboutsummaryrefslogtreecommitdiffstats
path: root/tools/checkAPIs.pl
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss.ws@gmail.com>2012-11-29 20:25:15 +0000
committerJeff Morriss <jeff.morriss.ws@gmail.com>2012-11-29 20:25:15 +0000
commit5ee917aea7940ac8b2f7d205db26fd808793138b (patch)
tree0e60b7137f7048ee356fc458404db6ce6c50d5bc /tools/checkAPIs.pl
parent04c9d29799875232d0fa3e34919c25bb46d6d4b7 (diff)
As requested by Anders on -dev: check enum_val_t's for NULL termination.
Also check that they are all const. svn path=/trunk/; revision=46294
Diffstat (limited to 'tools/checkAPIs.pl')
-rwxr-xr-xtools/checkAPIs.pl34
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl
index d6b8061f52..5e93f44dc2 100755
--- a/tools/checkAPIs.pl
+++ b/tools/checkAPIs.pl
@@ -1686,6 +1686,7 @@ my $StaticRegex = qr/ static \s+
my $ConstRegex = qr/ const \s+ /xs;
my $Static_andor_ConstRegex = qr/ (?: $StaticRegex $ConstRegex | $StaticRegex | $ConstRegex) /xs;
my $ValueStringRegex = qr/ $Static_andor_ConstRegex (?:value|string|range)_string \ + [^;*]+ = [^;]+ [{] [^;]+ ; /xs;
+my $EnumValRegex = qr/ $Static_andor_ConstRegex enum_val_t \ + [^;*]+ = [^;]+ [{] [^;]+ ; /xs;
#
# MAIN
@@ -1836,6 +1837,39 @@ while ($_ = $ARGV[0])
}
}
+ # Brute force check for enum_val_t arrays which are missing {NULL, NULL, ...}
+ # as the final (terminating) array entry
+ # For now use the same option to turn this and value_string checking on and off.
+ # (Is the option even necessary?)
+ if ($check_value_string_array_null_termination) {
+ # Assumption: definition is of form (pseudo-Regex):
+ # " (static const|static|const) enum_val_t .+ = { .+ ;"
+ # (possibly over multiple lines)
+ while ($fileContents =~ / ( $EnumValRegex ) /xsog) {
+ # enum_val_t array definition found; check if NULL terminated
+ my $vs = my $vsx = $1;
+ if ($debug_flag) {
+ $vsx =~ / ( .+ enum_val_t [^=]+ ) = /xo;
+ printf STDERR "==> %-35.35s: %s\n", $filename, $1;
+ printf STDERR "%s\n", $vs;
+ }
+ $vs =~ s{ \s } {}xg;
+ # README.developer says
+ # "Don't put a comma after the last tuple of an initializer of an array"
+ # However: since this usage is present in some number of cases, we'll allow for now
+ if ($vs !~ / NULL, NULL, -?[0-9] [}] ,? [}] ; $/xo) {
+ $vsx =~ /( enum_val_t [^=]+ ) = /xo;
+ printf STDERR "Error: %-35.35s: {NULL, NULL, ...} is required as the last enum_val_t array entry: %s\n", $filename, $1;
+ $errorCount++;
+ }
+ if ($vs !~ / (static)? const enum_val_t /xo) {
+ $vsx =~ /( enum_val_t [^=]+ ) = /xo;
+ printf STDERR "Error: %-35.35s: Missing 'const': %s\n", $filename, $1;
+ $errorCount++;
+ }
+ }
+ }
+
# Check and count APIs
for my $apiGroup (@apiGroups) {
my $pfx = "Warning";