Skip to content

Commit 075229e

Browse files
committed
Refactoring: Introduce immutable and mutable interfaces
Split Definition/ClassDef/NamespaceDef/MemberDef into a immutable and mutable part Aliases are immutable, other symbols are stored using an immutable interface but can be made mutable explicitly by dynamic casting.
1 parent 6922d5d commit 075229e

36 files changed

+1514
-1367
lines changed

src/clangparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ void ClangTUParser::linkIdentifier(CodeOutputInterface &ol,FileDef *fd,
696696
p->currentMemberDef && d->definitionType()==Definition::TypeMember &&
697697
(p->currentMemberDef!=d || p->currentLine<line)) // avoid self-reference
698698
{
699-
addDocCrossReference(p->currentMemberDef,dynamic_cast<MemberDef *>(d));
699+
addDocCrossReference(MemberDef::make_mutable(p->currentMemberDef),MemberDef::make_mutable(dynamic_cast<MemberDef *>(d)));
700700
}
701701
writeMultiLineCodeLink(ol,fd,line,column,d,text);
702702
}

src/classdef.cpp

Lines changed: 314 additions & 332 deletions
Large diffs are not rendered by default.

src/classdef.h

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
struct Argument;
3232
class MemberDef;
33+
class MemberDefMutable;
3334
class MemberList;
3435
class MemberDict;
3536
class ClassList;
@@ -52,6 +53,7 @@ struct IncludeInfo;
5253
class ClassDefImpl;
5354
class FTextStream;
5455
class ClassDef;
56+
class ClassDefMutable;
5557

5658
/** Class that contains information about an inheritance relation.
5759
*/
@@ -106,6 +108,7 @@ class ClassDef : virtual public Definition
106108

107109
virtual ~ClassDef() {}
108110

111+
static ClassDefMutable *make_mutable(const ClassDef *);
109112

110113
//-----------------------------------------------------------------------------------
111114
// --- getters
@@ -258,7 +261,7 @@ class ClassDef : virtual public Definition
258261
* available, or 0 otherwise.
259262
* @param name The name of the nested compound
260263
*/
261-
virtual Definition *findInnerCompound(const char *name) const = 0;
264+
virtual const Definition *findInnerCompound(const char *name) const = 0;
262265

263266
/** Returns the template parameter lists that form the template
264267
* declaration of this class.
@@ -355,6 +358,37 @@ class ClassDef : virtual public Definition
355358
virtual bool isSliceLocal() const = 0;
356359
virtual bool hasNonReferenceSuperClass() const = 0;
357360

361+
//-----------------------------------------------------------------------------------
362+
// --- count members ----
363+
//-----------------------------------------------------------------------------------
364+
365+
virtual int countMembersIncludingGrouped(MemberListType lt,
366+
const ClassDef *inheritedFrom,bool additional) const = 0;
367+
virtual int countInheritanceNodes() const = 0;
368+
virtual int countMemberDeclarations(MemberListType lt,const ClassDef *inheritedFrom,
369+
int lt2,bool invert,bool showAlways,QPtrDict<void> *visitedClasses) const = 0;
370+
371+
//-----------------------------------------------------------------------------------
372+
// --- helpers ----
373+
//-----------------------------------------------------------------------------------
374+
375+
virtual ClassDef *insertTemplateInstance(const QCString &fileName,int startLine,int startColumn,
376+
const QCString &templSpec,bool &freshInstance) const = 0;
377+
virtual void writeDeclarationLink(OutputList &ol,bool &found,
378+
const char *header,bool localNames) const = 0;
379+
380+
//-----------------------------------------------------------------------------------
381+
// --- visiting administration ----
382+
//-----------------------------------------------------------------------------------
383+
384+
virtual void setVisited(bool visited) const = 0;
385+
virtual bool isVisited() const = 0;
386+
387+
};
388+
389+
class ClassDefMutable : virtual public DefinitionMutable, virtual public ClassDef
390+
{
391+
public:
358392
//-----------------------------------------------------------------------------------
359393
// --- setters ----
360394
//-----------------------------------------------------------------------------------
@@ -391,8 +425,6 @@ class ClassDef : virtual public Definition
391425
virtual void addTaggedInnerClass(ClassDef *cd) = 0;
392426
virtual void addInnerCompound(const Definition *d) = 0;
393427
virtual bool addExample(const char *anchor,const char *name, const char *file) = 0;
394-
virtual ClassDef *insertTemplateInstance(const QCString &fileName,int startLine,int startColumn,
395-
const QCString &templSpec,bool &freshInstance) const = 0;
396428
virtual void addUsedClass(ClassDef *cd,const char *accessName,Protection prot) = 0;
397429
virtual void addUsedByClass(ClassDef *cd,const char *accessName,Protection prot) = 0;
398430
virtual void makeTemplateArgument(bool b=TRUE) = 0;
@@ -405,7 +437,7 @@ class ClassDef : virtual public Definition
405437
virtual void mergeMembers() = 0;
406438
virtual void sortMemberLists() = 0;
407439
virtual void distributeMemberGroupDocumentation() = 0;
408-
virtual void reclassifyMember(MemberDef *md,MemberType t) = 0;
440+
virtual void reclassifyMember(MemberDefMutable *md,MemberType t) = 0;
409441
virtual void removeMemberFromLists(MemberDef *md) = 0;
410442
virtual void setAnonymousEnumType() = 0;
411443
virtual void countMembers() = 0;
@@ -424,8 +456,6 @@ class ClassDef : virtual public Definition
424456
virtual void writeQuickMemberLinks(OutputList &ol,const MemberDef *md) const = 0;
425457
virtual void writeSummaryLinks(OutputList &ol) const = 0;
426458
virtual void writeInlineDocumentation(OutputList &ol) const = 0;
427-
virtual void writeDeclarationLink(OutputList &ol,bool &found,
428-
const char *header,bool localNames) const = 0;
429459
virtual void writeTagFile(FTextStream &) = 0;
430460
virtual void writeMemberDeclarations(OutputList &ol,MemberListType lt,const QCString &title,
431461
const char *subTitle=0,bool showInline=FALSE,const ClassDef *inheritedFrom=0,
@@ -434,27 +464,14 @@ class ClassDef : virtual public Definition
434464
virtual void addGroupedInheritedMembers(OutputList &ol,MemberListType lt,
435465
const ClassDef *inheritedFrom,const QCString &inheritId) const = 0;
436466

437-
//-----------------------------------------------------------------------------------
438-
// --- count members ----
439-
//-----------------------------------------------------------------------------------
440467

441-
virtual int countMembersIncludingGrouped(MemberListType lt,
442-
const ClassDef *inheritedFrom,bool additional) const = 0;
443-
virtual int countInheritanceNodes() const = 0;
444-
virtual int countMemberDeclarations(MemberListType lt,const ClassDef *inheritedFrom,
445-
int lt2,bool invert,bool showAlways,QPtrDict<void> *visitedClasses) const = 0;
446-
447-
448-
//-----------------------------------------------------------------------------------
449-
// --- visiting administration ----
450-
//-----------------------------------------------------------------------------------
451-
452-
virtual void setVisited(bool visited) const = 0;
453-
virtual bool isVisited() const = 0;
454468
};
455469

470+
inline ClassDefMutable *ClassDef::make_mutable(const ClassDef *cd)
471+
{ return dynamic_cast<ClassDefMutable*>(const_cast<ClassDef*>(cd)); }
472+
456473
/** Factory method to create a new ClassDef object */
457-
ClassDef *createClassDef(
474+
ClassDefMutable *createClassDef(
458475
const char *fileName,int startLine,int startColumn,
459476
const char *name,ClassDef::CompoundType ct,
460477
const char *ref=0,const char *fName=0,

src/classlist.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,17 @@ void ClassSDict::writeDeclaration(OutputList &ol,const ClassDef::CompoundType *f
102102
bool found=FALSE;
103103
for (sdi.toFirst();(cd=sdi.current());++sdi)
104104
{
105+
ClassDefMutable *cdm = ClassDef::make_mutable(cd);
105106
//printf(" ClassSDict::writeDeclaration for %s\n",cd->name().data());
106-
if (!cd->isAnonymous() &&
107+
if (cdm &&
108+
!cd->isAnonymous() &&
107109
!cd->isExtension() &&
108110
(cd->protection()!=Private || extractPrivate) &&
109111
(filter==0 || *filter==cd->compoundType())
110112
)
111113
{
112114
//printf("writeDeclarationLink()\n");
113-
cd->writeDeclarationLink(ol,found,header,localNames);
115+
cdm->writeDeclarationLink(ol,found,header,localNames);
114116
}
115117
}
116118
if (found) ol.endMemberList();
@@ -137,7 +139,9 @@ void ClassSDict::writeDocumentation(OutputList &ol,const Definition * container)
137139
// cd->name().data(),cd->getOuterScope(),cd->isLinkableInProject(),cd->isEmbeddedInOuterScope(),
138140
// container,cd->partOfGroups() ? cd->partOfGroups()->count() : 0);
139141

140-
if (!cd->isAnonymous() &&
142+
ClassDefMutable *cdm = ClassDef::make_mutable(cd);
143+
if (cdm &&
144+
!cd->isAnonymous() &&
141145
cd->isLinkableInProject() &&
142146
cd->isEmbeddedInOuterScope() &&
143147
!cd->isAlias() &&
@@ -154,7 +158,7 @@ void ClassSDict::writeDocumentation(OutputList &ol,const Definition * container)
154158
ol.endGroupHeader();
155159
found=TRUE;
156160
}
157-
cd->writeInlineDocumentation(ol);
161+
cdm->writeInlineDocumentation(ol);
158162
}
159163
}
160164
}

0 commit comments

Comments
 (0)