1
/* This file is part of KDevelop
2
Copyright (C) 2003 Roberto Raggi <roberto@kdevelop.org>
3
Copyright (C) 2004 Matt Rogers <mattr@kde.org>
4
Copyright (C) 2004 Alexander Dymo <adymo@kdevelop.org>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
26
Code Model - a memory symbol store.
31
#include <qstringlist.h>
32
#include <ksharedptr.h>
33
#include <qvaluevector.h>
34
#include "hashedstring.h"
46
class AbstractParseResult : public KShared {
48
virtual void read( QDataStream& stream ) = 0;
50
virtual void write( QDataStream& stream ) const = 0;
52
virtual ParsedFileType type() const = 0;
55
typedef KSharedPtr<AbstractParseResult> ParseResultPointer;
65
class FunctionDefinitionModel;
69
class EnumeratorModel;
74
Safe pointer to the @ref CodeModelItem.
75
This is a type definition: @code typedef KSharedPtr<CodeModelItem> ItemDom; @endcode
78
typedef KSharedPtr<CodeModelItem> ItemDom;
82
Safe pointer to the @ref FileModel.
83
This is a type definition: @code typedef KSharedPtr<FileModel> FileDom; @endcode
86
typedef KSharedPtr<FileModel> FileDom;
90
Safe pointer to the @ref NamespaceModel.
91
This is a type definition: @code typedef KSharedPtr<NamespaceModel> NamespaceDom; @endcode
94
typedef KSharedPtr<NamespaceModel> NamespaceDom;
98
Safe pointer to the @ref ClassModel.
99
This is a type definition: @code typedef KSharedPtr<ClassModel> ClassDom; @endcode
102
typedef KSharedPtr<ClassModel> ClassDom;
106
Safe pointer to the @ref FunctionModel.
107
This is a type definition: @code typedef KSharedPtr<FunctionModel> FunctionDom; @endcode
110
typedef KSharedPtr<FunctionModel> FunctionDom;
113
@class FunctionDefinitionDom
114
Safe pointer to the @ref FunctionDefinitionModel.
115
This is a type definition: @code typedef KSharedPtr<FunctionDefinitionModel> FunctionDefinitionDom; @endcode
118
typedef KSharedPtr<FunctionDefinitionModel> FunctionDefinitionDom;
122
Safe pointer to the @ref VariableModel.
123
This is a type definition: @code typedef KSharedPtr<VariableModel> VariableDom; @endcode
126
typedef KSharedPtr<VariableModel> VariableDom;
130
Safe pointer to the @ref ArgumentModel.
131
This is a type definition: @code typedef KSharedPtr<ArgumentModel> ArgumentDom; @endcode
134
typedef KSharedPtr<ArgumentModel> ArgumentDom;
138
Safe pointer to the @ref EnumModel.
139
This is a type definition: @code typedef KSharedPtr<EnumModel> EnumDom; @endcode
142
typedef KSharedPtr<EnumModel> EnumDom;
146
Safe pointer to the @ref TypeAliasModel.
147
This is a type definition: @code typedef KSharedPtr<TypeAliasModel> TypeAliasDom; @endcode
150
typedef KSharedPtr<TypeAliasModel> TypeAliasDom;
154
Safe pointer to the @ref EnumeratorModel.
155
This is a type definition: @code typedef KSharedPtr<EnumeratorModel> EnumeratorDom; @endcode
158
typedef KSharedPtr<EnumeratorModel> EnumeratorDom;
162
The list of code model items.
163
This is a type definition: @code typedef QValueList<ItemDom> ItemList; @endcode
166
typedef QValueList<ItemDom> ItemList;
170
The list of code model files.
171
This is a type definition: @code typedef QValueList<FileDom> FileList; @endcode
174
typedef QValueList<FileDom> FileList;
178
The list of code model namespaces.
179
This is a type definition: @code typedef QValueList<NamespaceDom> NamespaceList; @endcode
182
typedef QValueList<NamespaceDom> NamespaceList;
186
The list of code model classes.
187
This is a type definition: @code typedef QValueList<ClassDom> ClassList; @endcode
190
typedef QValueList<ClassDom> ClassList;
194
The list of code model functions.
195
This is a type definition: @code typedef QValueList<FunctionDom> FunctionList; @endcode
198
typedef QValueList<FunctionDom> FunctionList;
201
@class FunctionDefinitionList
202
The list of code model function definitions.
203
This is a type definition: @code typedef QValueList<FunctionDefinitionDom> FunctionDefinitionList; @endcode
207
typedef QValueList<FunctionDefinitionDom> FunctionDefinitionList;
210
The list of code model variables.
211
This is a type definition: @code typedef QValueList<VariableDom> VariableList; @endcode
214
typedef QValueList<VariableDom> VariableList;
218
The list of code model arguments.
219
This is a type definition: @code typedef QValueList<ArgumentDom> ArgumentList; @endcode
222
typedef QValueList<ArgumentDom> ArgumentList;
226
The list of code model enums.
227
This is a type definition: @code typedef QValueList<EnumDom> EnumList; @endcode
230
typedef QValueList<EnumDom> EnumList;
234
The list of code model type aliases.
235
This is a type definition: @code typedef QValueList<TypeAliasDom> TypeAliasList; @endcode
238
typedef QValueList<TypeAliasDom> TypeAliasList;
241
@class EnumeratorList
242
The list of code model enumerators.
243
This is a type definition: @code typedef QValueList<EnumeratorDom> EnumeratorList; @endcode
246
typedef QValueList<EnumeratorDom> EnumeratorList;
249
Iterates through @p lst and creates sorted list of code model item names.
250
Can be used, for example, to get the list of classes in the store:
252
QStringList classList = sortedNameList(codeModel()->globalNamespace()->classList());
254
@param lst The list to iterate.
255
@return Sorted list of code model item names.
257
template <class ItemList>
258
QStringList sortedNameList( const ItemList& lst )
260
QStringList nameList;
262
typename ItemList::ConstIterator it = lst.begin();
263
while( it != lst.end() ){
264
if( !(*it)->name().isEmpty() )
265
nameList << (*it)->name();
274
Casts safe code model pointers (@p KSharedPtr<T> objects like
275
FileDom, NamespaceDom, etc.) to the @p Result type.
279
//ns is of type NamespaceDom
280
ClassDom cl = model_cast<ClassDom>(ns);
282
@param x Object to cast.
284
template <class Result, class T>
285
Result model_cast( KSharedPtr<T> x )
287
Result r( static_cast<T*>(x) );
292
Casts code model pointers (objects like
293
FileModel, NamespaceModel, etc.) to the @p Result type.
297
//ns is of type NamespaceModel*
298
ClassDom cl = model_cast<ClassDom>(ns);
300
@param x Object to cast.
302
template <class Result, class T>
303
Result model_cast( T* x )
305
Result r( static_cast<T*>(x) );
311
Code Model - a memory symbol store.
312
Symbol store (aka class store) is a database of symbols
313
found in code with the important information about those symbols.
315
For example, programming language support plugins use symbol store
316
to remember information about classes, functions, etc. For each type
317
of symbol a certain information can be stored - symbol name, the
318
location in source file, etc.
320
@sa codemodel.h documentation for a list of typedefs and other convenience functions.
322
@sa codemodel_utils.h documentation for an additional code model utility functions and classes reference.
330
virtual ~CodeModel();
332
/**Creates a code model item. This should be used to create
335
For example, to create a class model somewhere in your plugin, use:
337
klass = codeModel()->create<ClassModel>();
338
klass->setName("ClassName");
339
klass->setFileName("FileName");
340
klass->setStartPosition(line, column);
342
@return Created code model item.*/
343
template <class T> typename T::Ptr create()
345
typename T::Ptr ptr( new T(this) );
349
/**Resets the CodeModel.*/
352
/**Gets the list of files in the store.
353
@return The FileList object that contains the list of files.*/
356
/**Gets the list of files in the store.
357
This is a const version for convenience.
358
@return The FileList object that contains the list of files.*/
359
const FileList fileList() const;
361
/**Checks to see if a file is in the store.
362
@return true if @p name is in the file list.*/
363
bool hasFile( const QString& name ) const;
365
/**Gets the FileDom object for a file.
366
@param name The name of the file to get the FileDom object for.*/
367
FileDom fileByName( const QString& name );
369
/**Gets the FileDom object for a file.
370
This is a const version provided for convenience.
371
@param name the name of the file to get the FileDom object for.*/
372
const FileDom fileByName( const QString& name ) const;
374
/**Adds a file to the store.
375
@param file The FileDom object to add to the store.
376
@return true if the file was added successfully.*/
377
bool addFile( FileDom file );
379
/**Removes a file from the store.
380
@param file the FileDom object to remove from the store.*/
381
void removeFile( FileDom file );
383
/**Gets the global namespace
384
@return The NamespaceDom object that represents the global namespace.*/
385
const NamespaceDom globalNamespace() const;
387
/**Reads the model from a stream.
388
Use this to save the memory symbol store to a file.
390
Language support plugins usually save symbols from projects before the project is
391
closed to avoid reparsing when the project is opened next time.
392
@param stream Stream to read from.
393
@return whether the read succeeded(may fail when the store-format is deprecated).*/
394
virtual void read( QDataStream& stream );
395
/**Writes the model to a stream.
396
Use this to restore the memory symbol store to a file.
398
Language support plugins usually save symbols from projects before the project is
399
closed to avoid reparsing when the project is opened next time.
400
@param stream Stream to write to.*/
401
virtual void write( QDataStream& stream ) const;
403
/** this will dump the whole tree into dot-file-format so it can be inspected, not ready yet*/
404
virtual void dump( std::ostream& file, QString Info="" );
406
/** Merges two groups, by changing the group-ids of the files.
407
Returns the id of the new group, or 0 on fail.
408
@param g1 first group
409
@param g2 second group */
410
int mergeGroups( int g1, int g2 );
412
/** Returns all files within the given group
413
it should be preferred calling FileModel::wholeGroup and
414
FileModel::wholeGroupStrings because those return in constant
415
time if they are the only member of the group */
416
FileList getGroup( int gid ) const;
418
FileList getGroup( const FileDom& file) const;
420
/** Same as above, but returns the names instead of the objects */
421
virtual QStringList getGroupStrings( int gid ) const;
424
/**Adds a namespace to the store.
425
@param target The NamespaceDom object that the namespace will be added to.
426
@param source The NamespaceDom object that contains the namespace to remove.*/
427
void addNamespace( NamespaceDom target, NamespaceDom source );
429
/**Removes a namespace from the store.
430
@param target The NamespaceDom object that the namespace will be removed from.
431
@param source The NamespaceDom object that contains the namespace to remove.*/
432
void removeNamespace( NamespaceDom target, NamespaceDom source );
435
QMap<QString, FileDom> m_files;
436
NamespaceDom m_globalNamespace;
438
virtual int newGroupId();
439
///the groups were introduced to represent dependencies between different files.
440
///Files can have slaves that are owned by other files within the same group.
441
///While parsing, whole groups should always be parsed/reparsed together.
442
int m_currentGroupId; ///normally, each file has its own group.
445
CodeModel( const CodeModel& source );
446
void operator = ( const CodeModel& source );
447
friend class CodeModelItem;
448
friend class FileModel;
453
Item in code model (symbol store).
454
Item is a symbol in a store. Code model provides several predefined classes
455
for predefined item types (files, namespaces, classes, functions and function definitions,
456
variables, arguments, enums and enumerators, type aliases.
458
Instances of this class should be created using @ref CodeModel::create method but usually
459
it is better to create instances of derived classes like ClassModel, NamespaceModel, FileModel, etc.
461
class CodeModelItem: public KShared
464
/**A definition of safe pointer to the code model item.*/
467
/**A type of a code model item.*/
471
Namespace, /**<Namespace.*/
473
Function, /**<Function or class method.*/
474
Variable, /**<Variable.*/
475
Argument, /**<Function or method parameter.*/
476
FunctionDefinition, /**<Function definition.*/
478
Enumerator, /**<Enumerator - a member of an Enum (example: @code enum Type { A, B, C} @endcode
479
Type will be an Enum; A, B and C - Enumerators.*/
480
TypeAlias, /**<Type alias (aka typedef in c++).*/
482
Custom = 1000 /**<Custom model items should have type greater than 1000*/
485
/**An access to the code model item.*/
488
Public, /**<Public.*/
489
Protected, /**<Protected.*/
490
Private /**<Private.*/
492
void update( const CodeModelItem* i );
493
bool canUpdate( const CodeModelItem* i ) const;
497
@param kind The type, see also @ref CodeModelItem::Kind.
498
@param model Code model which stores this item.*/
499
CodeModelItem( int kind, CodeModel* model );
503
virtual ~CodeModelItem();
505
/**@return The type (kind) of item.*/
506
int kind() const { return m_kind; }
508
/**Sets the type (kind) of item.
509
@param kind The type, see also @ref CodeModelItem::Kind.*/
510
void setKind( int kind ) { m_kind = kind; }
512
/**@return The name of the item.*/
513
QString name() const;
515
QString comment() const {
519
void setComment( QString comment ) {
523
/**Sets the name of the item.
524
@param name The name.*/
525
void setName( const QString& name );
527
/**Gets the file of the item.
528
@return The FileDom object for the item.*/
531
/**Gets the file of the item
532
This is a const version provided for convenience.
533
@return The FileDom object for the item.*/
534
const FileDom file() const;
536
/**@return The filename of the item.*/
537
QString fileName() const;
539
/**Sets the filename of the item.
540
@param fileName The file name.*/
541
void setFileName( const QString& fileName );
543
/**Gets the start position of the item.
544
@param line Will be set to the line number of the items start position. Pass 0 if line number is not necessary.
545
@param col Will be set to the column number of the items start position. Pass 0 if column number is not necessary.*/
546
void getStartPosition( int* line, int* col ) const;
548
/**Sets the start position of the item.
549
@param line Line number.
550
@param col Column number.*/
551
void setStartPosition( int line, int col );
553
/**Get the end position of the item.
554
@param line Will be set to the line number of the items end position. Pass 0 if line number is not necessary.
555
@param col Will be set to the column number of the items end position. Pass 0 if column number is not necessary.*/
556
void getEndPosition( int* line, int* col ) const;
558
/**Set the end position of the item.
559
@param line Line number.
560
@param col Column number.*/
561
void setEndPosition( int line, int col );
563
/**@return true if an item is a FileModel.*/
564
virtual bool isFile() const { return false; }
565
/**@return true if an item is a NamespaceModel.*/
566
virtual bool isNamespace() const { return false; }
567
/**@return true if an item is a ClassModel.*/
568
virtual bool isClass() const { return false; }
569
/**@return true if an item is a FunctionModel.*/
570
virtual bool isFunction() const { return false; }
571
/**@return true if an item is a FileDefinitionModel.*/
572
virtual bool isFunctionDefinition() const { return false; }
573
/**@return true if an item is a VariableModel.*/
574
virtual bool isVariable() const { return false; }
575
/**@return true if an item is an ArgumentModel.*/
576
virtual bool isArgument() const { return false; }
577
/**@return true if an item is a EnumModel.*/
578
virtual bool isEnum() const { return false; }
579
/**@return true if an item is a EnumeratorModel.*/
580
virtual bool isEnumerator() const { return false; }
581
/**@return true if an item is a TypeAliasModel.*/
582
virtual bool isTypeAlias() const { return false; }
583
/**@return true if an item is a custom item.*/
584
virtual bool isCustom() const { return false; }
586
virtual bool isTemplateable() const { return false; }
588
/**Reads an item from the stream.
589
@param stream The stream to read from.*/
590
virtual void read( QDataStream& stream );
591
/**Writes an item to the stream.
592
@param stream The stream to write to.*/
593
virtual void write( QDataStream& stream ) const;
595
virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
597
/**@return The code model for this item.*/
598
CodeModel* codeModel() { return m_model; }
600
/**@note This is a const version provided for convenience.
601
@return The code model for this item*/
602
const CodeModel* codeModel() const { return m_model; }
609
QString m_comment; ///not stored yet
610
int m_startLine, m_startColumn;
611
int m_endLine, m_endColumn;
614
CodeModelItem( const CodeModelItem& source );
615
void operator = ( const CodeModelItem& source );
620
class TemplateModelItem {
622
typedef QPair< QString, QString > ParamPair;
623
typedef QValueVector< ParamPair > ParamMap; ///The first is the name, and the second the default-parameter, or "" if there is none.
625
virtual const ParamMap& getTemplateParams() {
629
virtual void addTemplateParam( QString name, QString def = "" ) {
630
m_params.push_back( ParamPair( name, def ) );
633
virtual void clearTemplateParams() {
637
bool hasSpecializationDeclaration() const {
638
return !m_specialization.isEmpty();
641
virtual QString getSpecializationDeclaration() const {
642
return m_specialization;
645
void setSpecializationDeclaration( const QString& str ) {
646
m_specialization = str;
649
///returns -1 if the parameter does not exist
650
virtual int findTemplateParam( const QString& name ) const {
651
for( unsigned int a = 0; a< m_params.size(); a++)
652
if( m_params[a].first == name ) return a;
656
const ParamPair getParam( int index ) const {
657
return m_params[index];
660
virtual bool isTemplateable() const { return true; }
662
void write( QDataStream & stream ) const {
663
stream << m_specialization;
664
stream << (int)m_params.size();
665
for( ParamMap::const_iterator it = m_params.begin(); it != m_params.end(); ++it ) {
666
stream << (*it).first;
667
stream << (*it).second;
671
void read( QDataStream & stream ) {
673
stream >> m_specialization;
675
for( int a = 0; a < count; a++ ) {
678
stream >> tmp.second;
679
m_params.push_back( tmp );
685
QString m_specialization;
692
Represents a class in the code model.
694
Instances of this class should be created using @ref CodeModel::create method.
696
class ClassModel: public CodeModelItem, public TemplateModelItem
700
@param model Code model which stores this item.*/
701
ClassModel( CodeModel* model );
704
/**A definition of safe pointer to the class model.*/
705
typedef ClassDom Ptr;
707
virtual bool isClass() const { return true; }
709
/**@return The scope of the class. Scope is a string list composed from names of parent classes and namespaces.*/
710
QStringList scope() const { return m_scope; }
711
/**Sets the scope of this class.
712
@param scope The scope - a list of parent classes and namespaces.*/
713
void setScope( const QStringList& scope ) { m_scope = scope; }
715
/**@return The list of base class names.*/
716
QStringList baseClassList() const;
718
/**Adds a base class to the list of base classes.
719
@param baseClass The base class name.*/
720
bool addBaseClass( const QString& baseClass );
722
/**Removes a base class from the list of base classes.
723
@param baseClass The base class name.*/
724
void removeBaseClass( const QString& baseClass );
726
/**@return The list of (sub)classes in this model.*/
727
ClassList classList();
729
/**@note This is a const version provided for convenience.
730
@return The list of (sub)classes in this model.*/
731
const ClassList classList() const;
733
/**Checks if the class specified by @p name is in this model.
734
@param name The name of a class to look for.
735
@return true if the model has a class.*/
736
bool hasClass( const QString& name ) const;
738
/**@param name The name of a class.
739
@return A list of classes that match the name given by @p name.*/
740
ClassList classByName( const QString& name );
742
/**@param name The name of a class.
743
@return A list of classes that match the name given by @p name.
744
@note This is a const version provided for convenience.*/
745
const ClassList classByName( const QString& name ) const;
747
/**Adds a class to the model.
748
@param klass The class model to add.
749
@return true if addition was successful.*/
750
bool addClass( ClassDom klass );
752
/**Removes a class from the model.
753
@param klass The class model to remove.*/
754
void removeClass( ClassDom klass );
756
/**@return A list of functions in the model.*/
757
FunctionList functionList();
759
/**@return A list of functions in the model.
760
@note This is a const version provided for convenience.*/
761
const FunctionList functionList() const;
763
/**Check if the function specified by @p name is in the model.
764
@param name The name of a function to look for.
765
@return true if the model has a class.*/
766
bool hasFunction( const QString& name ) const;
768
/**@param name The name of a function to look for.
769
@return A list of functions that match the name given by @p name.*/
770
FunctionList functionByName( const QString& name );
772
/**@param name The name of a function to look for.
773
@return A list of functions that match the name given by @p name.
774
@note This is a const version provided for convenience.*/
775
const FunctionList functionByName( const QString& name ) const;
777
/**Adds a function to the class model.
778
@param fun The function model to add.
779
@return true if addition was successful.*/
780
bool addFunction( FunctionDom fun );
782
/**Removes a function from the class model.
783
@param fun The FunctionDom object to remove from the model.*/
784
void removeFunction( FunctionDom fun );
786
/**@return The list of function definitions in the model.*/
787
FunctionDefinitionList functionDefinitionList();
789
/**@return The list of function definitions
790
@note This is a const version provided for convenience.*/
791
const FunctionDefinitionList functionDefinitionList() const;
793
/**Checks if the function definition specified by \p name is in the model.
794
@param name The name of a function definition to look for.
795
@return true if the function definition was found.*/
796
bool hasFunctionDefinition( const QString& name ) const;
798
/**Gets the list of functions that match the name given by \p name.
799
If there are no matches, then the list returned is empty.
800
@param name The name of a function definition to look for.
801
@return The FunctionDefinitionList object containing the definitions that match.*/
802
FunctionDefinitionList functionDefinitionByName( const QString& name );
804
/**Gets the list of functions that match the name given by \p name.
805
If there are no matches, then the list returned is empty.
806
@param name The name of a function definition to look for.
807
@return The FunctionDefinitionList object containing the definitions that match.
808
@note This is a const version provided for convenience.*/
809
const FunctionDefinitionList functionDefinitionByName( const QString& name ) const;
811
/**Adds a function definition to the model.
812
@param fun The function fefinition model to add to the model.
813
@return true if the addition was successful.*/
814
bool addFunctionDefinition( FunctionDefinitionDom fun );
816
/**Removes a function definition from the model.
817
@param fun The function fefinition model to remove from the model.*/
818
void removeFunctionDefinition( FunctionDefinitionDom fun );
820
/**@return The list of variables in the model.*/
821
VariableList variableList();
823
/**@return The list of variables in the model.
824
@note This is a const version provided for convenience.*/
825
const VariableList variableList() const;
827
/**Checks if the variable specified by @p name is in the model.
828
@param name The name of a variable.
829
@return true if the variable was found.*/
830
bool hasVariable( const QString& name ) const;
832
/**Gets the variable specified by @p name.
833
If there are no matches, then the VariableDom object returned is empty.
834
@param name The name of a variable.
835
@return A VariableDom object that matches the name specified.*/
836
VariableDom variableByName( const QString& name );
838
/**Gets the variable specified by @p name.
839
If there are no matches, then the VariableDom object returned is empty.
840
@param name The name of a variable.
841
@return A VariableDom object that matches the name specified.
842
@note This is a const version provided for convenience.*/
843
const VariableDom variableByName( const QString& name ) const;
845
/**Adds a variable to the model.
846
@param var The variable model to add to the model.
847
@return true if the addition was successful.*/
848
bool addVariable( VariableDom var );
850
/**Removes a variable from the model.
851
@param var The variable model to remove from the model.*/
852
void removeVariable( VariableDom var );
854
/**@return The type alias list for this model.*/
855
TypeAliasList typeAliasList();
857
/**@return The type alias list for this model.
858
@note This is a const version provided for convenience.*/
859
const TypeAliasList typeAliasList() const;
861
/**Checks if the type alias specified by @p name is in the model.
862
@param name The name of a type alias.
863
@return true if the type alias was found.*/
864
bool hasTypeAlias( const QString& name ) const;
866
/**Gets the list of type aliases that match @p name.
867
If there are no matches, the TypeAliasList object is empty.
868
@param name The name of a type alias.
869
@return A TypeAliasList object that contains the matches.*/
870
TypeAliasList typeAliasByName( const QString& name );
872
/**Gets the list of type aliases that match @p name.
873
If there are no matches, the TypeAliasList object is empty.
874
@param name The name of a type alias.
875
@return A TypeAliasList object that contains the matches.
876
@note This is a const version provided for convenience.*/
877
const TypeAliasList typeAliasByName( const QString& name ) const;
879
/**Adds a type alias to the model.
880
@param typeAlias The type alias model to add to the model.
881
@return true if the addition was successful.*/
882
bool addTypeAlias( TypeAliasDom typeAlias );
884
/**Removes a type alias from the model.
885
@param typeAlias The TypeAliasDom object to remove from the model.*/
886
void removeTypeAlias( TypeAliasDom typeAlias );
888
/**@return The list of enums in the model.*/
891
/**@return The list of enums in the model.
892
@note This is a const version provided for convenience.*/
893
const EnumList enumList() const;
895
/**Checks if the enum specified by @p name is in the model.
896
@param name The name of an enum.
897
@return true if the enum was found.*/
898
bool hasEnum( const QString& name ) const;
900
/**Gets the enum specified by @p name.
901
The EnumDom object returned will be empty if no match is found.
902
@param name The name of an enum.
903
@return The EnumDom object that contains the match.*/
904
EnumDom enumByName( const QString& name );
906
/**Gets the enum specified by @p name.
907
The EnumDom object returned will be empty if no match is found.
908
@param name The name of an enum.
909
@return The EnumDom object that contains the match.*/
910
const EnumDom enumByName( const QString& name ) const;
912
/**Adds an enum to the model.
913
@param e The enum model to add to the model.
914
@return true if the addition was successful.*/
915
bool addEnum( EnumDom e );
917
/**Removes an enum from the model.
918
@param e The enum model to remove from the model.*/
919
void removeEnum( EnumDom e );
921
void update( const ClassModel* i );
922
bool canUpdate( const ClassModel* i ) const;
924
virtual void read( QDataStream& stream );
925
virtual void write( QDataStream& stream ) const;
927
virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
931
QStringList m_baseClassList;
932
QMap<QString, ClassList> m_classes;
933
QMap<QString, FunctionList> m_functions;
934
QMap<QString, FunctionDefinitionList> m_functionDefinitions;
935
QMap<QString, VariableDom> m_variables;
936
QMap<QString, TypeAliasList> m_typeAliases;
937
QMap<QString, EnumDom> m_enumerators;
940
ClassModel( const ClassModel& source );
941
void operator = ( const ClassModel& source );
942
friend class CodeModel;
945
class NamespaceAliasModel {
947
virtual void read( QDataStream& stream );
948
virtual void write( QDataStream& stream ) const;
950
QString name() const {
954
void setName( const QString& name ) {
958
void setAliasName( const QString& theValue ) {
959
m_aliasName = theValue;
962
QString aliasName() const {
966
void setFileName( const HashedString& theValue ) {
967
m_fileName = theValue;
970
HashedString fileName() const {
974
bool operator < ( const NamespaceAliasModel& rhs ) const {
975
if( m_name < rhs.m_name ) return true;
976
if( m_name == rhs.m_name ) {
977
if( m_aliasName < rhs.m_aliasName ) return true;
978
if( m_aliasName == rhs.m_aliasName && m_fileName < rhs.m_fileName ) return true;
983
bool operator == ( const NamespaceAliasModel& rhs ) const {
984
return m_name == rhs.m_name && m_aliasName == rhs.m_aliasName && m_fileName == rhs.m_fileName;
990
HashedString m_fileName;
993
class NamespaceImportModel {
995
virtual void read( QDataStream& stream );
996
virtual void write( QDataStream& stream ) const;
998
QString name() const {
1002
HashedString fileName() const {
1006
void setName( const QString& name ) {
1010
void setFileName( const HashedString& file ) {
1014
bool operator < ( const NamespaceImportModel& rhs ) const {
1015
if( m_name < rhs.m_name ) return true;
1016
if( m_name == rhs.m_name )
1017
if( m_fileName < rhs.m_fileName ) return true;
1022
bool operator == ( const NamespaceImportModel& rhs ) const {
1023
return m_name == rhs.m_name && m_fileName == rhs.m_fileName;
1028
HashedString m_fileName;
1033
Represents a namespace in the code model.
1034
Namespace model can represent either usual c++ namespaces
1035
and packages or modules from other languages.
1037
Instances of this class should be created using @ref CodeModel::create method.
1039
class NamespaceModel: public ClassModel
1043
@param model Code model which stores this item.*/
1044
NamespaceModel( CodeModel* model );
1047
typedef std::set<NamespaceAliasModel> NamespaceAliasModelList; ///I'm using std-sets here, because Qt-3 has no appropriate replacement
1048
typedef std::set<NamespaceImportModel> NamespaceImportModelList;
1050
/**A definition of safe pointer to the namespace model.*/
1051
typedef NamespaceDom Ptr;
1053
virtual bool isClass() const { return false; }
1054
virtual bool isNamespace() const { return true; }
1056
/**@return The list of namespaces in this model.*/
1057
NamespaceList namespaceList();
1059
/**@return The list of namespaces in this model.
1060
@note This is a const version provided for convenience.*/
1061
const NamespaceList namespaceList() const;
1063
/**Checks if the namespace referenced by @p name is in the model.
1064
@param name The name of a namespace.
1065
@return true if the namespace was found.*/
1066
bool hasNamespace( const QString& name ) const;
1068
/**Gets the namespace specified by @p name.
1069
If there are no matches, then the NamespaceDom object returned is empty.
1070
@param name The name of a namespace.
1071
@return The NamespaceDom object that contains the match.*/
1072
NamespaceDom namespaceByName( const QString& name );
1074
/**Gets the namespace specified by @p name.
1075
If there are no matches, then the NamespaceDom object returned is empty.
1076
@param name The name of a namespace.
1077
@return The NamespaceDom object that contains the match.
1078
@note This is a const version provided for convenience.*/
1079
const NamespaceDom namespaceByName( const QString& name ) const;
1081
/**Adds a namespace to the model.
1082
@param ns The namespace model to add to the model.
1083
@return true if addition was successful.*/
1084
bool addNamespace( NamespaceDom ns );
1086
/**Removes the namespace from the model.
1087
@param ns The namespace model to remove from the model.*/
1088
void removeNamespace( NamespaceDom ns );
1090
/**Updates this model so it has the same content as the other one. Only the line/column is updated. canUpdate(..) must be tested before.
1091
* @param ns the namespace to match
1093
void update( const NamespaceModel* ns );
1094
bool canUpdate( const NamespaceModel* ns ) const;
1096
virtual void read( QDataStream& stream );
1097
virtual void write( QDataStream& stream ) const;
1099
virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1101
void addNamespaceImport( const NamespaceImportModel& import );
1102
void addNamespaceAlias( const NamespaceAliasModel& alias );
1103
void removeNamespaceImport( const NamespaceImportModel& import );
1104
void removeNamespaceAlias( const NamespaceAliasModel& alias );
1106
///Must not be called on temporary objects because a reference is returned(for performance-reasons)
1107
const NamespaceAliasModelList& namespaceAliases() const {
1108
return m_namespaceAliases;
1111
///Must not be called on temporary objects because a reference is returned(for performance-reasons)
1112
const NamespaceImportModelList& namespaceImports() const {
1113
return m_namespaceImports;
1116
QMap<QString, NamespaceDom> m_namespaces;
1117
NamespaceAliasModelList m_namespaceAliases;
1118
NamespaceImportModelList m_namespaceImports;
1122
NamespaceModel( const NamespaceModel& source );
1123
void operator = ( const NamespaceModel& source );
1124
friend class CodeModel;
1132
Represents a file in the code model.
1133
Files in general contain classes, namespaces, functions,
1134
types, etc. Therefore FileModel is derived from NamespaceModel.
1136
Instances of this class should be created using @ref CodeModel::create method.
1138
class FileModel: public NamespaceModel
1142
@param model Code model which stores this item.*/
1143
FileModel( CodeModel* model );
1146
/**A definition of safe pointer to the file model.*/
1147
typedef FileDom Ptr;
1149
virtual bool isFile() const { return true; }
1151
virtual int groupId() const {
1155
virtual void setGroupId(int newId) {
1159
/** This function additionally does version-checking and
1160
should be used instead of read when read should be called
1162
@return whether the read was successful */
1164
virtual void write( QDataStream& stream ) const;
1166
FileList wholeGroup() ;
1168
QStringList wholeGroupStrings() const;
1170
virtual void read( QDataStream& stream );
1172
ParseResultPointer parseResult() const;
1173
void setParseResult( const ParseResultPointer& result );
1175
void update( const FileModel* i );
1178
ParseResultPointer m_parseResult;
1179
FileModel( const FileModel& );
1180
void operator = ( const FileModel& );
1181
friend class CodeModel;
1186
Function (procedure) argument model.
1187
Represents an argument in the function.
1189
Instances of this class should be created using @ref CodeModel::create method.
1191
class ArgumentModel: public CodeModelItem
1194
ArgumentModel( CodeModel* model );
1197
/**A definition of safe pointer to the argument model.*/
1198
typedef ArgumentDom Ptr;
1200
virtual bool isArgument() const { return true; }
1202
/**@return The type of this argument.*/
1203
QString type() const;
1205
/**Sets the type of this argument.
1206
@param type The type to set.*/
1207
void setType( const QString& type );
1209
/**@return The default value of this argument.*/
1210
QString defaultValue() const;
1212
/**Sets the default value of this argument.
1213
@param defaultValue The default value to set.*/
1214
void setDefaultValue( const QString& defaultValue );
1216
virtual void read( QDataStream& stream );
1217
virtual void write( QDataStream& stream ) const;
1219
virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1223
QString m_defaultValue;
1226
ArgumentModel( const ArgumentModel& source );
1227
void operator = ( const ArgumentModel& source );
1228
friend class CodeModel;
1239
In languages that have separate function declarations and definitions (c++)
1240
this represents only function declarations. @see FunctionDefinitionModel
1241
for a model of function definitions.
1243
Instances of this class should be created using @ref CodeModel::create method.
1245
class FunctionModel: public CodeModelItem, public TemplateModelItem
1249
@param model Code model which stores this item.*/
1250
FunctionModel( CodeModel* model );
1253
/**A definition of safe pointer to the function model.*/
1254
typedef FunctionDom Ptr;
1256
virtual bool isFunction() const { return true; }
1258
/**@return The scope of the function. Scope is a string list composed
1259
from names of parent functions, classes and namespaces.*/
1260
QStringList scope() const { return m_scope; }
1262
/**Sets the scope of the function.
1263
@param scope The scope to set.*/
1264
void setScope( const QStringList& scope ) { m_scope = scope; }
1266
/**@return The access level of the function. Can return either values of type @ref CodeModelItem::Access or
1267
other integers if the function has other access level (for example pascal methods can have "published"
1271
/**Sets the access level of the function.
1272
@param access The access level.*/
1273
void setAccess( int access );
1275
/**@return true if the function is a signal.*/
1276
bool isSignal() const;
1277
/**Sets the function to be a signal.
1278
@param isSignal The signal flag.*/
1279
void setSignal( bool isSignal );
1281
/**@return true if the function is a slot.*/
1282
bool isSlot() const;
1283
/**Sets the function to be a slot.
1284
@param isSlot The slot flag.*/
1285
void setSlot( bool isSlot );
1287
/**@return true if the function is a virtual function.*/
1288
bool isVirtual() const;
1289
/**Sets the function to be a virtual function.
1290
@param isVirtual The virtual flag.*/
1291
void setVirtual( bool isVirtual );
1293
/**@return true if the function is a static function.*/
1294
bool isStatic() const;
1295
/**Sets the function to be a static function.
1296
@param isStatic The static flag.*/
1297
void setStatic( bool isStatic );
1299
/**@return true if the function is an inline function.*/
1300
bool isInline() const;
1301
/**Sets the function to be an inline function.
1302
@param isInline The inline flag.*/
1303
void setInline( bool isInline );
1305
/**@return true if the function is a constant function.*/
1306
bool isConstant() const;
1307
/**Sets the function to be a constant function.
1308
@param isConstant The constant flag.*/
1309
void setConstant( bool isConstant );
1311
/**@return true if the function is an abstract function.*/
1312
bool isAbstract() const;
1313
/**Sets the function to be an inline function.
1314
@param isAbstract The abstract flag.*/
1315
void setAbstract( bool isAbstract );
1317
/**@return The result type of a function.*/
1318
QString resultType() const;
1319
/**Sets the result type of a function.
1320
@param type The type of a function result.*/
1321
void setResultType( const QString& type );
1323
/**Gets the list of arguments being passed to the function.
1324
If there are no arguments, then the list is empty.
1325
@return The ArgumentList object that contains the arguments for this function.*/
1326
ArgumentList argumentList();
1328
/**Gets the list of arguments being passed to the function.
1329
If there are no arguments, then the list is empty.
1330
@return The ArgumentList object that contains the arguments for this function.
1331
@note This is a const version provided for convenience.*/
1332
const ArgumentList argumentList() const;
1334
/**Adds an argument to the function.
1335
@param arg The argument model to add as an argument to the function.
1336
@return true if the addition was successful.*/
1337
bool addArgument( ArgumentDom arg );
1339
/**Removes an argument from the function.
1340
@param arg The argument model to remove from the function.*/
1341
void removeArgument( ArgumentDom arg );
1343
virtual void read( QDataStream& stream );
1344
virtual void write( QDataStream& stream ) const;
1346
virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1348
void update( const FunctionModel* i );
1349
bool canUpdate( const FunctionModel* i ) const;
1352
QStringList m_scope;
1368
QString m_resultType;
1369
ArgumentList m_arguments;
1372
FunctionModel( const FunctionModel& source );
1373
void operator = ( const FunctionModel& source );
1374
friend class CodeModel;
1379
Represents function definition for languages that have such.
1381
Instances of this class should be created using @ref CodeModel::create method.
1383
class FunctionDefinitionModel: public FunctionModel
1387
@param model Code model which stores this item.*/
1388
FunctionDefinitionModel( CodeModel* model );
1391
/**A definition of safe pointer to the function definition model.*/
1392
typedef FunctionDefinitionDom Ptr;
1394
virtual bool isFunctionDefinition() const { return true; }
1397
FunctionDefinitionModel( const FunctionDefinitionModel& source );
1398
void operator = ( const FunctionDefinitionModel& source );
1399
friend class CodeModel;
1405
Represents variables and class attributes.
1407
Instances of this class should be created using @ref CodeModel::create method.
1409
class VariableModel: public CodeModelItem
1413
@param model Code model which stores this item.*/
1414
VariableModel( CodeModel* model );
1417
/**A definition of safe pointer to the variable model.*/
1418
typedef VariableDom Ptr;
1420
virtual bool isVariable() const { return true; }
1422
/**@return The access level of the variable. Can return either values of type @ref CodeModelItem::Access or
1423
other integers if the variable has other access level (for example pascal attributes can have "published"
1426
/**Sets the access level of the variable.
1427
@param access The access level.*/
1428
void setAccess( int access );
1430
/**@return true if the variable is a static variable.*/
1431
bool isStatic() const;
1432
/**Sets the variable to be a static variable.
1433
@param isStatic The static flag.*/
1434
void setStatic( bool isStatic );
1436
/**@return A type of the variable.*/
1437
QString type() const;
1438
/**Sets the type of the variable.
1439
@param type The type name.*/
1440
void setType( const QString& type );
1442
/**@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. */
1443
bool isEnumeratorVariable() const;
1445
void setEnumeratorVariable( bool b );
1447
virtual void read( QDataStream& stream );
1448
virtual void write( QDataStream& stream ) const;
1450
virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1452
void update( const VariableModel* i );
1453
bool canUpdate( const VariableModel* i ) const;
1459
int m_isEnumeratorVariable;
1462
VariableModel( const VariableModel& source );
1463
void operator = ( const VariableModel& source );
1464
friend class CodeModel;
1472
Instances of this class should be created using @ref CodeModel::create method.
1474
class EnumModel: public CodeModelItem
1478
@param model Code model which stores this item.*/
1479
EnumModel( CodeModel* model );
1482
/**A definition of safe pointer to the enum model.*/
1483
typedef EnumDom Ptr;
1485
virtual bool isEnum() const { return true; }
1487
/**@return The access level of the enum. Can return either values
1488
of type @ref CodeModelItem::Access or other integers if the enum has other access level.*/
1490
/**Sets the access level of the enum.
1491
@param access The access level.*/
1492
void setAccess( int access );
1494
/**@return The list of enumerators in this enum.*/
1495
EnumeratorList enumeratorList();
1496
/**@return The list of enumerators in this enum.
1497
@note This is a const version provided for convenience.*/
1498
const EnumeratorList enumeratorList() const;
1499
/**Adds an enumerator to the model.
1500
@param e The enumerator model to add.*/
1501
void addEnumerator( EnumeratorDom e );
1502
/**Removes an enumerator from the model.
1503
@param e The enumerator model to remove.*/
1504
void removeEnumerator( EnumeratorDom e );
1506
virtual void read( QDataStream& stream );
1507
virtual void write( QDataStream& stream ) const;
1509
///The dump-function is not ready yet
1510
virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1512
void update( const EnumModel* i );
1513
bool canUpdate( const EnumModel* i ) const;
1517
QMap<QString, EnumeratorDom> m_enumerators;
1520
EnumModel( const EnumModel& source );
1521
void operator = ( const EnumModel& source );
1522
friend class CodeModel;
1528
Represents enumerators. Enums consist of enumerators, for example in code:
1530
enum Type { A, B, C};
1532
Type is represented as EnumModel;\n
1533
A, B, C are represented with EnumeratorModel.
1535
Instances of this class should be created using @ref CodeModel::create method.
1537
class EnumeratorModel: public CodeModelItem
1541
@param model Code model which stores this item.*/
1542
EnumeratorModel( CodeModel* model );
1545
/**A definition of safe pointer to the enumerator model.*/
1546
typedef EnumeratorDom Ptr;
1548
virtual bool isEnumerator() const { return true; }
1550
/**@return The value of an enumerator.*/
1551
QString value() const;
1552
/**Sets the value of an enumerator.
1553
@param value The value.*/
1554
void setValue( const QString& value );
1556
virtual void read( QDataStream& stream );
1557
virtual void write( QDataStream& stream ) const;
1559
virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1565
EnumeratorModel( const EnumeratorModel& source );
1566
void operator = ( const EnumeratorModel& source );
1567
friend class CodeModel;
1573
Represents type aliases (like subtypes/derived types in Ada and typedefs in c++).
1575
class TypeAliasModel: public CodeModelItem
1579
@param model Code model which stores this item.*/
1580
TypeAliasModel( CodeModel* model );
1583
/**A definition of safe pointer to the type alias model.*/
1584
typedef TypeAliasDom Ptr;
1586
virtual bool isTypeAlias() const { return true; }
1588
/**@return The actual type of an alias.*/
1589
QString type() const;
1590
/**Sets the type of an alias.
1591
@param type The type name.*/
1592
void setType( const QString& type );
1594
virtual void read( QDataStream& stream );
1595
virtual void write( QDataStream& stream ) const;
1598
virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1600
void update( const TypeAliasModel* i );
1601
bool canUpdate( const TypeAliasModel* i ) const;
1607
TypeAliasModel( const TypeAliasModel& source );
1608
void operator = ( const TypeAliasModel& source );
1609
friend class CodeModel;