[PATCH] D93633: [format] Add overload to parseConfiguration that accept llvm::MemoryBufferRef
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 23 04:08:46 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb9483b21053: [format] Add overload to parseConfiguration that accept llvm::MemoryBufferRef (authored by njames93).
Changed prior to commit:
https://reviews.llvm.org/D93633?vs=313096&id=313530#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93633/new/
https://reviews.llvm.org/D93633
Files:
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/test/Format/error-config.cpp
Index: clang/test/Format/error-config.cpp
===================================================================
--- clang/test/Format/error-config.cpp
+++ clang/test/Format/error-config.cpp
@@ -1,10 +1,10 @@
// RUN: clang-format %s --Wno-error=unknown --style="{UnknownKey: true}" 2>&1 | FileCheck %s -check-prefix=CHECK
// RUN: not clang-format %s --style="{UnknownKey: true}" 2>&1 | FileCheck %s -check-prefix=CHECK-FAIL
-// CHECK: YAML:1:2: warning: unknown key 'UnknownKey'
+// CHECK: <command-line>:1:2: warning: unknown key 'UnknownKey'
// CHECK-NEXT: {UnknownKey: true}
// CHECK-NEXT: ^~~~~~~~~~
-// CHECK-FAIL: YAML:1:2: error: unknown key 'UnknownKey'
+// CHECK-FAIL: <command-line>:1:2: error: unknown key 'UnknownKey'
// CHECK-FAIL-NEXT: {UnknownKey: true}
// CHECK-FAIL-NEXT: ^~~~~~~~~~
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1327,16 +1327,17 @@
return true;
}
-std::error_code parseConfiguration(StringRef Text, FormatStyle *Style,
+std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
+ FormatStyle *Style,
bool AllowUnknownOptions) {
assert(Style);
FormatStyle::LanguageKind Language = Style->Language;
assert(Language != FormatStyle::LK_None);
- if (Text.trim().empty())
+ if (Config.getBuffer().trim().empty())
return make_error_code(ParseError::Error);
Style->StyleSet.Clear();
std::vector<FormatStyle> Styles;
- llvm::yaml::Input Input(Text);
+ llvm::yaml::Input Input(Config);
// DocumentListTraits<vector<FormatStyle>> uses the context to get default
// values for the fields, keys for which are missing from the configuration.
// Mapping also uses the context to get the language to find the correct
@@ -2864,8 +2865,9 @@
if (StyleName.startswith("{")) {
// Parse YAML/JSON style from the command line.
- if (std::error_code ec =
- parseConfiguration(StyleName, &Style, AllowUnknownOptions))
+ if (std::error_code ec = parseConfiguration(
+ llvm::MemoryBufferRef(StyleName, "<command-line>"), &Style,
+ AllowUnknownOptions))
return make_string_error("Error parsing -style: " + ec.message());
return Style;
}
@@ -2909,8 +2911,8 @@
FS->getBufferForFile(ConfigFile.str());
if (std::error_code EC = Text.getError())
return make_string_error(EC.message());
- if (std::error_code ec = parseConfiguration(
- Text.get()->getBuffer(), &Style, AllowUnknownOptions)) {
+ if (std::error_code ec =
+ parseConfiguration(*Text.get(), &Style, AllowUnknownOptions)) {
if (ec == ParseError::Unsuitable) {
if (!UnsuitableConfigFiles.empty())
UnsuitableConfigFiles.append(", ");
Index: clang/include/clang/Format/Format.h
===================================================================
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -2879,7 +2879,8 @@
private:
FormatStyleSet StyleSet;
- friend std::error_code parseConfiguration(StringRef Text, FormatStyle *Style,
+ friend std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
+ FormatStyle *Style,
bool AllowUnknownOptions);
};
@@ -2938,9 +2939,17 @@
///
/// If AllowUnknownOptions is true, no errors are emitted if unknown
/// format options are occured.
-std::error_code parseConfiguration(StringRef Text, FormatStyle *Style,
+std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
+ FormatStyle *Style,
bool AllowUnknownOptions = false);
+/// Like above but accepts an unnamed buffer.
+inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
+ bool AllowUnknownOptions = false) {
+ return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
+ AllowUnknownOptions);
+}
+
/// Gets configuration in a YAML string.
std::string configurationAsText(const FormatStyle &Style);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93633.313530.patch
Type: text/x-patch
Size: 4314 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201223/8c44b576/attachment.bin>
More information about the cfe-commits
mailing list