Add cpp_function

This commit is contained in:
Jonathan Müller 2017-01-22 22:01:40 +01:00
commit ddadcfe88c
11 changed files with 338 additions and 42 deletions

View file

@ -36,6 +36,11 @@ const char* cppast::to_string(cpp_entity_kind kind) noexcept
case cpp_entity_kind::variable_t:
return "variable";
case cpp_entity_kind::function_parameter_t:
return "function parameter";
case cpp_entity_kind::function_t:
return "function";
case cpp_entity_kind::count:
break;
}
@ -59,6 +64,8 @@ bool cppast::is_type(cpp_entity_kind kind) noexcept
case cpp_entity_kind::using_declaration_t:
case cpp_entity_kind::enum_value_t:
case cpp_entity_kind::variable_t:
case cpp_entity_kind::function_parameter_t:
case cpp_entity_kind::function_t:
case cpp_entity_kind::count:
break;
}

29
src/cpp_function.cpp Normal file
View file

@ -0,0 +1,29 @@
// 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_function.hpp>
#include <cppast/cpp_entity_kind.hpp>
using namespace cppast;
std::unique_ptr<cpp_function_parameter> cpp_function_parameter::build(
const cpp_entity_index& idx, cpp_entity_id id, std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def)
{
auto result = std::unique_ptr<cpp_function_parameter>(
new cpp_function_parameter(std::move(name), std::move(type), std::move(def)));
idx.register_entity(std::move(id), type_safe::cref(*result));
return result;
}
cpp_entity_kind cpp_function_parameter::do_get_entity_kind() const noexcept
{
return cpp_entity_kind::function_parameter_t;
}
cpp_entity_kind cpp_function::do_get_entity_kind() const noexcept
{
return cpp_entity_kind::function_t;
}

View file

@ -69,7 +69,7 @@ bool cppast::is_valid(const cpp_type& type) noexcept
if (!can_compose(func.return_type()) || !is_valid(func.return_type()))
return false;
for (auto& arg : func.argument_types())
for (auto& arg : func.parameter_types())
if (!can_compose(arg) || !is_valid(arg))
return false;
@ -84,7 +84,7 @@ bool cppast::is_valid(const cpp_type& type) noexcept
else if (!can_compose(func.return_type()) || !is_valid(func.return_type()))
return false;
for (auto& arg : func.argument_types())
for (auto& arg : func.parameter_types())
if (!can_compose(arg) || !is_valid(arg))
return false;

View file

@ -11,10 +11,10 @@ using namespace cppast;
std::unique_ptr<cpp_variable> cpp_variable::build(const cpp_entity_index& idx, cpp_entity_id id,
std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def,
cpp_variable_specifiers spec)
cpp_storage_specifiers spec, bool is_constexpr)
{
auto result = std::unique_ptr<cpp_variable>(
new cpp_variable(std::move(name), std::move(type), std::move(def), spec));
new cpp_variable(std::move(name), std::move(type), std::move(def), spec, is_constexpr));
idx.register_entity(std::move(id), type_safe::cref(*result));
return result;
}

View file

@ -8,6 +8,7 @@
#include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_enum.hpp>
#include <cppast/cpp_file.hpp>
#include <cppast/cpp_function.hpp>
#include <cppast/cpp_language_linkage.hpp>
#include <cppast/cpp_namespace.hpp>
@ -44,6 +45,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::function_t:
return handle_container<cpp_function>(e, cb, functor);
case cpp_entity_kind::namespace_alias_t:
case cpp_entity_kind::using_directive_t:
@ -51,6 +54,7 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun
case cpp_entity_kind::type_alias_t:
case cpp_entity_kind::enum_value_t:
case cpp_entity_kind::variable_t:
case cpp_entity_kind::function_parameter_t:
return cb(functor, e, visitor_info::leaf_entity);
case cpp_entity_kind::count: