Cppcheck
cli
cli/main.cpp
Go to the documentation of this file.
1
/*
2
* Cppcheck - A tool for static C/C++ code analysis
3
* Copyright (C) 2007-2024 Cppcheck team.
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
20
/**
21
*
22
* @mainpage Cppcheck
23
* @version 2.14.99
24
*
25
* @section overview_sec Overview
26
* Cppcheck is a simple tool for static analysis of C/C++ code.
27
*
28
* When you write a checker you have access to:
29
* - %Token list - the tokenized code
30
* - Syntax tree - Syntax tree of each expression
31
* - %SymbolDatabase - Information about all types/variables/functions/etc
32
* in the current translation unit
33
* - Library - Configuration of functions/types
34
* - Value flow analysis - Data flow analysis that determine possible values for each token
35
*
36
* Use --debug-normal on the command line to see debug output for the token list
37
* and the syntax tree. If both --debug-normal and --verbose is used, the symbol
38
* database is also written.
39
*
40
* The checks are written in C++.
41
*
42
* @section detailed_overview_sec Detailed overview
43
* This happens when you execute cppcheck from the command line:
44
* -# CppCheckExecutor::check this function executes the Cppcheck
45
* -# CmdLineParser::parseFromArgs parse command line arguments
46
* - The Settings class is used to maintain settings
47
* - Use FileLister and command line arguments to get files to check
48
* -# ThreadExecutor create more instances of CppCheck if needed
49
* -# CppCheck::check is called for each file. It checks a single file
50
* -# Preprocess the file (through Preprocessor)
51
* - Comments are removed
52
* - Macros are expanded
53
* -# Tokenize the file (see Tokenizer)
54
* -# Run the runChecks of all check classes.
55
*
56
* When errors are found, they are reported back to the CppCheckExecutor through the ErrorLogger interface.
57
*/
58
59
60
#include "
cppcheckexecutor.h
"
61
62
#ifdef NDEBUG
63
#include "
errortypes.h
"
64
65
#include <cstdlib>
66
#include <exception>
67
#include <iostream>
68
#include <string>
69
#endif
70
71
/**
72
* Main function of cppcheck
73
*
74
* @param argc Passed to CppCheck::parseFromArgs()
75
* @param argv Passed to CppCheck::parseFromArgs()
76
* @return What CppCheckExecutor::check() returns.
77
*/
78
int
main
(
int
argc,
char
* argv[])
79
{
80
// MS Visual C++ memory leak debug tracing
81
#if defined(_MSC_VER) && defined(_DEBUG)
82
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
83
#endif
84
85
CppCheckExecutor
exec;
86
87
// *INDENT-OFF*
88
#ifdef NDEBUG
89
try
{
90
#endif
91
return
exec.
check
(argc, argv);
92
#ifdef NDEBUG
93
}
catch
(
const
InternalError
& e) {
94
std::cout << e.
errorMessage
<< std::endl;
95
}
catch
(
const
std::exception&
error
) {
96
std::cout <<
error
.what() << std::endl;
97
}
catch
(...) {
98
std::cout <<
"Unknown exception"
<< std::endl;
99
}
100
return
EXIT_FAILURE;
101
#endif
102
// *INDENT-ON*
103
}
CppCheckExecutor
This class works as an example of how CppCheck can be used in external programs without very little k...
Definition:
cppcheckexecutor.h:43
CppCheckExecutor::check
int check(int argc, const char *const argv[])
Starts the checking.
Definition:
cppcheckexecutor.cpp:185
main
int main(int argc, char *argv[])
Main function of cppcheck.
Definition:
cli/main.cpp:78
cppcheckexecutor.h
errortypes.h
Severity::error
@ error
Programming error.
InternalError
Simple container to be thrown when internal error is detected.
Definition:
errortypes.h:36
InternalError::errorMessage
std::string errorMessage
Definition:
errortypes.h:43
Generated on Tue May 14 2024 11:53:14 for Cppcheck by
1.9.1