Fix for UBSan build
[platform/upstream/doxygen.git] / src / classlist.cpp
1 /******************************************************************************
2  *
3  * $Id: classlist.cpp,v 1.14 2001/03/19 19:27:39 root Exp $
4  *
5  * Copyright (C) 1997-2012 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby 
9  * granted. No representations are made about the suitability of this software 
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  * Documents produced by Doxygen are derivative works derived from the
14  * input used in their production; they are not affected by this license.
15  *
16  */
17
18 #include "classlist.h"
19 #include "config.h"
20 #include "util.h"
21 #include "outputlist.h"
22 #include "language.h"
23 #include "doxygen.h"
24 #include "vhdldocgen.h"
25 #include "defargs.h"
26 #include "arguments.h"
27
28 ClassList::ClassList() : QList<ClassDef>()
29 {
30 }
31
32 ClassList::~ClassList()
33 {
34 }
35
36 static int compItems(void *item1,void *item2)
37 {
38   ClassDef *c1=(ClassDef *)item1;
39   ClassDef *c2=(ClassDef *)item2;
40   static bool b = Config_getBool("SORT_BY_SCOPE_NAME");
41   //printf("compItems: %d %s<->%s\n",b,c1->name().data(),c2->name().data());
42   if (b) 
43   { 
44      return stricmp(c1->name(),
45                     c2->name());
46   }
47   else
48   {
49      return stricmp(c1->className(),
50                     c2->className());
51   }
52 }
53
54 int ClassList::compareItems(GCI item1, GCI item2)
55 {
56   return compItems(item1,item2);
57 }
58
59 int ClassSDict::compareItems(GCI item1, GCI item2)
60 {
61   return compItems(item1,item2);
62 }
63
64 ClassListIterator::ClassListIterator(const ClassList &cllist) :
65   QListIterator<ClassDef>(cllist)
66 {
67 }
68
69 bool ClassSDict::declVisible(const ClassDef::CompoundType *filter) const
70 {
71   static bool hideUndocClasses = Config_getBool("HIDE_UNDOC_CLASSES");
72   static bool extractLocalClasses = Config_getBool("EXTRACT_LOCAL_CLASSES");
73   if (count()>0)
74   {
75     ClassSDict::Iterator sdi(*this);
76     ClassDef *cd=0;
77     for (sdi.toFirst();(cd=sdi.current());++sdi)
78     {
79       if (cd->name().find('@')==-1 && 
80           (filter==0 || *filter==cd->compoundType())
81          )
82       {
83         bool isLink = cd->isLinkable();
84         if (isLink || 
85              (!hideUndocClasses && 
86               (!cd->isLocal() || extractLocalClasses)
87              )
88            )
89         {
90           return TRUE;
91         }
92       }
93     }
94   }
95   return FALSE;
96 }
97
98 void ClassSDict::writeDeclaration(OutputList &ol,const ClassDef::CompoundType *filter,
99                                   const char *header,bool localNames)
100 {
101   static bool extractPrivate = Config_getBool("EXTRACT_PRIVATE");
102   if (count()>0)
103   {
104     ClassSDict::Iterator sdi(*this);
105     ClassDef *cd=0;
106     bool found=FALSE;
107     for (sdi.toFirst();(cd=sdi.current());++sdi)
108     {
109       //printf("  ClassSDict::writeDeclaration for %s\n",cd->name().data());
110       if (cd->name().find('@')==-1 && 
111           !cd->isExtension() && 
112           (cd->protection()!=Private || extractPrivate) &&
113           (filter==0 || *filter==cd->compoundType())
114          )
115       {
116         cd->writeDeclarationLink(ol,found,header,localNames);
117       }
118     }
119     if (found) ol.endMemberList();
120   }
121 }
122   
123 void ClassSDict::writeDocumentation(OutputList &ol,Definition * container)
124 {
125   static bool fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN");
126
127   static bool inlineGroupedClasses = Config_getBool("INLINE_GROUPED_CLASSES");
128   static bool inlineSimpleClasses = Config_getBool("INLINE_SIMPLE_STRUCTS");
129   if (!inlineGroupedClasses && !inlineSimpleClasses) return;
130
131   if (count()>0)
132   {
133     bool found=FALSE;
134
135     ClassSDict::Iterator sdi(*this);
136     ClassDef *cd=0;
137     for (sdi.toFirst();(cd=sdi.current());++sdi)
138     {
139       //printf("%s:writeDocumentation() %p embedded=%d container=%p\n",
140       //  cd->name().data(),cd->getOuterScope(),cd->isEmbeddedInOuterScope(),
141       //  container);
142
143       if (cd->name().find('@')==-1 && 
144           cd->isLinkableInProject() &&
145           cd->isEmbeddedInOuterScope() &&
146           (container==0 || cd->partOfGroups()==0) // if container==0 -> show as part of the group docs, otherwise only show if not part of a group
147           //&&
148           //(container==0 || // no container -> used for groups
149           // cd->getOuterScope()==container || // correct container -> used for namespaces and classes
150           // (container->definitionType()==Definition::TypeFile && cd->getOuterScope()==Doxygen::globalScope && cd->partOfGroups()==0) // non grouped class with file scope -> used for files
151           //)
152          )
153       {
154         if (!found)
155         {
156           ol.writeRuler();
157           ol.startGroupHeader();
158           ol.parseText(fortranOpt?theTranslator->trTypeDocumentation():
159               theTranslator->trClassDocumentation());
160           ol.endGroupHeader();
161           found=TRUE;
162         }
163         cd->writeInlineDocumentation(ol);
164       }
165     }
166   }
167 }
168
169 //-------------------------------------------
170
171 void GenericsSDict::insert(const QCString &key,ClassDef *cd)
172 {
173   int i=key.find('<');
174   if (i==-1) return;
175   ArgumentList argList;
176   stringToArgumentList(key.mid(i),&argList);
177   int c = argList.count();
178   if (c==0) return;
179   GenericsCollection *collection = m_dict.find(key.left(i));
180   if (collection==0) // new name
181   {
182     collection = new GenericsCollection;
183     m_dict.append(key.left(i),collection);
184   }
185   if (collection->find(c)==0) // should always be 0!
186   {
187     collection->insert(c,cd);
188   }
189 }
190
191 ClassDef *GenericsSDict::find(const QCString &key)
192 {
193   int i=key.find('<');
194   if (i==-1)
195   {
196     GenericsCollection *collection = m_dict.find(key);
197     if (collection && collection->count()==1)
198     {
199       QIntDictIterator<ClassDef> it(*collection);
200       return it.current();
201     }
202   }
203   else
204   {
205     GenericsCollection *collection = m_dict.find(key.left(i));
206     if (collection)
207     {
208       ArgumentList argList;
209       stringToArgumentList(key.mid(i),&argList);
210       int c = argList.count();
211       return collection->find(c);
212     }
213   }
214   return 0;
215 }
216
217
218
219