Cppcheck
cppchecklibrarydata.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2023 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 #ifndef CPPCHECKLIBRARYDATA_H
20 #define CPPCHECKLIBRARYDATA_H
21 
22 #include <QList>
23 #include <QMap>
24 #include <QPair>
25 #include <QSet>
26 #include <QString>
27 #include <QStringList>
28 
29 class QIODevice;
30 
32 public:
33  CppcheckLibraryData() = default;
34 
35  struct Container {
36  QString id;
37  QString inherits;
38  QString startPattern;
39  QString endPattern;
40  QString opLessAllowed;
41  QString itEndPattern;
42 
45 
46  struct {
48  QString string;
49  } type;
50 
52  QString name;
54  };
55 
56  struct Function {
57  QString name;
58  QString yields;
59  QString action;
60  };
61  QList<Function> accessFunctions;
62  QList<Function> otherFunctions;
63  QList<Function> sizeFunctions;
64  QList<RangeItemRecordType> rangeItemRecordTypeList;
65  };
66 
67  struct Define {
68  QString name;
69  QString value;
70  };
71 
72  struct Function {
73  QString comments;
74  QString name;
76  bool gccPure{};
77  bool gccConst{};
78  bool leakignore{};
79  bool useretval{};
80  struct ReturnValue {
81  QString type;
82  QString value;
83  int container = -1;
84  bool empty() const {
85  return type.isNull() && value.isNull() && container < 0;
86  }
88  struct {
89  QString scan;
90  QString secure;
92  struct Arg {
93  QString name;
94  unsigned int nr{};
95  static const unsigned int ANY;
96  static const unsigned int VARIADIC;
97  QString defaultValue;
98  bool notbool{};
99  bool notnull{};
100  bool notuninit{};
101  bool formatstr{};
102  bool strz{};
103  QString valid;
104  struct MinSize {
105  QString type;
106  QString arg;
107  QString arg2;
108  };
109  QList<MinSize> minsizes;
110  struct Iterator {
111  int container = -1;
112  QString type;
114  };
115  QList<Arg> args;
116 
117  struct {
118  QString severity;
119  QString cstd;
120  QString reason;
121  QString alternatives;
122  QString msg;
123 
124  bool isEmpty() const {
125  return cstd.isEmpty() &&
126  severity.isEmpty() &&
127  reason.isEmpty() &&
128  alternatives.isEmpty() &&
129  msg.isEmpty();
130  }
131  } warn;
132 
133  QMap<QString, QString> notOverlappingDataArgs;
134  QMap<QString, QString> containerAttributes;
135  };
136 
137  struct MemoryResource {
138  QString type; // "memory" or "resource"
139  struct Alloc {
140  bool isRealloc{};
141  bool init{};
142  int arg = -1; // -1: Has no optional "realloc-arg" attribute
143  int reallocArg = -1; // -1: Has no optional "arg" attribute
144  QString bufferSize;
145  QString name;
146  };
147  struct Dealloc {
148  int arg = -1; // -1: Has no optional "arg" attribute
149  QString name;
150  };
151 
152  QList<Alloc> alloc;
153  QList<Dealloc> dealloc;
154  QStringList use;
155  };
156 
157  struct PodType {
158  QString name;
159  QString stdtype;
160  QString size;
161  QString sign;
162  };
163 
164  struct PlatformType {
165  QString name;
166  QString value;
167  QStringList types; // Keeps element names w/o attribute (e.g. unsigned)
168  QStringList platforms; // Keeps "type" attribute of each "platform" element
169  };
170 
171  using TypeChecks = QList<QPair<QString, QString>>;
172 
173  struct Reflection {
174  struct Call {
175  int arg = -1; // -1: Mandatory "arg" attribute not available
176  QString name;
177  };
178 
179  QList<Call> calls;
180  };
181 
182  struct Markup {
183  struct CodeBlocks {
184  QStringList blocks;
185  int offset = -1;
186  QString start;
187  QString end;
188  };
189 
190  struct Exporter {
191  QString prefix;
192  QStringList prefixList;
193  QStringList suffixList;
194  };
195 
196  QString ext;
197  bool afterCode{};
198  bool reportErrors{};
199  QStringList keywords;
200  QStringList importer;
201  QList<CodeBlocks> codeBlocks;
202  QList<Exporter> exporter;
203  };
204 
205  struct SmartPointer {
206  QString name;
207  bool unique{};
208  };
209 
210  struct Entrypoint {
211  QString name;
212  };
213 
214  void clear() {
215  containers.clear();
216  defines.clear();
217  undefines.clear();
218  functions.clear();
219  memoryresource.clear();
220  podtypes.clear();
221  smartPointers.clear();
222  typeChecks.clear();
223  platformTypes.clear();
224  reflections.clear();
225  markups.clear();
226  entrypoints.clear();
227  }
228 
229  void swap(CppcheckLibraryData &other) {
230  containers.swap(other.containers);
231  defines.swap(other.defines);
232  undefines.swap(other.undefines);
233  functions.swap(other.functions);
234  memoryresource.swap(other.memoryresource);
235  podtypes.swap(other.podtypes);
236  smartPointers.swap(other.smartPointers);
237  typeChecks.swap(other.typeChecks);
238  platformTypes.swap(other.platformTypes);
239  reflections.swap(other.reflections);
240  markups.swap(other.markups);
241  entrypoints.swap(other.entrypoints);
242  }
243 
244  QString open(QIODevice &file);
245  QString toString() const;
246 
247  QList<Container> containers;
248  QList<Define> defines;
249  QList<Function> functions;
250  QList<MemoryResource> memoryresource;
251  QList<PodType> podtypes;
252  QList<TypeChecks> typeChecks;
253  QList<PlatformType> platformTypes;
254  QStringList undefines;
255  QList<SmartPointer> smartPointers;
256  QList<Reflection> reflections;
257  QList<Markup> markups;
258  QList<Entrypoint> entrypoints;
259 };
260 
261 #endif // CPPCHECKLIBRARYDATA_H
QList< QPair< QString, QString > > TypeChecks
QList< PlatformType > platformTypes
QList< PodType > podtypes
QList< SmartPointer > smartPointers
CppcheckLibraryData()=default
QList< Container > containers
QString open(QIODevice &file)
QList< Function > functions
QList< TypeChecks > typeChecks
void swap(CppcheckLibraryData &other)
QList< Entrypoint > entrypoints
QList< MemoryResource > memoryresource
QList< Reflection > reflections
struct CppcheckLibraryData::Container::@0 type
QList< RangeItemRecordType > rangeItemRecordTypeList
static const unsigned int VARIADIC
struct CppcheckLibraryData::Function::Arg::Iterator iterator
struct CppcheckLibraryData::Function::ReturnValue returnValue
struct CppcheckLibraryData::Function::@2 warn
enum CppcheckLibraryData::Function::TrueFalseUnknown noreturn
QMap< QString, QString > containerAttributes
struct CppcheckLibraryData::Function::@1 formatstr
QMap< QString, QString > notOverlappingDataArgs