Add forward declarations (#116)
This commit is contained in:
parent
87591d8cc9
commit
5069f2f167
21 changed files with 163 additions and 40 deletions
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
namespace cppast
|
||||
{
|
||||
enum cpp_access_specifier_kind : int;
|
||||
|
||||
/// A simple string view implementation, like [std::string_view]().
|
||||
///
|
||||
/// It "views" - stores a pointer to - some kind of string.
|
||||
|
|
@ -521,12 +519,6 @@ private:
|
|||
/// \returns Whether or not any code was actually written.
|
||||
bool generate_code(code_generator& generator, const cpp_entity& e);
|
||||
|
||||
/// \exclude
|
||||
class cpp_template_argument;
|
||||
|
||||
/// \exclude
|
||||
class cpp_token_string;
|
||||
|
||||
/// \exclude
|
||||
namespace detail
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <type_safe/reference.hpp>
|
||||
|
||||
#include <cppast/detail/assert.hpp>
|
||||
#include <cppast/cppast_fwd.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
|
|
|
|||
|
|
@ -107,8 +107,6 @@ type_safe::optional_ref<const cpp_attribute> has_attribute(const cpp_attribute_l
|
|||
type_safe::optional_ref<const cpp_attribute> has_attribute(const cpp_attribute_list& attributes,
|
||||
cpp_attribute_kind kind);
|
||||
|
||||
class cpp_entity;
|
||||
|
||||
/// \group has_attribute
|
||||
type_safe::optional_ref<const cpp_attribute> has_attribute(const cpp_entity& e,
|
||||
const std::string& name);
|
||||
|
|
|
|||
|
|
@ -16,12 +16,6 @@
|
|||
|
||||
namespace cppast
|
||||
{
|
||||
class cpp_entity;
|
||||
enum class cpp_entity_kind;
|
||||
class cpp_entity_index;
|
||||
struct cpp_entity_id;
|
||||
class cpp_template_parameter;
|
||||
class cpp_template;
|
||||
|
||||
/// The name of a scope.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -15,12 +15,10 @@
|
|||
#include <type_safe/reference.hpp>
|
||||
#include <type_safe/strong_typedef.hpp>
|
||||
|
||||
#include <cppast/cppast_fwd.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
class cpp_entity;
|
||||
class cpp_file;
|
||||
class cpp_namespace;
|
||||
|
||||
/// \exclude
|
||||
namespace detail
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#define CPPAST_CPP_ENTITY_KIND_HPP_INCLUDED
|
||||
|
||||
#include <cppast/detail/assert.hpp>
|
||||
#include <cppast/cppast_fwd.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
namespace cppast
|
||||
{
|
||||
enum class cpp_entity_kind;
|
||||
|
||||
/// A basic reference to some kind of [cppast::cpp_entity]().
|
||||
///
|
||||
|
|
|
|||
|
|
@ -86,11 +86,6 @@ private:
|
|||
/// \returns Whether or not the given entity is a definition.
|
||||
bool is_definition(const cpp_entity& e) noexcept;
|
||||
|
||||
class cpp_enum;
|
||||
class cpp_class;
|
||||
class cpp_variable;
|
||||
class cpp_function_base;
|
||||
|
||||
/// Gets the definition of an entity.
|
||||
/// \returns A [ts::optional_ref]() to the entity that is the definition.
|
||||
/// If the entity is a definition or not derived from [cppast::cpp_forward_declarable]() (only valid
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ private:
|
|||
};
|
||||
|
||||
/// The kinds of function bodies of a [cppast::cpp_function_base]().
|
||||
enum cpp_function_body_kind
|
||||
enum cpp_function_body_kind : int
|
||||
{
|
||||
cpp_function_declaration, //< Just a declaration.
|
||||
cpp_function_definition, //< Regular definition.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef CPPAST_CPP_STORAGE_CLASS_SPECIFIERS_HPP_INCLUDED
|
||||
#define CPPAST_CPP_STORAGE_CLASS_SPECIFIERS_HPP_INCLUDED
|
||||
|
||||
#include <cppast/cppast_fwd.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// C++ storage class specifiers.
|
||||
|
|
|
|||
|
|
@ -158,8 +158,6 @@ namespace detail
|
|||
};
|
||||
} // namespace detail
|
||||
|
||||
class cpp_template;
|
||||
|
||||
/// A reference to a [cppast::cpp_template]() or a [cppast::cpp_template_template_parameter]().
|
||||
using cpp_template_ref = basic_cpp_entity_ref<cpp_entity, detail::cpp_template_ref_predicate>;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include <type_safe/reference.hpp>
|
||||
|
||||
#include <cppast/cppast_fwd.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// The kinds of C++ tokens.
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ private:
|
|||
};
|
||||
|
||||
/// The C++ builtin types.
|
||||
enum cpp_builtin_type_kind
|
||||
enum cpp_builtin_type_kind : int
|
||||
{
|
||||
cpp_void, //< `void`
|
||||
|
||||
|
|
@ -246,9 +246,6 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
class cpp_template_parameter_type;
|
||||
class cpp_template_instantiation_type;
|
||||
|
||||
/// A [cppast::cpp_type]() that depends on another type.
|
||||
class cpp_dependent_type final : public cpp_type
|
||||
{
|
||||
|
|
@ -291,7 +288,7 @@ private:
|
|||
};
|
||||
|
||||
/// The kinds of C++ cv qualifiers.
|
||||
enum cpp_cv
|
||||
enum cpp_cv : int
|
||||
{
|
||||
cpp_cv_none,
|
||||
cpp_cv_const,
|
||||
|
|
@ -387,7 +384,7 @@ private:
|
|||
};
|
||||
|
||||
/// The kinds of C++ references.
|
||||
enum cpp_reference
|
||||
enum cpp_reference : int
|
||||
{
|
||||
cpp_ref_none,
|
||||
cpp_ref_lvalue,
|
||||
|
|
|
|||
127
include/cppast/cppast_fwd.hpp
Normal file
127
include/cppast/cppast_fwd.hpp
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
// Copyright (C) 2021 Julian Rüth <julian.rueth@fsfe.org>
|
||||
// This file is subject to the license terms in the LICENSE file
|
||||
// found in the top-level directory of this distribution.
|
||||
|
||||
#ifndef CPPAST_FORWARD_HPP_INCLUDED
|
||||
#define CPPAST_FORWARD_HPP_INCLUDED
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
|
||||
class code_generator;
|
||||
class compile_config;
|
||||
class cpp_access_specifier;
|
||||
class cpp_alias_template;
|
||||
class cpp_array_type;
|
||||
class cpp_attribute;
|
||||
class cpp_auto_type;
|
||||
class cpp_base_class;
|
||||
class cpp_bitfield;
|
||||
class cpp_builtin_type;
|
||||
class cpp_class;
|
||||
class cpp_class_template;
|
||||
class cpp_class_template_specialization;
|
||||
class cpp_constructor;
|
||||
class cpp_conversion_op;
|
||||
class cpp_cv_qualified_type;
|
||||
class cpp_decltype_auto_type;
|
||||
class cpp_decltype_type;
|
||||
class cpp_dependent_type;
|
||||
class cpp_destructor;
|
||||
class cpp_entity;
|
||||
class cpp_entity_index;
|
||||
class cpp_enum;
|
||||
class cpp_enum_value;
|
||||
class cpp_expression;
|
||||
class cpp_file;
|
||||
class cpp_forward_declarable;
|
||||
class cpp_friend;
|
||||
class cpp_function;
|
||||
class cpp_function_base;
|
||||
class cpp_function_parameter;
|
||||
class cpp_function_template;
|
||||
class cpp_function_template_specialization;
|
||||
class cpp_function_type;
|
||||
class cpp_include_directive;
|
||||
class cpp_language_linkage;
|
||||
class cpp_literal_expression;
|
||||
class cpp_macro_definition;
|
||||
class cpp_macro_parameter;
|
||||
class cpp_member_function;
|
||||
class cpp_member_function_base;
|
||||
class cpp_member_function_type;
|
||||
class cpp_member_object_type;
|
||||
class cpp_member_variable_base;
|
||||
class cpp_namespace;
|
||||
class cpp_non_type_template_parameter;
|
||||
class cpp_pointer_type;
|
||||
class cpp_reference_type;
|
||||
class cpp_scope_name;
|
||||
class cpp_static_assert;
|
||||
class cpp_template;
|
||||
class cpp_template_argument;
|
||||
class cpp_template_instantiation_type;
|
||||
class cpp_template_parameter;
|
||||
class cpp_template_parameter_type;
|
||||
class cpp_template_specialization;
|
||||
class cpp_template_template_parameter;
|
||||
class cpp_template_type_parameter;
|
||||
class cpp_token_string;
|
||||
class cpp_type;
|
||||
class cpp_type_alias;
|
||||
class cpp_unexposed_entity;
|
||||
class cpp_unexposed_expression;
|
||||
class cpp_unexposed_type;
|
||||
class cpp_user_defined_type;
|
||||
class cpp_using_declaration;
|
||||
class cpp_using_directive;
|
||||
class cpp_variable;
|
||||
class cpp_variable_base;
|
||||
class cpp_variable_template;
|
||||
class diagnostic_logger;
|
||||
class libclang_compilation_database;
|
||||
class libclang_compile_config;
|
||||
class libclang_error;
|
||||
class libclang_parser;
|
||||
class parser;
|
||||
class string_view;
|
||||
|
||||
enum class compile_flag;
|
||||
enum class cpp_attribute_kind;
|
||||
enum class cpp_class_kind;
|
||||
enum class cpp_entity_kind;
|
||||
enum class cpp_expression_kind;
|
||||
enum class cpp_include_kind;
|
||||
enum class cpp_standard;
|
||||
enum class cpp_template_keyword;
|
||||
enum class cpp_token_kind;
|
||||
enum class cpp_type_kind;
|
||||
enum class cpp_virtual_flags;
|
||||
enum class formatting_flags;
|
||||
enum class severity;
|
||||
enum class visit_filter;
|
||||
|
||||
enum cpp_access_specifier_kind : int;
|
||||
enum cpp_builtin_type_kind : int;
|
||||
enum cpp_cv : int;
|
||||
enum cpp_function_body_kind : int;
|
||||
enum cpp_reference : int;
|
||||
enum cpp_storage_class_specifiers : int;
|
||||
enum visitor_result : bool;
|
||||
|
||||
struct cpp_doc_comment;
|
||||
struct cpp_entity_id;
|
||||
struct cpp_token;
|
||||
struct diagnostic;
|
||||
struct newl_t;
|
||||
struct source_location;
|
||||
struct visitor_info;
|
||||
struct whitespace_t;
|
||||
|
||||
template <class Derived, typename T> class cpp_entity_container;
|
||||
template <class Parser> class simple_file_parser;
|
||||
template <typename T, typename Predicate> class basic_cpp_entity_ref;
|
||||
|
||||
} // namespace cppast
|
||||
|
||||
#endif // CPPAST_FORWARD_HPP_INCLUDED
|
||||
|
|
@ -11,10 +11,10 @@
|
|||
#include <type_safe/optional_ref.hpp>
|
||||
|
||||
#include <cppast/detail/assert.hpp>
|
||||
#include <cppast/cppast_fwd.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
class cpp_file;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include <type_safe/optional.hpp>
|
||||
|
||||
#include <cppast/cppast_fwd.hpp>
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
/// Describes a physical source location attached to a [cppast::diagnostic]().
|
||||
|
|
|
|||
|
|
@ -11,9 +11,6 @@
|
|||
|
||||
namespace cppast
|
||||
{
|
||||
class libclang_compile_config;
|
||||
class libclang_compilation_database;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct libclang_compile_config_access
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
namespace cppast
|
||||
{
|
||||
class cpp_entity_index;
|
||||
|
||||
/// Base class for a parser.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ set(header
|
|||
../include/cppast/cpp_variable_template.hpp
|
||||
../include/cppast/diagnostic.hpp
|
||||
../include/cppast/diagnostic_logger.hpp
|
||||
../include/cppast/cppast_fwd.hpp
|
||||
../include/cppast/libclang_parser.hpp
|
||||
../include/cppast/parser.hpp
|
||||
../include/cppast/visitor.hpp)
|
||||
|
|
|
|||
|
|
@ -494,6 +494,7 @@ namespace
|
|||
std::vector<const char*> get_arguments(const libclang_compile_config& config)
|
||||
{
|
||||
std::vector<const char*> args
|
||||
// TODO: Why? and Why?
|
||||
= {"-x", "c++", "-I."}; // force C++ and enable current directory for include search
|
||||
for (auto& flag : detail::libclang_compile_config_access::flags(config))
|
||||
args.push_back(flag.c_str());
|
||||
|
|
|
|||
|
|
@ -99,6 +99,25 @@ bool need_to_remove_scope(const CXCursor& cur, const CXType& type)
|
|||
|
||||
std::string get_type_spelling(const CXCursor& cur, const CXType& type)
|
||||
{
|
||||
// TODO: There are two interesting things we should keep track of here:
|
||||
// * The canonical name of a type (easy, clang has a shortcut for that)
|
||||
// * The type definition of this type, say for:
|
||||
// std::vector<int, default_alloator...> this should be the type (we
|
||||
// should ignore specialization here!) vector<T, S> whose parent is a
|
||||
// namespace in this case but could again be a concrete type as well (to
|
||||
// handle nested type specializations correctly.)
|
||||
/*
|
||||
auto ns_name = [](const CXCursor& cur) {
|
||||
auto parent = clang_getCursorSemanticParent(cur);
|
||||
if (clang_getCursorKind(parent) == CXCursor_TranslationUnit)
|
||||
return "";
|
||||
if (clang_getCursorKind(parent) == CXCursor_Namespace)
|
||||
return spelling of cursor ...
|
||||
};
|
||||
*/
|
||||
|
||||
// auto canonical = detail::cxstring(clang_getTypeSpelling(clang_getCanonicalType(type))).std_str();
|
||||
// auto declaration = detail::cxstring(clang_getCursorSpelling(clang_getTypeDeclaration(type))).std_str();
|
||||
auto spelling = detail::cxstring(clang_getTypeSpelling(type)).std_str();
|
||||
if (need_to_remove_scope(cur, type))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue