diff --git a/kdevplatform/CMakeLists.txt b/kdevplatform/CMakeLists.txt --- a/kdevplatform/CMakeLists.txt +++ b/kdevplatform/CMakeLists.txt @@ -4,7 +4,7 @@ # Increase this to reset incompatible item-repositories. # Changing KDEVELOP_VERSION automatically resets the itemrepository as well. -set(KDEV_ITEMREPOSITORY_INCREMENT 0) +set(KDEV_ITEMREPOSITORY_INCREMENT 1) set(KDevPlatform_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(KDevPlatform_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/kdevplatform/language/duchain/declaration.h b/kdevplatform/language/duchain/declaration.h --- a/kdevplatform/language/duchain/declaration.h +++ b/kdevplatform/language/duchain/declaration.h @@ -192,6 +192,24 @@ */ bool isExplicitlyDeleted() const; + /** + * Changes whether this declaration is explicitly typed. + * + * Explicitly typed declaration has the type writen as part of the + * declaration. The opposite, implicitly typed declaration, has the type + * deduced by the compiler. + * + * E.g. in C++ variable declarations are explicitly typed unless the "auto" + * keyword is used. + * + * \param explicitlyTyped true for explicitly typed, false for implicitly typed + */ + void setExplicitlyTyped(bool explicitlyTyped); + /** + * Determine whether this declaration is explicitly typed. + */ + bool isExplicitlyTyped() const; + /** * Retrieve the declaration which is specialized with the given * \a specialization index as seen from \a topContext. diff --git a/kdevplatform/language/duchain/declaration.cpp b/kdevplatform/language/duchain/declaration.cpp --- a/kdevplatform/language/duchain/declaration.cpp +++ b/kdevplatform/language/duchain/declaration.cpp @@ -61,6 +61,7 @@ , m_alwaysForceDirect(false) , m_isAutoDeclaration(false) , m_isExplicitlyDeleted(false) + , m_isExplicitlyTyped(false) { } @@ -511,6 +512,16 @@ d_func_dynamic()->m_isExplicitlyDeleted = deleted; } +bool Declaration::isExplicitlyTyped() const +{ + return d_func()->m_isExplicitlyTyped; +} + +void Declaration::setExplicitlyTyped(bool explicitlyTyped) +{ + d_func_dynamic()->m_isExplicitlyTyped = explicitlyTyped; +} + ///@todo see whether it would be useful to create an own TypeAliasDeclaration sub-class for this bool Declaration::isTypeAlias() const { DUCHAIN_D(Declaration); diff --git a/kdevplatform/language/duchain/declarationdata.h b/kdevplatform/language/duchain/declarationdata.h --- a/kdevplatform/language/duchain/declarationdata.h +++ b/kdevplatform/language/duchain/declarationdata.h @@ -61,6 +61,7 @@ bool m_alwaysForceDirect : 1; bool m_isAutoDeclaration : 1; bool m_isExplicitlyDeleted : 1; + bool m_isExplicitlyTyped : 1; }; } diff --git a/kdevplatform/tests/json/jsondeclarationtests.h b/kdevplatform/tests/json/jsondeclarationtests.h --- a/kdevplatform/tests/json/jsondeclarationtests.h +++ b/kdevplatform/tests/json/jsondeclarationtests.h @@ -64,6 +64,7 @@ * kind : string * isDeprecated : bool * isDefinition : bool + * isExplicitlyTyped : bool */ namespace KDevelop @@ -350,6 +351,14 @@ return compareValues(decl->isDefinition(), value, QStringLiteral("Declaration's isDefinition")); } +///JSON type: bool +///@returns whether the declaration's isExplicitlyTyped matches the given value +DeclarationTest(isExplicitlyTyped) +{ + VERIFY_NOT_NULL(decl); + return compareValues(decl->isExplicitlyTyped(), value, QStringLiteral("Declaration's isExplicitlyTyped")); +} + } } diff --git a/plugins/clang/duchain/builder.cpp b/plugins/clang/duchain/builder.cpp --- a/plugins/clang/duchain/builder.cpp +++ b/plugins/clang/duchain/builder.cpp @@ -428,6 +428,9 @@ } auto decl = new DeclType(range, nullptr); decl->setIdentifier(id); +#if CINDEX_VERSION_MINOR >= 32 + decl->setExplicitlyTyped(clang_getCursorType(cursor).kind != CXType_Auto); +#endif m_cursorToDeclarationCache[cursor] = decl; setDeclData(cursor, decl); { diff --git a/plugins/clang/tests/files/variables.cpp b/plugins/clang/tests/files/variables.cpp --- a/plugins/clang/tests/files/variables.cpp +++ b/plugins/clang/tests/files/variables.cpp @@ -10,3 +10,8 @@ void f(int); /// "internalContext" : { "localDeclarationCount" : 1} void f2(int a); + +/// "isExplicitlyTyped" : true +int a = 1; +/// "isExplicitlyTyped" : false +auto b = 2;