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
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: false
AlignEscapedNewlinesLeft: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
@ -16,28 +16,50 @@ AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: 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
ContinuationIndentWidth: 4
ColumnLimit: 100
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: true
Language: Cpp
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
NamespaceIndentation: Inner
PenaltyBreakBeforeFirstCallParameter: 19937
PenaltyReturnTypeOnItsOwnLine: 19937
PointerAlignment: Left
ReflowComments: false
SortIncludes: false
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false

View file

@ -5,7 +5,8 @@
/// \file
/// 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 <iostream>
@ -94,8 +95,8 @@ void generate_comparison(const cppast::cpp_file& file)
{
// it is a new class
auto& class_ = static_cast<const cppast::cpp_class&>(e);
auto& attribute =
cppast::has_attribute(e, "generate::comparison").value();
auto& attribute
= cppast::has_attribute(e, "generate::comparison").value();
// generate requested operators
if (attribute.arguments())

View file

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

View file

@ -5,7 +5,8 @@
/// \file
/// 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>
@ -43,8 +44,8 @@ void generate_to_string(const cppast::cpp_file& file)
<< ":\n";
// attribute can be used to override the string
if (auto attr =
cppast::has_attribute(enumerator, "generate::to_string"))
if (auto attr
= cppast::has_attribute(enumerator, "generate::to_string"))
std::cout << " return "
<< attr.value().arguments().value().as_string()
<< ";\n";

View file

@ -5,7 +5,8 @@
/// \file
/// 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>

View file

@ -7,8 +7,8 @@
#include <cstring>
#include <type_safe/index.hpp>
#include <type_safe/flag_set.hpp>
#include <type_safe/index.hpp>
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_ref.hpp>
@ -32,8 +32,7 @@ namespace cppast
/// \effects Creates it viewing the C string literal.
template <std::size_t Size>
constexpr string_view(const char (&str)[Size]) noexcept : str_(str), length_(Size - 1u)
{
}
{}
/// \returns The number of characters.
constexpr std::size_t length() const noexcept
@ -67,11 +66,9 @@ namespace cppast
{
public:
template <typename T>
explicit semantic_string_view(T&& obj,
decltype(string_view(std::forward<T>(obj)), 0) = 0)
explicit semantic_string_view(T&& obj, decltype(string_view(std::forward<T>(obj)), 0) = 0)
: str_(std::forward<T>(obj))
{
}
{}
const string_view& str() const noexcept
{
@ -194,7 +191,8 @@ namespace cppast
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
{
return !options_.is_set(exclude) && !options_.is_set(custom);
@ -236,7 +234,8 @@ namespace cppast
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
{
gen_->do_indent();
@ -374,7 +373,8 @@ namespace cppast
/// \effects Generates the code for the specified entity.
/// It can be used to generate additional entities while generating another one.
/// \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);
private:
@ -426,7 +426,8 @@ namespace cppast
virtual void do_indent() = 0;
/// \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;
/// \effects Writes the given token sequence.
@ -447,8 +448,7 @@ namespace cppast
do_write_token_seq(identifier);
}
/// \group write
virtual bool do_write_reference(type_safe::array_ref<const cpp_entity_id> id,
string_view name)
virtual bool do_write_reference(type_safe::array_ref<const cpp_entity_id> id, string_view name)
{
(void)id;
do_write_token_seq(name);

View file

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

View file

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

View file

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

View file

@ -34,9 +34,9 @@ namespace cppast
/// A C++ attribute, including `alignas` specifiers.
///
/// 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 arguments are as specified in the source code but do not include the outer-most `(` and `)`.
/// It can also be variadic or not.
/// The scope is just a single identifier and doesn't include the `::` and can be given explicitly
/// or via using. The arguments are as specified in the source code but do not include the
/// outer-most `(` and `)`. It can also be variadic or not.
///
/// An attribute can be known or unknown.
/// 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.
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,
type_safe::optional<cpp_token_string> arguments, bool is_variadic)
: scope_(std::move(scope)),
arguments_(std::move(arguments)),
name_(std::move(name)),
: scope_(std::move(scope)), arguments_(std::move(arguments)), name_(std::move(name)),
variadic_(is_variadic)
{
}
{}
/// \returns The kind of attribute, if it is known.
const cpp_attribute_kind& kind() const noexcept

View file

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

View file

@ -32,8 +32,7 @@ namespace cppast
private:
cpp_class_template(std::unique_ptr<cpp_class> func)
: cpp_template(std::unique_ptr<cpp_entity>(func.release()))
{
}
{}
cpp_entity_kind do_get_entity_kind() const noexcept override;
@ -62,8 +61,7 @@ namespace cppast
private:
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_entity_kind do_get_entity_kind() const noexcept override;

View file

@ -10,9 +10,9 @@
#include <type_safe/optional_ref.hpp>
#include <cppast/detail/intrusive_list.hpp>
#include <cppast/cpp_attribute.hpp>
#include <cppast/cpp_token.hpp>
#include <cppast/detail/intrusive_list.hpp>
namespace cppast
{
@ -41,10 +41,9 @@ namespace cppast
return templ_.has_value();
}
/// \returns An iteratable object iterating over the [cppast::cpp_template_parameter]() entities of the scope.
/// \requires The scope is templated.
detail::iteratable_intrusive_list<cpp_template_parameter> template_parameters() const
noexcept;
/// \returns An iteratable object iterating over the [cppast::cpp_template_parameter]() entities
/// of the scope. \requires The scope is templated.
detail::iteratable_intrusive_list<cpp_template_parameter> template_parameters() const noexcept;
private:
type_safe::object_ref<const cpp_entity> entity_;
@ -89,12 +88,11 @@ namespace cppast
/// \returns The documentation comment associated with that entity, if any.
/// \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. `/**`.
/// One space after the leading sequence will be skipped.
/// It ends either with `*/` or `**/`.
/// After a newline all whitespace is skipped, as well as an optional `*` followed by another optional space,
/// as well as trailing whitespace on each line.
/// 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 `*`, i.e.
/// `/**`. One space after the leading sequence will be skipped. It ends either with `*/` or
/// `**/`. After a newline all whitespace is skipped, as well as an optional `*` followed by
/// another optional space, as well as trailing whitespace on each line. 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 '!`,
/// i.e. `///` or `//!`.
/// 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.
/// 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
{
user_data_ = data;
@ -216,8 +215,7 @@ namespace cppast
private:
cpp_unexposed_entity(std::string name, cpp_token_string spelling)
: cpp_entity(std::move(name)), spelling_(std::move(spelling))
{
}
{}
cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -32,8 +32,7 @@ namespace cppast
private:
cpp_function_template(std::unique_ptr<cpp_function_base> func)
: cpp_template(std::unique_ptr<cpp_entity>(func.release()))
{
}
{}
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_template_ref primary)
: cpp_template_specialization(std::unique_ptr<cpp_entity>(func.release()), primary)
{
}
{}
cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

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

View file

@ -22,9 +22,7 @@ namespace cppast
{
public:
/// \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.
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.
inline bool is_overriding(const cpp_virtual& virt) noexcept
{
return static_cast<bool>(virt.value_or(cpp_virtual_flags::pure)
& cpp_virtual_flags::override);
return static_cast<bool>(virt.value_or(cpp_virtual_flags::pure) & cpp_virtual_flags::override);
}
/// \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.
cpp_member_function_base(std::string name, std::unique_ptr<cpp_type> return_type)
: cpp_function_base(std::move(name)),
return_type_(std::move(return_type)),
cv_(cpp_cv_none),
ref_(cpp_ref_none),
constexpr_(false)
{
}
: cpp_function_base(std::move(name)), return_type_(std::move(return_type)), cv_(cpp_cv_none),
ref_(cpp_ref_none), constexpr_(false)
{}
protected:
std::string do_get_signature() const override;
@ -212,8 +207,7 @@ namespace cppast
private:
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_entity_kind do_get_entity_kind() const noexcept override;
@ -262,8 +256,7 @@ namespace cppast
private:
cpp_constructor(std::string name)
: cpp_function_base(std::move(name)), explicit_(false), constexpr_(false)
{
}
{}
cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

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

View file

@ -19,7 +19,8 @@ namespace cppast
static cpp_entity_kind kind() noexcept;
/// \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)
{
return std::unique_ptr<cpp_macro_parameter>(new cpp_macro_parameter(std::move(name)));
@ -53,8 +54,7 @@ namespace cppast
{
public:
/// \effects Sets the name of the function like macro.
function_like_builder(std::string name)
: result_(new cpp_macro_definition(std::move(name)))
function_like_builder(std::string name) : result_(new cpp_macro_definition(std::move(name)))
{
result_->kind_ = function_like;
}
@ -189,11 +189,8 @@ namespace cppast
private:
cpp_entity_kind do_get_entity_kind() const noexcept override;
cpp_include_directive(const cpp_file_ref& target, cpp_include_kind kind,
std::string full_path)
: cpp_entity(target.name()),
target_(target.id()[0u]),
kind_(kind),
cpp_include_directive(const cpp_file_ref& target, cpp_include_kind kind, std::string full_path)
: cpp_entity(target.name()), target_(target.id()[0u]), kind_(kind),
full_path_(std::move(full_path))
{
DEBUG_ASSERT(!target.is_overloaded(), detail::precondition_error_handler{});

View file

@ -39,8 +39,7 @@ namespace cppast
private:
cpp_static_assert(std::unique_ptr<cpp_expression> expr, std::string msg)
: cpp_entity(""), expr_(std::move(expr)), msg_(std::move(msg))
{
}
{}
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_static =
2, //< *static* or *thread* storage duration and *internal* linkage.
cpp_storage_class_extern =
4, //< *static* or *thread* storage duration and *external* linkage.
cpp_storage_class_static = 2, //< *static* or *thread* storage duration and *internal* linkage.
cpp_storage_class_extern = 4, //< *static* or *thread* storage duration and *external* linkage.
cpp_storage_class_thread_local = 8, //< *thread* storage duration.
/// \notes This is the only one that can be combined with the others.

View file

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

View file

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

View file

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

View file

@ -8,9 +8,9 @@
#include <atomic>
#include <memory>
#include <cppast/detail/intrusive_list.hpp>
#include <cppast/cpp_entity_ref.hpp>
#include <cppast/code_generator.hpp>
#include <cppast/cpp_entity_ref.hpp>
#include <cppast/detail/intrusive_list.hpp>
namespace cppast
{
@ -67,7 +67,8 @@ namespace cppast
/// User data is just some kind of pointer, there are no requirements.
/// 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
{
user_data_ = data;
@ -205,11 +206,11 @@ namespace cppast
/// \returns A newly created user-defined type.
static std::unique_ptr<cpp_user_defined_type> build(cpp_type_ref entity)
{
return std::unique_ptr<cpp_user_defined_type>(
new cpp_user_defined_type(std::move(entity)));
return std::unique_ptr<cpp_user_defined_type>(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
{
return entity_;
@ -268,7 +269,8 @@ namespace cppast
}
/// \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
{
return *dependee_;
@ -277,8 +279,7 @@ namespace cppast
private:
cpp_dependent_type(std::string name, std::unique_ptr<cpp_type> dependee)
: name_(std::move(name)), dependee_(std::move(dependee))
{
}
{}
cpp_type_kind do_get_kind() const noexcept override
{
@ -316,8 +317,7 @@ namespace cppast
public:
/// \returns A newly created qualified type.
/// \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,
cpp_cv cv)
static std::unique_ptr<cpp_cv_qualified_type> build(std::unique_ptr<cpp_type> type, cpp_cv cv)
{
DEBUG_ASSERT(cv != cpp_cv_none, detail::precondition_error_handler{});
return std::unique_ptr<cpp_cv_qualified_type>(
@ -339,8 +339,7 @@ namespace cppast
private:
cpp_cv_qualified_type(std::unique_ptr<cpp_type> type, cpp_cv cv)
: type_(std::move(type)), cv_(cv)
{
}
{}
cpp_type_kind do_get_kind() const noexcept override
{
@ -405,8 +404,7 @@ namespace cppast
cpp_reference ref)
{
DEBUG_ASSERT(ref != cpp_ref_none, detail::precondition_error_handler{});
return std::unique_ptr<cpp_reference_type>(
new cpp_reference_type(std::move(type), ref));
return std::unique_ptr<cpp_reference_type>(new cpp_reference_type(std::move(type), ref));
}
/// \returns A reference to the [cppast::cpp_type]() that is referenced.
@ -424,8 +422,7 @@ namespace cppast
private:
cpp_reference_type(std::unique_ptr<cpp_type> referee, cpp_reference ref)
: referee_(std::move(referee)), ref_(ref)
{
}
{}
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.
static std::unique_ptr<cpp_type_alias> build(const cpp_entity_index& idx, cpp_entity_id id,
std::string name,
std::unique_ptr<cpp_type> type);
std::string name, std::unique_ptr<cpp_type> type);
/// \returns A newly created type alias that isn't registered.
/// \notes This function is intendend for templated type aliases.
static std::unique_ptr<cpp_type_alias> build(std::string name,
std::unique_ptr<cpp_type> type);
static std::unique_ptr<cpp_type_alias> build(std::string name, std::unique_ptr<cpp_type> type);
/// \returns A reference to the aliased [cppast::cpp_type]().
const cpp_type& underlying_type() const noexcept
@ -36,8 +34,7 @@ namespace cppast
private:
cpp_type_alias(std::string name, std::unique_ptr<cpp_type> type)
: cpp_entity(std::move(name)), type_(std::move(type))
{
}
{}
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,
std::unique_ptr<cpp_expression> def, cpp_storage_class_specifiers spec,
bool is_constexpr)
: cpp_entity(std::move(name)),
cpp_variable_base(std::move(type), std::move(def)),
storage_(spec),
is_constexpr_(is_constexpr)
{
}
: cpp_entity(std::move(name)), cpp_variable_base(std::move(type), std::move(def)),
storage_(spec), is_constexpr_(is_constexpr)
{}
cpp_entity_kind do_get_entity_kind() const noexcept override;

View file

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

View file

@ -32,8 +32,7 @@ namespace cppast
private:
cpp_variable_template(std::unique_ptr<cpp_variable> variable)
: cpp_template(std::unique_ptr<cpp_entity>(variable.release()))
{
}
{}
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>,
debug_assert::default_handler
{
};
{};
struct precondition_error_handler : debug_assert::set_level<CPPAST_PRECONDITION_LEVEL>,
debug_assert::default_handler
{
};
}
} // namespace cppast::detail
{};
} // namespace detail
} // namespace cppast
#endif // CPPAST_ASSERT_HPP_INCLUDED

View file

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

View file

@ -90,7 +90,8 @@ namespace cppast
warning, //< A warning that doesn't impact AST generation.
error, //< A non-critical error that does impact AST generation but not critically.
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.

View file

@ -26,7 +26,8 @@ namespace cppast
/// \effects Logs the diagnostic by invoking the `do_log()` member function.
/// \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;
/// \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,
/// 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();
/// 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,
/// if you want to parse one.
/// \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.
libclang_compile_config(const libclang_compilation_database& database,
const std::string& file);
/// \notes The file key will include the specified directory in the JSON, if it is not a full
/// path.
libclang_compile_config(const libclang_compilation_database& database, const std::string& file);
libclang_compile_config(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.
/// \notes It will be used for preprocessing.
/// \effects Sets the path to the location of the `clang++` binary and the version of that
/// binary. \notes It will be used for preprocessing.
void set_clang_binary(std::string binary, int major, int minor, int patch)
{
clang_binary_ = std::move(binary);
@ -134,13 +135,12 @@ namespace cppast
/// \effects Sets whether or not the fast preprocessor is enabled.
/// Default value is `false`.
/// \notes The fast preprocessor gets a list of all macros that are defined in the translation unit,
/// then preprocesses it without resolving includes but manually defining the list of macros to ensure correctness.
/// Later stages will use the includes again.
/// This hack breaks if you define the same macro multiple times in the file being parsed (headers don't matter)
/// or you rely on the order of macro directives.
/// \notes If this option is `true`, the full file name of include directives is not available,
/// just the name as written in the source code.
/// \notes The fast preprocessor gets a list of all macros that are defined in the translation
/// unit, then preprocesses it without resolving includes but manually defining the list of
/// macros to ensure correctness. Later stages will use the includes again. This hack breaks if
/// you define the same macro multiple times in the file being parsed (headers don't matter) or
/// you rely on the order of macro directives. \notes If this option is `true`, the full file
/// name of include directives is not available, just the name as written in the source code.
void fast_preprocessing(bool b) noexcept
{
fast_preprocessing_ = b;
@ -180,10 +180,11 @@ namespace cppast
/// Finds a configuration for a given file.
///
/// \returns If the database contains a configuration for the given file, returns that configuration.
/// Otherwise removes the file extension of the file and tries the same procedure
/// for common C++ header and source file extensions.
/// \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/).
/// \returns If the database contains a configuration for the given file, returns that
/// configuration. Otherwise removes the file extension of the file and tries the same procedure for
/// common C++ header and source file extensions. \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/).
type_safe::optional<libclang_compile_config> find_config_for(
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.
///
/// \effects Invokes [cppast::parse_files](standardese://parse_files_basic/) passing it the parser and file names,
/// and a `get_config` function using [cppast::find_config_for]().
/// \effects Invokes [cppast::parse_files](standardese://parse_files_basic/) passing it the parser
/// 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.
/// 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,
/// 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/).
/// It must also use the libclang parser,
/// \requires `FileParser` must have the same requirements as for
/// [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]().
template <class FileParser>
void parse_database(FileParser& parser, const libclang_compilation_database& database)

View file

@ -10,8 +10,8 @@
#include <cppast/compile_config.hpp>
#include <cppast/cpp_file.hpp>
#include <cppast/cpp_preprocessor.hpp>
#include <cppast/diagnostic_logger.hpp>
#include <cppast/diagnostic.hpp>
#include <cppast/diagnostic_logger.hpp>
namespace cppast
{
@ -22,7 +22,8 @@ namespace cppast
/// It reads a C++ source file and creates the matching [cppast::cpp_file]().
/// 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
{
public:
@ -33,9 +34,9 @@ namespace cppast
/// \effects Parses the given file.
/// \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.
/// \requires The dynamic type of `config` must match the required config type.
/// \notes This function is thread safe.
/// It can be `nullptr`, if there was an error or the specified file already registered in the
/// index. \requires The dynamic type of `config` must match the required config type. \notes
/// This function is thread safe.
std::unique_ptr<cpp_file> parse(const cpp_entity_index& idx, std::string path,
const compile_config& config) const
{
@ -65,11 +66,11 @@ namespace cppast
/// \effects Creates it giving it a reference to the logger it uses.
explicit parser(type_safe::object_ref<const diagnostic_logger> logger)
: logger_(logger), error_(false)
{
}
{}
/// \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
{
error_ = true;
@ -102,19 +103,16 @@ namespace cppast
/// \effects Creates a file parser populating the given index
/// and using the parser created by forwarding the given arguments.
template <typename... Args>
explicit simple_file_parser(type_safe::object_ref<const cpp_entity_index> idx,
Args&&... args)
explicit simple_file_parser(type_safe::object_ref<const cpp_entity_index> idx, Args&&... args)
: parser_(std::forward<Args>(args)...), idx_(idx)
{
}
{}
/// \effects Parses the given file using the given configuration.
/// \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)
{
parser_.logger().log("simple file parser",
diagnostic{"parsing file '" + path + "'", source_location(),
severity::info});
parser_.logger().log("simple file parser", diagnostic{"parsing file '" + path + "'",
source_location(), severity::info});
auto file = parser_.parse(*idx_, std::move(path), c);
auto ptr = file.get();
if (file)
@ -156,25 +154,20 @@ namespace cppast
namespace detail
{
struct std_begin
{
};
{};
struct adl_begin : std_begin
{
};
{};
struct member_begin : adl_begin
{
};
{};
template <class Range>
auto get_value_type_impl(member_begin, Range&& r)
-> decltype(std::forward<Range>(r).begin());
auto get_value_type_impl(member_begin, Range&& r) -> decltype(std::forward<Range>(r).begin());
template <class Range>
auto get_value_type_impl(adl_begin, Range&& r) -> decltype(begin(std::forward<Range>(r)));
template <class Range>
auto get_value_type_impl(std_begin, Range&& r)
-> decltype(std::begin(std::forward<Range>(r)));
auto get_value_type_impl(std_begin, Range&& r) -> decltype(std::begin(std::forward<Range>(r)));
template <class 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.
/// * `config` - The same as `parser::config`.
/// * `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.
/// \requires `Range` must be some type that can be iterated in a range-based for loop.
/// \requires `Configuration` must be a function that returns a configuration of type `FileParser::config` when given a path.
/// \unique_name parse_files_basic
/// \synopsis_return void
/// The parsing can be executed in a separated thread, but then a copy of the configuration and path
/// must be created. \requires `Range` must be some type that can be iterated in a range-based for
/// loop. \requires `Configuration` must be a function that returns a configuration of type
/// `FileParser::config` when given a path. \unique_name parse_files_basic \synopsis_return void
template <class FileParser, class Range, class Configuration>
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(
std::declval<detail::value_type<Range>>()))>::type,
typename std::enable_if<std::is_same<
typename std::decay<decltype(get_config(std::declval<detail::value_type<Range>>()))>::type,
typename FileParser::config>::value>::type
{
for (auto&& file : std::forward<Range>(file_names))
{
auto&& config = get_config(file);
parser.parse(std::forward<decltype(file)>(file),
std::forward<decltype(config)>(config));
parser.parse(std::forward<decltype(file)>(file), std::forward<decltype(config)>(config));
}
}
/// 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,
/// and a function that returns the same configuration for each file.
/// \effects Invokes [cppast::parse_files](standardese://parse_files_basic/) passing it the parser
/// and file names, and a function that returns the same configuration for each file.
template <class FileParser, class Range>
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,
/// 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,
};
@ -72,16 +73,14 @@ namespace cppast
using visitor_callback_t = bool (*)(void* mem, const cpp_entity&, visitor_info info);
struct visitor_info_void
{
};
{};
struct visitor_info_bool : visitor_info_void
{
};
{};
template <typename Func>
visitor_callback_t get_visitor_callback(
visitor_info_bool, decltype(std::declval<Func>()(std::declval<const cpp_entity&>(),
visitor_info{})) = true)
visitor_info_bool,
decltype(std::declval<Func>()(std::declval<const cpp_entity&>(), visitor_info{})) = true)
{
return [](void* mem, const cpp_entity& e, visitor_info info) {
auto& func = *static_cast<Func*>(mem);
@ -92,8 +91,7 @@ namespace cppast
template <typename Func>
visitor_callback_t get_visitor_callback(
visitor_info_void,
decltype(std::declval<Func>()(std::declval<const cpp_entity&>(), visitor_info{}),
0) = 0)
decltype(std::declval<Func>()(std::declval<const cpp_entity&>(), visitor_info{}), 0) = 0)
{
return [](void* mem, const cpp_entity& e, visitor_info info) {
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,
/// 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.
/// 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.
exclude = false, //< The entity is excluded and will not be visited.
exclude_and_children =
2, //< The entity and all direct children are excluded and will not be visited.
exclude_and_children
= 2, //< The entity and all direct children are excluded and will not be visited.
};
namespace detail
@ -140,8 +139,7 @@ namespace cppast
using visitor_filter_t = visit_filter (*)(const cpp_entity&);
template <typename Filter>
auto invoke_visit_filter(int, Filter f, const cpp_entity& e,
cpp_access_specifier_kind access)
auto invoke_visit_filter(int, Filter f, const cpp_entity& e, cpp_access_specifier_kind access)
-> decltype(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.
///
/// \effects It behaves like the non-filtered visit except it will only invoke the visitor for entities that match the filter.
/// 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]().
/// Visit will behave accordingly.
/// \effects It behaves like the non-filtered visit except it will only invoke the visitor for
/// entities that match the filter. 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](). Visit
/// will behave accordingly.
///
/// \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.
/// It must return a `bool` or a [cppast::visit_filter]().
/// The filter must be a function taking a [cppast::cpp_entity]() as first parameter and optionally
/// a [cppast::cpp_access_specifier_kind]() as second. It must return a `bool` or a
/// [cppast::visit_filter]().
template <typename Func, typename Filter>
void visit(const cpp_entity& e, Filter filter, Func f)
{
@ -210,20 +210,20 @@ namespace cppast
detail::visitor_filter_t blacklist()
{
return [](const cpp_entity& e) {
return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::exclude :
visit_filter::include;
return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::exclude : visit_filter::include;
};
}
/// 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>
detail::visitor_filter_t blacklist_and_children()
{
return [](const cpp_entity& e) {
return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::exclude_and_children :
visit_filter::include;
return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::exclude_and_children
: visit_filter::include;
};
}
@ -234,8 +234,7 @@ namespace cppast
detail::visitor_filter_t whitelist()
{
return [](const cpp_entity& e) {
return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::include :
visit_filter::exclude;
return detail::has_one_of_kind<Kinds...>(e) ? visit_filter::include : visit_filter::exclude;
};
}
} // namespace cppast

View file

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

View file

@ -37,7 +37,7 @@ namespace
return "<error>";
}
}
} // namespace
cpp_attribute::cpp_attribute(cpp_attribute_kind kind,
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(
const cpp_attribute_list& attributes, const std::string& name)
{
auto iter =
std::find_if(attributes.begin(), attributes.end(), [&](const cpp_attribute& attribute) {
auto iter
= std::find_if(attributes.begin(), attributes.end(), [&](const cpp_attribute& attribute) {
if (attribute.scope())
return attribute.scope().value() + "::" + attribute.name() == name;
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(
const cpp_attribute_list& attributes, cpp_attribute_kind kind)
{
auto iter =
std::find_if(attributes.begin(), attributes.end(),
auto iter
= std::find_if(attributes.begin(), attributes.end(),
[&](const cpp_attribute& attribute) { return attribute.kind() == kind; });
if (iter == attributes.end())

View file

@ -4,10 +4,10 @@
#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_class_template.hpp>
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_kind.hpp>
using namespace cppast;
@ -112,8 +112,7 @@ namespace
}
else if (type.kind() == cpp_type_kind::template_instantiation_t)
{
auto& ref =
static_cast<const cpp_template_instantiation_type&>(type).primary_template();
auto& ref = static_cast<const cpp_template_instantiation_type&>(type).primary_template();
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()));
}
}
}
} // namespace
type_safe::optional_ref<const cpp_class> cppast::get_class(const cpp_entity_index& index,
const cpp_base_class& base)

View file

@ -4,17 +4,16 @@
#include <cppast/cpp_entity_index.hpp>
#include <cppast/detail/assert.hpp>
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_file.hpp>
#include <cppast/detail/assert.hpp>
using namespace cppast;
cpp_entity_index::duplicate_definition_error::duplicate_definition_error()
: std::logic_error("duplicate registration of entity definition")
{
}
{}
void cpp_entity_index::register_definition(cpp_entity_id id,
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::unique_ptr<cpp_expression> value)
{
auto result =
std::unique_ptr<cpp_enum_value>(new cpp_enum_value(std::move(name), std::move(value)));
auto result
= 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));
return result;
}

View file

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

View file

@ -2,8 +2,8 @@
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#include <cppast/cpp_class.hpp>
#include <clang-c/Index.h>
#include <cppast/cpp_class.hpp>
#include "libclang_visitor.hpp"
#include "parse_functions.hpp"
@ -108,7 +108,7 @@ namespace
auto& base = builder.base_class(std::move(name), std::move(type), access, is_virtual);
base.add_attribute(attributes);
}
}
} // namespace
std::unique_ptr<cpp_entity> detail::parse_cpp_class(const detail::parse_context& context,
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();
}
if (!scope.empty())
semantic_parent =
cpp_entity_ref(detail::get_entity_id(clang_getCursorSemanticParent(cur)),
semantic_parent
= cpp_entity_ref(detail::get_entity_id(clang_getCursorSemanticParent(cur)),
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);
else if (kind == CXCursor_CXXFinalAttr)
builder.is_final();
else if (
kind == CXCursor_TemplateTypeParameter || kind == CXCursor_NonTypeTemplateParameter
else if (kind == CXCursor_TemplateTypeParameter
|| kind == CXCursor_NonTypeTemplateParameter
|| kind == CXCursor_TemplateTemplateParameter || kind == CXCursor_ParmDecl
|| clang_isExpression(kind) || clang_isReference(kind)
|| kind
== CXCursor_UnexposedAttr) // I have no idea what this is, but happens on Windows
|| kind == CXCursor_UnexposedAttr) // I have no idea what this is, but happens
// on Windows
// other children due to templates and stuff
return;
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))
return is_templated ?
builder.finish(std::move(semantic_parent)) :
builder.finish(*context.idx, get_entity_id(cur), std::move(semantic_parent));
return is_templated
? builder.finish(std::move(semantic_parent))
: builder.finish(*context.idx, get_entity_id(cur), std::move(semantic_parent));
else
return is_templated ? builder.finish_declaration(detail::get_entity_id(cur)) :
builder.finish_declaration(*context.idx, get_entity_id(cur));
return is_templated ? builder.finish_declaration(detail::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)
: value_(clang_getTokenSpelling(tu_unit, token)), kind_(clang_getTokenKind(token))
{
}
{}
namespace
{
@ -69,15 +68,15 @@ namespace
unsigned no_;
};
bool token_after_is(const CXTranslationUnit& tu, const CXFile& file,
const CXSourceLocation& loc, const char* token_str, int inc)
bool token_after_is(const CXTranslationUnit& tu, const CXFile& file, const CXSourceLocation& loc,
const char* token_str, int inc)
{
auto loc_after = get_next_location(tu, file, loc, inc);
if (!clang_Location_isFromMainFile(loc_after))
return false;
simple_tokenizer tokenizer(tu, inc > 0 ? clang_getRange(loc, loc_after) :
clang_getRange(loc_after, loc));
simple_tokenizer tokenizer(tu, inc > 0 ? clang_getRange(loc, loc_after)
: clang_getRange(loc_after, loc));
if (tokenizer.size() == 0u)
return false;
@ -103,8 +102,7 @@ namespace
|| kind == CXCursor_VarDecl || kind == CXCursor_FieldDecl || kind == CXCursor_ParmDecl
|| kind == CXCursor_NonTypeTemplateParameter)
{
if (token_after_is(tu, file, begin, "]", -2)
&& token_after_is(tu, file, begin, "]", -3))
if (token_after_is(tu, file, begin, "]", -2) && token_after_is(tu, file, begin, "]", -3))
{
while (!token_after_is(tu, file, begin, "[", -1)
&& !token_after_is(tu, file, begin, "[", -2))
@ -112,8 +110,8 @@ namespace
begin = get_next_location(tu, file, begin, -3);
DEBUG_ASSERT(token_after_is(tu, file, begin, "[", 0)
&& token_after_is(tu, file, get_next_location(tu, file, begin),
"[", 0),
&& token_after_is(tu, file, get_next_location(tu, file, begin), "[",
0),
detail::parse_error_handler{}, cur,
"error in pre-function attribute parsing");
}
@ -207,8 +205,7 @@ namespace
end = next;
#endif
}
else if (kind == CXCursor_TemplateTemplateParameter
&& token_after_is(tu, file, end, "<", 0))
else if (kind == CXCursor_TemplateTemplateParameter && token_after_is(tu, file, end, "<", 0))
{
// if you have a template template parameter in a template template parameter,
// the tokens are all messed up, only contain the `template`
@ -228,14 +225,12 @@ namespace
// second: skip until end of parameter
// no need to handle default, so look for '>' or ','
while (!token_after_is(tu, file, next, ">", 0)
&& !token_after_is(tu, file, next, ",", 0))
while (!token_after_is(tu, file, next, ">", 0) && !token_after_is(tu, file, next, ",", 0))
next = get_next_location(tu, file, next);
// now we found the proper end of the token
end = get_next_location(tu, file, next, -1);
}
else if ((kind == CXCursor_TemplateTypeParameter
|| kind == CXCursor_NonTypeTemplateParameter
else if ((kind == CXCursor_TemplateTypeParameter || kind == CXCursor_NonTypeTemplateParameter
|| kind == CXCursor_TemplateTemplateParameter)
&& token_after_is(tu, file, end, "...", 0))
{
@ -246,16 +241,13 @@ namespace
// this should all go away once I redid the whole token thing...
end = get_next_location(tu, file, end, 1);
DEBUG_ASSERT(token_after_is(tu, file, end, ">", 0)
|| token_after_is(tu, file, end, ",", 0),
DEBUG_ASSERT(token_after_is(tu, file, end, ">", 0) || token_after_is(tu, file, end, ",", 0),
detail::parse_error_handler{}, cur,
"unexpected token in variadic parameter workaround");
}
else if ((kind == CXCursor_TemplateTypeParameter
|| kind == CXCursor_NonTypeTemplateParameter
else if ((kind == CXCursor_TemplateTypeParameter || kind == CXCursor_NonTypeTemplateParameter
|| 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),
detail::parse_error_handler{}, cur,
@ -513,8 +505,7 @@ namespace
if (!scope && kind != cpp_attribute_kind::unknown)
return cpp_attribute(kind, std::move(arguments));
else
return cpp_attribute(std::move(scope), std::move(name), std::move(arguments),
is_variadic);
return cpp_attribute(std::move(scope), std::move(name), std::move(arguments), is_variadic);
}
bool parse_attribute_impl(cpp_attribute_list& result, detail::cxtoken_stream& stream)

View file

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

View file

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

View file

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

View file

@ -4,11 +4,11 @@
#include <cppast/cpp_friend.hpp>
#include <cppast/cpp_template_parameter.hpp>
#include <cppast/cpp_template.hpp>
#include <cppast/cpp_template_parameter.hpp>
#include "parse_functions.hpp"
#include "libclang_visitor.hpp"
#include "parse_functions.hpp"
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,
// as then the class name would be wrong
auto name = detail::get_cursor_name(referenced);
type =
cpp_user_defined_type::build(cpp_type_ref(detail::get_entity_id(referenced),
type = cpp_user_defined_type::build(
cpp_type_ref(detail::get_entity_id(referenced),
namespace_str + "::" + name.c_str()));
}
else

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -109,8 +109,7 @@ namespace
// parses missing header file diagnostic and returns the file name,
// if it is a missing header file diagnostic
ts::optional<std::string> parse_missing_file(const std::string& cur_file,
const std::string& msg)
ts::optional<std::string> parse_missing_file(const std::string& cur_file, const std::string& msg)
{
auto ptr = msg.c_str();
@ -174,8 +173,8 @@ namespace
auto flags = std::string("-x c++ -I. -E -dM");
flags += diagnostics_flags();
std::string cmd(detail::libclang_compile_config_access::clang_binary(c) + " "
+ std::move(flags) + " ");
std::string cmd(detail::libclang_compile_config_access::clang_binary(c) + " " + std::move(flags)
+ " ");
// other flags
for (auto& flag : detail::libclang_compile_config_access::flags(c))
{
@ -220,8 +219,8 @@ namespace
flags += macro_file_path;
}
std::string cmd(detail::libclang_compile_config_access::clang_binary(c) + " "
+ std::move(flags) + " ");
std::string cmd(detail::libclang_compile_config_access::clang_binary(c) + " " + std::move(flags)
+ " ");
// other flags
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,
const diagnostic_logger& logger,
const std::string& full_path,
const char* macro_path)
const std::string& full_path, const char* macro_path)
{
clang_preprocess_result result;
@ -452,19 +450,17 @@ namespace
auto exit_code = process.get_exit_status();
DEBUG_ASSERT(diagnostic.empty(), detail::assert_handler{});
if (exit_code != 0 && !expect_bad_exit_code)
throw libclang_error("preprocessor: command '" + cmd
+ "' exited with non-zero exit code (" + std::to_string(exit_code)
+ ")");
throw libclang_error("preprocessor: command '" + cmd + "' exited with non-zero exit code ("
+ std::to_string(exit_code) + ")");
return result;
}
clang_preprocess_result clang_preprocess(const libclang_compile_config& c,
const char* full_path, const diagnostic_logger& logger)
clang_preprocess_result clang_preprocess(const libclang_compile_config& c, const char* full_path,
const diagnostic_logger& logger)
{
if (!std::ifstream(full_path))
throw libclang_error("preprocessor: file '" + std::string(full_path)
+ "' doesn't exist");
throw libclang_error("preprocessor: file '" + std::string(full_path) + "' doesn't exist");
// 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
@ -505,8 +501,7 @@ namespace
public:
position(ts::object_ref<std::string> result, const char* ptr) noexcept
: result_(result), cur_line_(1u), cur_column_(0u), ptr_(ptr), write_(true)
{
}
{}
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 result;
result.kind =
end_of_line ? detail::pp_doc_comment::end_of_line : detail::pp_doc_comment::cpp;
result.kind = end_of_line ? detail::pp_doc_comment::end_of_line : detail::pp_doc_comment::cpp;
if (starts_with(p, " "))
// skip one whitespace at most
p.skip();
@ -861,8 +855,7 @@ namespace
return builder.finish();
}
std::unique_ptr<cpp_macro_definition> parse_macro(position& p,
detail::preprocessor_output& output)
std::unique_ptr<cpp_macro_definition> parse_macro(position& p, detail::preprocessor_output& output)
{
// format (at new line): #define <name> [replacement]
// or: #define <name>(<args>) [replacement]
@ -919,7 +912,8 @@ namespace
ts::optional<std::string> parse_undef(position& p)
{
// 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"))
return ts::nullopt;
p.bump(std::strlen("#undef"));
@ -973,8 +967,7 @@ namespace
if (!p.write_enabled())
return type_safe::nullopt;
if (filename.size() > 2u && filename[0] == '.'
&& (filename[1] == '/' || filename[1] == '\\'))
if (filename.size() > 2u && filename[0] == '.' && (filename[1] == '/' || filename[1] == '\\'))
filename = filename.substr(2);
return detail::pp_include{std::move(filename), "", include_kind, p.cur_line()};
@ -1002,7 +995,8 @@ namespace
line_directive, // no change in file
enter_new, // open a new file
enter_old, // return to an old file
} flag = line_directive;
} flag
= line_directive;
bool is_system = false;
};
@ -1016,8 +1010,7 @@ namespace
if (!p.was_newl() || !starts_with(p, "#"))
return ts::nullopt;
p.skip();
DEBUG_ASSERT(!starts_with(p, "define") && !starts_with(p, "undef")
&& !starts_with(p, "pragma"),
DEBUG_ASSERT(!starts_with(p, "define") && !starts_with(p, "undef") && !starts_with(p, "pragma"),
detail::assert_handler{}, "handle macros first");
linemarker result;
@ -1174,12 +1167,14 @@ detail::preprocessor_output detail::preprocess(const libclang_compile_config& co
}
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 last_dir = full_path.find_last_of("/\\");
auto file_name =
last_dir == std::string::npos ? full_path : full_path.substr(last_dir + 1u);
auto file_name = last_dir == std::string::npos
? full_path
: full_path.substr(last_dir + 1u);
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 iter = indirect_includes.find(last_sep == std::string::npos ?
include.file_name :
include.file_name.substr(last_sep + 1u));
auto iter = indirect_includes.find(last_sep == std::string::npos
? include.file_name
: include.file_name.substr(last_sep + 1u));
if (iter != indirect_includes.end())
include.full_path = iter->second;
else

View file

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

View file

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

View file

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

View file

@ -236,8 +236,8 @@ namespace
return cpp_ref_none;
}
std::unique_ptr<cpp_type> parse_type_impl(const detail::parse_context& context,
const CXCursor& cur, const CXType& type);
std::unique_ptr<cpp_type> parse_type_impl(const detail::parse_context& context, 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;
}
return size_expr.empty() ?
nullptr :
cpp_unexposed_expression::build(cpp_builtin_type::build(cpp_ulonglong),
return size_expr.empty()
? nullptr
: cpp_unexposed_expression::build(cpp_builtin_type::build(cpp_ulonglong),
cpp_token_string::tokenize(
std::string(size_expr.rbegin(),
size_expr.rend())));
@ -298,8 +298,7 @@ namespace
const CXCursor& cur, const CXType& type)
{
auto no_args = clang_getNumArgTypes(type);
DEBUG_ASSERT(no_args >= 0, detail::parse_error_handler{}, type,
"invalid number of arguments");
DEBUG_ASSERT(no_args >= 0, detail::parse_error_handler{}, type, "invalid number of arguments");
for (auto i = 0u; i != unsigned(no_args); ++i)
builder.add_parameter(parse_type_impl(context, cur, clang_getArgType(type, i)));
@ -345,8 +344,8 @@ namespace
auto cv = suffix_cv(spelling);
auto class_t = clang_Type_getClassType(type);
auto class_entity =
make_ref_qualified(make_cv_qualified(parse_type_impl(context, cur, class_t), cv), ref);
auto class_entity
= 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 result = clang_getResultType(pointee);
@ -392,8 +391,8 @@ namespace
return clang_getNullCursor();
}
std::unique_ptr<cpp_type> try_parse_template_parameter_type(
const detail::parse_context& context, const CXCursor& cur, const CXType& type)
std::unique_ptr<cpp_type> try_parse_template_parameter_type(const detail::parse_context& context,
const CXCursor& cur, const CXType& type)
{
// see if we have a parent template
auto templ = get_template(cur);
@ -402,20 +401,17 @@ namespace
return nullptr;
// doesn't respect cv qualifiers properly
auto result =
make_leave_type(cur, type,
[&](std::string&& type_spelling) -> std::unique_ptr<cpp_type> {
auto result
= make_leave_type(cur, type, [&](std::string&& type_spelling) -> std::unique_ptr<cpp_type> {
// look at the template parameters,
// see if we find a matching one
auto param = clang_getNullCursor();
detail::visit_children(templ, [&](const CXCursor& child) {
if (clang_getCursorKind(child) == CXCursor_TemplateTypeParameter
&& get_type_spelling(child, clang_getCursorType(child))
== type_spelling)
&& get_type_spelling(child, clang_getCursorType(child)) == type_spelling)
{
// found one
DEBUG_ASSERT(clang_Cursor_isNull(param),
detail::assert_handler{});
DEBUG_ASSERT(clang_Cursor_isNull(param), detail::assert_handler{});
param = child;
}
});
@ -425,8 +421,7 @@ namespace
else
// found matching parameter
return cpp_template_parameter_type::build(
cpp_template_type_parameter_ref(detail::get_entity_id(
param),
cpp_template_type_parameter_ref(detail::get_entity_id(param),
std::move(type_spelling)));
});
@ -503,8 +498,8 @@ namespace
});
}
std::unique_ptr<cpp_type> try_parse_decltype_type(const detail::parse_context&,
const CXCursor& cur, const CXType& type)
std::unique_ptr<cpp_type> try_parse_decltype_type(const detail::parse_context&, const CXCursor& cur,
const CXType& type)
{
if (clang_isExpression(clang_getCursorKind(cur)))
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,
const CXCursor& cur, const CXType& type)
std::unique_ptr<cpp_type> parse_type_impl(const detail::parse_context& context, const CXCursor& cur,
const CXType& type)
{
switch (type.kind)
{
@ -589,10 +584,10 @@ namespace
context.logger->log("libclang parser",
format_diagnostic(severity::warning, detail::make_location(type),
"unexpected type of kind '",
detail::get_type_kind_spelling(type).c_str(),
"'"));
detail::get_type_kind_spelling(type).c_str(), "'"));
// 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:
if (auto ftype = try_parse_function_type(context, cur, type))
// guess what: after you've called clang_getPointeeType() on a function pointer
@ -621,36 +616,30 @@ namespace
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_bool); });
case CXType_UChar:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_uchar);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_uchar); });
case CXType_UShort:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_ushort);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_ushort); });
case CXType_UInt:
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_uint); });
case CXType_ULong:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_ulong);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_ulong); });
case CXType_ULongLong:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_ulonglong);
});
case CXType_UInt128:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_uint128);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_uint128); });
case CXType_SChar:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_schar);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_schar); });
case CXType_Short:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_short);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_short); });
case CXType_Int:
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_int); });
@ -658,49 +647,40 @@ namespace
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_long); });
case CXType_LongLong:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_longlong);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_longlong); });
case CXType_Int128:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_int128);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_int128); });
case CXType_Float:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_float);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_float); });
case CXType_Double:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_double);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_double); });
case CXType_LongDouble:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_longdouble);
});
case CXType_Float128:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_float128);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_float128); });
case CXType_Char_U:
case CXType_Char_S:
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_char); });
case CXType_Char16:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_char16);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_char16); });
case CXType_Char32:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_char32);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_char32); });
case CXType_WChar:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_wchar);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_wchar); });
case CXType_NullPtr:
return make_leave_type(cur, type, [](std::string&&) {
return cpp_builtin_type::build(cpp_nullptr);
});
return make_leave_type(cur, type,
[](std::string&&) { return cpp_builtin_type::build(cpp_nullptr); });
case CXType_Elaborated:
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));
case CXType_Auto:
return make_leave_type(cur, type,
[&](std::string&&) { return cpp_auto_type::build(); });
return make_leave_type(cur, type, [&](std::string&&) { return cpp_auto_type::build(); });
}
DEBUG_UNREACHABLE(detail::assert_handler{});
return nullptr;
}
}
} // namespace
std::unique_ptr<cpp_type> detail::parse_type(const detail::parse_context& context,
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));
else
{
result =
cpp_type_alias::build(*context.idx, get_entity_id(cur), name.c_str(), std::move(type));
result = cpp_type_alias::build(*context.idx, get_entity_id(cur), name.c_str(),
std::move(type));
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);
for (auto& token : tokenizer)
if (token.value() == "thread_local")
storage_class =
cpp_storage_class_specifiers(storage_class | cpp_storage_class_thread_local);
storage_class
= cpp_storage_class_specifiers(storage_class | cpp_storage_class_thread_local);
else if (token.value() == "constexpr")
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;
if (clang_isCursorDefinition(cur))
{
result =
cpp_variable::build(*context.idx, get_entity_id(cur), name.c_str(), std::move(type),
result
= cpp_variable::build(*context.idx, get_entity_id(cur), name.c_str(), std::move(type),
std::move(default_value), storage_class, is_constexpr);
}
else

View file

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

View file

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

View file

@ -270,8 +270,8 @@ using ns1::d;
)";
cpp_entity_index idx;
auto check_declaration = [&](const cpp_using_declaration& decl, const char* target_full_name,
unsigned no) {
auto check_declaration
= [&](const cpp_using_declaration& decl, const char* target_full_name, unsigned no) {
auto target = decl.target();
REQUIRE((target.no_overloaded() == no));
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"};
auto check_macro = [](const cpp_macro_definition& macro, const char* replacement,
const char* args) {
auto check_macro
= [](const cpp_macro_definition& macro, const char* replacement, const char* args) {
REQUIRE(macro.replacement() == replacement);
if (args)
{
@ -117,8 +117,8 @@ b
auto file_a = parse(idx, "header_a.hpp", header_a);
auto file_b = parse(idx, "header_b.hpp", header_b);
auto count =
test_visit<cpp_include_directive>(*file_a, [&](const cpp_include_directive& include) {
auto count
= test_visit<cpp_include_directive>(*file_a, [&](const cpp_include_directive& include) {
if (include.name() == "iostream")
{
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);
auto& param =
static_cast<const cpp_template_type_parameter&>(p);
auto& param
= static_cast<const cpp_template_type_parameter&>(p);
if (param.name() == "A")
{
REQUIRE(alias.name() == "a");
@ -132,8 +132,8 @@ using d = void;
REQUIRE(p.kind()
== cpp_entity_kind::non_type_template_parameter_t);
auto& param =
static_cast<const cpp_non_type_template_parameter&>(p);
auto& param
= static_cast<const cpp_non_type_template_parameter&>(p);
if (param.name() == "A")
{
REQUIRE(alias.name() == "a");
@ -227,8 +227,8 @@ using d = void;
REQUIRE(p.kind()
== cpp_entity_kind::template_template_parameter_t);
auto& param =
static_cast<const cpp_template_template_parameter&>(p);
auto& param
= static_cast<const cpp_template_template_parameter&>(p);
REQUIRE(param.keyword() == cpp_template_keyword::keyword_class);
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:
{
auto& entity_parsed = static_cast<const cpp_template_parameter_type&>(parsed).entity();
auto& entity_synthesized =
static_cast<const cpp_template_parameter_type&>(synthesized).entity();
auto& entity_synthesized
= static_cast<const cpp_template_parameter_type&>(synthesized).entity();
return equal_ref(idx, entity_parsed, entity_synthesized);
}
case cpp_type_kind::template_instantiation_t:
@ -357,8 +357,8 @@ typedef decltype(0) w;
}
else if (alias.name() == "d")
{
auto type =
cpp_pointer_type::build(add_cv(cpp_builtin_type::build(cpp_uint), cpp_cv_const));
auto type
= cpp_pointer_type::build(add_cv(cpp_builtin_type::build(cpp_uint), cpp_cv_const));
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
else if (alias.name() == "e")
@ -375,8 +375,8 @@ typedef decltype(0) w;
}
else if (alias.name() == "g")
{
auto type =
cpp_reference_type::build(add_cv(cpp_builtin_type::build(cpp_int), cpp_cv_const),
auto type
= cpp_reference_type::build(add_cv(cpp_builtin_type::build(cpp_int), cpp_cv_const),
cpp_ref_rvalue);
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
@ -399,21 +399,21 @@ typedef decltype(0) w;
}
else if (alias.name() == "k")
{
auto type =
cpp_array_type::build(cpp_builtin_type::build(cpp_int), make_size("42", true));
auto type
= cpp_array_type::build(cpp_builtin_type::build(cpp_int), make_size("42", true));
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
else if (alias.name() == "l")
{
auto type =
cpp_array_type::build(cpp_pointer_type::build(cpp_builtin_type::build(cpp_float)),
auto type
= cpp_array_type::build(cpp_pointer_type::build(cpp_builtin_type::build(cpp_float)),
nullptr);
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
else if (alias.name() == "m")
{
auto type =
cpp_array_type::build(cpp_builtin_type::build(cpp_char), make_size("42", true));
auto type
= cpp_array_type::build(cpp_builtin_type::build(cpp_char), make_size("42", true));
REQUIRE(equal_types(idx, alias.underlying_type(), *type));
}
else if (alias.name() == "n")
@ -474,10 +474,12 @@ typedef decltype(0) w;
}
else if (alias.name() == "s")
{
auto pointee = cpp_member_object_type::
build(cpp_user_defined_type::build(cpp_type_ref(cpp_entity_id(""), "foo")),
auto pointee
= cpp_member_object_type::build(cpp_user_defined_type::build(
cpp_type_ref(cpp_entity_id(""), "foo")),
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));
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 <csignal>
//#include <csetjmp> -- same as above
#include <cstdarg>
#include <typeinfo>
#include <typeindex>
#include <type_traits>
#include <bitset>
#include <functional>
#include <utility>
#include <ctime>
#include <chrono>
#include <cstdarg>
#include <cstddef>
#include <ctime>
#include <functional>
#include <initializer_list>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <utility>
#include <new>
#include <memory>
#include <new>
#include <scoped_allocator>
#include <climits>
#include <cfloat>
#include <climits>
#include <cstdint>
//#include <cinttypes> -- missing types from C header (for some reason)
#include <limits>
//#include <exception> -- weird issue with compiler built-in stuff
#include <stdexcept>
#include <cassert>
#include <system_error>
#include <cerrno>
#include <stdexcept>
#include <system_error>
#include <cctype>
#include <cwctype>
#include <cstring>
#include <cwchar>
#include <cwctype>
//#include <cuchar> -- not supported on CI
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <list>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
@ -70,22 +70,22 @@ TEST_CASE("stdlib", "[!hide][integration]")
//#include <cmath> -- non-conforming GCC extension with regards to constexpr
//#include <complex> -- weird double include issue under MSVC
#include <valarray>
#include <random>
#include <numeric>
#include <random>
#include <ratio>
#include <valarray>
//#include <cfenv> -- same issue with cinttypes
#include <iosfwd>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <streambuf>
#include <cstdio>
#include <locale>
//#include <clocale> -- issue on OSX
@ -94,10 +94,10 @@ TEST_CASE("stdlib", "[!hide][integration]")
//#include <atomic> -- issue on MSVC
#include <thread>
#include <mutex>
#include <future>
#include <condition_variable>
#include <future>
#include <mutex>
#include <thread>
)";
write_file("stdlib.cpp", code);

View file

@ -65,7 +65,8 @@ TEST_CASE("preprocessing use external macro")
auto result = NAN;
#endif
)", fast_preprocessing);
)",
fast_preprocessing);
test_visit<cpp_variable>(*file, [&](const cpp_variable&) {});
}
@ -302,7 +303,8 @@ void j();
{
if (comment.content == "cstddef\ncstddef")
// 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;
else
REQUIRE(comment.content == "u");

View file

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