Skip to content

Commit

Permalink
Refactoring: Added ENABLE_CLANG_TIDY option and added rule of 0 or ru…
Browse files Browse the repository at this point in the history
…le of 5 special members
  • Loading branch information
doxygen committed Apr 10, 2024
1 parent a10076c commit aa55cc8
Show file tree
Hide file tree
Showing 67 changed files with 212 additions and 210 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
cmake_minimum_required(VERSION 3.14)
project(doxygen)

option("ENABLE_CLANG_TIDY" "Enable static analysis with clang-tidy" OFF)

option(build_wizard "Build the GUI frontend for doxygen." OFF)
option(build_app "Example showing how to embed doxygen in an application." OFF)
option(build_parse "Parses source code and dumps the dependencies between the code elements." OFF)
Expand All @@ -33,6 +35,7 @@ option(enable_coverage "Enable coverage reporting for gcc/clang [development]" O
option(enable_tracing "Enable tracing option in release builds [development]" OFF)
option(enable_lex_debug "Enable debugging info for lexical scanners in release builds [development]" OFF)


set(force_qt CACHE INTERNAL "Forces doxywizard to build using the specified major version, this can be Qt5 or Qt6")
set_property(CACHE force_qt PROPERTY STRINGS OFF Qt6 Qt5)

Expand Down Expand Up @@ -83,6 +86,17 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

if (ENABLE_CLANG_TIDY)
find_program("CLANGTIDY" "clang-tidy")
if (CLANGTIDY)
set(CMAKE_CXX_CLANG_TIDY clang-tidy;
-header-filter=.;
-checks=-*,cppcoreguidelines-special-member-functions)
else()
message(SEND_ERROR "clang-tidy requested but executable not found")
endif()
endif()

# produce compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down
7 changes: 3 additions & 4 deletions src/anchor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <memory>
#include <string>

#include "construct.h"

/** Singleton class used to generate anchors for Markdown headers */
class AnchorGenerator
{
Expand Down Expand Up @@ -46,11 +48,8 @@ class AnchorGenerator

private:
AnchorGenerator();
AnchorGenerator(const AnchorGenerator &) = delete;
AnchorGenerator &operator=(const AnchorGenerator &) = delete;
AnchorGenerator(AnchorGenerator &&) = delete;
AnchorGenerator &operator=(AnchorGenerator &&) = delete;
~AnchorGenerator();
NON_COPYABLE(AnchorGenerator)
struct Private;
std::unique_ptr<Private> p;
};
Expand Down
15 changes: 7 additions & 8 deletions src/cite.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@
#include <memory>

#include "qcstring.h"
#include "construct.h"

/// Citation-related data.
struct CiteInfo
{
virtual ~CiteInfo() = default;
CiteInfo() = default;
CiteInfo(const CiteInfo &) = delete;
CiteInfo &operator=(const CiteInfo &) = delete;
CiteInfo(CiteInfo &&) = delete;
CiteInfo &operator=(CiteInfo &&) = delete;
virtual QCString label() const = 0;
virtual QCString text() const = 0;
ABSTRACT_BASE_CLASS(CiteInfo)

virtual QCString label() const = 0;
virtual QCString text() const = 0;
};

/**
Expand Down Expand Up @@ -72,6 +69,8 @@ class CitationManager
private:
/** Create the database, with an expected maximum of \a size entries */
CitationManager();
~CitationManager() = default;
NON_COPYABLE(CitationManager)
void insertCrossReferencesForBibFile(const QCString &bibFile);
QCString getFormulas(const QCString &s);
QCString replaceFormulas(const QCString &s);
Expand Down
16 changes: 6 additions & 10 deletions src/clangparser.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#ifndef CLANGPARSER_H
#define CLANGPARSER_H

#include "containers.h"
#include "types.h"
#include <memory>
#include <string>
#include <cstdint>

#include "containers.h"
#include "types.h"
#include "construct.h"

class OutputCodeList;
class FileDef;
class ClangParser;
Expand All @@ -23,10 +25,7 @@ class ClangTUParser
{
public:
ClangTUParser(const ClangParser &parser,const FileDef *fd);
ClangTUParser(const ClangTUParser &) = delete;
ClangTUParser &operator=(const ClangTUParser &) = delete;
ClangTUParser(ClangTUParser &&) = delete;
ClangTUParser &operator=(ClangTUParser &&) = delete;
NON_COPYABLE(ClangTUParser)
virtual ~ClangTUParser();

/** Parse the file given at construction time as a translation unit
Expand Down Expand Up @@ -90,10 +89,7 @@ class ClangParser
class Private;
std::unique_ptr<Private> p;
ClangParser();
ClangParser(const ClangParser &) = delete;
ClangParser &operator=(const ClangParser &) = delete;
ClangParser(ClangParser &&) = delete;
ClangParser &operator=(ClangParser &&) = delete;
NON_COPYABLE(ClangParser)
virtual ~ClangParser();
static ClangParser *s_instance;
};
Expand Down
6 changes: 2 additions & 4 deletions src/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define CODE_H

#include "parserintf.h"
#include "construct.h"

class FileDef;
class MemberDef;
Expand All @@ -29,11 +30,8 @@ class CCodeParser : public CodeParserInterface
{
public:
CCodeParser();
CCodeParser(const CCodeParser &) = delete;
CCodeParser &operator=(CCodeParser &) = delete;
CCodeParser(CCodeParser &&) = delete;
CCodeParser &operator=(CCodeParser &&) = delete;
virtual ~CCodeParser();
NON_COPYABLE(CCodeParser)
void parseCode(OutputCodeList &codeOutIntf,
const QCString &scopeName,
const QCString &input,
Expand Down
10 changes: 3 additions & 7 deletions src/configimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "containers.h"
#include "qcstring.h"
#include "config.h"
#include "construct.h"

class TextStream;

Expand All @@ -38,6 +39,7 @@ class ConfigOption
friend class ConfigImpl;

public:
ABSTRACT_BASE_CLASS(ConfigOption)

/*! The type of option */
enum OptionType
Expand All @@ -62,9 +64,6 @@ class ConfigOption
{
m_spaces.fill(' ',40);
}
virtual ~ConfigOption()
{
}

/*! returns the kind of option this is. */
OptionType kind() const { return m_kind; }
Expand Down Expand Up @@ -195,9 +194,6 @@ class ConfigString : public ConfigOption
m_doc = doc;
m_widgetType = String;
}
~ConfigString()
{
}
void setWidgetType(WidgetType w) { m_widgetType = w; }
WidgetType widgetType() const { return m_widgetType; }
void setDefaultValue(const char *v) { m_defValue = v; }
Expand Down Expand Up @@ -522,7 +518,7 @@ class ConfigImpl
*/
void writeXMLDoxyfile(TextStream &t);

/*! Writes all possible setting ids to an XSD file for validation
/*! Writes all possible setting ids to an XSD file for validation
* through the stream \a t.
*/
void writeXSDDoxyfile(TextStream &t);
Expand Down
3 changes: 3 additions & 0 deletions src/constexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
#include <string>
#include <memory>

#include "construct.h"

/** @brief constant expression parser used for the C preprocessor */
class ConstExpressionParser
{
public:
ConstExpressionParser();
~ConstExpressionParser();
NON_COPYABLE(ConstExpressionParser)
bool parse(const char *fileName,int line,const std::string &expression,const std::string &orgExpression);
private:
struct Private;
Expand Down
60 changes: 60 additions & 0 deletions src/construct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/******************************************************************************
*
* Copyright (C) 1997-2024 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/

#ifndef CONSTRUCT_H
#define CONSTRUCT_H

//! Macro to implement rule of 5 for an abstract base class
#define ABSTRACT_BASE_CLASS(cls) \
cls() = default; \
cls(const cls &) = delete; \
cls &operator=(const cls &) = delete; \
cls(cls &&) = delete; \
cls &operator=(cls &&) = delete; \
virtual ~cls() = default; \

//! Macro to help implementing the rule of 5 for a default copyable & movable class
#define DEFAULT_COPYABLE(cls) \
cls(const cls &) = default; \
cls &operator=(const cls &) = default; \
cls(cls &&) = default; \
cls &operator=(cls &&) = default; \
virtual ~cls() = default;

//! Macro to help implementing the rule of 5 for a non-copyable & movable class
#define NON_COPYABLE(cls) \
cls(const cls &) = delete; \
cls &operator=(const cls &) = delete; \
cls(cls &&) = delete; \
cls &operator=(cls &&) = delete; \

//! Macro to help implementing the rule of 5 for a class that can be moved but not copied
#define ONLY_DEFAULT_MOVABLE(cls) \
cls(const cls &) = delete; \
cls &operator=(const cls &) = delete; \
cls(cls &&) = default; \
cls &operator=(cls &&) = default; \

#define ONLY_MOVABLE_DECL(cls) \
cls(const cls &) = delete; \
cls &operator=(const cls &) = delete; \
cls(cls &&); \
cls &operator=(cls &&); \

#define DEFAULT_MOVABLE_IMPL(cls) \
cls::cls(cls &&) = default; \
cls &cls::operator=(cls &&) = default; \

#endif
6 changes: 2 additions & 4 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cstdint>
#include "qcstring.h"
#include "construct.h"

/** Class containing a print function for diagnostics. */
class Debug
Expand Down Expand Up @@ -87,11 +88,8 @@ class DebugLex
{
public:
DebugLex(Debug::DebugMask mask,const char *lexName,const char *fileName);
DebugLex(const DebugLex &) = delete;
DebugLex &operator=(DebugLex &) = delete;
DebugLex(DebugLex &&) = delete;
DebugLex &operator=(DebugLex &&) = delete;
~DebugLex();
NON_COPYABLE(DebugLex)
static void print(Debug::DebugMask mask,const char *state,const char *lexName,const char *fileName);
private:

Expand Down
4 changes: 1 addition & 3 deletions src/diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,9 +1071,7 @@ ClassDiagram::ClassDiagram(const ClassDef *root) : p(std::make_unique<Private>(r
}
}

ClassDiagram::~ClassDiagram()
{
}
ClassDiagram::~ClassDiagram() = default;

void ClassDiagram::writeFigure(TextStream &output,const QCString &path,
const QCString &fileName) const
Expand Down
2 changes: 2 additions & 0 deletions src/diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <memory>
#include "qcstring.h"
#include "construct.h"

class ClassDef;
class TextStream;
Expand All @@ -31,6 +32,7 @@ class ClassDiagram
public:
ClassDiagram(const ClassDef *root);
~ClassDiagram();
NON_COPYABLE(ClassDiagram)
void writeFigure(TextStream &t,const QCString &path,
const QCString &file) const;
void writeImage(TextStream &t,const QCString &path,const QCString &relPath,
Expand Down
4 changes: 0 additions & 4 deletions src/dirdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,6 @@ UsedDir::UsedDir(const DirDef *dir) :
{
}

UsedDir::~UsedDir()
{
}

void UsedDir::addFileDep(const FileDef *srcFd,const FileDef *dstFd, bool srcDirect, bool dstDirect)
{
m_filePairs.add(FilePair::key(srcFd,dstFd),std::make_unique<FilePair>(srcFd,dstFd));
Expand Down
1 change: 0 additions & 1 deletion src/dirdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class UsedDir
{
public:
UsedDir(const DirDef *dir);
virtual ~UsedDir();

/**
* Take up dependency between files.
Expand Down
8 changes: 2 additions & 6 deletions src/docnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "htmlentity.h"
#include "growvector.h"
#include "section.h"
#include "construct.h"

class MemberDef;
class Definition;
Expand Down Expand Up @@ -80,13 +81,8 @@ class DocNode
public:
/*! Creates a new node */
DocNode(DocParser *parser,DocNodeVariant *parent) : m_parser(parser), m_parent(parent) {}

// allow nodes to be moved but not copied
DocNode(const DocNode &) = delete;
DocNode &operator=(const DocNode &) = delete;
DocNode(DocNode &&) = default;
DocNode &operator=(DocNode &&) = default;
~DocNode() = default;
ONLY_DEFAULT_MOVABLE(DocNode)

/*! Returns the parent of this node or nullptr for the root node. */
DocNodeVariant *parent() { return m_parent; }
Expand Down
5 changes: 0 additions & 5 deletions src/docparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ IDocParserPtr createDocParser()
return std::make_unique<DocParser>();
}

//---------------------------------------------------------------------------
DocParser::~DocParser()
{
}

void DocParser::pushContext()
{
//QCString indent;
Expand Down

0 comments on commit aa55cc8

Please sign in to comment.