forked from qt-creator/qt-creator
ClangSupport: Use simpler structures in some cases
The patch is mostly mechanical, but contains also a few spurious changes from values references for some local variables, foreach -> ranged for etc that I coulnd't resist. Change-Id: I58f0bd972546895eb318607cbfbd7ac35caf3f23 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -72,7 +72,7 @@ public:
|
||||
while (hasSourceRangesForCurrentLine(currentLineNumber)) {
|
||||
SourceRange &sourceRange = *m_currentSourceRangeIterator;
|
||||
|
||||
popSourceRangeIfMultiLineEndsHere(currentLineNumber, sourceRange.start().column());
|
||||
popSourceRangeIfMultiLineEndsHere(currentLineNumber, sourceRange.start.column);
|
||||
|
||||
formatSourceRange(sourceRange,
|
||||
currentLineNumber,
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
bool hasSourceRangesForCurrentLine(uint currentLineNumber) const
|
||||
{
|
||||
return m_currentSourceRangeIterator != m_sourceRanges.end()
|
||||
&& m_currentSourceRangeIterator->start().line() == currentLineNumber;
|
||||
&& m_currentSourceRangeIterator->start.line == currentLineNumber;
|
||||
}
|
||||
|
||||
bool hasOnlySCurrentlyUsedSourceRanges() const
|
||||
@@ -112,8 +112,8 @@ public:
|
||||
void formatSingleSourceRange(const SourceRange &sourceRange,
|
||||
int textFormatIndex)
|
||||
{
|
||||
int size = int(sourceRange.end().column() - sourceRange.start().column());
|
||||
m_highlighter.setFormat(int(sourceRange.start().column()) - 1,
|
||||
int size = int(sourceRange.end.column - sourceRange.start.column);
|
||||
m_highlighter.setFormat(int(sourceRange.start.column) - 1,
|
||||
size,
|
||||
m_textFormats[textFormatIndex]);
|
||||
}
|
||||
@@ -122,8 +122,8 @@ public:
|
||||
int textSize,
|
||||
int textFormatIndex)
|
||||
{
|
||||
int size = textSize - int(sourceRange.start().column()) + 1;
|
||||
m_highlighter.setFormat(int(sourceRange.start().column()) - 1,
|
||||
int size = textSize - int(sourceRange.start.column) + 1;
|
||||
m_highlighter.setFormat(int(sourceRange.start.column) - 1,
|
||||
size,
|
||||
m_textFormats[textFormatIndex]);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
void formatEndMultipleSourceRange(const SourceRange &sourceRange,
|
||||
int textFormatIndex)
|
||||
{
|
||||
int size = int(sourceRange.end().column()) - 1;
|
||||
int size = int(sourceRange.end.column) - 1;
|
||||
m_highlighter.setFormat(0, size, m_textFormats[textFormatIndex]);
|
||||
}
|
||||
|
||||
@@ -146,11 +146,11 @@ public:
|
||||
int textSize,
|
||||
int textFormatIndex)
|
||||
{
|
||||
if (sourceRange.start().line() == sourceRange.end().line())
|
||||
if (sourceRange.start.line == sourceRange.end.line)
|
||||
formatSingleSourceRange(sourceRange, textFormatIndex);
|
||||
else if (sourceRange.start().line() == currentLineNumber)
|
||||
else if (sourceRange.start.line == currentLineNumber)
|
||||
formatStartMultipleSourceRange(sourceRange, textSize, textFormatIndex);
|
||||
else if (sourceRange.end().line() == currentLineNumber)
|
||||
else if (sourceRange.end.line == currentLineNumber)
|
||||
formatEndMultipleSourceRange(sourceRange, textFormatIndex);
|
||||
else
|
||||
formatMiddleMultipleSourceRange(textSize, textFormatIndex);
|
||||
@@ -169,8 +169,8 @@ public:
|
||||
bool currentlyUsedHasEndLineAndColumnNumber(uint currentLineNumber, uint currentColumnNumber)
|
||||
{
|
||||
return !m_currentlyUsedSourceRanges.empty()
|
||||
&& m_currentlyUsedSourceRanges.back().end().line() <= currentLineNumber
|
||||
&& m_currentlyUsedSourceRanges.back().end().column() <= currentColumnNumber;
|
||||
&& m_currentlyUsedSourceRanges.back().end.line <= currentLineNumber
|
||||
&& m_currentlyUsedSourceRanges.back().end.column <= currentColumnNumber;
|
||||
}
|
||||
|
||||
void popSourceRangeIfMultiLineEndsHere(uint currentLineNumber, uint currentColumnNumber)
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
{
|
||||
return !m_currentlyUsedSourceRanges.empty()
|
||||
&& m_currentSourceRangeIterator == m_sourceRanges.end()
|
||||
&& m_currentlyUsedSourceRanges.back().end().line() == currentLineNumber;
|
||||
&& m_currentlyUsedSourceRanges.back().end.line == currentLineNumber;
|
||||
}
|
||||
|
||||
void popSourceRangeIfMultiLineEndsHereAndAllSourceRangesAreConsumed(uint currentLineNumber)
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
bool currentlyUsedHasEndedBeforeLineNumber(uint currentLineNumber)
|
||||
{
|
||||
return !m_currentlyUsedSourceRanges.empty()
|
||||
&& m_currentlyUsedSourceRanges.back().end().line() < currentLineNumber;
|
||||
&& m_currentlyUsedSourceRanges.back().end.line < currentLineNumber;
|
||||
}
|
||||
|
||||
void popSourceRangeIfMultiLineEndedBefore(uint currentLineNumber)
|
||||
|
||||
@@ -56,8 +56,8 @@ void ClangQueryHighlighter::setDiagnostics(
|
||||
Contexts contexts;
|
||||
|
||||
for (const ClangBackEnd::DynamicASTMatcherDiagnosticContainer &diagnostic : diagnostics) {
|
||||
Messages newMessages = diagnostic.messages();
|
||||
Contexts newContexts = diagnostic.contexts();
|
||||
const Messages &newMessages = diagnostic.messages;
|
||||
const Contexts &newContexts = diagnostic.contexts;
|
||||
std::copy(newMessages.begin(), newMessages.end(), std::back_inserter(messages));
|
||||
std::copy(newContexts.begin(), newContexts.end(), std::back_inserter(contexts));
|
||||
}
|
||||
|
||||
@@ -69,25 +69,25 @@ public:
|
||||
bool hasMessage(uint currentLineNumber) const
|
||||
{
|
||||
return m_currentMessagesIterator != m_messages.end()
|
||||
&& m_currentMessagesIterator->sourceRange().start().line() == currentLineNumber;
|
||||
&& m_currentMessagesIterator->sourceRange.start.line == currentLineNumber;
|
||||
}
|
||||
|
||||
bool hasContext(uint currentLineNumber) const
|
||||
{
|
||||
return m_currentContextsIterator != m_contexts.end()
|
||||
&& m_currentContextsIterator->sourceRange().start().line() == currentLineNumber;
|
||||
&& m_currentContextsIterator->sourceRange.start.line == currentLineNumber;
|
||||
}
|
||||
|
||||
bool isMessageNext() const
|
||||
{
|
||||
return m_currentMessagesIterator->sourceRange().start().column()
|
||||
< m_currentContextsIterator->sourceRange().start().column();
|
||||
return m_currentMessagesIterator->sourceRange.start.column
|
||||
< m_currentContextsIterator->sourceRange.start.column;
|
||||
}
|
||||
|
||||
void formatSameLineSourceRange(const SourceRange &sourceRange, const QTextCharFormat &textFormat)
|
||||
{
|
||||
uint startColumn = sourceRange.start().column();
|
||||
uint endColumn = sourceRange.end().column();
|
||||
uint startColumn = sourceRange.start.column;
|
||||
uint endColumn = sourceRange.end.column;
|
||||
m_highlighter.setFormat(startColumn - 1, endColumn - startColumn, textFormat);
|
||||
}
|
||||
|
||||
@@ -95,13 +95,13 @@ public:
|
||||
int textSize,
|
||||
const QTextCharFormat &textFormat)
|
||||
{
|
||||
uint startColumn = sourceRange.start().column();
|
||||
uint startColumn = sourceRange.start.column;
|
||||
m_highlighter.setFormat(startColumn - 1, textSize - startColumn, textFormat);
|
||||
}
|
||||
|
||||
void formatEndLineSourceRange(const SourceRange &sourceRange, const QTextCharFormat &textFormat)
|
||||
{
|
||||
uint endColumn = sourceRange.end().column();
|
||||
uint endColumn = sourceRange.end.column;
|
||||
m_highlighter.setFormat(0, endColumn - 1, textFormat);
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@ public:
|
||||
static
|
||||
bool isSameLine(const SourceRange &sourceRange)
|
||||
{
|
||||
uint startLine = sourceRange.start().line();
|
||||
uint endLine = sourceRange.end().line();
|
||||
uint startLine = sourceRange.start.line;
|
||||
uint endLine = sourceRange.end.line;
|
||||
|
||||
return startLine == endLine;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
static
|
||||
bool isStartLine(const SourceRange &sourceRange, uint currentLineNumber)
|
||||
{
|
||||
uint startLine = sourceRange.start().line();
|
||||
uint startLine = sourceRange.start.line;
|
||||
|
||||
return startLine == currentLineNumber;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
static
|
||||
bool isEndLine(const SourceRange &sourceRange, uint currentLineNumber)
|
||||
{
|
||||
uint endLine = sourceRange.end().line();
|
||||
uint endLine = sourceRange.end.line;
|
||||
|
||||
return endLine == currentLineNumber;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
int textSize,
|
||||
const QTextCharFormat &textFormat)
|
||||
{
|
||||
const SourceRange &sourceRange = iterator->sourceRange();
|
||||
const SourceRange &sourceRange = iterator->sourceRange;
|
||||
|
||||
formatLine(sourceRange, currentLineNumber, textSize, textFormat);
|
||||
|
||||
@@ -175,7 +175,7 @@ public:
|
||||
auto newEnd = std::remove_if(container.begin(),
|
||||
container.end(),
|
||||
[&] (const auto &entry) {
|
||||
return ClangQueryHighlightMarker::isEndLine(entry.sourceRange(), currentLineNumber);
|
||||
return ClangQueryHighlightMarker::isEndLine(entry.sourceRange, currentLineNumber);
|
||||
});
|
||||
|
||||
container.erase(newEnd, container.end());
|
||||
@@ -183,12 +183,12 @@ public:
|
||||
|
||||
template<typename Container>
|
||||
void formatCurrentlyUsed(Container container,
|
||||
uint currentLineNumber,
|
||||
int textSize,
|
||||
const QTextCharFormat &textFormat)
|
||||
uint currentLineNumber,
|
||||
int textSize,
|
||||
const QTextCharFormat &textFormat)
|
||||
{
|
||||
for (const auto &entry : container) {
|
||||
formatLine(entry.sourceRange(), currentLineNumber, textSize, textFormat);;
|
||||
formatLine(entry.sourceRange, currentLineNumber, textSize, textFormat);;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,25 +253,25 @@ public:
|
||||
static
|
||||
bool isAfterStartColumn(const SourceRange &sourceRange, uint line, uint column)
|
||||
{
|
||||
return sourceRange.start().line() == line && sourceRange.start().column() <= column;
|
||||
return sourceRange.start.line == line && sourceRange.start.column <= column;
|
||||
}
|
||||
|
||||
static
|
||||
bool isBeforeEndColumn(const SourceRange &sourceRange, uint line, uint column)
|
||||
{
|
||||
return sourceRange.end().line() == line && sourceRange.end().column() >= column;
|
||||
return sourceRange.end.line == line && sourceRange.end.column >= column;
|
||||
}
|
||||
|
||||
static
|
||||
bool isInBetweenLine(const SourceRange &sourceRange, uint line)
|
||||
{
|
||||
return sourceRange.start().line() < line && sourceRange.end().line() > line;
|
||||
return sourceRange.start.line < line && sourceRange.end.line > line;
|
||||
}
|
||||
|
||||
static
|
||||
bool isSingleLine(const SourceRange &sourceRange)
|
||||
{
|
||||
return sourceRange.start().line() == sourceRange.end().line();
|
||||
return sourceRange.start.line == sourceRange.end.line;
|
||||
}
|
||||
|
||||
static
|
||||
@@ -303,7 +303,7 @@ public:
|
||||
Messages messages;
|
||||
|
||||
auto underPosition = [=] (const Message &message) {
|
||||
return ClangQueryHighlightMarker::isInsideRange(message.sourceRange(), line, column);
|
||||
return ClangQueryHighlightMarker::isInsideRange(message.sourceRange, line, column);
|
||||
};
|
||||
|
||||
std::copy_if(m_messages.begin(),
|
||||
@@ -319,7 +319,7 @@ public:
|
||||
Contexts contexts;
|
||||
|
||||
auto underPosition = [=] (const Context &context) {
|
||||
return ClangQueryHighlightMarker::isInsideRange(context.sourceRange(), line, column);
|
||||
return ClangQueryHighlightMarker::isInsideRange(context.sourceRange, line, column);
|
||||
};
|
||||
|
||||
std::copy_if(m_contexts.begin(),
|
||||
|
||||
@@ -57,9 +57,9 @@ void ClangQueryHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorW
|
||||
Contexts contexts = m_highligher->contextsForLineAndColumn(uint(line), uint(column));
|
||||
|
||||
if (!messages.empty())
|
||||
setToolTip(QString("%1: %2").arg(QString(messages[0].errorTypeText())).arg(QString(messages[0].arguments().join(", "))));
|
||||
setToolTip(QString("%1: %2").arg(QString(messages[0].errorTypeText())).arg(QString(messages[0].arguments.join(", "))));
|
||||
else if (!contexts.empty())
|
||||
setToolTip(QString("%1: %2").arg(QString(contexts[0].contextTypeText())).arg(QString(contexts[0].arguments().join(", "))));
|
||||
setToolTip(QString("%1: %2").arg(QString(contexts[0].contextTypeText())).arg(QString(contexts[0].arguments.join(", "))));
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -100,7 +100,7 @@ SearchHandle *ClangQueryProjectsFindFilter::find(const QString &queryText)
|
||||
|
||||
auto message = createMessage(queryText);
|
||||
|
||||
m_refactoringClient.setExpectedResultCount(uint(message.sources().size()));
|
||||
m_refactoringClient.setExpectedResultCount(uint(message.sources.size()));
|
||||
|
||||
m_server.requestSourceRangesForQueryMessage(std::move(message));
|
||||
|
||||
@@ -183,7 +183,7 @@ bool unsavedContentContains(const ClangBackEnd::FilePath &sourceFilePath,
|
||||
const std::vector<ClangBackEnd::V2::FileContainer> &unsavedContent)
|
||||
{
|
||||
auto compare = [&] (const ClangBackEnd::V2::FileContainer &unsavedEntry) {
|
||||
return unsavedEntry.filePath() == sourceFilePath;
|
||||
return unsavedEntry.filePath == sourceFilePath;
|
||||
};
|
||||
|
||||
auto found = std::find_if(unsavedContent.begin(), unsavedContent.end(), compare);
|
||||
|
||||
@@ -43,9 +43,9 @@ void RefactoringClient::alive()
|
||||
void RefactoringClient::sourceLocationsForRenamingMessage(
|
||||
ClangBackEnd::SourceLocationsForRenamingMessage &&message)
|
||||
{
|
||||
m_localRenamingCallback(message.symbolName().toQString(),
|
||||
message.sourceLocations(),
|
||||
message.textDocumentRevision());
|
||||
m_localRenamingCallback(message.symbolName.toQString(),
|
||||
message.sourceLocations,
|
||||
message.textDocumentRevision);
|
||||
|
||||
m_refactoringEngine->setRefactoringEngineAvailable(true);
|
||||
}
|
||||
@@ -54,13 +54,13 @@ void RefactoringClient::sourceRangesAndDiagnosticsForQueryMessage(
|
||||
ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage &&message)
|
||||
{
|
||||
m_clangQueryExampleHighlighter->setSourceRanges(message.takeSourceRanges());
|
||||
m_clangQueryHighlighter->setDiagnostics(message.diagnostics());
|
||||
m_clangQueryHighlighter->setDiagnostics(message.diagnostics);
|
||||
}
|
||||
|
||||
void RefactoringClient::sourceRangesForQueryMessage(ClangBackEnd::SourceRangesForQueryMessage &&message)
|
||||
{
|
||||
++m_resultCounter;
|
||||
addSearchResults(message.sourceRanges());
|
||||
addSearchResults(message.sourceRanges);
|
||||
setResultCounterAndSendSearchIsFinishedIfFinished();
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ void RefactoringClient::setRefactoringConnectionClient(
|
||||
|
||||
void RefactoringClient::addSearchResults(const ClangBackEnd::SourceRangesContainer &sourceRanges)
|
||||
{
|
||||
for (const auto &sourceRangeWithText : sourceRanges.sourceRangeWithTextContainers())
|
||||
for (const auto &sourceRangeWithText : sourceRanges.sourceRangeWithTextContainers)
|
||||
addSearchResult(sourceRangeWithText);
|
||||
}
|
||||
|
||||
@@ -134,13 +134,13 @@ void RefactoringClient::addSearchResult(const ClangBackEnd::SourceRangeWithTextC
|
||||
auto &filePathCache = m_refactoringEngine->filePathCache();
|
||||
|
||||
m_searchHandle->addResult(QString(filePathCache.filePath(sourceRangeWithText.filePathId()).path()),
|
||||
QString(sourceRangeWithText.text()),
|
||||
{{int(sourceRangeWithText.start().line()),
|
||||
int(sourceRangeWithText.start().column() - 1),
|
||||
int(sourceRangeWithText.start().offset())},
|
||||
{int(sourceRangeWithText.end().line()),
|
||||
int(sourceRangeWithText.end().column() - 1),
|
||||
int(sourceRangeWithText.end().offset())}});
|
||||
QString(sourceRangeWithText.text),
|
||||
{{int(sourceRangeWithText.start.line),
|
||||
int(sourceRangeWithText.start.column - 1),
|
||||
int(sourceRangeWithText.start.offset)},
|
||||
{int(sourceRangeWithText.end.line),
|
||||
int(sourceRangeWithText.end.column - 1),
|
||||
int(sourceRangeWithText.end.offset)}});
|
||||
}
|
||||
|
||||
void RefactoringClient::setResultCounterAndSendSearchIsFinishedIfFinished()
|
||||
|
||||
Reference in New Issue
Block a user