Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CppParser: fix for std::function<void()> parameter #4027

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CppParser/src/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,29 @@ std::string Symbol::extractName(const std::string& decl)
return "operator []";

std::string::size_type pos = decl.find('(');
if (pos != std::string::npos) {
// special case std::function<void(int)> a
// ^ ^^
// In case the marked patterns are found,
// reset pos to npos to make sure "(" is not seen as the beginning of a function
int bracket = 1;
std::string::size_type i = pos + 1;
while (i < decl.size() && bracket != 0){
if (decl[i] == '('){
bracket++;
} else if (decl[i] == ')'){
bracket--;
}

i++;
}

while (i < decl.size() && std::isspace(decl[i])) i++;
if (i < decl.size() && decl[i] == '>') {
pos = std::string::npos;
}
}

// another special case: function pointer
if (pos != std::string::npos && pos < decl.size() - 1)
{
Expand Down
16 changes: 16 additions & 0 deletions CppParser/testsuite/src/CppParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ void CppParserTest::testExtractName()
decl = "void func(int arg1, int arg2)";
name = Symbol::extractName(decl);
assertTrue (name == "func");

decl = "std::function<bool> func";
name = Symbol::extractName(decl);
assertTrue (name == "func");

decl = "std::function<void(bool)> func";
name = Symbol::extractName(decl);
assertTrue (name == "func");

decl = "std::function<std::vector<int>(std::vector<bool>)> func";
name = Symbol::extractName(decl);
assertTrue (name == "func");

decl = "std::function<void*(std::function<const int*(void)>)> func";
name = Symbol::extractName(decl);
assertTrue (name == "func");

decl = "const std::vector<NS::MyType>* var";
name = Symbol::extractName(decl);
Expand Down
Loading