NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
|
This class analyzes the code handled by the editor by accessing it with friends rights. More...
#include <codeanalyzer.hpp>
Public Member Functions | |
CodeAnalyzer (NumeReEditor *parent, Options *opts) | |
void | run () |
Starts the code analysis. Requires a pointer to the editor and to the options. More... | |
Static Public Member Functions | |
static char | getVariableType (const std::string &sVarName) |
Returns the leading character, which indicates the type of this variable or a null character, if either the leading character is not known or if it does not fulfill the requirements. More... | |
static void | changeVariableType (std::string &sVarName, char type) |
Change the variable's type to the passed type. More... | |
Private Member Functions | |
AnnotationCount | analyseCommands () |
Analyses commands in the code. More... | |
AnnotationCount | analyseFunctions (bool isContinuedLine) |
Analyses calls to standard functions. More... | |
AnnotationCount | analyseProcedures () |
Analyses calls to procedures. More... | |
AnnotationCount | analyseIdentifiers () |
Analyses occurences of identifiers. More... | |
AnnotationCount | analyseOperators () |
Analyses occurences of operators. More... | |
AnnotationCount | analyseNumbers () |
Analyses occurences of numerical literals. More... | |
AnnotationCount | analysePreDefs () |
Analyses occurences of special predefined variables. More... | |
AnnotationCount | addToAnnotation (const std::string &sMessage, int nStyle) |
Adds the passed sMessage with the style to the internal cache. More... | |
std::string | highlightFoundOccurence (const std::string &sElement, int nPos, int nLength) |
Highlights the occurence in the editor. More... | |
bool | containsAssignment (const std::string &sCurrentLine) |
Checks for assignments. More... | |
int | calculateCyclomaticComplexity (int startline, int endline) |
Calculates the cyclomatic complexity between both lines. More... | |
int | calculateLinesOfCode (int startline, int endline) |
Calculates the lines of code between both lines. More... | |
int | countNumberOfComments (int startline, int endline) |
Counts the number of comment lines between both lines. More... | |
Private Attributes | |
NumeReEditor * | m_editor |
Options * | m_options |
SymDefManager | m_symdefs |
std::vector< std::string > | m_MATOP_FUNCS |
std::vector< std::string > | m_DRAW_FUNCS |
std::vector< std::string > | m_STRING_FUNCS |
std::vector< std::string > | m_STRING_METHODS |
std::string | m_sNote |
std::string | m_sWarn |
std::string | m_sError |
std::string | m_sCurrentLine |
std::string | m_sStyles |
std::string | m_currentMode |
int | m_nCurPos |
int | m_nCurrentLine |
bool | m_hasProcedureDefinition |
std::vector< std::pair< std::string, int > > | m_vLocalVariables |
const double | MINCOMMENTDENSITY = 0.5 |
const double | MAXCOMMENTDENSITY = 1.5 |
const int | MAXCOMPLEXITYNOTIFY = 15 |
const int | MAXCOMPLEXITYWARN = 20 |
const int | MAXLINESOFCODE = 100 |
This class analyzes the code handled by the editor by accessing it with friends rights.
Definition at line 58 of file codeanalyzer.hpp.
CodeAnalyzer::CodeAnalyzer | ( | NumeReEditor * | parent, |
Options * | opts | ||
) |
Constructor
parent | NumeReEditor* |
opts | Options* |
Definition at line 46 of file codeanalyzer.cpp.
References _guilang, Language::get(), Language::getList(), m_DRAW_FUNCS, m_MATOP_FUNCS, m_sError, m_sNote, m_STRING_FUNCS, m_STRING_METHODS, m_sWarn, and replaceDocStrings().
|
private |
Adds the passed sMessage with the style to the internal cache.
sMessage | const string& |
nStyle | int |
Definition at line 1662 of file codeanalyzer.cpp.
References ANNOTATION_ERROR, ANNOTATION_NOTE, ANNOTATION_WARN, NumeReEditor::countUmlauts(), Options::GetAnalyzerOption(), m_editor, m_options, m_sCurrentLine, m_sStyles, AnnotationCount::nErrors, AnnotationCount::nNotes, AnnotationCount::nWarnings, Options::USE_ERRORS, Options::USE_NOTES, and Options::USE_WARNINGS.
Referenced by analyseCommands(), analyseFunctions(), analyseIdentifiers(), analyseNumbers(), analyseOperators(), analysePreDefs(), analyseProcedures(), and run().
|
private |
Analyses commands in the code.
This member function analyses syntax elements, which are highlighted as commands
Definition at line 356 of file codeanalyzer.cpp.
References _guilang, addToAnnotation(), Options::ALWAYS_SHOW_METRICS, ANNOTATION_ERROR, ANNOTATION_NOTE, ANNOTATION_WARN, NumeReEditor::BlockMatch(), calculateCyclomaticComplexity(), calculateLinesOfCode(), Options::COMMENT_DENSITY, Options::COMPLEXITY, containsAssignment(), countNumberOfComments(), SymDefManager::createSymbol(), FILE_MATLAB, FILE_NPRC, SearchController::FindAll(), findCommand(), SearchController::FindNamingProcedure(), findParameter(), Language::get(), Options::GetAnalyzerOption(), NumeReEditor::GetFileName(), getNextArgument(), Includer::getNextLine(), SyntaxError::getToken(), getVariableType(), Options::GLOBAL_VARIABLES, highlightFoundOccurence(), Options::INLINE_IF, Includer::is_open(), NumeReEditor::isBlockEnd(), NumeReEditor::isBlockStart(), SymDefManager::isSymbol(), Options::LINES_OF_CODE, m_currentMode, m_editor, NumeReEditor::m_fileType, m_hasProcedureDefinition, m_nCurPos, m_nCurrentLine, m_options, NumeReEditor::m_search, m_sError, m_sNote, m_sWarn, m_symdefs, m_vLocalVariables, MAXCOMMENTDENSITY, MAXCOMPLEXITYNOTIFY, MAXCOMPLEXITYWARN, MAXLINESOFCODE, MINCOMMENTDENSITY, Options::MISLEADING_TYPE, Match::nPos, Options::PROCEDURE_LENGTH, Options::PROGRESS_RUNTIME, Options::RESULT_ASSIGNMENT, Options::RESULT_SUPPRESSION, Match::sString, StripSpaces(), Options::SWITCH_FALLTHROUGH, SYMDEF_COMMAND, Options::THISFILE_NAMESPACE, toString(), and Options::UNUSED_VARIABLES.
Referenced by run().
|
private |
Analyses calls to standard functions.
isContinuedLine | bool Has to be true, if the current line is continued from above |
This member function analyses syntax elements, which are highlighted as functions
Definition at line 1188 of file codeanalyzer.cpp.
References _guilang, addToAnnotation(), ANNOTATION_ERROR, ANNOTATION_WARN, FILE_MATLAB, FILE_NPRC, FILE_NSCR, Language::get(), Options::GetAnalyzerOption(), highlightFoundOccurence(), NumeReEditor::isStyleType(), m_currentMode, m_DRAW_FUNCS, m_editor, NumeReEditor::m_fileType, m_MATOP_FUNCS, m_nCurPos, m_nCurrentLine, m_options, m_sError, m_STRING_FUNCS, m_STRING_METHODS, m_sWarn, Options::RESULT_ASSIGNMENT, StripSpaces(), NumeReEditor::STYLE_COMMAND, NumeReEditor::STYLE_DATAOBJECT, and NumeReEditor::STYLE_PROCEDURE.
Referenced by run().
|
private |
Analyses occurences of identifiers.
This member function analyses syntax elements, which are highlighted as identifiers (aka variable names)
Definition at line 1345 of file codeanalyzer.cpp.
References _guilang, SettingsValue::active(), addToAnnotation(), ANNOTATION_NOTE, ANNOTATION_WARN, Options::ARGUMENT_UNDERSCORE, FILE_MATLAB, FILE_NPRC, Language::get(), Options::GetAnalyzerOption(), Settings::getSetting(), getVariableType(), Options::GLOBAL_VARIABLES, highlightFoundOccurence(), NumeReEditor::isStyleType(), SymDefManager::isSymbol(), m_editor, NumeReEditor::m_fileType, m_hasProcedureDefinition, m_nCurPos, m_nCurrentLine, m_options, m_sNote, m_sWarn, m_symdefs, m_vLocalVariables, SETTING_B_TABLEREFS, NumeReEditor::STYLE_DATAOBJECT, Options::TYPE_ORIENTATION, and Options::VARIABLE_LENGTH.
Referenced by run().
|
private |
Analyses occurences of numerical literals.
This member function analyses syntax elements, which are highlighted as numbers
Definition at line 1504 of file codeanalyzer.cpp.
References _guilang, addToAnnotation(), ANNOTATION_WARN, Language::get(), Options::GetAnalyzerOption(), highlightFoundOccurence(), NumeReEditor::isStyleType(), m_editor, m_nCurPos, m_nCurrentLine, m_options, m_sWarn, Options::MAGIC_NUMBERS, NumeReEditor::STYLE_NUMBER, and NumeReEditor::STYLE_OPERATOR.
Referenced by run().
|
private |
Analyses occurences of operators.
This member function analyses syntax elements, which are highlighted as operators
Definition at line 1478 of file codeanalyzer.cpp.
References _guilang, addToAnnotation(), ANNOTATION_ERROR, Language::get(), highlightFoundOccurence(), m_editor, m_nCurPos, and m_sError.
Referenced by run().
|
private |
Analyses occurences of special predefined variables.
Definition at line 1553 of file codeanalyzer.cpp.
References _guilang, addToAnnotation(), ANNOTATION_WARN, findVariableInExpression(), Language::get(), getAllArguments(), highlightFoundOccurence(), m_editor, m_nCurPos, m_nCurrentLine, and m_sWarn.
Referenced by run().
|
private |
Analyses calls to procedures.
This member function analyses syntax elements, which are highlighted as procedure calls
Definition at line 1293 of file codeanalyzer.cpp.
References _guilang, addToAnnotation(), ANNOTATION_ERROR, SearchController::FindMarkedProcedure(), SearchController::FindProcedureDefinition(), Language::get(), highlightFoundOccurence(), NumeReEditor::isStyleType(), m_editor, m_nCurPos, NumeReEditor::m_search, m_sError, and NumeReEditor::STYLE_PROCEDURE.
Referenced by run().
|
private |
Calculates the cyclomatic complexity between both lines.
startline | int |
endline | int |
The cyclomatic complexity (also called McGabe metric) is calculated from the number of possible control flow paths, which the code may take in a scope.
Definition at line 1769 of file codeanalyzer.cpp.
References NumeReEditor::isStyleType(), m_editor, NumeReEditor::STYLE_COMMAND, NumeReEditor::STYLE_FUNCTION, and NumeReEditor::STYLE_OPERATOR.
Referenced by analyseCommands(), and run().
|
private |
Calculates the lines of code between both lines.
startline | int |
endline | int |
The lines of code a calculated from the number of all non-comment and non-whitespace lines (i.e. all lines, which contain code)
Definition at line 1844 of file codeanalyzer.cpp.
References NumeReEditor::isStyleType(), m_editor, NumeReEditor::STYLE_COMMENT_BLOCK, and NumeReEditor::STYLE_COMMENT_LINE.
Referenced by analyseCommands(), and run().
|
static |
Change the variable's type to the passed type.
sVarName | std::string& |
type | char |
Definition at line 1988 of file codeanalyzer.cpp.
References getVariableType(), and isNumericType().
Referenced by NumeReEditor::fixSymbolName().
|
private |
Checks for assignments.
sCurrentLine | const string& |
This member function checks, whether the current line contains an assignement, i.e. the calculation result is stored into a target variable
Definition at line 1716 of file codeanalyzer.cpp.
References isInQuotes().
Referenced by analyseCommands().
|
private |
Counts the number of comment lines between both lines.
startline | int |
endline | int |
The number of comment lines are calculated from every line comment and the number of lines contained in additional block comments.
Definition at line 1895 of file codeanalyzer.cpp.
References NumeReEditor::isStyleType(), m_editor, NumeReEditor::STYLE_COMMENT_BLOCK, and NumeReEditor::STYLE_COMMENT_LINE.
Referenced by analyseCommands(), and run().
|
static |
Returns the leading character, which indicates the type of this variable or a null character, if either the leading character is not known or if it does not fulfill the requirements.
sVarName | const std::string& |
Definition at line 1939 of file codeanalyzer.cpp.
Referenced by analyseCommands(), analyseIdentifiers(), and changeVariableType().
|
private |
Highlights the occurence in the editor.
sElement | const string& |
nPos | int |
nLength | int |
The found occurence is highlighted in the editor using an indicator
Definition at line 1750 of file codeanalyzer.cpp.
References HIGHLIGHT_ANNOTATION, and m_editor.
Referenced by analyseCommands(), analyseFunctions(), analyseIdentifiers(), analyseNumbers(), analyseOperators(), analysePreDefs(), analyseProcedures(), and run().
void CodeAnalyzer::run | ( | ) |
Starts the code analysis. Requires a pointer to the editor and to the options.
This member function is the wrapper for the static code analyzer It may handle NumeRe and MATLAB files. The results are written directly as annotations in the editor.
Definition at line 73 of file codeanalyzer.cpp.
References _guilang, addToAnnotation(), Options::ALWAYS_SHOW_METRICS, analyseCommands(), analyseFunctions(), analyseIdentifiers(), analyseNumbers(), analyseOperators(), analysePreDefs(), analyseProcedures(), ANNOTATION_ERROR, ANNOTATION_NOTE, ANNOTATION_WARN, calculateCyclomaticComplexity(), calculateLinesOfCode(), SymDefManager::clear(), Options::COMMENT_DENSITY, Options::COMPLEXITY, Options::CONSTANT_EXPRESSION, countNumberOfComments(), FILE_CPP, FILE_MATLAB, FILE_NPRC, FILE_NSCR, Language::get(), Options::GetAnalyzerOption(), NumeReEditor::getEditorSetting(), NumeReEditor::GetFilenameString(), HIGHLIGHT_ANNOTATION, highlightFoundOccurence(), NumeReEditor::isStyleType(), Options::LINES_OF_CODE, m_currentMode, m_editor, NumeReEditor::m_fileType, m_hasProcedureDefinition, m_nCurPos, m_nCurrentLine, m_options, m_sCurrentLine, m_sNote, m_sStyles, m_sWarn, m_symdefs, MAXCOMMENTDENSITY, MAXCOMPLEXITYNOTIFY, MAXCOMPLEXITYWARN, MAXLINESOFCODE, MINCOMMENTDENSITY, AnnotationCount::nErrors, AnnotationCount::nNotes, AnnotationCount::nWarnings, Options::RESULT_SUPPRESSION, NumeReEditor::SETTING_USEANALYZER, StripSpaces(), NumeReEditor::STYLE_COMMAND, NumeReEditor::STYLE_COMMENT_BLOCK, NumeReEditor::STYLE_COMMENT_LINE, NumeReEditor::STYLE_DATAOBJECT, NumeReEditor::STYLE_FUNCTION, NumeReEditor::STYLE_IDENTIFIER, NumeReEditor::STYLE_NUMBER, NumeReEditor::STYLE_OPERATOR, NumeReEditor::STYLE_PROCEDURE, and toString().
Referenced by NumeReEditor::AnalyseCode(), NumeReEditor::AsynchEvaluations(), NumeReEditor::FindAndOpenProcedure(), and NumeReEditor::ToggleSettings().
|
private |
Definition at line 77 of file codeanalyzer.hpp.
Referenced by analyseCommands(), analyseFunctions(), and run().
|
private |
Definition at line 66 of file codeanalyzer.hpp.
Referenced by analyseFunctions(), and CodeAnalyzer().
|
private |
Definition at line 61 of file codeanalyzer.hpp.
Referenced by addToAnnotation(), analyseCommands(), analyseFunctions(), analyseIdentifiers(), analyseNumbers(), analyseOperators(), analysePreDefs(), analyseProcedures(), calculateCyclomaticComplexity(), calculateLinesOfCode(), countNumberOfComments(), highlightFoundOccurence(), and run().
|
private |
Definition at line 82 of file codeanalyzer.hpp.
Referenced by analyseCommands(), analyseIdentifiers(), and run().
|
private |
Definition at line 65 of file codeanalyzer.hpp.
Referenced by analyseFunctions(), and CodeAnalyzer().
|
private |
Definition at line 79 of file codeanalyzer.hpp.
Referenced by analyseCommands(), analyseFunctions(), analyseIdentifiers(), analyseNumbers(), analyseOperators(), analysePreDefs(), analyseProcedures(), and run().
|
private |
Definition at line 80 of file codeanalyzer.hpp.
Referenced by analyseCommands(), analyseFunctions(), analyseIdentifiers(), analyseNumbers(), analysePreDefs(), and run().
|
private |
Definition at line 62 of file codeanalyzer.hpp.
Referenced by addToAnnotation(), analyseCommands(), analyseFunctions(), analyseIdentifiers(), analyseNumbers(), and run().
|
private |
Definition at line 74 of file codeanalyzer.hpp.
Referenced by addToAnnotation(), and run().
|
private |
Definition at line 72 of file codeanalyzer.hpp.
Referenced by analyseCommands(), analyseFunctions(), analyseOperators(), analyseProcedures(), and CodeAnalyzer().
|
private |
Definition at line 70 of file codeanalyzer.hpp.
Referenced by analyseCommands(), analyseIdentifiers(), CodeAnalyzer(), and run().
|
private |
Definition at line 75 of file codeanalyzer.hpp.
Referenced by addToAnnotation(), and run().
|
private |
Definition at line 67 of file codeanalyzer.hpp.
Referenced by analyseFunctions(), and CodeAnalyzer().
|
private |
Definition at line 68 of file codeanalyzer.hpp.
Referenced by analyseFunctions(), and CodeAnalyzer().
|
private |
Definition at line 71 of file codeanalyzer.hpp.
Referenced by analyseCommands(), analyseFunctions(), analyseIdentifiers(), analyseNumbers(), analysePreDefs(), CodeAnalyzer(), and run().
|
private |
Definition at line 63 of file codeanalyzer.hpp.
Referenced by analyseCommands(), analyseIdentifiers(), and run().
|
private |
Definition at line 83 of file codeanalyzer.hpp.
Referenced by analyseCommands(), and analyseIdentifiers().
|
private |
Definition at line 86 of file codeanalyzer.hpp.
Referenced by analyseCommands(), and run().
|
private |
Definition at line 87 of file codeanalyzer.hpp.
Referenced by analyseCommands(), and run().
|
private |
Definition at line 88 of file codeanalyzer.hpp.
Referenced by analyseCommands(), and run().
|
private |
Definition at line 89 of file codeanalyzer.hpp.
Referenced by analyseCommands(), and run().
|
private |
Definition at line 85 of file codeanalyzer.hpp.
Referenced by analyseCommands(), and run().