Skip to content

Commit 62e571a

Browse files
committed
Update copyright notices
1 parent 373717c commit 62e571a

File tree

133 files changed

+957
-1124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+957
-1124
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright (C) 2017-2018 Jonathan Müller <[email protected]>
2-
# This file is subject to the license terms in the LICENSE file
1+
# Copyright (C) 2017-2022 Jonathan Müller and cppast contributors
2+
# SPDX-License-Identifier: MIT
33
# found in the top-level directory of this distribution.
44

55
cmake_minimum_required(VERSION 3.11)

example/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright (C) 2017-2018 Jonathan Müller <[email protected]>
2-
# This file is subject to the license terms in the LICENSE file
1+
# Copyright (C) 2017-2022 Jonathan Müller and cppast contributors
2+
# SPDX-License-Identifier: MIT
33
# found in the top-level directory of this distribution.
44

55
function(_cppast_example name)

example/ast_printer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// Copyright (C) 2017-2019 Jonathan Müller <[email protected]>
2-
// This file is subject to the license terms in the LICENSE file
3-
// found in the top-level directory of this distribution.
1+
// Copyright (C) 2017-2022 Jonathan Müller and cppast contributors
2+
// SPDX-License-Identifier: MIT
43

54
/// \file
65
/// This is a very primitive version of the cppast tool.

example/comparison.cpp

+41-44
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// Copyright (C) 2017-2019 Jonathan Müller <[email protected]>
2-
// This file is subject to the license terms in the LICENSE file
3-
// found in the top-level directory of this distribution.
1+
// Copyright (C) 2017-2022 Jonathan Müller and cppast contributors
2+
// SPDX-License-Identifier: MIT
43

54
/// \file
65
/// Generate equality comparisons.
@@ -80,48 +79,46 @@ void generate_op_non_equal(std::ostream& out, const cppast::cpp_class& c)
8079
// generate comparison operators for all classes in the file
8180
void generate_comparison(const cppast::cpp_file& file)
8281
{
83-
cppast::visit(file,
84-
[](const cppast::cpp_entity& e) {
85-
// only visit non-templated class definitions that have the attribute set
86-
return (!cppast::is_templated(e)
87-
&& e.kind() == cppast::cpp_entity_kind::class_t
88-
&& cppast::is_definition(e)
89-
&& cppast::has_attribute(e, "generate::comparison"))
90-
// or all namespaces
91-
|| e.kind() == cppast::cpp_entity_kind::namespace_t;
92-
},
93-
[](const cppast::cpp_entity& e, const cppast::visitor_info& info) {
94-
if (e.kind() == cppast::cpp_entity_kind::class_t && !info.is_old_entity())
95-
{
96-
// it is a new class
97-
auto& class_ = static_cast<const cppast::cpp_class&>(e);
98-
auto& attribute
99-
= cppast::has_attribute(e, "generate::comparison").value();
82+
cppast::visit(
83+
file,
84+
[](const cppast::cpp_entity& e) {
85+
// only visit non-templated class definitions that have the attribute set
86+
return (!cppast::is_templated(e) && e.kind() == cppast::cpp_entity_kind::class_t
87+
&& cppast::is_definition(e) && cppast::has_attribute(e, "generate::comparison"))
88+
// or all namespaces
89+
|| e.kind() == cppast::cpp_entity_kind::namespace_t;
90+
},
91+
[](const cppast::cpp_entity& e, const cppast::visitor_info& info) {
92+
if (e.kind() == cppast::cpp_entity_kind::class_t && !info.is_old_entity())
93+
{
94+
// it is a new class
95+
auto& class_ = static_cast<const cppast::cpp_class&>(e);
96+
auto& attribute = cppast::has_attribute(e, "generate::comparison").value();
10097

101-
// generate requested operators
102-
if (attribute.arguments())
103-
{
104-
if (has_token(attribute.arguments().value(), "=="))
105-
generate_op_equal(std::cout, class_);
106-
if (has_token(attribute.arguments().value(), "!="))
107-
generate_op_non_equal(std::cout, class_);
108-
}
109-
else
110-
{
111-
generate_op_equal(std::cout, class_);
112-
generate_op_non_equal(std::cout, class_);
113-
}
114-
}
115-
else if (e.kind() == cppast::cpp_entity_kind::namespace_t)
116-
{
117-
if (info.event == cppast::visitor_info::container_entity_enter)
118-
// open namespace
119-
std::cout << "namespace " << e.name() << " {\n\n";
120-
else // if (info.event == cppast::visitor_info::container_entity_exit)
121-
// close namespace
122-
std::cout << "}\n";
123-
}
124-
});
98+
// generate requested operators
99+
if (attribute.arguments())
100+
{
101+
if (has_token(attribute.arguments().value(), "=="))
102+
generate_op_equal(std::cout, class_);
103+
if (has_token(attribute.arguments().value(), "!="))
104+
generate_op_non_equal(std::cout, class_);
105+
}
106+
else
107+
{
108+
generate_op_equal(std::cout, class_);
109+
generate_op_non_equal(std::cout, class_);
110+
}
111+
}
112+
else if (e.kind() == cppast::cpp_entity_kind::namespace_t)
113+
{
114+
if (info.event == cppast::visitor_info::container_entity_enter)
115+
// open namespace
116+
std::cout << "namespace " << e.name() << " {\n\n";
117+
else // if (info.event == cppast::visitor_info::container_entity_exit)
118+
// close namespace
119+
std::cout << "}\n";
120+
}
121+
});
125122
}
126123

127124
int main(int argc, char* argv[])

example/documentation_generator.cpp

+35-36
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// Copyright (C) 2017-2019 Jonathan Müller <[email protected]>
2-
// This file is subject to the license terms in the LICENSE file
3-
// found in the top-level directory of this distribution.
1+
// Copyright (C) 2017-2022 Jonathan Müller and cppast contributors
2+
// SPDX-License-Identifier: MIT
43

54
/// \file
65
/// A primitive documentation generator.
@@ -120,39 +119,39 @@ std::string generate_synopsis(const cppast::cpp_entity& e)
120119
void generate_documentation(const cppast::cpp_file& file)
121120
{
122121
// visit each entity
123-
cppast::visit(file,
124-
[](const cppast::cpp_entity& e, cppast::cpp_access_specifier_kind access) {
125-
if (is_excluded_documentation(e, access))
126-
// exclude this and all children
127-
return cppast::visit_filter::exclude_and_children;
128-
else if (cppast::is_templated(e) || cppast::is_friended(e))
129-
// continue on with children for a dummy entity
130-
return cppast::visit_filter::exclude;
131-
else
132-
return cppast::visit_filter::include;
133-
},
134-
[](const cppast::cpp_entity& e, const cppast::visitor_info& info) {
135-
if (info.is_old_entity())
136-
// already done
137-
return;
138-
139-
// print name
140-
std::cout << "## " << cppast::to_string(e.kind()) << " '" << e.name()
141-
<< "'\n";
142-
std::cout << '\n';
143-
144-
// print synopsis
145-
std::cout << "```\n";
146-
std::cout << generate_synopsis(e);
147-
std::cout << "```\n\n";
148-
149-
// print documentation comment
150-
if (e.comment())
151-
std::cout << e.comment().value() << '\n';
152-
153-
// print separator
154-
std::cout << "\n---\n\n";
155-
});
122+
cppast::visit(
123+
file,
124+
[](const cppast::cpp_entity& e, cppast::cpp_access_specifier_kind access) {
125+
if (is_excluded_documentation(e, access))
126+
// exclude this and all children
127+
return cppast::visit_filter::exclude_and_children;
128+
else if (cppast::is_templated(e) || cppast::is_friended(e))
129+
// continue on with children for a dummy entity
130+
return cppast::visit_filter::exclude;
131+
else
132+
return cppast::visit_filter::include;
133+
},
134+
[](const cppast::cpp_entity& e, const cppast::visitor_info& info) {
135+
if (info.is_old_entity())
136+
// already done
137+
return;
138+
139+
// print name
140+
std::cout << "## " << cppast::to_string(e.kind()) << " '" << e.name() << "'\n";
141+
std::cout << '\n';
142+
143+
// print synopsis
144+
std::cout << "```\n";
145+
std::cout << generate_synopsis(e);
146+
std::cout << "```\n\n";
147+
148+
// print documentation comment
149+
if (e.comment())
150+
std::cout << e.comment().value() << '\n';
151+
152+
// print separator
153+
std::cout << "\n---\n\n";
154+
});
156155
std::cout << "\n\n";
157156
}
158157

example/enum_category.cpp

+57-59
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// Copyright (C) 2017-2019 Jonathan Müller <[email protected]>
2-
// This file is subject to the license terms in the LICENSE file
3-
// found in the top-level directory of this distribution.
1+
// Copyright (C) 2017-2022 Jonathan Müller and cppast contributors
2+
// SPDX-License-Identifier: MIT
43

54
/// \file
65
/// Generates enum category functions.
@@ -55,68 +54,67 @@ const cppast::cpp_enum& get_enum(const cppast::cpp_entity_index& index,
5554
// generates the function definitions
5655
void generate_enum_category(const cppast::cpp_entity_index& index, const cppast::cpp_file& file)
5756
{
58-
cppast::visit(file,
59-
[](const cppast::cpp_entity& e) {
60-
// only visit function declarations that have the attribute set
61-
return (e.kind() == cppast::cpp_entity_kind::function_t
62-
&& !cppast::is_definition(e)
63-
&& cppast::has_attribute(e, "generate::enum_category"))
64-
// or all namespaces
65-
|| e.kind() == cppast::cpp_entity_kind::namespace_t;
66-
},
67-
[&](const cppast::cpp_entity& e, const cppast::visitor_info& info) {
68-
if (e.kind() == cppast::cpp_entity_kind::function_t)
69-
{
70-
// a new function, generate implementation
71-
assert(info.is_new_entity());
57+
cppast::visit(
58+
file,
59+
[](const cppast::cpp_entity& e) {
60+
// only visit function declarations that have the attribute set
61+
return (e.kind() == cppast::cpp_entity_kind::function_t && !cppast::is_definition(e)
62+
&& cppast::has_attribute(e, "generate::enum_category"))
63+
// or all namespaces
64+
|| e.kind() == cppast::cpp_entity_kind::namespace_t;
65+
},
66+
[&](const cppast::cpp_entity& e, const cppast::visitor_info& info) {
67+
if (e.kind() == cppast::cpp_entity_kind::function_t)
68+
{
69+
// a new function, generate implementation
70+
assert(info.is_new_entity());
7271

73-
auto category = cppast::has_attribute(e, "generate::enum_category")
74-
.value()
75-
.arguments()
76-
.value()
77-
.as_string();
72+
auto category = cppast::has_attribute(e, "generate::enum_category")
73+
.value()
74+
.arguments()
75+
.value()
76+
.as_string();
7877

79-
auto& func = static_cast<const cppast::cpp_function&>(e);
80-
// return type must be bool
81-
assert(func.return_type().kind() == cppast::cpp_type_kind::builtin_t
82-
&& static_cast<const cppast::cpp_builtin_type&>(func.return_type())
83-
.builtin_type_kind()
84-
== cppast::cpp_bool);
78+
auto& func = static_cast<const cppast::cpp_function&>(e);
79+
// return type must be bool
80+
assert(func.return_type().kind() == cppast::cpp_type_kind::builtin_t
81+
&& static_cast<const cppast::cpp_builtin_type&>(func.return_type())
82+
.builtin_type_kind()
83+
== cppast::cpp_bool);
8584

86-
// single parameter...
87-
assert(std::next(func.parameters().begin()) == func.parameters().end());
88-
auto& param = *func.parameters().begin();
89-
auto& enum_ = get_enum(index, param);
85+
// single parameter...
86+
assert(std::next(func.parameters().begin()) == func.parameters().end());
87+
auto& param = *func.parameters().begin();
88+
auto& enum_ = get_enum(index, param);
9089

91-
// generate function definition
92-
std::cout << "inline bool " << func.name() << "("
93-
<< cppast::to_string(param.type()) << " e) {\n";
90+
// generate function definition
91+
std::cout << "inline bool " << func.name() << "(" << cppast::to_string(param.type())
92+
<< " e) {\n";
9493

95-
// generate switch
96-
std::cout << " switch (e) {\n";
97-
for (const auto& enumerator : enum_)
98-
{
99-
std::cout << " case " << enum_.name() << "::" << enumerator.name()
100-
<< ":\n";
101-
if (is_category(enumerator, category))
102-
std::cout << " return true;\n";
103-
else
104-
std::cout << " return false;\n";
105-
}
106-
std::cout << " }\n";
94+
// generate switch
95+
std::cout << " switch (e) {\n";
96+
for (const auto& enumerator : enum_)
97+
{
98+
std::cout << " case " << enum_.name() << "::" << enumerator.name() << ":\n";
99+
if (is_category(enumerator, category))
100+
std::cout << " return true;\n";
101+
else
102+
std::cout << " return false;\n";
103+
}
104+
std::cout << " }\n";
107105

108-
std::cout << "}\n\n";
109-
}
110-
else if (e.kind() == cppast::cpp_entity_kind::namespace_t)
111-
{
112-
if (info.event == cppast::visitor_info::container_entity_enter)
113-
// open namespace
114-
std::cout << "namespace " << e.name() << " {\n\n";
115-
else // if (info.event == cppast::visitor_info::container_entity_exit)
116-
// close namespace
117-
std::cout << "}\n";
118-
}
119-
});
106+
std::cout << "}\n\n";
107+
}
108+
else if (e.kind() == cppast::cpp_entity_kind::namespace_t)
109+
{
110+
if (info.event == cppast::visitor_info::container_entity_enter)
111+
// open namespace
112+
std::cout << "namespace " << e.name() << " {\n\n";
113+
else // if (info.event == cppast::visitor_info::container_entity_exit)
114+
// close namespace
115+
std::cout << "}\n";
116+
}
117+
});
120118
}
121119

122120
int main(int argc, char* argv[])

0 commit comments

Comments
 (0)