Add signature() to cpp_function_base
This commit is contained in:
parent
592eb0284f
commit
93d2c58f7f
8 changed files with 112 additions and 22 deletions
|
|
@ -35,6 +35,22 @@ cpp_entity_kind cpp_function_parameter::do_get_entity_kind() const noexcept
|
|||
return kind();
|
||||
}
|
||||
|
||||
std::string cpp_function_base::do_get_signature() const
|
||||
{
|
||||
std::string result = "(";
|
||||
for (auto& param : parameters())
|
||||
result += detail::to_string(param.type()) + ',';
|
||||
if (is_variadic())
|
||||
result += "...";
|
||||
|
||||
if (result.back() == ',')
|
||||
result.back() = ')';
|
||||
else
|
||||
result.push_back(')');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
cpp_entity_kind cpp_function::kind() noexcept
|
||||
{
|
||||
return cpp_entity_kind::function_t;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,23 @@
|
|||
|
||||
using namespace cppast;
|
||||
|
||||
std::string cpp_member_function_base::do_get_signature() const
|
||||
{
|
||||
auto result = cpp_function_base::do_get_signature();
|
||||
|
||||
if (is_const(cv_qualifier()))
|
||||
result += " const";
|
||||
if (is_volatile(cv_qualifier()))
|
||||
result += " volatile";
|
||||
|
||||
if (ref_qualifier() == cpp_ref_lvalue)
|
||||
result += " &";
|
||||
else if (ref_qualifier() == cpp_ref_rvalue)
|
||||
result += " &&";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
cpp_entity_kind cpp_member_function::kind() noexcept
|
||||
{
|
||||
return cpp_entity_kind::member_function_t;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <cppast/cpp_entity.hpp>
|
||||
#include <cppast/cpp_entity_kind.hpp>
|
||||
#include <cppast/cpp_function_type.hpp>
|
||||
#include <cppast/cpp_type_alias.hpp>
|
||||
#include <cppast/cpp_template.hpp>
|
||||
|
||||
using namespace cppast;
|
||||
|
|
@ -545,3 +546,37 @@ void detail::write_type(code_generator::output& output, const cpp_type& type, st
|
|||
output << operator_ws << punctuation("...") << operator_ws;
|
||||
write_type_suffix(output, type);
|
||||
}
|
||||
|
||||
std::string detail::to_string(const cpp_type& type)
|
||||
{
|
||||
class to_string_generator : public code_generator
|
||||
{
|
||||
public:
|
||||
std::string get()
|
||||
{
|
||||
return std::move(result_);
|
||||
}
|
||||
|
||||
private:
|
||||
void do_indent() override
|
||||
{
|
||||
}
|
||||
|
||||
void do_unindent() override
|
||||
{
|
||||
}
|
||||
|
||||
void do_write_token_seq(string_view tokens) override
|
||||
{
|
||||
result_ += tokens.c_str();
|
||||
}
|
||||
|
||||
std::string result_;
|
||||
} generator;
|
||||
|
||||
// just a dummy type for the output
|
||||
static auto dummy_entity = cpp_type_alias::build("foo", cpp_builtin_type::build(cpp_int));
|
||||
to_string_generator::output output(type_safe::ref(generator), type_safe::ref(*dummy_entity));
|
||||
write_type(output, type, "");
|
||||
return generator.get();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue