I use libclang to parse source file and get reference to some type as CXType
, say it is "const std::__1::basic_string<char>
" (as reported by clang_getTypeSpelling
). How can I get reference to same type but without const qualifier?
Asked
Active
Viewed 319 times
11

kriomant
- 2,216
- 1
- 16
- 21
-
Same problem here. need to walk from a const CXType to its corresponding non const – uzul Sep 19 '18 at 04:57
1 Answers
0
I was able to do this by visiting the type's cursor's children. For example, given a CXCursor 'cursor',
CXType type = clang_getCursorType(cursor);
if (clang_isConstQualifiedType(type))
{
auto RemoveConstFromType = [](CXCursor c, CXCursor, CXClientData d)
{
*(CXType*)d = clang_getCursorType(c);
return (clang_isConstQualifiedType(*(CXType*)d) ? CXChildVisit_Recurse : CXChildVisit_Break);
};
clang_visitChildren(cursor, RemoveConstFromType, &type);
}
I hope that helps. =)

Daniel Hilburn
- 43
- 7