File indexing completed on 2024-05-12 04:39:20

0001 /*
0002     SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef CLANGTIDY_CHECKGROUP_H
0008 #define CLANGTIDY_CHECKGROUP_H
0009 
0010 // Qt
0011 #include <QStringList>
0012 #include <QVector>
0013 
0014 namespace ClangTidy
0015 {
0016 
0017 class CheckGroup
0018 {
0019 public:
0020     enum EnabledState {
0021         Disabled,
0022         Enabled,
0023         EnabledInherited,
0024     };
0025 
0026     static CheckGroup* fromPlainList(const QStringList& checks);
0027 
0028     ~CheckGroup();
0029 
0030 private:
0031     explicit CheckGroup(const QString& name, CheckGroup* superGroup = nullptr);
0032     CheckGroup() = default;
0033     Q_DISABLE_COPY(CheckGroup)
0034 
0035 public:
0036     const QString& prefix() const;
0037     CheckGroup* superGroup() const;
0038     const QStringList& checkNames() const;
0039     const QVector<CheckGroup*>& subGroups() const;
0040 
0041     EnabledState groupEnabledState() const;
0042     EnabledState effectiveGroupEnabledState() const;
0043 
0044     EnabledState checkEnabledState(int index) const;
0045     EnabledState effectiveCheckEnabledState(int index) const;
0046 
0047     QString wildCardText() const;
0048     QStringList enabledChecksRules() const;
0049     int enabledChecksCount() const;
0050     bool hasSubGroupWithExplicitEnabledState() const;
0051 
0052     void setGroupEnabledState(EnabledState groupEnabledState);
0053     void setCheckEnabledState(int index, EnabledState checkEnabledState);
0054 
0055     void setEnabledChecks(const QStringList& rules);
0056 
0057 private:
0058     void addCheck(const QString& checkName);
0059     void applyEnabledRule(const QStringRef& rule, EnabledState enabledState);
0060     void resetEnabledState(EnabledState enabledState);
0061     void collectEnabledChecks(QStringList& enabledChecks) const;
0062 
0063     void setEnabledChecksCountDirtyInSuperGroups();
0064     void setEnabledChecksCountDirtyInSubGroups();
0065     void updateData() const;
0066 
0067 private:
0068     CheckGroup* m_superGroup = nullptr;
0069 
0070     EnabledState m_groupEnabledState = EnabledInherited;
0071     QVector<EnabledState> m_checksEnabledStates;
0072     QString m_prefix;
0073     QVector<CheckGroup*> m_subGroups;
0074     QStringList m_checks;
0075 
0076     mutable int m_enabledChecksCount = 0;
0077     mutable bool m_enabledChecksCountDirty = false;
0078     mutable bool m_hasSubGroupWithExplicitEnabledState = false;
0079 };
0080 
0081 }
0082 
0083 #endif