Skip to content

Commit

Permalink
Write directory dependency graphs recursively.
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Sep 10, 2021
1 parent dc219e4 commit 6d5a075
Show file tree
Hide file tree
Showing 4 changed files with 323 additions and 102 deletions.
8 changes: 8 additions & 0 deletions src/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3847,6 +3847,14 @@ UML notation for the relationships.
option to 1 or 2 may greatly reduce the computation time needed for large
code bases. Also note that the size of a graph can be further restricted by
\ref cfg_dot_graph_max_nodes "DOT_GRAPH_MAX_NODES". Using a depth of 0 means no depth restriction.
]]>
</docs>
</option>
<option type='int' id='MAX_DOT_GRAPH_SUCCESSOR' minval='0' maxval='1000' defval='1' depends='DIRECTORY_GRAPH'>
<docs>
<![CDATA[
The \c MAX_DOT_GRAPH_SUCCESSOR tag can be used to set the maximum number of
levels of child directories generated in directory dependency graphs by \c dot.
]]>
</docs>
</option>
Expand Down
40 changes: 29 additions & 11 deletions src/dirdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DirDefImpl : public DefinitionMixin<DirDef>
virtual void setParent(DirDef *parent);
virtual void setLevel();
virtual void addUsesDependency(const DirDef *usedDir,const FileDef *srcFd,
const FileDef *dstFd,bool inherited);
const FileDef *dstFd,const bool inheritedByDependent, const bool inheritedByDependee);
virtual void computeDependencies();

public:
Expand Down Expand Up @@ -631,7 +631,7 @@ void DirDefImpl::setLevel()
* that was caused by a dependency on file \a fd.
*/
void DirDefImpl::addUsesDependency(const DirDef *dir,const FileDef *srcFd,
const FileDef *dstFd,bool inherited)
const FileDef *dstFd,const bool inheritedByDependent, const bool inheritedByDependee)
{
if (this==dir) return; // do not add self-dependencies
//static int count=0;
Expand All @@ -650,7 +650,7 @@ void DirDefImpl::addUsesDependency(const DirDef *dir,const FileDef *srcFd,
if (usedPair==0) // new file dependency
{
//printf(" => new file\n");
usedDir->addFileDep(srcFd,dstFd);
usedDir->addFileDep(srcFd,dstFd, inheritedByDependent, inheritedByDependee);
added=TRUE;
}
else
Expand All @@ -661,8 +661,8 @@ void DirDefImpl::addUsesDependency(const DirDef *dir,const FileDef *srcFd,
else // new directory dependency
{
//printf(" => new file\n");
auto newUsedDir = std::make_unique<UsedDir>(dir,inherited);
newUsedDir->addFileDep(srcFd,dstFd);
auto newUsedDir = std::make_unique<UsedDir>(dir);
newUsedDir->addFileDep(srcFd,dstFd, inheritedByDependent, inheritedByDependee);
usedDir = m_usedDirs.add(dir->getOutputFileBase(),std::move(newUsedDir));
added=TRUE;
}
Expand All @@ -671,12 +671,17 @@ void DirDefImpl::addUsesDependency(const DirDef *dir,const FileDef *srcFd,
if (dir->parent())
{
// add relation to parent of used dir
addUsesDependency(dir->parent(),srcFd,dstFd,inherited);
addUsesDependency(
dir->parent(),
srcFd,
dstFd,
inheritedByDependent,
true);
}
if (parent())
{
// add relation for the parent of this dir as well
parent()->addUsesDependency(dir,srcFd,dstFd,TRUE);
parent()->addUsesDependency(dir, srcFd, dstFd, true, inheritedByDependee);
}
}
}
Expand All @@ -701,7 +706,7 @@ void DirDefImpl::computeDependencies()
// add dependency: thisDir->usedDir
//static int count=0;
//printf(" %d: add dependency %s->%s\n",count++,qPrint(name()),qPrint(usedDir->name()));
addUsesDependency(usedDir,fd,ii.fileDef,FALSE);
addUsesDependency(usedDir,fd,ii.fileDef,false, false);
}
}
}
Expand Down Expand Up @@ -735,18 +740,22 @@ bool DirDefImpl::depGraphIsTrivial() const

//----------------------------------------------------------------------

UsedDir::UsedDir(const DirDef *dir,bool inherited) :
m_dir(dir), m_inherited(inherited)
UsedDir::UsedDir(const DirDef *dir) :
m_dir(dir), m_SODO(false), m_SODI(false), m_SIDO(false), m_SIDI(false)
{
}

UsedDir::~UsedDir()
{
}

void UsedDir::addFileDep(const FileDef *srcFd,const FileDef *dstFd)
void UsedDir::addFileDep(const FileDef *srcFd,const FileDef *dstFd, const bool isInheritedByDependent, const bool isInheritedByDependee)
{
m_filePairs.add(FilePair::key(srcFd,dstFd),std::make_unique<FilePair>(srcFd,dstFd));
m_SODO = m_SODO || (!isInheritedByDependent && !isInheritedByDependee);
m_SODI = m_SODI || (!isInheritedByDependent && isInheritedByDependee);
m_SIDO = m_SIDO || (isInheritedByDependent && !isInheritedByDependee);
m_SIDI = m_SIDI || (isInheritedByDependent && isInheritedByDependee);
}

void UsedDir::sort()
Expand Down Expand Up @@ -1113,3 +1122,12 @@ const DirDef *toDirDef(const Definition *d)
}
}

bool UsedDir::isAllDependentsInherited() const
{
return !(m_SODI || m_SODO);
}

bool UsedDir::isAllDependeesInherited(const bool checkAlsoInheritedDependents) const
{
return !(m_SODO || (checkAlsoInheritedDependents && m_SIDO));
}
55 changes: 50 additions & 5 deletions src/dirdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,64 @@ class FilePairLinkedMap : public LinkedMap<FilePair>
class UsedDir
{
public:
UsedDir(const DirDef *dir,bool inherited);
UsedDir(const DirDef *dir);
virtual ~UsedDir();
void addFileDep(const FileDef *srcFd,const FileDef *dstFd);

/**
* Take up dependency between files.
* @param[in] srcFd dependent file which depends on dstFd
* @param[in] dstFd dependee file on which srcFd depends on
* @param isInheritedByDependent true if dependency was inherited by dependent
* @param isInheritedByDependee true if dependency was inherited by dependee
*/
void addFileDep(const FileDef *srcFd,const FileDef *dstFd, const bool isInheritedByDependent, const bool isInheritedByDependee);
FilePair *findFilePair(const QCString &name);
const FilePairLinkedMap &filePairs() const { return m_filePairs; }
const DirDef *dir() const { return m_dir; }
bool inherited() const { return m_inherited; }
/** @return true if all file dependencies were inherited by their dependents */
bool isAllDependentsInherited() const;

/**
* Checks if all the file dependencies where inherited by the dependees.
* @param checkAlsoInheritedDependents if true, also those dependencies, which have been inherited
* by dependents are considered
* @return true if all file dependencies were inherited by their dependees
*/
bool isAllDependeesInherited(const bool checkAlsoInheritedDependents) const;
void sort();

private:
const DirDef *m_dir;
FilePairLinkedMap m_filePairs;
bool m_inherited;

/**
* @name Markers for directory dependency inheritance
*
* These markers are required for evaluation, if a dependency between directories
* shall be drawn at a certain level within the directory dependency graph.
*
* The dependent (*source*) depends on the dependee (*destination*).
*
* The dependency from the dependent directory (has a list containing this used
* directory) and dependee directory (m_dir) may be inherited by the successors
* of the dependent or the dependee. Only in case, the original directory is
* truncated in the graph, the next drawn inheritor directory is used as node
* for the relation.
*
* In order to properly graph the directory dependencies for more than one level
* of successors, it is necessary to record the *combination* of inheritance by
* dependent and inheritance by dependee. It is not sufficient to only record
* the individual inheritance.
*
* As it is sufficient to know if a combination exists in one of the file pairs,
* that information is accumulated when adding file dependencies.
*/
///@{
bool m_SODO; //!< dependency is neither inherited by dependent nor by dependee
bool m_SODI; //!< dependency is not inherited by dependent but by dependee
bool m_SIDO; //!< dependency is inherited by dependent but not by dependee
bool m_SIDI; //!< dependency is inherited by dependent and by dependee
///@}
};

// ------------------
Expand Down Expand Up @@ -119,7 +164,7 @@ class DirDef : public DefinitionMutable, public Definition
virtual void setParent(DirDef *parent) = 0;
virtual void setLevel() = 0;
virtual void addUsesDependency(const DirDef *usedDir,const FileDef *srcFd,
const FileDef *dstFd,bool inherited) = 0;
const FileDef *dstFd,const bool inheritedByDependent, const bool inheritedByDependee) = 0;
virtual void computeDependencies() = 0;
};

Expand Down
Loading

0 comments on commit 6d5a075

Please sign in to comment.