diff options
author | Leandro Melo <leandro.melo@nokia.com> | 2011-11-14 13:14:39 +0100 |
---|---|---|
committer | Leandro Melo <leandro.melo@nokia.com> | 2011-11-15 11:12:36 +0100 |
commit | fa7c7c4ecaa829ab4ab6d6f2b5aec454d3b4b180 (patch) | |
tree | bc6f603c3a99f90984fcb842eaae7f1461c26ab4 /src/plugins/cpptools/cpptoolsreuse.cpp | |
parent | dfd58916cd20abc50536a9793952c53ce82ac72c (diff) | |
download | qt-creator-fa7c7c4ecaa829ab4ab6d6f2b5aec454d3b4b180.tar.gz |
C++: Don't show unused mark for known RAII types
Change-Id: Id552539c6a2cf5d7558adf88bed61a11ab770516
Reviewed-by: Christian Kamm <christian.d.kamm@nokia.com>
Diffstat (limited to 'src/plugins/cpptools/cpptoolsreuse.cpp')
-rw-r--r-- | src/plugins/cpptools/cpptoolsreuse.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cpptoolsreuse.cpp b/src/plugins/cpptools/cpptoolsreuse.cpp index ec1903c7a5..27b09656e7 100644 --- a/src/plugins/cpptools/cpptoolsreuse.cpp +++ b/src/plugins/cpptools/cpptoolsreuse.cpp @@ -32,9 +32,17 @@ #include "cpptoolsreuse.h" +#include <Symbols.h> +#include <CoreTypes.h> +#include <cplusplus/Overview.h> +#include <cplusplus/LookupContext.h> + +#include <QtCore/QSet> #include <QtGui/QTextDocument> #include <QtGui/QTextCursor> +using namespace CPlusPlus; + namespace CppTools { void moveCursorToEndOfIdentifier(QTextCursor *tc) { @@ -49,4 +57,50 @@ void moveCursorToEndOfIdentifier(QTextCursor *tc) { } } +static bool isOwnershipRAIIName(const QString &name) +{ + static QSet<QString> knownNames; + if (knownNames.isEmpty()) { + // Qt + knownNames.insert(QLatin1String("QScopedPointer")); + knownNames.insert(QLatin1String("QScopedArrayPointer")); + knownNames.insert(QLatin1String("QMutexLocker")); + knownNames.insert(QLatin1String("QReadLocker")); + knownNames.insert(QLatin1String("QWriteLocker")); + // Standard C++ + knownNames.insert(QLatin1String("auto_ptr")); + knownNames.insert(QLatin1String("unique_ptr")); + // Boost + knownNames.insert(QLatin1String("scoped_ptr")); + knownNames.insert(QLatin1String("scoped_array")); + } + + return knownNames.contains(name); +} + +bool isOwnershipRAIIType(CPlusPlus::Symbol *symbol, const LookupContext &context) +{ + if (!symbol) + return false; + + // This is not a "real" comparison of types. What we do is to resolve the symbol + // in question and then try to match its name with already known ones. + if (symbol->isDeclaration()) { + Declaration *declaration = symbol->asDeclaration(); + const NamedType *namedType = declaration->type()->asNamedType(); + if (namedType) { + ClassOrNamespace *clazz = context.lookupType(namedType->name(), + declaration->enclosingScope()); + if (clazz && !clazz->symbols().isEmpty()) { + Overview overview; + Symbol *symbol = clazz->symbols().at(0); + return isOwnershipRAIIName(overview.prettyName(symbol->name())); + } + } + } + + return false; +} + + } // CppTools |