#This script is designed to run with Understand - CodeCheck use base qw(Understand::Codecheck); use strict; use Codecheck::Libraries::InfoSiftr qw(getFunctionParams); use constant ERR1 => 'Violation: function prototype for "%1" missing identifiers for the following arguments: %2'; sub register_tr_text { my $check = shift; $check->add_tr_text(ERR1); } sub name { '16.3 All prototype parameters must have an identifier.' } sub description { '16.3 (Required) Identifiers shall be given for all of the parameters in a function prototype declaration.' } sub detailed_description { <<'END_DESC' Names shall be given for all the parameters in the function declaration for reasons of compatibility, clarity and maintainability. END_DESC } sub test_language { my $language = shift; return $language eq 'C++'; } sub test_entity { 1 } sub test_global { 0 } sub define_options { } sub check { my $check = shift; my $file = shift; return unless $file->kind->check('file'); my $lexer = $file->lexer(0); return unless $lexer; foreach my $ref ($file->filerefs('declare', 'function', 0)) { my @params = getFunctionParams($ref, $lexer, 0); my @rawParams = getFunctionParams($ref, $lexer, 1); my @badParams; for (my $i = 0; $i < @params; ++$i) { my $param = $params[$i]; my $rawParam = $rawParams[$i]; my @tokens = grep { # filter out '...' and 'void' $_->{token} ne 'Punctuation' && $_->{text} ne 'void' } @$rawParam; next unless @tokens; @tokens = grep { $_->{token} eq 'Identifier' } @tokens; if (@tokens && $check->db->lookup($tokens[0]->{text}, 'typedef, enum, struct, class, union', 1)) { my $trash = shift @tokens; # weed out named types, like typedefs, enums, structs, classes } unless (@tokens) { push @badParams, $param; } } if (@badParams) { $check->violation($ref->ent, $ref->file, $ref->line, $ref->column, ERR1, $ref->ent->longname, join ', ', @badParams); } } return; }