Parse cpp_variable
This commit is contained in:
parent
76f4136c86
commit
51bdbca81d
12 changed files with 281 additions and 58 deletions
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <cppast/cpp_entity.hpp>
|
||||
#include <cppast/cpp_entity_container.hpp>
|
||||
#include <cppast/cpp_storage_specifiers.hpp>
|
||||
#include <cppast/cpp_storage_class_specifiers.hpp>
|
||||
#include <cppast/cpp_variable_base.hpp>
|
||||
|
||||
namespace cppast
|
||||
|
|
@ -157,7 +157,7 @@ namespace cppast
|
|||
}
|
||||
|
||||
/// \effects Sets the storage class.
|
||||
void storage_class(cpp_storage_specifiers storage)
|
||||
void storage_class(cpp_storage_class_specifiers storage)
|
||||
{
|
||||
function->storage_ = storage;
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ namespace cppast
|
|||
/// \returns The [cppast::cpp_storage_specifiers]() of the function.
|
||||
/// \notes If it is `cpp_storage_class_static` and inside a [cppast::cpp_class](),
|
||||
/// it is a `static` class function.
|
||||
cpp_storage_specifiers storage_class() const noexcept
|
||||
cpp_storage_class_specifiers storage_class() const noexcept
|
||||
{
|
||||
return storage_;
|
||||
}
|
||||
|
|
@ -207,16 +207,16 @@ namespace cppast
|
|||
cpp_function(std::string name, std::unique_ptr<cpp_type> ret)
|
||||
: cpp_function_base(std::move(name)),
|
||||
return_type_(std::move(ret)),
|
||||
storage_(cpp_storage_class_none),
|
||||
storage_(cpp_storage_class_auto),
|
||||
friend_(false),
|
||||
constexpr_(false)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<cpp_type> return_type_;
|
||||
cpp_storage_specifiers storage_;
|
||||
bool friend_;
|
||||
bool constexpr_;
|
||||
std::unique_ptr<cpp_type> return_type_;
|
||||
cpp_storage_class_specifiers storage_;
|
||||
bool friend_;
|
||||
bool constexpr_;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
||||
|
|
|
|||
53
include/cppast/cpp_storage_class_specifiers.hpp
Normal file
53
include/cppast/cpp_storage_class_specifiers.hpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// 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_STORAGE_CLASS_SPECIFIERS_HPP_INCLUDED
|
||||
#define CPPAST_CPP_STORAGE_CLASS_SPECIFIERS_HPP_INCLUDED
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// C++ storage class specifiers.
|
||||
///
|
||||
/// See http://en.cppreference.com/w/cpp/language/storage_duration, for example.
|
||||
enum cpp_storage_class_specifiers
|
||||
{
|
||||
cpp_storage_class_none = 0, //< no storage class specifier given.
|
||||
|
||||
cpp_storage_class_auto = 1, //< *automatic* storage duration.
|
||||
|
||||
cpp_storage_class_static =
|
||||
2, //< *static* or *thread* storage duration and *internal* linkage.
|
||||
cpp_storage_class_extern =
|
||||
4, //< *static* or *thread* storage duration and *external* linkage.
|
||||
|
||||
cpp_storage_class_thread_local = 8, //< *thread* storage duration.
|
||||
/// \notes This is the only one that can be combined with the others.
|
||||
};
|
||||
|
||||
/// \returns Whether the [cppast::cpp_storage_class_specifiers]() contain `thread_local`.
|
||||
inline bool is_thread_local(cpp_storage_class_specifiers spec) noexcept
|
||||
{
|
||||
return (spec & cpp_storage_class_thread_local) != 0;
|
||||
}
|
||||
|
||||
/// \returns Whether the [cppast::cpp_storage_class_speicifers]() contain `auto`.
|
||||
inline bool is_auto(cpp_storage_class_specifiers spec) noexcept
|
||||
{
|
||||
return (spec & cpp_storage_class_auto) != 0;
|
||||
}
|
||||
|
||||
/// \returns Whether the [cppast::cpp_storage_class_specifiers]() contain `static`.
|
||||
inline bool is_static(cpp_storage_class_specifiers spec) noexcept
|
||||
{
|
||||
return (spec & cpp_storage_class_static) != 0;
|
||||
}
|
||||
|
||||
/// \returns Whether the [cppast::cpp_storage_class_specifiers]() contain `extern`.
|
||||
inline bool is_extern(cpp_storage_class_specifiers spec) noexcept
|
||||
{
|
||||
return (spec & cpp_storage_class_extern) != 0;
|
||||
}
|
||||
} // namespace cppast
|
||||
|
||||
#endif // CPPAST_CPP_STORAGE_CLASS_SPECIFIERS_HPP_INCLUDED
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
// 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_STORAGE_SPECIFIERS_HPP_INCLUDED
|
||||
#define CPPAST_CPP_STORAGE_SPECIFIERS_HPP_INCLUDED
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// C++ storage class specifiers.
|
||||
enum cpp_storage_specifiers
|
||||
{
|
||||
cpp_storage_class_none = 0,
|
||||
|
||||
cpp_storage_class_static = 1,
|
||||
cpp_storage_class_extern = 2,
|
||||
|
||||
cpp_storage_class_thread_local = 4,
|
||||
};
|
||||
|
||||
/// \returns Whether the [cppast::cpp_storage_specifiers]() contain `thread_local`.
|
||||
inline bool is_thread_local(cpp_storage_specifiers spec) noexcept
|
||||
{
|
||||
return (spec & cpp_storage_class_thread_local) != 0;
|
||||
}
|
||||
|
||||
/// \returns Whether the [cppast::cpp_storage_specifiers]() contain `static`.
|
||||
inline bool is_static(cpp_storage_specifiers spec) noexcept
|
||||
{
|
||||
return (spec & cpp_storage_class_static) != 0;
|
||||
}
|
||||
|
||||
/// \returns Whether the [cppast::cpp_storage_specifiers]() contain `extern`.
|
||||
inline bool is_extern(cpp_storage_specifiers spec) noexcept
|
||||
{
|
||||
return (spec & cpp_storage_class_extern) != 0;
|
||||
}
|
||||
} // namespace cppast
|
||||
|
||||
#endif // CPPAST_CPP_STORAGE_SPECIFIERS_HPP_INCLUDED
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
#define CPPAST_CPP_VARIABLE_HPP_INCLUDED
|
||||
|
||||
#include <cppast/cpp_entity.hpp>
|
||||
#include <cppast/cpp_storage_specifiers.hpp>
|
||||
#include <cppast/cpp_storage_class_specifiers.hpp>
|
||||
#include <cppast/cpp_variable_base.hpp>
|
||||
|
||||
namespace cppast
|
||||
|
|
@ -17,15 +17,18 @@ namespace cppast
|
|||
class cpp_variable final : public cpp_entity, public cpp_variable_base
|
||||
{
|
||||
public:
|
||||
static cpp_entity_kind kind() noexcept;
|
||||
|
||||
/// \returns A newly created and registered variable.
|
||||
/// \notes The default value may be `nullptr` indicating no default value.
|
||||
static std::unique_ptr<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_storage_specifiers spec, bool is_constexpr);
|
||||
cpp_storage_class_specifiers spec,
|
||||
bool is_constexpr);
|
||||
|
||||
/// \returns The [cppast::cpp_storage_specifiers]() on that variable.
|
||||
cpp_storage_specifiers storage_class() const noexcept
|
||||
cpp_storage_class_specifiers storage_class() const noexcept
|
||||
{
|
||||
return storage_;
|
||||
}
|
||||
|
|
@ -38,7 +41,7 @@ namespace cppast
|
|||
|
||||
private:
|
||||
cpp_variable(std::string name, std::unique_ptr<cpp_type> type,
|
||||
std::unique_ptr<cpp_expression> def, cpp_storage_specifiers spec,
|
||||
std::unique_ptr<cpp_expression> def, cpp_storage_class_specifiers spec,
|
||||
bool is_constexpr)
|
||||
: cpp_entity(std::move(name)),
|
||||
cpp_variable_base(std::move(type), std::move(def)),
|
||||
|
|
@ -49,8 +52,8 @@ namespace cppast
|
|||
|
||||
cpp_entity_kind do_get_entity_kind() const noexcept override;
|
||||
|
||||
cpp_storage_specifiers storage_;
|
||||
bool is_constexpr_;
|
||||
cpp_storage_class_specifiers storage_;
|
||||
bool is_constexpr_;
|
||||
};
|
||||
} // namespace cppast
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue