summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineFormatter.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2015-02-04 15:26:27 +0000
committerNico Weber <nicolasweber@gmx.de>2015-02-04 15:26:27 +0000
commitfac2371be324d6a3aa0c9622f5147abbc707894e (patch)
treeab2798e1ac869f49f56ecef6739680977cc1eefd /clang/lib/Format/UnwrappedLineFormatter.cpp
parente67d27f5ccebb22e238072afe0ea74bc3a7a653e (diff)
downloadbcm5719-llvm-fac2371be324d6a3aa0c9622f5147abbc707894e.tar.gz
bcm5719-llvm-fac2371be324d6a3aa0c9622f5147abbc707894e.zip
clang-format: Add support for SEH __try / __except / __finally blocks.
This lets clang-format format __try { } __except(0) { } and __try { } __finally { } correctly. __try and __finally are keywords if `LangOpts.MicrosoftExt` is set, so this turns this on. This also enables a few other keywords, but it shouldn't overly perturb regular clang-format operation. __except is a context-sensitive keyword, so `AdditionalKeywords` needs to be passed around to a few more places. Fixes PR22321. llvm-svn: 228148
Diffstat (limited to 'clang/lib/Format/UnwrappedLineFormatter.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 4844b66f9fd..0c744e493f0 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -27,7 +27,8 @@ bool startsExternCBlock(const AnnotatedLine &Line) {
class LineJoiner {
public:
- LineJoiner(const FormatStyle &Style) : Style(Style) {}
+ LineJoiner(const FormatStyle &Style, const AdditionalKeywords &Keywords)
+ : Style(Style), Keywords(Keywords) {}
/// \brief Calculates how many lines can be merged into 1 starting at \p I.
unsigned
@@ -200,7 +201,9 @@ private:
if (Line.First->isOneOf(tok::kw_else, tok::kw_case))
return 0;
if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try,
- tok::kw_catch, tok::kw_for, tok::r_brace)) {
+ tok::kw___try, tok::kw_catch, tok::kw___finally,
+ tok::kw_for, tok::r_brace) ||
+ Line.First->is(Keywords.kw___except)) {
if (!Style.AllowShortBlocksOnASingleLine)
return 0;
if (!Style.AllowShortIfStatementsOnASingleLine &&
@@ -211,7 +214,11 @@ private:
return 0;
// FIXME: Consider an option to allow short exception handling clauses on
// a single line.
- if (Line.First->isOneOf(tok::kw_try, tok::kw_catch))
+ // FIXME: This isn't covered by tests.
+ // FIXME: For catch, __except, __finally the first token on the line
+ // is '}', so this isn't correct here.
+ if (Line.First->isOneOf(tok::kw_try, tok::kw___try, tok::kw_catch,
+ Keywords.kw___except, tok::kw___finally))
return 0;
}
@@ -286,6 +293,7 @@ private:
}
const FormatStyle &Style;
+ const AdditionalKeywords &Keywords;
};
class NoColumnLimitFormatter {
@@ -324,7 +332,7 @@ unsigned
UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines,
bool DryRun, int AdditionalIndent,
bool FixBadIndentation) {
- LineJoiner Joiner(Style);
+ LineJoiner Joiner(Style, Keywords);
// Try to look up already computed penalty in DryRun-mode.
std::pair<const SmallVectorImpl<AnnotatedLine *> *, unsigned> CacheKey(
OpenPOWER on IntegriCloud