Skip to content

Commit 0e04786

Browse files
authored
Use the Google Style for clang-format without exceptions (#8706)
This reduces the friction when merging from github and google repos by using the exact same clang style guide. MARKDOWN=true
1 parent 881eaab commit 0e04786

Some content is hidden

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

84 files changed

+8187
-6662
lines changed

.clang-format

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
---
22
Language: Cpp
33
BasedOnStyle: Google
4-
DerivePointerAlignment: false
5-
PointerAlignment: Right
6-
IndentPPDirectives: AfterHash
7-
Cpp11BracedListStyle: false
8-
AlwaysBreakTemplateDeclarations: false
9-
AllowShortCaseLabelsOnASingleLine: true
10-
SpaceAfterTemplateKeyword: false
11-
AllowShortBlocksOnASingleLine: true
124
...
135

goldens/swift/basic_generated.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// swiftlint:disable all
33
// swiftformat:disable all
44

5+
#if canImport(Common)
6+
import Common
7+
#endif
8+
59
import FlatBuffers
610

711
public struct flatbuffers_goldens_Galaxy: FlatBufferObject, Verifiable {

grpc/src/compiler/schema_interface.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include <vector>
2525

2626
#ifndef GRPC_CUSTOM_STRING
27-
# include <string>
28-
# define GRPC_CUSTOM_STRING std::string
27+
#include <string>
28+
#define GRPC_CUSTOM_STRING std::string
2929
#endif
3030

3131
namespace grpc {
@@ -55,10 +55,10 @@ struct Method : public CommentHolder {
5555
virtual grpc::string output_type_name() const = 0;
5656

5757
virtual bool get_module_and_message_path_input(
58-
grpc::string *str, grpc::string generator_file_name,
58+
grpc::string* str, grpc::string generator_file_name,
5959
bool generate_in_pb2_grpc, grpc::string import_prefix) const = 0;
6060
virtual bool get_module_and_message_path_output(
61-
grpc::string *str, grpc::string generator_file_name,
61+
grpc::string* str, grpc::string generator_file_name,
6262
bool generate_in_pb2_grpc, grpc::string import_prefix) const = 0;
6363

6464
virtual std::vector<grpc::string> get_input_namespace_parts() const = 0;
@@ -89,9 +89,9 @@ struct Service : public CommentHolder {
8989
struct Printer {
9090
virtual ~Printer() {}
9191

92-
virtual void Print(const std::map<grpc::string, grpc::string> &vars,
93-
const char *template_string) = 0;
94-
virtual void Print(const char *string) = 0;
92+
virtual void Print(const std::map<grpc::string, grpc::string>& vars,
93+
const char* template_string) = 0;
94+
virtual void Print(const char* string) = 0;
9595
virtual void SetIndentationSize(const size_t size) = 0;
9696
virtual void Indent() = 0;
9797
virtual void Outdent() = 0;
@@ -112,7 +112,7 @@ struct File : public CommentHolder {
112112
virtual std::unique_ptr<const Service> service(int i) const = 0;
113113

114114
virtual std::unique_ptr<Printer> CreatePrinter(
115-
grpc::string *str, const char indentation_type = ' ') const = 0;
115+
grpc::string* str, const char indentation_type = ' ') const = 0;
116116
};
117117
} // namespace grpc_generator
118118

grpc/tests/grpctest.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ void message_builder_tests();
3333
// code. It implements all rpcs specified in the FlatBuffers schema.
3434
class ServiceImpl final : public MyGame::Example::MonsterStorage::Service {
3535
virtual ::grpc::Status Store(
36-
::grpc::ServerContext *context,
37-
const flatbuffers::grpc::Message<Monster> *request,
38-
flatbuffers::grpc::Message<Stat> *response) override {
36+
::grpc::ServerContext* context,
37+
const flatbuffers::grpc::Message<Monster>* request,
38+
flatbuffers::grpc::Message<Stat>* response) override {
3939
// Create a response from the incoming request name.
4040
fbb_.Clear();
4141
auto stat_offset = CreateStat(
@@ -46,9 +46,9 @@ class ServiceImpl final : public MyGame::Example::MonsterStorage::Service {
4646
return grpc::Status::OK;
4747
}
4848
virtual ::grpc::Status Retrieve(
49-
::grpc::ServerContext *context,
50-
const flatbuffers::grpc::Message<Stat> *request,
51-
::grpc::ServerWriter<flatbuffers::grpc::Message<Monster>> *writer)
49+
::grpc::ServerContext* context,
50+
const flatbuffers::grpc::Message<Stat>* request,
51+
::grpc::ServerWriter<flatbuffers::grpc::Message<Monster>>* writer)
5252
override {
5353
for (int i = 0; i < 5; i++) {
5454
fbb_.Clear();
@@ -73,7 +73,7 @@ class ServiceImpl final : public MyGame::Example::MonsterStorage::Service {
7373
};
7474

7575
// Track the server instance, so we can terminate it later.
76-
grpc::Server *server_instance = nullptr;
76+
grpc::Server* server_instance = nullptr;
7777
// Mutex to protec this variable.
7878
std::mutex wait_for_server;
7979
std::condition_variable server_instance_cv;
@@ -98,7 +98,8 @@ void RunServer() {
9898
server_instance->Wait();
9999
}
100100

101-
template<class Builder> void StoreRPC(MonsterStorage::Stub *stub) {
101+
template <class Builder>
102+
void StoreRPC(MonsterStorage::Stub* stub) {
102103
Builder fbb;
103104
grpc::ClientContext context;
104105
// Build a request with the name set.
@@ -119,7 +120,8 @@ template<class Builder> void StoreRPC(MonsterStorage::Stub *stub) {
119120
}
120121
}
121122

122-
template<class Builder> void RetrieveRPC(MonsterStorage::Stub *stub) {
123+
template <class Builder>
124+
void RetrieveRPC(MonsterStorage::Stub* stub) {
123125
Builder fbb;
124126
grpc::ClientContext context;
125127
fbb.Clear();
@@ -179,7 +181,7 @@ int grpc_server_test() {
179181
return 0;
180182
}
181183

182-
int main(int /*argc*/, const char * /*argv*/[]) {
184+
int main(int /*argc*/, const char* /*argv*/[]) {
183185
message_builder_tests();
184186
grpc_server_test();
185187

grpc/tests/grpctest_callback_client_compile.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,43 @@ using namespace MyGame::Example; // NOLINT
1515
// Unary async overloads
1616
static_assert(std::is_member_function_pointer<
1717
decltype(static_cast<void (Stub::*)(
18-
::grpc::ClientContext *,
19-
const flatbuffers::grpc::Message<Monster> &,
20-
flatbuffers::grpc::Message<Stat> *,
18+
::grpc::ClientContext*,
19+
const flatbuffers::grpc::Message<Monster>&,
20+
flatbuffers::grpc::Message<Stat>*,
2121
std::function<void(::grpc::Status)>)>(
2222
&Stub::async_Store))>::value,
2323
"Function-form unary async_Store missing");
24-
static_assert(std::is_member_function_pointer<
25-
decltype(static_cast<void (Stub::*)(
26-
::grpc::ClientContext *,
27-
const flatbuffers::grpc::Message<Monster> &,
28-
flatbuffers::grpc::Message<Stat> *,
29-
::grpc::ClientUnaryReactor *)>(
30-
&Stub::async_Store))>::value,
31-
"Reactor-form unary async_Store missing");
24+
static_assert(
25+
std::is_member_function_pointer<
26+
decltype(static_cast<void (Stub::*)(
27+
::grpc::ClientContext*,
28+
const flatbuffers::grpc::Message<Monster>&,
29+
flatbuffers::grpc::Message<Stat>*,
30+
::grpc::ClientUnaryReactor*)>(&Stub::async_Store))>::value,
31+
"Reactor-form unary async_Store missing");
3232

3333
// Streaming reactor entry points
3434
static_assert(
3535
std::is_member_function_pointer<
3636
decltype(static_cast<void (Stub::*)(
37-
::grpc::ClientContext *,
38-
const flatbuffers::grpc::Message<Stat> &,
37+
::grpc::ClientContext*,
38+
const flatbuffers::grpc::Message<Stat>&,
3939
::grpc::ClientReadReactor<flatbuffers::grpc::Message<
40-
Monster> > *)>(&Stub::async_Retrieve))>::value,
40+
Monster> >*)>(&Stub::async_Retrieve))>::value,
4141
"Server streaming reactor async_Retrieve missing");
4242
static_assert(
4343
std::is_member_function_pointer<
4444
decltype(static_cast<void (Stub::*)(
45-
::grpc::ClientContext *,
46-
flatbuffers::grpc::Message<Stat> *,
45+
::grpc::ClientContext*, flatbuffers::grpc::Message<Stat>*,
4746
::grpc::ClientWriteReactor<flatbuffers::grpc::Message<
48-
Monster> > *)>(&Stub::async_GetMaxHitPoint))>::value,
47+
Monster> >*)>(&Stub::async_GetMaxHitPoint))>::value,
4948
"Client streaming reactor async_GetMaxHitPoint missing");
5049
static_assert(std::is_member_function_pointer<
5150
decltype(static_cast<void (Stub::*)(
52-
::grpc::ClientContext *,
51+
::grpc::ClientContext*,
5352
::grpc::ClientBidiReactor<
5453
flatbuffers::grpc::Message<Monster>,
55-
flatbuffers::grpc::Message<Stat> > *)>(
54+
flatbuffers::grpc::Message<Stat> >*)>(
5655
&Stub::async_GetMinMaxHitPoints))>::value,
5756
"Bidi streaming reactor async_GetMinMaxHitPoints missing");
5857
#endif // FLATBUFFERS_GENERATED_GRPC_CALLBACK_API &&

grpc/tests/message_builder_test.cpp

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ using MyGame::Example::Any_NONE;
77
using MyGame::Example::CreateStat;
88
using MyGame::Example::Vec3;
99

10-
bool verify(flatbuffers::grpc::Message<Monster> &msg,
11-
const std::string &expected_name, Color expected_color) {
12-
const Monster *monster = msg.GetRoot();
10+
bool verify(flatbuffers::grpc::Message<Monster>& msg,
11+
const std::string& expected_name, Color expected_color) {
12+
const Monster* monster = msg.GetRoot();
1313
const auto name = monster->name()->str();
1414
const auto color = monster->color();
1515
TEST_EQ(name, expected_name);
1616
TEST_EQ(color, expected_color);
1717
return (name == expected_name) && (color == expected_color);
1818
}
1919

20-
bool release_n_verify(flatbuffers::grpc::MessageBuilder &mbb,
21-
const std::string &expected_name, Color expected_color) {
20+
bool release_n_verify(flatbuffers::grpc::MessageBuilder& mbb,
21+
const std::string& expected_name, Color expected_color) {
2222
flatbuffers::grpc::Message<Monster> msg = mbb.ReleaseMessage<Monster>();
2323
return verify(msg, expected_name, expected_color);
2424
}
@@ -41,11 +41,13 @@ void builder_move_assign_after_releaseraw_test(
4141
TEST_EQ(src.GetSize(), 0);
4242
}
4343

44-
template<class SrcBuilder>
44+
template <class SrcBuilder>
4545
struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
4646
static void builder_reusable_after_release_message_test(
4747
TestSelector selector) {
48-
if (!selector.count(REUSABLE_AFTER_RELEASE_MESSAGE)) { return; }
48+
if (!selector.count(REUSABLE_AFTER_RELEASE_MESSAGE)) {
49+
return;
50+
}
4951

5052
flatbuffers::grpc::MessageBuilder mb;
5153
std::vector<flatbuffers::grpc::Message<Monster>> buffers;
@@ -58,7 +60,9 @@ struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
5860
}
5961

6062
static void builder_reusable_after_release_test(TestSelector selector) {
61-
if (!selector.count(REUSABLE_AFTER_RELEASE)) { return; }
63+
if (!selector.count(REUSABLE_AFTER_RELEASE)) {
64+
return;
65+
}
6266

6367
// FIXME: Populate-Release loop fails assert(GRPC_SLICE_IS_EMPTY(slice_)) in
6468
// SliceAllocator::allocate in the second iteration.
@@ -74,22 +78,26 @@ struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
7478
}
7579

7680
static void builder_reusable_after_releaseraw_test(TestSelector selector) {
77-
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW)) { return; }
81+
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW)) {
82+
return;
83+
}
7884

7985
flatbuffers::grpc::MessageBuilder mb;
8086
for (int i = 0; i < 5; ++i) {
8187
auto root_offset1 = populate1(mb);
8288
mb.Finish(root_offset1);
8389
size_t size, offset;
8490
::grpc::Slice slice;
85-
const uint8_t *buf = mb.ReleaseRaw(size, offset, slice);
91+
const uint8_t* buf = mb.ReleaseRaw(size, offset, slice);
8692
TEST_ASSERT_FUNC(verify(buf, offset, m1_name(), m1_color()));
8793
}
8894
}
8995

9096
static void builder_reusable_after_release_and_move_assign_test(
9197
TestSelector selector) {
92-
if (!selector.count(REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN)) { return; }
98+
if (!selector.count(REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN)) {
99+
return;
100+
}
93101

94102
// FIXME: Release-move_assign loop fails assert(p ==
95103
// GRPC_SLICE_START_PTR(slice_)) in DetachedBuffer destructor after all the
@@ -137,15 +145,17 @@ struct BuilderReuseTests<flatbuffers::grpc::MessageBuilder, SrcBuilder> {
137145

138146
static void builder_reusable_after_releaseraw_and_move_assign_test(
139147
TestSelector selector) {
140-
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN)) { return; }
148+
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN)) {
149+
return;
150+
}
141151

142152
flatbuffers::grpc::MessageBuilder dst;
143153
for (int i = 0; i < 5; ++i) {
144154
auto root_offset1 = populate1(dst);
145155
dst.Finish(root_offset1);
146156
size_t size, offset;
147157
::grpc::Slice slice;
148-
const uint8_t *buf = dst.ReleaseRaw(size, offset, slice);
158+
const uint8_t* buf = dst.ReleaseRaw(size, offset, slice);
149159
TEST_ASSERT_FUNC(verify(buf, offset, m1_name(), m1_color()));
150160

151161
SrcBuilder src;
@@ -170,7 +180,7 @@ void slice_allocator_tests() {
170180
{
171181
size_t size = 2048;
172182
flatbuffers::grpc::SliceAllocator sa1;
173-
uint8_t *buf = sa1.allocate(size);
183+
uint8_t* buf = sa1.allocate(size);
174184
TEST_ASSERT_FUNC(buf != 0);
175185
buf[0] = 100;
176186
buf[size - 1] = 200;
@@ -184,7 +194,7 @@ void slice_allocator_tests() {
184194
// move-assign test
185195
{
186196
flatbuffers::grpc::SliceAllocator sa1, sa2;
187-
uint8_t *buf = sa1.allocate(2048);
197+
uint8_t* buf = sa1.allocate(2048);
188198
sa1 = std::move(sa2);
189199
// sa1 deletes previously allocated memory in move-assign.
190200
// So buf is no longer usable here.
@@ -194,15 +204,15 @@ void slice_allocator_tests() {
194204

195205
/// This function does not populate exactly the first half of the table. But it
196206
/// could.
197-
void populate_first_half(MyGame::Example::MonsterBuilder &wrapper,
207+
void populate_first_half(MyGame::Example::MonsterBuilder& wrapper,
198208
flatbuffers::Offset<flatbuffers::String> name_offset) {
199209
wrapper.add_name(name_offset);
200210
wrapper.add_color(m1_color());
201211
}
202212

203213
/// This function does not populate exactly the second half of the table. But it
204214
/// could.
205-
void populate_second_half(MyGame::Example::MonsterBuilder &wrapper) {
215+
void populate_second_half(MyGame::Example::MonsterBuilder& wrapper) {
206216
wrapper.add_hp(77);
207217
wrapper.add_mana(88);
208218
Vec3 vec3;
@@ -216,9 +226,9 @@ void populate_second_half(MyGame::Example::MonsterBuilder &wrapper) {
216226
/// between FlatBufferBuilders. If MonsterBuilder had a fbb_ pointer, this hack
217227
/// would be unnecessary. That involves a code-generator change though.
218228
void test_only_hack_update_fbb_reference(
219-
MyGame::Example::MonsterBuilder &monsterBuilder,
220-
flatbuffers::grpc::MessageBuilder &mb) {
221-
*reinterpret_cast<flatbuffers::FlatBufferBuilder **>(&monsterBuilder) = &mb;
229+
MyGame::Example::MonsterBuilder& monsterBuilder,
230+
flatbuffers::grpc::MessageBuilder& mb) {
231+
*reinterpret_cast<flatbuffers::FlatBufferBuilder**>(&monsterBuilder) = &mb;
222232
}
223233

224234
/// This test validates correctness of move conversion of FlatBufferBuilder to a
@@ -351,15 +361,14 @@ void message_builder_tests() {
351361
BuilderTests<MessageBuilder, FlatBufferBuilder>::all_tests();
352362

353363
BuilderReuseTestSelector tests[6] = {
354-
// REUSABLE_AFTER_RELEASE, // Assertion failed:
355-
// (GRPC_SLICE_IS_EMPTY(slice_))
356-
// REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN, // Assertion failed: (p ==
357-
// GRPC_SLICE_START_PTR(slice_)
358-
359-
REUSABLE_AFTER_RELEASE_RAW, REUSABLE_AFTER_RELEASE_MESSAGE,
360-
REUSABLE_AFTER_RELEASE_MESSAGE_AND_MOVE_ASSIGN,
361-
REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN
362-
};
364+
// REUSABLE_AFTER_RELEASE, // Assertion failed:
365+
// (GRPC_SLICE_IS_EMPTY(slice_))
366+
// REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN, // Assertion failed: (p ==
367+
// GRPC_SLICE_START_PTR(slice_)
368+
369+
REUSABLE_AFTER_RELEASE_RAW, REUSABLE_AFTER_RELEASE_MESSAGE,
370+
REUSABLE_AFTER_RELEASE_MESSAGE_AND_MOVE_ASSIGN,
371+
REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN};
363372

364373
BuilderReuseTests<MessageBuilder, MessageBuilder>::run_tests(
365374
TestSelector(tests, tests + 6));

0 commit comments

Comments
 (0)