Commit 4f341479 authored by Pedro Olsen Ferreira's avatar Pedro Olsen Ferreira
Browse files

Add support for the Atomic CXType

This is used for C11 and OpenCL atomics.
Fixes cursor errors similar to:
kdevelop.plugins.clang: Unhandled type: Atomic _Atomic(char)
kdevelop.plugins.clang: Unhandled type: Atomic _Atomic(signed char)
kdevelop.plugins.clang: Unhandled type: Atomic _Atomic(unsigned char)
kdevelop.plugins.clang: Unhandled type: Atomic _Atomic(short)
parent fa0dd1b7
......@@ -818,6 +818,8 @@ QStringList AbstractDeclarationNavigationContext::declarationDetails(const Decla
details << i18nc("a variable that won't change, const", "constant");
if (t->modifiers() & AbstractType::VolatileModifier)
details << QStringLiteral("volatile");
if (t->modifiers() & AbstractType::AtomicModifier)
details << QStringLiteral("_Atomic");
}
if (function) {
if (function->isInline())
......
......@@ -139,32 +139,31 @@ QString AbstractType::toString() const
QString AbstractType::toString(bool spaceOnLeft) const
{
// TODO complete
if (!spaceOnLeft) {
if (modifiers() & ConstModifier) {
if (modifiers() & VolatileModifier) {
return QStringLiteral("const volatile ");
} else {
return QStringLiteral("const ");
}
} else {
if (modifiers() & VolatileModifier)
return QStringLiteral("volatile ");
else
return QString();
}
} else {
if (modifiers() & ConstModifier) {
if (modifiers() & VolatileModifier) {
return QStringLiteral(" const volatile");
} else {
return QStringLiteral(" const");
}
} else {
if (modifiers() & VolatileModifier)
return QStringLiteral(" volatile");
else
return QString();
}
QString modifiersStr;
if (modifiers() & ConstModifier) {
modifiersStr.append(QStringLiteral("const"));
}
if (modifiers() & VolatileModifier) {
if (!modifiersStr.isEmpty())
modifiersStr.append(QStringLiteral(" "));
modifiersStr.append(QStringLiteral("volatile"));
}
if (modifiers() & AtomicModifier) {
if (!modifiersStr.isEmpty())
modifiersStr.append(QStringLiteral(" "));
modifiersStr.append(QStringLiteral("_Atomic"));
}
if (!modifiersStr.isEmpty()) {
if (spaceOnLeft)
modifiersStr.prepend(QStringLiteral(" "));
else
modifiersStr.append(QStringLiteral(" "));
}
return modifiersStr;
}
}
......@@ -102,8 +102,9 @@ public:
LongLongModifier = 1 << 9,
SignedModifier = 1 << 10,
UnsignedModifier = 1 << 11,
AtomicModifier = 1 << 12,
LanguageSpecificModifier = 1 << 12
LanguageSpecificModifier = 1 << 13
};
/// Constructor.
......
......@@ -514,6 +514,13 @@ struct Visitor
return new IntegralType(CursorKindTraits::integralType(TK));
}
template <CXTypeKind TK, EnableIf<TK == CXType_Atomic> = dummy>
AbstractType* createType(CXType type, CXCursor parent)
{
// Decompose the atomic type.
return makeType(clang_Type_getValueType(type), parent);
}
template<CXTypeKind TK, EnableIf<CursorKindTraits::isPointerType(TK)> = dummy>
AbstractType *createType(CXType type, CXCursor parent)
{
......@@ -888,6 +895,9 @@ void Visitor::setTypeModifiers(CXType type, AbstractType* kdevType) const
if (clang_isVolatileQualifiedType(type)) {
modifiers |= AbstractType::VolatileModifier;
}
if (TK == CXType_Atomic) {
modifiers |= AbstractType::AtomicModifier;
}
if (TK == CXType_Short || TK == CXType_UShort) {
modifiers |= AbstractType::ShortModifier;
}
......@@ -1382,6 +1392,7 @@ AbstractType *Visitor::makeType(CXType type, CXCursor parent)
#if CINDEX_VERSION_MINOR >= 38
UseKind(CXType_Float128);
#endif
UseKind(CXType_Atomic);
UseKind(CXType_Complex);
case CXType_Invalid:
return nullptr;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment