summaryrefslogtreecommitdiffstats
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2018-06-25 16:29:19 +0000
committerEric Liu <ioeric@google.com>2018-06-25 16:29:19 +0000
commite0e097a759cc3c58306d8201dcc4e2f5fcc84e63 (patch)
tree0d354c7492685189b16d0d6068ca715f86777e05 /lib/Format/Format.cpp
parenta605c7e73552ba349e2ceb5baa8daba92d9faf98 (diff)
[clang-format] Add a default format style that can be used by users of `getStyle`
Summary: Tools that reformat code often call `getStyle` to decide the format style to use on a certain source file. In practice, "file" style is widely used. As a result, many tools hardcode "file" when calling `getStyle`, which makes it hard to control the default style in tools across a codebase when needed. This change introduces a `DefaultFormatStyle` constant (default to "file" in upstream), which can be modified downstream if wanted, so that all users/tools built from the same source tree can have a consistent default format style. This also adds an DefaultFallbackStyle that is recommended to be used by tools and can be modified downstream. Reviewers: sammccall, djasper Reviewed By: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48492 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335492 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 76dfc81950..374c25064a 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -2144,6 +2144,10 @@ FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
return GuessedLanguage;
}
+const char *DefaultFormatStyle = "file";
+
+const char *DefaultFallbackStyle = "LLVM";
+
llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
StringRef FallbackStyleName,
StringRef Code, vfs::FileSystem *FS) {