Skip to content

Commit ce779b3

Browse files
authored
Allow clang-format to indent preprocessor directives (UniversalRobots#246)
Our current clang-format structure does not allow indenting preprocessor directives. As there might be more of them coming up, I'd like to add an auto-format rule for those.
1 parent 25d81bf commit ce779b3

File tree

3 files changed

+113
-115
lines changed

3 files changed

+113
-115
lines changed

.clang-format

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,64 @@
11
---
2-
BasedOnStyle: Google
32
AccessModifierOffset: -2
4-
ConstructorInitializerIndentWidth: 2
53
AlignEscapedNewlinesLeft: false
64
AlignTrailingComments: true
75
AllowAllParametersOfDeclarationOnNextLine: false
6+
AllowShortFunctionsOnASingleLine: None
87
AllowShortIfStatementsOnASingleLine: false
98
AllowShortLoopsOnASingleLine: false
10-
AllowShortFunctionsOnASingleLine: None
11-
AlwaysBreakTemplateDeclarations: true
129
AlwaysBreakBeforeMultilineStrings: false
10+
AlwaysBreakTemplateDeclarations: true
11+
BasedOnStyle: Google
12+
BinPackParameters: true
13+
14+
BraceWrapping: # Control of individual brace wrapping cases
15+
AfterCaseLabel: 'true'
16+
AfterClass: 'true'
17+
AfterControlStatement: 'true'
18+
AfterEnum: 'true'
19+
AfterFunction: 'true'
20+
AfterNamespace: 'true'
21+
AfterStruct: 'true'
22+
AfterUnion: 'true'
23+
BeforeCatch: 'true'
24+
BeforeElse: 'true'
25+
IndentBraces: 'false'
26+
1327
BreakBeforeBinaryOperators: false
1428
BreakBeforeTernaryOperators: false
1529
BreakConstructorInitializersBeforeComma: true
16-
BinPackParameters: true
17-
ColumnLimit: 120
30+
BreakBeforeBraces: Custom # Configure each individual brace in BraceWrapping
31+
32+
ColumnLimit: 120
1833
ConstructorInitializerAllOnOneLineOrOnePerLine: true
34+
ConstructorInitializerIndentWidth: 2
35+
ContinuationIndentWidth: 4
36+
Cpp11BracedListStyle: false
1937
DerivePointerBinding: false
20-
PointerBindsToType: true
2138
ExperimentalAutoDetectBinPacking: false
2239
IndentCaseLabels: true
40+
IndentFunctionDeclarationAfterType: false
41+
IndentPPDirectives: AfterHash
42+
IndentWidth: 2
2343
MaxEmptyLinesToKeep: 1
2444
NamespaceIndentation: None
2545
ObjCSpaceBeforeProtocolList: true
2646
PenaltyBreakBeforeFirstCallParameter: 19
2747
PenaltyBreakComment: 60
28-
PenaltyBreakString: 1
2948
PenaltyBreakFirstLessLess: 1000
49+
PenaltyBreakString: 1
3050
PenaltyExcessCharacter: 1000
3151
PenaltyReturnTypeOnItsOwnLine: 90
32-
SpacesBeforeTrailingComments: 2
33-
Cpp11BracedListStyle: false
34-
Standard: Auto
35-
IndentWidth: 2
36-
TabWidth: 2
37-
UseTab: Never
38-
IndentFunctionDeclarationAfterType: false
39-
SpacesInParentheses: false
40-
SpacesInAngles: false
41-
SpaceInEmptyParentheses: false
42-
SpacesInCStyleCastParentheses: false
43-
SpaceAfterControlStatementKeyword: true
44-
SpaceBeforeAssignmentOperators: true
45-
ContinuationIndentWidth: 4
52+
PointerBindsToType: true
4653
SortIncludes: false
4754
SpaceAfterCStyleCast: false
48-
49-
# Configure each individual brace in BraceWrapping
50-
BreakBeforeBraces: Custom
51-
52-
# Control of individual brace wrapping cases
53-
BraceWrapping: {
54-
AfterCaseLabel: 'true'
55-
AfterClass: 'true'
56-
AfterControlStatement: 'true'
57-
AfterEnum : 'true'
58-
AfterFunction : 'true'
59-
AfterNamespace : 'true'
60-
AfterStruct : 'true'
61-
AfterUnion : 'true'
62-
BeforeCatch : 'true'
63-
BeforeElse : 'true'
64-
IndentBraces : 'false'
65-
}
66-
...
55+
SpaceAfterControlStatementKeyword: true
56+
SpaceBeforeAssignmentOperators: true
57+
SpaceInEmptyParentheses: false
58+
SpacesBeforeTrailingComments: 2
59+
SpacesInAngles: false
60+
SpacesInCStyleCastParentheses: false
61+
SpacesInParentheses: false
62+
Standard: Auto
63+
TabWidth: 2
64+
UseTab: Never

include/ur_client_library/queue/atomicops.h

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,46 @@
1919

2020
// Platform detection
2121
#if defined(__INTEL_COMPILER)
22-
#define AE_ICC
22+
# define AE_ICC
2323
#elif defined(_MSC_VER)
24-
#define AE_VCPP
24+
# define AE_VCPP
2525
#elif defined(__GNUC__)
26-
#define AE_GCC
26+
# define AE_GCC
2727
#endif
2828

2929
#if defined(_M_IA64) || defined(__ia64__)
30-
#define AE_ARCH_IA64
30+
# define AE_ARCH_IA64
3131
#elif defined(_WIN64) || defined(__amd64__) || defined(_M_X64) || defined(__x86_64__)
32-
#define AE_ARCH_X64
32+
# define AE_ARCH_X64
3333
#elif defined(_M_IX86) || defined(__i386__)
34-
#define AE_ARCH_X86
34+
# define AE_ARCH_X86
3535
#elif defined(_M_PPC) || defined(__powerpc__)
36-
#define AE_ARCH_PPC
36+
# define AE_ARCH_PPC
3737
#else
38-
#define AE_ARCH_UNKNOWN
38+
# define AE_ARCH_UNKNOWN
3939
#endif
4040

4141
// AE_UNUSED
4242
#define AE_UNUSED(x) ((void)x)
4343

4444
// AE_FORCEINLINE
4545
#if defined(AE_VCPP) || defined(AE_ICC)
46-
#define AE_FORCEINLINE __forceinline
46+
# define AE_FORCEINLINE __forceinline
4747
#elif defined(AE_GCC)
4848
// #define AE_FORCEINLINE __attribute__((always_inline))
49-
#define AE_FORCEINLINE inline
49+
# define AE_FORCEINLINE inline
5050
#else
51-
#define AE_FORCEINLINE inline
51+
# define AE_FORCEINLINE inline
5252
#endif
5353

5454
// AE_ALIGN
5555
#if defined(AE_VCPP) || defined(AE_ICC)
56-
#define AE_ALIGN(x) __declspec(align(x))
56+
# define AE_ALIGN(x) __declspec(align(x))
5757
#elif defined(AE_GCC)
58-
#define AE_ALIGN(x) __attribute__((aligned(x)))
58+
# define AE_ALIGN(x) __attribute__((aligned(x)))
5959
#else
6060
// Assume GCC compliant syntax...
61-
#define AE_ALIGN(x) __attribute__((aligned(x)))
61+
# define AE_ALIGN(x) __attribute__((aligned(x)))
6262
#endif
6363

6464
// Portable atomic fences implemented below:
@@ -83,28 +83,28 @@ enum memory_order
8383
#if (defined(AE_VCPP) && (_MSC_VER < 1700 || defined(__cplusplus_cli))) || defined(AE_ICC)
8484
// VS2010 and ICC13 don't support std::atomic_*_fence, implement our own fences
8585

86-
#include <intrin.h>
87-
88-
#if defined(AE_ARCH_X64) || defined(AE_ARCH_X86)
89-
#define AeFullSync _mm_mfence
90-
#define AeLiteSync _mm_mfence
91-
#elif defined(AE_ARCH_IA64)
92-
#define AeFullSync __mf
93-
#define AeLiteSync __mf
94-
#elif defined(AE_ARCH_PPC)
95-
#include <ppcintrinsics.h>
96-
#define AeFullSync __sync
97-
#define AeLiteSync __lwsync
98-
#endif
99-
100-
#ifdef AE_VCPP
101-
#pragma warning(push)
102-
#pragma warning(disable : 4365) // Disable erroneous 'conversion from long to unsigned int, signed/unsigned mismatch'
103-
// error when using `assert`
104-
#ifdef __cplusplus_cli
105-
#pragma managed(push, off)
106-
#endif
107-
#endif
86+
# include <intrin.h>
87+
88+
# if defined(AE_ARCH_X64) || defined(AE_ARCH_X86)
89+
# define AeFullSync _mm_mfence
90+
# define AeLiteSync _mm_mfence
91+
# elif defined(AE_ARCH_IA64)
92+
# define AeFullSync __mf
93+
# define AeLiteSync __mf
94+
# elif defined(AE_ARCH_PPC)
95+
# include <ppcintrinsics.h>
96+
# define AeFullSync __sync
97+
# define AeLiteSync __lwsync
98+
# endif
99+
100+
# ifdef AE_VCPP
101+
# pragma warning(push)
102+
# pragma warning(disable : 4365) // Disable erroneous 'conversion from long to unsigned int, signed/unsigned
103+
// mismatch' error when using `assert`
104+
# ifdef __cplusplus_cli
105+
# pragma managed(push, off)
106+
# endif
107+
# endif
108108

109109
namespace moodycamel
110110
{
@@ -134,7 +134,7 @@ AE_FORCEINLINE void compilerFence(memory_order order)
134134
// x86/x64 have a strong memory model -- all loads and stores have
135135
// acquire and release semantics automatically (so only need compiler
136136
// barriers for those).
137-
#if defined(AE_ARCH_X86) || defined(AE_ARCH_X64)
137+
# if defined(AE_ARCH_X86) || defined(AE_ARCH_X64)
138138
AE_FORCEINLINE void fence(memory_order order)
139139
{
140140
switch (order)
@@ -159,7 +159,7 @@ AE_FORCEINLINE void fence(memory_order order)
159159
assert(false);
160160
}
161161
}
162-
#else
162+
# else
163163
AE_FORCEINLINE void fence(memory_order order)
164164
{
165165
// Non-specialized arch, use heavier memory barriers everywhere just in case :-(
@@ -191,11 +191,11 @@ AE_FORCEINLINE void fence(memory_order order)
191191
assert(false);
192192
}
193193
}
194-
#endif
194+
# endif
195195
} // end namespace moodycamel
196196
#else
197197
// Use standard library of atomics
198-
#include <atomic>
198+
# include <atomic>
199199

200200
namespace moodycamel
201201
{
@@ -250,11 +250,11 @@ AE_FORCEINLINE void fence(memory_order order)
250250
#endif
251251

252252
#if !defined(AE_VCPP) || (_MSC_VER >= 1700 && !defined(__cplusplus_cli))
253-
#define AE_USE_STD_ATOMIC_FOR_WEAK_ATOMIC
253+
# define AE_USE_STD_ATOMIC_FOR_WEAK_ATOMIC
254254
#endif
255255

256256
#ifdef AE_USE_STD_ATOMIC_FOR_WEAK_ATOMIC
257-
#include <atomic>
257+
# include <atomic>
258258
#endif
259259
#include <utility>
260260

@@ -272,7 +272,7 @@ class WeakAtomic
272272
{
273273
}
274274
#ifdef AE_VCPP
275-
#pragma warning(disable : 4100) // Get rid of (erroneous) 'unreferenced formal parameter' warning
275+
# pragma warning(disable : 4100) // Get rid of (erroneous) 'unreferenced formal parameter' warning
276276
#endif
277277
template <typename U>
278278
WeakAtomic(U&& x) : value_(std::forward<U>(x))
@@ -291,7 +291,7 @@ class WeakAtomic
291291
{
292292
}
293293
#ifdef AE_VCPP
294-
#pragma warning(default : 4100)
294+
# pragma warning(default : 4100)
295295
#endif
296296

297297
AE_FORCEINLINE operator T() const
@@ -319,32 +319,32 @@ class WeakAtomic
319319

320320
AE_FORCEINLINE T fetchAddAcquire(T increment)
321321
{
322-
#if defined(AE_ARCH_X64) || defined(AE_ARCH_X86)
322+
# if defined(AE_ARCH_X64) || defined(AE_ARCH_X86)
323323
if (sizeof(T) == 4)
324324
return _InterlockedExchangeAdd((long volatile*)&value_, (long)increment);
325-
#if defined(_M_AMD64)
325+
# if defined(_M_AMD64)
326326
else if (sizeof(T) == 8)
327327
return _InterlockedExchangeAdd64((long long volatile*)&value_, (long long)increment);
328-
#endif
329-
#else
330-
#error Unsupported platform
331-
#endif
328+
# endif
329+
# else
330+
# error Unsupported platform
331+
# endif
332332
assert(false && "T must be either a 32 or 64 bit type");
333333
return value_;
334334
}
335335

336336
AE_FORCEINLINE T fetchAddRelease(T increment)
337337
{
338-
#if defined(AE_ARCH_X64) || defined(AE_ARCH_X86)
338+
# if defined(AE_ARCH_X64) || defined(AE_ARCH_X86)
339339
if (sizeof(T) == 4)
340340
return _InterlockedExchangeAdd((long volatile*)&value_, (long)increment);
341-
#if defined(_M_AMD64)
341+
# if defined(_M_AMD64)
342342
else if (sizeof(T) == 8)
343343
return _InterlockedExchangeAdd64((long long volatile*)&value_, (long long)increment);
344-
#endif
345-
#else
346-
#error Unsupported platform
347-
#endif
344+
# endif
345+
# else
346+
# error Unsupported platform
347+
# endif
348348
assert(false && "T must be either a 32 or 64 bit type");
349349
return value_;
350350
}
@@ -407,9 +407,9 @@ __declspec(dllimport) unsigned long __stdcall WaitForSingleObject(void* hHandle,
407407
__declspec(dllimport) int __stdcall ReleaseSemaphore(void* hSemaphore, long lReleaseCount, long* lpPreviousCount);
408408
}
409409
#elif defined(__MACH__)
410-
#include <mach/mach.h>
410+
# include <mach/mach.h>
411411
#elif defined(__unix__)
412-
#include <semaphore.h>
412+
# include <semaphore.h>
413413
#endif
414414

415415
namespace moodycamel
@@ -625,7 +625,7 @@ class Semaphore
625625
}
626626
};
627627
#else
628-
#error Unsupported platform! (No semaphore wrapper available)
628+
# error Unsupported platform! (No semaphore wrapper available)
629629
#endif
630630

631631
//---------------------------------------------------------
@@ -731,8 +731,8 @@ class LightweightSemaphore
731731
} // end namespace moodycamel
732732

733733
#if defined(AE_VCPP) && (_MSC_VER < 1700 || defined(__cplusplus_cli))
734-
#pragma warning(pop)
735-
#ifdef __cplusplus_cli
736-
#pragma managed(pop)
737-
#endif
734+
# pragma warning(pop)
735+
# ifdef __cplusplus_cli
736+
# pragma managed(pop)
737+
# endif
738738
#endif

0 commit comments

Comments
 (0)