CppTools: Modernize

Change-Id: I78af9cd4ccddfa4ed744dce96b772ae5644c89d2
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Nikolai Kosjar
2019-02-07 10:09:21 +01:00
parent 69281bcdcf
commit 12f4b1ee86
15 changed files with 61 additions and 96 deletions

View File

@@ -50,7 +50,7 @@ namespace {
CursorInfo::Range toRange(const SemanticInfo::Use &use) CursorInfo::Range toRange(const SemanticInfo::Use &use)
{ {
return CursorInfo::Range(use.line, use.column, use.length); return {use.line, use.column, use.length};
} }
CursorInfo::Range toRange(int tokenIndex, TranslationUnit *translationUnit) CursorInfo::Range toRange(int tokenIndex, TranslationUnit *translationUnit)
@@ -60,10 +60,9 @@ CursorInfo::Range toRange(int tokenIndex, TranslationUnit *translationUnit)
if (column) if (column)
--column; // adjust the column position. --column; // adjust the column position.
return CursorInfo::Range( return {line,
line, column + 1,
column +1, translationUnit->tokenAt(static_cast<unsigned>(tokenIndex)).utf16chars()};
translationUnit->tokenAt(static_cast<unsigned>(tokenIndex)).utf16chars());
} }
CursorInfo::Range toRange(const QTextCursor &textCursor, CursorInfo::Range toRange(const QTextCursor &textCursor,
@@ -74,10 +73,9 @@ CursorInfo::Range toRange(const QTextCursor &textCursor,
cursor.setPosition(static_cast<int>(utf16offset)); cursor.setPosition(static_cast<int>(utf16offset));
const QTextBlock textBlock = cursor.block(); const QTextBlock textBlock = cursor.block();
return CursorInfo::Range( return {static_cast<unsigned>(textBlock.blockNumber() + 1),
static_cast<unsigned>(textBlock.blockNumber() + 1), static_cast<unsigned>(cursor.position() - textBlock.position() + 1),
static_cast<unsigned>(cursor.position() - textBlock.position() + 1), length};
length);
} }
CursorInfo::Ranges toRanges(const SemanticUses &uses) CursorInfo::Ranges toRanges(const SemanticUses &uses)
@@ -216,8 +214,8 @@ private:
bool good = false; bool good = false;
foreach (const CppTools::SemanticInfo::Use &use, uses) { foreach (const CppTools::SemanticInfo::Use &use, uses) {
unsigned l = static_cast<unsigned>(m_line); const auto l = static_cast<unsigned>(m_line);
unsigned c = static_cast<unsigned>(m_column); const auto c = static_cast<unsigned>(m_column);
if (l == use.line && c >= use.column && c <= (use.column + use.length)) { if (l == use.line && c >= use.column && c <= (use.column + use.length)) {
good = true; good = true;
break; break;

View File

@@ -51,6 +51,8 @@
#include <QStringListModel> #include <QStringListModel>
#include <QUuid> #include <QUuid>
#include <memory>
namespace CppTools { namespace CppTools {
using namespace Constants; using namespace Constants;
@@ -383,7 +385,7 @@ private:
} }
} }
QVariant data(const QModelIndex &fullIndex, int role = Qt::DisplayRole) const override final QVariant data(const QModelIndex &fullIndex, int role = Qt::DisplayRole) const final
{ {
if (!fullIndex.isValid() || role == Qt::DecorationRole) if (!fullIndex.isValid() || role == Qt::DecorationRole)
return QVariant(); return QVariant();
@@ -447,7 +449,7 @@ private:
QModelIndex indexForTree(const ClazyChecksTree *tree) const { QModelIndex indexForTree(const ClazyChecksTree *tree) const {
if (!tree) if (!tree)
return QModelIndex(); return {};
QModelIndex result; QModelIndex result;
traverse(index(0, 0, QModelIndex()), [&](const QModelIndex &index){ traverse(index(0, 0, QModelIndex()), [&](const QModelIndex &index){
@@ -989,11 +991,11 @@ static void setupTreeView(QTreeView *view, QAbstractItemModel *model, int expand
void ClangDiagnosticConfigsWidget::setupTabs() void ClangDiagnosticConfigsWidget::setupTabs()
{ {
m_clangBaseChecks.reset(new CppTools::Ui::ClangBaseChecks); m_clangBaseChecks = std::make_unique<CppTools::Ui::ClangBaseChecks>();
m_clangBaseChecksWidget = new QWidget(); m_clangBaseChecksWidget = new QWidget();
m_clangBaseChecks->setupUi(m_clangBaseChecksWidget); m_clangBaseChecks->setupUi(m_clangBaseChecksWidget);
m_clazyChecks.reset(new CppTools::Ui::ClazyChecks); m_clazyChecks = std::make_unique<CppTools::Ui::ClazyChecks>();
m_clazyChecksWidget = new QWidget(); m_clazyChecksWidget = new QWidget();
m_clazyChecks->setupUi(m_clazyChecksWidget); m_clazyChecks->setupUi(m_clazyChecksWidget);
m_clazySortFilterProxyModel = new ClazyChecksSortFilterModel(this); m_clazySortFilterProxyModel = new ClazyChecksSortFilterModel(this);
@@ -1030,7 +1032,7 @@ void ClangDiagnosticConfigsWidget::setupTabs()
= codeModelSettings()->enableLowerClazyLevels() ? Qt::Checked : Qt::Unchecked; = codeModelSettings()->enableLowerClazyLevels() ? Qt::Checked : Qt::Unchecked;
m_clazyChecks->enableLowerLevelsCheckBox->setCheckState(checkEnableLowerClazyLevels); m_clazyChecks->enableLowerLevelsCheckBox->setCheckState(checkEnableLowerClazyLevels);
m_tidyChecks.reset(new CppTools::Ui::TidyChecks); m_tidyChecks = std::make_unique<CppTools::Ui::TidyChecks>();
m_tidyChecksWidget = new QWidget(); m_tidyChecksWidget = new QWidget();
m_tidyChecks->setupUi(m_tidyChecksWidget); m_tidyChecks->setupUi(m_tidyChecksWidget);
setupTreeView(m_tidyChecks->checksPrefixesTree, m_tidyTreeModel.get()); setupTreeView(m_tidyChecks->checksPrefixesTree, m_tidyTreeModel.get());

View File

@@ -666,7 +666,7 @@ CodeFormatter::State CodeFormatter::state(int belowTop) const
if (belowTop < m_currentState.size()) if (belowTop < m_currentState.size())
return m_currentState.at(m_currentState.size() - 1 - belowTop); return m_currentState.at(m_currentState.size() - 1 - belowTop);
else else
return State(); return {};
} }
int CodeFormatter::tokenIndex() const int CodeFormatter::tokenIndex() const

View File

@@ -36,7 +36,7 @@
using namespace CppTools; using namespace CppTools;
static Core::Id initialClangDiagnosticConfigId() static Core::Id initialClangDiagnosticConfigId()
{ return Core::Id(Constants::CPP_CLANG_BUILTIN_CONFIG_ID_EVERYTHING_WITH_EXCEPTIONS); } { return {Constants::CPP_CLANG_BUILTIN_CONFIG_ID_EVERYTHING_WITH_EXCEPTIONS}; }
static CppCodeModelSettings::PCHUsage initialPchUsage() static CppCodeModelSettings::PCHUsage initialPchUsage()
{ return CppCodeModelSettings::PchUse_BuildSystem; } { return CppCodeModelSettings::PchUse_BuildSystem; }

View File

@@ -76,7 +76,7 @@ CppCodeStyleSettings CppCodeStylePreferences::currentCodeStyleSettings() const
QVariant v = currentValue(); QVariant v = currentValue();
if (!v.canConvert<CppCodeStyleSettings>()) { if (!v.canConvert<CppCodeStyleSettings>()) {
// warning // warning
return CppCodeStyleSettings(); return {};
} }
return v.value<CppCodeStyleSettings>(); return v.value<CppCodeStyleSettings>();
} }

View File

@@ -67,30 +67,7 @@ using namespace CppTools;
// ------------------ CppCodeStyleSettingsWidget // ------------------ CppCodeStyleSettingsWidget
CppCodeStyleSettings::CppCodeStyleSettings() : CppCodeStyleSettings::CppCodeStyleSettings() = default;
indentBlockBraces(false)
, indentBlockBody(true)
, indentClassBraces(false)
, indentEnumBraces(false)
, indentNamespaceBraces(false)
, indentNamespaceBody(false)
, indentAccessSpecifiers(false)
, indentDeclarationsRelativeToAccessSpecifiers(true)
, indentFunctionBody(true)
, indentFunctionBraces(false)
, indentSwitchLabels(false)
, indentStatementsRelativeToSwitchLabels(true)
, indentBlocksRelativeToSwitchLabels(false)
, indentControlFlowRelativeToSwitchLabels(true)
, bindStarToIdentifier(true)
, bindStarToTypeName(false)
, bindStarToLeftSpecifier(false)
, bindStarToRightSpecifier(false)
, extraPaddingForConditionsIfConfusingAlign(true)
, alignAssignments(false)
, preferGetterNameWithoutGetPrefix(true)
{
}
void CppCodeStyleSettings::toSettings(const QString &category, QSettings *s) const void CppCodeStyleSettings::toSettings(const QString &category, QSettings *s) const
{ {
@@ -203,21 +180,20 @@ bool CppCodeStyleSettings::equals(const CppCodeStyleSettings &rhs) const
Utils::optional<CppCodeStyleSettings> CppCodeStyleSettings::currentProjectCodeStyle() Utils::optional<CppCodeStyleSettings> CppCodeStyleSettings::currentProjectCodeStyle()
{ {
ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject(); ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject();
using OptSettings = Utils::optional<CppCodeStyleSettings>;
if (!project) if (!project)
return OptSettings(); return {};
ProjectExplorer::EditorConfiguration *editorConfiguration = project->editorConfiguration(); ProjectExplorer::EditorConfiguration *editorConfiguration = project->editorConfiguration();
QTC_ASSERT(editorConfiguration, return OptSettings()); QTC_ASSERT(editorConfiguration, return {});
TextEditor::ICodeStylePreferences *codeStylePreferences TextEditor::ICodeStylePreferences *codeStylePreferences
= editorConfiguration->codeStyle(Constants::CPP_SETTINGS_ID); = editorConfiguration->codeStyle(Constants::CPP_SETTINGS_ID);
QTC_ASSERT(codeStylePreferences, return OptSettings()); QTC_ASSERT(codeStylePreferences, return {});
auto cppCodeStylePreferences = auto cppCodeStylePreferences =
dynamic_cast<const CppCodeStylePreferences *>(codeStylePreferences); dynamic_cast<const CppCodeStylePreferences *>(codeStylePreferences);
if (!cppCodeStylePreferences) if (!cppCodeStylePreferences)
return OptSettings(); return {};
return cppCodeStylePreferences->currentCodeStyleSettings(); return cppCodeStylePreferences->currentCodeStyleSettings();
} }

View File

@@ -45,26 +45,26 @@ class CPPTOOLS_EXPORT CppCodeStyleSettings
public: public:
CppCodeStyleSettings(); CppCodeStyleSettings();
bool indentBlockBraces; bool indentBlockBraces = false;
bool indentBlockBody; bool indentBlockBody = true;
bool indentClassBraces; bool indentClassBraces = false;
bool indentEnumBraces; bool indentEnumBraces = false;
bool indentNamespaceBraces; bool indentNamespaceBraces = false;
bool indentNamespaceBody; bool indentNamespaceBody = false;
bool indentAccessSpecifiers; bool indentAccessSpecifiers = false;
bool indentDeclarationsRelativeToAccessSpecifiers; bool indentDeclarationsRelativeToAccessSpecifiers = true;
bool indentFunctionBody; bool indentFunctionBody = true;
bool indentFunctionBraces; bool indentFunctionBraces = false;
bool indentSwitchLabels; bool indentSwitchLabels = false;
bool indentStatementsRelativeToSwitchLabels; bool indentStatementsRelativeToSwitchLabels = true;
bool indentBlocksRelativeToSwitchLabels; bool indentBlocksRelativeToSwitchLabels = false;
bool indentControlFlowRelativeToSwitchLabels; bool indentControlFlowRelativeToSwitchLabels = true;
// Formatting of pointer and reference declarations, see Overview::StarBindFlag. // Formatting of pointer and reference declarations, see Overview::StarBindFlag.
bool bindStarToIdentifier; bool bindStarToIdentifier = true;
bool bindStarToTypeName; bool bindStarToTypeName = false;
bool bindStarToLeftSpecifier; bool bindStarToLeftSpecifier = false;
bool bindStarToRightSpecifier; bool bindStarToRightSpecifier = false;
// false: if (a && // false: if (a &&
// b) // b)
@@ -75,15 +75,15 @@ public:
// but always: while (a && // but always: while (a &&
// b) // b)
// foo; // foo;
bool extraPaddingForConditionsIfConfusingAlign; bool extraPaddingForConditionsIfConfusingAlign = true;
// false: a = a + // false: a = a +
// b; // b;
// true: a = a + // true: a = a +
// b // b
bool alignAssignments; bool alignAssignments = false;
bool preferGetterNameWithoutGetPrefix; bool preferGetterNameWithoutGetPrefix = true;
void toSettings(const QString &category, QSettings *s) const; void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s); void fromSettings(const QString &category, const QSettings *s);

View File

@@ -1737,9 +1737,8 @@ void InternalCppCompletionAssistProcessor::addClassMembersToCompletion(Scope *sc
else else
addCompletionItem(member); addCompletionItem(member);
} }
std::set<Class *>::const_iterator citEnd = nestedAnonymouses.end(); for (Class *klass : nestedAnonymouses)
for (std::set<Class *>::const_iterator cit = nestedAnonymouses.begin(); cit != citEnd; ++cit) addClassMembersToCompletion(klass, staticLookup);
addClassMembersToCompletion(*cit, staticLookup);
} }
bool InternalCppCompletionAssistProcessor::completeQtMethod(const QList<LookupItem> &results, bool InternalCppCompletionAssistProcessor::completeQtMethod(const QList<LookupItem> &results,

View File

@@ -179,7 +179,7 @@ CppCodeStyleSettings CppQtStyleIndenter::codeStyleSettings() const
{ {
if (m_cppCodeStylePreferences) if (m_cppCodeStylePreferences)
return m_cppCodeStylePreferences->currentCodeStyleSettings(); return m_cppCodeStylePreferences->currentCodeStyleSettings();
return CppCodeStyleSettings(); return {};
} }
TextEditor::IndentationForBlock CppQtStyleIndenter::indentationForBlocks( TextEditor::IndentationForBlock CppQtStyleIndenter::indentationForBlocks(

View File

@@ -198,12 +198,12 @@ Utils::ChangeSet::Range CppRefactoringFile::range(unsigned tokenIndex) const
unsigned line, column; unsigned line, column;
cppDocument()->translationUnit()->getPosition(token.utf16charsBegin(), &line, &column); cppDocument()->translationUnit()->getPosition(token.utf16charsBegin(), &line, &column);
const int start = document()->findBlockByNumber(line - 1).position() + column - 1; const int start = document()->findBlockByNumber(line - 1).position() + column - 1;
return Utils::ChangeSet::Range(start, start + token.utf16chars()); return {start, static_cast<int>(start + token.utf16chars())};
} }
Utils::ChangeSet::Range CppRefactoringFile::range(AST *ast) const Utils::ChangeSet::Range CppRefactoringFile::range(AST *ast) const
{ {
return Utils::ChangeSet::Range(startOf(ast), endOf(ast)); return {startOf(ast), endOf(ast)};
} }
int CppRefactoringFile::startOf(unsigned index) const int CppRefactoringFile::startOf(unsigned index) const

View File

@@ -42,12 +42,7 @@
using namespace CppTools; using namespace CppTools;
using namespace CPlusPlus; using namespace CPlusPlus;
DoxygenGenerator::DoxygenGenerator() DoxygenGenerator::DoxygenGenerator() = default;
: m_addLeadingAsterisks(true)
, m_generateBrief(true)
, m_startComment(true)
, m_style(QtStyle)
{}
void DoxygenGenerator::setStyle(DocumentationStyle style) void DoxygenGenerator::setStyle(DocumentationStyle style)
{ {

View File

@@ -85,10 +85,10 @@ private:
void assignCommentOffset(QTextCursor cursor); void assignCommentOffset(QTextCursor cursor);
QString offsetString() const; QString offsetString() const;
bool m_addLeadingAsterisks; bool m_addLeadingAsterisks = true;
bool m_generateBrief; bool m_generateBrief = true;
bool m_startComment; bool m_startComment = true;
DocumentationStyle m_style; DocumentationStyle m_style = QtStyle;
CPlusPlus::Overview m_printer; CPlusPlus::Overview m_printer;
QString m_commentOffset; QString m_commentOffset;
}; };

View File

@@ -248,10 +248,7 @@ private:
} // end of anonymous namespace } // end of anonymous namespace
InsertionLocation::InsertionLocation() InsertionLocation::InsertionLocation() = default;
: m_line(0)
, m_column(0)
{}
InsertionLocation::InsertionLocation(const QString &fileName, InsertionLocation::InsertionLocation(const QString &fileName,
const QString &prefix, const QString &prefix,
@@ -316,11 +313,9 @@ class HighestValue
{ {
Key _key; Key _key;
Value _value; Value _value;
bool _set; bool _set = false;
public: public:
HighestValue() HighestValue() = default;
: _key(), _set(false)
{}
HighestValue(const Key &initialKey, const Value &initialValue) HighestValue(const Key &initialKey, const Value &initialValue)
: _key(initialKey) : _key(initialKey)

View File

@@ -63,8 +63,8 @@ private:
QString m_fileName; QString m_fileName;
QString m_prefix; QString m_prefix;
QString m_suffix; QString m_suffix;
unsigned m_line; unsigned m_line = 0;
unsigned m_column; unsigned m_column = 0;
}; };
class CPPTOOLS_EXPORT InsertionPointLocator class CPPTOOLS_EXPORT InsertionPointLocator

View File

@@ -41,7 +41,7 @@ namespace CppTools {
class SearchSymbols: protected CPlusPlus::SymbolVisitor class SearchSymbols: protected CPlusPlus::SymbolVisitor
{ {
public: public:
typedef SymbolSearcher::SymbolTypes SymbolTypes; using SymbolTypes = SymbolSearcher::SymbolTypes;
static SymbolTypes AllTypes; static SymbolTypes AllTypes;