Add cpp_class

This commit is contained in:
Jonathan Müller 2017-01-24 19:22:25 +01:00
commit f32af61614
5 changed files with 204 additions and 1 deletions

57
src/cpp_class.cpp Normal file
View file

@ -0,0 +1,57 @@
// Copyright (C) 2017 Jonathan Müller <jonathanmueller.dev@gmail.com>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#include <cppast/cpp_class.hpp>
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_kind.hpp>
using namespace cppast;
std::unique_ptr<cpp_class> cpp_class::builder::finish(const cpp_entity_index& idx,
cpp_entity_id id) noexcept
{
idx.register_entity(std::move(id), type_safe::ref(*class_));
return std::move(class_);
}
const char* cppast::to_string(cpp_class_kind kind) noexcept
{
switch (kind)
{
case cpp_class_kind::class_t:
return "class";
case cpp_class_kind::struct_t:
return "struct";
case cpp_class_kind::union_t:
return "union";
}
return "should not get here";
}
const char* cppast::to_string(cpp_access_specifier_kind access) noexcept
{
switch (access)
{
case cpp_public:
return "public";
case cpp_protected:
return "protected";
case cpp_private:
return "private";
}
return "should not get here either";
}
cpp_entity_kind cpp_access_specifier::do_get_entity_kind() const noexcept
{
return cpp_entity_kind::access_specifier_t;
}
cpp_entity_kind cpp_class::do_get_entity_kind() const noexcept
{
return cpp_entity_kind::class_t;
}

View file

@ -33,6 +33,11 @@ const char* cppast::to_string(cpp_entity_kind kind) noexcept
case cpp_entity_kind::enum_value_t:
return "enum value";
case cpp_entity_kind::class_t:
return "class";
case cpp_entity_kind::access_specifier_t:
return "access specifier";
case cpp_entity_kind::variable_t:
return "variable";
@ -52,8 +57,9 @@ bool cppast::is_type(cpp_entity_kind kind) noexcept
{
switch (kind)
{
case cpp_entity_kind::enum_t:
case cpp_entity_kind::type_alias_t:
case cpp_entity_kind::enum_t:
case cpp_entity_kind::class_t:
return true;
case cpp_entity_kind::file_t:
@ -63,6 +69,8 @@ bool cppast::is_type(cpp_entity_kind kind) noexcept
case cpp_entity_kind::using_directive_t:
case cpp_entity_kind::using_declaration_t:
case cpp_entity_kind::enum_value_t:
case cpp_entity_kind::access_specifier_t:
break;
case cpp_entity_kind::variable_t:
case cpp_entity_kind::function_parameter_t:
case cpp_entity_kind::function_t:

View file

@ -6,6 +6,7 @@
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_class.hpp>
#include <cppast/cpp_enum.hpp>
#include <cppast/cpp_file.hpp>
#include <cppast/cpp_function.hpp>
@ -45,6 +46,8 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun
return handle_container<cpp_namespace>(e, cb, functor);
case cpp_entity_kind::enum_t:
return handle_container<cpp_enum>(e, cb, functor);
case cpp_entity_kind::class_t:
return handle_container<cpp_class>(e, cb, functor);
case cpp_entity_kind::function_t:
return handle_container<cpp_function>(e, cb, functor);
@ -53,6 +56,7 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun
case cpp_entity_kind::using_declaration_t:
case cpp_entity_kind::type_alias_t:
case cpp_entity_kind::enum_value_t:
case cpp_entity_kind::access_specifier_t:
case cpp_entity_kind::variable_t:
case cpp_entity_kind::function_parameter_t:
return cb(functor, e, visitor_info::leaf_entity);