Doxygen
Loading...
Searching...
No Matches
stlsupport.cpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2019 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16#include "stlsupport.h"
17#include "entry.h"
18#include "config.h"
19
20/** A struct contained the data for an STL class */
21struct STLInfo
22{
23 const char *className;
24 const char *baseClass1;
25 const char *baseClass2;
26 const char *templType1;
27 const char *templName1;
28 const char *templType2;
29 const char *templName2;
32};
33
35{
36 // className baseClass1 baseClass2 templType1 templName1 templType2 templName2 virtInheritance // iterators
37 { "allocator", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, false },
38 { "auto_ptr", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // deprecated
39 { "smart_ptr", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // C++11
40 { "unique_ptr", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // C++11
41 { "shared_ptr", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // C++14
42 { "weak_ptr", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // C++11
43 { "atomic", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // C++11
44 { "atomic_ref", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // C++20
45 { "lock_guard", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // C++11
46 { "unique_lock", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // C++11
47 { "shared_lock", nullptr, nullptr, "T", "ptr", nullptr, nullptr, false, false }, // C++14
48 { "ios_base", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
49 { "error_code", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
50 { "error_category", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
51 { "system_error", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
52 { "error_condition", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
53 { "thread", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
54 { "jthread", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
55 { "mutex", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
56 { "timed_mutex", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
57 { "recursive_mutex", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
58 { "recursive_timed_mutex",nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++11
59 { "shared_mutex", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++17
60 { "shared_timed_mutex", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }, // C++14
61 { "basic_ios", "ios_base", nullptr, "Char", nullptr, nullptr, nullptr, false, false },
62 { "basic_istream", "basic_ios<Char>", nullptr, "Char", nullptr, nullptr, nullptr, true, false },
63 { "basic_ostream", "basic_ios<Char>", nullptr, "Char", nullptr, nullptr, nullptr, true, false },
64 { "basic_iostream", "basic_istream<Char>", "basic_ostream<Char>", "Char", nullptr, nullptr, nullptr, false, false },
65 { "basic_ifstream", "basic_istream<Char>", nullptr, "Char", nullptr, nullptr, nullptr, false, false },
66 { "basic_ofstream", "basic_ostream<Char>", nullptr, "Char", nullptr, nullptr, nullptr, false, false },
67 { "basic_fstream", "basic_iostream<Char>", nullptr, "Char", nullptr, nullptr, nullptr, false, false },
68 { "basic_istringstream", "basic_istream<Char>", nullptr, "Char", nullptr, nullptr, nullptr, false, false },
69 { "basic_ostringstream", "basic_ostream<Char>", nullptr, "Char", nullptr, nullptr, nullptr, false, false },
70 { "basic_stringstream", "basic_iostream<Char>", nullptr, "Char", nullptr, nullptr, nullptr, false, false },
71 { "ios", "basic_ios<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
72 { "wios", "basic_ios<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
73 { "istream", "basic_istream<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
74 { "wistream", "basic_istream<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
75 { "ostream", "basic_ostream<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
76 { "wostream", "basic_ostream<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
77 { "ifstream", "basic_ifstream<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
78 { "wifstream", "basic_ifstream<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
79 { "ofstream", "basic_ofstream<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
80 { "wofstream", "basic_ofstream<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
81 { "fstream", "basic_fstream<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
82 { "wfstream", "basic_fstream<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
83 { "istringstream", "basic_istringstream<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
84 { "wistringstream", "basic_istringstream<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
85 { "ostringstream", "basic_ostringstream<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
86 { "wostringstream", "basic_ostringstream<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
87 { "stringstream", "basic_stringstream<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
88 { "wstringstream", "basic_stringstream<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
89 { "basic_string", nullptr, nullptr, "Char", nullptr, nullptr, nullptr, false, true },
90 { "string", "basic_string<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true },
91 { "wstring", "basic_string<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true },
92 { "u8string", "basic_string<char8_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true }, // C++20
93 { "u16string", "basic_string<char16_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true }, // C++11
94 { "u32string", "basic_string<char32_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true }, // C++11
95 { "basic_string_view", nullptr, nullptr, "Char", nullptr, nullptr, nullptr, false, true },
96 { "string_view", "basic_string_view<char>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true }, // C++17
97 { "wstring_view", "basic_string_view<wchar_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true }, // C++17
98 { "u8string_view", "basic_string_view<char8_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true }, // C++20
99 { "u16string_view", "basic_string_view<char16_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true }, // C++17
100 { "u32string_view", "basic_string_view<char32_t>", nullptr, nullptr, nullptr, nullptr, nullptr, false, true }, // C++17
101 { "complex", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
102 { "bitset", nullptr, nullptr, "Bits", nullptr, nullptr, nullptr, false, false },
103 { "deque", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, true },
104 { "list", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, true },
105 { "forward_list", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, true }, // C++11
106 { "pair", nullptr, nullptr, "T1", "first_type", "T2", "second_type", false, false },
107 { "map", nullptr, nullptr, "K", "keys", "T", "elements", false, true },
108 { "unordered_map", nullptr, nullptr, "K", "keys", "T", "elements", false, true }, // C++11
109 { "multimap", nullptr, nullptr, "K", "keys", "T", "elements", false, true },
110 { "unordered_multimap", nullptr, nullptr, "K", "keys", "T", "elements", false, true }, // C++11
111 { "set", nullptr, nullptr, "K", "keys", nullptr, nullptr, false, true },
112 { "unordered_set", nullptr, nullptr, "K", "keys", nullptr, nullptr, false, true }, // C++11
113 { "multiset", nullptr, nullptr, "K", "keys", nullptr, nullptr, false, true },
114 { "unordered_multiset", nullptr, nullptr, "K", "keys", nullptr, nullptr, false, true }, // C++11
115 { "array", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, true }, // C++11
116 { "vector", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, true },
117 { "span", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, true }, // C++20
118 { "queue", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, false },
119 { "priority_queue", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, false },
120 { "stack", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, false },
121 { "valarray", nullptr, nullptr, "T", "elements", nullptr, nullptr, false, false },
122 { "exception", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
123 { "bad_alloc", "exception", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
124 { "bad_cast", "exception", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
125 { "bad_typeid", "exception", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
126 { "logic_error", "exception", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
127 { "ios_base::failure", "exception", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
128 { "runtime_error", "exception", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
129 { "bad_exception", "exception", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
130 { "domain_error", "logic_error", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
131 { "invalid_argument", "logic_error", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
132 { "length_error", "logic_error", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
133 { "out_of_range", "logic_error", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
134 { "range_error", "runtime_error", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
135 { "overflow_error", "runtime_error", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
136 { "underflow_error", "runtime_error", nullptr, nullptr, nullptr, nullptr, nullptr, false, false },
137 { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, false, false }
138};
139
140static void addSTLMember(const std::shared_ptr<Entry> &root,const char *type,const char *name)
141{
142 std::shared_ptr<Entry> memEntry = std::make_shared<Entry>();
143 memEntry->name = name;
144 memEntry->type = type;
145 memEntry->protection = Protection::Public;
146 memEntry->section = EntryType::makeVariable();
147 memEntry->brief = "STL member";
148 memEntry->hidden = false;
149 memEntry->artificial = true;
150 root->moveToSubEntryAndKeep(memEntry);
151}
152
153static void addSTLIterator(const std::shared_ptr<Entry> &classEntry,const QCString &name)
154{
155 std::shared_ptr<Entry> iteratorClassEntry = std::make_shared<Entry>();
156 iteratorClassEntry->fileName = "[STL]";
157 iteratorClassEntry->startLine = 1;
158 iteratorClassEntry->name = name;
159 iteratorClassEntry->section = EntryType::makeClass();
160 iteratorClassEntry->brief = "STL iterator class";
161 iteratorClassEntry->hidden = false;
162 iteratorClassEntry->artificial= true;
163 classEntry->moveToSubEntryAndKeep(iteratorClassEntry);
164}
165
166static void addSTLClass(const std::shared_ptr<Entry> &root,const STLInfo *info)
167{
168 //printf("Adding STL class %s\n",info->className);
169 QCString fullName = info->className;
170 fullName.prepend("std::");
171
172 // add fake Entry for the class
173 std::shared_ptr<Entry> classEntry = std::make_shared<Entry>();
174 classEntry->fileName = "[STL]";
175 classEntry->startLine = 1;
176 classEntry->name = fullName;
177 classEntry->section = EntryType::makeClass();
178 classEntry->brief = "STL class";
179 classEntry->hidden = false;
180 classEntry->artificial= true;
181
182 // add template arguments to class
183 if (info->templType1 != nullptr)
184 {
185 ArgumentList al;
186 Argument a;
187 a.type="typename";
188 a.name=info->templType1;
189 al.push_back(a);
190 if (info->templType2 != nullptr) // another template argument
191 {
192 a.type="typename";
193 a.name=info->templType2;
194 al.push_back(a);
195 }
196 classEntry->tArgLists.push_back(al);
197 }
198 // add member variables
199 if (info->templName1 != nullptr)
200 {
201 addSTLMember(classEntry,info->templType1,info->templName1);
202 }
203 if (info->templName2 != nullptr)
204 {
205 addSTLMember(classEntry,info->templType2,info->templName2);
206 }
207 if (fullName=="std::auto_ptr" ||
208 fullName=="std::smart_ptr" ||
209 fullName=="std::shared_ptr" ||
210 fullName=="std::weak_ptr" ||
211 fullName=="std::unique_ptr")
212 {
213 std::shared_ptr<Entry> memEntry = std::make_shared<Entry>();
214 memEntry->name = "operator->";
215 memEntry->args = "()";
216 memEntry->type = "T*";
217 memEntry->protection = Protection::Public;
218 memEntry->section = EntryType::makeFunction();
219 memEntry->brief = "STL member";
220 memEntry->hidden = false;
221 memEntry->artificial = false;
222 classEntry->moveToSubEntryAndKeep(memEntry);
223 }
225 if (info->baseClass1 != nullptr)
226 {
227 classEntry->extends.emplace_back(info->baseClass1, Protection::Public, virt);
228 }
229 if (info->baseClass2 != nullptr)
230 {
231 classEntry->extends.emplace_back(info->baseClass2, Protection::Public, virt);
232 }
233 if (info->iterators)
234 {
235 // add iterator class
236 addSTLIterator(classEntry,fullName+"::iterator");
237 addSTLIterator(classEntry,fullName+"::const_iterator");
238 addSTLIterator(classEntry,fullName+"::reverse_iterator");
239 addSTLIterator(classEntry,fullName+"::const_reverse_iterator");
240 }
241 root->moveToSubEntryAndKeep(classEntry);
242}
243
244
245static void addSTLClasses(const std::shared_ptr<Entry> &root)
246{
247 std::shared_ptr<Entry> namespaceEntry = std::make_shared<Entry>();
248 namespaceEntry->fileName = "[STL]";
249 namespaceEntry->startLine = 1;
250 namespaceEntry->name = "std";
251 namespaceEntry->section = EntryType::makeNamespace();
252 namespaceEntry->brief = "STL namespace";
253 namespaceEntry->hidden = false;
254 namespaceEntry->artificial= true;
255
256 STLInfo *info = g_stlinfo;
257 while (info->className != nullptr)
258 {
259 addSTLClass(namespaceEntry,info);
260 info++;
261 }
262
263 root->moveToSubEntryAndKeep(namespaceEntry);
264}
265
266void addSTLSupport(std::shared_ptr<Entry> &root)
267{
268 if (Config_getBool(BUILTIN_STL_SUPPORT))
269 {
270 addSTLClasses(root);
271 }
272}
This class represents an function or template argument list.
Definition arguments.h:60
void push_back(const Argument &a)
Definition arguments.h:95
This is an alternative implementation of QCString.
Definition qcstring.h:101
QCString & prepend(const char *s)
Definition qcstring.h:407
#define Config_getBool(name)
Definition config.h:33
static void addSTLMember(const std::shared_ptr< Entry > &root, const char *type, const char *name)
static STLInfo g_stlinfo[]
static void addSTLClass(const std::shared_ptr< Entry > &root, const STLInfo *info)
static void addSTLClasses(const std::shared_ptr< Entry > &root)
void addSTLSupport(std::shared_ptr< Entry > &root)
Add stub entries for the most used classes in the standard template library.
static void addSTLIterator(const std::shared_ptr< Entry > &classEntry, const QCString &name)
This class contains the information about the argument of a function or template.
Definition arguments.h:27
QCString type
Definition arguments.h:37
QCString name
Definition arguments.h:39
A struct contained the data for an STL class.
const char * templType2
const char * templName2
const char * baseClass2
const char * templType1
const char * baseClass1
bool iterators
const char * templName1
bool virtualInheritance
const char * className
@ Public
Definition types.h:26
Specifier
Virtualness of a member.
Definition types.h:29
@ Virtual
Definition types.h:29
@ Normal
Definition types.h:29