summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-09-05 14:08:34 +0000
committerAlexander Kornienko <alexfh@google.com>2013-09-05 14:08:34 +0000
commitebb43caae250d5d5f3f853392460456a0a58abb1 (patch)
tree29874d67e67d34dd9d144d1ad8a29c2de1906a8b /clang/lib/Format/Format.cpp
parent15832288f4feac7abfbccdbb567a7cd456913ae5 (diff)
downloadbcm5719-llvm-ebb43caae250d5d5f3f853392460456a0a58abb1.tar.gz
bcm5719-llvm-ebb43caae250d5d5f3f853392460456a0a58abb1.zip
Handle zero-width and double-width characters in string literals and comments.
Summary: Count column width instead of the number of code points. This also includes correct handling of tabs inside string literals and comments (with an exception of multiline string literals/comments, where tabs are present before the first escaped newline). Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1601 llvm-svn: 190052
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c482c402ec8..02adc5acd6b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -136,6 +136,7 @@ template <> struct MappingTraits<clang::format::FormatStyle> {
IO.mapOptional("Cpp11BracedListStyle", Style.Cpp11BracedListStyle);
IO.mapOptional("Standard", Style.Standard);
IO.mapOptional("IndentWidth", Style.IndentWidth);
+ IO.mapOptional("TabWidth", Style.TabWidth);
IO.mapOptional("UseTab", Style.UseTab);
IO.mapOptional("BreakBeforeBraces", Style.BreakBeforeBraces);
IO.mapOptional("IndentFunctionDeclarationAfterType",
@@ -184,6 +185,7 @@ FormatStyle getLLVMStyle() {
LLVMStyle.IndentCaseLabels = false;
LLVMStyle.IndentFunctionDeclarationAfterType = false;
LLVMStyle.IndentWidth = 2;
+ LLVMStyle.TabWidth = 8;
LLVMStyle.MaxEmptyLinesToKeep = 1;
LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
@@ -225,6 +227,7 @@ FormatStyle getGoogleStyle() {
GoogleStyle.IndentCaseLabels = true;
GoogleStyle.IndentFunctionDeclarationAfterType = true;
GoogleStyle.IndentWidth = 2;
+ GoogleStyle.TabWidth = 8;
GoogleStyle.MaxEmptyLinesToKeep = 1;
GoogleStyle.NamespaceIndentation = FormatStyle::NI_None;
GoogleStyle.ObjCSpaceBeforeProtocolList = false;
@@ -629,7 +632,7 @@ private:
++Column;
break;
case '\t':
- Column += Style.IndentWidth - Column % Style.IndentWidth;
+ Column += Style.TabWidth - Column % Style.TabWidth;
break;
default:
++Column;
@@ -681,10 +684,12 @@ private:
StringRef Text = FormatTok->TokenText;
size_t FirstNewlinePos = Text.find('\n');
if (FirstNewlinePos != StringRef::npos) {
- FormatTok->CodePointsInFirstLine = encoding::getCodePointCount(
- Text.substr(0, FirstNewlinePos), Encoding);
- FormatTok->CodePointsInLastLine = encoding::getCodePointCount(
- Text.substr(Text.find_last_of('\n') + 1), Encoding);
+ // FIXME: Handle embedded tabs.
+ FormatTok->FirstLineColumnWidth = encoding::columnWidthWithTabs(
+ Text.substr(0, FirstNewlinePos), 0, Style.TabWidth, Encoding);
+ FormatTok->LastLineColumnWidth = encoding::columnWidthWithTabs(
+ Text.substr(Text.find_last_of('\n') + 1), 0, Style.TabWidth,
+ Encoding);
}
}
// FIXME: Add the CodePointCount to Column.
OpenPOWER on IntegriCloud