#This script is designed to run with Understand - CodeCheck #Rule 2.2 The character sequence // shall not be used. use base qw(Understand::Codecheck); use strict; use constant ERR1 => 'Violation: C99 style comment found: %1'; sub register_tr_text { my $check = shift; $check->add_tr_text(ERR1); } sub name { '2.2 only use /* comments' } sub description { '2.2 (Required) Source code shall only use /* ... */ style comments.' } sub detailed_description { <<'END_DESC' This excludes the use of // C99 style comments and C++ style comments, since these are not permitted in C90. Many compilers support the // style of comments as an extension to C90. The use of // in preprocessor directives (e.g. #define) can vary. Also the mixing of /* ... */ and // is not consistent. This is more than a style issue, since different (pre C99) compilers may behave differently. 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); my @lexemes = $lexer->lexemes if $lexer; foreach my $lexeme (@lexemes){ if ($lexeme->token eq 'Comment' && $lexeme->text =~ m! ^ // !sx) { $check->violation(0, $file, $lexeme->line_begin, $lexeme->column_begin, ERR1, $lexeme->text); } } return; }