Doxygen
stlsupport.cpp
浏览该文件的文档.
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 */
21 struct 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;
30  bool virtualInheritance;
31  bool iterators;
32 };
33 
34 static STLInfo g_stlinfo[] =
35 {
36  // className baseClass1 baseClass2 templType1 templName1 templType2 templName2 virtInheritance // iterators
37  { "allocator", 0, 0, "T", "elements", 0, 0, FALSE, FALSE },
38  { "auto_ptr", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // deprecated
39  { "smart_ptr", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // C++11
40  { "unique_ptr", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // C++11
41  { "shared_ptr", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // C++14
42  { "weak_ptr", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // C++11
43  { "atomic", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // C++11
44  { "atomic_ref", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // C++20
45  { "lock_guard", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // C++11
46  { "unique_lock", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // C++11
47  { "shared_lock", 0, 0, "T", "ptr", 0, 0, FALSE, FALSE }, // C++14
48  { "ios_base", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
49  { "error_code", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
50  { "error_category", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
51  { "system_error", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
52  { "error_condition", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
53  { "thread", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
54  { "jthread", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
55  { "mutex", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
56  { "timed_mutex", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
57  { "recursive_mutex", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
58  { "recursive_timed_mutex",0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++11
59  { "shared_mutex", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++17
60  { "shared_timed_mutex", 0, 0, 0, 0, 0, 0, FALSE, FALSE }, // C++14
61  { "basic_ios", "ios_base", 0, "Char", 0, 0, 0, FALSE, FALSE },
62  { "basic_istream", "basic_ios<Char>", 0, "Char", 0, 0, 0, TRUE, FALSE },
63  { "basic_ostream", "basic_ios<Char>", 0, "Char", 0, 0, 0, TRUE, FALSE },
64  { "basic_iostream", "basic_istream<Char>", "basic_ostream<Char>", "Char", 0, 0, 0, FALSE, FALSE },
65  { "basic_ifstream", "basic_istream<Char>", 0, "Char", 0, 0, 0, FALSE, FALSE },
66  { "basic_ofstream", "basic_ostream<Char>", 0, "Char", 0, 0, 0, FALSE, FALSE },
67  { "basic_fstream", "basic_iostream<Char>", 0, "Char", 0, 0, 0, FALSE, FALSE },
68  { "basic_istringstream", "basic_istream<Char>", 0, "Char", 0, 0, 0, FALSE, FALSE },
69  { "basic_ostringstream", "basic_ostream<Char>", 0, "Char", 0, 0, 0, FALSE, FALSE },
70  { "basic_stringstream", "basic_iostream<Char>", 0, "Char", 0, 0, 0, FALSE, FALSE },
71  { "ios", "basic_ios<char>", 0, 0, 0, 0, 0, FALSE, FALSE },
72  { "wios", "basic_ios<wchar_t>", 0, 0, 0, 0, 0, FALSE, FALSE },
73  { "istream", "basic_istream<char>", 0, 0, 0, 0, 0, FALSE, FALSE },
74  { "wistream", "basic_istream<wchar_t>", 0, 0, 0, 0, 0, FALSE, FALSE },
75  { "ostream", "basic_ostream<char>", 0, 0, 0, 0, 0, FALSE, FALSE },
76  { "wostream", "basic_ostream<wchar_t>", 0, 0, 0, 0, 0, FALSE, FALSE },
77  { "ifstream", "basic_ifstream<char>", 0, 0, 0, 0, 0, FALSE, FALSE },
78  { "wifstream", "basic_ifstream<wchar_t>", 0, 0, 0, 0, 0, FALSE, FALSE },
79  { "ofstream", "basic_ofstream<char>", 0, 0, 0, 0, 0, FALSE, FALSE },
80  { "wofstream", "basic_ofstream<wchar_t>", 0, 0, 0, 0, 0, FALSE, FALSE },
81  { "fstream", "basic_fstream<char>", 0, 0, 0, 0, 0, FALSE, FALSE },
82  { "wfstream", "basic_fstream<wchar_t>", 0, 0, 0, 0, 0, FALSE, FALSE },
83  { "istringstream", "basic_istringstream<char>", 0, 0, 0, 0, 0, FALSE, FALSE },
84  { "wistringstream", "basic_istringstream<wchar_t>", 0, 0, 0, 0, 0, FALSE, FALSE },
85  { "ostringstream", "basic_ostringstream<char>", 0, 0, 0, 0, 0, FALSE, FALSE },
86  { "wostringstream", "basic_ostringstream<wchar_t>", 0, 0, 0, 0, 0, FALSE, FALSE },
87  { "stringstream", "basic_stringstream<char>", 0, 0, 0, 0, 0, FALSE, FALSE },
88  { "wstringstream", "basic_stringstream<wchar_t>", 0, 0, 0, 0, 0, FALSE, FALSE },
89  { "basic_string", 0, 0, "Char", 0, 0, 0, FALSE, TRUE },
90  { "string", "basic_string<char>", 0, 0, 0, 0, 0, FALSE, TRUE },
91  { "wstring", "basic_string<wchar_t>", 0, 0, 0, 0, 0, FALSE, TRUE },
92  { "u8string", "basic_string<char8_t>", 0, 0, 0, 0, 0, FALSE, TRUE }, // C++20
93  { "u16string", "basic_string<char16_t>", 0, 0, 0, 0, 0, FALSE, TRUE }, // C++11
94  { "u32string", "basic_string<char32_t>", 0, 0, 0, 0, 0, FALSE, TRUE }, // C++11
95  { "basic_string_view", 0, 0, "Char", 0, 0, 0, FALSE, TRUE },
96  { "string_view", "basic_string_view<char>", 0, 0, 0, 0, 0, FALSE, TRUE }, // C++17
97  { "wstring_view", "basic_string_view<wchar_t>", 0, 0, 0, 0, 0, FALSE, TRUE }, // C++17
98  { "u8string_view", "basic_string_view<char8_t>", 0, 0, 0, 0, 0, FALSE, TRUE }, // C++20
99  { "u16string_view", "basic_string_view<char16_t>", 0, 0, 0, 0, 0, FALSE, TRUE }, // C++17
100  { "u32string_view", "basic_string_view<char32_t>", 0, 0, 0, 0, 0, FALSE, TRUE }, // C++17
101  { "complex", 0, 0, 0, 0, 0, 0, FALSE, FALSE },
102  { "bitset", 0, 0, "Bits", 0, 0, 0, FALSE, FALSE },
103  { "deque", 0, 0, "T", "elements", 0, 0, FALSE, TRUE },
104  { "list", 0, 0, "T", "elements", 0, 0, FALSE, TRUE },
105  { "forward_list", 0, 0, "T", "elements", 0, 0, FALSE, TRUE }, // C++11
106  { "map", 0, 0, "K", "keys", "T", "elements", FALSE, TRUE },
107  { "unordered_map", 0, 0, "K", "keys", "T", "elements", FALSE, TRUE }, // C++11
108  { "multimap", 0, 0, "K", "keys", "T", "elements", FALSE, TRUE },
109  { "unordered_multimap", 0, 0, "K", "keys", "T", "elements", FALSE, TRUE }, // C++11
110  { "set", 0, 0, "K", "keys", 0, 0, FALSE, TRUE },
111  { "unordered_set", 0, 0, "K", "keys", 0, 0, FALSE, TRUE }, // C++11
112  { "multiset", 0, 0, "K", "keys", 0, 0, FALSE, TRUE },
113  { "unordered_multiset", 0, 0, "K", "keys", 0, 0, FALSE, TRUE }, // C++11
114  { "array", 0, 0, "T", "elements", 0, 0, FALSE, TRUE }, // C++11
115  { "vector", 0, 0, "T", "elements", 0, 0, FALSE, TRUE },
116  { "span", 0, 0, "T", "elements", 0, 0, FALSE, TRUE }, // C++20
117  { "queue", 0, 0, "T", "elements", 0, 0, FALSE, FALSE },
118  { "priority_queue", 0, 0, "T", "elements", 0, 0, FALSE, FALSE },
119  { "stack", 0, 0, "T", "elements", 0, 0, FALSE, FALSE },
120  { "valarray", 0, 0, "T", "elements", 0, 0, FALSE, FALSE },
121  { "exception", 0, 0, 0, 0, 0, 0, FALSE, FALSE },
122  { "bad_alloc", "exception", 0, 0, 0, 0, 0, FALSE, FALSE },
123  { "bad_cast", "exception", 0, 0, 0, 0, 0, FALSE, FALSE },
124  { "bad_typeid", "exception", 0, 0, 0, 0, 0, FALSE, FALSE },
125  { "logic_error", "exception", 0, 0, 0, 0, 0, FALSE, FALSE },
126  { "ios_base::failure", "exception", 0, 0, 0, 0, 0, FALSE, FALSE },
127  { "runtime_error", "exception", 0, 0, 0, 0, 0, FALSE, FALSE },
128  { "bad_exception", "exception", 0, 0, 0, 0, 0, FALSE, FALSE },
129  { "domain_error", "logic_error", 0, 0, 0, 0, 0, FALSE, FALSE },
130  { "invalid_argument", "logic_error", 0, 0, 0, 0, 0, FALSE, FALSE },
131  { "length_error", "logic_error", 0, 0, 0, 0, 0, FALSE, FALSE },
132  { "out_of_range", "logic_error", 0, 0, 0, 0, 0, FALSE, FALSE },
133  { "range_error", "runtime_error", 0, 0, 0, 0, 0, FALSE, FALSE },
134  { "overflow_error", "runtime_error", 0, 0, 0, 0, 0, FALSE, FALSE },
135  { "underflow_error", "runtime_error", 0, 0, 0, 0, 0, FALSE, FALSE },
136  { 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE }
137 };
138 
139 static void addSTLMember(const std::shared_ptr<Entry> &root,const char *type,const char *name)
140 {
141  std::shared_ptr<Entry> memEntry = std::make_shared<Entry>();
142  memEntry->name = name;
143  memEntry->type = type;
144  memEntry->protection = Public;
145  memEntry->section = Entry::VARIABLE_SEC;
146  memEntry->brief = "STL member";
147  memEntry->hidden = FALSE;
148  memEntry->artificial = TRUE;
149  root->moveToSubEntryAndKeep(memEntry);
150 }
151 
152 static void addSTLIterator(const std::shared_ptr<Entry> &classEntry,const QCString &name)
153 {
154  std::shared_ptr<Entry> iteratorClassEntry = std::make_shared<Entry>();
155  iteratorClassEntry->fileName = "[STL]";
156  iteratorClassEntry->startLine = 1;
157  iteratorClassEntry->name = name;
158  iteratorClassEntry->section = Entry::CLASS_SEC;
159  iteratorClassEntry->brief = "STL iterator class";
160  iteratorClassEntry->hidden = FALSE;
161  iteratorClassEntry->artificial= TRUE;
162  classEntry->moveToSubEntryAndKeep(iteratorClassEntry);
163 }
164 
165 static void addSTLClass(const std::shared_ptr<Entry> &root,const STLInfo *info)
166 {
167  //printf("Adding STL class %s\n",info->className);
168  QCString fullName = info->className;
169  fullName.prepend("std::");
170 
171  // add fake Entry for the class
172  std::shared_ptr<Entry> classEntry = std::make_shared<Entry>();
173  classEntry->fileName = "[STL]";
174  classEntry->startLine = 1;
175  classEntry->name = fullName;
176  classEntry->section = Entry::CLASS_SEC;
177  classEntry->brief = "STL class";
178  classEntry->hidden = FALSE;
179  classEntry->artificial= TRUE;
180 
181  // add template arguments to class
182  if (info->templType1)
183  {
184  ArgumentList al;
185  Argument a;
186  a.type="typename";
187  a.name=info->templType1;
188  al.push_back(a);
189  if (info->templType2) // another template argument
190  {
191  a.type="typename";
192  a.name=info->templType2;
193  al.push_back(a);
194  }
195  classEntry->tArgLists.push_back(al);
196  }
197  // add member variables
198  if (info->templName1)
199  {
200  addSTLMember(classEntry,info->templType1,info->templName1);
201  }
202  if (info->templName2)
203  {
204  addSTLMember(classEntry,info->templType2,info->templName2);
205  }
206  if (fullName=="std::auto_ptr" ||
207  fullName=="std::smart_ptr" ||
208  fullName=="std::shared_ptr" ||
209  fullName=="std::weak_ptr" ||
210  fullName=="std::unique_ptr")
211  {
212  std::shared_ptr<Entry> memEntry = std::make_shared<Entry>();
213  memEntry->name = "operator->";
214  memEntry->args = "()";
215  memEntry->type = "T*";
216  memEntry->protection = Public;
217  memEntry->section = Entry::FUNCTION_SEC;
218  memEntry->brief = "STL member";
219  memEntry->hidden = FALSE;
220  memEntry->artificial = FALSE;
221  classEntry->moveToSubEntryAndKeep(memEntry);
222  }
223  if (info->baseClass1)
224  {
225  classEntry->extends.push_back(BaseInfo(info->baseClass1,Public,info->virtualInheritance?Virtual:Normal));
226  }
227  if (info->baseClass2)
228  {
229  classEntry->extends.push_back(BaseInfo(info->baseClass2,Public,info->virtualInheritance?Virtual:Normal));
230  }
231  if (info->iterators)
232  {
233  // add iterator class
234  addSTLIterator(classEntry,fullName+"::iterator");
235  addSTLIterator(classEntry,fullName+"::const_iterator");
236  addSTLIterator(classEntry,fullName+"::reverse_iterator");
237  addSTLIterator(classEntry,fullName+"::const_reverse_iterator");
238  }
239  root->moveToSubEntryAndKeep(classEntry);
240 }
241 
242 
243 static void addSTLClasses(const std::shared_ptr<Entry> &root)
244 {
245  std::shared_ptr<Entry> namespaceEntry = std::make_shared<Entry>();
246  namespaceEntry->fileName = "[STL]";
247  namespaceEntry->startLine = 1;
248  namespaceEntry->name = "std";
249  namespaceEntry->section = Entry::NAMESPACE_SEC;
250  namespaceEntry->brief = "STL namespace";
251  namespaceEntry->hidden = FALSE;
252  namespaceEntry->artificial= TRUE;
253 
254  STLInfo *info = g_stlinfo;
255  while (info->className)
256  {
257  addSTLClass(namespaceEntry,info);
258  info++;
259  }
260 
261  root->moveToSubEntryAndKeep(namespaceEntry);
262 }
263 
264 void addSTLSupport(std::shared_ptr<Entry> &root)
265 {
266  if (Config_getBool(BUILTIN_STL_SUPPORT))
267  {
268  addSTLClasses(root);
269  }
270 }
STLInfo::templType2
const char * templType2
Definition: stlsupport.cpp:41
ArgumentList::push_back
void push_back(const Argument &a)
Definition: arguments.h:95
Normal
@ Normal
Definition: types.h:29
STLInfo::className
const char * className
Definition: stlsupport.cpp:36
ArgumentList
This class represents an function or template argument list.
Definition: arguments.h:59
STLInfo::iterators
bool iterators
Definition: stlsupport.cpp:44
stlsupport.h
addSTLClasses
static void addSTLClasses(const std::shared_ptr< Entry > &root)
Definition: stlsupport.cpp:243
Virtual
@ Virtual
Definition: types.h:29
Public
@ Public
Definition: types.h:26
STLInfo::virtualInheritance
bool virtualInheritance
Definition: stlsupport.cpp:43
Argument::type
QCString type
Definition: arguments.h:50
Entry::NAMESPACE_SEC
@ NAMESPACE_SEC
Definition: entry.h:68
entry.h
STLInfo::baseClass2
const char * baseClass2
Definition: stlsupport.cpp:38
Entry::CLASS_SEC
@ CLASS_SEC
Definition: entry.h:67
addSTLClass
static void addSTLClass(const std::shared_ptr< Entry > &root, const STLInfo *info)
Definition: stlsupport.cpp:165
Argument
This class contains the information about the argument of a function or template
Definition: arguments.h:26
addSTLMember
static void addSTLMember(const std::shared_ptr< Entry > &root, const char *type, const char *name)
Definition: stlsupport.cpp:139
TRUE
#define TRUE
Definition: qcstring.h:36
Entry::FUNCTION_SEC
@ FUNCTION_SEC
Definition: entry.h:97
STLInfo::templName1
const char * templName1
Definition: stlsupport.cpp:40
Config_getBool
#define Config_getBool(name)
Definition: config.h:33
addSTLIterator
static void addSTLIterator(const std::shared_ptr< Entry > &classEntry, const QCString &name)
Definition: stlsupport.cpp:152
addSTLSupport
void addSTLSupport(std::shared_ptr< Entry > &root)
Add stub entries for the most used classes in the standard template library
Definition: stlsupport.cpp:264
Argument::name
QCString name
Definition: arguments.h:52
config.h
BaseInfo
This class stores information about an inheritance relation
Definition: entry.h:35
Entry::VARIABLE_SEC
@ VARIABLE_SEC
Definition: entry.h:96
STLInfo::templType1
const char * templType1
Definition: stlsupport.cpp:39
g_stlinfo
static STLInfo g_stlinfo[]
Definition: stlsupport.cpp:34
QCString::prepend
QCString & prepend(const char *s)
Definition: qcstring.h:339
STLInfo::baseClass1
const char * baseClass1
Definition: stlsupport.cpp:37
STLInfo
A struct contained the data for an STL class
Definition: stlsupport.cpp:21
FALSE
#define FALSE
Definition: qcstring.h:33
STLInfo::templName2
const char * templName2
Definition: stlsupport.cpp:42
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108