Clang: Cleanup more PrintTo functions

Change-Id: If1389462479ae10b067904f05cf785c3d8fb9638
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Marco Bubke
2017-06-13 18:23:05 +02:00
parent 50790f6187
commit 1f18848ee7
16 changed files with 71 additions and 64 deletions

View File

@@ -208,6 +208,6 @@ private:
CMBIPC_EXPORT QDebug operator<<(QDebug debug, CodeCompletion::Kind kind); CMBIPC_EXPORT QDebug operator<<(QDebug debug, CodeCompletion::Kind kind);
std::ostream &operator<<(std::ostream &os, const CodeCompletion::Kind kind); CMBIPC_EXPORT std::ostream &operator<<(std::ostream &os, const CodeCompletion::Kind kind);
std::ostream &operator<<(std::ostream &os, const CodeCompletion::Availability availability); CMBIPC_EXPORT std::ostream &operator<<(std::ostream &os, const CodeCompletion::Availability availability);
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -423,12 +423,15 @@ bool operator==(const Document &first, const Document &second)
&& first.projectPart().id() == second.projectPart().id(); && first.projectPart().id() == second.projectPart().id();
} }
void PrintTo(const Document &document, ::std::ostream *os) std::ostream &operator<<(std::ostream &os, const Document &document)
{ {
*os << "Document(" os << "("
<< document.filePath().constData() << ", " << document.filePath() << ", "
<< document.projectPart().id().constData() << ", " << document.projectPart().id() << ", "
<< document.documentRevision() << ")"; << document.documentRevision()
<< ")";
return os;
} }
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -133,5 +133,5 @@ private:
}; };
bool operator==(const Document &first, const Document &second); bool operator==(const Document &first, const Document &second);
void PrintTo(const Document &document, ::std::ostream *os); std::ostream &operator<<(std::ostream &os, const Document &document);
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -107,7 +107,6 @@ public:
{ {
return second == first; return second == first;
} }
template<typename Type, template<typename Type,
typename = typename std::enable_if<std::is_pointer<Type>::value>::type typename = typename std::enable_if<std::is_pointer<Type>::value>::type
> >
@@ -124,11 +123,9 @@ public:
return second == first; return second == first;
} }
friend std::ostream &operator<<(std::ostream &out, const ClangString &string) friend std::ostream &operator<<(std::ostream &os, const ClangString &string)
{ {
out << string.cString(); return os << string.cString();
return out;
} }
private: private:

View File

@@ -144,17 +144,20 @@ bool operator==(Type first, Type second)
return clang_equalTypes(first.cxType, second.cxType); return clang_equalTypes(first.cxType, second.cxType);
} }
void PrintTo(CXTypeKind typeKind, ::std::ostream* os) std::ostream &operator<<(std::ostream &os, CXTypeKind typeKind)
{ {
ClangString typeKindSpelling(clang_getTypeKindSpelling(typeKind)); ClangString typeKindSpelling(clang_getTypeKindSpelling(typeKind));
*os << typeKindSpelling.cString();
return os << typeKindSpelling.cString();
} }
void PrintTo(const Type &type, ::std::ostream* os) std::ostream &operator<<(std::ostream &os, const Type &type)
{ {
ClangString typeKindSpelling(clang_getTypeKindSpelling(type.kind())); ClangString typeKindSpelling(clang_getTypeKindSpelling(type.kind()));
*os << typeKindSpelling.cString() os << typeKindSpelling
<< ": \"" << type.spelling().cString() << "\""; << ": \"" << type.spelling() << "\"";
return os;
} }

View File

@@ -77,6 +77,6 @@ private:
bool operator==(Type first, Type second); bool operator==(Type first, Type second);
void PrintTo(CXTypeKind typeKind, ::std::ostream* os); std::ostream &operator<<(std::ostream &os, CXTypeKind typeKind);
void PrintTo(const Type &type, ::std::ostream* os); std::ostream &operator<<(std::ostream &os, const Type &type);
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -28,10 +28,6 @@
#include "clangstring.h" #include "clangstring.h"
#include "codecompletionchunkconverter.h" #include "codecompletionchunkconverter.h"
#ifdef CLANGBACKEND_TESTS
#include <gtest/gtest.h>
#endif
#include <QDebug> #include <QDebug>
namespace ClangBackEnd { namespace ClangBackEnd {
@@ -344,15 +340,15 @@ const CodeCompletion &CodeCompletionsExtractor::currentCodeCompletion() const
return currentCodeCompletion_; return currentCodeCompletion_;
} }
#ifdef CLANGBACKEND_TESTS std::ostream &operator<<(std::ostream &os, const CodeCompletionsExtractor &extractor)
void PrintTo(const CodeCompletionsExtractor &extractor, std::ostream *os)
{ {
*os << "name: " << ::testing::PrintToString(extractor.currentCodeCompletion().text()) os << "name: " << extractor.currentCodeCompletion().text()
<< ", kind: " << ::testing::PrintToString(extractor.currentCodeCompletion().completionKind()) << ", kind: " << extractor.currentCodeCompletion().completionKind()
<< ", priority: " << extractor.currentCodeCompletion().priority() << ", priority: " << extractor.currentCodeCompletion().priority()
<< ", kind: " << ::testing::PrintToString(extractor.currentCodeCompletion().availability()); << ", kind: " << extractor.currentCodeCompletion().availability();
return os;
} }
#endif
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -31,6 +31,8 @@
#include <QVector> #include <QVector>
#include <iosfwd>
namespace ClangBackEnd { namespace ClangBackEnd {
class CodeCompletionsExtractor class CodeCompletionsExtractor
@@ -78,7 +80,5 @@ private:
uint cxCodeCompleteResultIndex = -1; uint cxCodeCompleteResultIndex = -1;
}; };
#ifdef CLANGBACKEND_TESTS std::ostream &operator<<(std::ostream &os, const CodeCompletionsExtractor &extractor);
void PrintTo(const CodeCompletionsExtractor &extractor, ::std::ostream* os);
#endif
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -403,29 +403,31 @@ bool operator!=(const Cursor &first, const Cursor &second)
return !(first == second); return !(first == second);
} }
void PrintTo(CXCursorKind cursorKind, ::std::ostream *os) std::ostream &operator<<(std::ostream &os, CXCursorKind cursorKind)
{ {
ClangString cursorKindSpelling(clang_getCursorKindSpelling(cursorKind)); ClangString cursorKindSpelling(clang_getCursorKindSpelling(cursorKind));
*os << cursorKindSpelling.cString(); return os << cursorKindSpelling.cString();
} }
void PrintTo(const Cursor &cursor, ::std::ostream*os) std::ostream &operator<<(std::ostream &os, const Cursor &cursor)
{ {
if (cursor.isValid()) { if (cursor.isValid()) {
ClangString cursorKindSpelling(clang_getCursorKindSpelling(cursor.kind())); ClangString cursorKindSpelling(clang_getCursorKindSpelling(cursor.kind()));
*os << cursorKindSpelling.cString() << " "; os << cursorKindSpelling << " ";
auto identifier = cursor.displayName(); auto identifier = cursor.displayName();
if (identifier.hasContent()) { if (identifier.hasContent()) {
*os << "\"" os << "\""
<< identifier << identifier
<< "\": "; << "\": ";
} }
PrintTo(cursor.sourceLocation(), os); os << cursor.sourceLocation();
} else { } else {
*os << "Invalid cursor!"; os << "Invalid cursor!";
} }
return os;
} }
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -130,6 +130,7 @@ void Cursor::visit(VisitorCallback visitorCallback) const
bool operator==(const Cursor &first, const Cursor &second); bool operator==(const Cursor &first, const Cursor &second);
bool operator!=(const Cursor &first, const Cursor &second); bool operator!=(const Cursor &first, const Cursor &second);
void PrintTo(CXCursorKind cursorKind, ::std::ostream *os); std::ostream &operator<<(std::ostream &os, CXCursorKind cursorKind);
void PrintTo(const Cursor &cursor, ::std::ostream* os); std::ostream &operator<<(std::ostream &os, const Cursor &cursor);
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -114,15 +114,17 @@ SourceLocation::operator CXSourceLocation() const
return cxSourceLocation; return cxSourceLocation;
} }
void PrintTo(const SourceLocation &sourceLocation, std::ostream *os) std::ostream &operator<<(std::ostream &os, const SourceLocation &sourceLocation)
{ {
auto filePath = sourceLocation.filePath(); auto filePath = sourceLocation.filePath();
if (filePath.hasContent()) if (filePath.hasContent())
*os << filePath.constData() << ", "; os << filePath << ", ";
*os << "line: " << sourceLocation.line() os << "line: " << sourceLocation.line()
<< ", column: "<< sourceLocation.column() << ", column: "<< sourceLocation.column()
<< ", offset: "<< sourceLocation.offset(); << ", offset: "<< sourceLocation.offset();
return os;
} }
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -72,6 +72,6 @@ private:
bool operator==(const SourceLocation &first, const SourceLocation &second); bool operator==(const SourceLocation &first, const SourceLocation &second);
void PrintTo(const SourceLocation &sourceLocation, ::std::ostream* os); std::ostream &operator<<(std::ostream &os, const SourceLocation &sourceLocation);
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -100,13 +100,14 @@ bool operator==(const SourceRange &first, const SourceRange &second)
return clang_equalRanges(first.cxSourceRange, second.cxSourceRange); return clang_equalRanges(first.cxSourceRange, second.cxSourceRange);
} }
void PrintTo(const SourceRange &sourceRange, ::std::ostream* os) std::ostream &operator<<(std::ostream &os, const SourceRange &sourceRange)
{ {
*os << "["; os << "["
PrintTo(sourceRange.start(), os); << sourceRange.start() << ", "
*os << ", "; << sourceRange.end()
PrintTo(sourceRange.end(), os); << "]";
*os << "]";
return os;
} }
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -61,5 +61,5 @@ private:
}; };
bool operator==(const SourceRange &first, const SourceRange &second); bool operator==(const SourceRange &first, const SourceRange &second);
void PrintTo(const SourceRange &sourceRange, ::std::ostream* os); std::ostream &operator<<(std::ostream &os, const SourceRange &sourceRange);
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -97,12 +97,14 @@ bool UnsavedFile::replaceAt(uint position, uint length, const Utf8String &replac
return false; return false;
} }
void PrintTo(const UnsavedFile &unsavedFile, std::ostream *os) std::ostream &operator<<(std::ostream &os, const UnsavedFile &unsavedFile)
{ {
*os << "UnsavedFile(" os << "UnsavedFile("
<< unsavedFile.m_filePath.constData() << ", " << unsavedFile.m_filePath << ", "
<< unsavedFile.m_fileContent.constData() << ", " << unsavedFile.m_fileContent << ", "
<< unsavedFile.m_fileContent.byteSize() << ")"; << unsavedFile.m_fileContent << ")";
return os;
} }
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -34,7 +34,7 @@ using uint = unsigned int;
class UnsavedFile class UnsavedFile
{ {
public: public:
friend void PrintTo(const UnsavedFile &unsavedFile, std::ostream *os); friend std::ostream &operator<<(std::ostream &os, const UnsavedFile &unsavedFile);
UnsavedFile(); UnsavedFile();
UnsavedFile(const Utf8String &filePath, const Utf8String &fileContent); UnsavedFile(const Utf8String &filePath, const Utf8String &fileContent);