forked from qt-creator/qt-creator
Clang: Highlight invalid declarations as text
...instead of the corresponding declaration color. Task-number: QTCREATORBUG-18686 Change-Id: Ice4d84816351af79efa286f49516c392bd80da86 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -41,4 +41,9 @@ enum class PreferredTranslationUnit
|
|||||||
# define IS_PRETTY_DECL_SUPPORTED
|
# define IS_PRETTY_DECL_SUPPORTED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// CLANG-UPGRADE-CHECK: Remove IS_INVALIDDECL_SUPPORTED once we require clang >= 7.0
|
||||||
|
#if defined(CINDEX_VERSION_HAS_ISINVALIDECL_BACKPORTED) || CINDEX_VERSION_MINOR >= 46
|
||||||
|
# define IS_INVALIDDECL_SUPPORTED
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
@@ -29,6 +29,8 @@
|
|||||||
#include "sourcelocation.h"
|
#include "sourcelocation.h"
|
||||||
#include "sourcerange.h"
|
#include "sourcerange.h"
|
||||||
|
|
||||||
|
#include "clangbackend_global.h"
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
@@ -103,6 +105,15 @@ bool Cursor::isDeclaration() const
|
|||||||
return clang_isDeclaration(kind());
|
return clang_isDeclaration(kind());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Cursor::isInvalidDeclaration() const
|
||||||
|
{
|
||||||
|
#ifdef IS_INVALIDDECL_SUPPORTED
|
||||||
|
return clang_isInvalidDeclaration(cxCursor);
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool Cursor::isLocalVariable() const
|
bool Cursor::isLocalVariable() const
|
||||||
{
|
{
|
||||||
switch (semanticParent().kind()) {
|
switch (semanticParent().kind()) {
|
||||||
|
@@ -61,6 +61,7 @@ public:
|
|||||||
bool isStaticMethod() const;
|
bool isStaticMethod() const;
|
||||||
bool isCompoundType() const;
|
bool isCompoundType() const;
|
||||||
bool isDeclaration() const;
|
bool isDeclaration() const;
|
||||||
|
bool isInvalidDeclaration() const;
|
||||||
bool isLocalVariable() const;
|
bool isLocalVariable() const;
|
||||||
bool isReference() const;
|
bool isReference() const;
|
||||||
bool isExpression() const;
|
bool isExpression() const;
|
||||||
|
@@ -308,6 +308,9 @@ void TokenInfo::identifierKind(const Cursor &cursor, Recursion recursion)
|
|||||||
{
|
{
|
||||||
m_isIdentifier = (cursor.kind() != CXCursor_PreprocessingDirective);
|
m_isIdentifier = (cursor.kind() != CXCursor_PreprocessingDirective);
|
||||||
|
|
||||||
|
if (cursor.isInvalidDeclaration())
|
||||||
|
return;
|
||||||
|
|
||||||
switch (cursor.kind()) {
|
switch (cursor.kind()) {
|
||||||
case CXCursor_Destructor:
|
case CXCursor_Destructor:
|
||||||
case CXCursor_Constructor:
|
case CXCursor_Constructor:
|
||||||
|
@@ -39,3 +39,9 @@
|
|||||||
#else
|
#else
|
||||||
# define DISABLED_WITHOUT_PRETTYDECL_PATCH(x) DISABLED_##x
|
# define DISABLED_WITHOUT_PRETTYDECL_PATCH(x) DISABLED_##x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef IS_INVALIDDECL_SUPPORTED
|
||||||
|
# define DISABLED_WITHOUT_INVALIDDECL_PATCH(x) x
|
||||||
|
#else
|
||||||
|
# define DISABLED_WITHOUT_INVALIDDECL_PATCH(x) DISABLED_##x
|
||||||
|
#endif
|
||||||
|
@@ -588,3 +588,5 @@ void BaseClass::VirtualFunction() {}
|
|||||||
class WithVirtualFunctionDefined {
|
class WithVirtualFunctionDefined {
|
||||||
virtual void VirtualFunctionDefinition() {};
|
virtual void VirtualFunctionDefinition() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Undeclared u;
|
||||||
|
@@ -1246,6 +1246,20 @@ TEST_F(TokenInfos, DefineIsNotIdentifier)
|
|||||||
ASSERT_THAT(container.isIncludeDirectivePath(), false);
|
ASSERT_THAT(container.isIncludeDirectivePath(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TokenInfos, DISABLED_WITHOUT_INVALIDDECL_PATCH(TypeNameOfInvalidDeclarationIsInvalid))
|
||||||
|
{
|
||||||
|
const auto infos = translationUnit.tokenInfosInRange(sourceRange(592, 14));
|
||||||
|
|
||||||
|
ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Invalid));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TokenInfos, DISABLED_WITHOUT_INVALIDDECL_PATCH(VariableNameOfInvalidDeclarationIsInvalid))
|
||||||
|
{
|
||||||
|
const auto infos = translationUnit.tokenInfosInRange(sourceRange(592, 14));
|
||||||
|
|
||||||
|
ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid));
|
||||||
|
}
|
||||||
|
|
||||||
Data *TokenInfos::d;
|
Data *TokenInfos::d;
|
||||||
|
|
||||||
void TokenInfos::SetUpTestCase()
|
void TokenInfos::SetUpTestCase()
|
||||||
|
Reference in New Issue
Block a user