Add cpp_file
This commit is contained in:
parent
865217a190
commit
170c4045e2
6 changed files with 91 additions and 8 deletions
|
|
@ -55,7 +55,7 @@ namespace cppast
|
||||||
type_safe::optional_ref<cpp_entity> parent_;
|
type_safe::optional_ref<cpp_entity> parent_;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
|
|
||||||
friend detail::intrusive_list_access<cpp_entity>;
|
friend detail::intrusive_list<cpp_entity>;
|
||||||
};
|
};
|
||||||
} // namespace cppast
|
} // namespace cppast
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace cppast
|
||||||
/// All possible types of C++ entities.
|
/// All possible types of C++ entities.
|
||||||
enum class cpp_entity_type
|
enum class cpp_entity_type
|
||||||
{
|
{
|
||||||
|
file_t,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \returns Whether or not a given entity type is one derived from [cppast::cpp_scope]().
|
/// \returns Whether or not a given entity type is one derived from [cppast::cpp_scope]().
|
||||||
|
|
|
||||||
69
include/cppast/cpp_file.hpp
Normal file
69
include/cppast/cpp_file.hpp
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
// 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_FILE_HPP_INCLUDED
|
||||||
|
#define CPPAST_CPP_FILE_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <cppast/cpp_entity.hpp>
|
||||||
|
|
||||||
|
namespace cppast
|
||||||
|
{
|
||||||
|
/// A [cppast::cpp_entity]() referring to a file.
|
||||||
|
///
|
||||||
|
/// This is the top-level entity of the AST.
|
||||||
|
class cpp_file final : public cpp_entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// Builds a [cppast::cpp_file]().
|
||||||
|
class builder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// \effects Sets the file name.
|
||||||
|
explicit builder(std::string name) : file_(new cpp_file(std::move(name)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \effects Adds an entity.
|
||||||
|
void add_child(std::unique_ptr<cpp_entity> child) noexcept
|
||||||
|
{
|
||||||
|
file_->children_.push_back(std::move(child));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \returns The finished file.
|
||||||
|
std::unique_ptr<cpp_file> finish() noexcept
|
||||||
|
{
|
||||||
|
return std::move(file_);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<cpp_file> file_;
|
||||||
|
};
|
||||||
|
|
||||||
|
using iterator = detail::intrusive_list<cpp_entity>::const_iterator;
|
||||||
|
|
||||||
|
/// \returns A const iterator to the first child.
|
||||||
|
iterator begin() const noexcept
|
||||||
|
{
|
||||||
|
return children_.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \returns A const iterator to the last child.
|
||||||
|
iterator end() const noexcept
|
||||||
|
{
|
||||||
|
return children_.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
cpp_file(std::string name) : cpp_entity(nullptr, std::move(name))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \returns [cpp_entity_type::file_t]().
|
||||||
|
cpp_entity_type do_get_entity_type() const noexcept override;
|
||||||
|
|
||||||
|
detail::intrusive_list<cpp_entity> children_;
|
||||||
|
};
|
||||||
|
} // namespace cppast
|
||||||
|
|
||||||
|
#endif // CPPAST_CPP_FILE_HPP_INCLUDED
|
||||||
|
|
@ -16,9 +16,6 @@ namespace cppast
|
||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template <typename T>
|
|
||||||
class intrusive_list;
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class intrusive_list_node
|
class intrusive_list_node
|
||||||
{
|
{
|
||||||
|
|
@ -103,7 +100,8 @@ namespace cppast
|
||||||
|
|
||||||
T* cur_;
|
T* cur_;
|
||||||
|
|
||||||
friend intrusive_list<T>;
|
template <typename U>
|
||||||
|
friend class intrusive_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
@ -115,12 +113,12 @@ namespace cppast
|
||||||
//=== modifiers ===//
|
//=== modifiers ===//
|
||||||
void push_back(std::unique_ptr<T> obj) noexcept
|
void push_back(std::unique_ptr<T> obj) noexcept
|
||||||
{
|
{
|
||||||
DEBUG_ASSERT(obj, detail::assert_handler{});
|
DEBUG_ASSERT(obj != nullptr, detail::assert_handler{});
|
||||||
|
|
||||||
if (last_)
|
if (last_)
|
||||||
{
|
{
|
||||||
auto ptr = intrusive_list_access<T>::set_next(last_.value(), std::move(obj));
|
auto ptr = intrusive_list_access<T>::set_next(last_.value(), std::move(obj));
|
||||||
last_ = type_safe::opt_cref(ptr);
|
last_ = *ptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ bool cppast::is_scope(cpp_entity_type type) noexcept
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
case cpp_entity_type::file_t:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
14
src/cpp_file.cpp
Normal file
14
src/cpp_file.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_file.hpp>
|
||||||
|
|
||||||
|
#include <cppast/cpp_entity_type.hpp>
|
||||||
|
|
||||||
|
using namespace cppast;
|
||||||
|
|
||||||
|
cpp_entity_type cpp_file::do_get_entity_type() const noexcept
|
||||||
|
{
|
||||||
|
return cpp_entity_type::file_t;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue