summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/ContinuationIndenter.h
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-10-30 14:01:50 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-10-30 14:01:50 +0000
commit9ad83fe7f64dbb7f2bebafa8e9b7637f98de8c8d (patch)
tree872a89f5225814bbfa0b4000f9f638f49c962f79 /clang/lib/Format/ContinuationIndenter.h
parent5cde1ccb2998fe06e3930c1d5a8f3c4fb93e845d (diff)
downloadbcm5719-llvm-9ad83fe7f64dbb7f2bebafa8e9b7637f98de8c8d.tar.gz
bcm5719-llvm-9ad83fe7f64dbb7f2bebafa8e9b7637f98de8c8d.zip
[clang-format] Format raw string literals
Summary: This patch adds raw string literal formatting. Reviewers: djasper, klimek Reviewed By: klimek Subscribers: klimek, mgorny Differential Revision: https://reviews.llvm.org/D35943 llvm-svn: 316903
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.h')
-rw-r--r--clang/lib/Format/ContinuationIndenter.h37
1 files changed, 30 insertions, 7 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.h b/clang/lib/Format/ContinuationIndenter.h
index 631129c1ea1..3bc9929b3df 100644
--- a/clang/lib/Format/ContinuationIndenter.h
+++ b/clang/lib/Format/ContinuationIndenter.h
@@ -20,6 +20,8 @@
#include "FormatToken.h"
#include "clang/Format/Format.h"
#include "llvm/Support/Regex.h"
+#include <map>
+#include <tuple>
namespace clang {
class SourceManager;
@@ -30,8 +32,17 @@ class AnnotatedLine;
struct FormatToken;
struct LineState;
struct ParenState;
+struct RawStringFormatStyleManager;
class WhitespaceManager;
+struct RawStringFormatStyleManager {
+ llvm::StringMap<FormatStyle> DelimiterStyle;
+
+ RawStringFormatStyleManager(const FormatStyle &CodeStyle);
+
+ llvm::Optional<FormatStyle> get(StringRef Delimiter) const;
+};
+
class ContinuationIndenter {
public:
/// \brief Constructs a \c ContinuationIndenter to format \p Line starting in
@@ -44,9 +55,11 @@ public:
bool BinPackInconclusiveFunctions);
/// \brief Get the initial state, i.e. the state after placing \p Line's
- /// first token at \p FirstIndent.
- LineState getInitialState(unsigned FirstIndent, const AnnotatedLine *Line,
- bool DryRun);
+ /// first token at \p FirstIndent. When reformatting a fragment of code, as in
+ /// the case of formatting inside raw string literals, \p FirstStartColumn is
+ /// the column at which the state of the parent formatter is.
+ LineState getInitialState(unsigned FirstIndent, unsigned FirstStartColumn,
+ const AnnotatedLine *Line, bool DryRun);
// FIXME: canBreak and mustBreak aren't strictly indentation-related. Find a
// better home.
@@ -88,15 +101,24 @@ private:
/// \brief Update 'State' with the next token opening a nested block.
void moveStateToNewBlock(LineState &State);
+ /// \brief Reformats a raw string literal.
+ ///
+ /// \returns An extra penalty induced by reformatting the token.
+ unsigned reformatRawStringLiteral(const FormatToken &Current,
+ unsigned StartColumn, LineState &State,
+ StringRef Delimiter,
+ const FormatStyle &RawStringStyle,
+ bool DryRun);
+
/// \brief If the current token sticks out over the end of the line, break
/// it if possible.
///
/// \returns An extra penalty if a token was broken, otherwise 0.
///
- /// The returned penalty will cover the cost of the additional line breaks and
- /// column limit violation in all lines except for the last one. The penalty
- /// for the column limit violation in the last line (and in single line
- /// tokens) is handled in \c addNextStateToQueue.
+ /// The returned penalty will cover the cost of the additional line breaks
+ /// and column limit violation in all lines except for the last one. The
+ /// penalty for the column limit violation in the last line (and in single
+ /// line tokens) is handled in \c addNextStateToQueue.
unsigned breakProtrudingToken(const FormatToken &Current, LineState &State,
bool DryRun);
@@ -143,6 +165,7 @@ private:
encoding::Encoding Encoding;
bool BinPackInconclusiveFunctions;
llvm::Regex CommentPragmasRegex;
+ const RawStringFormatStyleManager RawStringFormats;
};
struct ParenState {
OpenPOWER on IntegriCloud