summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-11-13 16:25:37 +0000
committerNico Weber <nicolasweber@gmx.de>2014-11-13 16:25:37 +0000
commit34272657debfc462e0a1c4b77dd7a216309f72c2 (patch)
tree7b294e1c816bf85a4660102c0cc43275fc84ed23 /clang/lib/Format/Format.cpp
parent17072ef34813eb0a8f9dce4758167d78b504d1df (diff)
downloadbcm5719-llvm-34272657debfc462e0a1c4b77dd7a216309f72c2.tar.gz
bcm5719-llvm-34272657debfc462e0a1c4b77dd7a216309f72c2.zip
clang-format: Format extern "C" blocks like namespace blocks.
namespace blocks act as if KeepEmptyLinesAtTheStartOfBlocks is always true, and aren't collapsed to a single line even if they would fit. Do the same for extern "C" blocks. Before, extern "C" { void ExternCFunction(); } was collapsed into `extern "C" { void ExternCFunction(); }`. Now it stays like it was. Fixes http://crbug.com/432640 and part of PR21419. llvm-svn: 221897
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 8e4be3e053d..74adaf76056 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -574,6 +574,13 @@ std::string configurationAsText(const FormatStyle &Style) {
namespace {
+bool startsExternCBlock(const AnnotatedLine &Line) {
+ const FormatToken *Next = Line.First->getNextNonComment();
+ const FormatToken *NextNext = Next ? Next->getNextNonComment() : nullptr;
+ return Line.First->is(tok::kw_extern) && Next && Next->isStringLiteral() &&
+ NextNext && NextNext->is(tok::l_brace);
+}
+
class NoColumnLimitFormatter {
public:
NoColumnLimitFormatter(ContinuationIndenter *Indenter) : Indenter(Indenter) {}
@@ -785,7 +792,8 @@ private:
Tok->SpacesRequiredBefore = 0;
Tok->CanBreakBefore = true;
return 1;
- } else if (Limit != 0 && Line.First->isNot(tok::kw_namespace)) {
+ } else if (Limit != 0 && Line.First->isNot(tok::kw_namespace) &&
+ !startsExternCBlock(Line)) {
// We don't merge short records.
if (Line.First->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct))
return 0;
@@ -1069,7 +1077,8 @@ private:
// Remove empty lines after "{".
if (!Style.KeepEmptyLinesAtTheStartOfBlocks && PreviousLine &&
PreviousLine->Last->is(tok::l_brace) &&
- PreviousLine->First->isNot(tok::kw_namespace))
+ PreviousLine->First->isNot(tok::kw_namespace) &&
+ !startsExternCBlock(*PreviousLine))
Newlines = 1;
// Insert extra new line before access specifiers.
OpenPOWER on IntegriCloud