Update clang-format

This commit is contained in:
Jonathan Müller 2018-09-20 19:57:03 +02:00
commit 9f18b7f4d8
89 changed files with 11377 additions and 11546 deletions

View file

@ -2,10 +2,10 @@ AccessModifierOffset: -4
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: false AlignEscapedNewlinesLeft: Right
AlignOperands: true AlignOperands: true
AlignTrailingComments: true AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty AllowShortFunctionsOnASingleLine: Empty
@ -16,28 +16,50 @@ AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true AlwaysBreakTemplateDeclarations: true
BinPackArguments: true BinPackArguments: true
BinPackParameters: true BinPackParameters: true
BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Custom
BreakBeforeBraces: Allman BraceWrapping:
BreakBeforeTernaryOperators: false AfterClass: true
BreakConstructorInitializersBeforeComma: false AfterControlStatement: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakStringLiterals: false
ColumnLimit: 100
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0 ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 4 ContinuationIndentWidth: 4
ColumnLimit: 100
Cpp11BracedListStyle: true Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: false IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4 IndentWidth: 4
IndentWrappedFunctionNames: true IndentWrappedFunctionNames: true
Language: Cpp
KeepEmptyLinesAtTheStartOfBlocks: false KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1 MaxEmptyLinesToKeep: 1
NamespaceIndentation: All NamespaceIndentation: Inner
PenaltyBreakBeforeFirstCallParameter: 19937 PenaltyBreakBeforeFirstCallParameter: 19937
PenaltyReturnTypeOnItsOwnLine: 19937 PenaltyReturnTypeOnItsOwnLine: 19937
PointerAlignment: Left PointerAlignment: Left
ReflowComments: false ReflowComments: true
SortIncludes: false SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false SpaceInEmptyParentheses: false

View file

@ -5,7 +5,8 @@
/// \file /// \file
/// Generate equality comparisons. /// Generate equality comparisons.
/// ///
/// Given an input file, it will generate comparison operators for each class that has the [[generate::comparison]] attribute. /// Given an input file, it will generate comparison operators for each class that has the
/// [[generate::comparison]] attribute.
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
@ -94,8 +95,8 @@ void generate_comparison(const cppast::cpp_file& file)
{ {
// it is a new class // it is a new class
auto& class_ = static_cast<const cppast::cpp_class&>(e); auto& class_ = static_cast<const cppast::cpp_class&>(e);
auto& attribute = auto& attribute
cppast::has_attribute(e, "generate::comparison").value(); = cppast::has_attribute(e, "generate::comparison").value();
// generate requested operators // generate requested operators
if (attribute.arguments()) if (attribute.arguments())

View file

@ -5,8 +5,9 @@
/// \file /// \file
/// Generates enum category functions. /// Generates enum category functions.
/// ///
/// Given an input file, it will generate definitions for functions marked with [[generate::enum_category(name)]]. /// Given an input file, it will generate definitions for functions marked with
/// The function takes an enumerator and will return true if it is marked with the same category. /// [[generate::enum_category(name)]]. The function takes an enumerator and will return true if it
/// is marked with the same category.
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
@ -24,8 +25,8 @@ bool is_category(const cppast::cpp_enum_value& e, const std::string& name)
if (auto attr = cppast::has_attribute(e, "generate::enum_category")) if (auto attr = cppast::has_attribute(e, "generate::enum_category"))
{ {
// ... by looking for the token // ... by looking for the token
auto iter = auto iter
std::find_if(attr.value().arguments().value().begin(), = std::find_if(attr.value().arguments().value().begin(),
attr.value().arguments().value().end(), attr.value().arguments().value().end(),
[&](const cppast::cpp_token& tok) { return tok.spelling == name; }); [&](const cppast::cpp_token& tok) { return tok.spelling == name; });
return iter != attr.value().arguments().value().end(); return iter != attr.value().arguments().value().end();
@ -42,8 +43,10 @@ const cppast::cpp_enum& get_enum(const cppast::cpp_entity_index& index,
// it is an enum // it is an enum
assert(param_type.kind() == cppast::cpp_type_kind::user_defined_t); assert(param_type.kind() == cppast::cpp_type_kind::user_defined_t);
// lookup definition // lookup definition
auto& definition = auto& definition = static_cast<const cppast::cpp_user_defined_type&>(param_type)
static_cast<const cppast::cpp_user_defined_type&>(param_type).entity().get(index)[0u].get(); .entity()
.get(index)[0u]
.get();
assert(definition.kind() == cppast::cpp_entity_kind::enum_t); assert(definition.kind() == cppast::cpp_entity_kind::enum_t);
return static_cast<const cppast::cpp_enum&>(definition); return static_cast<const cppast::cpp_enum&>(definition);

View file

@ -5,7 +5,8 @@
/// \file /// \file
/// Generates enum `to_string()` code. /// Generates enum `to_string()` code.
/// ///
/// Given an input file, it will generate a to_string() function for all enums marked with [[generate::to_string]]. /// Given an input file, it will generate a to_string() function for all enums marked with
/// [[generate::to_string]].
#include <iostream> #include <iostream>
@ -43,8 +44,8 @@ void generate_to_string(const cppast::cpp_file& file)
<< ":\n"; << ":\n";
// attribute can be used to override the string // attribute can be used to override the string
if (auto attr = if (auto attr
cppast::has_attribute(enumerator, "generate::to_string")) = cppast::has_attribute(enumerator, "generate::to_string"))
std::cout << " return " std::cout << " return "
<< attr.value().arguments().value().as_string() << attr.value().arguments().value().as_string()
<< ";\n"; << ";\n";

View file

@ -5,7 +5,8 @@
/// \file /// \file
/// Serialization code generation. /// Serialization code generation.
/// ///
/// Given an input file, it will generate a serialize() function for each class marked with [[generate::serialize]]. /// Given an input file, it will generate a serialize() function for each class marked with
/// [[generate::serialize]].
#include <iostream> #include <iostream>

View file

@ -7,8 +7,8 @@
#include <cstring> #include <cstring>
#include <type_safe/index.hpp>
#include <type_safe/flag_set.hpp> #include <type_safe/flag_set.hpp>
#include <type_safe/index.hpp>
#include <cppast/cpp_entity.hpp> #include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_ref.hpp> #include <cppast/cpp_entity_ref.hpp>
@ -32,8 +32,7 @@ namespace cppast
/// \effects Creates it viewing the C string literal. /// \effects Creates it viewing the C string literal.
template <std::size_t Size> template <std::size_t Size>
constexpr string_view(const char (&str)[Size]) noexcept : str_(str), length_(Size - 1u) constexpr string_view(const char (&str)[Size]) noexcept : str_(str), length_(Size - 1u)
{ {}
}
/// \returns The number of characters. /// \returns The number of characters.
constexpr std::size_t length() const noexcept constexpr std::size_t length() const noexcept
@ -67,11 +66,9 @@ namespace cppast
{ {
public: public:
template <typename T> template <typename T>
explicit semantic_string_view(T&& obj, explicit semantic_string_view(T&& obj, decltype(string_view(std::forward<T>(obj)), 0) = 0)
decltype(string_view(std::forward<T>(obj)), 0) = 0)
: str_(std::forward<T>(obj)) : str_(std::forward<T>(obj))
{ {}
}
const string_view& str() const noexcept const string_view& str() const noexcept
{ {
@ -194,7 +191,8 @@ namespace cppast
output& operator=(const output&) = delete; output& operator=(const output&) = delete;
/// \returns Whether or not the `on_XXX` function returned something other than `exclude` or `custom`. /// \returns Whether or not the `on_XXX` function returned something other than `exclude` or
/// `custom`.
explicit operator bool() const noexcept explicit operator bool() const noexcept
{ {
return !options_.is_set(exclude) && !options_.is_set(custom); return !options_.is_set(exclude) && !options_.is_set(custom);
@ -236,7 +234,8 @@ namespace cppast
gen_->on_container_end(*this, *e_); gen_->on_container_end(*this, *e_);
} }
/// \effects Call `do_indent()` followed by `do_write_newline()` (if `print_newline` is `true`). /// \effects Call `do_indent()` followed by `do_write_newline()` (if `print_newline` is
/// `true`).
void indent(bool print_newline = true) const noexcept void indent(bool print_newline = true) const noexcept
{ {
gen_->do_indent(); gen_->do_indent();
@ -374,7 +373,8 @@ namespace cppast
/// \effects Generates the code for the specified entity. /// \effects Generates the code for the specified entity.
/// It can be used to generate additional entities while generating another one. /// It can be used to generate additional entities while generating another one.
/// \returns Whether or not any code was generated. /// \returns Whether or not any code was generated.
/// \notes This does not affect the main entity, but otherwise behaves just like [cppast::generate_code()](). /// \notes This does not affect the main entity, but otherwise behaves just like
/// [cppast::generate_code()]().
bool generate_code(const cpp_entity& entity); bool generate_code(const cpp_entity& entity);
private: private:
@ -426,7 +426,8 @@ namespace cppast
virtual void do_indent() = 0; virtual void do_indent() = 0;
/// \effects Will be invoked when the indentation level should be decreased by one. /// \effects Will be invoked when the indentation level should be decreased by one.
/// The level change must be applied immediately if nothing else has been written on the current line. /// The level change must be applied immediately if nothing else has been written on the current
/// line.
virtual void do_unindent() = 0; virtual void do_unindent() = 0;
/// \effects Writes the given token sequence. /// \effects Writes the given token sequence.
@ -447,8 +448,7 @@ namespace cppast
do_write_token_seq(identifier); do_write_token_seq(identifier);
} }
/// \group write /// \group write
virtual bool do_write_reference(type_safe::array_ref<const cpp_entity_id> id, virtual bool do_write_reference(type_safe::array_ref<const cpp_entity_id> id, string_view name)
string_view name)
{ {
(void)id; (void)id;
do_write_token_seq(name); do_write_token_seq(name);

View file

@ -8,8 +8,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <type_safe/reference.hpp>
#include <type_safe/flag_set.hpp> #include <type_safe/flag_set.hpp>
#include <type_safe/reference.hpp>
#include <cppast/detail/assert.hpp> #include <cppast/detail/assert.hpp>

View file

@ -32,8 +32,7 @@ namespace cppast
private: private:
cpp_alias_template(std::unique_ptr<cpp_type_alias> alias) cpp_alias_template(std::unique_ptr<cpp_type_alias> alias)
: cpp_template(std::unique_ptr<cpp_entity>(alias.release())) : cpp_template(std::unique_ptr<cpp_entity>(alias.release()))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -29,8 +29,8 @@ namespace cppast
return *type_; return *type_;
} }
/// \returns An optional reference to the [cppast::cpp_expression]() that is the size of the array. /// \returns An optional reference to the [cppast::cpp_expression]() that is the size of the
/// \notes An unsized array - `T[]` - does not have a size. /// array. \notes An unsized array - `T[]` - does not have a size.
type_safe::optional_ref<const cpp_expression> size() const noexcept type_safe::optional_ref<const cpp_expression> size() const noexcept
{ {
return type_safe::opt_cref(size_.get()); return type_safe::opt_cref(size_.get());
@ -39,8 +39,7 @@ namespace cppast
private: private:
cpp_array_type(std::unique_ptr<cpp_type> type, std::unique_ptr<cpp_expression> size) cpp_array_type(std::unique_ptr<cpp_type> type, std::unique_ptr<cpp_expression> size)
: type_(std::move(type)), size_(std::move(size)) : type_(std::move(type)), size_(std::move(size))
{ {}
}
cpp_type_kind do_get_kind() const noexcept override cpp_type_kind do_get_kind() const noexcept override
{ {

View file

@ -34,9 +34,9 @@ namespace cppast
/// A C++ attribute, including `alignas` specifiers. /// A C++ attribute, including `alignas` specifiers.
/// ///
/// It consists of a name, an optional namespace scope and optional arguments. /// It consists of a name, an optional namespace scope and optional arguments.
/// The scope is just a single identifier and doesn't include the `::` and can be given explicitly or via using. /// The scope is just a single identifier and doesn't include the `::` and can be given explicitly
/// The arguments are as specified in the source code but do not include the outer-most `(` and `)`. /// or via using. The arguments are as specified in the source code but do not include the
/// It can also be variadic or not. /// outer-most `(` and `)`. It can also be variadic or not.
/// ///
/// An attribute can be known or unknown. /// An attribute can be known or unknown.
/// A known attribute will have the [cppast::cpp_attribute_kind]() set properly. /// A known attribute will have the [cppast::cpp_attribute_kind]() set properly.
@ -46,15 +46,13 @@ namespace cppast
/// \effects Creates a known attribute, potentially with arguments. /// \effects Creates a known attribute, potentially with arguments.
cpp_attribute(cpp_attribute_kind kind, type_safe::optional<cpp_token_string> arguments); cpp_attribute(cpp_attribute_kind kind, type_safe::optional<cpp_token_string> arguments);
/// \effects Creates an unknown attribute giving it the optional scope, names, arguments and whether it is variadic. /// \effects Creates an unknown attribute giving it the optional scope, names, arguments and
/// whether it is variadic.
cpp_attribute(type_safe::optional<std::string> scope, std::string name, cpp_attribute(type_safe::optional<std::string> scope, std::string name,
type_safe::optional<cpp_token_string> arguments, bool is_variadic) type_safe::optional<cpp_token_string> arguments, bool is_variadic)
: scope_(std::move(scope)), : scope_(std::move(scope)), arguments_(std::move(arguments)), name_(std::move(name)),
arguments_(std::move(arguments)),
name_(std::move(name)),
variadic_(is_variadic) variadic_(is_variadic)
{ {}
}
/// \returns The kind of attribute, if it is known. /// \returns The kind of attribute, if it is known.
const cpp_attribute_kind& kind() const noexcept const cpp_attribute_kind& kind() const noexcept

View file

@ -57,8 +57,7 @@ namespace cppast
private: private:
cpp_access_specifier(cpp_access_specifier_kind access) cpp_access_specifier(cpp_access_specifier_kind access)
: cpp_entity(to_string(access)), access_(access) : cpp_entity(to_string(access)), access_(access)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -74,10 +73,8 @@ namespace cppast
/// \returns A newly created base class specifier. /// \returns A newly created base class specifier.
/// \notes It is not meant to be registered at the [cppast::cpp_entity_index](), /// \notes It is not meant to be registered at the [cppast::cpp_entity_index](),
/// as nothing can refer to the specifier itself. /// as nothing can refer to the specifier itself.
static std::unique_ptr<cpp_base_class> build(std::string name, static std::unique_ptr<cpp_base_class> build(std::string name, std::unique_ptr<cpp_type> base,
std::unique_ptr<cpp_type> base, cpp_access_specifier_kind access, bool is_virtual)
cpp_access_specifier_kind access,
bool is_virtual)
{ {
return std::unique_ptr<cpp_base_class>( return std::unique_ptr<cpp_base_class>(
new cpp_base_class(std::move(name), std::move(base), access, is_virtual)); new cpp_base_class(std::move(name), std::move(base), access, is_virtual));
@ -105,8 +102,7 @@ namespace cppast
cpp_base_class(std::string name, std::unique_ptr<cpp_type> base, cpp_base_class(std::string name, std::unique_ptr<cpp_type> base,
cpp_access_specifier_kind access, bool is_virtual) cpp_access_specifier_kind access, bool is_virtual)
: cpp_entity(std::move(name)), type_(std::move(base)), access_(access), virtual_(is_virtual) : cpp_entity(std::move(name)), type_(std::move(base)), access_(access), virtual_(is_virtual)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -134,8 +130,7 @@ namespace cppast
/// \effects Sets the name and kind and whether it is `final`. /// \effects Sets the name and kind and whether it is `final`.
explicit builder(std::string name, cpp_class_kind kind, bool is_final = false) explicit builder(std::string name, cpp_class_kind kind, bool is_final = false)
: class_(new cpp_class(std::move(name), kind, is_final)) : class_(new cpp_class(std::move(name), kind, is_final))
{ {}
}
/// \effects Marks the class as final. /// \effects Marks the class as final.
void is_final() noexcept void is_final() noexcept
@ -192,8 +187,8 @@ namespace cppast
/// \notes This is intended for templated classes only. /// \notes This is intended for templated classes only.
std::unique_ptr<cpp_class> finish(type_safe::optional<cpp_entity_ref> semantic_parent); std::unique_ptr<cpp_class> finish(type_safe::optional<cpp_entity_ref> semantic_parent);
/// \effects Returns the finish class without registering it and marks it as forward declaration. /// \effects Returns the finish class without registering it and marks it as forward
/// \notes This is intended for templated classes only. /// declaration. \notes This is intended for templated classes only.
std::unique_ptr<cpp_class> finish_declaration(cpp_entity_id definition_id); std::unique_ptr<cpp_class> finish_declaration(cpp_entity_id definition_id);
private: private:
@ -221,8 +216,7 @@ namespace cppast
private: private:
cpp_class(std::string name, cpp_class_kind kind, bool final) cpp_class(std::string name, cpp_class_kind kind, bool final)
: cpp_entity(std::move(name)), kind_(kind), final_(final) : cpp_entity(std::move(name)), kind_(kind), final_(final)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -32,8 +32,7 @@ namespace cppast
private: private:
cpp_class_template(std::unique_ptr<cpp_class> func) cpp_class_template(std::unique_ptr<cpp_class> func)
: cpp_template(std::unique_ptr<cpp_entity>(func.release())) : cpp_template(std::unique_ptr<cpp_entity>(func.release()))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -62,8 +61,7 @@ namespace cppast
private: private:
cpp_class_template_specialization(std::unique_ptr<cpp_class> func, cpp_template_ref primary) cpp_class_template_specialization(std::unique_ptr<cpp_class> func, cpp_template_ref primary)
: cpp_template_specialization(std::unique_ptr<cpp_entity>(func.release()), primary) : cpp_template_specialization(std::unique_ptr<cpp_entity>(func.release()), primary)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -10,9 +10,9 @@
#include <type_safe/optional_ref.hpp> #include <type_safe/optional_ref.hpp>
#include <cppast/detail/intrusive_list.hpp>
#include <cppast/cpp_attribute.hpp> #include <cppast/cpp_attribute.hpp>
#include <cppast/cpp_token.hpp> #include <cppast/cpp_token.hpp>
#include <cppast/detail/intrusive_list.hpp>
namespace cppast namespace cppast
{ {
@ -41,10 +41,9 @@ namespace cppast
return templ_.has_value(); return templ_.has_value();
} }
/// \returns An iteratable object iterating over the [cppast::cpp_template_parameter]() entities of the scope. /// \returns An iteratable object iterating over the [cppast::cpp_template_parameter]() entities
/// \requires The scope is templated. /// of the scope. \requires The scope is templated.
detail::iteratable_intrusive_list<cpp_template_parameter> template_parameters() const detail::iteratable_intrusive_list<cpp_template_parameter> template_parameters() const noexcept;
noexcept;
private: private:
type_safe::object_ref<const cpp_entity> entity_; type_safe::object_ref<const cpp_entity> entity_;
@ -89,12 +88,11 @@ namespace cppast
/// \returns The documentation comment associated with that entity, if any. /// \returns The documentation comment associated with that entity, if any.
/// \notes A documentation comment can have three forms: /// \notes A documentation comment can have three forms:
/// ///
/// * A C style doc comment. It is a C style comment starting with an additional `*`, i.e. `/**`. /// * A C style doc comment. It is a C style comment starting with an additional `*`, i.e.
/// One space after the leading sequence will be skipped. /// `/**`. One space after the leading sequence will be skipped. It ends either with `*/` or
/// It ends either with `*/` or `**/`. /// `**/`. After a newline all whitespace is skipped, as well as an optional `*` followed by
/// After a newline all whitespace is skipped, as well as an optional `*` followed by another optional space, /// another optional space, as well as trailing whitespace on each line. I.e. `/** a\n * b
/// as well as trailing whitespace on each line. /// */` yields the text `a\nb`.
/// I.e. `/** a\n * b */` yields the text `a\nb`.
/// * A C++ style doc comment. It is a C++ style comment starting with an additional `/` or '!`, /// * A C++ style doc comment. It is a C++ style comment starting with an additional `/` or '!`,
/// i.e. `///` or `//!`. /// i.e. `///` or `//!`.
/// One space character after the leading sequence will be skipped, /// One space character after the leading sequence will be skipped,
@ -153,7 +151,8 @@ namespace cppast
/// User data is just some kind of pointer, there are no requirements. /// User data is just some kind of pointer, there are no requirements.
/// The class will do no lifetime management. /// The class will do no lifetime management.
/// ///
/// User data is useful if you need to store additional data for an entity without the need to maintain a registry. /// User data is useful if you need to store additional data for an entity without the need to
/// maintain a registry.
void set_user_data(void* data) const noexcept void set_user_data(void* data) const noexcept
{ {
user_data_ = data; user_data_ = data;
@ -216,8 +215,7 @@ namespace cppast
private: private:
cpp_unexposed_entity(std::string name, cpp_token_string spelling) cpp_unexposed_entity(std::string name, cpp_token_string spelling)
: cpp_entity(std::move(name)), spelling_(std::move(spelling)) : cpp_entity(std::move(name)), spelling_(std::move(spelling))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -51,7 +51,7 @@ namespace cppast
{ {
return cpp_entity_id(str); return cpp_entity_id(str);
} }
} } // namespace literals
/// An index of all [cppast::cpp_entity]() objects created. /// An index of all [cppast::cpp_entity]() objects created.
/// ///
@ -93,23 +93,22 @@ namespace cppast
/// \effects Registers a new [cppast::cpp_namespace](). /// \effects Registers a new [cppast::cpp_namespace]().
/// \notes The namespace object must live as long as the index lives. /// \notes The namespace object must live as long as the index lives.
/// \notes This operation is thread safe. /// \notes This operation is thread safe.
void register_namespace(cpp_entity_id id, void register_namespace(cpp_entity_id id, type_safe::object_ref<const cpp_namespace> ns) const;
type_safe::object_ref<const cpp_namespace> ns) const;
/// \returns A [ts::optional_ref]() corresponding to the entity(/ies) of the given [cppast::cpp_entity_id](). /// \returns A [ts::optional_ref]() corresponding to the entity(/ies) of the given
/// If no definition has been registered, it return the first declaration that was registered. /// [cppast::cpp_entity_id](). If no definition has been registered, it return the first
/// If the id resolves to a namespaces, returns an empty optional. /// declaration that was registered. If the id resolves to a namespaces, returns an empty
/// \notes This operation is thread safe. /// optional. \notes This operation is thread safe.
type_safe::optional_ref<const cpp_entity> lookup(const cpp_entity_id& id) const noexcept; type_safe::optional_ref<const cpp_entity> lookup(const cpp_entity_id& id) const noexcept;
/// \returns A [ts::optional_ref]() corresponding to the entity of the given [cppast::cpp_entity_id](). /// \returns A [ts::optional_ref]() corresponding to the entity of the given
/// If no definition has been registered, it returns an empty optional. /// [cppast::cpp_entity_id](). If no definition has been registered, it returns an empty
/// \notes This operation is thread safe. /// optional. \notes This operation is thread safe.
type_safe::optional_ref<const cpp_entity> lookup_definition(const cpp_entity_id& id) const type_safe::optional_ref<const cpp_entity> lookup_definition(const cpp_entity_id& id) const
noexcept; noexcept;
/// \returns A [ts::array_ref]() of references to all namespaces matching the given [cppast::cpp_entity_id](). /// \returns A [ts::array_ref]() of references to all namespaces matching the given
/// If no namespace is found, it returns an empty array reference. /// [cppast::cpp_entity_id](). If no namespace is found, it returns an empty array reference.
/// \notes This operation is thread safe. /// \notes This operation is thread safe.
auto lookup_namespace(const cpp_entity_id& id) const noexcept auto lookup_namespace(const cpp_entity_id& id) const noexcept
-> type_safe::array_ref<type_safe::object_ref<const cpp_namespace>>; -> type_safe::array_ref<type_safe::object_ref<const cpp_namespace>>;
@ -130,8 +129,7 @@ namespace cppast
value(type_safe::object_ref<const cpp_entity> e, bool def) value(type_safe::object_ref<const cpp_entity> e, bool def)
: entity(std::move(e)), is_definition(def) : entity(std::move(e)), is_definition(def)
{ {}
}
}; };
mutable std::mutex mutex_; mutable std::mutex mutex_;

View file

@ -9,8 +9,8 @@
#include <type_safe/variant.hpp> #include <type_safe/variant.hpp>
#include <cppast/detail/assert.hpp>
#include <cppast/cpp_entity_index.hpp> #include <cppast/cpp_entity_index.hpp>
#include <cppast/detail/assert.hpp>
namespace cppast namespace cppast
{ {
@ -28,15 +28,13 @@ namespace cppast
/// \effects Creates it giving it the target id and name. /// \effects Creates it giving it the target id and name.
basic_cpp_entity_ref(cpp_entity_id target_id, std::string target_name) basic_cpp_entity_ref(cpp_entity_id target_id, std::string target_name)
: target_(std::move(target_id)), name_(std::move(target_name)) : target_(std::move(target_id)), name_(std::move(target_name))
{ {}
}
/// \effects Creates it giving it multiple target ids and name. /// \effects Creates it giving it multiple target ids and name.
/// \notes This is to refer to an overloaded function. /// \notes This is to refer to an overloaded function.
basic_cpp_entity_ref(std::vector<cpp_entity_id> target_ids, std::string target_name) basic_cpp_entity_ref(std::vector<cpp_entity_id> target_ids, std::string target_name)
: target_(std::move(target_ids)), name_(std::move(target_name)) : target_(std::move(target_ids)), name_(std::move(target_name))
{ {}
}
/// \returns The name of the reference, as spelled in the source code. /// \returns The name of the reference, as spelled in the source code.
const std::string& name() const noexcept const std::string& name() const noexcept
@ -122,7 +120,7 @@ namespace cppast
return true; return true;
} }
}; };
} } // namespace detail
/// A [cppast::basic_cpp_entity_ref]() to any [cppast::cpp_entity](). /// A [cppast::basic_cpp_entity_ref]() to any [cppast::cpp_entity]().
using cpp_entity_ref = basic_cpp_entity_ref<cpp_entity, detail::cpp_entity_ref_predicate>; using cpp_entity_ref = basic_cpp_entity_ref<cpp_entity, detail::cpp_entity_ref_predicate>;

View file

@ -9,9 +9,9 @@
#include <type_safe/optional_ref.hpp> #include <type_safe/optional_ref.hpp>
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_container.hpp> #include <cppast/cpp_entity_container.hpp>
#include <cppast/cpp_entity_index.hpp> #include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_expression.hpp> #include <cppast/cpp_expression.hpp>
#include <cppast/cpp_forward_declarable.hpp> #include <cppast/cpp_forward_declarable.hpp>
#include <cppast/cpp_type.hpp> #include <cppast/cpp_type.hpp>
@ -26,8 +26,8 @@ namespace cppast
/// \returns A newly created and registered enum value. /// \returns A newly created and registered enum value.
/// \notes `value` may be `nullptr`, in which case the enum has an implicit value. /// \notes `value` may be `nullptr`, in which case the enum has an implicit value.
static std::unique_ptr<cpp_enum_value> build( static std::unique_ptr<cpp_enum_value> build(const cpp_entity_index& idx, cpp_entity_id id,
const cpp_entity_index& idx, cpp_entity_id id, std::string name, std::string name,
std::unique_ptr<cpp_expression> value = nullptr); std::unique_ptr<cpp_expression> value = nullptr);
/// \returns A [ts::optional_ref]() to the [cppast::cpp_expression]() that is the enum value. /// \returns A [ts::optional_ref]() to the [cppast::cpp_expression]() that is the enum value.
@ -40,8 +40,7 @@ namespace cppast
private: private:
cpp_enum_value(std::string name, std::unique_ptr<cpp_expression> value) cpp_enum_value(std::string name, std::unique_ptr<cpp_expression> value)
: cpp_entity(std::move(name)), value_(std::move(value)) : cpp_entity(std::move(name)), value_(std::move(value))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -64,11 +63,9 @@ namespace cppast
{ {
public: public:
/// \effects Sets the name, underlying type and whether it is scoped. /// \effects Sets the name, underlying type and whether it is scoped.
builder(std::string name, bool scoped, std::unique_ptr<cpp_type> type, builder(std::string name, bool scoped, std::unique_ptr<cpp_type> type, bool explicit_type)
bool explicit_type)
: enum_(new cpp_enum(std::move(name), std::move(type), explicit_type, scoped)) : enum_(new cpp_enum(std::move(name), std::move(type), explicit_type, scoped))
{ {}
}
/// \effects Adds a [cppast::cpp_enum_value](). /// \effects Adds a [cppast::cpp_enum_value]().
void add_value(std::unique_ptr<cpp_enum_value> value) void add_value(std::unique_ptr<cpp_enum_value> value)
@ -128,12 +125,8 @@ namespace cppast
private: private:
cpp_enum(std::string name, std::unique_ptr<cpp_type> type, bool type_given, bool scoped) cpp_enum(std::string name, std::unique_ptr<cpp_type> type, bool type_given, bool scoped)
: cpp_entity(std::move(name)), : cpp_entity(std::move(name)), type_(std::move(type)), scoped_(scoped), type_given_(type_given)
type_(std::move(type)), {}
scoped_(scoped),
type_given_(type_given)
{
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -53,7 +53,8 @@ namespace cppast
/// User data is just some kind of pointer, there are no requirements. /// User data is just some kind of pointer, there are no requirements.
/// The class will do no lifetime management. /// The class will do no lifetime management.
/// ///
/// User data is useful if you need to store additional data for an entity without the need to maintain a registry. /// User data is useful if you need to store additional data for an entity without the need to
/// maintain a registry.
void set_user_data(void* data) const noexcept void set_user_data(void* data) const noexcept
{ {
user_data_ = data; user_data_ = data;
@ -98,8 +99,7 @@ namespace cppast
private: private:
cpp_unexposed_expression(std::unique_ptr<cpp_type> type, cpp_token_string str) cpp_unexposed_expression(std::unique_ptr<cpp_type> type, cpp_token_string str)
: cpp_expression(std::move(type)), str_(std::move(str)) : cpp_expression(std::move(type)), str_(std::move(str))
{ {}
}
cpp_expression_kind do_get_kind() const noexcept override cpp_expression_kind do_get_kind() const noexcept override
{ {
@ -130,8 +130,7 @@ namespace cppast
private: private:
cpp_literal_expression(std::unique_ptr<cpp_type> type, std::string value) cpp_literal_expression(std::unique_ptr<cpp_type> type, std::string value)
: cpp_expression(std::move(type)), value_(std::move(value)) : cpp_expression(std::move(type)), value_(std::move(value))
{ {}
}
cpp_expression_kind do_get_kind() const noexcept override cpp_expression_kind do_get_kind() const noexcept override
{ {

View file

@ -7,8 +7,8 @@
#include <vector> #include <vector>
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_container.hpp> #include <cppast/cpp_entity_container.hpp>
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_ref.hpp> #include <cppast/cpp_entity_ref.hpp>
namespace cppast namespace cppast
@ -19,10 +19,7 @@ namespace cppast
std::string content; std::string content;
unsigned line; unsigned line;
cpp_doc_comment(std::string content, unsigned line) cpp_doc_comment(std::string content, unsigned line) : content(std::move(content)), line(line) {}
: content(std::move(content)), line(line)
{
}
}; };
/// A [cppast::cpp_entity]() modelling a file. /// A [cppast::cpp_entity]() modelling a file.

View file

@ -93,11 +93,10 @@ namespace cppast
/// Gets the definition of an entity. /// Gets the definition of an entity.
/// \returns A [ts::optional_ref]() to the entity that is the definition. /// \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 for the generic entity overload), /// If the entity is a definition or not derived from [cppast::cpp_forward_declarable]() (only valid
/// returns a reference to the entity itself. /// for the generic entity overload), returns a reference to the entity itself. Otherwise lookups
/// Otherwise lookups the definition id and returns it. /// the definition id and returns it. \notes The return value will only be `nullptr`, if the
/// \notes The return value will only be `nullptr`, if the definition is not registered. /// definition is not registered. \group get_definition
/// \group get_definition
type_safe::optional_ref<const cpp_entity> get_definition(const cpp_entity_index& idx, type_safe::optional_ref<const cpp_entity> get_definition(const cpp_entity_index& idx,
const cpp_entity& e); const cpp_entity& e);
/// \group get_definition /// \group get_definition

View file

@ -5,11 +5,11 @@
#ifndef CPPAST_CPP_FUNCTION_HPP_INCLUDED #ifndef CPPAST_CPP_FUNCTION_HPP_INCLUDED
#define CPPAST_CPP_FUNCTION_HPP_INCLUDED #define CPPAST_CPP_FUNCTION_HPP_INCLUDED
#include <cppast/detail/intrusive_list.hpp>
#include <cppast/cpp_entity.hpp> #include <cppast/cpp_entity.hpp>
#include <cppast/cpp_forward_declarable.hpp> #include <cppast/cpp_forward_declarable.hpp>
#include <cppast/cpp_storage_class_specifiers.hpp> #include <cppast/cpp_storage_class_specifiers.hpp>
#include <cppast/cpp_variable_base.hpp> #include <cppast/cpp_variable_base.hpp>
#include <cppast/detail/intrusive_list.hpp>
namespace cppast namespace cppast
{ {
@ -20,21 +20,23 @@ namespace cppast
static cpp_entity_kind kind() noexcept; static cpp_entity_kind kind() noexcept;
/// \returns A newly created and registered function parameter. /// \returns A newly created and registered function parameter.
static std::unique_ptr<cpp_function_parameter> build( static std::unique_ptr<cpp_function_parameter> build(const cpp_entity_index& idx,
const cpp_entity_index& idx, cpp_entity_id id, std::string name, cpp_entity_id id, std::string name,
std::unique_ptr<cpp_type> type, std::unique_ptr<cpp_expression> def = nullptr); std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def
= nullptr);
/// \returns A newly created unnamed function parameter. /// \returns A newly created unnamed function parameter.
/// \notes It will not be registered, as nothing can refer to it. /// \notes It will not be registered, as nothing can refer to it.
static std::unique_ptr<cpp_function_parameter> build( static std::unique_ptr<cpp_function_parameter> build(std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_type> type, std::unique_ptr<cpp_expression> def = nullptr); std::unique_ptr<cpp_expression> def
= nullptr);
private: private:
cpp_function_parameter(std::string name, std::unique_ptr<cpp_type> type, cpp_function_parameter(std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def) std::unique_ptr<cpp_expression> def)
: cpp_entity(std::move(name)), cpp_variable_base(std::move(type), std::move(def)) : cpp_entity(std::move(name)), cpp_variable_base(std::move(type), std::move(def))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
}; };
@ -67,7 +69,8 @@ namespace cppast
class cpp_function_base : public cpp_entity, public cpp_forward_declarable class cpp_function_base : public cpp_entity, public cpp_forward_declarable
{ {
public: public:
/// \returns An iteratable object iterating over the [cppast::cpp_function__parameter]() entities. /// \returns An iteratable object iterating over the [cppast::cpp_function__parameter]()
/// entities.
detail::iteratable_intrusive_list<cpp_function_parameter> parameters() const noexcept detail::iteratable_intrusive_list<cpp_function_parameter> parameters() const noexcept
{ {
return type_safe::ref(parameters_); return type_safe::ref(parameters_);
@ -80,9 +83,10 @@ namespace cppast
return body_; return body_;
} }
/// \returns A [ts::optional_ref]() to the [cppast::cpp_expression]() that is the given `noexcept` condition. /// \returns A [ts::optional_ref]() to the [cppast::cpp_expression]() that is the given
/// \notes If this returns `nullptr`, the function has the implicit noexcept value (i.e. none, unless it is a destructor). /// `noexcept` condition. \notes If this returns `nullptr`, the function has the implicit
/// \notes There is no way to distinguish between `noexcept` and `noexcept(true)`. /// noexcept value (i.e. none, unless it is a destructor). \notes There is no way to distinguish
/// between `noexcept` and `noexcept(true)`.
type_safe::optional_ref<const cpp_expression> noexcept_condition() const noexcept type_safe::optional_ref<const cpp_expression> noexcept_condition() const noexcept
{ {
return type_safe::opt_cref(noexcept_expr_.get()); return type_safe::opt_cref(noexcept_expr_.get());
@ -117,8 +121,7 @@ namespace cppast
void add_parameter(std::unique_ptr<cpp_function_parameter> parameter) void add_parameter(std::unique_ptr<cpp_function_parameter> parameter)
{ {
static_cast<cpp_function_base&>(*function).parameters_.push_back(*function, static_cast<cpp_function_base&>(*function).parameters_.push_back(*function,
std::move( std::move(parameter));
parameter));
} }
/// \effects Marks the function as variadic. /// \effects Marks the function as variadic.
@ -179,8 +182,7 @@ namespace cppast
cpp_function_base(std::string name) cpp_function_base(std::string name)
: cpp_entity(std::move(name)), body_(cpp_function_declaration), variadic_(false) : cpp_entity(std::move(name)), body_(cpp_function_declaration), variadic_(false)
{ {}
}
protected: protected:
/// \returns The signature, it is called by [*signature()](). /// \returns The signature, it is called by [*signature()]().
@ -250,12 +252,9 @@ namespace cppast
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
cpp_function(std::string name, std::unique_ptr<cpp_type> ret) cpp_function(std::string name, std::unique_ptr<cpp_type> ret)
: cpp_function_base(std::move(name)), : cpp_function_base(std::move(name)), return_type_(std::move(ret)),
return_type_(std::move(ret)), storage_(cpp_storage_class_auto), constexpr_(false)
storage_(cpp_storage_class_auto), {}
constexpr_(false)
{
}
std::unique_ptr<cpp_type> return_type_; std::unique_ptr<cpp_type> return_type_;
cpp_storage_class_specifiers storage_; cpp_storage_class_specifiers storage_;

View file

@ -32,8 +32,7 @@ namespace cppast
private: private:
cpp_function_template(std::unique_ptr<cpp_function_base> func) cpp_function_template(std::unique_ptr<cpp_function_base> func)
: cpp_template(std::unique_ptr<cpp_entity>(func.release())) : cpp_template(std::unique_ptr<cpp_entity>(func.release()))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -67,8 +66,7 @@ namespace cppast
cpp_function_template_specialization(std::unique_ptr<cpp_function_base> func, cpp_function_template_specialization(std::unique_ptr<cpp_function_base> func,
cpp_template_ref primary) cpp_template_ref primary)
: cpp_template_specialization(std::unique_ptr<cpp_entity>(func.release()), primary) : cpp_template_specialization(std::unique_ptr<cpp_entity>(func.release()), primary)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -22,8 +22,7 @@ namespace cppast
/// \effects Sets the return type. /// \effects Sets the return type.
explicit builder(std::unique_ptr<cpp_type> return_type) explicit builder(std::unique_ptr<cpp_type> return_type)
: func_(new cpp_function_type(std::move(return_type))) : func_(new cpp_function_type(std::move(return_type)))
{ {}
}
/// \effects Adds an parameter type. /// \effects Adds an parameter type.
void add_parameter(std::unique_ptr<cpp_type> arg) void add_parameter(std::unique_ptr<cpp_type> arg)
@ -68,8 +67,7 @@ namespace cppast
private: private:
cpp_function_type(std::unique_ptr<cpp_type> return_type) cpp_function_type(std::unique_ptr<cpp_type> return_type)
: return_type_(std::move(return_type)), variadic_(false) : return_type_(std::move(return_type)), variadic_(false)
{ {}
}
cpp_type_kind do_get_kind() const noexcept override cpp_type_kind do_get_kind() const noexcept override
{ {
@ -83,9 +81,10 @@ namespace cppast
/// A [cppast::cpp_type]() that is a member function. /// A [cppast::cpp_type]() that is a member function.
/// ///
/// A member function with cv qualifier is created by wrapping it in [cppast::cpp_cv_qualified_type](). /// A member function with cv qualifier is created by wrapping it in
/// A member function with reference qualifier is created by wrapping it in [cppast::cpp_reference_type](). /// [cppast::cpp_cv_qualified_type](). A member function with reference qualifier is created by
/// A member function pointer is created by wrapping it in [cppast::cpp_pointer_type](). /// wrapping it in [cppast::cpp_reference_type](). A member function pointer is created by wrapping
/// it in [cppast::cpp_pointer_type]().
class cpp_member_function_type final : public cpp_type class cpp_member_function_type final : public cpp_type
{ {
public: public:
@ -96,8 +95,7 @@ namespace cppast
/// \effects Sets the class and return type. /// \effects Sets the class and return type.
builder(std::unique_ptr<cpp_type> class_type, std::unique_ptr<cpp_type> return_type) builder(std::unique_ptr<cpp_type> class_type, std::unique_ptr<cpp_type> return_type)
: func_(new cpp_member_function_type(std::move(class_type), std::move(return_type))) : func_(new cpp_member_function_type(std::move(class_type), std::move(return_type)))
{ {}
}
/// \effects Adds a parameter type. /// \effects Adds a parameter type.
void add_parameter(std::unique_ptr<cpp_type> arg) void add_parameter(std::unique_ptr<cpp_type> arg)
@ -149,8 +147,7 @@ namespace cppast
cpp_member_function_type(std::unique_ptr<cpp_type> class_type, cpp_member_function_type(std::unique_ptr<cpp_type> class_type,
std::unique_ptr<cpp_type> return_type) std::unique_ptr<cpp_type> return_type)
: class_type_(std::move(class_type)), return_type_(std::move(return_type)), variadic_(false) : class_type_(std::move(class_type)), return_type_(std::move(return_type)), variadic_(false)
{ {}
}
cpp_type_kind do_get_kind() const noexcept override cpp_type_kind do_get_kind() const noexcept override
{ {
@ -192,8 +189,7 @@ namespace cppast
cpp_member_object_type(std::unique_ptr<cpp_type> class_type, cpp_member_object_type(std::unique_ptr<cpp_type> class_type,
std::unique_ptr<cpp_type> object_type) std::unique_ptr<cpp_type> object_type)
: class_type_(std::move(class_type)), object_type_(std::move(object_type)) : class_type_(std::move(class_type)), object_type_(std::move(object_type))
{ {}
}
cpp_type_kind do_get_kind() const noexcept override cpp_type_kind do_get_kind() const noexcept override
{ {

View file

@ -22,9 +22,7 @@ namespace cppast
{ {
public: public:
/// \effects Sets the name, that is the kind of language linkage. /// \effects Sets the name, that is the kind of language linkage.
explicit builder(std::string name) : linkage_(new cpp_language_linkage(std::move(name))) explicit builder(std::string name) : linkage_(new cpp_language_linkage(std::move(name))) {}
{
}
/// \effects Adds an entity to the language linkage. /// \effects Adds an entity to the language linkage.
void add_child(std::unique_ptr<cpp_entity> child) void add_child(std::unique_ptr<cpp_entity> child)

View file

@ -49,8 +49,7 @@ namespace cppast
/// \returns Whether or not a member function overrides another one. /// \returns Whether or not a member function overrides another one.
inline bool is_overriding(const cpp_virtual& virt) noexcept inline bool is_overriding(const cpp_virtual& virt) noexcept
{ {
return static_cast<bool>(virt.value_or(cpp_virtual_flags::pure) return static_cast<bool>(virt.value_or(cpp_virtual_flags::pure) & cpp_virtual_flags::override);
& cpp_virtual_flags::override);
} }
/// \returns Whether or not a member function is `final`. /// \returns Whether or not a member function is `final`.
@ -139,13 +138,9 @@ namespace cppast
/// \effects Sets name and return type, as well as the rest to defaults. /// \effects Sets name and return type, as well as the rest to defaults.
cpp_member_function_base(std::string name, std::unique_ptr<cpp_type> return_type) cpp_member_function_base(std::string name, std::unique_ptr<cpp_type> return_type)
: cpp_function_base(std::move(name)), : cpp_function_base(std::move(name)), return_type_(std::move(return_type)), cv_(cpp_cv_none),
return_type_(std::move(return_type)), ref_(cpp_ref_none), constexpr_(false)
cv_(cpp_cv_none), {}
ref_(cpp_ref_none),
constexpr_(false)
{
}
protected: protected:
std::string do_get_signature() const override; std::string do_get_signature() const override;
@ -212,8 +207,7 @@ namespace cppast
private: private:
cpp_conversion_op(std::string name, std::unique_ptr<cpp_type> return_t) cpp_conversion_op(std::string name, std::unique_ptr<cpp_type> return_t)
: cpp_member_function_base(std::move(name), std::move(return_t)), explicit_(false) : cpp_member_function_base(std::move(name), std::move(return_t)), explicit_(false)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -262,8 +256,7 @@ namespace cppast
private: private:
cpp_constructor(std::string name) cpp_constructor(std::string name)
: cpp_function_base(std::move(name)), explicit_(false), constexpr_(false) : cpp_function_base(std::move(name)), explicit_(false), constexpr_(false)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -23,11 +23,9 @@ namespace cppast
protected: protected:
cpp_member_variable_base(std::string name, std::unique_ptr<cpp_type> type, cpp_member_variable_base(std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def, bool is_mutable) std::unique_ptr<cpp_expression> def, bool is_mutable)
: cpp_entity(std::move(name)), : cpp_entity(std::move(name)), cpp_variable_base(std::move(type), std::move(def)),
cpp_variable_base(std::move(type), std::move(def)),
mutable_(is_mutable) mutable_(is_mutable)
{ {}
}
private: private:
bool mutable_; bool mutable_;
@ -41,8 +39,8 @@ namespace cppast
/// \returns A newly created and registered member variable. /// \returns A newly created and registered member variable.
/// \notes `def` may be `nullptr` in which case there is no member initializer provided. /// \notes `def` may be `nullptr` in which case there is no member initializer provided.
static std::unique_ptr<cpp_member_variable> build(const cpp_entity_index& idx, static std::unique_ptr<cpp_member_variable> build(const cpp_entity_index& idx, cpp_entity_id id,
cpp_entity_id id, std::string name, std::string name,
std::unique_ptr<cpp_type> type, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def, std::unique_ptr<cpp_expression> def,
bool is_mutable); bool is_mutable);
@ -81,8 +79,7 @@ namespace cppast
bool is_mutable) bool is_mutable)
: cpp_member_variable_base(std::move(name), std::move(type), nullptr, is_mutable), : cpp_member_variable_base(std::move(name), std::move(type), nullptr, is_mutable),
bits_(no_bits) bits_(no_bits)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -7,8 +7,8 @@
#include <cppast/cpp_entity_container.hpp> #include <cppast/cpp_entity_container.hpp>
#include <cppast/cpp_entity_index.hpp> #include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_ref.hpp>
#include <cppast/cpp_entity_kind.hpp> #include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_entity_ref.hpp>
namespace cppast namespace cppast
{ {
@ -26,8 +26,7 @@ namespace cppast
/// \effects Sets the namespace name and whether it is inline and nested. /// \effects Sets the namespace name and whether it is inline and nested.
explicit builder(std::string name, bool is_inline, bool is_nested) explicit builder(std::string name, bool is_inline, bool is_nested)
: namespace_(new cpp_namespace(std::move(name), is_inline, is_nested)) : namespace_(new cpp_namespace(std::move(name), is_inline, is_nested))
{ {}
}
/// \effects Adds an entity. /// \effects Adds an entity.
void add_child(std::unique_ptr<cpp_entity> child) noexcept void add_child(std::unique_ptr<cpp_entity> child) noexcept
@ -75,8 +74,7 @@ namespace cppast
private: private:
cpp_namespace(std::string name, bool is_inline, bool is_nested) cpp_namespace(std::string name, bool is_inline, bool is_nested)
: cpp_entity(std::move(name)), inline_(is_inline), nested_(is_nested) : cpp_entity(std::move(name)), inline_(is_inline), nested_(is_nested)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -99,8 +97,7 @@ namespace cppast
} // namespace detail } // namespace detail
/// A reference to a [cppast::cpp_namespace](). /// A reference to a [cppast::cpp_namespace]().
using cpp_namespace_ref = using cpp_namespace_ref = basic_cpp_entity_ref<cpp_namespace, detail::cpp_namespace_ref_predicate>;
basic_cpp_entity_ref<cpp_namespace, detail::cpp_namespace_ref_predicate>;
/// A [cppast::cpp_entity]() modelling a namespace alias. /// A [cppast::cpp_entity]() modelling a namespace alias.
class cpp_namespace_alias final : public cpp_entity class cpp_namespace_alias final : public cpp_entity
@ -109,9 +106,8 @@ namespace cppast
static cpp_entity_kind kind() noexcept; static cpp_entity_kind kind() noexcept;
/// \returns A newly created and registered namespace alias. /// \returns A newly created and registered namespace alias.
static std::unique_ptr<cpp_namespace_alias> build(const cpp_entity_index& idx, static std::unique_ptr<cpp_namespace_alias> build(const cpp_entity_index& idx, cpp_entity_id id,
cpp_entity_id id, std::string name, std::string name, cpp_namespace_ref target);
cpp_namespace_ref target);
/// \returns The [cppast::cpp_namespace_ref]() to the aliased namespace. /// \returns The [cppast::cpp_namespace_ref]() to the aliased namespace.
/// \notes If the namespace aliases aliases another namespace alias, /// \notes If the namespace aliases aliases another namespace alias,
@ -124,8 +120,7 @@ namespace cppast
private: private:
cpp_namespace_alias(std::string name, cpp_namespace_ref target) cpp_namespace_alias(std::string name, cpp_namespace_ref target)
: cpp_entity(std::move(name)), target_(std::move(target)) : cpp_entity(std::move(name)), target_(std::move(target))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -156,9 +151,7 @@ namespace cppast
} }
private: private:
cpp_using_directive(cpp_namespace_ref target) : cpp_entity(""), target_(std::move(target)) cpp_using_directive(cpp_namespace_ref target) : cpp_entity(""), target_(std::move(target)) {}
{
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -179,8 +172,7 @@ namespace cppast
/// as nothing can refer to it. /// as nothing can refer to it.
static std::unique_ptr<cpp_using_declaration> build(cpp_entity_ref target) static std::unique_ptr<cpp_using_declaration> build(cpp_entity_ref target)
{ {
return std::unique_ptr<cpp_using_declaration>( return std::unique_ptr<cpp_using_declaration>(new cpp_using_declaration(std::move(target)));
new cpp_using_declaration(std::move(target)));
} }
/// \returns The [cppast::cpp_entity_ref]() that is being used. /// \returns The [cppast::cpp_entity_ref]() that is being used.

View file

@ -19,7 +19,8 @@ namespace cppast
static cpp_entity_kind kind() noexcept; static cpp_entity_kind kind() noexcept;
/// \returns A newly built macro parameter. /// \returns A newly built macro parameter.
/// \notes It is not meant to be registered in the [cppast::cpp_entity_index]() as no other [cppast::cpp_entity]() can refer to it. /// \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_parameter> build(std::string name) static std::unique_ptr<cpp_macro_parameter> build(std::string name)
{ {
return std::unique_ptr<cpp_macro_parameter>(new cpp_macro_parameter(std::move(name))); return std::unique_ptr<cpp_macro_parameter>(new cpp_macro_parameter(std::move(name)));
@ -53,8 +54,7 @@ namespace cppast
{ {
public: public:
/// \effects Sets the name of the function like macro. /// \effects Sets the name of the function like macro.
function_like_builder(std::string name) function_like_builder(std::string name) : result_(new cpp_macro_definition(std::move(name)))
: result_(new cpp_macro_definition(std::move(name)))
{ {
result_->kind_ = function_like; result_->kind_ = function_like;
} }
@ -189,11 +189,8 @@ namespace cppast
private: private:
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
cpp_include_directive(const cpp_file_ref& target, cpp_include_kind kind, cpp_include_directive(const cpp_file_ref& target, cpp_include_kind kind, std::string full_path)
std::string full_path) : cpp_entity(target.name()), target_(target.id()[0u]), kind_(kind),
: cpp_entity(target.name()),
target_(target.id()[0u]),
kind_(kind),
full_path_(std::move(full_path)) full_path_(std::move(full_path))
{ {
DEBUG_ASSERT(!target.is_overloaded(), detail::precondition_error_handler{}); DEBUG_ASSERT(!target.is_overloaded(), detail::precondition_error_handler{});

View file

@ -39,8 +39,7 @@ namespace cppast
private: private:
cpp_static_assert(std::unique_ptr<cpp_expression> expr, std::string msg) cpp_static_assert(std::unique_ptr<cpp_expression> expr, std::string msg)
: cpp_entity(""), expr_(std::move(expr)), msg_(std::move(msg)) : cpp_entity(""), expr_(std::move(expr)), msg_(std::move(msg))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -18,10 +18,8 @@ namespace cppast
cpp_storage_class_auto = 1, //< *automatic* storage duration. cpp_storage_class_auto = 1, //< *automatic* storage duration.
cpp_storage_class_static = cpp_storage_class_static = 2, //< *static* or *thread* storage duration and *internal* linkage.
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_extern =
4, //< *static* or *thread* storage duration and *external* linkage.
cpp_storage_class_thread_local = 8, //< *thread* storage duration. cpp_storage_class_thread_local = 8, //< *thread* storage duration.
/// \notes This is the only one that can be combined with the others. /// \notes This is the only one that can be combined with the others.

View file

@ -11,8 +11,8 @@
#include <cppast/cpp_entity.hpp> #include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_container.hpp> #include <cppast/cpp_entity_container.hpp>
#include <cppast/cpp_token.hpp>
#include <cppast/cpp_template_parameter.hpp> #include <cppast/cpp_template_parameter.hpp>
#include <cppast/cpp_token.hpp>
namespace cppast namespace cppast
{ {
@ -22,8 +22,8 @@ namespace cppast
class cpp_template : public cpp_entity, public cpp_entity_container<cpp_template, cpp_entity> class cpp_template : public cpp_entity, public cpp_entity_container<cpp_template, cpp_entity>
{ {
public: public:
/// \returns An iteratable object iterating over the [cppast::cpp_template_parameter]() entities. /// \returns An iteratable object iterating over the [cppast::cpp_template_parameter]()
/// \notes These may be empty for a full specialization. /// entities. \notes These may be empty for a full specialization.
detail::iteratable_intrusive_list<cpp_template_parameter> parameters() const noexcept detail::iteratable_intrusive_list<cpp_template_parameter> parameters() const noexcept
{ {
return type_safe::ref(parameters_); return type_safe::ref(parameters_);
@ -38,9 +38,7 @@ namespace cppast
{ {
public: public:
/// \effects Sets the entity that is begin templated. /// \effects Sets the entity that is begin templated.
basic_builder(std::unique_ptr<EntityT> templ) : template_entity(new T(std::move(templ))) basic_builder(std::unique_ptr<EntityT> templ) : template_entity(new T(std::move(templ))) {}
{
}
basic_builder(basic_builder&&) = default; basic_builder(basic_builder&&) = default;
@ -59,14 +57,12 @@ namespace cppast
/// \effects Registers the template. /// \effects Registers the template.
/// \returns The finished template. /// \returns The finished template.
std::unique_ptr<T> finish(const cpp_entity_index& idx, cpp_entity_id id, std::unique_ptr<T> finish(const cpp_entity_index& idx, cpp_entity_id id, bool is_definition)
bool is_definition)
{ {
if (is_definition) if (is_definition)
idx.register_definition(std::move(id), type_safe::cref(*template_entity)); idx.register_definition(std::move(id), type_safe::cref(*template_entity));
else else
idx.register_forward_declaration(std::move(id), idx.register_forward_declaration(std::move(id), type_safe::cref(*template_entity));
type_safe::cref(*template_entity));
return std::move(template_entity); return std::move(template_entity);
} }
@ -86,9 +82,9 @@ namespace cppast
private: private:
type_safe::optional<cppast::cpp_scope_name> do_get_scope_name() const override type_safe::optional<cppast::cpp_scope_name> do_get_scope_name() const override
{ {
return begin()->scope_name() ? return begin()->scope_name()
type_safe::make_optional(cppast::cpp_scope_name(type_safe::ref(*this))) : ? type_safe::make_optional(cppast::cpp_scope_name(type_safe::ref(*this)))
type_safe::nullopt; : type_safe::nullopt;
} }
detail::intrusive_list<cpp_template_parameter> parameters_; detail::intrusive_list<cpp_template_parameter> parameters_;
@ -105,15 +101,13 @@ namespace cppast
/// \effects Sets the primary template being instantiated. /// \effects Sets the primary template being instantiated.
builder(cpp_template_ref templ) builder(cpp_template_ref templ)
: result_(new cpp_template_instantiation_type(std::move(templ))) : result_(new cpp_template_instantiation_type(std::move(templ)))
{ {}
}
/// \effects Adds the next argument. /// \effects Adds the next argument.
/// \requires No call to `add_unexposed_arguments()` has happened before. /// \requires No call to `add_unexposed_arguments()` has happened before.
void add_argument(cpp_template_argument arg) void add_argument(cpp_template_argument arg)
{ {
result_->arguments_ result_->arguments_.value(type_safe::variant_type<std::vector<cpp_template_argument>>{})
.value(type_safe::variant_type<std::vector<cpp_template_argument>>{})
.push_back(std::move(arg)); .push_back(std::move(arg));
} }
@ -144,8 +138,7 @@ namespace cppast
/// \returns Whether or not the arguments are exposed. /// \returns Whether or not the arguments are exposed.
bool arguments_exposed() const noexcept bool arguments_exposed() const noexcept
{ {
return arguments_.has_value( return arguments_.has_value(type_safe::variant_type<std::vector<cpp_template_argument>>{});
type_safe::variant_type<std::vector<cpp_template_argument>>{});
} }
/// \returns An array ref to the [cppast::cpp_template_argument](), if there are any. /// \returns An array ref to the [cppast::cpp_template_argument](), if there are any.
@ -153,8 +146,7 @@ namespace cppast
type_safe::optional<type_safe::array_ref<const cpp_template_argument>> arguments() const type_safe::optional<type_safe::array_ref<const cpp_template_argument>> arguments() const
noexcept noexcept
{ {
auto& vec = auto& vec = arguments_.value(type_safe::variant_type<std::vector<cpp_template_argument>>{});
arguments_.value(type_safe::variant_type<std::vector<cpp_template_argument>>{});
if (vec.empty()) if (vec.empty())
return type_safe::nullopt; return type_safe::nullopt;
return type_safe::ref(vec.data(), vec.size()); return type_safe::ref(vec.data(), vec.size());
@ -171,8 +163,7 @@ namespace cppast
cpp_template_instantiation_type(cpp_template_ref ref) cpp_template_instantiation_type(cpp_template_ref ref)
: arguments_(type_safe::variant_type<std::vector<cpp_template_argument>>{}), : arguments_(type_safe::variant_type<std::vector<cpp_template_argument>>{}),
templ_(std::move(ref)) templ_(std::move(ref))
{ {}
}
cpp_type_kind do_get_kind() const noexcept override cpp_type_kind do_get_kind() const noexcept override
{ {
@ -196,8 +187,7 @@ namespace cppast
/// \returns Whether or not the arguments are exposed. /// \returns Whether or not the arguments are exposed.
bool arguments_exposed() const noexcept bool arguments_exposed() const noexcept
{ {
return arguments_.has_value( return arguments_.has_value(type_safe::variant_type<std::vector<cpp_template_argument>>{});
type_safe::variant_type<std::vector<cpp_template_argument>>{});
} }
/// \returns An iteratable object iterating over the [cppast::cpp_template_argument]()s. /// \returns An iteratable object iterating over the [cppast::cpp_template_argument]()s.
@ -206,8 +196,7 @@ namespace cppast
/// meaning that the arguments are not explictly given but deduced from the signature. /// meaning that the arguments are not explictly given but deduced from the signature.
type_safe::array_ref<const cpp_template_argument> arguments() const noexcept type_safe::array_ref<const cpp_template_argument> arguments() const noexcept
{ {
auto& vec = auto& vec = arguments_.value(type_safe::variant_type<std::vector<cpp_template_argument>>{});
arguments_.value(type_safe::variant_type<std::vector<cpp_template_argument>>{});
return type_safe::ref(vec.data(), vec.size()); return type_safe::ref(vec.data(), vec.size());
} }
@ -241,12 +230,12 @@ namespace cppast
this->template_entity = std::unique_ptr<T>(new T(std::move(entity), templ)); this->template_entity = std::unique_ptr<T>(new T(std::move(entity), templ));
} }
/// \effects Adds the next argument for the [cppast::cpp_template_parameter]() of the primary template. /// \effects Adds the next argument for the [cppast::cpp_template_parameter]() of the
/// \requires No call to `add_unexposed_arguments()` has happened before. /// primary template. \requires No call to `add_unexposed_arguments()` has happened before.
void add_argument(cpp_template_argument arg) void add_argument(cpp_template_argument arg)
{ {
auto& specialization = auto& specialization
static_cast<cpp_template_specialization&>(*this->template_entity); = static_cast<cpp_template_specialization&>(*this->template_entity);
specialization.arguments_ specialization.arguments_
.value(type_safe::variant_type<std::vector<cpp_template_argument>>{}) .value(type_safe::variant_type<std::vector<cpp_template_argument>>{})
.push_back(std::move(arg)); .push_back(std::move(arg));
@ -255,8 +244,8 @@ namespace cppast
/// \effects Adds unexposed arguments as string. /// \effects Adds unexposed arguments as string.
void add_unexposed_arguments(cpp_token_string arg) void add_unexposed_arguments(cpp_token_string arg)
{ {
auto& specialization = auto& specialization
static_cast<cpp_template_specialization&>(*this->template_entity); = static_cast<cpp_template_specialization&>(*this->template_entity);
specialization.arguments_ = std::move(arg); specialization.arguments_ = std::move(arg);
} }
@ -265,8 +254,7 @@ namespace cppast
}; };
/// \effects Sets the entity that is being templated and the primary template. /// \effects Sets the entity that is being templated and the primary template.
cpp_template_specialization(std::unique_ptr<cpp_entity> entity, cpp_template_specialization(std::unique_ptr<cpp_entity> entity, const cpp_template_ref& templ)
const cpp_template_ref& templ)
: cpp_template(std::move(entity)), : cpp_template(std::move(entity)),
arguments_(type_safe::variant_type<std::vector<cpp_template_argument>>{}), arguments_(type_safe::variant_type<std::vector<cpp_template_argument>>{}),
templ_(templ.id()[0u]) templ_(templ.id()[0u])

View file

@ -8,9 +8,9 @@
#include <type_safe/optional.hpp> #include <type_safe/optional.hpp>
#include <type_safe/variant.hpp> #include <type_safe/variant.hpp>
#include <cppast/detail/intrusive_list.hpp>
#include <cppast/cpp_entity.hpp> #include <cppast/cpp_entity.hpp>
#include <cppast/cpp_variable_base.hpp> #include <cppast/cpp_variable_base.hpp>
#include <cppast/detail/intrusive_list.hpp>
namespace cppast namespace cppast
{ {
@ -27,8 +27,7 @@ namespace cppast
protected: protected:
cpp_template_parameter(std::string name, bool variadic) cpp_template_parameter(std::string name, bool variadic)
: cpp_entity(std::move(name)), variadic_(variadic) : cpp_entity(std::move(name)), variadic_(variadic)
{ {}
}
private: private:
bool variadic_; bool variadic_;
@ -53,9 +52,8 @@ namespace cppast
/// \returns A newly created and registered template type parameter. /// \returns A newly created and registered template type parameter.
/// \notes The `default_type` may be `nullptr` in which case the parameter has no default. /// \notes The `default_type` may be `nullptr` in which case the parameter has no default.
static std::unique_ptr<cpp_template_type_parameter> build( static std::unique_ptr<cpp_template_type_parameter> build(
const cpp_entity_index& idx, cpp_entity_id id, std::string name, const cpp_entity_index& idx, cpp_entity_id id, std::string name, cpp_template_keyword kw,
cpp_template_keyword kw, bool variadic, bool variadic, std::unique_ptr<cpp_type> default_type = nullptr);
std::unique_ptr<cpp_type> default_type = nullptr);
/// \returns A [ts::optional_ref]() to the default type. /// \returns A [ts::optional_ref]() to the default type.
type_safe::optional_ref<const cpp_type> default_type() const noexcept type_safe::optional_ref<const cpp_type> default_type() const noexcept
@ -72,11 +70,9 @@ namespace cppast
private: private:
cpp_template_type_parameter(std::string name, cpp_template_keyword kw, bool variadic, cpp_template_type_parameter(std::string name, cpp_template_keyword kw, bool variadic,
std::unique_ptr<cpp_type> default_type) std::unique_ptr<cpp_type> default_type)
: cpp_template_parameter(std::move(name), variadic), : cpp_template_parameter(std::move(name), variadic), default_type_(std::move(default_type)),
default_type_(std::move(default_type)),
keyword_(kw) keyword_(kw)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -94,8 +90,8 @@ namespace cppast
} // namespace detail } // namespace detail
/// Reference to a [cppast::cpp_template_type_parameter](). /// Reference to a [cppast::cpp_template_type_parameter]().
using cpp_template_type_parameter_ref = using cpp_template_type_parameter_ref
basic_cpp_entity_ref<cpp_template_type_parameter, = basic_cpp_entity_ref<cpp_template_type_parameter,
detail::cpp_template_parameter_ref_predicate>; detail::cpp_template_parameter_ref_predicate>;
/// A [cppast::cpp_type]() defined by a [cppast::cpp_template_type_parameter](). /// A [cppast::cpp_type]() defined by a [cppast::cpp_template_type_parameter]().
@ -119,8 +115,7 @@ namespace cppast
private: private:
cpp_template_parameter_type(cpp_template_type_parameter_ref parameter) cpp_template_parameter_type(cpp_template_type_parameter_ref parameter)
: parameter_(std::move(parameter)) : parameter_(std::move(parameter))
{ {}
}
cpp_type_kind do_get_kind() const noexcept override cpp_type_kind do_get_kind() const noexcept override
{ {
@ -145,12 +140,11 @@ namespace cppast
std::unique_ptr<cpp_expression> default_value = nullptr); std::unique_ptr<cpp_expression> default_value = nullptr);
private: private:
cpp_non_type_template_parameter(std::string name, std::unique_ptr<cpp_type> type, cpp_non_type_template_parameter(std::string name, std::unique_ptr<cpp_type> type, bool variadic,
bool variadic, std::unique_ptr<cpp_expression> def) std::unique_ptr<cpp_expression> def)
: cpp_template_parameter(std::move(name), variadic), : cpp_template_parameter(std::move(name), variadic),
cpp_variable_base(std::move(type), std::move(def)) cpp_variable_base(std::move(type), std::move(def))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
}; };
@ -182,8 +176,7 @@ namespace cppast
/// \effects Sets the name and whether it is variadic. /// \effects Sets the name and whether it is variadic.
builder(std::string name, bool variadic) builder(std::string name, bool variadic)
: parameter_(new cpp_template_template_parameter(std::move(name), variadic)) : parameter_(new cpp_template_template_parameter(std::move(name), variadic))
{ {}
}
/// \effects Sets the keyword, /// \effects Sets the keyword,
/// default is [cpp_template_keyword::keyword_class](). /// default is [cpp_template_keyword::keyword_class]().
@ -218,7 +211,8 @@ namespace cppast
std::unique_ptr<cpp_template_template_parameter> parameter_; std::unique_ptr<cpp_template_template_parameter> parameter_;
}; };
/// \returns An iteratable object containing the template parameters of the template template parameter. /// \returns An iteratable object containing the template parameters of the template template
/// parameter.
detail::iteratable_intrusive_list<cpp_template_parameter> parameters() const noexcept detail::iteratable_intrusive_list<cpp_template_parameter> parameters() const noexcept
{ {
return type_safe::ref(parameters_); return type_safe::ref(parameters_);
@ -240,8 +234,7 @@ namespace cppast
cpp_template_template_parameter(std::string name, bool variadic) cpp_template_template_parameter(std::string name, bool variadic)
: cpp_template_parameter(std::move(name), variadic), : cpp_template_parameter(std::move(name), variadic),
keyword_(cpp_template_keyword::keyword_class) keyword_(cpp_template_keyword::keyword_class)
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -252,35 +245,32 @@ namespace cppast
/// An argument for a [cppast::cpp_template_parameter](). /// An argument for a [cppast::cpp_template_parameter]().
/// ///
/// It is based on a [ts::variant]() of [cppast::cpp_type]() (for [cppast::cpp_template_type_parameter]()), /// It is based on a [ts::variant]() of [cppast::cpp_type]() (for
/// [cppast::cpp_expression]() (for [cppast::cpp_non_type_template_parameter]()) and [cppast::cpp_template_ref]() /// [cppast::cpp_template_type_parameter]()), [cppast::cpp_expression]() (for
/// (for [cppast::cpp_template_template_parameter](). /// [cppast::cpp_non_type_template_parameter]()) and [cppast::cpp_template_ref]() (for
/// [cppast::cpp_template_template_parameter]().
class cpp_template_argument class cpp_template_argument
{ {
public: public:
/// \effects Initializes it passing a type as argument. /// \effects Initializes it passing a type as argument.
/// This corresponds to a [cppast::cpp_template_type_parameter](). /// This corresponds to a [cppast::cpp_template_type_parameter]().
/// \notes This constructor only participates in overload resolution if `T` is dervied from [cppast::cpp_type](). /// \notes This constructor only participates in overload resolution if `T` is dervied from
/// \param 1 /// [cppast::cpp_type](). \param 1 \exclude
/// \exclude
template <typename T, template <typename T,
typename std::enable_if<std::is_base_of<cpp_type, T>::value, int>::type = 0> typename std::enable_if<std::is_base_of<cpp_type, T>::value, int>::type = 0>
cpp_template_argument(std::unique_ptr<T> type) cpp_template_argument(std::unique_ptr<T> type)
: arg_(std::unique_ptr<cpp_type>(std::move(type))) : arg_(std::unique_ptr<cpp_type>(std::move(type)))
{ {}
}
/// \effects Initializes it passing an expression as argument. /// \effects Initializes it passing an expression as argument.
/// This corresponds to a [cppast::cpp_non_type_template_parameter](). /// This corresponds to a [cppast::cpp_non_type_template_parameter]().
/// \notes This constructor only participates in overload resolution if `T` is dervied from [cppast::cpp_expression](). /// \notes This constructor only participates in overload resolution if `T` is dervied from
/// \param 1 /// [cppast::cpp_expression](). \param 1 \exclude
/// \exclude template <typename T,
template <typename T, typename = typename std::enable_if< typename = typename std::enable_if<std::is_base_of<cpp_expression, T>::value>::type>
std::is_base_of<cpp_expression, T>::value>::type>
cpp_template_argument(std::unique_ptr<T> expr) cpp_template_argument(std::unique_ptr<T> expr)
: arg_(std::unique_ptr<cpp_expression>(std::move(expr))) : arg_(std::unique_ptr<cpp_expression>(std::move(expr)))
{ {}
}
/// \effects Initializes it passing a template as argument. /// \effects Initializes it passing a template as argument.
/// This corresponds to a [cppast::cpp_template_template_parameter](). /// This corresponds to a [cppast::cpp_template_template_parameter]().
@ -295,9 +285,7 @@ namespace cppast
type_safe::optional_ref<const cpp_expression> expression() const noexcept type_safe::optional_ref<const cpp_expression> expression() const noexcept
{ {
return arg_.optional_value(type_safe::variant_type<std::unique_ptr<cpp_expression>>{}) return arg_.optional_value(type_safe::variant_type<std::unique_ptr<cpp_expression>>{})
.map([](const std::unique_ptr<cpp_expression>& expr) { .map([](const std::unique_ptr<cpp_expression>& expr) { return type_safe::ref(*expr); });
return type_safe::ref(*expr);
});
} }
type_safe::optional_ref<const cpp_template_ref> template_ref() const noexcept type_safe::optional_ref<const cpp_template_ref> template_ref() const noexcept
@ -306,8 +294,7 @@ namespace cppast
} }
private: private:
type_safe::variant<std::unique_ptr<cpp_type>, std::unique_ptr<cpp_expression>, type_safe::variant<std::unique_ptr<cpp_type>, std::unique_ptr<cpp_expression>, cpp_template_ref>
cpp_template_ref>
arg_; arg_;
}; };
} // namespace cppast } // namespace cppast

View file

@ -30,10 +30,8 @@ namespace cppast
std::string spelling; std::string spelling;
cpp_token_kind kind; cpp_token_kind kind;
cpp_token(cpp_token_kind kind, std::string spelling) cpp_token(cpp_token_kind kind, std::string spelling) : spelling(std::move(spelling)), kind(kind)
: spelling(std::move(spelling)), kind(kind) {}
{
}
friend bool operator==(const cpp_token& lhs, const cpp_token& rhs) noexcept friend bool operator==(const cpp_token& lhs, const cpp_token& rhs) noexcept
{ {
@ -77,8 +75,8 @@ namespace cppast
/// Tokenizes a string. /// Tokenizes a string.
/// \effects Splits the string into C++ tokens. /// \effects Splits the string into C++ tokens.
/// The string must contain valid tokens and must already be preprocessed (i.e. translation phase 6 is already done). /// The string must contain valid tokens and must already be preprocessed (i.e. translation
/// \returns The tokenized string. /// phase 6 is already done). \returns The tokenized string.
static cpp_token_string tokenize(std::string str); static cpp_token_string tokenize(std::string str);
/// \effects Creates it from a sequence of tokens. /// \effects Creates it from a sequence of tokens.

View file

@ -8,9 +8,9 @@
#include <atomic> #include <atomic>
#include <memory> #include <memory>
#include <cppast/detail/intrusive_list.hpp>
#include <cppast/cpp_entity_ref.hpp>
#include <cppast/code_generator.hpp> #include <cppast/code_generator.hpp>
#include <cppast/cpp_entity_ref.hpp>
#include <cppast/detail/intrusive_list.hpp>
namespace cppast namespace cppast
{ {
@ -67,7 +67,8 @@ namespace cppast
/// User data is just some kind of pointer, there are no requirements. /// User data is just some kind of pointer, there are no requirements.
/// The class will do no lifetime management. /// The class will do no lifetime management.
/// ///
/// User data is useful if you need to store additional data for an entity without the need to maintain a registry. /// User data is useful if you need to store additional data for an entity without the need to
/// maintain a registry.
void set_user_data(void* data) const noexcept void set_user_data(void* data) const noexcept
{ {
user_data_ = data; user_data_ = data;
@ -205,11 +206,11 @@ namespace cppast
/// \returns A newly created user-defined type. /// \returns A newly created user-defined type.
static std::unique_ptr<cpp_user_defined_type> build(cpp_type_ref entity) static std::unique_ptr<cpp_user_defined_type> build(cpp_type_ref entity)
{ {
return std::unique_ptr<cpp_user_defined_type>( return std::unique_ptr<cpp_user_defined_type>(new cpp_user_defined_type(std::move(entity)));
new cpp_user_defined_type(std::move(entity)));
} }
/// \returns A [cppast::cpp_type_ref]() to the associated [cppast::cpp_entity]() that is the type. /// \returns A [cppast::cpp_type_ref]() to the associated [cppast::cpp_entity]() that is the
/// type.
const cpp_type_ref& entity() const noexcept const cpp_type_ref& entity() const noexcept
{ {
return entity_; return entity_;
@ -268,7 +269,8 @@ namespace cppast
} }
/// \returns A reference to the [cppast::cpp_type]() it depends one. /// \returns A reference to the [cppast::cpp_type]() it depends one.
/// \notes This is either [cppast::cpp_template_parameter_type]() or [cppast:cpp_template_instantiation_type](). /// \notes This is either [cppast::cpp_template_parameter_type]() or
/// [cppast:cpp_template_instantiation_type]().
const cpp_type& dependee() const noexcept const cpp_type& dependee() const noexcept
{ {
return *dependee_; return *dependee_;
@ -277,8 +279,7 @@ namespace cppast
private: private:
cpp_dependent_type(std::string name, std::unique_ptr<cpp_type> dependee) cpp_dependent_type(std::string name, std::unique_ptr<cpp_type> dependee)
: name_(std::move(name)), dependee_(std::move(dependee)) : name_(std::move(name)), dependee_(std::move(dependee))
{ {}
}
cpp_type_kind do_get_kind() const noexcept override cpp_type_kind do_get_kind() const noexcept override
{ {
@ -316,8 +317,7 @@ namespace cppast
public: public:
/// \returns A newly created qualified type. /// \returns A newly created qualified type.
/// \requires `cv` must not be [cppast::cpp_cv::cpp_cv_none](). /// \requires `cv` must not be [cppast::cpp_cv::cpp_cv_none]().
static std::unique_ptr<cpp_cv_qualified_type> build(std::unique_ptr<cpp_type> type, static std::unique_ptr<cpp_cv_qualified_type> build(std::unique_ptr<cpp_type> type, cpp_cv cv)
cpp_cv cv)
{ {
DEBUG_ASSERT(cv != cpp_cv_none, detail::precondition_error_handler{}); DEBUG_ASSERT(cv != cpp_cv_none, detail::precondition_error_handler{});
return std::unique_ptr<cpp_cv_qualified_type>( return std::unique_ptr<cpp_cv_qualified_type>(
@ -339,8 +339,7 @@ namespace cppast
private: private:
cpp_cv_qualified_type(std::unique_ptr<cpp_type> type, cpp_cv cv) cpp_cv_qualified_type(std::unique_ptr<cpp_type> type, cpp_cv cv)
: type_(std::move(type)), cv_(cv) : type_(std::move(type)), cv_(cv)
{ {}
}
cpp_type_kind do_get_kind() const noexcept override cpp_type_kind do_get_kind() const noexcept override
{ {
@ -405,8 +404,7 @@ namespace cppast
cpp_reference ref) cpp_reference ref)
{ {
DEBUG_ASSERT(ref != cpp_ref_none, detail::precondition_error_handler{}); DEBUG_ASSERT(ref != cpp_ref_none, detail::precondition_error_handler{});
return std::unique_ptr<cpp_reference_type>( return std::unique_ptr<cpp_reference_type>(new cpp_reference_type(std::move(type), ref));
new cpp_reference_type(std::move(type), ref));
} }
/// \returns A reference to the [cppast::cpp_type]() that is referenced. /// \returns A reference to the [cppast::cpp_type]() that is referenced.
@ -424,8 +422,7 @@ namespace cppast
private: private:
cpp_reference_type(std::unique_ptr<cpp_type> referee, cpp_reference ref) cpp_reference_type(std::unique_ptr<cpp_type> referee, cpp_reference ref)
: referee_(std::move(referee)), ref_(ref) : referee_(std::move(referee)), ref_(ref)
{ {}
}
cpp_type_kind do_get_kind() const noexcept override cpp_type_kind do_get_kind() const noexcept override
{ {

View file

@ -19,13 +19,11 @@ namespace cppast
/// \returns A newly created and registered type alias. /// \returns A newly created and registered type alias.
static std::unique_ptr<cpp_type_alias> build(const cpp_entity_index& idx, cpp_entity_id id, static std::unique_ptr<cpp_type_alias> build(const cpp_entity_index& idx, cpp_entity_id id,
std::string name, std::string name, std::unique_ptr<cpp_type> type);
std::unique_ptr<cpp_type> type);
/// \returns A newly created type alias that isn't registered. /// \returns A newly created type alias that isn't registered.
/// \notes This function is intendend for templated type aliases. /// \notes This function is intendend for templated type aliases.
static std::unique_ptr<cpp_type_alias> build(std::string name, static std::unique_ptr<cpp_type_alias> build(std::string name, std::unique_ptr<cpp_type> type);
std::unique_ptr<cpp_type> type);
/// \returns A reference to the aliased [cppast::cpp_type](). /// \returns A reference to the aliased [cppast::cpp_type]().
const cpp_type& underlying_type() const noexcept const cpp_type& underlying_type() const noexcept
@ -36,8 +34,7 @@ namespace cppast
private: private:
cpp_type_alias(std::string name, std::unique_ptr<cpp_type> type) cpp_type_alias(std::string name, std::unique_ptr<cpp_type> type)
: cpp_entity(std::move(name)), type_(std::move(type)) : cpp_entity(std::move(name)), type_(std::move(type))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -55,12 +55,9 @@ namespace cppast
cpp_variable(std::string name, std::unique_ptr<cpp_type> type, cpp_variable(std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def, cpp_storage_class_specifiers spec, std::unique_ptr<cpp_expression> def, cpp_storage_class_specifiers spec,
bool is_constexpr) bool is_constexpr)
: cpp_entity(std::move(name)), : cpp_entity(std::move(name)), cpp_variable_base(std::move(type), std::move(def)),
cpp_variable_base(std::move(type), std::move(def)), storage_(spec), is_constexpr_(is_constexpr)
storage_(spec), {}
is_constexpr_(is_constexpr)
{
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -32,8 +32,7 @@ namespace cppast
protected: protected:
cpp_variable_base(std::unique_ptr<cpp_type> type, std::unique_ptr<cpp_expression> def) cpp_variable_base(std::unique_ptr<cpp_type> type, std::unique_ptr<cpp_expression> def)
: type_(std::move(type)), default_(std::move(def)) : type_(std::move(type)), default_(std::move(def))
{ {}
}
~cpp_variable_base() noexcept = default; ~cpp_variable_base() noexcept = default;

View file

@ -32,8 +32,7 @@ namespace cppast
private: private:
cpp_variable_template(std::unique_ptr<cpp_variable> variable) cpp_variable_template(std::unique_ptr<cpp_variable> variable)
: cpp_template(std::unique_ptr<cpp_entity>(variable.release())) : cpp_template(std::unique_ptr<cpp_entity>(variable.release()))
{ {}
}
cpp_entity_kind do_get_entity_kind() const noexcept override; cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -25,14 +25,12 @@ namespace cppast
{ {
struct assert_handler : debug_assert::set_level<CPPAST_ASSERTION_LEVEL>, struct assert_handler : debug_assert::set_level<CPPAST_ASSERTION_LEVEL>,
debug_assert::default_handler debug_assert::default_handler
{ {};
};
struct precondition_error_handler : debug_assert::set_level<CPPAST_PRECONDITION_LEVEL>, struct precondition_error_handler : debug_assert::set_level<CPPAST_PRECONDITION_LEVEL>,
debug_assert::default_handler debug_assert::default_handler
{ {};
}; } // namespace detail
} } // namespace cppast
} // namespace cppast::detail
#endif // CPPAST_ASSERT_HPP_INCLUDED #endif // CPPAST_ASSERT_HPP_INCLUDED

View file

@ -5,8 +5,8 @@
#ifndef CPPAST_INTRUSIVE_LIST_HPP_INCLUDED #ifndef CPPAST_INTRUSIVE_LIST_HPP_INCLUDED
#define CPPAST_INTRUSIVE_LIST_HPP_INCLUDED #define CPPAST_INTRUSIVE_LIST_HPP_INCLUDED
#include <memory>
#include <iterator> #include <iterator>
#include <memory>
#include <type_safe/optional_ref.hpp> #include <type_safe/optional_ref.hpp>
@ -120,15 +120,15 @@ namespace cppast
intrusive_list() = default; intrusive_list() = default;
//=== modifiers ===// //=== modifiers ===//
template <typename Dummy = T, typename = typename std::enable_if< template <typename Dummy = T,
std::is_same<Dummy, cpp_file>::value>::type> typename = typename std::enable_if<std::is_same<Dummy, cpp_file>::value>::type>
void push_back(std::unique_ptr<T> obj) noexcept void push_back(std::unique_ptr<T> obj) noexcept
{ {
push_back_impl(std::move(obj)); push_back_impl(std::move(obj));
} }
template <typename U, typename = typename std::enable_if< template <typename U,
!std::is_same<T, cpp_file>::value, U>::type> typename = typename std::enable_if<!std::is_same<T, cpp_file>::value, U>::type>
void push_back(const U& parent, std::unique_ptr<T> obj) noexcept void push_back(const U& parent, std::unique_ptr<T> obj) noexcept
{ {
push_back_impl(std::move(obj)); push_back_impl(std::move(obj));
@ -210,10 +210,8 @@ namespace cppast
class iteratable_intrusive_list class iteratable_intrusive_list
{ {
public: public:
iteratable_intrusive_list(type_safe::object_ref<const intrusive_list<T>> list) iteratable_intrusive_list(type_safe::object_ref<const intrusive_list<T>> list) : list_(list)
: list_(list) {}
{
}
bool empty() const noexcept bool empty() const noexcept
{ {
@ -235,7 +233,7 @@ namespace cppast
private: private:
type_safe::object_ref<const intrusive_list<T>> list_; type_safe::object_ref<const intrusive_list<T>> list_;
}; };
} } // namespace detail
} // namespace cppast::detail } // namespace cppast
#endif // CPPAST_INTRUSIVE_LIST_HPP_INCLUDED #endif // CPPAST_INTRUSIVE_LIST_HPP_INCLUDED

View file

@ -90,7 +90,8 @@ namespace cppast
warning, //< A warning that doesn't impact AST generation. warning, //< A warning that doesn't impact AST generation.
error, //< A non-critical error that does impact AST generation but not critically. error, //< A non-critical error that does impact AST generation but not critically.
critical, //< A critical error where AST generation isn't possible. critical, //< A critical error where AST generation isn't possible.
/// \notes This will usually result in an exception being thrown after the diagnostic has been displayed. /// \notes This will usually result in an exception being thrown after the diagnostic has been
/// displayed.
}; };
/// \returns A human-readable string describing the severity. /// \returns A human-readable string describing the severity.

View file

@ -26,7 +26,8 @@ namespace cppast
/// \effects Logs the diagnostic by invoking the `do_log()` member function. /// \effects Logs the diagnostic by invoking the `do_log()` member function.
/// \returns Whether or not the diagnostic was logged. /// \returns Whether or not the diagnostic was logged.
/// \notes `source` points to a string literal that gives additional context to what generates the message. /// \notes `source` points to a string literal that gives additional context to what generates
/// the message.
bool log(const char* source, const diagnostic& d) const; bool log(const char* source, const diagnostic& d) const;
/// \effects Sets whether or not the logger prints debugging diagnostics. /// \effects Sets whether or not the logger prints debugging diagnostics.

View file

@ -97,7 +97,8 @@ namespace cppast
/// ///
/// \effects It will set the clang binary determined by the build system, /// \effects It will set the clang binary determined by the build system,
/// as well as the libclang system include directory determined by the build system. /// as well as the libclang system include directory determined by the build system.
/// It will also define `__cppast__` with the value `"libclang"` as well as `__cppast_major__` and `__cppast_minor__`. /// It will also define `__cppast__` with the value `"libclang"` as well as `__cppast_major__`
/// and `__cppast_minor__`.
libclang_compile_config(); libclang_compile_config();
/// Creates the configuration stored in the database. /// Creates the configuration stored in the database.
@ -110,15 +111,15 @@ namespace cppast
/// you need to pass in the file name of the corresponding source file, /// you need to pass in the file name of the corresponding source file,
/// if you want to parse one. /// if you want to parse one.
/// \notes It will only consider options you could also set by the other functions. /// \notes It will only consider options you could also set by the other functions.
/// \notes The file key will include the specified directory in the JSON, if it is not a full path. /// \notes The file key will include the specified directory in the JSON, if it is not a full
libclang_compile_config(const libclang_compilation_database& database, /// path.
const std::string& file); libclang_compile_config(const libclang_compilation_database& database, const std::string& file);
libclang_compile_config(const libclang_compile_config& other) = default; libclang_compile_config(const libclang_compile_config& other) = default;
libclang_compile_config& operator=(const libclang_compile_config& other) = default; libclang_compile_config& operator=(const libclang_compile_config& other) = default;
/// \effects Sets the path to the location of the `clang++` binary and the version of that binary. /// \effects Sets the path to the location of the `clang++` binary and the version of that
/// \notes It will be used for preprocessing. /// binary. \notes It will be used for preprocessing.
void set_clang_binary(std::string binary, int major, int minor, int patch) void set_clang_binary(std::string binary, int major, int minor, int patch)
{ {
clang_binary_ = std::move(binary); clang_binary_ = std::move(binary);
@ -134,13 +135,12 @@ namespace cppast
/// \effects Sets whether or not the fast preprocessor is enabled. /// \effects Sets whether or not the fast preprocessor is enabled.
/// Default value is `false`. /// Default value is `false`.
/// \notes The fast preprocessor gets a list of all macros that are defined in the translation unit, /// \notes The fast preprocessor gets a list of all macros that are defined in the translation
/// then preprocesses it without resolving includes but manually defining the list of macros to ensure correctness. /// unit, then preprocesses it without resolving includes but manually defining the list of
/// Later stages will use the includes again. /// macros to ensure correctness. Later stages will use the includes again. This hack breaks if
/// This hack breaks if you define the same macro multiple times in the file being parsed (headers don't matter) /// you define the same macro multiple times in the file being parsed (headers don't matter) or
/// or you rely on the order of macro directives. /// you rely on the order of macro directives. \notes If this option is `true`, the full file
/// \notes If this option is `true`, the full file name of include directives is not available, /// name of include directives is not available, just the name as written in the source code.
/// just the name as written in the source code.
void fast_preprocessing(bool b) noexcept void fast_preprocessing(bool b) noexcept
{ {
fast_preprocessing_ = b; fast_preprocessing_ = b;
@ -180,10 +180,11 @@ namespace cppast
/// Finds a configuration for a given file. /// Finds a configuration for a given file.
/// ///
/// \returns If the database contains a configuration for the given file, returns that configuration. /// \returns If the database contains a configuration for the given file, returns that
/// Otherwise removes the file extension of the file and tries the same procedure /// configuration. Otherwise removes the file extension of the file and tries the same procedure for
/// for common C++ header and source file extensions. /// common C++ header and source file extensions. \notes This function is intended to be used as the
/// \notes This function is intended to be used as the basis for a `get_config` function of [cppast::parse_files](standardese://cppast::parse_files_basic/). /// basis for a `get_config` function of
/// [cppast::parse_files](standardese://cppast::parse_files_basic/).
type_safe::optional<libclang_compile_config> find_config_for( type_safe::optional<libclang_compile_config> find_config_for(
const libclang_compilation_database& database, std::string file_name); const libclang_compilation_database& database, std::string file_name);
@ -211,10 +212,11 @@ namespace cppast
/// Parses multiple files using a [cppast::libclang_parser]() and a compilation database. /// Parses multiple files using a [cppast::libclang_parser]() and a compilation database.
/// ///
/// \effects Invokes [cppast::parse_files](standardese://parse_files_basic/) passing it the parser and file names, /// \effects Invokes [cppast::parse_files](standardese://parse_files_basic/) passing it the parser
/// and a `get_config` function using [cppast::find_config_for](). /// and file names, and a `get_config` function using [cppast::find_config_for]().
/// ///
/// \throws [cppast::libclang_error]() if no configuration for a given file could be found in the database. /// \throws [cppast::libclang_error]() if no configuration for a given file could be found in the
/// database.
/// ///
/// \requires `FileParser` must use the libclang parser. /// \requires `FileParser` must use the libclang parser.
/// i.e. `FileParser::parser` must be an alias of [cppast::libclang_parser](). /// i.e. `FileParser::parser` must be an alias of [cppast::libclang_parser]().
@ -237,8 +239,8 @@ namespace cppast
/// \effects For each file specified in a compilation database, /// \effects For each file specified in a compilation database,
/// uses the `FileParser` to parse the file with the configuration specified in the database. /// uses the `FileParser` to parse the file with the configuration specified in the database.
/// ///
/// \requires `FileParser` must have the same requirements as for [cppast::parse_files](standardese://parse_files_basic/). /// \requires `FileParser` must have the same requirements as for
/// It must also use the libclang parser, /// [cppast::parse_files](standardese://parse_files_basic/). It must also use the libclang parser,
/// i.e. `FileParser::parser` must be an alias of [cppast::libclang_parser](). /// i.e. `FileParser::parser` must be an alias of [cppast::libclang_parser]().
template <class FileParser> template <class FileParser>
void parse_database(FileParser& parser, const libclang_compilation_database& database) void parse_database(FileParser& parser, const libclang_compilation_database& database)

View file

@ -10,8 +10,8 @@
#include <cppast/compile_config.hpp> #include <cppast/compile_config.hpp>
#include <cppast/cpp_file.hpp> #include <cppast/cpp_file.hpp>
#include <cppast/cpp_preprocessor.hpp> #include <cppast/cpp_preprocessor.hpp>
#include <cppast/diagnostic_logger.hpp>
#include <cppast/diagnostic.hpp> #include <cppast/diagnostic.hpp>
#include <cppast/diagnostic_logger.hpp>
namespace cppast namespace cppast
{ {
@ -22,7 +22,8 @@ namespace cppast
/// It reads a C++ source file and creates the matching [cppast::cpp_file](). /// It reads a C++ source file and creates the matching [cppast::cpp_file]().
/// Derived classes can implement how the file is parsed. /// Derived classes can implement how the file is parsed.
/// ///
/// \requires A derived class must provide an alias `config` which is the corresponding derived class of the [cppast::compile_config](). /// \requires A derived class must provide an alias `config` which is the corresponding derived
/// class of the [cppast::compile_config]().
class parser class parser
{ {
public: public:
@ -33,9 +34,9 @@ namespace cppast
/// \effects Parses the given file. /// \effects Parses the given file.
/// \returns The [cppast::cpp_file]() object describing it. /// \returns The [cppast::cpp_file]() object describing it.
/// It can be `nullptr`, if there was an error or the specified file already registered in the index. /// It can be `nullptr`, if there was an error or the specified file already registered in the
/// \requires The dynamic type of `config` must match the required config type. /// index. \requires The dynamic type of `config` must match the required config type. \notes
/// \notes This function is thread safe. /// This function is thread safe.
std::unique_ptr<cpp_file> parse(const cpp_entity_index& idx, std::string path, std::unique_ptr<cpp_file> parse(const cpp_entity_index& idx, std::string path,
const compile_config& config) const const compile_config& config) const
{ {
@ -65,11 +66,11 @@ namespace cppast
/// \effects Creates it giving it a reference to the logger it uses. /// \effects Creates it giving it a reference to the logger it uses.
explicit parser(type_safe::object_ref<const diagnostic_logger> logger) explicit parser(type_safe::object_ref<const diagnostic_logger> logger)
: logger_(logger), error_(false) : logger_(logger), error_(false)
{ {}
}
/// \effects Sets the error state. /// \effects Sets the error state.
/// This must be called when an error or critical diagnostic is logged and the AST is incomplete. /// This must be called when an error or critical diagnostic is logged and the AST is
/// incomplete.
void set_error() const noexcept void set_error() const noexcept
{ {
error_ = true; error_ = true;
@ -102,19 +103,16 @@ namespace cppast
/// \effects Creates a file parser populating the given index /// \effects Creates a file parser populating the given index
/// and using the parser created by forwarding the given arguments. /// and using the parser created by forwarding the given arguments.
template <typename... Args> template <typename... Args>
explicit simple_file_parser(type_safe::object_ref<const cpp_entity_index> idx, explicit simple_file_parser(type_safe::object_ref<const cpp_entity_index> idx, Args&&... args)
Args&&... args)
: parser_(std::forward<Args>(args)...), idx_(idx) : parser_(std::forward<Args>(args)...), idx_(idx)
{ {}
}
/// \effects Parses the given file using the given configuration. /// \effects Parses the given file using the given configuration.
/// \returns The parsed file or an empty optional, if a fatal error occurred. /// \returns The parsed file or an empty optional, if a fatal error occurred.
type_safe::optional_ref<const cpp_file> parse(std::string path, const config& c) type_safe::optional_ref<const cpp_file> parse(std::string path, const config& c)
{ {
parser_.logger().log("simple file parser", parser_.logger().log("simple file parser", diagnostic{"parsing file '" + path + "'",
diagnostic{"parsing file '" + path + "'", source_location(), source_location(), severity::info});
severity::info});
auto file = parser_.parse(*idx_, std::move(path), c); auto file = parser_.parse(*idx_, std::move(path), c);
auto ptr = file.get(); auto ptr = file.get();
if (file) if (file)
@ -156,25 +154,20 @@ namespace cppast
namespace detail namespace detail
{ {
struct std_begin struct std_begin
{ {};
};
struct adl_begin : std_begin struct adl_begin : std_begin
{ {};
};
struct member_begin : adl_begin struct member_begin : adl_begin
{ {};
};
template <class Range> template <class Range>
auto get_value_type_impl(member_begin, Range&& r) auto get_value_type_impl(member_begin, Range&& r) -> decltype(std::forward<Range>(r).begin());
-> decltype(std::forward<Range>(r).begin());
template <class Range> template <class Range>
auto get_value_type_impl(adl_begin, Range&& r) -> decltype(begin(std::forward<Range>(r))); auto get_value_type_impl(adl_begin, Range&& r) -> decltype(begin(std::forward<Range>(r)));
template <class Range> template <class Range>
auto get_value_type_impl(std_begin, Range&& r) auto get_value_type_impl(std_begin, Range&& r) -> decltype(std::begin(std::forward<Range>(r)));
-> decltype(std::begin(std::forward<Range>(r)));
template <class Range> template <class Range>
using value_type = decltype(*get_value_type_impl(member_begin{}, std::declval<Range>())); using value_type = decltype(*get_value_type_impl(member_begin{}, std::declval<Range>()));
@ -189,28 +182,26 @@ namespace cppast
/// * `parser` - A typedef for the parser being used to do the parsing. /// * `parser` - A typedef for the parser being used to do the parsing.
/// * `config` - The same as `parser::config`. /// * `config` - The same as `parser::config`.
/// * `parse(path, config)` - Parses the given file with the configuration using its parser. /// * `parse(path, config)` - Parses the given file with the configuration using its parser.
/// The parsing can be executed in a separated thread, but then a copy of the configuration and path must be created. /// The parsing can be executed in a separated thread, but then a copy of the configuration and path
/// \requires `Range` must be some type that can be iterated in a range-based for loop. /// must be created. \requires `Range` must be some type that can be iterated in a range-based for
/// \requires `Configuration` must be a function that returns a configuration of type `FileParser::config` when given a path. /// loop. \requires `Configuration` must be a function that returns a configuration of type
/// \unique_name parse_files_basic /// `FileParser::config` when given a path. \unique_name parse_files_basic \synopsis_return void
/// \synopsis_return void
template <class FileParser, class Range, class Configuration> template <class FileParser, class Range, class Configuration>
auto parse_files(FileParser& parser, Range&& file_names, const Configuration& get_config) -> auto parse_files(FileParser& parser, Range&& file_names, const Configuration& get_config) ->
typename std::enable_if<std::is_same<typename std::decay<decltype(get_config( typename std::enable_if<std::is_same<
std::declval<detail::value_type<Range>>()))>::type, typename std::decay<decltype(get_config(std::declval<detail::value_type<Range>>()))>::type,
typename FileParser::config>::value>::type typename FileParser::config>::value>::type
{ {
for (auto&& file : std::forward<Range>(file_names)) for (auto&& file : std::forward<Range>(file_names))
{ {
auto&& config = get_config(file); auto&& config = get_config(file);
parser.parse(std::forward<decltype(file)>(file), parser.parse(std::forward<decltype(file)>(file), std::forward<decltype(config)>(config));
std::forward<decltype(config)>(config));
} }
} }
/// Parses multiple files using a given `FileParser` and configuration. /// Parses multiple files using a given `FileParser` and configuration.
/// \effects Invokes [cppast::parse_files](standardese://parse_files_basic/) passing it the parser and file names, /// \effects Invokes [cppast::parse_files](standardese://parse_files_basic/) passing it the parser
/// and a function that returns the same configuration for each file. /// and file names, and a function that returns the same configuration for each file.
template <class FileParser, class Range> template <class FileParser, class Range>
void parse_files(FileParser& parser, Range&& file_names, typename FileParser::config config) void parse_files(FileParser& parser, Range&& file_names, typename FileParser::config config)
{ {

View file

@ -62,7 +62,8 @@ namespace cppast
continue_visit_no_children = false, continue_visit_no_children = false,
/// Visit should be aborted. /// Visit should be aborted.
/// \notes This only happens when the event is not [cppast::visitor_info::container_entity_enter](). /// \notes This only happens when the event is not
/// [cppast::visitor_info::container_entity_enter]().
abort_visit = false, abort_visit = false,
}; };
@ -72,16 +73,14 @@ namespace cppast
using visitor_callback_t = bool (*)(void* mem, const cpp_entity&, visitor_info info); using visitor_callback_t = bool (*)(void* mem, const cpp_entity&, visitor_info info);
struct visitor_info_void struct visitor_info_void
{ {};
};
struct visitor_info_bool : visitor_info_void struct visitor_info_bool : visitor_info_void
{ {};
};
template <typename Func> template <typename Func>
visitor_callback_t get_visitor_callback( visitor_callback_t get_visitor_callback(
visitor_info_bool, decltype(std::declval<Func>()(std::declval<const cpp_entity&>(), visitor_info_bool,
visitor_info{})) = true) decltype(std::declval<Func>()(std::declval<const cpp_entity&>(), visitor_info{})) = true)
{ {
return [](void* mem, const cpp_entity& e, visitor_info info) { return [](void* mem, const cpp_entity& e, visitor_info info) {
auto& func = *static_cast<Func*>(mem); auto& func = *static_cast<Func*>(mem);
@ -92,8 +91,7 @@ namespace cppast
template <typename Func> template <typename Func>
visitor_callback_t get_visitor_callback( visitor_callback_t get_visitor_callback(
visitor_info_void, visitor_info_void,
decltype(std::declval<Func>()(std::declval<const cpp_entity&>(), visitor_info{}), decltype(std::declval<Func>()(std::declval<const cpp_entity&>(), visitor_info{}), 0) = 0)
0) = 0)
{ {
return [](void* mem, const cpp_entity& e, visitor_info info) { return [](void* mem, const cpp_entity& e, visitor_info info) {
auto& func = *static_cast<Func*>(mem); auto& func = *static_cast<Func*>(mem);
@ -116,7 +114,8 @@ namespace cppast
/// ///
/// \effects It will invoke the callback - the visitor - for the current entity and children, /// \effects It will invoke the callback - the visitor - for the current entity and children,
/// as controlled by the [cppast::visitor_result](). /// as controlled by the [cppast::visitor_result]().
/// The visitor is given a reference to the currently visited entity and the [cppast::visitor_info](). /// The visitor is given a reference to the currently visited entity and the
/// [cppast::visitor_info]().
/// ///
/// \requires The visitor must be callable as specified and must either return `bool` or nothing. /// \requires The visitor must be callable as specified and must either return `bool` or nothing.
/// If it returns nothing, a return value [cppast::visitor_result::continue_visit]() is assumed. /// If it returns nothing, a return value [cppast::visitor_result::continue_visit]() is assumed.
@ -131,8 +130,8 @@ namespace cppast
{ {
include = true, //< The entity is included. include = true, //< The entity is included.
exclude = false, //< The entity is excluded and will not be visited. exclude = false, //< The entity is excluded and will not be visited.
exclude_and_children = exclude_and_children
2, //< The entity and all direct children are excluded and will not be visited. = 2, //< The entity and all direct children are excluded and will not be visited.
}; };
namespace detail namespace detail
@ -140,8 +139,7 @@ namespace cppast
using visitor_filter_t = visit_filter (*)(const cpp_entity&); using visitor_filter_t = visit_filter (*)(const cpp_entity&);
template <typename Filter> template <typename Filter>
auto invoke_visit_filter(int, Filter f, const cpp_entity& e, auto invoke_visit_filter(int, Filter f, const cpp_entity& e, cpp_access_specifier_kind access)
cpp_access_specifier_kind access)
-> decltype(static_cast<visit_filter>(f(e, access))) -> decltype(static_cast<visit_filter>(f(e, access)))
{ {
return static_cast<visit_filter>(f(e, access)); return static_cast<visit_filter>(f(e, access));
@ -157,13 +155,15 @@ namespace cppast
/// Visits a [cppast::cpp_entity]() and children that pass a given filter. /// Visits a [cppast::cpp_entity]() and children that pass a given filter.
/// ///
/// \effects It behaves like the non-filtered visit except it will only invoke the visitor for entities that match the filter. /// \effects It behaves like the non-filtered visit except it will only invoke the visitor for
/// The filter is a predicate that will be invoked with the current entity and access specifier first and the result converted to [cppast::visit_filter](). /// entities that match the filter. The filter is a predicate that will be invoked with the current
/// Visit will behave accordingly. /// entity and access specifier first and the result converted to [cppast::visit_filter](). Visit
/// will behave accordingly.
/// ///
/// \requires The visitor must be as specified for the other overload. /// \requires The visitor must be as specified for the other overload.
/// The filter must be a function taking a [cppast::cpp_entity]() as first parameter and optionally a [cppast::cpp_access_specifier_kind]() as second. /// The filter must be a function taking a [cppast::cpp_entity]() as first parameter and optionally
/// It must return a `bool` or a [cppast::visit_filter](). /// a [cppast::cpp_access_specifier_kind]() as second. It must return a `bool` or a
/// [cppast::visit_filter]().
template <typename Func, typename Filter> template <typename Func, typename Filter>
void visit(const cpp_entity& e, Filter filter, Func f) void visit(const cpp_entity& e, Filter filter, Func f)
{ {
@ -210,20 +210,20 @@ namespace cppast
detail::visitor_filter_t blacklist() detail::visitor_filter_t blacklist()
{ {
return [](const cpp_entity& e) { return [](const cpp_entity& e) {
return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::exclude : return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::exclude : visit_filter::include;
visit_filter::include;
}; };
} }
/// Generates a blacklist visitor filter. /// Generates a blacklist visitor filter.
/// ///
/// \returns A visitor filter that excludes all entities having one of the specified kinds and children of those entities. /// \returns A visitor filter that excludes all entities having one of the specified kinds and
/// children of those entities.
template <cpp_entity_kind... Kinds> template <cpp_entity_kind... Kinds>
detail::visitor_filter_t blacklist_and_children() detail::visitor_filter_t blacklist_and_children()
{ {
return [](const cpp_entity& e) { return [](const cpp_entity& e) {
return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::exclude_and_children : return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::exclude_and_children
visit_filter::include; : visit_filter::include;
}; };
} }
@ -234,8 +234,7 @@ namespace cppast
detail::visitor_filter_t whitelist() detail::visitor_filter_t whitelist()
{ {
return [](const cpp_entity& e) { return [](const cpp_entity& e) {
return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::include : return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::include : visit_filter::exclude;
visit_filter::exclude;
}; };
} }
} // namespace cppast } // namespace cppast

View file

@ -133,8 +133,7 @@ namespace
bool generate_include_directive(code_generator& generator, const cpp_include_directive& include, bool generate_include_directive(code_generator& generator, const cpp_include_directive& include,
cpp_access_specifier_kind cur_access) cpp_access_specifier_kind cur_access)
{ {
code_generator::output output(type_safe::ref(generator), type_safe::ref(include), code_generator::output output(type_safe::ref(generator), type_safe::ref(include), cur_access);
cur_access);
if (output) if (output)
{ {
output << preprocessor_token("#include") << whitespace; output << preprocessor_token("#include") << whitespace;
@ -155,8 +154,7 @@ namespace
bool generate_language_linkage(code_generator& generator, const cpp_language_linkage& linkage, bool generate_language_linkage(code_generator& generator, const cpp_language_linkage& linkage,
cpp_access_specifier_kind cur_access) cpp_access_specifier_kind cur_access)
{ {
code_generator::output output(type_safe::ref(generator), type_safe::ref(linkage), code_generator::output output(type_safe::ref(generator), type_safe::ref(linkage), cur_access);
cur_access);
if (output) if (output)
{ {
output << keyword("extern") << whitespace << string_literal(linkage.name()); output << keyword("extern") << whitespace << string_literal(linkage.name());
@ -220,16 +218,14 @@ namespace
bool generate_using_directive(code_generator& generator, const cpp_using_directive& directive, bool generate_using_directive(code_generator& generator, const cpp_using_directive& directive,
cpp_access_specifier_kind cur_access) cpp_access_specifier_kind cur_access)
{ {
code_generator::output output(type_safe::ref(generator), type_safe::ref(directive), code_generator::output output(type_safe::ref(generator), type_safe::ref(directive), cur_access);
cur_access);
if (output) if (output)
output << keyword("using") << whitespace << keyword("namespace") << whitespace output << keyword("using") << whitespace << keyword("namespace") << whitespace
<< directive.target() << punctuation(";") << newl; << directive.target() << punctuation(";") << newl;
return static_cast<bool>(output); return static_cast<bool>(output);
} }
bool generate_using_declaration(code_generator& generator, bool generate_using_declaration(code_generator& generator, const cpp_using_declaration& declaration,
const cpp_using_declaration& declaration,
cpp_access_specifier_kind cur_access) cpp_access_specifier_kind cur_access)
{ {
code_generator::output output(type_safe::ref(generator), type_safe::ref(declaration), code_generator::output output(type_safe::ref(generator), type_safe::ref(declaration),
@ -267,8 +263,7 @@ namespace
if (value.value()) if (value.value())
{ {
output << operator_ws << punctuation("=") << operator_ws; output << operator_ws << punctuation("=") << operator_ws;
detail:: detail::write_expression(output,
write_expression(output,
value.value() value.value()
.value()); // should have named something differently... .value()); // should have named something differently...
} }
@ -423,8 +418,7 @@ namespace
output.indent(); output.indent();
auto need_sep = false; auto need_sep = false;
auto last_access = auto last_access = c.class_kind() == cpp_class_kind::class_t ? cpp_private : cpp_public;
c.class_kind() == cpp_class_kind::class_t ? cpp_private : cpp_public;
auto last_written_access = last_access; auto last_written_access = last_access;
for (auto& member : c) for (auto& member : c)
{ {
@ -599,8 +593,8 @@ namespace
} }
} }
bool generate_function( bool generate_function(code_generator& generator, const cpp_function& func,
code_generator& generator, const cpp_function& func, cpp_access_specifier_kind cur_access, cpp_access_specifier_kind cur_access,
type_safe::optional_ref<const cpp_template_specialization> spec = nullptr) type_safe::optional_ref<const cpp_template_specialization> spec = nullptr)
{ {
code_generator::output output(type_safe::ref(generator), type_safe::ref(func), cur_access); code_generator::output output(type_safe::ref(generator), type_safe::ref(func), cur_access);
@ -699,10 +693,10 @@ namespace
return need_ws; return need_ws;
} }
bool generate_member_function( bool generate_member_function(code_generator& generator, const cpp_member_function& func,
code_generator& generator, const cpp_member_function& func,
cpp_access_specifier_kind cur_access, cpp_access_specifier_kind cur_access,
type_safe::optional_ref<const cpp_template_specialization> spec = nullptr) type_safe::optional_ref<const cpp_template_specialization> spec
= nullptr)
{ {
code_generator::output output(type_safe::ref(generator), type_safe::ref(func), cur_access); code_generator::output output(type_safe::ref(generator), type_safe::ref(func), cur_access);
if (output) if (output)
@ -816,8 +810,8 @@ namespace
if (is_friended(dtor)) if (is_friended(dtor))
output << keyword("friend") << whitespace; output << keyword("friend") << whitespace;
write_prefix_virtual(output, dtor.virtual_info()); write_prefix_virtual(output, dtor.virtual_info());
output << identifier(dtor.semantic_scope()) << identifier(dtor.name()) output << identifier(dtor.semantic_scope()) << identifier(dtor.name()) << punctuation("(")
<< punctuation("(") << punctuation(")"); << punctuation(")");
write_noexcept(output, dtor, output.formatting().is_set(formatting_flags::operator_ws)); write_noexcept(output, dtor, output.formatting().is_set(formatting_flags::operator_ws));
write_suffix_virtual(output, dtor.virtual_info(), dtor.is_definition()); write_suffix_virtual(output, dtor.virtual_info(), dtor.is_definition());
@ -836,8 +830,7 @@ namespace
return generate_function(generator, static_cast<const cpp_function&>(base), cur_access, return generate_function(generator, static_cast<const cpp_function&>(base), cur_access,
type_safe::ref(spec)); type_safe::ref(spec));
case cpp_entity_kind::member_function_t: case cpp_entity_kind::member_function_t:
return generate_member_function(generator, return generate_member_function(generator, static_cast<const cpp_member_function&>(base),
static_cast<const cpp_member_function&>(base),
cur_access, type_safe::ref(spec)); cur_access, type_safe::ref(spec));
case cpp_entity_kind::conversion_op_t: case cpp_entity_kind::conversion_op_t:
return generate_conversion_op(generator, static_cast<const cpp_conversion_op&>(base), return generate_conversion_op(generator, static_cast<const cpp_conversion_op&>(base),
@ -1040,8 +1033,7 @@ namespace
bool generate_static_assert(code_generator& generator, const cpp_static_assert& assert, bool generate_static_assert(code_generator& generator, const cpp_static_assert& assert,
cpp_access_specifier_kind cur_access) cpp_access_specifier_kind cur_access)
{ {
code_generator::output output(type_safe::ref(generator), type_safe::ref(assert), code_generator::output output(type_safe::ref(generator), type_safe::ref(assert), cur_access);
cur_access);
if (output) if (output)
{ {
output << keyword("static_assert") << punctuation("(") << bracket_ws; output << keyword("static_assert") << punctuation("(") << bracket_ws;
@ -1055,8 +1047,7 @@ namespace
bool generate_unexposed(code_generator& generator, const cpp_unexposed_entity& entity, bool generate_unexposed(code_generator& generator, const cpp_unexposed_entity& entity,
cpp_access_specifier_kind cur_access) cpp_access_specifier_kind cur_access)
{ {
code_generator::output output(type_safe::ref(generator), type_safe::ref(entity), code_generator::output output(type_safe::ref(generator), type_safe::ref(entity), cur_access);
cur_access);
if (output) if (output)
{ {
detail::write_token_string(output, entity.spelling()); detail::write_token_string(output, entity.spelling());

View file

@ -37,7 +37,7 @@ namespace
return "<error>"; return "<error>";
} }
} } // namespace
cpp_attribute::cpp_attribute(cpp_attribute_kind kind, cpp_attribute::cpp_attribute(cpp_attribute_kind kind,
type_safe::optional<cpp_token_string> arguments) type_safe::optional<cpp_token_string> arguments)
@ -49,8 +49,8 @@ cpp_attribute::cpp_attribute(cpp_attribute_kind kind,
type_safe::optional_ref<const cpp_attribute> cppast::has_attribute( type_safe::optional_ref<const cpp_attribute> cppast::has_attribute(
const cpp_attribute_list& attributes, const std::string& name) const cpp_attribute_list& attributes, const std::string& name)
{ {
auto iter = auto iter
std::find_if(attributes.begin(), attributes.end(), [&](const cpp_attribute& attribute) { = std::find_if(attributes.begin(), attributes.end(), [&](const cpp_attribute& attribute) {
if (attribute.scope()) if (attribute.scope())
return attribute.scope().value() + "::" + attribute.name() == name; return attribute.scope().value() + "::" + attribute.name() == name;
else else
@ -66,8 +66,8 @@ type_safe::optional_ref<const cpp_attribute> cppast::has_attribute(
type_safe::optional_ref<const cpp_attribute> cppast::has_attribute( type_safe::optional_ref<const cpp_attribute> cppast::has_attribute(
const cpp_attribute_list& attributes, cpp_attribute_kind kind) const cpp_attribute_list& attributes, cpp_attribute_kind kind)
{ {
auto iter = auto iter
std::find_if(attributes.begin(), attributes.end(), = std::find_if(attributes.begin(), attributes.end(),
[&](const cpp_attribute& attribute) { return attribute.kind() == kind; }); [&](const cpp_attribute& attribute) { return attribute.kind() == kind; });
if (iter == attributes.end()) if (iter == attributes.end())

View file

@ -4,10 +4,10 @@
#include <cppast/cpp_class.hpp> #include <cppast/cpp_class.hpp>
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_alias_template.hpp> #include <cppast/cpp_alias_template.hpp>
#include <cppast/cpp_class_template.hpp> #include <cppast/cpp_class_template.hpp>
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_kind.hpp>
using namespace cppast; using namespace cppast;
@ -112,8 +112,7 @@ namespace
} }
else if (type.kind() == cpp_type_kind::template_instantiation_t) else if (type.kind() == cpp_type_kind::template_instantiation_t)
{ {
auto& ref = auto& ref = static_cast<const cpp_template_instantiation_type&>(type).primary_template();
static_cast<const cpp_template_instantiation_type&>(type).primary_template();
return cpp_entity_ref(ref.id()[0u], ref.name()); return cpp_entity_ref(ref.id()[0u], ref.name());
} }
@ -166,7 +165,7 @@ namespace
return type_safe::ref(static_cast<const cpp_class&>(entity.value())); return type_safe::ref(static_cast<const cpp_class&>(entity.value()));
} }
} }
} } // namespace
type_safe::optional_ref<const cpp_class> cppast::get_class(const cpp_entity_index& index, type_safe::optional_ref<const cpp_class> cppast::get_class(const cpp_entity_index& index,
const cpp_base_class& base) const cpp_base_class& base)

View file

@ -4,17 +4,16 @@
#include <cppast/cpp_entity_index.hpp> #include <cppast/cpp_entity_index.hpp>
#include <cppast/detail/assert.hpp>
#include <cppast/cpp_entity.hpp> #include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_kind.hpp> #include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_file.hpp> #include <cppast/cpp_file.hpp>
#include <cppast/detail/assert.hpp>
using namespace cppast; using namespace cppast;
cpp_entity_index::duplicate_definition_error::duplicate_definition_error() cpp_entity_index::duplicate_definition_error::duplicate_definition_error()
: std::logic_error("duplicate registration of entity definition") : std::logic_error("duplicate registration of entity definition")
{ {}
}
void cpp_entity_index::register_definition(cpp_entity_id id, void cpp_entity_index::register_definition(cpp_entity_id id,
type_safe::object_ref<const cpp_entity> entity) const type_safe::object_ref<const cpp_entity> entity) const

View file

@ -17,8 +17,8 @@ std::unique_ptr<cpp_enum_value> cpp_enum_value::build(const cpp_entity_index& id
std::string name, std::string name,
std::unique_ptr<cpp_expression> value) std::unique_ptr<cpp_expression> value)
{ {
auto result = auto result
std::unique_ptr<cpp_enum_value>(new cpp_enum_value(std::move(name), std::move(value))); = std::unique_ptr<cpp_enum_value>(new cpp_enum_value(std::move(name), std::move(value)));
idx.register_definition(std::move(id), type_safe::ref(*result)); idx.register_definition(std::move(id), type_safe::ref(*result));
return result; return result;
} }

View file

@ -77,7 +77,7 @@ namespace
{ {
detail::write_token_string(output, expr.expression()); detail::write_token_string(output, expr.expression());
} }
} } // namespace
void detail::write_expression(code_generator::output& output, const cpp_expression& expr) void detail::write_expression(code_generator::output& output, const cpp_expression& expr)
{ {

View file

@ -10,8 +10,8 @@
#include <cppast/cpp_entity.hpp> #include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_kind.hpp> #include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_function_type.hpp> #include <cppast/cpp_function_type.hpp>
#include <cppast/cpp_type_alias.hpp>
#include <cppast/cpp_template.hpp> #include <cppast/cpp_template.hpp>
#include <cppast/cpp_type_alias.hpp>
using namespace cppast; using namespace cppast;
@ -269,12 +269,11 @@ namespace
void write_decltype_auto(code_generator::output& output, const cpp_decltype_auto_type&) void write_decltype_auto(code_generator::output& output, const cpp_decltype_auto_type&)
{ {
output << keyword("decltype") << punctuation("(") << bracket_ws << keyword("auto") output << keyword("decltype") << punctuation("(") << bracket_ws << keyword("auto") << bracket_ws
<< bracket_ws << punctuation(")"); << punctuation(")");
} }
void write_cv_qualified_prefix(code_generator::output& output, void write_cv_qualified_prefix(code_generator::output& output, const cpp_cv_qualified_type& type)
const cpp_cv_qualified_type& type)
{ {
detail::write_type_prefix(output, type.type()); detail::write_type_prefix(output, type.type());
@ -287,8 +286,7 @@ namespace
output << whitespace << keyword("volatile"); output << whitespace << keyword("volatile");
} }
void write_cv_qualified_suffix(code_generator::output& output, void write_cv_qualified_suffix(code_generator::output& output, const cpp_cv_qualified_type& type)
const cpp_cv_qualified_type& type)
{ {
if (is_direct_complex(type.type())) if (is_direct_complex(type.type()))
output << bracket_ws << punctuation(")"); output << bracket_ws << punctuation(")");
@ -457,8 +455,7 @@ namespace
detail::write_type_suffix(output, type.return_type()); detail::write_type_suffix(output, type.return_type());
} }
void write_member_object_prefix(code_generator::output& output, void write_member_object_prefix(code_generator::output& output, const cpp_member_object_type& type)
const cpp_member_object_type& type)
{ {
detail::write_type_prefix(output, type.object_type()); detail::write_type_prefix(output, type.object_type());
output << punctuation("(") << bracket_ws; output << punctuation("(") << bracket_ws;

View file

@ -2,8 +2,8 @@
// This file is subject to the license terms in the LICENSE file // This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution. // found in the top-level directory of this distribution.
#include <cppast/cpp_class.hpp>
#include <clang-c/Index.h> #include <clang-c/Index.h>
#include <cppast/cpp_class.hpp>
#include "libclang_visitor.hpp" #include "libclang_visitor.hpp"
#include "parse_functions.hpp" #include "parse_functions.hpp"
@ -108,7 +108,7 @@ namespace
auto& base = builder.base_class(std::move(name), std::move(type), access, is_virtual); auto& base = builder.base_class(std::move(name), std::move(type), access, is_virtual);
base.add_attribute(attributes); base.add_attribute(attributes);
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::parse_cpp_class(const detail::parse_context& context, std::unique_ptr<cpp_entity> detail::parse_cpp_class(const detail::parse_context& context,
const CXCursor& cur, const CXCursor& parent_cur) const CXCursor& cur, const CXCursor& parent_cur)
@ -145,8 +145,8 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_class(const detail::parse_context&
stream.bump(); stream.bump();
} }
if (!scope.empty()) if (!scope.empty())
semantic_parent = semantic_parent
cpp_entity_ref(detail::get_entity_id(clang_getCursorSemanticParent(cur)), = cpp_entity_ref(detail::get_entity_id(clang_getCursorSemanticParent(cur)),
std::move(scope)); std::move(scope));
} }
@ -159,12 +159,12 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_class(const detail::parse_context&
add_base_class(builder, context, child, cur); add_base_class(builder, context, child, cur);
else if (kind == CXCursor_CXXFinalAttr) else if (kind == CXCursor_CXXFinalAttr)
builder.is_final(); builder.is_final();
else if ( else if (kind == CXCursor_TemplateTypeParameter
kind == CXCursor_TemplateTypeParameter || kind == CXCursor_NonTypeTemplateParameter || kind == CXCursor_NonTypeTemplateParameter
|| kind == CXCursor_TemplateTemplateParameter || kind == CXCursor_ParmDecl || kind == CXCursor_TemplateTemplateParameter || kind == CXCursor_ParmDecl
|| clang_isExpression(kind) || clang_isReference(kind) || clang_isExpression(kind) || clang_isReference(kind)
|| kind || kind == CXCursor_UnexposedAttr) // I have no idea what this is, but happens
== CXCursor_UnexposedAttr) // I have no idea what this is, but happens on Windows // on Windows
// other children due to templates and stuff // other children due to templates and stuff
return; return;
else if (auto entity = parse_entity(context, &builder.get(), child)) else if (auto entity = parse_entity(context, &builder.get(), child))
@ -173,10 +173,10 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_class(const detail::parse_context&
} }
if (!is_friend && clang_isCursorDefinition(cur)) if (!is_friend && clang_isCursorDefinition(cur))
return is_templated ? return is_templated
builder.finish(std::move(semantic_parent)) : ? builder.finish(std::move(semantic_parent))
builder.finish(*context.idx, get_entity_id(cur), std::move(semantic_parent)); : builder.finish(*context.idx, get_entity_id(cur), std::move(semantic_parent));
else else
return is_templated ? builder.finish_declaration(detail::get_entity_id(cur)) : return is_templated ? builder.finish_declaration(detail::get_entity_id(cur))
builder.finish_declaration(*context.idx, get_entity_id(cur)); : builder.finish_declaration(*context.idx, get_entity_id(cur));
} }

View file

@ -13,8 +13,7 @@ using namespace cppast;
detail::cxtoken::cxtoken(const CXTranslationUnit& tu_unit, const CXToken& token) detail::cxtoken::cxtoken(const CXTranslationUnit& tu_unit, const CXToken& token)
: value_(clang_getTokenSpelling(tu_unit, token)), kind_(clang_getTokenKind(token)) : value_(clang_getTokenSpelling(tu_unit, token)), kind_(clang_getTokenKind(token))
{ {}
}
namespace namespace
{ {
@ -69,15 +68,15 @@ namespace
unsigned no_; unsigned no_;
}; };
bool token_after_is(const CXTranslationUnit& tu, const CXFile& file, bool token_after_is(const CXTranslationUnit& tu, const CXFile& file, const CXSourceLocation& loc,
const CXSourceLocation& loc, const char* token_str, int inc) const char* token_str, int inc)
{ {
auto loc_after = get_next_location(tu, file, loc, inc); auto loc_after = get_next_location(tu, file, loc, inc);
if (!clang_Location_isFromMainFile(loc_after)) if (!clang_Location_isFromMainFile(loc_after))
return false; return false;
simple_tokenizer tokenizer(tu, inc > 0 ? clang_getRange(loc, loc_after) : simple_tokenizer tokenizer(tu, inc > 0 ? clang_getRange(loc, loc_after)
clang_getRange(loc_after, loc)); : clang_getRange(loc_after, loc));
if (tokenizer.size() == 0u) if (tokenizer.size() == 0u)
return false; return false;
@ -103,8 +102,7 @@ namespace
|| kind == CXCursor_VarDecl || kind == CXCursor_FieldDecl || kind == CXCursor_ParmDecl || kind == CXCursor_VarDecl || kind == CXCursor_FieldDecl || kind == CXCursor_ParmDecl
|| kind == CXCursor_NonTypeTemplateParameter) || kind == CXCursor_NonTypeTemplateParameter)
{ {
if (token_after_is(tu, file, begin, "]", -2) if (token_after_is(tu, file, begin, "]", -2) && token_after_is(tu, file, begin, "]", -3))
&& token_after_is(tu, file, begin, "]", -3))
{ {
while (!token_after_is(tu, file, begin, "[", -1) while (!token_after_is(tu, file, begin, "[", -1)
&& !token_after_is(tu, file, begin, "[", -2)) && !token_after_is(tu, file, begin, "[", -2))
@ -112,8 +110,8 @@ namespace
begin = get_next_location(tu, file, begin, -3); begin = get_next_location(tu, file, begin, -3);
DEBUG_ASSERT(token_after_is(tu, file, begin, "[", 0) DEBUG_ASSERT(token_after_is(tu, file, begin, "[", 0)
&& token_after_is(tu, file, get_next_location(tu, file, begin), && token_after_is(tu, file, get_next_location(tu, file, begin), "[",
"[", 0), 0),
detail::parse_error_handler{}, cur, detail::parse_error_handler{}, cur,
"error in pre-function attribute parsing"); "error in pre-function attribute parsing");
} }
@ -207,8 +205,7 @@ namespace
end = next; end = next;
#endif #endif
} }
else if (kind == CXCursor_TemplateTemplateParameter else if (kind == CXCursor_TemplateTemplateParameter && token_after_is(tu, file, end, "<", 0))
&& token_after_is(tu, file, end, "<", 0))
{ {
// if you have a template template parameter in a template template parameter, // if you have a template template parameter in a template template parameter,
// the tokens are all messed up, only contain the `template` // the tokens are all messed up, only contain the `template`
@ -228,14 +225,12 @@ namespace
// second: skip until end of parameter // second: skip until end of parameter
// no need to handle default, so look for '>' or ',' // no need to handle default, so look for '>' or ','
while (!token_after_is(tu, file, next, ">", 0) while (!token_after_is(tu, file, next, ">", 0) && !token_after_is(tu, file, next, ",", 0))
&& !token_after_is(tu, file, next, ",", 0))
next = get_next_location(tu, file, next); next = get_next_location(tu, file, next);
// now we found the proper end of the token // now we found the proper end of the token
end = get_next_location(tu, file, next, -1); end = get_next_location(tu, file, next, -1);
} }
else if ((kind == CXCursor_TemplateTypeParameter else if ((kind == CXCursor_TemplateTypeParameter || kind == CXCursor_NonTypeTemplateParameter
|| kind == CXCursor_NonTypeTemplateParameter
|| kind == CXCursor_TemplateTemplateParameter) || kind == CXCursor_TemplateTemplateParameter)
&& token_after_is(tu, file, end, "...", 0)) && token_after_is(tu, file, end, "...", 0))
{ {
@ -246,16 +241,13 @@ namespace
// this should all go away once I redid the whole token thing... // this should all go away once I redid the whole token thing...
end = get_next_location(tu, file, end, 1); end = get_next_location(tu, file, end, 1);
DEBUG_ASSERT(token_after_is(tu, file, end, ">", 0) DEBUG_ASSERT(token_after_is(tu, file, end, ">", 0) || token_after_is(tu, file, end, ",", 0),
|| token_after_is(tu, file, end, ",", 0),
detail::parse_error_handler{}, cur, detail::parse_error_handler{}, cur,
"unexpected token in variadic parameter workaround"); "unexpected token in variadic parameter workaround");
} }
else if ((kind == CXCursor_TemplateTypeParameter else if ((kind == CXCursor_TemplateTypeParameter || kind == CXCursor_NonTypeTemplateParameter
|| kind == CXCursor_NonTypeTemplateParameter
|| kind == CXCursor_TemplateTemplateParameter) || kind == CXCursor_TemplateTemplateParameter)
&& !token_after_is(tu, file, end, ">", 0) && !token_after_is(tu, file, end, ">", 0) && !token_after_is(tu, file, end, ",", 0))
&& !token_after_is(tu, file, end, ",", 0))
{ {
DEBUG_ASSERT(token_after_is(tu, file, get_next_location(tu, file, end, -2), ">>", 0), DEBUG_ASSERT(token_after_is(tu, file, get_next_location(tu, file, end, -2), ">>", 0),
detail::parse_error_handler{}, cur, detail::parse_error_handler{}, cur,
@ -513,8 +505,7 @@ namespace
if (!scope && kind != cpp_attribute_kind::unknown) if (!scope && kind != cpp_attribute_kind::unknown)
return cpp_attribute(kind, std::move(arguments)); return cpp_attribute(kind, std::move(arguments));
else else
return cpp_attribute(std::move(scope), std::move(name), std::move(arguments), return cpp_attribute(std::move(scope), std::move(name), std::move(arguments), is_variadic);
is_variadic);
} }
bool parse_attribute_impl(cpp_attribute_list& result, detail::cxtoken_stream& stream) bool parse_attribute_impl(cpp_attribute_list& result, detail::cxtoken_stream& stream)

View file

@ -67,8 +67,7 @@ namespace cppast
class cxtokenizer class cxtokenizer
{ {
public: public:
explicit cxtokenizer(const CXTranslationUnit& tu, const CXFile& file, explicit cxtokenizer(const CXTranslationUnit& tu, const CXFile& file, const CXCursor& cur);
const CXCursor& cur);
cxtoken_iterator begin() const noexcept cxtoken_iterator begin() const noexcept
{ {
@ -97,13 +96,9 @@ namespace cppast
{ {
public: public:
explicit cxtoken_stream(const cxtokenizer& tokenizer, const CXCursor& cur) explicit cxtoken_stream(const cxtokenizer& tokenizer, const CXCursor& cur)
: cursor_(cur), : cursor_(cur), begin_(tokenizer.begin()), cur_(begin_), end_(tokenizer.end()),
begin_(tokenizer.begin()),
cur_(begin_),
end_(tokenizer.end()),
unmunch_(tokenizer.unmunch()) unmunch_(tokenizer.unmunch())
{ {}
}
const cxtoken& peek() const noexcept const cxtoken& peek() const noexcept
{ {
@ -202,7 +197,7 @@ namespace cppast
// note: does not consume the token if it is not valid, // note: does not consume the token if it is not valid,
// returns false in that case // returns false in that case
bool append_scope(cxtoken_stream& stream, std::string& scope); bool append_scope(cxtoken_stream& stream, std::string& scope);
} } // namespace detail
} // namespace cppast::detail } // namespace cppast
#endif // CPPAST_CXTOKENIZER_HPP_INCLUDED #endif // CPPAST_CXTOKENIZER_HPP_INCLUDED

View file

@ -25,7 +25,7 @@ namespace cppast
void print_tokens(const CXTranslationUnit& tu, const CXFile& file, void print_tokens(const CXTranslationUnit& tu, const CXFile& file,
const CXCursor& cur) noexcept; const CXCursor& cur) noexcept;
} } // namespace detail
} // namespace cppast::detail } // namespace cppast
#endif // CPPAST_DEBUG_HELPER_HPP_INCLUDED #endif // CPPAST_DEBUG_HELPER_HPP_INCLUDED

View file

@ -4,8 +4,8 @@
#include <cppast/cpp_enum.hpp> #include <cppast/cpp_enum.hpp>
#include "parse_functions.hpp"
#include "libclang_visitor.hpp" #include "libclang_visitor.hpp"
#include "parse_functions.hpp"
using namespace cppast; using namespace cppast;
@ -32,9 +32,8 @@ namespace
if (detail::skip_if(stream, "=")) if (detail::skip_if(stream, "="))
{ {
detail::visit_children(cur, [&](const CXCursor& child) { detail::visit_children(cur, [&](const CXCursor& child) {
DEBUG_ASSERT(clang_isExpression(child.kind) && !value, DEBUG_ASSERT(clang_isExpression(child.kind) && !value, detail::parse_error_handler{},
detail::parse_error_handler{}, cur, cur, "unexpected child cursor of enum value");
"unexpected child cursor of enum value");
value = detail::parse_expression(context, child); value = detail::parse_expression(context, child);
}); });
@ -61,11 +60,9 @@ namespace
std::string scope; std::string scope;
while (!detail::skip_if(stream, name.c_str())) while (!detail::skip_if(stream, name.c_str()))
if (!detail::append_scope(stream, scope)) if (!detail::append_scope(stream, scope))
DEBUG_UNREACHABLE(detail::parse_error_handler{}, cur, DEBUG_UNREACHABLE(detail::parse_error_handler{}, cur, "unexpected tokens in enum name");
"unexpected tokens in enum name");
if (!scope.empty()) if (!scope.empty())
semantic_parent = semantic_parent = cpp_entity_ref(detail::get_entity_id(clang_getCursorSemanticParent(cur)),
cpp_entity_ref(detail::get_entity_id(clang_getCursorSemanticParent(cur)),
std::move(scope)); std::move(scope));
// parse type // parse type
@ -76,7 +73,7 @@ namespace
result.get().add_attribute(attributes); result.get().add_attribute(attributes);
return result; return result;
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::parse_cpp_enum(const detail::parse_context& context, std::unique_ptr<cpp_entity> detail::parse_cpp_enum(const detail::parse_context& context,
const CXCursor& cur) const CXCursor& cur)

View file

@ -4,11 +4,11 @@
#include <cppast/cpp_friend.hpp> #include <cppast/cpp_friend.hpp>
#include <cppast/cpp_template_parameter.hpp>
#include <cppast/cpp_template.hpp> #include <cppast/cpp_template.hpp>
#include <cppast/cpp_template_parameter.hpp>
#include "parse_functions.hpp"
#include "libclang_visitor.hpp" #include "libclang_visitor.hpp"
#include "parse_functions.hpp"
using namespace cppast; using namespace cppast;
@ -45,8 +45,8 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_friend(const detail::parse_context
// we can't use the other branch here, // we can't use the other branch here,
// as then the class name would be wrong // as then the class name would be wrong
auto name = detail::get_cursor_name(referenced); auto name = detail::get_cursor_name(referenced);
type = type = cpp_user_defined_type::build(
cpp_user_defined_type::build(cpp_type_ref(detail::get_entity_id(referenced), cpp_type_ref(detail::get_entity_id(referenced),
namespace_str + "::" + name.c_str())); namespace_str + "::" + name.c_str()));
} }
else else

View file

@ -25,9 +25,9 @@ namespace
if (name.empty()) if (name.empty())
result = cpp_function_parameter::build(std::move(type), std::move(default_value)); result = cpp_function_parameter::build(std::move(type), std::move(default_value));
else else
result = cpp_function_parameter::build(*context.idx, detail::get_entity_id(cur), result
name.c_str(), std::move(type), = cpp_function_parameter::build(*context.idx, detail::get_entity_id(cur), name.c_str(),
std::move(default_value)); std::move(type), std::move(default_value));
result->add_attribute(attributes); result->add_attribute(attributes);
return result; return result;
} }
@ -71,8 +71,8 @@ namespace
for (auto i = 0; i != no; ++i) for (auto i = 0; i != no; ++i)
try try
{ {
auto parameter = auto parameter
parse_parameter(context, clang_Cursor_getArgument(cur, unsigned(i))); = parse_parameter(context, clang_Cursor_getArgument(cur, unsigned(i)));
builder.add_parameter(std::move(parameter)); builder.add_parameter(std::move(parameter));
} }
catch (detail::parse_error& ex) catch (detail::parse_error& ex)
@ -88,8 +88,7 @@ namespace
diagnostic{ex.what(), diagnostic{ex.what(),
detail::make_location(context.file, detail::make_location(context.file,
clang_Cursor_getArgument(cur, clang_Cursor_getArgument(cur,
unsigned( unsigned(i))),
i))),
severity::error}); severity::error});
} }
} }
@ -122,9 +121,8 @@ namespace
bool is_class(const CXCursor& parent) bool is_class(const CXCursor& parent)
{ {
auto kind = clang_getCursorKind(parent); auto kind = clang_getCursorKind(parent);
return kind == CXCursor_ClassDecl || kind == CXCursor_StructDecl return kind == CXCursor_ClassDecl || kind == CXCursor_StructDecl || kind == CXCursor_UnionDecl
|| kind == CXCursor_UnionDecl || kind == CXCursor_ClassTemplate || kind == CXCursor_ClassTemplate || kind == CXCursor_ClassTemplatePartialSpecialization;
|| kind == CXCursor_ClassTemplatePartialSpecialization;
} }
// returns the scope where the function is contained in // returns the scope where the function is contained in
@ -152,8 +150,7 @@ namespace
{ {
if (clang_getCursorKind(a) == clang_getCursorKind(b) if (clang_getCursorKind(a) == clang_getCursorKind(b)
&& clang_getCursorKind(a) == CXCursor_Namespace) && clang_getCursorKind(a) == CXCursor_Namespace)
return detail::cxstring(clang_getCursorUSR(a)) return detail::cxstring(clang_getCursorUSR(a)) == detail::cxstring(clang_getCursorUSR(b));
== detail::cxstring(clang_getCursorUSR(b));
else else
return clang_equalCursors(a, b) == 1; return clang_equalCursors(a, b) == 1;
} }
@ -201,8 +198,7 @@ namespace
// and the scope outside of the class for friend functions // and the scope outside of the class for friend functions
for (auto definition = get_definition_scope(cur, is_friend), for (auto definition = get_definition_scope(cur, is_friend),
parent = clang_getCursorSemanticParent(cur); parent = clang_getCursorSemanticParent(cur);
!equivalent_cursor(definition, parent); !equivalent_cursor(definition, parent); parent = clang_getCursorSemanticParent(parent))
parent = clang_getCursorSemanticParent(parent))
{ {
DEBUG_ASSERT(!clang_isTranslationUnit(clang_getCursorKind(parent)), DEBUG_ASSERT(!clang_isTranslationUnit(clang_getCursorKind(parent)),
detail::parse_error_handler{}, cur, detail::parse_error_handler{}, cur,
@ -282,8 +278,7 @@ namespace
return true; return true;
} }
prefix_info parse_prefix_info(detail::cxtoken_stream& stream, const char* name, prefix_info parse_prefix_info(detail::cxtoken_stream& stream, const char* name, bool is_ctor_dtor)
bool is_ctor_dtor)
{ {
prefix_info result; prefix_info result;
@ -298,8 +293,7 @@ namespace
else else
{ {
auto attributes = detail::parse_attributes(stream, true); auto attributes = detail::parse_attributes(stream, true);
result.attributes.insert(result.attributes.end(), attributes.begin(), result.attributes.insert(result.attributes.end(), attributes.begin(), attributes.end());
attributes.end());
} }
} }
DEBUG_ASSERT(!stream.done(), detail::parse_error_handler{}, stream.cursor(), DEBUG_ASSERT(!stream.done(), detail::parse_error_handler{}, stream.cursor(),
@ -325,10 +319,8 @@ namespace
cpp_virtual virtual_keywords; cpp_virtual virtual_keywords;
suffix_info(const CXCursor& cur) suffix_info(const CXCursor& cur)
: body_kind(clang_isCursorDefinition(cur) ? cpp_function_definition : : body_kind(clang_isCursorDefinition(cur) ? cpp_function_definition : cpp_function_declaration)
cpp_function_declaration) {}
{
}
}; };
cpp_cv parse_cv(detail::cxtoken_stream& stream) cpp_cv parse_cv(detail::cxtoken_stream& stream)
@ -414,9 +406,8 @@ namespace
} }
// precondition: we've skipped the function parameters // precondition: we've skipped the function parameters
suffix_info parse_suffix_info(detail::cxtoken_stream& stream, suffix_info parse_suffix_info(detail::cxtoken_stream& stream, const detail::parse_context& context,
const detail::parse_context& context, bool allow_qualifier, bool allow_qualifier, bool allow_virtual)
bool allow_virtual)
{ {
suffix_info result(stream.cursor()); suffix_info result(stream.cursor());
@ -507,8 +498,7 @@ namespace
auto attributes = detail::parse_attributes(stream); auto attributes = detail::parse_attributes(stream);
if (!attributes.empty()) if (!attributes.empty())
result.attributes.insert(result.attributes.end(), attributes.begin(), result.attributes.insert(result.attributes.end(), attributes.begin(), attributes.end());
attributes.end());
if (detail::skip_if(stream, "=")) if (detail::skip_if(stream, "="))
parse_body(stream, result, allow_virtual); parse_body(stream, result, allow_virtual);
@ -534,8 +524,7 @@ namespace
"free function cannot be virtual or explicit"); "free function cannot be virtual or explicit");
cpp_function::builder builder(name.c_str(), cpp_function::builder builder(name.c_str(),
detail::parse_type(context, cur, detail::parse_type(context, cur, clang_getCursorResultType(cur)));
clang_getCursorResultType(cur)));
context.comments.match(builder.get(), cur); context.comments.match(builder.get(), cur);
builder.get().add_attribute(prefix.attributes); builder.get().add_attribute(prefix.attributes);
@ -562,7 +551,7 @@ namespace
return builder.finish(*context.idx, detail::get_entity_id(cur), suffix.body_kind, return builder.finish(*context.idx, detail::get_entity_id(cur), suffix.body_kind,
parse_scope(cur, is_friend)); parse_scope(cur, is_friend));
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::parse_cpp_function(const detail::parse_context& context, std::unique_ptr<cpp_entity> detail::parse_cpp_function(const detail::parse_context& context,
const CXCursor& cur, bool is_friend) const CXCursor& cur, bool is_friend)
@ -604,8 +593,7 @@ namespace
else if (clang_CXXMethod_isPureVirtual(cur)) else if (clang_CXXMethod_isPureVirtual(cur))
{ {
// pure virtual function - all information in the suffix // pure virtual function - all information in the suffix
DEBUG_ASSERT(virtual_suffix.has_value() DEBUG_ASSERT(virtual_suffix.has_value() && virtual_suffix.value() & cpp_virtual_flags::pure,
&& virtual_suffix.value() & cpp_virtual_flags::pure,
detail::parse_error_handler{}, cur, "pure virtual not detected"); detail::parse_error_handler{}, cur, "pure virtual not detected");
return virtual_suffix; return virtual_suffix;
} }
@ -649,9 +637,9 @@ namespace
} }
template <class Builder> template <class Builder>
std::unique_ptr<cpp_entity> handle_suffix(const detail::parse_context& context, std::unique_ptr<cpp_entity> handle_suffix(const detail::parse_context& context, const CXCursor& cur,
const CXCursor& cur, Builder& builder, Builder& builder, detail::cxtoken_stream& stream,
detail::cxtoken_stream& stream, bool is_virtual, bool is_virtual,
type_safe::optional<cpp_entity_ref> semantic_parent) type_safe::optional<cpp_entity_ref> semantic_parent)
{ {
auto allow_qualifiers = set_qualifier(0, builder, cpp_cv_none, cpp_ref_none); auto allow_qualifiers = set_qualifier(0, builder, cpp_cv_none, cpp_ref_none);
@ -671,7 +659,7 @@ namespace
return builder.finish(*context.idx, detail::get_entity_id(cur), suffix.body_kind, return builder.finish(*context.idx, detail::get_entity_id(cur), suffix.body_kind,
std::move(semantic_parent)); std::move(semantic_parent));
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::parse_cpp_member_function(const detail::parse_context& context, std::unique_ptr<cpp_entity> detail::parse_cpp_member_function(const detail::parse_context& context,
const CXCursor& cur, bool is_friend) const CXCursor& cur, bool is_friend)

View file

@ -4,8 +4,8 @@
#include "parse_functions.hpp" #include "parse_functions.hpp"
#include <cppast/cpp_language_linkage.hpp>
#include <clang-c/Index.h> #include <clang-c/Index.h>
#include <cppast/cpp_language_linkage.hpp>
#include "libclang_visitor.hpp" #include "libclang_visitor.hpp"

View file

@ -10,12 +10,12 @@
#include <clang-c/CXCompilationDatabase.h> #include <clang-c/CXCompilationDatabase.h>
#include "cxtokenizer.hpp"
#include "libclang_visitor.hpp" #include "libclang_visitor.hpp"
#include "raii_wrapper.hpp"
#include "parse_error.hpp" #include "parse_error.hpp"
#include "parse_functions.hpp" #include "parse_functions.hpp"
#include "preprocessor.hpp" #include "preprocessor.hpp"
#include "cxtokenizer.hpp" #include "raii_wrapper.hpp"
using namespace cppast; using namespace cppast;
@ -94,9 +94,7 @@ namespace
} // namespace } // namespace
libclang_compile_config::libclang_compile_config() libclang_compile_config::libclang_compile_config()
: compile_config({}), : compile_config({}), write_preprocessed_(false), fast_preprocessing_(false),
write_preprocessed_(false),
fast_preprocessing_(false),
remove_comments_in_macro_(false) remove_comments_in_macro_(false)
{ {
// set given clang binary // set given clang binary
@ -134,8 +132,7 @@ namespace
bool is_absolute(const std::string& file) bool is_absolute(const std::string& file)
{ {
return !file.empty() return !file.empty() && (has_drive_prefix(file) || file.front() == '/' || file.front() == '\\');
&& (has_drive_prefix(file) || file.front() == '/' || file.front() == '\\');
} }
std::string get_full_path(const detail::cxstring& dir, const std::string& file) std::string get_full_path(const detail::cxstring& dir, const std::string& file)
@ -232,8 +229,8 @@ libclang_compile_config::libclang_compile_config(const libclang_compilation_data
const std::string& file) const std::string& file)
: libclang_compile_config() : libclang_compile_config()
{ {
auto cxcommands = auto cxcommands
clang_CompilationDatabase_getCompileCommands(database.database_, file.c_str()); = clang_CompilationDatabase_getCompileCommands(database.database_, file.c_str());
if (cxcommands == nullptr) if (cxcommands == nullptr)
throw libclang_error(detail::format("no compile commands specified for file '", file, "'")); throw libclang_error(detail::format("no compile commands specified for file '", file, "'"));
cxcompile_commands commands(cxcommands); cxcompile_commands commands(cxcommands);
@ -353,8 +350,8 @@ type_safe::optional<libclang_compile_config> cppast::find_config_for(
if (database.has_config(file_name)) if (database.has_config(file_name))
return libclang_compile_config(database, std::move(file_name)); return libclang_compile_config(database, std::move(file_name));
static const char* extensions[] = {".h", ".hpp", ".cpp", ".h++", ".c++", ".hxx", static const char* extensions[]
".cxx", ".hh", ".cc", ".H", ".C"}; = {".h", ".hpp", ".cpp", ".h++", ".c++", ".hxx", ".cxx", ".hh", ".cc", ".H", ".C"};
for (auto ext : extensions) for (auto ext : extensions)
{ {
auto name = file_name + ext; auto name = file_name + ext;
@ -370,16 +367,14 @@ struct libclang_parser::impl
detail::cxindex index; detail::cxindex index;
impl() : index(clang_createIndex(0, 0)) // no diagnostic, other one is irrelevant impl() : index(clang_createIndex(0, 0)) // no diagnostic, other one is irrelevant
{ {}
}
}; };
libclang_parser::libclang_parser() : libclang_parser(default_logger()) {} libclang_parser::libclang_parser() : libclang_parser(default_logger()) {}
libclang_parser::libclang_parser(type_safe::object_ref<const diagnostic_logger> logger) libclang_parser::libclang_parser(type_safe::object_ref<const diagnostic_logger> logger)
: parser(logger), pimpl_(new impl) : parser(logger), pimpl_(new impl)
{ {}
}
libclang_parser::~libclang_parser() noexcept {} libclang_parser::~libclang_parser() noexcept {}
@ -387,8 +382,8 @@ namespace
{ {
std::vector<const char*> get_arguments(const libclang_compile_config& config) std::vector<const char*> get_arguments(const libclang_compile_config& config)
{ {
std::vector<const char*> args = std::vector<const char*> args
{"-x", "c++", "-I."}; // force C++ and enable current directory for include search = {"-x", "c++", "-I."}; // force C++ and enable current directory for include search
for (auto& flag : detail::libclang_compile_config_access::flags(config)) for (auto& flag : detail::libclang_compile_config_access::flags(config))
args.push_back(flag.c_str()); args.push_back(flag.c_str());
return args; return args;
@ -436,8 +431,7 @@ namespace
} }
} }
detail::cxtranslation_unit get_cxunit(const diagnostic_logger& logger, detail::cxtranslation_unit get_cxunit(const diagnostic_logger& logger, const detail::cxindex& idx,
const detail::cxindex& idx,
const libclang_compile_config& config, const char* path, const libclang_compile_config& config, const char* path,
const std::string& source) const std::string& source)
{ {
@ -452,8 +446,8 @@ namespace
auto flags = CXTranslationUnit_Incomplete | CXTranslationUnit_KeepGoing auto flags = CXTranslationUnit_Incomplete | CXTranslationUnit_KeepGoing
| CXTranslationUnit_DetailedPreprocessingRecord; | CXTranslationUnit_DetailedPreprocessingRecord;
auto error = auto error
clang_parseTranslationUnit2(idx.get(), path, // index and path = clang_parseTranslationUnit2(idx.get(), path, // index and path
args.data(), args.data(),
static_cast<int>(args.size()), // arguments (ptr + size) static_cast<int>(args.size()), // arguments (ptr + size)
&file, 1, // unsaved files (ptr + size) &file, 1, // unsaved files (ptr + size)
@ -530,8 +524,8 @@ std::unique_ptr<cpp_file> libclang_parser::do_parse(const cpp_entity_index& idx,
&& get_line_no(cur) >= include_iter->line, && get_line_no(cur) >= include_iter->line,
detail::assert_handler{}); detail::assert_handler{});
auto full_path = include_iter->full_path.empty() ? include_iter->file_name : auto full_path = include_iter->full_path.empty() ? include_iter->file_name
include_iter->full_path; : include_iter->full_path;
// if we got an absolute file path for the current file, // if we got an absolute file path for the current file,
// also use an absolute file path for the id // also use an absolute file path for the id
@ -543,8 +537,8 @@ std::unique_ptr<cpp_file> libclang_parser::do_parse(const cpp_entity_index& idx,
else else
id = cpp_entity_id(include_iter->file_name.c_str()); id = cpp_entity_id(include_iter->file_name.c_str());
auto include = auto include
cpp_include_directive::build(cpp_file_ref(id, = cpp_include_directive::build(cpp_file_ref(id,
std::move(include_iter->file_name)), std::move(include_iter->file_name)),
include_iter->kind, std::move(full_path)); include_iter->kind, std::move(full_path));
context.comments.match(*include, include_iter->line, context.comments.match(*include, include_iter->line,

View file

@ -54,7 +54,7 @@ namespace cppast
f(cur); f(cur);
}); });
} }
} } // namespace detail
} // namespace cppast::detail } // namespace cppast
#endif // CPPAST_LIBCLANG_VISITOR_HPP_INCLUDED #endif // CPPAST_LIBCLANG_VISITOR_HPP_INCLUDED

View file

@ -13,8 +13,7 @@ using namespace cppast;
namespace namespace
{ {
cpp_namespace::builder make_ns_builder(const detail::parse_context& context, cpp_namespace::builder make_ns_builder(const detail::parse_context& context, const CXCursor& cur)
const CXCursor& cur)
{ {
detail::cxtokenizer tokenizer(context.tu, context.file, cur); detail::cxtokenizer tokenizer(context.tu, context.file, cur);
detail::cxtoken_stream stream(tokenizer, cur); detail::cxtoken_stream stream(tokenizer, cur);
@ -55,7 +54,7 @@ namespace
result.get().add_attribute(attributes); result.get().add_attribute(attributes);
return result; return result;
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::parse_cpp_namespace(const detail::parse_context& context, std::unique_ptr<cpp_entity> detail::parse_cpp_namespace(const detail::parse_context& context,
cpp_entity& parent, const CXCursor& cur) cpp_entity& parent, const CXCursor& cur)
@ -103,7 +102,7 @@ namespace
true); true);
return result; return result;
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::parse_cpp_namespace_alias(const detail::parse_context& context, std::unique_ptr<cpp_entity> detail::parse_cpp_namespace_alias(const detail::parse_context& context,
const CXCursor& cur) const CXCursor& cur)
@ -197,12 +196,11 @@ namespace
DEBUG_UNREACHABLE(detail::parse_error_handler{}, cur, DEBUG_UNREACHABLE(detail::parse_error_handler{}, cur,
"unexpected target for using declaration"); "unexpected target for using declaration");
} }
}, },
true); true);
return result.value(); return result.value();
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::parse_cpp_using_declaration( std::unique_ptr<cpp_entity> detail::parse_cpp_using_declaration(
const detail::parse_context& context, const CXCursor& cur) const detail::parse_context& context, const CXCursor& cur)

View file

@ -7,8 +7,8 @@
#include <stdexcept> #include <stdexcept>
#include <debug_assert.hpp>
#include <cppast/diagnostic.hpp> #include <cppast/diagnostic.hpp>
#include <debug_assert.hpp>
#include "debug_helper.hpp" #include "debug_helper.hpp"
@ -45,18 +45,15 @@ namespace cppast
public: public:
parse_error(source_location loc, std::string message) parse_error(source_location loc, std::string message)
: std::logic_error(std::move(message)), location_(std::move(loc)) : std::logic_error(std::move(message)), location_(std::move(loc))
{ {}
}
parse_error(const CXCursor& cur, std::string message) parse_error(const CXCursor& cur, std::string message)
: parse_error(make_location(cur), std::move(message)) : parse_error(make_location(cur), std::move(message))
{ {}
}
parse_error(const CXType& type, std::string message) parse_error(const CXType& type, std::string message)
: parse_error(make_location(type), std::move(message)) : parse_error(make_location(type), std::move(message))
{ {}
}
diagnostic get_diagnostic(const CXFile& file) diagnostic get_diagnostic(const CXFile& file)
{ {
@ -77,19 +74,19 @@ namespace cppast
// throws a parse_error exception // throws a parse_error exception
struct parse_error_handler : debug_assert::set_level<1>, debug_assert::allow_exception struct parse_error_handler : debug_assert::set_level<1>, debug_assert::allow_exception
{ {
static void handle(const debug_assert::source_location&, const char*, static void handle(const debug_assert::source_location&, const char*, const CXCursor& cur,
const CXCursor& cur, std::string message) std::string message)
{ {
throw parse_error(cur, std::move(message)); throw parse_error(cur, std::move(message));
} }
static void handle(const debug_assert::source_location&, const char*, static void handle(const debug_assert::source_location&, const char*, const CXType& type,
const CXType& type, std::string message) std::string message)
{ {
throw parse_error(type, std::move(message)); throw parse_error(type, std::move(message));
} }
}; };
} } // namespace detail
} // namespace cppast::detail } // namespace cppast
#endif // CPPAST_PARSE_ERROR_HPP_INCLUDED #endif // CPPAST_PARSE_ERROR_HPP_INCLUDED

View file

@ -4,8 +4,8 @@
#include "parse_functions.hpp" #include "parse_functions.hpp"
#include <cppast/cpp_storage_class_specifiers.hpp>
#include <cppast/cpp_static_assert.hpp> #include <cppast/cpp_static_assert.hpp>
#include <cppast/cpp_storage_class_specifiers.hpp>
#include "libclang_visitor.hpp" #include "libclang_visitor.hpp"
@ -109,7 +109,7 @@ namespace
return false; return false;
#endif #endif
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& context, std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& context,
cpp_entity* parent, const CXCursor& cur, cpp_entity* parent, const CXCursor& cur,
@ -165,25 +165,25 @@ std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& co
return parse_cpp_member_variable(context, cur); return parse_cpp_member_variable(context, cur);
case CXCursor_FunctionDecl: case CXCursor_FunctionDecl:
if (auto tfunc = if (auto tfunc
try_parse_cpp_function_template_specialization(context, cur, is_friend(parent_cur))) = try_parse_cpp_function_template_specialization(context, cur, is_friend(parent_cur)))
return tfunc; return tfunc;
return parse_cpp_function(context, cur, is_friend(parent_cur)); return parse_cpp_function(context, cur, is_friend(parent_cur));
case CXCursor_CXXMethod: case CXCursor_CXXMethod:
if (auto tfunc = if (auto tfunc
try_parse_cpp_function_template_specialization(context, cur, is_friend(parent_cur))) = try_parse_cpp_function_template_specialization(context, cur, is_friend(parent_cur)))
return tfunc; return tfunc;
else if (auto func = try_parse_static_cpp_function(context, cur)) else if (auto func = try_parse_static_cpp_function(context, cur))
return func; return func;
return parse_cpp_member_function(context, cur, is_friend(parent_cur)); return parse_cpp_member_function(context, cur, is_friend(parent_cur));
case CXCursor_ConversionFunction: case CXCursor_ConversionFunction:
if (auto tfunc = if (auto tfunc
try_parse_cpp_function_template_specialization(context, cur, is_friend(parent_cur))) = try_parse_cpp_function_template_specialization(context, cur, is_friend(parent_cur)))
return tfunc; return tfunc;
return parse_cpp_conversion_op(context, cur, is_friend(parent_cur)); return parse_cpp_conversion_op(context, cur, is_friend(parent_cur));
case CXCursor_Constructor: case CXCursor_Constructor:
if (auto tfunc = if (auto tfunc
try_parse_cpp_function_template_specialization(context, cur, is_friend(parent_cur))) = try_parse_cpp_function_template_specialization(context, cur, is_friend(parent_cur)))
return tfunc; return tfunc;
return parse_cpp_constructor(context, cur, is_friend(parent_cur)); return parse_cpp_constructor(context, cur, is_friend(parent_cur));
case CXCursor_Destructor: case CXCursor_Destructor:

View file

@ -8,10 +8,10 @@
#include <cppast/cpp_entity.hpp> #include <cppast/cpp_entity.hpp>
#include <cppast/parser.hpp> #include <cppast/parser.hpp>
#include "raii_wrapper.hpp"
#include "cxtokenizer.hpp" // for convenience #include "cxtokenizer.hpp" // for convenience
#include "parse_error.hpp" // for convenience #include "parse_error.hpp" // for convenience
#include "preprocessor.hpp" #include "preprocessor.hpp"
#include "raii_wrapper.hpp"
#if CINDEX_VERSION_MINOR >= 36 #if CINDEX_VERSION_MINOR >= 36
# define CPPAST_CINDEX_HAS_FRIEND 1 # define CPPAST_CINDEX_HAS_FRIEND 1
@ -42,8 +42,7 @@ namespace cppast
public: public:
explicit comment_context(std::vector<pp_doc_comment>& comments) explicit comment_context(std::vector<pp_doc_comment>& comments)
: cur_(comments.data()), end_(comments.data() + comments.size()) : cur_(comments.data()), end_(comments.data() + comments.size())
{ {}
}
// must be called for entities that want an associated comment // must be called for entities that want an associated comment
// must be called *BEFORE* the children are added // must be called *BEFORE* the children are added
@ -77,8 +76,8 @@ namespace cppast
// and ends at the given iterator // and ends at the given iterator
// this is required for situations where there is no type exposed, // this is required for situations where there is no type exposed,
// like default type of a template type parameter // like default type of a template type parameter
std::unique_ptr<cpp_type> parse_raw_type(const parse_context& context, std::unique_ptr<cpp_type> parse_raw_type(const parse_context& context, cxtoken_stream& stream,
cxtoken_stream& stream, cxtoken_iterator end); cxtoken_iterator end);
std::unique_ptr<cpp_expression> parse_expression(const parse_context& context, std::unique_ptr<cpp_expression> parse_expression(const parse_context& context,
const CXCursor& cur); const CXCursor& cur);
@ -123,10 +122,8 @@ namespace cppast
std::unique_ptr<cpp_entity> parse_cpp_type_alias(const parse_context& context, std::unique_ptr<cpp_entity> parse_cpp_type_alias(const parse_context& context,
const CXCursor& cur, const CXCursor& cur,
const CXCursor& template_cur); const CXCursor& template_cur);
std::unique_ptr<cpp_entity> parse_cpp_enum(const parse_context& context, std::unique_ptr<cpp_entity> parse_cpp_enum(const parse_context& context, const CXCursor& cur);
const CXCursor& cur); std::unique_ptr<cpp_entity> parse_cpp_class(const parse_context& context, const CXCursor& cur,
std::unique_ptr<cpp_entity> parse_cpp_class(const parse_context& context,
const CXCursor& cur,
const CXCursor& parent_cur); const CXCursor& parent_cur);
std::unique_ptr<cpp_entity> parse_cpp_variable(const parse_context& context, std::unique_ptr<cpp_entity> parse_cpp_variable(const parse_context& context,
@ -146,14 +143,12 @@ namespace cppast
std::unique_ptr<cpp_entity> parse_cpp_destructor(const parse_context& context, std::unique_ptr<cpp_entity> parse_cpp_destructor(const parse_context& context,
const CXCursor& cur, bool is_friend); const CXCursor& cur, bool is_friend);
std::unique_ptr<cpp_entity> parse_cpp_friend(const parse_context& context, std::unique_ptr<cpp_entity> parse_cpp_friend(const parse_context& context, const CXCursor& cur);
const CXCursor& cur);
std::unique_ptr<cpp_entity> parse_cpp_alias_template(const parse_context& context, std::unique_ptr<cpp_entity> parse_cpp_alias_template(const parse_context& context,
const CXCursor& cur); const CXCursor& cur);
std::unique_ptr<cpp_entity> parse_cpp_function_template(const parse_context& context, std::unique_ptr<cpp_entity> parse_cpp_function_template(const parse_context& context,
const CXCursor& cur, const CXCursor& cur, bool is_friend);
bool is_friend);
std::unique_ptr<cpp_entity> parse_cpp_class_template(const parse_context& context, std::unique_ptr<cpp_entity> parse_cpp_class_template(const parse_context& context,
const CXCursor& cur); const CXCursor& cur);
std::unique_ptr<cpp_entity> parse_cpp_class_template_specialization( std::unique_ptr<cpp_entity> parse_cpp_class_template_specialization(
@ -164,10 +159,10 @@ namespace cppast
// parent: used for nested namespace, doesn't matter otherwise // parent: used for nested namespace, doesn't matter otherwise
// parent_cur: used when parsing templates or friends // parent_cur: used when parsing templates or friends
std::unique_ptr<cpp_entity> parse_entity( std::unique_ptr<cpp_entity> parse_entity(const parse_context& context, cpp_entity* parent,
const parse_context& context, cpp_entity* parent, const CXCursor& cur, const CXCursor& cur,
const CXCursor& parent_cur = clang_getNullCursor()); const CXCursor& parent_cur = clang_getNullCursor());
} } // namespace detail
} // namespace cppast::detail } // namespace cppast
#endif // CPPAST_PARSE_FUNCTIONS_HPP_INCLUDED #endif // CPPAST_PARSE_FUNCTIONS_HPP_INCLUDED

View file

@ -109,8 +109,7 @@ namespace
// parses missing header file diagnostic and returns the file name, // parses missing header file diagnostic and returns the file name,
// if it is a missing header file diagnostic // if it is a missing header file diagnostic
ts::optional<std::string> parse_missing_file(const std::string& cur_file, ts::optional<std::string> parse_missing_file(const std::string& cur_file, const std::string& msg)
const std::string& msg)
{ {
auto ptr = msg.c_str(); auto ptr = msg.c_str();
@ -174,8 +173,8 @@ namespace
auto flags = std::string("-x c++ -I. -E -dM"); auto flags = std::string("-x c++ -I. -E -dM");
flags += diagnostics_flags(); flags += diagnostics_flags();
std::string cmd(detail::libclang_compile_config_access::clang_binary(c) + " " std::string cmd(detail::libclang_compile_config_access::clang_binary(c) + " " + std::move(flags)
+ std::move(flags) + " "); + " ");
// other flags // other flags
for (auto& flag : detail::libclang_compile_config_access::flags(c)) for (auto& flag : detail::libclang_compile_config_access::flags(c))
{ {
@ -220,8 +219,8 @@ namespace
flags += macro_file_path; flags += macro_file_path;
} }
std::string cmd(detail::libclang_compile_config_access::clang_binary(c) + " " std::string cmd(detail::libclang_compile_config_access::clang_binary(c) + " " + std::move(flags)
+ std::move(flags) + " "); + " ");
// other flags // other flags
for (const auto& flag : detail::libclang_compile_config_access::flags(c)) for (const auto& flag : detail::libclang_compile_config_access::flags(c))
@ -402,8 +401,7 @@ namespace
clang_preprocess_result clang_preprocess_impl(const libclang_compile_config& c, clang_preprocess_result clang_preprocess_impl(const libclang_compile_config& c,
const diagnostic_logger& logger, const diagnostic_logger& logger,
const std::string& full_path, const std::string& full_path, const char* macro_path)
const char* macro_path)
{ {
clang_preprocess_result result; clang_preprocess_result result;
@ -452,19 +450,17 @@ namespace
auto exit_code = process.get_exit_status(); auto exit_code = process.get_exit_status();
DEBUG_ASSERT(diagnostic.empty(), detail::assert_handler{}); DEBUG_ASSERT(diagnostic.empty(), detail::assert_handler{});
if (exit_code != 0 && !expect_bad_exit_code) if (exit_code != 0 && !expect_bad_exit_code)
throw libclang_error("preprocessor: command '" + cmd throw libclang_error("preprocessor: command '" + cmd + "' exited with non-zero exit code ("
+ "' exited with non-zero exit code (" + std::to_string(exit_code) + std::to_string(exit_code) + ")");
+ ")");
return result; return result;
} }
clang_preprocess_result clang_preprocess(const libclang_compile_config& c, clang_preprocess_result clang_preprocess(const libclang_compile_config& c, const char* full_path,
const char* full_path, const diagnostic_logger& logger) const diagnostic_logger& logger)
{ {
if (!std::ifstream(full_path)) if (!std::ifstream(full_path))
throw libclang_error("preprocessor: file '" + std::string(full_path) throw libclang_error("preprocessor: file '" + std::string(full_path) + "' doesn't exist");
+ "' doesn't exist");
// if we're fast preprocessing we only preprocess the main file, not includes // if we're fast preprocessing we only preprocess the main file, not includes
// this is done by disabling all include search paths when doing the preprocessing // this is done by disabling all include search paths when doing the preprocessing
@ -505,8 +501,7 @@ namespace
public: public:
position(ts::object_ref<std::string> result, const char* ptr) noexcept position(ts::object_ref<std::string> result, const char* ptr) noexcept
: result_(result), cur_line_(1u), cur_column_(0u), ptr_(ptr), write_(true) : result_(result), cur_line_(1u), cur_column_(0u), ptr_(ptr), write_(true)
{ {}
}
void set_line(unsigned line) void set_line(unsigned line)
{ {
@ -764,8 +759,7 @@ namespace
detail::pp_doc_comment parse_cpp_doc_comment(position& p, bool end_of_line) detail::pp_doc_comment parse_cpp_doc_comment(position& p, bool end_of_line)
{ {
detail::pp_doc_comment result; detail::pp_doc_comment result;
result.kind = result.kind = end_of_line ? detail::pp_doc_comment::end_of_line : detail::pp_doc_comment::cpp;
end_of_line ? detail::pp_doc_comment::end_of_line : detail::pp_doc_comment::cpp;
if (starts_with(p, " ")) if (starts_with(p, " "))
// skip one whitespace at most // skip one whitespace at most
p.skip(); p.skip();
@ -861,8 +855,7 @@ namespace
return builder.finish(); return builder.finish();
} }
std::unique_ptr<cpp_macro_definition> parse_macro(position& p, std::unique_ptr<cpp_macro_definition> parse_macro(position& p, detail::preprocessor_output& output)
detail::preprocessor_output& output)
{ {
// format (at new line): #define <name> [replacement] // format (at new line): #define <name> [replacement]
// or: #define <name>(<args>) [replacement] // or: #define <name>(<args>) [replacement]
@ -919,7 +912,8 @@ namespace
ts::optional<std::string> parse_undef(position& p) ts::optional<std::string> parse_undef(position& p)
{ {
// format (at new line): #undef <name> // format (at new line): #undef <name>
// due to a clang bug (http://bugs.llvm.org/show_bug.cgi?id=32631) I'll also an undef in the middle of the line // due to a clang bug (http://bugs.llvm.org/show_bug.cgi?id=32631) I'll also an undef in the
// middle of the line
if (/*!p.was_newl() ||*/ !starts_with(p, "#undef")) if (/*!p.was_newl() ||*/ !starts_with(p, "#undef"))
return ts::nullopt; return ts::nullopt;
p.bump(std::strlen("#undef")); p.bump(std::strlen("#undef"));
@ -973,8 +967,7 @@ namespace
if (!p.write_enabled()) if (!p.write_enabled())
return type_safe::nullopt; return type_safe::nullopt;
if (filename.size() > 2u && filename[0] == '.' if (filename.size() > 2u && filename[0] == '.' && (filename[1] == '/' || filename[1] == '\\'))
&& (filename[1] == '/' || filename[1] == '\\'))
filename = filename.substr(2); filename = filename.substr(2);
return detail::pp_include{std::move(filename), "", include_kind, p.cur_line()}; return detail::pp_include{std::move(filename), "", include_kind, p.cur_line()};
@ -1002,7 +995,8 @@ namespace
line_directive, // no change in file line_directive, // no change in file
enter_new, // open a new file enter_new, // open a new file
enter_old, // return to an old file enter_old, // return to an old file
} flag = line_directive; } flag
= line_directive;
bool is_system = false; bool is_system = false;
}; };
@ -1016,8 +1010,7 @@ namespace
if (!p.was_newl() || !starts_with(p, "#")) if (!p.was_newl() || !starts_with(p, "#"))
return ts::nullopt; return ts::nullopt;
p.skip(); p.skip();
DEBUG_ASSERT(!starts_with(p, "define") && !starts_with(p, "undef") DEBUG_ASSERT(!starts_with(p, "define") && !starts_with(p, "undef") && !starts_with(p, "pragma"),
&& !starts_with(p, "pragma"),
detail::assert_handler{}, "handle macros first"); detail::assert_handler{}, "handle macros first");
linemarker result; linemarker result;
@ -1174,12 +1167,14 @@ detail::preprocessor_output detail::preprocess(const libclang_compile_config& co
} }
else else
{ {
// this is an indirect include, remember it to get full path for indirect includes // this is an indirect include, remember it to get full path for indirect
// includes
auto& full_path = lm.value().file; auto& full_path = lm.value().file;
auto last_dir = full_path.find_last_of("/\\"); auto last_dir = full_path.find_last_of("/\\");
auto file_name = auto file_name = last_dir == std::string::npos
last_dir == std::string::npos ? full_path : full_path.substr(last_dir + 1u); ? full_path
: full_path.substr(last_dir + 1u);
indirect_includes.emplace(std::move(file_name), full_path); indirect_includes.emplace(std::move(file_name), full_path);
} }
@ -1237,9 +1232,9 @@ detail::preprocessor_output detail::preprocess(const libclang_compile_config& co
{ {
auto last_sep = include.file_name.find_last_of("/\\"); auto last_sep = include.file_name.find_last_of("/\\");
auto iter = indirect_includes.find(last_sep == std::string::npos ? auto iter = indirect_includes.find(last_sep == std::string::npos
include.file_name : ? include.file_name
include.file_name.substr(last_sep + 1u)); : include.file_name.substr(last_sep + 1u));
if (iter != indirect_includes.end()) if (iter != indirect_includes.end())
include.full_path = iter->second; include.full_path = iter->second;
else else

View file

@ -49,7 +49,7 @@ namespace cppast
preprocessor_output preprocess(const libclang_compile_config& config, const char* path, preprocessor_output preprocess(const libclang_compile_config& config, const char* path,
const diagnostic_logger& logger); const diagnostic_logger& logger);
} } // namespace detail
} // namespace cppast::detail } // namespace cppast
#endif // CPPAST_PREPROCESSOR_HPP_INCLUDED #endif // CPPAST_PREPROCESSOR_HPP_INCLUDED

View file

@ -144,8 +144,7 @@ namespace cppast
explicit string(CXString str) explicit string(CXString str)
: str(std::move(str)), c_str(clang_getCString(str)), length(std::strlen(c_str)) : str(std::move(str)), c_str(clang_getCString(str)), length(std::strlen(c_str))
{ {}
}
}; };
type_safe::optional<string> str_; type_safe::optional<string> str_;
}; };
@ -179,7 +178,7 @@ namespace cppast
{ {
return !(str == b); return !(str == b);
} }
} } // namespace detail
} // namespace cppast::detail } // namespace cppast
#endif // CPPAST_RAII_WRAPPER_HPP_INCLUDED #endif // CPPAST_RAII_WRAPPER_HPP_INCLUDED

View file

@ -16,8 +16,8 @@ using namespace cppast;
namespace namespace
{ {
template <typename TemplateT, typename EntityT, typename Predicate> template <typename TemplateT, typename EntityT, typename Predicate>
type_safe::optional<typename TemplateT::builder> get_builder( type_safe::optional<typename TemplateT::builder> get_builder(const detail::parse_context& context,
const detail::parse_context& context, const CXCursor& cur, Predicate p) const CXCursor& cur, Predicate p)
{ {
// we need the actual entity first, then the parameters // we need the actual entity first, then the parameters
// so two visit calls are required // so two visit calls are required
@ -38,14 +38,13 @@ namespace
auto entity = detail::parse_entity(context, nullptr, result, cur); auto entity = detail::parse_entity(context, nullptr, result, cur);
if (!entity) if (!entity)
return type_safe::nullopt; return type_safe::nullopt;
DEBUG_ASSERT(p(entity->kind()), detail::parse_error_handler{}, cur, DEBUG_ASSERT(p(entity->kind()), detail::parse_error_handler{}, cur, "wrong child of template");
"wrong child of template");
return typename TemplateT::builder( return typename TemplateT::builder(
std::unique_ptr<EntityT>(static_cast<EntityT*>(entity.release()))); std::unique_ptr<EntityT>(static_cast<EntityT*>(entity.release())));
} }
std::unique_ptr<cpp_template_parameter> parse_type_parameter( std::unique_ptr<cpp_template_parameter> parse_type_parameter(const detail::parse_context& context,
const detail::parse_context& context, const CXCursor& cur) const CXCursor& cur)
{ {
DEBUG_ASSERT(clang_getCursorKind(cur) == CXCursor_TemplateTypeParameter, DEBUG_ASSERT(clang_getCursorKind(cur) == CXCursor_TemplateTypeParameter,
detail::assert_handler{}); detail::assert_handler{});
@ -110,8 +109,7 @@ namespace
break; break;
} }
auto result = auto result = cpp_non_type_template_parameter::build(*context.idx, detail::get_entity_id(cur),
cpp_non_type_template_parameter::build(*context.idx, detail::get_entity_id(cur),
name.c_str(), name.c_str(),
detail::parse_type(context, cur, type), detail::parse_type(context, cur, type),
is_variadic, std::move(def)); is_variadic, std::move(def));
@ -168,11 +166,9 @@ namespace
spelling += stream.get().c_str(); spelling += stream.get().c_str();
if (stream.unmunch()) if (stream.unmunch())
{ {
DEBUG_ASSERT(!spelling.empty() && spelling.back() == '>', DEBUG_ASSERT(!spelling.empty() && spelling.back() == '>', detail::assert_handler{});
detail::assert_handler{});
spelling.pop_back(); spelling.pop_back();
DEBUG_ASSERT(!spelling.empty() && spelling.back() == '>', DEBUG_ASSERT(!spelling.empty() && spelling.back() == '>', detail::assert_handler{});
detail::assert_handler{});
} }
builder.default_template( builder.default_template(
@ -187,8 +183,7 @@ namespace
} }
template <class Builder> template <class Builder>
void parse_parameters(Builder& builder, const detail::parse_context& context, void parse_parameters(Builder& builder, const detail::parse_context& context, const CXCursor& cur)
const CXCursor& cur)
{ {
// now visit to get the parameters // now visit to get the parameters
detail::visit_children(cur, [&](const CXCursor& child) { detail::visit_children(cur, [&](const CXCursor& child) {
@ -212,15 +207,15 @@ namespace
// copy attributes over // copy attributes over
templ_entity.add_attribute(non_template.attributes()); templ_entity.add_attribute(non_template.attributes());
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::parse_cpp_alias_template(const detail::parse_context& context, std::unique_ptr<cpp_entity> detail::parse_cpp_alias_template(const detail::parse_context& context,
const CXCursor& cur) const CXCursor& cur)
{ {
DEBUG_ASSERT(clang_getCursorKind(cur) == CXCursor_TypeAliasTemplateDecl, DEBUG_ASSERT(clang_getCursorKind(cur) == CXCursor_TypeAliasTemplateDecl,
detail::assert_handler{}); detail::assert_handler{});
auto builder = auto builder
get_builder<cpp_alias_template, cpp_type_alias>(context, cur, [](cpp_entity_kind k) { = get_builder<cpp_alias_template, cpp_type_alias>(context, cur, [](cpp_entity_kind k) {
return k == cpp_entity_kind::type_alias_t; return k == cpp_entity_kind::type_alias_t;
}); });
if (!builder) if (!builder)
@ -280,8 +275,7 @@ namespace
detail::cxtokenizer tokenizer(context.tu, context.file, cur); detail::cxtokenizer tokenizer(context.tu, context.file, cur);
detail::cxtoken_stream stream(tokenizer, cur); detail::cxtoken_stream stream(tokenizer, cur);
while (!stream.done() while (!stream.done() && !detail::skip_if(stream, detail::get_cursor_name(cur).c_str(), true))
&& !detail::skip_if(stream, detail::get_cursor_name(cur).c_str(), true))
stream.bump(); stream.bump();
if (stream.peek() == "<") if (stream.peek() == "<")
@ -295,7 +289,7 @@ namespace
else else
b.add_unexposed_arguments(cpp_token_string::builder().finish()); b.add_unexposed_arguments(cpp_token_string::builder().finish());
} }
} } // namespace
std::unique_ptr<cpp_entity> detail::try_parse_cpp_function_template_specialization( std::unique_ptr<cpp_entity> detail::try_parse_cpp_function_template_specialization(
const detail::parse_context& context, const CXCursor& cur, bool is_friend) const detail::parse_context& context, const CXCursor& cur, bool is_friend)

View file

@ -236,8 +236,8 @@ namespace
return cpp_ref_none; return cpp_ref_none;
} }
std::unique_ptr<cpp_type> parse_type_impl(const detail::parse_context& context, std::unique_ptr<cpp_type> parse_type_impl(const detail::parse_context& context, const CXCursor& cur,
const CXCursor& cur, const CXType& type); const CXType& type);
std::unique_ptr<cpp_expression> parse_array_size(const CXCursor& cur, const CXType& type) std::unique_ptr<cpp_expression> parse_array_size(const CXCursor& cur, const CXType& type)
{ {
@ -263,9 +263,9 @@ namespace
size_expr += *ptr; size_expr += *ptr;
} }
return size_expr.empty() ? return size_expr.empty()
nullptr : ? nullptr
cpp_unexposed_expression::build(cpp_builtin_type::build(cpp_ulonglong), : cpp_unexposed_expression::build(cpp_builtin_type::build(cpp_ulonglong),
cpp_token_string::tokenize( cpp_token_string::tokenize(
std::string(size_expr.rbegin(), std::string(size_expr.rbegin(),
size_expr.rend()))); size_expr.rend())));
@ -298,8 +298,7 @@ namespace
const CXCursor& cur, const CXType& type) const CXCursor& cur, const CXType& type)
{ {
auto no_args = clang_getNumArgTypes(type); auto no_args = clang_getNumArgTypes(type);
DEBUG_ASSERT(no_args >= 0, detail::parse_error_handler{}, type, DEBUG_ASSERT(no_args >= 0, detail::parse_error_handler{}, type, "invalid number of arguments");
"invalid number of arguments");
for (auto i = 0u; i != unsigned(no_args); ++i) for (auto i = 0u; i != unsigned(no_args); ++i)
builder.add_parameter(parse_type_impl(context, cur, clang_getArgType(type, i))); builder.add_parameter(parse_type_impl(context, cur, clang_getArgType(type, i)));
@ -345,8 +344,8 @@ namespace
auto cv = suffix_cv(spelling); auto cv = suffix_cv(spelling);
auto class_t = clang_Type_getClassType(type); auto class_t = clang_Type_getClassType(type);
auto class_entity = auto class_entity
make_ref_qualified(make_cv_qualified(parse_type_impl(context, cur, class_t), cv), ref); = make_ref_qualified(make_cv_qualified(parse_type_impl(context, cur, class_t), cv), ref);
auto pointee = clang_getPointeeType(type); // for everything except the class type auto pointee = clang_getPointeeType(type); // for everything except the class type
auto result = clang_getResultType(pointee); auto result = clang_getResultType(pointee);
@ -392,8 +391,8 @@ namespace
return clang_getNullCursor(); return clang_getNullCursor();
} }
std::unique_ptr<cpp_type> try_parse_template_parameter_type( std::unique_ptr<cpp_type> try_parse_template_parameter_type(const detail::parse_context& context,
const detail::parse_context& context, const CXCursor& cur, const CXType& type) const CXCursor& cur, const CXType& type)
{ {
// see if we have a parent template // see if we have a parent template
auto templ = get_template(cur); auto templ = get_template(cur);
@ -402,20 +401,17 @@ namespace
return nullptr; return nullptr;
// doesn't respect cv qualifiers properly // doesn't respect cv qualifiers properly
auto result = auto result
make_leave_type(cur, type, = make_leave_type(cur, type, [&](std::string&& type_spelling) -> std::unique_ptr<cpp_type> {
[&](std::string&& type_spelling) -> std::unique_ptr<cpp_type> {
// look at the template parameters, // look at the template parameters,
// see if we find a matching one // see if we find a matching one
auto param = clang_getNullCursor(); auto param = clang_getNullCursor();
detail::visit_children(templ, [&](const CXCursor& child) { detail::visit_children(templ, [&](const CXCursor& child) {
if (clang_getCursorKind(child) == CXCursor_TemplateTypeParameter if (clang_getCursorKind(child) == CXCursor_TemplateTypeParameter
&& get_type_spelling(child, clang_getCursorType(child)) && get_type_spelling(child, clang_getCursorType(child)) == type_spelling)
== type_spelling)
{ {
// found one // found one
DEBUG_ASSERT(clang_Cursor_isNull(param), DEBUG_ASSERT(clang_Cursor_isNull(param), detail::assert_handler{});
detail::assert_handler{});
param = child; param = child;
} }
}); });
@ -425,8 +421,7 @@ namespace
else else
// found matching parameter // found matching parameter
return cpp_template_parameter_type::build( return cpp_template_parameter_type::build(
cpp_template_type_parameter_ref(detail::get_entity_id( cpp_template_type_parameter_ref(detail::get_entity_id(param),
param),
std::move(type_spelling))); std::move(type_spelling)));
}); });
@ -503,8 +498,8 @@ namespace
}); });
} }
std::unique_ptr<cpp_type> try_parse_decltype_type(const detail::parse_context&, std::unique_ptr<cpp_type> try_parse_decltype_type(const detail::parse_context&, const CXCursor& cur,
const CXCursor& cur, const CXType& type) const CXType& type)
{ {
if (clang_isExpression(clang_getCursorKind(cur))) if (clang_isExpression(clang_getCursorKind(cur)))
return nullptr; // don't use decltype here return nullptr; // don't use decltype here
@ -523,8 +518,8 @@ namespace
}); });
} }
std::unique_ptr<cpp_type> parse_type_impl(const detail::parse_context& context, std::unique_ptr<cpp_type> parse_type_impl(const detail::parse_context& context, const CXCursor& cur,
const CXCursor& cur, const CXType& type) const CXType& type)
{ {
switch (type.kind) switch (type.kind)
{ {
@ -589,10 +584,10 @@ namespace
context.logger->log("libclang parser", context.logger->log("libclang parser",
format_diagnostic(severity::warning, detail::make_location(type), format_diagnostic(severity::warning, detail::make_location(type),
"unexpected type of kind '", "unexpected type of kind '",
detail::get_type_kind_spelling(type).c_str(), detail::get_type_kind_spelling(type).c_str(), "'"));
"'"));
// fallthrough // fallthrough
case CXType_Dependent: // seems to have something to do with expressions, just ignore that (for now?) case CXType_Dependent: // seems to have something to do with expressions, just ignore that (for
// now?)
case CXType_Unexposed: case CXType_Unexposed:
if (auto ftype = try_parse_function_type(context, cur, type)) if (auto ftype = try_parse_function_type(context, cur, type))
// guess what: after you've called clang_getPointeeType() on a function pointer // guess what: after you've called clang_getPointeeType() on a function pointer
@ -621,36 +616,30 @@ namespace
return make_leave_type(cur, type, return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_bool); }); [](std::string&&) { return cpp_builtin_type::build(cpp_bool); });
case CXType_UChar: case CXType_UChar:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_uchar); [](std::string&&) { return cpp_builtin_type::build(cpp_uchar); });
});
case CXType_UShort: case CXType_UShort:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_ushort); [](std::string&&) { return cpp_builtin_type::build(cpp_ushort); });
});
case CXType_UInt: case CXType_UInt:
return make_leave_type(cur, type, return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_uint); }); [](std::string&&) { return cpp_builtin_type::build(cpp_uint); });
case CXType_ULong: case CXType_ULong:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_ulong); [](std::string&&) { return cpp_builtin_type::build(cpp_ulong); });
});
case CXType_ULongLong: case CXType_ULongLong:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_ulonglong); return cpp_builtin_type::build(cpp_ulonglong);
}); });
case CXType_UInt128: case CXType_UInt128:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_uint128); [](std::string&&) { return cpp_builtin_type::build(cpp_uint128); });
});
case CXType_SChar: case CXType_SChar:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_schar); [](std::string&&) { return cpp_builtin_type::build(cpp_schar); });
});
case CXType_Short: case CXType_Short:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_short); [](std::string&&) { return cpp_builtin_type::build(cpp_short); });
});
case CXType_Int: case CXType_Int:
return make_leave_type(cur, type, return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_int); }); [](std::string&&) { return cpp_builtin_type::build(cpp_int); });
@ -658,49 +647,40 @@ namespace
return make_leave_type(cur, type, return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_long); }); [](std::string&&) { return cpp_builtin_type::build(cpp_long); });
case CXType_LongLong: case CXType_LongLong:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_longlong); [](std::string&&) { return cpp_builtin_type::build(cpp_longlong); });
});
case CXType_Int128: case CXType_Int128:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_int128); [](std::string&&) { return cpp_builtin_type::build(cpp_int128); });
});
case CXType_Float: case CXType_Float:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_float); [](std::string&&) { return cpp_builtin_type::build(cpp_float); });
});
case CXType_Double: case CXType_Double:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_double); [](std::string&&) { return cpp_builtin_type::build(cpp_double); });
});
case CXType_LongDouble: case CXType_LongDouble:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_longdouble); return cpp_builtin_type::build(cpp_longdouble);
}); });
case CXType_Float128: case CXType_Float128:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_float128); [](std::string&&) { return cpp_builtin_type::build(cpp_float128); });
});
case CXType_Char_U: case CXType_Char_U:
case CXType_Char_S: case CXType_Char_S:
return make_leave_type(cur, type, return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_char); }); [](std::string&&) { return cpp_builtin_type::build(cpp_char); });
case CXType_Char16: case CXType_Char16:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_char16); [](std::string&&) { return cpp_builtin_type::build(cpp_char16); });
});
case CXType_Char32: case CXType_Char32:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_char32); [](std::string&&) { return cpp_builtin_type::build(cpp_char32); });
});
case CXType_WChar: case CXType_WChar:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_wchar); [](std::string&&) { return cpp_builtin_type::build(cpp_wchar); });
});
case CXType_NullPtr: case CXType_NullPtr:
return make_leave_type(cur, type, [](std::string&&) { return make_leave_type(cur, type,
return cpp_builtin_type::build(cpp_nullptr); [](std::string&&) { return cpp_builtin_type::build(cpp_nullptr); });
});
case CXType_Elaborated: case CXType_Elaborated:
if (auto itype = try_parse_instantiation_type(context, cur, type)) if (auto itype = try_parse_instantiation_type(context, cur, type))
@ -748,14 +728,13 @@ namespace
return cpp_pointer_type::build(parse_member_pointee_type(context, cur, type)); return cpp_pointer_type::build(parse_member_pointee_type(context, cur, type));
case CXType_Auto: case CXType_Auto:
return make_leave_type(cur, type, return make_leave_type(cur, type, [&](std::string&&) { return cpp_auto_type::build(); });
[&](std::string&&) { return cpp_auto_type::build(); });
} }
DEBUG_UNREACHABLE(detail::assert_handler{}); DEBUG_UNREACHABLE(detail::assert_handler{});
return nullptr; return nullptr;
} }
} } // namespace
std::unique_ptr<cpp_type> detail::parse_type(const detail::parse_context& context, std::unique_ptr<cpp_type> detail::parse_type(const detail::parse_context& context,
const CXCursor& cur, const CXType& type) const CXCursor& cur, const CXType& type)
@ -789,8 +768,8 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_type_alias(const detail::parse_con
result = cpp_type_alias::build(name.c_str(), std::move(type)); result = cpp_type_alias::build(name.c_str(), std::move(type));
else else
{ {
result = result = cpp_type_alias::build(*context.idx, get_entity_id(cur), name.c_str(),
cpp_type_alias::build(*context.idx, get_entity_id(cur), name.c_str(), std::move(type)); std::move(type));
context.comments.match(*result, cur); context.comments.match(*result, cur);
} }

View file

@ -64,8 +64,8 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_variable(const detail::parse_conte
detail::cxtokenizer tokenizer(context.tu, context.file, cur); detail::cxtokenizer tokenizer(context.tu, context.file, cur);
for (auto& token : tokenizer) for (auto& token : tokenizer)
if (token.value() == "thread_local") if (token.value() == "thread_local")
storage_class = storage_class
cpp_storage_class_specifiers(storage_class | cpp_storage_class_thread_local); = cpp_storage_class_specifiers(storage_class | cpp_storage_class_thread_local);
else if (token.value() == "constexpr") else if (token.value() == "constexpr")
is_constexpr = true; is_constexpr = true;
@ -75,8 +75,8 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_variable(const detail::parse_conte
std::unique_ptr<cpp_variable> result; std::unique_ptr<cpp_variable> result;
if (clang_isCursorDefinition(cur)) if (clang_isCursorDefinition(cur))
{ {
result = result
cpp_variable::build(*context.idx, get_entity_id(cur), name.c_str(), std::move(type), = cpp_variable::build(*context.idx, get_entity_id(cur), name.c_str(), std::move(type),
std::move(default_value), storage_class, is_constexpr); std::move(default_value), storage_class, is_constexpr);
} }
else else

View file

@ -21,9 +21,9 @@ namespace
cpp_access_specifier_kind get_initial_access(const cpp_entity& e) cpp_access_specifier_kind get_initial_access(const cpp_entity& e)
{ {
if (e.kind() == cpp_class::kind()) if (e.kind() == cpp_class::kind())
return static_cast<const cpp_class&>(e).class_kind() == cpp_class_kind::class_t ? return static_cast<const cpp_class&>(e).class_kind() == cpp_class_kind::class_t
cpp_private : ? cpp_private
cpp_public; : cpp_public;
return cpp_public; return cpp_public;
} }
@ -39,8 +39,8 @@ namespace
{ {
auto& container = static_cast<const T&>(e); auto& container = static_cast<const T&>(e);
auto handle_children = auto handle_children
cb(functor, container, {visitor_info::container_entity_enter, cur_access, last_child}); = cb(functor, container, {visitor_info::container_entity_enter, cur_access, last_child});
if (handle_children) if (handle_children)
{ {
auto child_access = get_initial_access(e); auto child_access = get_initial_access(e);
@ -56,8 +56,7 @@ namespace
} }
} }
return cb(functor, container, return cb(functor, container, {visitor_info::container_entity_exit, cur_access, last_child});
{visitor_info::container_entity_exit, cur_access, last_child});
} }
} // namespace } // namespace

View file

@ -46,9 +46,9 @@ alignas(type) int var;
auto file = parse({}, "cpp_attribute.cpp", code); auto file = parse({}, "cpp_attribute.cpp", code);
auto check_attribute = [](const cpp_attribute& attr, const char* name, auto check_attribute
type_safe::optional<std::string> scope, bool variadic, = [](const cpp_attribute& attr, const char* name, type_safe::optional<std::string> scope,
const char* args, cpp_attribute_kind kind) { bool variadic, const char* args, cpp_attribute_kind kind) {
REQUIRE(attr.kind() == kind); REQUIRE(attr.kind() == kind);
REQUIRE(attr.name() == name); REQUIRE(attr.name() == name);
REQUIRE(attr.scope() == scope); REQUIRE(attr.scope() == scope);
@ -60,8 +60,8 @@ alignas(type) int var;
REQUIRE(*args == '\0'); REQUIRE(*args == '\0');
}; };
auto count = auto count
test_visit<cpp_function>(*file, = test_visit<cpp_function>(*file,
[&](const cpp_entity& e) { [&](const cpp_entity& e) {
auto& attributes = e.attributes(); auto& attributes = e.attributes();
REQUIRE(attributes.size() >= 1u); REQUIRE(attributes.size() >= 1u);
@ -79,8 +79,8 @@ alignas(type) int var;
cpp_attribute_kind::unknown); cpp_attribute_kind::unknown);
} }
else if (e.name() == "c") else if (e.name() == "c")
check_attribute(attr, "variadic", type_safe::nullopt, true, check_attribute(attr, "variadic", type_safe::nullopt,
"", cpp_attribute_kind::unknown); true, "", cpp_attribute_kind::unknown);
else if (e.name() == "d") else if (e.name() == "d")
{ {
REQUIRE(has_attribute(e, "ns::attribute")); REQUIRE(has_attribute(e, "ns::attribute"));
@ -94,17 +94,19 @@ alignas(type) int var;
else if (e.name() == "f") else if (e.name() == "f")
{ {
REQUIRE(attributes.size() == 2u); REQUIRE(attributes.size() == 2u);
check_attribute(attr, "attribute", "ns", false, "+,-,0 4", check_attribute(attr, "attribute", "ns", false,
cpp_attribute_kind::unknown); "+,-,0 4", cpp_attribute_kind::unknown);
check_attribute(attributes[1u], "other_attribute", check_attribute(attributes[1u], "other_attribute",
type_safe::nullopt, false, "", type_safe::nullopt, false, "",
cpp_attribute_kind::unknown); cpp_attribute_kind::unknown);
} }
else if (e.name() == "g") else if (e.name() == "g")
{ {
REQUIRE(has_attribute(e, cpp_attribute_kind::deprecated)); REQUIRE(
has_attribute(e, cpp_attribute_kind::deprecated));
check_attribute(attr, "deprecated", type_safe::nullopt, check_attribute(attr, "deprecated", type_safe::nullopt,
false, "", cpp_attribute_kind::deprecated); false, "",
cpp_attribute_kind::deprecated);
} }
else if (e.name() == "h") else if (e.name() == "h")
check_attribute(attr, "maybe_unused", type_safe::nullopt, check_attribute(attr, "maybe_unused", type_safe::nullopt,
@ -112,7 +114,8 @@ alignas(type) int var;
cpp_attribute_kind::maybe_unused); cpp_attribute_kind::maybe_unused);
else if (e.name() == "i") else if (e.name() == "i")
check_attribute(attr, "nodiscard", type_safe::nullopt, check_attribute(attr, "nodiscard", type_safe::nullopt,
false, "", cpp_attribute_kind::nodiscard); false, "",
cpp_attribute_kind::nodiscard);
else if (e.name() == "j") else if (e.name() == "j")
check_attribute(attr, "noreturn", type_safe::nullopt, check_attribute(attr, "noreturn", type_safe::nullopt,
false, "", cpp_attribute_kind::noreturn); false, "", cpp_attribute_kind::noreturn);

View file

@ -226,8 +226,8 @@ int d() {}
} }
else if (entity.value().kind() == cpp_entity_kind::function_template_specialization_t) else if (entity.value().kind() == cpp_entity_kind::function_template_specialization_t)
{ {
auto& func = auto& func
static_cast<const cpp_function_template_specialization&>(entity.value()); = static_cast<const cpp_function_template_specialization&>(entity.value());
if (func.name() == "templ_c") if (func.name() == "templ_c")
{ {
REQUIRE(func.function().is_declaration()); REQUIRE(func.function().is_declaration());

View file

@ -270,8 +270,8 @@ using ns1::d;
)"; )";
cpp_entity_index idx; cpp_entity_index idx;
auto check_declaration = [&](const cpp_using_declaration& decl, const char* target_full_name, auto check_declaration
unsigned no) { = [&](const cpp_using_declaration& decl, const char* target_full_name, unsigned no) {
auto target = decl.target(); auto target = decl.target();
REQUIRE((target.no_overloaded() == no)); REQUIRE((target.no_overloaded() == no));
for (auto entity : target.get(idx)) for (auto entity : target.get(idx))

View file

@ -34,8 +34,8 @@ namespace ns2
)"; )";
const char* order[] = {"A", "B", "ns", "C", "D", "E", "ns2", "F"}; const char* order[] = {"A", "B", "ns", "C", "D", "E", "ns2", "F"};
auto check_macro = [](const cpp_macro_definition& macro, const char* replacement, auto check_macro
const char* args) { = [](const cpp_macro_definition& macro, const char* replacement, const char* args) {
REQUIRE(macro.replacement() == replacement); REQUIRE(macro.replacement() == replacement);
if (args) if (args)
{ {
@ -117,8 +117,8 @@ b
auto file_a = parse(idx, "header_a.hpp", header_a); auto file_a = parse(idx, "header_a.hpp", header_a);
auto file_b = parse(idx, "header_b.hpp", header_b); auto file_b = parse(idx, "header_b.hpp", header_b);
auto count = auto count
test_visit<cpp_include_directive>(*file_a, [&](const cpp_include_directive& include) { = test_visit<cpp_include_directive>(*file_a, [&](const cpp_include_directive& include) {
if (include.name() == "iostream") if (include.name() == "iostream")
{ {
REQUIRE(include.target().name() == include.name()); REQUIRE(include.target().name() == include.name());

View file

@ -45,8 +45,8 @@ using e = void;
{ {
REQUIRE(p.kind() == cpp_entity_kind::template_type_parameter_t); REQUIRE(p.kind() == cpp_entity_kind::template_type_parameter_t);
auto& param = auto& param
static_cast<const cpp_template_type_parameter&>(p); = static_cast<const cpp_template_type_parameter&>(p);
if (param.name() == "A") if (param.name() == "A")
{ {
REQUIRE(alias.name() == "a"); REQUIRE(alias.name() == "a");
@ -132,8 +132,8 @@ using d = void;
REQUIRE(p.kind() REQUIRE(p.kind()
== cpp_entity_kind::non_type_template_parameter_t); == cpp_entity_kind::non_type_template_parameter_t);
auto& param = auto& param
static_cast<const cpp_non_type_template_parameter&>(p); = static_cast<const cpp_non_type_template_parameter&>(p);
if (param.name() == "A") if (param.name() == "A")
{ {
REQUIRE(alias.name() == "a"); REQUIRE(alias.name() == "a");
@ -227,8 +227,8 @@ using d = void;
REQUIRE(p.kind() REQUIRE(p.kind()
== cpp_entity_kind::template_template_parameter_t); == cpp_entity_kind::template_template_parameter_t);
auto& param = auto& param
static_cast<const cpp_template_template_parameter&>(p); = static_cast<const cpp_template_template_parameter&>(p);
REQUIRE(param.keyword() == cpp_template_keyword::keyword_class); REQUIRE(param.keyword() == cpp_template_keyword::keyword_class);
if (param.name() == "A") if (param.name() == "A")
{ {

View file

@ -134,8 +134,8 @@ bool equal_types(const cpp_entity_index& idx, const cpp_type& parsed, const cpp_
case cpp_type_kind::template_parameter_t: case cpp_type_kind::template_parameter_t:
{ {
auto& entity_parsed = static_cast<const cpp_template_parameter_type&>(parsed).entity(); auto& entity_parsed = static_cast<const cpp_template_parameter_type&>(parsed).entity();
auto& entity_synthesized = auto& entity_synthesized
static_cast<const cpp_template_parameter_type&>(synthesized).entity(); = static_cast<const cpp_template_parameter_type&>(synthesized).entity();
return equal_ref(idx, entity_parsed, entity_synthesized); return equal_ref(idx, entity_parsed, entity_synthesized);
} }
case cpp_type_kind::template_instantiation_t: case cpp_type_kind::template_instantiation_t:
@ -357,8 +357,8 @@ typedef decltype(0) w;
} }
else if (alias.name() == "d") else if (alias.name() == "d")
{ {
auto type = auto type
cpp_pointer_type::build(add_cv(cpp_builtin_type::build(cpp_uint), cpp_cv_const)); = cpp_pointer_type::build(add_cv(cpp_builtin_type::build(cpp_uint), cpp_cv_const));
REQUIRE(equal_types(idx, alias.underlying_type(), *type)); REQUIRE(equal_types(idx, alias.underlying_type(), *type));
} }
else if (alias.name() == "e") else if (alias.name() == "e")
@ -375,8 +375,8 @@ typedef decltype(0) w;
} }
else if (alias.name() == "g") else if (alias.name() == "g")
{ {
auto type = auto type
cpp_reference_type::build(add_cv(cpp_builtin_type::build(cpp_int), cpp_cv_const), = cpp_reference_type::build(add_cv(cpp_builtin_type::build(cpp_int), cpp_cv_const),
cpp_ref_rvalue); cpp_ref_rvalue);
REQUIRE(equal_types(idx, alias.underlying_type(), *type)); REQUIRE(equal_types(idx, alias.underlying_type(), *type));
} }
@ -399,21 +399,21 @@ typedef decltype(0) w;
} }
else if (alias.name() == "k") else if (alias.name() == "k")
{ {
auto type = auto type
cpp_array_type::build(cpp_builtin_type::build(cpp_int), make_size("42", true)); = cpp_array_type::build(cpp_builtin_type::build(cpp_int), make_size("42", true));
REQUIRE(equal_types(idx, alias.underlying_type(), *type)); REQUIRE(equal_types(idx, alias.underlying_type(), *type));
} }
else if (alias.name() == "l") else if (alias.name() == "l")
{ {
auto type = auto type
cpp_array_type::build(cpp_pointer_type::build(cpp_builtin_type::build(cpp_float)), = cpp_array_type::build(cpp_pointer_type::build(cpp_builtin_type::build(cpp_float)),
nullptr); nullptr);
REQUIRE(equal_types(idx, alias.underlying_type(), *type)); REQUIRE(equal_types(idx, alias.underlying_type(), *type));
} }
else if (alias.name() == "m") else if (alias.name() == "m")
{ {
auto type = auto type
cpp_array_type::build(cpp_builtin_type::build(cpp_char), make_size("42", true)); = cpp_array_type::build(cpp_builtin_type::build(cpp_char), make_size("42", true));
REQUIRE(equal_types(idx, alias.underlying_type(), *type)); REQUIRE(equal_types(idx, alias.underlying_type(), *type));
} }
else if (alias.name() == "n") else if (alias.name() == "n")
@ -474,10 +474,12 @@ typedef decltype(0) w;
} }
else if (alias.name() == "s") else if (alias.name() == "s")
{ {
auto pointee = cpp_member_object_type:: auto pointee
build(cpp_user_defined_type::build(cpp_type_ref(cpp_entity_id(""), "foo")), = cpp_member_object_type::build(cpp_user_defined_type::build(
cpp_type_ref(cpp_entity_id(""), "foo")),
cpp_unexposed_type::build( cpp_unexposed_type::build(
"int")); // type not exposed directly for some reason "int")); // type not exposed directly for some
// reason
auto type = cpp_pointer_type::build(std::move(pointee)); auto type = cpp_pointer_type::build(std::move(pointee));
REQUIRE(equal_types(idx, alias.underlying_type(), *type)); REQUIRE(equal_types(idx, alias.underlying_type(), *type));

View file

@ -16,53 +16,53 @@ TEST_CASE("stdlib", "[!hide][integration]")
//#include <cstdlib> -- problem with compiler built-in stuff on OSX //#include <cstdlib> -- problem with compiler built-in stuff on OSX
#include <csignal> #include <csignal>
//#include <csetjmp> -- same as above //#include <csetjmp> -- same as above
#include <cstdarg>
#include <typeinfo>
#include <typeindex>
#include <type_traits>
#include <bitset> #include <bitset>
#include <functional>
#include <utility>
#include <ctime>
#include <chrono> #include <chrono>
#include <cstdarg>
#include <cstddef> #include <cstddef>
#include <ctime>
#include <functional>
#include <initializer_list> #include <initializer_list>
#include <tuple> #include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <utility>
#include <new>
#include <memory> #include <memory>
#include <new>
#include <scoped_allocator> #include <scoped_allocator>
#include <climits>
#include <cfloat> #include <cfloat>
#include <climits>
#include <cstdint> #include <cstdint>
//#include <cinttypes> -- missing types from C header (for some reason) //#include <cinttypes> -- missing types from C header (for some reason)
#include <limits> #include <limits>
//#include <exception> -- weird issue with compiler built-in stuff //#include <exception> -- weird issue with compiler built-in stuff
#include <stdexcept>
#include <cassert> #include <cassert>
#include <system_error>
#include <cerrno> #include <cerrno>
#include <stdexcept>
#include <system_error>
#include <cctype> #include <cctype>
#include <cwctype>
#include <cstring> #include <cstring>
#include <cwchar> #include <cwchar>
#include <cwctype>
//#include <cuchar> -- not supported on CI //#include <cuchar> -- not supported on CI
#include <string> #include <string>
#include <array> #include <array>
#include <vector>
#include <deque> #include <deque>
#include <list>
#include <forward_list> #include <forward_list>
#include <set> #include <list>
#include <map> #include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue> #include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm> #include <algorithm>
@ -70,22 +70,22 @@ TEST_CASE("stdlib", "[!hide][integration]")
//#include <cmath> -- non-conforming GCC extension with regards to constexpr //#include <cmath> -- non-conforming GCC extension with regards to constexpr
//#include <complex> -- weird double include issue under MSVC //#include <complex> -- weird double include issue under MSVC
#include <valarray>
#include <random>
#include <numeric> #include <numeric>
#include <random>
#include <ratio> #include <ratio>
#include <valarray>
//#include <cfenv> -- same issue with cinttypes //#include <cfenv> -- same issue with cinttypes
#include <iosfwd> #include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios> #include <ios>
#include <iosfwd>
#include <iostream>
#include <istream> #include <istream>
#include <ostream> #include <ostream>
#include <iostream>
#include <fstream>
#include <sstream> #include <sstream>
#include <iomanip>
#include <streambuf> #include <streambuf>
#include <cstdio>
#include <locale> #include <locale>
//#include <clocale> -- issue on OSX //#include <clocale> -- issue on OSX
@ -94,10 +94,10 @@ TEST_CASE("stdlib", "[!hide][integration]")
//#include <atomic> -- issue on MSVC //#include <atomic> -- issue on MSVC
#include <thread>
#include <mutex>
#include <future>
#include <condition_variable> #include <condition_variable>
#include <future>
#include <mutex>
#include <thread>
)"; )";
write_file("stdlib.cpp", code); write_file("stdlib.cpp", code);

View file

@ -65,7 +65,8 @@ TEST_CASE("preprocessing use external macro")
auto result = NAN; auto result = NAN;
#endif #endif
)", fast_preprocessing); )",
fast_preprocessing);
test_visit<cpp_variable>(*file, [&](const cpp_variable&) {}); test_visit<cpp_variable>(*file, [&](const cpp_variable&) {});
} }
@ -302,7 +303,8 @@ void j();
{ {
if (comment.content == "cstddef\ncstddef") if (comment.content == "cstddef\ncstddef")
// happens if include parsing is not supported // happens if include parsing is not supported
// error is still going to be detected because if it is supported, the entity will be matched above // error is still going to be detected because if it is supported, the entity will be
// matched above
add = 1u; add = 1u;
else else
REQUIRE(comment.content == "u"); REQUIRE(comment.content == "u");

View file

@ -6,12 +6,12 @@
#include <cxxopts.hpp> #include <cxxopts.hpp>
#include <cppast/libclang_parser.hpp> // for libclang_parser, libclang_compile_config, cpp_entity,...
#include <cppast/visitor.hpp> // for visit()
#include <cppast/code_generator.hpp> // for generate_code() #include <cppast/code_generator.hpp> // for generate_code()
#include <cppast/cpp_entity_kind.hpp> // for the cpp_entity_kind definition #include <cppast/cpp_entity_kind.hpp> // for the cpp_entity_kind definition
#include <cppast/cpp_forward_declarable.hpp> // for is_definition() #include <cppast/cpp_forward_declarable.hpp> // for is_definition()
#include <cppast/cpp_namespace.hpp> // for cpp_namespace #include <cppast/cpp_namespace.hpp> // for cpp_namespace
#include <cppast/libclang_parser.hpp> // for libclang_parser, libclang_compile_config, cpp_entity,...
#include <cppast/visitor.hpp> // for visit()
// print help options // print help options
void print_help(const cxxopts::Options& options) void print_help(const cxxopts::Options& options)
@ -239,12 +239,12 @@ int main(int argc, char* argv[]) try
cppast::libclang_compilation_database database( cppast::libclang_compilation_database database(
options["database_dir"].as<std::string>()); options["database_dir"].as<std::string>());
if (options.count("database_file")) if (options.count("database_file"))
config = config
cppast::libclang_compile_config(database, = cppast::libclang_compile_config(database,
options["database_file"].as<std::string>()); options["database_file"].as<std::string>());
else else
config = config
cppast::libclang_compile_config(database, options["file"].as<std::string>()); = cppast::libclang_compile_config(database, options["file"].as<std::string>());
} }
if (options.count("verbose")) if (options.count("verbose"))