Fix for UBSan build
[platform/upstream/doxygen.git] / src / filedef.h
1 /******************************************************************************
2  *
3  * $Id: filedef.h,v 1.32 2001/03/19 19:27:40 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 #ifndef FILEDEF_H
19 #define FILEDEF_H
20
21 #include "index.h"
22 #include <qlist.h>
23 #include <qintdict.h>
24 #include <qdict.h>
25 #include "config.h"
26 #include "definition.h"
27 #include "memberlist.h"
28 #include "util.h"
29
30 class FileDef;
31 class FileList;
32 class ClassSDict;
33 class ClassDef;
34 class ClassList;
35 class MemberDef;
36 class OutputList;
37 class NamespaceDef;
38 class NamespaceSDict;
39 class MemberGroupSDict;
40 class PackageDef;
41 class DirDef;
42
43 /** Class representing the data associated with a \#include statement. */
44 struct IncludeInfo
45 {
46   IncludeInfo() { fileDef=0; local=FALSE; indirect=FALSE; }
47   ~IncludeInfo() {}
48   FileDef *fileDef;
49   QCString includeName;
50   bool local;
51   bool imported;
52   bool indirect;
53 };
54
55 /** A model of a file symbol. 
56  *   
57  *  An object of this class contains all file information that is gathered.
58  *  This includes the members and compounds defined in the file.
59  *   
60  *  The member writeDocumentation() can be used to generate the page of
61  *  documentation to HTML and LaTeX.
62  */
63 class FileDef : public Definition
64 {
65   friend class FileName;
66
67   public:
68     //enum FileType { Source, Header, Unknown };
69
70     FileDef(const char *p,const char *n,const char *ref=0,const char *dn=0);
71    ~FileDef();
72     DefType definitionType() const { return TypeFile; }
73
74     /*! Returns the unique file name (this may include part of the path). */
75     QCString name() const 
76     { 
77       if (Config_getBool("FULL_PATH_NAMES")) 
78         return filename; 
79       else 
80         return Definition::name(); 
81     } 
82     QCString displayName(bool=TRUE) const { return name(); }
83     QCString fileName() const { return filename; }
84     
85     QCString getOutputFileBase() const 
86     { return convertNameToFile(diskname); }
87     QCString anchor() const
88     { return QCString(); }
89
90     QCString getFileBase() const
91     { return diskname; }
92
93     QCString getSourceFileBase() const;
94     
95     /*! Returns the name of the verbatim copy of this file (if any). */
96     QCString includeName() const;
97     
98     /*! Returns the absolute path including the file name. */
99     QCString absFilePath() const { return filepath; }
100     
101     
102     /*! Returns the name as it is used in the documentation */
103     QCString docName() const { return docname; }
104     
105     void addSourceRef(int line,Definition *d,MemberDef *md);
106     Definition *getSourceDefinition(int lineNr);
107     MemberDef *getSourceMember(int lineNr);
108
109     /* Sets the name of the include file to \a n. */
110     //void setIncludeName(const char *n_) { incName=n_; }
111     
112     /*! Returns the absolute path of this file. */ 
113     QCString getPath() const { return path; }
114
115     /*! Returns version of this file. */
116     QCString getVersion() const { return fileVersion; }
117     
118     bool isLinkableInProject() const;
119
120     bool isLinkable() const
121     {
122       return isLinkableInProject() || isReference();
123     }
124     bool isIncluded(const QCString &name) const;
125
126     //bool isJava() const { return m_isJava; }
127     //bool isCSharp() const { return m_isCSharp; }
128
129     void writeDocumentation(OutputList &ol);
130     void writeMemberPages(OutputList &ol);
131     void writeQuickMemberLinks(OutputList &ol,MemberDef *currentMd) const;
132     void writeSummaryLinks(OutputList &ol);
133
134     void writeSource(OutputList &ol);
135     void parseSource();
136     friend void generatedFileNames();
137     void insertMember(MemberDef *md);
138     void insertClass(ClassDef *cd);
139     void insertNamespace(NamespaceDef *nd);
140     void computeAnchors();
141
142     void setPackageDef(PackageDef *pd) { package=pd; }
143     PackageDef *packageDef() const { return package; }
144     
145     void setDirDef(DirDef *dd) { dir=dd; }
146     DirDef *getDirDef() const { return dir; }
147
148     void addUsingDirective(NamespaceDef *nd);
149     NamespaceSDict *getUsedNamespaces() const;
150     void addUsingDeclaration(Definition *def);
151     SDict<Definition> *getUsedClasses() const { return usingDeclList; }
152     void combineUsingRelations();
153
154     bool generateSourceFile() const;
155     void sortMemberLists();
156
157     void addIncludeDependency(FileDef *fd,const char *incName,bool local,bool imported,bool indirect);
158     void addIncludedByDependency(FileDef *fd,const char *incName,bool local,bool imported);
159     QList<IncludeInfo> *includeFileList() const { return includeList; }
160     QList<IncludeInfo> *includedByFileList() const { return includedByList; }
161
162     void addMembersToMemberGroup();
163     void distributeMemberGroupDocumentation();
164     void findSectionsInDocumentation();
165     void addIncludedUsingDirectives();
166
167     void addListReferences();
168     bool isDocumentationFile() const;
169     //bool includes(FileDef *incFile,QDict<FileDef> *includedFiles) const;
170     //bool includesByName(const QCString &name) const;
171
172     MemberList *getMemberList(MemberList::ListType lt) const;
173     const QList<MemberList> &getMemberLists() const { return m_memberLists; }
174
175     /* user defined member groups */
176     MemberGroupSDict *getMemberGroupSDict() const { return memberGroupSDict; }
177     NamespaceSDict *getNamespaceSDict() const     { return namespaceSDict; }
178     ClassSDict *getClassSDict() const             { return classSDict; }
179     
180     bool visited;
181
182   protected:
183     /**
184      * Retrieves the file version from version control system.
185      */
186     void acquireFileVersion();
187
188   private: 
189     MemberList *createMemberList(MemberList::ListType lt);
190     void addMemberToList(MemberList::ListType lt,MemberDef *md);
191     void writeMemberDeclarations(OutputList &ol,MemberList::ListType lt,const QCString &title);
192     void writeMemberDocumentation(OutputList &ol,MemberList::ListType lt,const QCString &title);
193     void writeIncludeFiles(OutputList &ol);
194     void writeIncludeGraph(OutputList &ol);
195     void writeIncludedByGraph(OutputList &ol);
196     void writeMemberGroups(OutputList &ol);
197     void writeAuthorSection(OutputList &ol);
198     void writeSourceLink(OutputList &ol);
199     void writeNamespaceDeclarations(OutputList &ol,const QCString &title);
200     void writeClassDeclarations(OutputList &ol,const QCString &title);
201     void writeInlineClasses(OutputList &ol);
202     void startMemberDeclarations(OutputList &ol);
203     void endMemberDeclarations(OutputList &ol);
204     void startMemberDocumentation(OutputList &ol);
205     void endMemberDocumentation(OutputList &ol);
206     void writeDetailedDescription(OutputList &ol,const QCString &title);
207     void writeBriefDescription(OutputList &ol);
208
209     QDict<IncludeInfo>   *includeDict;
210     QList<IncludeInfo>   *includeList;
211     QDict<IncludeInfo>   *includedByDict;
212     QList<IncludeInfo>   *includedByList;
213     NamespaceSDict       *usingDirList;
214     SDict<Definition>    *usingDeclList;
215     QCString              path;
216     QCString              filepath;
217     QCString              diskname;
218     QCString              filename;
219     QCString              docname;
220     QIntDict<Definition> *srcDefDict;
221     QIntDict<MemberDef>  *srcMemberDict;
222     bool                  isSource;
223     QCString              fileVersion;
224     PackageDef           *package;
225     DirDef               *dir;
226     QList<MemberList>     m_memberLists;
227     MemberGroupSDict     *memberGroupSDict;
228     NamespaceSDict       *namespaceSDict;
229     ClassSDict           *classSDict;
230     bool                  m_subGrouping;
231 };
232
233 /** Class representing a list of FileDef objects. */
234 class FileList : public QList<FileDef>
235 {
236   public:
237     FileList() : m_pathName("tmp") {}
238     FileList(const char *path) : QList<FileDef>(), m_pathName(path) {}
239    ~FileList() {}
240     QCString path() const { return m_pathName; }
241     int compareItems(GCI item1,GCI item2)
242     {
243       FileDef *md1 = (FileDef *)item1;
244       FileDef *md2 = (FileDef *)item2;
245       return stricmp(md1->name(),md2->name());
246     }
247   private:
248     QCString m_pathName;
249 };
250
251 class OutputNameList : public QList<FileList>
252 {
253   public:
254     OutputNameList() : QList<FileList>() {}
255    ~OutputNameList() {}
256     int compareItems(GCI item1,GCI item2)
257     {
258       FileList *fl1 = (FileList *)item1;
259       FileList *fl2 = (FileList *)item2;
260       return stricmp(fl1->path(),fl2->path());
261     }
262 };
263
264 class OutputNameDict : public QDict<FileList>
265 {
266   public:
267     OutputNameDict(int size) : QDict<FileList>(size) {}
268    ~OutputNameDict() {}
269 };
270
271 class Directory;
272
273 /** Class representing an entry (file or sub directory) in a directory */
274 class DirEntry
275 {
276   public:
277     enum EntryKind { Dir, File };
278     DirEntry(DirEntry *parent,FileDef *fd)  
279        : m_parent(parent), m_name(fd->name()), m_kind(File), m_fd(fd), 
280          m_isLast(FALSE) { }
281     DirEntry(DirEntry *parent,QCString name)              
282        : m_parent(parent), m_name(name), m_kind(Dir), 
283          m_fd(0), m_isLast(FALSE) { }
284     virtual ~DirEntry() { }
285     EntryKind kind() const { return m_kind; }
286     FileDef *file()  const { return m_fd; }
287     bool isLast() const    { return m_isLast; }
288     void setLast(bool b)   { m_isLast=b; }
289     DirEntry *parent() const { return m_parent; }
290     QCString name() const  { return m_name; }
291     QCString path() const  { return parent() ? parent()->path()+"/"+name() : name(); }
292
293   protected:
294     DirEntry *m_parent;
295     QCString m_name;
296
297   private:
298     EntryKind m_kind;
299     FileDef   *m_fd;
300     int num;
301     bool m_isLast;
302 };
303
304 /** Class representing a directory tree of DirEntry objects. */
305 class Directory : public DirEntry
306 {
307   public:
308     Directory(Directory *parent,const QCString &name) 
309        : DirEntry(parent,name)
310     { m_children.setAutoDelete(TRUE); }
311     virtual ~Directory()              {}
312     void addChild(DirEntry *d)        { m_children.append(d); d->setLast(TRUE); }
313     QList<DirEntry> &children()       { return m_children; }
314     void rename(const QCString &name) { m_name=name; }
315     void reParent(Directory *parent)  { m_parent=parent; }
316
317   private:
318     QList<DirEntry> m_children;
319 };
320
321 void generateFileTree();
322
323 #endif
324