amaiorano created this revision.
amaiorano added reviewers: ioeric, cfe-commits, klimek, djasper.
See https://reviews.llvm.org/D28081 for the changes to getStyle
This change will be committed right after https://reviews.llvm.org/D28081.
https://reviews.llvm.org/D28315
Files:
change-namespace/ChangeNamespace.cpp
clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
clang-move/ClangMove.cpp
clang-tidy/ClangTidy.cpp
include-fixer/tool/ClangIncludeFixer.cpp
Index: include-fixer/tool/ClangIncludeFixer.cpp
===================================================================
--- include-fixer/tool/ClangIncludeFixer.cpp
+++ include-fixer/tool/ClangIncludeFixer.cpp
@@ -297,10 +297,13 @@
const IncludeFixerContext::HeaderInfo &RHS) {
return LHS.QualifiedName == RHS.QualifiedName;
});
- format::FormatStyle InsertStyle =
- format::getStyle("file", Context.getFilePath(), Style);
+ auto InsertStyle = format::getStyle("file", Context.getFilePath(), Style);
+ if (!InsertStyle) {
+ llvm::errs() << llvm::toString(InsertStyle.takeError()) << "\n";
+ return 1;
+ }
auto Replacements = clang::include_fixer::createIncludeFixerReplacements(
- Code->getBuffer(), Context, InsertStyle,
+ Code->getBuffer(), Context, *InsertStyle,
/*AddQualifiers=*/IsUniqueQualifiedName);
if (!Replacements) {
errs() << "Failed to create replacements: "
@@ -371,16 +374,20 @@
std::vector<tooling::Replacements> FixerReplacements;
for (const auto &Context : Contexts) {
StringRef FilePath = Context.getFilePath();
- format::FormatStyle InsertStyle = format::getStyle("file", FilePath, Style);
+ auto InsertStyle = format::getStyle("file", FilePath, Style);
+ if (!InsertStyle) {
+ llvm::errs() << llvm::toString(InsertStyle.takeError()) << "\n";
+ return 1;
+ }
auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
if (!Buffer) {
errs() << "Couldn't open file: " + FilePath.str() + ": "
<< Buffer.getError().message() + "\n";
return 1;
}
auto Replacements = clang::include_fixer::createIncludeFixerReplacements(
- Buffer.get()->getBuffer(), Context, InsertStyle);
+ Buffer.get()->getBuffer(), Context, *InsertStyle);
if (!Replacements) {
errs() << "Failed to create replacement: "
<< llvm::toString(Replacements.takeError()) << "\n";
Index: clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -197,10 +197,14 @@
continue;
}
StringRef Code = Buffer.get()->getBuffer();
- format::FormatStyle Style = format::getStyle("file", File, FormatStyle);
+ auto Style = format::getStyle("file", File, FormatStyle);
+ if (!Style) {
+ llvm::errs() << llvm::toString(Style.takeError()) << "\n";
+ continue;
+ }
llvm::Expected<Replacements> CleanReplacements =
format::cleanupAroundReplacements(Code, FileAndReplacements.second,
- Style);
+ *Style);
if (!CleanReplacements) {
llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n";
continue;
Index: clang-move/ClangMove.cpp
===================================================================
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -712,10 +712,13 @@
// Ignore replacements for new.h/cc.
if (SI == FilePathToFileID.end()) continue;
llvm::StringRef Code = SM.getBufferData(SI->second);
- format::FormatStyle Style =
- format::getStyle("file", FilePath, Context->FallbackStyle);
+ auto Style = format::getStyle("file", FilePath, Context->FallbackStyle);
+ if (!Style) {
+ llvm::errs() << llvm::toString(Style.takeError()) << "\n";
+ continue;
+ }
auto CleanReplacements = format::cleanupAroundReplacements(
- Code, Context->FileToReplacements[FilePath], Style);
+ Code, Context->FileToReplacements[FilePath], *Style);
if (!CleanReplacements) {
llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n";
Index: clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
===================================================================
--- clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -207,9 +207,14 @@
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts.get());
// Determine a formatting style from options.
- format::FormatStyle FormatStyle;
- if (DoFormat)
+ llvm::Expected<format::FormatStyle> FormatStyle = format::getNoStyle();
+ if (DoFormat) {
FormatStyle = format::getStyle(FormatStyleOpt, FormatStyleConfig, "LLVM");
+ if (!FormatStyle) {
+ llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n";
+ return 1;
+ }
+ }
TUReplacements TURs;
TUReplacementFiles TUFiles;
@@ -262,7 +267,7 @@
// Apply formatting if requested.
if (DoFormat &&
!applyFormatting(FileAndReplacements.second, NewFileData, NewFileData,
- FormatStyle, Diagnostics)) {
+ *FormatStyle, Diagnostics)) {
errs() << "Failed to apply reformatting replacements for " << FileName
<< "\n";
continue;
Index: change-namespace/ChangeNamespace.cpp
===================================================================
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -886,11 +886,14 @@
// Add replacements referring to the changed code to existing replacements,
// which refers to the original code.
Replaces = Replaces.merge(NewReplacements);
- format::FormatStyle Style =
- format::getStyle("file", FilePath, FallbackStyle);
+ auto Style = format::getStyle("file", FilePath, FallbackStyle);
+ if (!Style) {
+ llvm::errs() << llvm::toString(Style.takeError()) << "\n";
+ continue;
+ }
// Clean up old namespaces if there is nothing in it after moving.
auto CleanReplacements =
- format::cleanupAroundReplacements(Code, Replaces, Style);
+ format::cleanupAroundReplacements(Code, Replaces, *Style);
if (!CleanReplacements) {
llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n";
continue;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits