summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authormydeveloperday <mydeveloperday@gmail.com>2019-11-16 11:54:21 +0000
committerpaulhoad <mydeveloperday@gmail.com>2019-11-16 11:54:21 +0000
commita4a7c1259e8a8f2d11fa29686a6c2834948c1358 (patch)
treeab315a8d692d9765a93b2a2347774241779fbca2 /clang/lib
parent42effc106966d45053abdd4e3d03ecfe256869b5 (diff)
downloadbcm5719-llvm-a4a7c1259e8a8f2d11fa29686a6c2834948c1358.tar.gz
bcm5719-llvm-a4a7c1259e8a8f2d11fa29686a6c2834948c1358.zip
[clang-format] Add SpaceBeforeBrackets
Summary: Adds a new option SpaceBeforeBrackets to add spaces before brackets (i.e. int a[23]; -> int a [23];) This is present as an option in the Visual Studio C++ code formatting settings, but there was no matching setting in clang-format. Reviewers: djasper, MyDeveloperDay, mitchell-stellar Reviewed By: MyDeveloperDay Subscribers: llvm-commits, cfe-commits, klimek Patch by: Anteru Tags: #clang, #clang-format, #llvm Differential Revision: https://reviews.llvm.org/D6920
Diffstat (limited to 'clang/lib')
-rwxr-xr-x[-rw-r--r--]clang/lib/Format/Format.cpp12
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp4
2 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 083c3a8f02f..4e42bab5618 100644..100755
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -543,6 +543,8 @@ template <> struct MappingTraits<FormatStyle> {
Style.SpacesInCStyleCastParentheses);
IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
+ IO.mapOptional("SpaceBeforeSquareBrackets",
+ Style.SpaceBeforeSquareBrackets);
IO.mapOptional("Standard", Style.Standard);
IO.mapOptional("StatementMacros", Style.StatementMacros);
IO.mapOptional("TabWidth", Style.TabWidth);
@@ -813,6 +815,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.SpaceBeforeRangeBasedForLoopColon = true;
LLVMStyle.SpaceBeforeAssignmentOperators = true;
LLVMStyle.SpaceBeforeCpp11BracedList = false;
+ LLVMStyle.SpaceBeforeSquareBrackets = false;
LLVMStyle.SpacesInAngles = false;
LLVMStyle.PenaltyBreakAssignment = prec::Assignment;
@@ -1354,10 +1357,11 @@ public:
WhitespaceManager Whitespaces(
Env.getSourceManager(), Style,
- Style.DeriveLineEnding ?
- inputUsesCRLF(Env.getSourceManager().getBufferData(Env.getFileID()),
- Style.UseCRLF) :
- Style.UseCRLF);
+ Style.DeriveLineEnding
+ ? inputUsesCRLF(
+ Env.getSourceManager().getBufferData(Env.getFileID()),
+ Style.UseCRLF)
+ : Style.UseCRLF);
ContinuationIndenter Indenter(Style, Tokens.getKeywords(),
Env.getSourceManager(), Whitespaces, Encoding,
BinPackInconclusiveFunctions);
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index c5ed49e9a40..dcdc6e6e336 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2724,7 +2724,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
TT_DesignatedInitializerLSquare,
TT_StructuredBindingLSquare, TT_AttributeSquare) &&
- !Left.isOneOf(tok::numeric_constant, TT_DictLiteral))
+ !Left.isOneOf(tok::numeric_constant, TT_DictLiteral) &&
+ !(!Left.is(tok::r_square) && Style.SpaceBeforeSquareBrackets &&
+ Right.is(TT_ArraySubscriptLSquare)))
return false;
if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
return !Left.Children.empty(); // No spaces in "{}".
OpenPOWER on IntegriCloud