summaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-06-12 02:50:04 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-06-12 02:50:04 +0000
commit7096fc133c10858858ab44ea040aa7bc9d06482e (patch)
tree90fc19aaeda8e21e154b9045cb042be8a6dd75ad /lib/Format/Format.cpp
parentf7c47be1c1bfb2b86ca32e5651fa809486c9729d (diff)
downloadclang-7096fc133c10858858ab44ea040aa7bc9d06482e.tar.gz
clang-7096fc133c10858858ab44ea040aa7bc9d06482e.tar.bz2
clang-7096fc133c10858858ab44ea040aa7bc9d06482e.tar.xz
Give clang-format its own error category.
The posix errno values are probably to the best thing to use for describing parse errors. This should also fix the mingw build. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210739 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index e3378d1446..d8633d88f1 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -258,6 +258,29 @@ template <> struct DocumentListTraits<std::vector<FormatStyle> > {
namespace clang {
namespace format {
+const std::error_category &getParestCategory() {
+ static ParseErrorCategory C;
+ return C;
+}
+std::error_code make_error_code(ParseError e) {
+ return std::error_code(static_cast<int>(e), getParestCategory());
+}
+
+const char *ParseErrorCategory::name() const LLVM_NOEXCEPT {
+ return "clang-format.parse_error";
+}
+
+std::string ParseErrorCategory::message(int EV) const {
+ switch (static_cast<ParseError>(EV)) {
+ case ParseError::Success:
+ return "Success";
+ case ParseError::Error:
+ return "Invalid argument";
+ case ParseError::Unsuitable:
+ return "Unsuitable";
+ }
+}
+
FormatStyle getLLVMStyle() {
FormatStyle LLVMStyle;
LLVMStyle.Language = FormatStyle::LK_Cpp;
@@ -447,7 +470,7 @@ llvm::error_code parseConfiguration(StringRef Text, FormatStyle *Style) {
FormatStyle::LanguageKind Language = Style->Language;
assert(Language != FormatStyle::LK_None);
if (Text.trim().empty())
- return llvm::make_error_code(std::errc::invalid_argument);
+ return make_error_code(ParseError::Error);
std::vector<FormatStyle> Styles;
llvm::yaml::Input Input(Text);
@@ -463,14 +486,14 @@ llvm::error_code parseConfiguration(StringRef Text, FormatStyle *Style) {
for (unsigned i = 0; i < Styles.size(); ++i) {
// Ensures that only the first configuration can skip the Language option.
if (Styles[i].Language == FormatStyle::LK_None && i != 0)
- return llvm::make_error_code(std::errc::invalid_argument);
+ return make_error_code(ParseError::Error);
// Ensure that each language is configured at most once.
for (unsigned j = 0; j < i; ++j) {
if (Styles[i].Language == Styles[j].Language) {
DEBUG(llvm::dbgs()
<< "Duplicate languages in the config file on positions " << j
<< " and " << i << "\n");
- return llvm::make_error_code(std::errc::invalid_argument);
+ return make_error_code(ParseError::Error);
}
}
}
@@ -482,10 +505,10 @@ llvm::error_code parseConfiguration(StringRef Text, FormatStyle *Style) {
Styles[i].Language == FormatStyle::LK_None) {
*Style = Styles[i];
Style->Language = Language;
- return llvm::error_code();
+ return make_error_code(ParseError::Success);
}
}
- return llvm::make_error_code(std::errc::not_supported);
+ return make_error_code(ParseError::Unsuitable);
}
std::string configurationAsText(const FormatStyle &Style) {
@@ -2049,7 +2072,7 @@ FormatStyle getStyle(StringRef StyleName, StringRef FileName,
break;
}
if (llvm::error_code ec = parseConfiguration(Text->getBuffer(), &Style)) {
- if (ec == std::errc::not_supported) {
+ if (ec == ParseError::Unsuitable) {
if (!UnsuitableConfigFiles.empty())
UnsuitableConfigFiles.append(", ");
UnsuitableConfigFiles.append(ConfigFile);