#This script is designed to run with Understand - CodeCheck use base ("Understand::Codecheck"); use strict; use constant ERR1 => '#include directive must be followed by or "filename" sequence'; sub register_tr_text() { my $check = shift; $check->add_tr_text(ERR1); } sub name { return "16-2-6 The #include directive shall be followed by either a or \"filename\" sequence";} sub description { return "16-2-6 (Required) The #include directive shall be followed by either a or \"filename\" sequence";} sub detailed_description { return <<"END_DESC"

Rationale
These are the only forms for the #include directive permitted by ISO/IEC 14882:2003 [1].

Example
For example, the following are allowed.
#include "filename.h" // Compliant
#include  // Compliant
#define HEADER "filename.h" // Non-compliant with Rule 16𣇼
#include HEADER // Compliant
#include another.h // Non-compliant
END_DESC } sub test_language { my $language = shift; return $language =~ /C\+\+/; #Handles C and C++ } sub test_entity { return 1;} sub test_global { return 0;} sub define_options{} sub check { my $check = shift; my $file = shift; return unless $file->kind->check("file ~unknown ~unresolved"); return unless $file->filerefs("include","file"); my $lexer = $file->lexer(1,8,1,1); return unless $lexer; foreach my $lexeme($lexer->lexemes()){ if($lexeme->token eq "Preprocessor" && $lexeme->text eq "include"){ do { $lexeme = $lexeme->next }while($lexeme && $lexeme->token eq "Whitespace"); my $string = $lexeme->ent->type if($lexeme->ent && $lexeme->ent->kind->check("macro")); $string = $lexeme->text if !$string && $lexeme->token eq "String"; if(!$string || $string !~ /^".+"$|^<.+>$/){ $check->violation($lexeme->ent,$file,$lexeme->line_begin,$lexeme->column_begin,ERR1); } } } }