Commit 54585bcd authored by Milian Wolff's avatar Milian Wolff

Fix ClangUtils::getDefaultArguments when encountering macros

Use ClangUtils::getRawContents instead of manual tokenization. This
is apparently more reliable and gives us the user-written text which
is imo the best we can hope for. I.e. now the user will see e.g.

    foo(int a = INT_MAX)

Which is way more expressive then us displaying the macro value.
We may want to replace more usages of clang_getTokenSpelling with
ClangUtils::getRawContents...

BUG: 369546
parent e962535f
Pipeline #13556 passed with stage
in 49 minutes and 33 seconds
......@@ -33,3 +33,12 @@ int foodef(int a = 1);
/// "b" : { "defaultParameter" : "3" }
/// } }
int foo(int sure, int a = 4, int b = 3);
#define FOO 1
#define BAR 2
/// "internalContext" : { "localDeclarationCount" : 4, "findDeclarations" : {
/// "a" : { "defaultParameter" : "FOO" },
/// "b" : { "defaultParameter" : "BAR" },
/// "c" : { "defaultParameter" : "3" }
/// } }
int foobar(int sure, int a = FOO, int b = BAR, int c = 3);
......@@ -144,11 +144,7 @@ CXChildVisitResult paramVisitor(CXCursor cursor, CXCursor /*parent*/, CXClientDa
//the declaration or definition, and the default arguments don't have lexical
//parents. So this range check is the only thing that really works.
if ((info->fileName.isEmpty() || fileName == info->fileName) && info->range.contains(range.toRange())) {
const ClangTokens tokens(info->unit, range.range());
info->stringParts.reserve(info->stringParts.size() + tokens.size());
for (CXToken token : tokens) {
info->stringParts.append(ClangString(clang_getTokenSpelling(info->unit, token)).toString());
}
info->stringParts.append(ClangUtils::getRawContents(info->unit, range.range()));
}
return CXChildVisit_Continue;
}
......
Markdown is supported
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