#This script is designed to run with Understand - CodeCheck
#Robert Gempeler - July 18, 2010
use base ("Understand::Codecheck");
use strict;
use constant ERR1 => 'File contains "goto" statement.';
sub register_tr_text() {
my $check = shift;
$check->add_tr_text(ERR1);
}
sub name { return "Goto Statements";}
sub description { return "The \"goto\" statement shall not be used.";}
sub detailed_description { return <<"END_DESC"
Rationale
The "goto" statement is considered very dangerous in many aspects and should almost never be used.
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");
return unless $file->contents =~ /goto/i;
return unless my $lexer = $file->lexer();
#check if lexeme text == "goto"; report error if match is found.
foreach my $lexeme ($lexer->lexemes()) {
if ($lexeme->text() eq "goto" && $lexeme->token() eq "Keyword"){
$check->violation($lexeme->ent(),$file,$lexeme->line_begin(),$lexeme->column_begin(),ERR1);
}
}
}