Skip to content

Commit 3ebebd2

Browse files
authored
Merge pull request #120 from heinezen/fix/code-format
Use `clang-format` on entire code base
2 parents 5bce3f4 + 23a9304 commit 3ebebd2

Some content is hidden

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

81 files changed

+733
-889
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ IndentCaseBlocks: false
8181
IndentCaseLabels: false
8282
IndentExternBlock: NoIndent
8383
IndentGotoLabels: false
84-
IndentPPDirectives: None
84+
IndentPPDirectives: BeforeHash
8585
IndentWidth: 4
8686
IndentWrappedFunctionNames: false
8787
# clang-format-16 InsertNewlineAtEOF: true

nyan/api_error.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ MemberTypeError::MemberTypeError(const fqon_t &objname,
2020
const std::string &real_type,
2121
const std::string &wrong_type) :
2222
APIError{(static_cast<const std::ostringstream &>(
23-
std::ostringstream{} << "type mismatch for member " << objname + "." << member
24-
<< ": tried to convert real type " << real_type << " to " << wrong_type))
25-
.str()},
23+
std::ostringstream{} << "type mismatch for member " << objname + "." << member
24+
<< ": tried to convert real type " << real_type << " to " << wrong_type))
25+
.str()},
2626
objname{objname},
2727
member{member},
2828
real_type{real_type},

nyan/api_error.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ class InvalidObjectError : public APIError {
3131
*/
3232
class MemberTypeError : public APIError {
3333
public:
34-
MemberTypeError(const fqon_t &objname, const memberid_t &member,
35-
const std::string &real_type, const std::string &wrong_type);
34+
MemberTypeError(const fqon_t &objname,
35+
const memberid_t &member,
36+
const std::string &real_type,
37+
const std::string &wrong_type);
3638

3739
protected:
3840
/**

nyan/ast.cpp

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ void ASTObject::ast_parents(TokenStream &tokens) {
282282
if (token.type != token_type::ID) {
283283
throw ASTError{
284284
"expected inheritance parent identifier, but there is",
285-
token
286-
};
285+
token};
287286
}
288287

289288
this->parents.emplace_back(token, stream);
@@ -301,9 +300,9 @@ void ASTObject::ast_members(TokenStream &tokens) {
301300
bool object_next = false;
302301
auto lookahead = tokens.next();
303302

304-
if (lookahead->type == token_type::OPERATOR // value assignment
305-
or lookahead->type == token_type::COLON // type declaration
306-
or lookahead->type == token_type::DOT) { // inherited member access (e.g. Parent.some_member)
303+
if (lookahead->type == token_type::OPERATOR // value assignment
304+
or lookahead->type == token_type::COLON // type declaration
305+
or lookahead->type == token_type::DOT) { // inherited member access (e.g. Parent.some_member)
307306
object_next = false;
308307
}
309308
else if (lookahead->type == token_type::LANGLE or lookahead->type == token_type::LBRACKET or lookahead->type == token_type::LPAREN) {
@@ -434,7 +433,6 @@ ASTMember::ASTMember(const Token &name,
434433
name{IDToken{name, tokens}},
435434
type{std::nullopt},
436435
value{std::nullopt} {
437-
438436
auto token = tokens.next();
439437
bool had_def_or_decl = false;
440438

@@ -535,7 +533,6 @@ ASTMember::ASTMember(const Token &name,
535533
ASTMemberType::ASTMemberType(const Token &name,
536534
TokenStream &tokens) :
537535
name{IDToken{name, tokens}} {
538-
539536
// now there may follow type arguments, e.g.:
540537
// set(arg, key=val)
541538
// optional(dict(ktype, vtype))
@@ -547,7 +544,6 @@ ASTMemberType::ASTMemberType(const Token &name,
547544
size_t num_expected_types = member_type.expected_nested_types();
548545

549546
if (token->type == token_type::LPAREN) {
550-
551547
// TODO: if we introduce optional arguments for composite types
552548
// we have to adjust the allowed count here.
553549
// or just count the non-kwarg arguments, and ignored the kwarg count.
@@ -561,29 +557,28 @@ ASTMemberType::ASTMemberType(const Token &name,
561557
num_expected_types,
562558
[this](const Token &token, TokenStream &stream) {
563559
this->nested_types.emplace_back(token, stream);
564-
}
565-
);
560+
});
566561

567562
if (unlikely(num_read_types != num_expected_types)) {
568563
throw ASTError(
569564
std::string("expected ")
570-
+ std::to_string(num_expected_types)
571-
+ " arguments for "
572-
+ composite_type_to_string(member_type.composite_type)
573-
+ " declaration, but only "
574-
+ std::to_string(num_read_types)
575-
+ " could be found",
565+
+ std::to_string(num_expected_types)
566+
+ " arguments for "
567+
+ composite_type_to_string(member_type.composite_type)
568+
+ " declaration, but only "
569+
+ std::to_string(num_read_types)
570+
+ " could be found",
576571
*token,
577572
false);
578573
}
579574
}
580575
else if (num_expected_types > 0) {
581576
throw ASTError(
582577
std::string("expected ")
583-
+ std::to_string(num_expected_types)
584-
+ " arguments for "
585-
+ composite_type_to_string(member_type.composite_type)
586-
+ " declaration",
578+
+ std::to_string(num_expected_types)
579+
+ " arguments for "
580+
+ composite_type_to_string(member_type.composite_type)
581+
+ " declaration",
587582
*token,
588583
false);
589584
}
@@ -739,12 +734,11 @@ void ASTObject::strb(std::ostringstream &builder, int indentlevel) const {
739734

740735
// object parents
741736
builder << "(";
742-
util::strjoin(builder, ", ", this->parents,
743-
[](auto &stream, auto &elem) {
744-
stream << elem.str();
745-
});
737+
util::strjoin(builder, ", ", this->parents, [](auto &stream, auto &elem) {
738+
stream << elem.str();
739+
});
746740
builder << "):"
747-
<< std::endl;
741+
<< std::endl;
748742

749743
if (this->objects.size() > 0) {
750744
for (auto &object : this->objects) {
@@ -795,8 +789,8 @@ void ASTMember::strb(std::ostringstream &builder, int indentlevel) const {
795789

796790
if (this->value.has_value()) {
797791
builder << " "
798-
<< op_to_string(this->operation)
799-
<< " ";
792+
<< op_to_string(this->operation)
793+
<< " ";
800794

801795
this->value->strb(builder);
802796
}
@@ -810,10 +804,9 @@ void ASTMemberType::strb(std::ostringstream &builder, int /*indentlevel*/) const
810804

811805
if (this->args.size() > 0) {
812806
builder << "(";
813-
util::strjoin(builder, ", ", this->args,
814-
[](auto &stream, auto& elem) {
815-
elem.strb(stream);
816-
});
807+
util::strjoin(builder, ", ", this->args, [](auto &stream, auto &elem) {
808+
elem.strb(stream);
809+
});
817810
builder << ")";
818811
}
819812
}
@@ -846,8 +839,7 @@ void ASTMemberValue::strb(std::ostringstream &builder, int /*indentlevel*/) cons
846839
throw InternalError{"unhandled container type"};
847840
}
848841

849-
util::strjoin(builder, ", ", this->values,
850-
[](auto &stream, auto &elem) { stream << elem.str(); });
842+
util::strjoin(builder, ", ", this->values, [](auto &stream, auto &elem) { stream << elem.str(); });
851843

852844
switch (this->composite_type) {
853845
case composite_t::SET:
@@ -869,7 +861,7 @@ ASTError::ASTError(const std::string &msg,
869861
if (add_token) {
870862
std::ostringstream builder;
871863
builder << msg << ": "
872-
<< token_type_str(token.type);
864+
<< token_type_str(token.type);
873865
this->msg = std::move(builder).str();
874866
}
875867
else {
@@ -885,7 +877,7 @@ ASTError::ASTError(const std::string &msg,
885877
if (add_token) {
886878
std::ostringstream builder;
887879
builder << msg << ": "
888-
<< token_type_str(token.get_type());
880+
<< token_type_str(token.get_type());
889881
this->msg = builder.str();
890882
}
891883
else {

nyan/ast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ unsigned int comma_list(token_type end,
3838
TokenStream &tokens,
3939
size_t limit,
4040
const std::function<void(const Token &, TokenStream &)> &func,
41-
bool unlimited=false);
41+
bool unlimited = false);
4242

4343

4444
/**

nyan/basic_type.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,10 @@ size_t BasicType::expected_nested_types() const {
102102

103103

104104
bool BasicType::operator==(const BasicType &other) const {
105-
return (this->primitive_type == other.primitive_type and
106-
this->composite_type == other.composite_type);
105+
return (this->primitive_type == other.primitive_type and this->composite_type == other.composite_type);
107106
}
108107

109108

110-
111109
std::string BasicType::str() const {
112110
if (this->is_fundamental()) {
113111
return type_to_string(this->primitive_type);
@@ -130,22 +128,19 @@ BasicType BasicType::from_type_token(const IDToken &tok) {
130128
{"text", primitive_t::TEXT},
131129
{"file", primitive_t::FILENAME},
132130
{"int", primitive_t::INT},
133-
{"float", primitive_t::FLOAT}
134-
};
131+
{"float", primitive_t::FLOAT}};
135132

136133
// container type name map
137134
static const std::unordered_map<std::string, composite_t> container_types = {
138135
{"set", composite_t::SET},
139136
{"orderedset", composite_t::ORDEREDSET},
140-
{"dict", composite_t::DICT}
141-
};
137+
{"dict", composite_t::DICT}};
142138

143139
// modifier type name map
144140
static const std::unordered_map<std::string, composite_t> modifiers = {
145141
{"abstract", composite_t::ABSTRACT},
146142
{"children", composite_t::CHILDREN},
147-
{"optional", composite_t::OPTIONAL}
148-
};
143+
{"optional", composite_t::OPTIONAL}};
149144

150145
primitive_t type = primitive_t::OBJECT;
151146
composite_t composite_type = composite_t::SINGLE;

nyan/c3.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ std::vector<fqon_t>
3333
linearize_recurse(const fqon_t &name,
3434
const objstate_fetch_t &get_obj,
3535
std::unordered_set<fqon_t> *seen) {
36-
3736
using namespace std::string_literals;
3837

3938
// test for inheritance loops
4039
if (seen->find(name) != std::end(*seen)) {
4140
throw C3Error{
4241
"recursive inheritance loop detected: '"s + name + "' already in {"
4342
+ util::strjoin(", ", *seen)
44-
+ "}"
45-
};
43+
+ "}"};
4644
}
4745
else {
4846
seen->insert(name);
@@ -67,14 +65,12 @@ linearize_recurse(const fqon_t &name,
6765
for (auto &parent : parents) {
6866
// Recursive call to get the linearization of the parent
6967
par_linearizations.push_back(
70-
linearize_recurse(parent, get_obj, seen)
71-
);
68+
linearize_recurse(parent, get_obj, seen));
7269
}
7370

7471
// And at the end, add all parents of this object to the merge-list.
7572
par_linearizations.push_back(
76-
{std::begin(parents), std::end(parents)}
77-
);
73+
{std::begin(parents), std::end(parents)});
7874

7975
// remove current name from the seen set
8076
// we only needed it for the recursive call above.
@@ -109,7 +105,6 @@ linearize_recurse(const fqon_t &name,
109105

110106
// Test if the candidate is in any tail
111107
for (size_t j = 0; j < par_linearizations.size(); j++) {
112-
113108
// The current list will never contain the candidate again.
114109
if (j == i) {
115110
continue;
@@ -121,7 +116,6 @@ linearize_recurse(const fqon_t &name,
121116
// Start one slot after the head
122117
// and check that the candidate is not in that tail.
123118
for (size_t k = headpos_try + 1; k < tail.size(); k++) {
124-
125119
// The head is in that tail, so we fail
126120
if (unlikely(*candidate == tail[k])) {
127121
candidate_ok = false;
@@ -138,7 +132,8 @@ linearize_recurse(const fqon_t &name,
138132
// The candidate was not in any tail
139133
if (candidate_ok) {
140134
break;
141-
} else {
135+
}
136+
else {
142137
// Try the next candidate,
143138
// this means to select the next par_lin list.
144139
continue;
@@ -171,8 +166,7 @@ linearize_recurse(const fqon_t &name,
171166
if (not candidate_ok) {
172167
throw C3Error{
173168
"Can't find consistent C3 resolution order for "s
174-
+ name + " for bases " + util::strjoin(", ", parents)
175-
};
169+
+ name + " for bases " + util::strjoin(", ", parents)};
176170
}
177171
}
178172

@@ -181,8 +175,7 @@ linearize_recurse(const fqon_t &name,
181175
}
182176

183177

184-
C3Error::C3Error(const std::string &msg)
185-
:
178+
C3Error::C3Error(const std::string &msg) :
186179
Error{msg} {}
187180

188181

nyan/change_tracker.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ ObjectChanges &ChangeTracker::track_patch(const fqon_t &target_name) {
2525
// else: create a new one.
2626
auto it = this->changes.find(target_name);
2727
if (it == std::end(this->changes)) {
28-
return this->changes.emplace(
29-
target_name,
30-
ObjectChanges{}
31-
).first->second;
28+
auto it_new_tracker = this->changes.emplace(target_name, ObjectChanges{}).first;
29+
return it_new_tracker->second;
3230
}
3331
else {
3432
return it->second;

nyan/change_tracker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class ObjectChanges {
5151
*/
5252
class ChangeTracker {
5353
public:
54-
5554
/**
5655
* Get the ObjectChanges for an object targeted by a patch
5756
* from the changes map or create a new one if there doesn't

nyan/compiler.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* The expression is expected to be true (=likely) or false (=unlikely).
88
*/
99
#if defined(__GNUC__)
10-
#define likely(x) __builtin_expect(!!(x), 1)
11-
#define unlikely(x) __builtin_expect(!!(x), 0)
10+
#define likely(x) __builtin_expect(!!(x), 1)
11+
#define unlikely(x) __builtin_expect(!!(x), 0)
1212
#else
13-
#define likely(x) (x)
13+
#define likely(x) (x)
1414
#define unlikely(x) (x)
1515
#endif
1616

@@ -31,9 +31,9 @@
3131
*/
3232
#if defined(_WIN32)
3333
#if defined(nyan_EXPORTS)
34-
#define NYANAPI __declspec(dllexport) // library is built
34+
#define NYANAPI __declspec(dllexport) // library is built
3535
#else
36-
#define NYANAPI __declspec(dllimport) // library is used
36+
#define NYANAPI __declspec(dllimport) // library is used
3737
#endif /* nyan_EXPORTS */
3838
#else
3939
#define NYANAPI __attribute__((visibility("default")))

nyan/config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#pragma once
44

55
#ifdef _MSC_VER
6-
// Allow using alternative operator representation with non-conforming compiler
7-
#include <ciso646>
6+
// Allow using alternative operator representation with non-conforming compiler
7+
#include <ciso646>
88
#endif
99

10-
#include <cstdint>
1110
#include <cstddef>
11+
#include <cstdint>
1212
#include <limits>
1313
#include <string>
1414

0 commit comments

Comments
 (0)