1 /* This file is part of KDevelop
2     SPDX-FileCopyrightText: 2003 Roberto Raggi <roberto@kdevelop.org>
3     SPDX-FileCopyrightText: 2004 Matt Rogers <mattr@kde.org>
4     SPDX-FileCopyrightText: 2004 Alexander Dymo <adymo@kdevelop.org>
5 
6     SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 #ifndef CODEMODEL_H
9 #define CODEMODEL_H
10 
11 /**
12 @file codemodel.h
13 Code Model - a memory symbol store.
14 */
15 
16 #include "ast.h"
17 
18 #include <qmap.h>
19 #include <QStringList>
20 #include <qvector.h>
21 #include "hashedstring.h"
22 
23 #include <iostream>
24 #include <ostream>
25 #include <string>
26 #include <sstream>
27 #include <set>
28 
29 enum ParsedFileType {
30     CppParsedFile
31 };
32 
33 class AbstractParseResult : public KShared
34 {
35 public:
~AbstractParseResult()36     virtual ~AbstractParseResult() {}
37     virtual void read(QDataStream& stream) = 0;
38 
39     virtual void write(QDataStream& stream) const = 0;
40 
41     virtual ParsedFileType type() const = 0;
42 };
43 
44 typedef KSharedPtr<AbstractParseResult> ParseResultPointer;
45 
46 using namespace std;
47 
48 class CodeModel;
49 class CodeModelItem;
50 class FileModel;
51 class NamespaceModel;
52 class ClassModel;
53 class FunctionModel;
54 class FunctionDefinitionModel;
55 class VariableModel;
56 class ArgumentModel;
57 class EnumModel;
58 class EnumeratorModel;
59 class TypeAliasModel;
60 
61 /**
62 @class ItemDom
63 Safe pointer to the @ref CodeModelItem.
64 This is a type definition: @code typedef KSharedPtr<CodeModelItem> ItemDom; @endcode
65 @sa KSharedPtr
66 */
67 typedef KSharedPtr<CodeModelItem> ItemDom;
68 
69 /**
70 @class FileDom
71 Safe pointer to the @ref FileModel.
72 This is a type definition: @code typedef KSharedPtr<FileModel> FileDom; @endcode
73 @sa KSharedPtr
74 */
75 typedef KSharedPtr<FileModel> FileDom;
76 
77 /**
78 @class NamespaceDom
79 Safe pointer to the @ref NamespaceModel.
80 This is a type definition: @code typedef KSharedPtr<NamespaceModel> NamespaceDom; @endcode
81 @sa KSharedPtr
82 */
83 typedef KSharedPtr<NamespaceModel> NamespaceDom;
84 
85 /**
86 @class ClassDom
87 Safe pointer to the @ref ClassModel.
88 This is a type definition: @code typedef KSharedPtr<ClassModel> ClassDom; @endcode
89 @sa KSharedPtr
90 */
91 typedef KSharedPtr<ClassModel> ClassDom;
92 
93 /**
94 @class FunctionDom
95 Safe pointer to the @ref FunctionModel.
96 This is a type definition: @code typedef KSharedPtr<FunctionModel> FunctionDom; @endcode
97 @sa KSharedPtr
98 */
99 typedef KSharedPtr<FunctionModel> FunctionDom;
100 
101 /**
102 @class FunctionDefinitionDom
103 Safe pointer to the @ref FunctionDefinitionModel.
104 This is a type definition: @code typedef KSharedPtr<FunctionDefinitionModel> FunctionDefinitionDom; @endcode
105 @sa KSharedPtr
106 */
107 typedef KSharedPtr<FunctionDefinitionModel> FunctionDefinitionDom;
108 
109 /**
110 @class VariableDom
111 Safe pointer to the @ref VariableModel.
112 This is a type definition: @code typedef KSharedPtr<VariableModel> VariableDom; @endcode
113 @sa KSharedPtr
114 */
115 typedef KSharedPtr<VariableModel> VariableDom;
116 
117 /**
118 @class ArgumentDom
119 Safe pointer to the @ref ArgumentModel.
120 This is a type definition: @code typedef KSharedPtr<ArgumentModel> ArgumentDom; @endcode
121 @sa KSharedPtr
122 */
123 typedef KSharedPtr<ArgumentModel> ArgumentDom;
124 
125 /**
126 @class EnumDom
127 Safe pointer to the @ref EnumModel.
128 This is a type definition: @code typedef KSharedPtr<EnumModel> EnumDom; @endcode
129 @sa KSharedPtr
130 */
131 typedef KSharedPtr<EnumModel> EnumDom;
132 
133 /**
134 @class TypeAliasDom
135 Safe pointer to the @ref TypeAliasModel.
136 This is a type definition: @code typedef KSharedPtr<TypeAliasModel> TypeAliasDom; @endcode
137 @sa KSharedPtr
138 */
139 typedef KSharedPtr<TypeAliasModel> TypeAliasDom;
140 
141 /**
142 @class EnumeratorDom
143 Safe pointer to the @ref EnumeratorModel.
144 This is a type definition: @code typedef KSharedPtr<EnumeratorModel> EnumeratorDom; @endcode
145 @sa KSharedPtr
146 */
147 typedef KSharedPtr<EnumeratorModel> EnumeratorDom;
148 
149 /**
150 @class ItemList
151 The list of code model items.
152 This is a type definition: @code typedef QList<ItemDom> ItemList; @endcode
153 @sa QList
154 */
155 typedef QList<ItemDom> ItemList;
156 
157 /**
158 @class FileList
159 The list of code model files.
160 This is a type definition: @code typedef QList<FileDom> FileList; @endcode
161 @sa QList
162 */
163 typedef QList<FileDom> FileList;
164 
165 /**
166 @class NamespaceList
167 The list of code model namespaces.
168 This is a type definition: @code typedef QList<NamespaceDom> NamespaceList; @endcode
169 @sa QList
170 */
171 typedef QList<NamespaceDom> NamespaceList;
172 
173 /**
174 @class ClassList
175 The list of code model classes.
176 This is a type definition: @code typedef QList<ClassDom> ClassList; @endcode
177 @sa QList
178 */
179 typedef QList<ClassDom> ClassList;
180 
181 /**
182 @class FunctionList
183 The list of code model functions.
184 This is a type definition: @code typedef QList<FunctionDom> FunctionList; @endcode
185 @sa QList
186 */
187 typedef QList<FunctionDom> FunctionList;
188 
189 /**
190 @class FunctionDefinitionList
191 The list of code model function definitions.
192 This is a type definition: @code typedef QList<FunctionDefinitionDom> FunctionDefinitionList; @endcode
193 @sa QList
194 */
195 
196 typedef QList<FunctionDefinitionDom> FunctionDefinitionList;
197 /**
198 @class VariableList
199 The list of code model variables.
200 This is a type definition: @code typedef QList<VariableDom> VariableList; @endcode
201 @sa QList
202 */
203 typedef QList<VariableDom> VariableList;
204 
205 /**
206 @class ArgumentList
207 The list of code model arguments.
208 This is a type definition: @code typedef QList<ArgumentDom> ArgumentList; @endcode
209 @sa QList
210 */
211 typedef QList<ArgumentDom> ArgumentList;
212 
213 /**
214 @class EnumList
215 The list of code model enums.
216 This is a type definition: @code typedef QList<EnumDom> EnumList; @endcode
217 @sa QList
218 */
219 typedef QList<EnumDom> EnumList;
220 
221 /**
222 @class TypeAliasList
223 The list of code model type aliases.
224 This is a type definition: @code typedef QList<TypeAliasDom> TypeAliasList; @endcode
225 @sa QList
226 */
227 typedef QList<TypeAliasDom> TypeAliasList;
228 
229 /**
230 @class EnumeratorList
231 The list of code model enumerators.
232 This is a type definition: @code typedef QList<EnumeratorDom> EnumeratorList; @endcode
233 @sa QList
234 */
235 typedef QList<EnumeratorDom> EnumeratorList;
236 
237 /**
238 Iterates through @p lst and creates sorted list of code model item names.
239 Can be used, for example, to get the list of classes in the store:
240 @code
241 QStringList classList = sortedNameList(codeModel()->globalNamespace()->classList());
242 @endcode
243 @param lst The list to iterate.
244 @return Sorted list of code model item names.
245 */
246 template <class ItemList>
sortedNameList(const ItemList & lst)247 QStringList sortedNameList(const ItemList& lst)
248 {
249     QStringList nameList;
250 
251     typename ItemList::ConstIterator it = lst.begin();
252     while (it != lst.end()) {
253         if (!(*it)->name().isEmpty())
254             nameList << (*it)->name();
255         ++it;
256     }
257 
258     nameList.sort();
259     return nameList;
260 }
261 
262 /**
263 Casts safe code model pointers (@p KSharedPtr<T> objects like
264 FileDom, NamespaceDom, etc.) to the @p Result type.
265 
266 Example:
267 @code
268 //ns is of type NamespaceDom
269 ClassDom cl = model_cast<ClassDom>(ns);
270 @endcode
271 @param x Object to cast.
272 */
273 template <class Result, class T>
model_cast(KSharedPtr<T> x)274 Result model_cast(KSharedPtr<T> x)
275 {
276     Result r(static_cast<T*>(x));
277     return r;
278 }
279 
280 /**
281 Casts code model pointers (objects like
282 FileModel, NamespaceModel, etc.) to the @p Result type.
283 
284 Example:
285 @code
286 //ns is of type NamespaceModel*
287 ClassDom cl = model_cast<ClassDom>(ns);
288 @endcode
289 @param x Object to cast.
290 */
291 template <class Result, class T>
model_cast(T * x)292 Result model_cast(T* x)
293 {
294     Result r(static_cast<T*>(x));
295     return r;
296 }
297 
298 
299 /**
300 Code Model - a memory symbol store.
301 Symbol store (aka class store) is a database of symbols
302 found in code with the important information about those symbols.
303 
304 For example, programming language support plugins use symbol store
305 to remember information about classes, functions, etc. For each type
306 of symbol a certain information can be stored - symbol name, the
307 location in source file, etc.
308 
309 @sa codemodel.h documentation for a list of typedefs and other convenience functions.
310 
311 @sa codemodel_utils.h documentation for an additional code model utility functions and classes reference.
312 */
313 class CodeModel
314 {
315 public:
316     /**Constructor.*/
317     CodeModel();
318     /**Destructor.*/
319     virtual ~CodeModel();
320 
321     /**Creates a code model item. This should be used to create
322     code model items.
323 
324     For example, to create a class model somewhere in your plugin, use:
325     @code
326     klass = codeModel()->create<ClassModel>();
327     klass->setName("ClassName");
328     klass->setFileName("FileName");
329     klass->setStartPosition(line, column);
330     @endcode
331     @return Created code model item.*/
create()332     template <class T> typename T::Ptr create()
333     {
334         typename T::Ptr ptr(new T(this));
335         return ptr;
336     }
337 
338     /**Resets the CodeModel.*/
339     void wipeout();
340 
341     /**Gets the list of files in the store.
342     @return The FileList object that contains the list of files.*/
343     FileList fileList();
344 
345     /**Gets the list of files in the store.
346     This is a const version for convenience.
347     @return The FileList object that contains the list of files.*/
348     const FileList fileList() const;
349 
350     /**Checks to see if a file is in the store.
351     @return true if @p name is in the file list.*/
352     bool hasFile(const QString& name) const;
353 
354     /**Gets the FileDom object for a file.
355     @param name The name of the file to get the FileDom object for.*/
356     FileDom fileByName(const QString& name);
357 
358     /**Gets the FileDom object for a file.
359     This is a const version provided for convenience.
360     @param name the name of the file to get the FileDom object for.*/
361     const FileDom fileByName(const QString& name) const;
362 
363     /**Adds a file to the store.
364     @param file The FileDom object to add to the store.
365     @return true if the file was added successfully.*/
366     bool addFile(FileDom file);
367 
368     /**Removes a file from the store.
369     @param file the FileDom object to remove from the store.*/
370     void removeFile(FileDom file);
371 
372     /**Gets the global namespace
373     @return The NamespaceDom object that represents the global namespace.*/
374     const NamespaceDom globalNamespace() const;
375 
376     /**Reads the model from a stream.
377     Use this to save the memory symbol store to a file.
378 
379     Language support plugins usually save symbols from projects before the project is
380     closed to avoid reparsing when the project is opened next time.
381     @param stream Stream to read from.
382     @return whether the read succeeded(may fail when the store-format is deprecated).*/
383     virtual void read(QDataStream& stream);
384     /**Writes the model to a stream.
385     Use this to restore the memory symbol store to a file.
386 
387     Language support plugins usually save symbols from projects before the project is
388     closed to avoid reparsing when the project is opened next time.
389     @param stream Stream to write to.*/
390     virtual void write(QDataStream& stream) const;
391 
392     /** this will dump the whole tree into dot-file-format so it can be inspected, not ready yet*/
393     virtual void dump(std::ostream& file, QString Info = QString());
394 
395     /** Merges two groups, by changing the group-ids of the files.
396     Returns the id of the new group, or 0 on fail.
397     @param g1 first group
398     @param g2 second group */
399     int mergeGroups(int g1, int g2);
400 
401     /** Returns all files within the given group
402     it should be preferred calling FileModel::wholeGroup and
403     FileModel::wholeGroupStrings because those return in constant
404     time if they are the only member of the group */
405     FileList getGroup(int gid) const;
406 
407     FileList getGroup(const FileDom& file) const;
408 
409     /** Same as above, but returns the names instead of the objects */
410     virtual QStringList getGroupStrings(int gid) const;
411 
412 private:
413     /**Adds a namespace to the store.
414     @param target The NamespaceDom object that the namespace will be added to.
415     @param source The NamespaceDom object that contains the namespace to remove.*/
416     void addNamespace(NamespaceDom target, NamespaceDom source);
417 
418     /**Removes a namespace from the store.
419     @param target The NamespaceDom object that the namespace will be removed from.
420     @param source The NamespaceDom object that contains the namespace to remove.*/
421     void removeNamespace(NamespaceDom target, NamespaceDom source);
422 
423 private:
424     QMap<QString, FileDom> m_files;
425     NamespaceDom m_globalNamespace;
426 
427     virtual int newGroupId();
428     ///the groups were introduced to represent dependencies between different files.
429     ///Files can have slaves that are owned by other files within the same group.
430     ///While parsing, whole groups should always be parsed/reparsed together.
431     int m_currentGroupId;   ///normally, each file has its own group.
432 
433 private:
434     CodeModel(const CodeModel& source);
435     void operator = (const CodeModel& source);
436     friend class CodeModelItem;
437     friend class FileModel;
438 };
439 
440 
441 /**
442 Item in code model (symbol store).
443 Item is a symbol in a store. Code model provides several predefined classes
444 for predefined item types (files, namespaces, classes, functions and function definitions,
445 variables, arguments, enums and enumerators, type aliases.
446 
447 Instances of this class should be created using @ref CodeModel::create method but usually
448 it is better to create instances of derived classes like ClassModel, NamespaceModel, FileModel, etc.
449 */
450 class CodeModelItem: public KShared
451 {
452 public:
453     /**A definition of safe pointer to the code model item.*/
454     typedef ItemDom Ptr;
455 
456     /**A type of a code model item.*/
457     enum Kind {
458         File,                /**<File.*/
459         Namespace,           /**<Namespace.*/
460         Class,               /**<Class.*/
461         Function,            /**<Function or class method.*/
462         Variable,            /**<Variable.*/
463         Argument,            /**<Function or method parameter.*/
464         FunctionDefinition,  /**<Function definition.*/
465         Enum,                /**<Enum.*/
466         Enumerator,          /**<Enumerator - a member of an Enum (example: @code enum Type { A, B, C} @endcode
467                                 Type will be an Enum; A, B and C - Enumerators.*/
468         TypeAlias,           /**<Type alias (aka typedef in c++).*/
469 
470         Custom = 1000        /**<Custom model items should have type greater than 1000*/
471     };
472 
473     /**An access to the code model item.*/
474     enum Access {
475         Public,        /**<Public.*/
476         Protected,     /**<Protected.*/
477         Private        /**<Private.*/
478     };
479     void update(const CodeModelItem* i);
480     bool canUpdate(const CodeModelItem* i) const;
481 
482 protected:
483     /**Constructor.
484     @param kind The type, see also @ref CodeModelItem::Kind.
485     @param model Code model which stores this item.*/
486     CodeModelItem(int kind, CodeModel* model);
487 
488 public:
489     /**Destructor.*/
490     virtual ~CodeModelItem();
491 
492     /**@return The type (kind) of item.*/
kind()493     int kind() const
494     {
495         return m_kind;
496     }
497 
498     /**Sets the type (kind) of item.
499     @param kind The type, see also @ref CodeModelItem::Kind.*/
setKind(int kind)500     void setKind(int kind)
501     {
502         m_kind = kind;
503     }
504 
505     /**@return The name of the item.*/
506     QString name() const;
507 
comment()508     QString comment() const
509     {
510         return m_comment;
511     }
512 
setComment(QString comment)513     void setComment(QString comment)
514     {
515         m_comment = comment;
516     }
517 
518     /**Sets the name of the item.
519     @param name The name.*/
520     void setName(const QString& name);
521 
522     /**Gets the file of the item.
523     @return The FileDom object for the item.*/
524     FileDom file();
525 
526     /**Gets the file of the item
527     This is a const version provided for convenience.
528     @return The FileDom object for the item.*/
529     const FileDom file() const;
530 
531     /**@return The filename of the item.*/
532     QString fileName() const;
533 
534     /**Sets the filename of the item.
535     @param fileName The file name.*/
536     void setFileName(const QString& fileName);
537 
538     /**Gets the start position of the item.
539     @param line Will be set to the line number of the items start position. Pass 0 if line number is not necessary.
540     @param col Will be set to the column number of the items start position. Pass 0 if column number is not necessary.*/
541     void getStartPosition(int* line, int* col) const;
542 
543     /**Sets the start position of the item.
544     @param line Line number.
545     @param col Column number.*/
546     void setStartPosition(int line, int col);
547 
548     /**Get the end position of the item.
549     @param line Will be set to the line number of the items end position. Pass 0 if line number is not necessary.
550     @param col Will be set to the column number of the items end position. Pass 0 if column number is not necessary.*/
551     void getEndPosition(int* line, int* col) const;
552 
553     /**Set the end position of the item.
554     @param line Line number.
555     @param col Column number.*/
556     void setEndPosition(int line, int col);
557 
558     /**@return true if an item is a FileModel.*/
isFile()559     virtual bool isFile() const
560     {
561         return false;
562     }
563     /**@return true if an item is a NamespaceModel.*/
isNamespace()564     virtual bool isNamespace() const
565     {
566         return false;
567     }
568     /**@return true if an item is a ClassModel.*/
isClass()569     virtual bool isClass() const
570     {
571         return false;
572     }
573     /**@return true if an item is a FunctionModel.*/
isFunction()574     virtual bool isFunction() const
575     {
576         return false;
577     }
578     /**@return true if an item is a FileDefinitionModel.*/
isFunctionDefinition()579     virtual bool isFunctionDefinition() const
580     {
581         return false;
582     }
583     /**@return true if an item is a VariableModel.*/
isVariable()584     virtual bool isVariable() const
585     {
586         return false;
587     }
588     /**@return true if an item is an ArgumentModel.*/
isArgument()589     virtual bool isArgument() const
590     {
591         return false;
592     }
593     /**@return true if an item is an EnumModel.*/
isEnum()594     virtual bool isEnum() const
595     {
596         return false;
597     }
598     /**@return true if an item is an EnumeratorModel.*/
isEnumerator()599     virtual bool isEnumerator() const
600     {
601         return false;
602     }
603     /**@return true if an item is a TypeAliasModel.*/
isTypeAlias()604     virtual bool isTypeAlias() const
605     {
606         return false;
607     }
608     /**@return true if an item is a custom item.*/
isCustom()609     virtual bool isCustom() const
610     {
611         return false;
612     }
613 
isTemplateable()614     virtual bool isTemplateable() const
615     {
616         return false;
617     }
618 
619     /**Reads an item from the stream.
620     @param stream The stream to read from.*/
621     virtual void read(QDataStream& stream);
622     /**Writes an item to the stream.
623     @param stream The stream to write to.*/
624     virtual void write(QDataStream& stream) const;
625 
626     virtual void dump(std::ostream& file, bool recurse=false, QString Info = QString());
627 
628     /**@return The code model for this item.*/
codeModel()629     CodeModel* codeModel()
630     {
631         return m_model;
632     }
633 
634     /**@note This is a const version provided for convenience.
635     @return The code model for this item*/
codeModel()636     const CodeModel* codeModel() const
637     {
638         return m_model;
639     }
640 
641 private:
642     int m_kind;
643     CodeModel* m_model;
644     QString m_name;
645     QString m_fileName;
646     QString m_comment; ///not stored yet
647     int m_startLine, m_startColumn;
648     int m_endLine, m_endColumn;
649 
650 private:
651     CodeModelItem(const CodeModelItem& source);
652     void operator = (const CodeModelItem& source);
653 };
654 
655 
656 
657 class TemplateModelItem
658 {
659 public:
660     typedef QPair< QString, QString > ParamPair;
661     typedef QVector< ParamPair > ParamMap; ///The first is the name, and the second the default-parameter, or "" if there is none.
662 
~TemplateModelItem()663     virtual ~TemplateModelItem() {}
664 
getTemplateParams()665     virtual const ParamMap& getTemplateParams()
666     {
667         return m_params;
668     }
669 
670     virtual void addTemplateParam(QString name, QString def = QString())
671     {
672         m_params.push_back(ParamPair(name, def));
673     }
674 
clearTemplateParams()675     virtual void clearTemplateParams()
676     {
677         m_params.clear();
678     }
679 
hasSpecializationDeclaration()680     bool hasSpecializationDeclaration() const
681     {
682         return !m_specialization.isEmpty();
683     }
684 
getSpecializationDeclaration()685     virtual QString getSpecializationDeclaration() const
686     {
687         return m_specialization;
688     }
689 
setSpecializationDeclaration(const QString & str)690     void setSpecializationDeclaration(const QString& str)
691     {
692         m_specialization = str;
693     }
694 
695     ///returns -1 if the parameter does not exist
findTemplateParam(const QString & name)696     virtual int findTemplateParam(const QString& name) const
697     {
698         for (int a = 0; a< m_params.size(); a++)
699             if (m_params[a].first == name) return a;
700         return -1;
701     }
702 
getParam(int index)703     const ParamPair getParam(int index) const
704     {
705         return m_params[index];
706     }
707 
isTemplateable()708     virtual bool isTemplateable() const
709     {
710         return true;
711     }
712 
write(QDataStream & stream)713     void write(QDataStream & stream) const
714     {
715         stream << m_specialization;
716         stream << (int)m_params.size();
717         for (ParamMap::const_iterator it = m_params.begin(); it != m_params.end(); ++it) {
718             stream << (*it).first;
719             stream << (*it).second;
720         }
721     }
722 
read(QDataStream & stream)723     void read(QDataStream & stream)
724     {
725         int count;
726         stream >> m_specialization;
727         stream >> count;
728         for (int a = 0; a < count; a++) {
729             ParamPair tmp;
730             stream >> tmp.first;
731             stream >> tmp.second;
732             m_params.push_back(tmp);
733         }
734     }
735 
736 protected:
737     ParamMap m_params;
738     QString m_specialization;
739 };
740 
741 
742 
743 /**
744 Class model.
745 Represents a class in the code model.
746 
747 Instances of this class should be created using @ref CodeModel::create method.
748 */
749 class ClassModel: public CodeModelItem, public TemplateModelItem
750 {
751 protected:
752     /**Constructor.
753     @param model Code model which stores this item.*/
754     ClassModel(CodeModel* model);
755 
756 public:
757     /**A definition of safe pointer to the class model.*/
758     typedef ClassDom Ptr;
759 
isClass()760     virtual bool isClass() const
761     {
762         return true;
763     }
764 
765     /**@return The scope of the class. Scope is a string list composed from names of parent classes and namespaces.*/
scope()766     QStringList scope() const
767     {
768         return m_scope;
769     }
770     /**Sets the scope of this class.
771     @param scope The scope - a list of parent classes and namespaces.*/
setScope(const QStringList & scope)772     void setScope(const QStringList& scope)
773     {
774         m_scope = scope;
775     }
776 
777     /**@return The list of base class names.*/
778     QStringList baseClassList() const;
779 
780     /**Adds a base class to the list of base classes.
781     @param baseClass The base class name.*/
782     bool addBaseClass(const QString& baseClass);
783 
784     /**Removes a base class from the list of base classes.
785     @param baseClass The base class name.*/
786     void removeBaseClass(const QString& baseClass);
787 
788     /**@return The list of (sub)classes in this model.*/
789     ClassList classList();
790 
791     /**@note This is a const version provided for convenience.
792     @return The list of (sub)classes in this model.*/
793     const ClassList classList() const;
794 
795     /**Checks if the class specified by @p name is in this model.
796     @param name The name of a class to look for.
797     @return true if the model has a class.*/
798     bool hasClass(const QString& name) const;
799 
800     /**@param name The name of a class.
801     @return A list of classes that match the name given by @p name.*/
802     ClassList classByName(const QString& name);
803 
804     /**@param name The name of a class.
805     @return A list of classes that match the name given by @p name.
806     @note This is a const version provided for convenience.*/
807     const ClassList classByName(const QString& name) const;
808 
809     /**Adds a class to the model.
810     @param klass The class model to add.
811     @return true if addition was successful.*/
812     bool addClass(ClassDom klass);
813 
814     /**Removes a class from the model.
815     @param klass The class model to remove.*/
816     void removeClass(ClassDom klass);
817 
818     /**@return A list of functions in the model.*/
819     FunctionList functionList();
820 
821     /**@return A list of functions in the model.
822     @note This is a const version provided for convenience.*/
823     const FunctionList functionList() const;
824 
825     /**Check if the function specified by @p name is in the model.
826     @param name The name of a function to look for.
827     @return true if the model has a class.*/
828     bool hasFunction(const QString& name) const;
829 
830     /**@param name The name of a function to look for.
831     @return A list of functions that match the name given by @p name.*/
832     FunctionList functionByName(const QString& name);
833 
834     /**@param name The name of a function to look for.
835     @return A list of functions that match the name given by @p name.
836     @note This is a const version provided for convenience.*/
837     const FunctionList functionByName(const QString& name) const;
838 
839     /**Adds a function to the class model.
840     @param fun The function model to add.
841     @return true if addition was successful.*/
842     bool addFunction(FunctionDom fun);
843 
844     /**Removes a function from the class model.
845     @param fun The FunctionDom object to remove from the model.*/
846     void removeFunction(FunctionDom fun);
847 
848     /**@return The list of function definitions in the model.*/
849     FunctionDefinitionList functionDefinitionList();
850 
851     /**@return The list of function definitions
852     @note This is a const version provided for convenience.*/
853     const FunctionDefinitionList functionDefinitionList() const;
854 
855     /**Checks if the function definition specified by \p name is in the model.
856     @param name The name of a function definition to look for.
857     @return true if the function definition was found.*/
858     bool hasFunctionDefinition(const QString& name) const;
859 
860     /**Gets the list of functions that match the name given by \p name.
861     If there are no matches, then the list returned is empty.
862     @param name The name of a function definition to look for.
863     @return The FunctionDefinitionList object containing the definitions that match.*/
864     FunctionDefinitionList functionDefinitionByName(const QString& name);
865 
866     /**Gets the list of functions that match the name given by \p name.
867     If there are no matches, then the list returned is empty.
868     @param name The name of a function definition to look for.
869     @return The FunctionDefinitionList object containing the definitions that match.
870     @note This is a const version provided for convenience.*/
871     const FunctionDefinitionList functionDefinitionByName(const QString& name) const;
872 
873     /**Adds a function definition to the model.
874     @param fun The function fefinition model to add to the model.
875     @return true if the addition was successful.*/
876     bool addFunctionDefinition(FunctionDefinitionDom fun);
877 
878     /**Removes a function definition from the model.
879     @param fun The function fefinition model to remove from the model.*/
880     void removeFunctionDefinition(FunctionDefinitionDom fun);
881 
882     /**@return The list of variables in the model.*/
883     VariableList variableList();
884 
885     /**@return The list of variables in the model.
886     @note This is a const version provided for convenience.*/
887     const VariableList variableList() const;
888 
889     /**Checks if the variable specified by @p name is in the model.
890     @param name The name of a variable.
891     @return true if the variable was found.*/
892     bool hasVariable(const QString& name) const;
893 
894     /**Gets the variable specified by @p name.
895     If there are no matches, then the VariableDom object returned is empty.
896     @param name The name of a variable.
897     @return A VariableDom object that matches the name specified.*/
898     VariableDom variableByName(const QString& name);
899 
900     /**Gets the variable specified by @p name.
901     If there are no matches, then the VariableDom object returned is empty.
902     @param name The name of a variable.
903     @return A VariableDom object that matches the name specified.
904     @note This is a const version provided for convenience.*/
905     const VariableDom variableByName(const QString& name) const;
906 
907     /**Adds a variable to the model.
908     @param var The variable model to add to the model.
909     @return true if the addition was successful.*/
910     bool addVariable(VariableDom var);
911 
912     /**Removes a variable from the model.
913     @param var The variable model to remove from the model.*/
914     void removeVariable(VariableDom var);
915 
916     /**@return The type alias list for this model.*/
917     TypeAliasList typeAliasList();
918 
919     /**@return The type alias list for this model.
920     @note This is a const version provided for convenience.*/
921     const TypeAliasList typeAliasList() const;
922 
923     /**Checks if the type alias specified by @p name is in the model.
924     @param name The name of a type alias.
925     @return true if the type alias was found.*/
926     bool hasTypeAlias(const QString& name) const;
927 
928     /**Gets the list of type aliases that match @p name.
929     If there are no matches, the TypeAliasList object is empty.
930     @param name The name of a type alias.
931     @return A TypeAliasList object that contains the matches.*/
932     TypeAliasList typeAliasByName(const QString& name);
933 
934     /**Gets the list of type aliases that match @p name.
935     If there are no matches, the TypeAliasList object is empty.
936     @param name The name of a type alias.
937     @return A TypeAliasList object that contains the matches.
938     @note This is a const version provided for convenience.*/
939     const TypeAliasList typeAliasByName(const QString& name) const;
940 
941     /**Adds a type alias to the model.
942     @param typeAlias The type alias model to add to the model.
943     @return true if the addition was successful.*/
944     bool addTypeAlias(TypeAliasDom typeAlias);
945 
946     /**Removes a type alias from the model.
947     @param typeAlias The TypeAliasDom object to remove from the model.*/
948     void removeTypeAlias(TypeAliasDom typeAlias);
949 
950     /**@return The list of enums in the model.*/
951     EnumList enumList();
952 
953     /**@return The list of enums in the model.
954     @note This is a const version provided for convenience.*/
955     const EnumList enumList() const;
956 
957     /**Checks if the enum specified by @p name is in the model.
958     @param name The name of an enum.
959     @return true if the enum was found.*/
960     bool hasEnum(const QString& name) const;
961 
962     /**Gets the enum specified by @p name.
963     The EnumDom object returned will be empty if no match is found.
964     @param name The name of an enum.
965     @return The EnumDom object that contains the match.*/
966     EnumDom enumByName(const QString& name);
967 
968     /**Gets the enum specified by @p name.
969     The EnumDom object returned will be empty if no match is found.
970     @param name The name of an enum.
971     @return The EnumDom object that contains the match.*/
972     const EnumDom enumByName(const QString& name) const;
973 
974     /**Adds an enum to the model.
975     @param e The enum model to add to the model.
976     @return true if the addition was successful.*/
977     bool addEnum(EnumDom e);
978 
979     /**Removes an enum from the model.
980     @param e The enum model to remove from the model.*/
981     void removeEnum(EnumDom e);
982 
983     void update(const ClassModel* i);
984     bool canUpdate(const ClassModel* i) const;
985 
986     virtual void read(QDataStream& stream);
987     virtual void write(QDataStream& stream) const;
988 
989     virtual void dump(std::ostream& file, bool recurse=false, QString Info = QString());
990 
991 private:
992     QStringList m_scope;
993     QStringList m_baseClassList;
994     QMap<QString, ClassList> m_classes;
995     QMap<QString, FunctionList> m_functions;
996     QMap<QString, FunctionDefinitionList> m_functionDefinitions;
997     QMap<QString, VariableDom> m_variables;
998     QMap<QString, TypeAliasList> m_typeAliases;
999     QMap<QString, EnumDom> m_enumerators;
1000 
1001 private:
1002     ClassModel(const ClassModel& source);
1003     void operator = (const ClassModel& source);
1004     friend class CodeModel;
1005 };
1006 
1007 class NamespaceAliasModel
1008 {
1009 public:
~NamespaceAliasModel()1010     virtual ~NamespaceAliasModel() {}
1011 
1012     virtual void read(QDataStream& stream);
1013     virtual void write(QDataStream& stream) const;
1014 
name()1015     QString name() const
1016     {
1017         return m_name;
1018     }
1019 
setName(const QString & name)1020     void setName(const QString& name)
1021     {
1022         m_name = name;
1023     }
1024 
setAliasName(const QString & theValue)1025     void setAliasName(const QString& theValue)
1026     {
1027         m_aliasName = theValue;
1028     }
1029 
aliasName()1030     QString aliasName() const
1031     {
1032         return m_aliasName;
1033     }
1034 
setFileName(const HashedString & theValue)1035     void setFileName(const HashedString& theValue)
1036     {
1037         m_fileName = theValue;
1038     }
1039 
fileName()1040     HashedString fileName() const
1041     {
1042         return m_fileName;
1043     }
1044 
1045     bool operator < (const NamespaceAliasModel& rhs) const
1046     {
1047         if (m_name < rhs.m_name) return true;
1048         if (m_name == rhs.m_name) {
1049             if (m_aliasName < rhs.m_aliasName) return true;
1050             if (m_aliasName == rhs.m_aliasName && m_fileName < rhs.m_fileName) return true;
1051         }
1052         return false;
1053     }
1054 
1055     bool operator == (const NamespaceAliasModel& rhs) const
1056     {
1057         return m_name == rhs.m_name && m_aliasName == rhs.m_aliasName && m_fileName == rhs.m_fileName;
1058     }
1059 
1060 private:
1061     QString m_name;
1062     QString m_aliasName;
1063     HashedString m_fileName;
1064 };
1065 
1066 class NamespaceImportModel
1067 {
1068 public:
~NamespaceImportModel()1069     virtual ~NamespaceImportModel() {}
1070     virtual void read(QDataStream& stream);
1071     virtual void write(QDataStream& stream) const;
1072 
name()1073     QString name() const
1074     {
1075         return m_name;
1076     }
1077 
fileName()1078     HashedString fileName() const
1079     {
1080         return m_fileName;
1081     }
1082 
setName(const QString & name)1083     void setName(const QString& name)
1084     {
1085         m_name = name;
1086     }
1087 
setFileName(const HashedString & file)1088     void setFileName(const HashedString& file)
1089     {
1090         m_fileName = file;
1091     }
1092 
1093     bool operator < (const NamespaceImportModel& rhs) const
1094     {
1095         if (m_name < rhs.m_name) return true;
1096         if (m_name == rhs.m_name)
1097             if (m_fileName < rhs.m_fileName) return true;
1098 
1099         return false;
1100     }
1101 
1102     bool operator == (const NamespaceImportModel& rhs) const
1103     {
1104         return m_name == rhs.m_name && m_fileName == rhs.m_fileName;
1105     }
1106 
1107 private:
1108     QString m_name;
1109     HashedString m_fileName;
1110 };
1111 
1112 /**
1113 Namespace model.
1114 Represents a namespace in the code model.
1115 Namespace model can represent either usual c++ namespaces
1116 and packages or modules from other languages.
1117 
1118 Instances of this class should be created using @ref CodeModel::create method.
1119 */
1120 class NamespaceModel: public ClassModel
1121 {
1122 protected:
1123     /**Constructor.
1124     @param model Code model which stores this item.*/
1125     NamespaceModel(CodeModel* model);
1126 
1127 public:
1128     typedef std::set<NamespaceAliasModel> NamespaceAliasModelList; ///I'm using std-sets here, because Qt-3 has no appropriate replacement
1129     typedef std::set<NamespaceImportModel> NamespaceImportModelList;
1130 
1131     /**A definition of safe pointer to the namespace model.*/
1132     typedef NamespaceDom Ptr;
1133 
isClass()1134     virtual bool isClass() const
1135     {
1136         return false;
1137     }
isNamespace()1138     virtual bool isNamespace() const
1139     {
1140         return true;
1141     }
1142 
1143     /**@return The list of namespaces in this model.*/
1144     NamespaceList namespaceList();
1145 
1146     /**@return The list of namespaces in this model.
1147     @note This is a const version provided for convenience.*/
1148     const NamespaceList namespaceList() const;
1149 
1150     /**Checks if the namespace referenced by @p name is in the model.
1151     @param name The name of a namespace.
1152     @return true if the namespace was found.*/
1153     bool hasNamespace(const QString& name) const;
1154 
1155     /**Gets the namespace specified by @p name.
1156     If there are no matches, then the NamespaceDom object returned is empty.
1157     @param name The name of a namespace.
1158     @return The NamespaceDom object that contains the match.*/
1159     NamespaceDom namespaceByName(const QString& name);
1160 
1161     /**Gets the namespace specified by @p name.
1162     If there are no matches, then the NamespaceDom object returned is empty.
1163     @param name The name of a namespace.
1164     @return The NamespaceDom object that contains the match.
1165     @note This is a const version provided for convenience.*/
1166     const NamespaceDom namespaceByName(const QString& name) const;
1167 
1168     /**Adds a namespace to the model.
1169     @param ns The namespace model to add to the model.
1170     @return true if addition was successful.*/
1171     bool addNamespace(NamespaceDom ns);
1172 
1173     /**Removes the namespace from the model.
1174     @param ns The namespace model to remove from the model.*/
1175     void removeNamespace(NamespaceDom ns);
1176 
1177     /**Updates this model so it has the same content as the other one. Only the line/column is updated. canUpdate(..) must be tested before.
1178      * @param ns the namespace to match
1179     */
1180     void update(const NamespaceModel* ns);
1181     bool canUpdate(const NamespaceModel* ns) const;
1182 
1183     virtual void read(QDataStream& stream);
1184     virtual void write(QDataStream& stream) const;
1185 
1186     virtual void dump(std::ostream& file, bool recurse=false, QString Info = QString());
1187 
1188     void addNamespaceImport(const NamespaceImportModel& import);
1189     void addNamespaceAlias(const NamespaceAliasModel& alias);
1190     void removeNamespaceImport(const NamespaceImportModel& import);
1191     void removeNamespaceAlias(const NamespaceAliasModel& alias);
1192 
1193     ///Must not be called on temporary objects because a reference is returned(for performance-reasons)
namespaceAliases()1194     const NamespaceAliasModelList& namespaceAliases() const
1195     {
1196         return m_namespaceAliases;
1197     }
1198 
1199     ///Must not be called on temporary objects because a reference is returned(for performance-reasons)
namespaceImports()1200     const NamespaceImportModelList& namespaceImports() const
1201     {
1202         return m_namespaceImports;
1203     }
1204 private:
1205     QMap<QString, NamespaceDom> m_namespaces;
1206     NamespaceAliasModelList m_namespaceAliases;
1207     NamespaceImportModelList m_namespaceImports;
1208 
1209 private:
1210 
1211     NamespaceModel(const NamespaceModel& source);
1212     void operator = (const NamespaceModel& source);
1213     friend class CodeModel;
1214 };
1215 
1216 
1217 
1218 
1219 /**
1220 File model.
1221 Represents a file in the code model.
1222 Files in general contain classes, namespaces, functions,
1223 types, etc. Therefore FileModel is derived from NamespaceModel.
1224 
1225 Instances of this class should be created using @ref CodeModel::create method.
1226 */
1227 class FileModel: public NamespaceModel
1228 {
1229 protected:
1230     /**Constructor.
1231     @param model Code model which stores this item.*/
1232     FileModel(CodeModel* model);
1233 
1234 public:
1235     /**A definition of safe pointer to the file model.*/
1236     typedef FileDom Ptr;
1237 
isFile()1238     virtual bool isFile() const
1239     {
1240         return true;
1241     }
1242 
groupId()1243     virtual int groupId() const
1244     {
1245         return m_groupId;
1246     }
1247 
setGroupId(int newId)1248     virtual void setGroupId(int newId)
1249     {
1250         m_groupId = newId;
1251     }
1252 
1253     /** This function additionally does version-checking and
1254         should be used instead of read when read should be called
1255         from outside.
1256     @return whether the read was successful */
1257 
1258     virtual void write(QDataStream& stream) const;
1259 
1260     FileList wholeGroup() ;
1261 
1262     QStringList wholeGroupStrings() const;
1263 
1264     virtual void read(QDataStream& stream);
1265 
1266     ParseResultPointer parseResult() const;
1267     void setParseResult(const ParseResultPointer& result);
1268 
1269     void update(const FileModel* i);
1270 private:
1271     int m_groupId;
1272     ParseResultPointer m_parseResult;
1273     FileModel(const FileModel&);
1274     void operator = (const FileModel&);
1275     friend class CodeModel;
1276 };
1277 
1278 
1279 /**
1280 Function (procedure) argument model.
1281 Represents an argument in the function.
1282 
1283 Instances of this class should be created using @ref CodeModel::create method.
1284 */
1285 class ArgumentModel: public CodeModelItem
1286 {
1287 protected:
1288     ArgumentModel(CodeModel* model);
1289 
1290 public:
1291     /**A definition of safe pointer to the argument model.*/
1292     typedef ArgumentDom Ptr;
1293 
isArgument()1294     virtual bool isArgument() const
1295     {
1296         return true;
1297     }
1298 
1299     /**@return The type of this argument.*/
1300     QString type() const;
1301 
1302     /**Sets the type of this argument.
1303     @param type The type to set.*/
1304     void setType(const QString& type);
1305 
1306     /**@return The default value of this argument.*/
1307     QString defaultValue() const;
1308 
1309     /**Sets the default value of this argument.
1310     @param defaultValue The default value to set.*/
1311     void setDefaultValue(const QString& defaultValue);
1312 
1313     virtual void read(QDataStream& stream);
1314     virtual void write(QDataStream& stream) const;
1315 
1316     virtual void dump(std::ostream& file, bool recurse=false, QString Info = QString());
1317 
1318 private:
1319     QString m_type;
1320     QString m_defaultValue;
1321 
1322 private:
1323     ArgumentModel(const ArgumentModel& source);
1324     void operator = (const ArgumentModel& source);
1325     friend class CodeModel;
1326 };
1327 
1328 
1329 /**
1330 Function model.
1331 Represents:
1332 - functions;
1333 - procedures;
1334 - class methods;
1335 .
1336 In languages that have separate function declarations and definitions (c++)
1337 this represents only function declarations. @see FunctionDefinitionModel
1338 for a model of function definitions.
1339 
1340 Instances of this class should be created using @ref CodeModel::create method.
1341 */
1342 class FunctionModel: public CodeModelItem, public TemplateModelItem
1343 {
1344 protected:
1345     /**Constructor.
1346     @param model Code model which stores this item.*/
1347     FunctionModel(CodeModel* model);
1348 
1349 public:
1350     /**A definition of safe pointer to the function model.*/
1351     typedef FunctionDom Ptr;
1352 
isFunction()1353     virtual bool isFunction() const
1354     {
1355         return true;
1356     }
1357 
1358     /**@return The scope of the function. Scope is a string list composed
1359     from names of parent functions, classes and namespaces.*/
scope()1360     QStringList scope() const
1361     {
1362         return m_scope;
1363     }
1364 
1365     /**Sets the scope of the function.
1366     @param scope The scope to set.*/
setScope(const QStringList & scope)1367     void setScope(const QStringList& scope)
1368     {
1369         m_scope = scope;
1370     }
1371 
1372     /**@return The access level of the function. Can return either values of type @ref CodeModelItem::Access or
1373     other integers if the function has other access level (for example pascal methods can have "published"
1374     access level).*/
1375     int access() const;
1376 
1377     /**Sets the access level of the function.
1378     @param access The access level.*/
1379     void setAccess(int access);
1380 
1381     /**@return true if the function is a signal.*/
1382     bool isSignal() const;
1383     /**Sets the function to be a signal.
1384     @param isSignal The signal flag.*/
1385     void setSignal(bool isSignal);
1386 
1387     /**@return true if the function is a slot.*/
1388     bool isSlot() const;
1389     /**Sets the function to be a slot.
1390     @param isSlot The slot flag.*/
1391     void setSlot(bool isSlot);
1392 
1393     /**@return true if the function is a virtual function.*/
1394     bool isVirtual() const;
1395     /**Sets the function to be a virtual function.
1396     @param isVirtual The virtual flag.*/
1397     void setVirtual(bool isVirtual);
1398 
1399     /**@return true if the function is a static function.*/
1400     bool isStatic() const;
1401     /**Sets the function to be a static function.
1402     @param isStatic The static flag.*/
1403     void setStatic(bool isStatic);
1404 
1405     /**@return true if the function is an inline function.*/
1406     bool isInline() const;
1407     /**Sets the function to be an inline function.
1408     @param isInline The inline flag.*/
1409     void setInline(bool isInline);
1410 
1411     /**@return true if the function is a constant function.*/
1412     bool isConstant() const;
1413     /**Sets the function to be a constant function.
1414     @param isConstant The constant flag.*/
1415     void setConstant(bool isConstant);
1416 
1417     /**@return true if the function is an abstract function.*/
1418     bool isAbstract() const;
1419     /**Sets the function to be an inline function.
1420     @param isAbstract The abstract flag.*/
1421     void setAbstract(bool isAbstract);
1422 
1423     /**@return The result type of a function.*/
1424     QString resultType() const;
1425     /**Sets the result type of a function.
1426     @param type The type of a function result.*/
1427     void setResultType(const QString& type);
1428 
1429     /**Gets the list of arguments being passed to the function.
1430     If there are no arguments, then the list is empty.
1431     @return The ArgumentList object that contains the arguments for this function.*/
1432     ArgumentList argumentList();
1433 
1434     /**Gets the list of arguments being passed to the function.
1435     If there are no arguments, then the list is empty.
1436     @return The ArgumentList object that contains the arguments for this function.
1437     @note This is a const version provided for convenience.*/
1438     const ArgumentList argumentList() const;
1439 
1440     /**Adds an argument to the function.
1441     @param arg The argument model to add as an argument to the function.
1442     @return true if the addition was successful.*/
1443     bool addArgument(ArgumentDom arg);
1444 
1445     /**Removes an argument from the function.
1446     @param arg The argument model to remove from the function.*/
1447     void removeArgument(ArgumentDom arg);
1448 
1449     virtual void read(QDataStream& stream);
1450     virtual void write(QDataStream& stream) const;
1451 
1452     virtual void dump(std::ostream& file, bool recurse=false, QString Info = QString());
1453 
1454     void update(const FunctionModel* i);
1455     bool canUpdate(const FunctionModel* i) const;
1456 
1457 private:
1458     QStringList m_scope;
1459     int m_access;
1460 
1461     union {
1462         struct {
1463             int m_signal : 1;
1464             int m_slot : 1;
1465             int m_virtual : 1;
1466             int m_static : 1;
1467             int m_inline : 1;
1468             int m_constant : 1;
1469             int m_abstract : 1;
1470         } v;
1471         int flags;
1472     } d;
1473 
1474     QString m_resultType;
1475     ArgumentList m_arguments;
1476 
1477 private:
1478     FunctionModel(const FunctionModel& source);
1479     void operator = (const FunctionModel& source);
1480     friend class CodeModel;
1481 };
1482 
1483 /**
1484 Function model.
1485 Represents function definition for languages that have such.
1486 
1487 Instances of this class should be created using @ref CodeModel::create method.
1488 */
1489 class FunctionDefinitionModel: public FunctionModel
1490 {
1491 protected:
1492     /**Constructor.
1493     @param model Code model which stores this item.*/
1494     FunctionDefinitionModel(CodeModel* model);
1495 
1496 public:
1497     /**A definition of safe pointer to the function definition model.*/
1498     typedef FunctionDefinitionDom Ptr;
1499 
isFunctionDefinition()1500     virtual bool isFunctionDefinition() const
1501     {
1502         return true;
1503     }
1504 
1505 private:
1506     FunctionDefinitionModel(const FunctionDefinitionModel& source);
1507     void operator = (const FunctionDefinitionModel& source);
1508     friend class CodeModel;
1509 };
1510 
1511 
1512 /**
1513 Variable model.
1514 Represents variables and class attributes.
1515 
1516 Instances of this class should be created using @ref CodeModel::create method.
1517 */
1518 class VariableModel: public CodeModelItem
1519 {
1520 protected:
1521     /**Constructor.
1522     @param model Code model which stores this item.*/
1523     VariableModel(CodeModel* model);
1524 
1525 public:
1526     /**A definition of safe pointer to the variable model.*/
1527     typedef VariableDom Ptr;
1528 
isVariable()1529     virtual bool isVariable() const
1530     {
1531         return true;
1532     }
1533 
1534     /**@return The access level of the variable. Can return either values of type @ref CodeModelItem::Access or
1535     other integers if the variable has other access level (for example pascal attributes can have "published"
1536     access level).*/
1537     int access() const;
1538     /**Sets the access level of the variable.
1539     @param access The access level.*/
1540     void setAccess(int access);
1541 
1542     /**@return true if the variable is a static variable.*/
1543     bool isStatic() const;
1544     /**Sets the variable to be a static variable.
1545     @param isStatic The static flag.*/
1546     void setStatic(bool isStatic);
1547 
1548     /**@return A type of the variable.*/
1549     QString type() const;
1550     /**Sets the type of the variable.
1551     @param type The type name.*/
1552     void setType(const QString& type);
1553 
1554     /**@return If this is an enumerator, the enum it is part of, else an empty string. This is just a hack, necessary because EnumeratorModel is not used at all by the cpp-code-model. */
1555     bool isEnumeratorVariable() const;
1556 
1557     void setEnumeratorVariable(bool b);
1558 
1559     virtual void read(QDataStream& stream);
1560     virtual void write(QDataStream& stream) const;
1561 
1562     virtual void dump(std::ostream& file, bool recurse=false, QString Info = QString());
1563 
1564     void update(const VariableModel* i);
1565     bool canUpdate(const VariableModel* i) const;
1566 
1567 private:
1568     int m_access;
1569     int m_static;
1570     QString m_type;
1571     int m_isEnumeratorVariable;
1572 
1573 private:
1574     VariableModel(const VariableModel& source);
1575     void operator = (const VariableModel& source);
1576     friend class CodeModel;
1577 };
1578 
1579 
1580 /**
1581 Enum model.
1582 Represents enums.
1583 
1584 Instances of this class should be created using @ref CodeModel::create method.
1585 */
1586 class EnumModel: public CodeModelItem
1587 {
1588 protected:
1589     /**Constructor.
1590     @param model Code model which stores this item.*/
1591     EnumModel(CodeModel* model);
1592 
1593 public:
1594     /**A definition of safe pointer to the enum model.*/
1595     typedef EnumDom Ptr;
1596 
isEnum()1597     virtual bool isEnum() const
1598     {
1599         return true;
1600     }
1601 
1602     /**@return The access level of the enum. Can return either values
1603     of type @ref CodeModelItem::Access or other integers if the enum has other access level.*/
1604     int access() const;
1605     /**Sets the access level of the enum.
1606     @param access The access level.*/
1607     void setAccess(int access);
1608 
1609     /**@return The list of enumerators in this enum.*/
1610     EnumeratorList enumeratorList();
1611     /**@return The list of enumerators in this enum.
1612     @note This is a const version provided for convenience.*/
1613     const EnumeratorList enumeratorList() const;
1614     /**Adds an enumerator to the model.
1615     @param e The enumerator model to add.*/
1616     void addEnumerator(EnumeratorDom e);
1617     /**Removes an enumerator from the model.
1618     @param e The enumerator model to remove.*/
1619     void removeEnumerator(EnumeratorDom e);
1620 
1621     virtual void read(QDataStream& stream);
1622     virtual void write(QDataStream& stream) const;
1623 
1624     ///The dump-function is not ready yet
1625     virtual void dump(std::ostream& file, bool recurse=false, QString Info = QString());
1626 
1627     void update(const EnumModel* i);
1628     bool canUpdate(const EnumModel* i) const;
1629 
1630 private:
1631     int m_access;
1632     QMap<QString, EnumeratorDom> m_enumerators;
1633 
1634 private:
1635     EnumModel(const EnumModel& source);
1636     void operator = (const EnumModel& source);
1637     friend class CodeModel;
1638 };
1639 
1640 
1641 /**
1642 Enumerator model.
1643 Represents enumerators. Enums consist of enumerators, for example in code:
1644 @code
1645 enum Type { A, B, C};
1646 @endcode
1647 Type is represented as EnumModel;\n
1648 A, B, C are represented with EnumeratorModel.
1649 
1650 Instances of this class should be created using @ref CodeModel::create method.
1651 */
1652 class EnumeratorModel: public CodeModelItem
1653 {
1654 protected:
1655     /**Constructor.
1656     @param model Code model which stores this item.*/
1657     EnumeratorModel(CodeModel* model);
1658 
1659 public:
1660     /**A definition of safe pointer to the enumerator model.*/
1661     typedef EnumeratorDom Ptr;
1662 
isEnumerator()1663     virtual bool isEnumerator() const
1664     {
1665         return true;
1666     }
1667 
1668     /**@return The value of an enumerator.*/
1669     QString value() const;
1670     /**Sets the value of an enumerator.
1671     @param value The value.*/
1672     void setValue(const QString& value);
1673 
1674     virtual void read(QDataStream& stream);
1675     virtual void write(QDataStream& stream) const;
1676 
1677     virtual void dump(std::ostream& file, bool recurse=false, QString Info = QString());
1678 
1679 private:
1680     QString m_value;
1681 
1682 private:
1683     EnumeratorModel(const EnumeratorModel& source);
1684     void operator = (const EnumeratorModel& source);
1685     friend class CodeModel;
1686 };
1687 
1688 
1689 /**
1690 Type alias model.
1691 Represents type aliases (like subtypes/derived types in Ada and typedefs in c++).
1692 */
1693 class TypeAliasModel: public CodeModelItem
1694 {
1695 protected:
1696     /**Constructor.
1697     @param model Code model which stores this item.*/
1698     TypeAliasModel(CodeModel* model);
1699 
1700 public:
1701     /**A definition of safe pointer to the type alias model.*/
1702     typedef TypeAliasDom Ptr;
1703 
isTypeAlias()1704     virtual bool isTypeAlias() const
1705     {
1706         return true;
1707     }
1708 
1709     /**@return The actual type of an alias.*/
1710     QString type() const;
1711     /**Sets the type of an alias.
1712     @param type The type name.*/
1713     void setType(const QString& type);
1714 
1715     virtual void read(QDataStream& stream);
1716     virtual void write(QDataStream& stream) const;
1717 
1718 
1719     virtual void dump(std::ostream& file, bool recurse=false, QString Info = QString());
1720 
1721     void update(const TypeAliasModel* i);
1722     bool canUpdate(const TypeAliasModel* i) const;
1723 
1724 private:
1725     QString m_type;
1726 
1727 private:
1728     TypeAliasModel(const TypeAliasModel& source);
1729     void operator = (const TypeAliasModel& source);
1730     friend class CodeModel;
1731 };
1732 
1733 #endif
1734