#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 "19.3 The #include directive shall be followed by either a or \"filename\" sequence";} sub description { return "19.3 (Required) The #include directive shall be followed by either a or \"filename\" sequence";} sub detailed_description { return <<"END_DESC" For example, the following are allowed. #include "filename.h" #include #define FILE_A "filename.h" #include FILE_A 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); } } } }