Add cpp_macro_definition
This commit is contained in:
parent
78157d43fc
commit
54b6c86e5b
5 changed files with 86 additions and 0 deletions
|
|
@ -14,6 +14,8 @@ namespace cppast
|
|||
{
|
||||
file_t,
|
||||
|
||||
macro_definition_t,
|
||||
|
||||
language_linkage_t,
|
||||
|
||||
namespace_t,
|
||||
|
|
|
|||
64
include/cppast/cpp_preprocessor.hpp
Normal file
64
include/cppast/cpp_preprocessor.hpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
// 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.
|
||||
|
||||
#ifndef CPPAST_CPP_PREPROCESSOR_HPP_INCLUDED
|
||||
#define CPPAST_CPP_PREPROCESSOR_HPP_INCLUDED
|
||||
|
||||
#include <type_safe/optional.hpp>
|
||||
|
||||
#include <cppast/cpp_entity.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// A [cppast::cpp_entity]() modelling a macro definition.
|
||||
class cpp_macro_definition final : public cpp_entity
|
||||
{
|
||||
public:
|
||||
/// \returns A newly built macro definition.
|
||||
/// \notes It is not meant to be registered in the [cppast::cpp_entity_index](),
|
||||
/// as no other [cppast::cpp_entity]() can refer to it.
|
||||
static std::unique_ptr<cpp_macro_definition> build(
|
||||
std::string name, type_safe::optional<std::string> parameters, std::string replacement)
|
||||
{
|
||||
return std::unique_ptr<cpp_macro_definition>(
|
||||
new cpp_macro_definition(std::move(name), std::move(parameters),
|
||||
std::move(replacement)));
|
||||
}
|
||||
|
||||
/// \returns The replacement text of the macro.
|
||||
const std::string& replacement() const noexcept
|
||||
{
|
||||
return replacement_;
|
||||
}
|
||||
|
||||
/// \returns Whether or not it is a function like macro.
|
||||
bool is_function_like() const noexcept
|
||||
{
|
||||
return parameters_.has_value();
|
||||
}
|
||||
|
||||
/// \returns The parameters of the macro, as the string spelled out in the source code.
|
||||
/// \notes It has none if it is not a function like macro.
|
||||
const type_safe::optional<std::string>& parameters() const noexcept
|
||||
{
|
||||
return parameters_;
|
||||
}
|
||||
|
||||
private:
|
||||
cpp_entity_kind do_get_entity_kind() const noexcept override;
|
||||
|
||||
cpp_macro_definition(std::string name, type_safe::optional<std::string> parameters,
|
||||
std::string replacement)
|
||||
: cpp_entity(std::move(name)),
|
||||
parameters_(std::move(parameters)),
|
||||
replacement_(std::move(replacement))
|
||||
{
|
||||
}
|
||||
|
||||
type_safe::optional<std::string> parameters_;
|
||||
std::string replacement_;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
||||
#endif // CPPAST_CPP_PREPROCESSOR_HPP_INCLUDED
|
||||
|
|
@ -13,6 +13,9 @@ const char* cppast::to_string(cpp_entity_kind kind) noexcept
|
|||
case cpp_entity_kind::file_t:
|
||||
return "file";
|
||||
|
||||
case cpp_entity_kind::macro_definition_t:
|
||||
return "macro definition";
|
||||
|
||||
case cpp_entity_kind::language_linkage_t:
|
||||
return "language linkage";
|
||||
|
||||
|
|
@ -97,6 +100,7 @@ bool cppast::is_type(cpp_entity_kind kind) noexcept
|
|||
return true;
|
||||
|
||||
case cpp_entity_kind::file_t:
|
||||
case cpp_entity_kind::macro_definition_t:
|
||||
case cpp_entity_kind::language_linkage_t:
|
||||
case cpp_entity_kind::namespace_t:
|
||||
case cpp_entity_kind::namespace_alias_t:
|
||||
|
|
@ -143,6 +147,7 @@ bool cppast::is_template(cpp_entity_kind kind) noexcept
|
|||
return true;
|
||||
|
||||
case cpp_entity_kind::file_t:
|
||||
case cpp_entity_kind::macro_definition_t:
|
||||
case cpp_entity_kind::language_linkage_t:
|
||||
case cpp_entity_kind::namespace_t:
|
||||
case cpp_entity_kind::namespace_alias_t:
|
||||
|
|
|
|||
14
src/cpp_preprocessor.cpp
Normal file
14
src/cpp_preprocessor.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// 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_preprocessor.hpp>
|
||||
|
||||
#include <cppast/cpp_entity_kind.hpp>
|
||||
|
||||
using namespace cppast;
|
||||
|
||||
cpp_entity_kind cpp_macro_definition::do_get_entity_kind() const noexcept
|
||||
{
|
||||
return cpp_entity_kind::macro_definition_t;
|
||||
}
|
||||
|
|
@ -77,6 +77,7 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun
|
|||
case cpp_entity_kind::class_template_specialization_t:
|
||||
return handle_container<cpp_class_template_specialization>(e, cb, functor);
|
||||
|
||||
case cpp_entity_kind::macro_definition_t:
|
||||
case cpp_entity_kind::namespace_alias_t:
|
||||
case cpp_entity_kind::using_directive_t:
|
||||
case cpp_entity_kind::using_declaration_t:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue