Skip to content

Commit 0d7d9c2

Browse files
committed
Update tools to use new getStyle API
Depends on https://reviews.llvm.org/D28081 Differential Revision: https://reviews.llvm.org/D28315 llvm-svn: 292175
1 parent 3adfb6a commit 0d7d9c2

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

clang-tools-extra/change-namespace/ChangeNamespace.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,11 +883,14 @@ void ChangeNamespaceTool::onEndOfTranslationUnit() {
883883
// Add replacements referring to the changed code to existing replacements,
884884
// which refers to the original code.
885885
Replaces = Replaces.merge(NewReplacements);
886-
format::FormatStyle Style =
887-
format::getStyle("file", FilePath, FallbackStyle);
886+
auto Style = format::getStyle("file", FilePath, FallbackStyle);
887+
if (!Style) {
888+
llvm::errs() << llvm::toString(Style.takeError()) << "\n";
889+
continue;
890+
}
888891
// Clean up old namespaces if there is nothing in it after moving.
889892
auto CleanReplacements =
890-
format::cleanupAroundReplacements(Code, Replaces, Style);
893+
format::cleanupAroundReplacements(Code, Replaces, *Style);
891894
if (!CleanReplacements) {
892895
llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n";
893896
continue;

clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,15 @@ int main(int argc, char **argv) {
208208

209209
// Determine a formatting style from options.
210210
format::FormatStyle FormatStyle;
211-
if (DoFormat)
212-
FormatStyle = format::getStyle(FormatStyleOpt, FormatStyleConfig, "LLVM");
211+
if (DoFormat) {
212+
auto FormatStyleOrError =
213+
format::getStyle(FormatStyleOpt, FormatStyleConfig, "LLVM");
214+
if (!FormatStyleOrError) {
215+
llvm::errs() << llvm::toString(FormatStyleOrError.takeError()) << "\n";
216+
return 1;
217+
}
218+
FormatStyle = *FormatStyleOrError;
219+
}
213220

214221
TUReplacements TURs;
215222
TUReplacementFiles TUFiles;

clang-tools-extra/clang-move/ClangMove.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,13 @@ void ClangMoveTool::removeDeclsInOldFiles() {
742742
// Ignore replacements for new.h/cc.
743743
if (SI == FilePathToFileID.end()) continue;
744744
llvm::StringRef Code = SM.getBufferData(SI->second);
745-
format::FormatStyle Style =
746-
format::getStyle("file", FilePath, Context->FallbackStyle);
745+
auto Style = format::getStyle("file", FilePath, Context->FallbackStyle);
746+
if (!Style) {
747+
llvm::errs() << llvm::toString(Style.takeError()) << "\n";
748+
continue;
749+
}
747750
auto CleanReplacements = format::cleanupAroundReplacements(
748-
Code, Context->FileToReplacements[FilePath], Style);
751+
Code, Context->FileToReplacements[FilePath], *Style);
749752

750753
if (!CleanReplacements) {
751754
llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n";

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,14 @@ class ErrorReporter {
197197
continue;
198198
}
199199
StringRef Code = Buffer.get()->getBuffer();
200-
format::FormatStyle Style = format::getStyle("file", File, FormatStyle);
200+
auto Style = format::getStyle("file", File, FormatStyle);
201+
if (!Style) {
202+
llvm::errs() << llvm::toString(Style.takeError()) << "\n";
203+
continue;
204+
}
201205
llvm::Expected<Replacements> CleanReplacements =
202206
format::cleanupAroundReplacements(Code, FileAndReplacements.second,
203-
Style);
207+
*Style);
204208
if (!CleanReplacements) {
205209
llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n";
206210
continue;

clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,13 @@ int includeFixerMain(int argc, const char **argv) {
303303
const IncludeFixerContext::HeaderInfo &RHS) {
304304
return LHS.QualifiedName == RHS.QualifiedName;
305305
});
306-
format::FormatStyle InsertStyle =
307-
format::getStyle("file", Context.getFilePath(), Style);
306+
auto InsertStyle = format::getStyle("file", Context.getFilePath(), Style);
307+
if (!InsertStyle) {
308+
llvm::errs() << llvm::toString(InsertStyle.takeError()) << "\n";
309+
return 1;
310+
}
308311
auto Replacements = clang::include_fixer::createIncludeFixerReplacements(
309-
Code->getBuffer(), Context, InsertStyle,
312+
Code->getBuffer(), Context, *InsertStyle,
310313
/*AddQualifiers=*/IsUniqueQualifiedName);
311314
if (!Replacements) {
312315
errs() << "Failed to create replacements: "
@@ -378,7 +381,11 @@ int includeFixerMain(int argc, const char **argv) {
378381
std::vector<tooling::Replacements> FixerReplacements;
379382
for (const auto &Context : Contexts) {
380383
StringRef FilePath = Context.getFilePath();
381-
format::FormatStyle InsertStyle = format::getStyle("file", FilePath, Style);
384+
auto InsertStyle = format::getStyle("file", FilePath, Style);
385+
if (!InsertStyle) {
386+
llvm::errs() << llvm::toString(InsertStyle.takeError()) << "\n";
387+
return 1;
388+
}
382389
auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
383390
if (!Buffer) {
384391
errs() << "Couldn't open file: " + FilePath.str() + ": "
@@ -387,7 +394,7 @@ int includeFixerMain(int argc, const char **argv) {
387394
}
388395

389396
auto Replacements = clang::include_fixer::createIncludeFixerReplacements(
390-
Buffer.get()->getBuffer(), Context, InsertStyle);
397+
Buffer.get()->getBuffer(), Context, *InsertStyle);
391398
if (!Replacements) {
392399
errs() << "Failed to create replacement: "
393400
<< llvm::toString(Replacements.takeError()) << "\n";

0 commit comments

Comments
 (0)