Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Dec 17, 2024
1 parent acc6f98 commit 086d098
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
65 changes: 65 additions & 0 deletions include/boost/dll/detail/demangling/msvc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,71 @@ namespace parser
return (*this)(boost::core::string_view(e.demangled.data(), e.demangled.size()));
}
};

template <class Signature>
class is_function_with_name;

template <class Result, class... Args>
class is_function_with_name<Result(*)(Args...)> {
const std::string function_name_;
const mangled_storage_impl& ms_;

public:
is_function_with_name(std::string function_name, const mangled_storage_impl& ms)
: function_name_(std::move(function_name)), ms_(ms) {}

inline bool operator()(boost::core::string_view s) const {
{
const auto visibility_pos = parser::find_visibility(s);
if (visibility_pos != std::string::npos) {
s.remove_prefix(visibility_pos);
s = trim_prefix(s, " static ");
}
}
{
const auto type_pos = parser::find_type<Result>(ms_, s);
if (type_pos == std::string::npos) {
return false;
}
s.remove_prefix(type_pos);
}
if (!s.starts_with(" __cdecl ")) {
return false;
}
s.remove_prefix(sizeof(" __cdecl ") - 1);

if (!s.starts_with(function_name_)) {
return false;
}
s.remove_prefix(function_name_.size());

if (!s.starts_with("(")) {
return false;
}
s.remove_prefix(1);

{
using Signature = Result(*)(Args...);
const auto arg_list_pos = parser::find_arg_list(ms_, s, Signature());
if (arg_list_pos == std::string::npos) {
return false;
}
s.remove_prefix(arg_list_pos);
}

if (!s.starts_with(")")) {
return false;
}
s.remove_prefix(1);

s = parser::trim_ptrs(s);
return s.empty();
}

inline bool operator()(const mangled_storage_base::entry& e) const {
return (*this)(boost::core::string_view(e.demangled.data(), e.demangled.size()));
}
};
}


Expand Down
11 changes: 11 additions & 0 deletions test/cpp_mangling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ int main(int argc, char* argv[])
("double const unscoped_c_var")
));


BOOST_TEST((
parser::is_function_with_name<void(*)(int)>("overloaded", ms)
("void __cdecl overloaded(int)")
));

BOOST_TEST((
parser::is_function_with_name<void(*)(double)>("overloaded", ms)
("void __cdecl overloaded(double)")
));

return boost::report_errors();
}
#else
Expand Down

0 comments on commit 086d098

Please sign in to comment.