NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
codeanalyzer.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2019 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef CODEANALYZER_HPP
20#define CODEANALYZER_HPP
21
22#include <string>
23#include <vector>
24#include <utility>
25
26#include "../../kernel/core/symdef.hpp"
27
33{
34 size_t nNotes;
35 size_t nWarnings;
36 size_t nErrors;
37
40 {
41 nNotes += annotcount.nNotes;
42 nWarnings += annotcount.nWarnings;
43 nErrors += annotcount.nErrors;
44 return *this;
45 }
46};
47
48
49class NumeReEditor;
50class Options;
51
52
59{
60 private:
64
65 std::vector<std::string> m_MATOP_FUNCS;
66 std::vector<std::string> m_DRAW_FUNCS;
67 std::vector<std::string> m_STRING_FUNCS;
68 std::vector<std::string> m_STRING_METHODS;
69
70 std::string m_sNote;
71 std::string m_sWarn;
72 std::string m_sError;
73
74 std::string m_sCurrentLine;
75 std::string m_sStyles;
76
77 std::string m_currentMode;
78
81
83 std::vector<std::pair<std::string,int>> m_vLocalVariables;
84
85 const double MINCOMMENTDENSITY = 0.5;
86 const double MAXCOMMENTDENSITY = 1.5;
87 const int MAXCOMPLEXITYNOTIFY = 15;
88 const int MAXCOMPLEXITYWARN = 20;
89 const int MAXLINESOFCODE = 100;
90
92 AnnotationCount analyseFunctions(bool isContinuedLine);
98 AnnotationCount addToAnnotation(const std::string& sMessage, int nStyle);
99
100 std::string highlightFoundOccurence(const std::string& sElement, int nPos, int nLength);
101 bool containsAssignment(const std::string& sCurrentLine);
102 int calculateCyclomaticComplexity(int startline, int endline);
103 int calculateLinesOfCode(int startline, int endline);
104 int countNumberOfComments(int startline, int endline);
105
106 public:
107 CodeAnalyzer(NumeReEditor* parent, Options* opts);
108
109 static char getVariableType(const std::string& sVarName);
110 static void changeVariableType(std::string& sVarName, char type);
111 void run();
112};
113
114
115#endif // CODEANALYZER_HPP
116
This class analyzes the code handled by the editor by accessing it with friends rights.
int calculateCyclomaticComplexity(int startline, int endline)
Calculates the cyclomatic complexity between both lines.
std::string m_sCurrentLine
const int MAXLINESOFCODE
bool m_hasProcedureDefinition
std::string m_sStyles
AnnotationCount analyseNumbers()
Analyses occurences of numerical literals.
AnnotationCount analyseFunctions(bool isContinuedLine)
Analyses calls to standard functions.
int calculateLinesOfCode(int startline, int endline)
Calculates the lines of code between both lines.
const double MINCOMMENTDENSITY
AnnotationCount analysePreDefs()
Analyses occurences of special predefined variables.
std::vector< std::pair< std::string, int > > m_vLocalVariables
std::vector< std::string > m_STRING_METHODS
Options * m_options
std::string m_sNote
const int MAXCOMPLEXITYWARN
std::string m_currentMode
void run()
Starts the code analysis. Requires a pointer to the editor and to the options.
AnnotationCount analyseCommands()
Analyses commands in the code.
AnnotationCount analyseOperators()
Analyses occurences of operators.
bool containsAssignment(const std::string &sCurrentLine)
Checks for assignments.
std::string m_sWarn
const int MAXCOMPLEXITYNOTIFY
const double MAXCOMMENTDENSITY
std::string m_sError
std::vector< std::string > m_STRING_FUNCS
std::vector< std::string > m_MATOP_FUNCS
SymDefManager m_symdefs
static void changeVariableType(std::string &sVarName, char type)
Change the variable's type to the passed type.
AnnotationCount analyseProcedures()
Analyses calls to procedures.
AnnotationCount addToAnnotation(const std::string &sMessage, int nStyle)
Adds the passed sMessage with the style to the internal cache.
std::vector< std::string > m_DRAW_FUNCS
CodeAnalyzer(NumeReEditor *parent, Options *opts)
NumeReEditor * m_editor
AnnotationCount analyseIdentifiers()
Analyses occurences of identifiers.
std::string highlightFoundOccurence(const std::string &sElement, int nPos, int nLength)
Highlights the occurence in the editor.
int countNumberOfComments(int startline, int endline)
Counts the number of comment lines between both lines.
static char getVariableType(const std::string &sVarName)
Returns the leading character, which indicates the type of this variable or a null character,...
The class of the editor window.
Definition: editor.h:53
This class implements an interface of the internal Settings object adapted to be usable from the GUI.
Definition: Options.h:178
This class handles the file-static constants, which are more or less macros similar to #define in C/C...
Definition: symdef.hpp:32
Stores the number of annotations for displaying a summary.
AnnotationCount & operator+=(const AnnotationCount &annotcount)