diff options
Diffstat (limited to 'clang/tools/clang-format/ClangFormat.cpp')
| -rw-r--r-- | clang/tools/clang-format/ClangFormat.cpp | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 893c17d91708..07110a0db091 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -79,7 +79,18 @@ static cl::opt<std::string> AssumeFileName( "assume-filename", cl::desc("Override filename used to determine the language.\n" "When reading from stdin, clang-format assumes this\n" - "filename to determine the language."), + "filename to determine the language.\n" + "Unrecognized filenames are treated as C++.\n" + "supported:\n" + " CSharp: .cs\n" + " Java: .java\n" + " JavaScript: .mjs .js .ts\n" + " Json: .json\n" + " Objective-C: .m .mm\n" + " Proto: .proto .protodevel\n" + " TableGen: .td\n" + " TextProto: .textpb .pb.txt .textproto .asciipb\n" + " Verilog: .sv .svh .v .vh"), cl::init("<stdin>"), cl::cat(ClangFormatCategory)); static cl::opt<bool> Inplace("i", @@ -100,17 +111,16 @@ static cl::opt<unsigned> "clang-format from an editor integration"), cl::init(0), cl::cat(ClangFormatCategory)); -static cl::opt<bool> SortIncludes( - "sort-includes", - cl::desc("If set, overrides the include sorting behavior determined by the " - "SortIncludes style flag"), - cl::cat(ClangFormatCategory)); +static cl::opt<bool> + SortIncludes("sort-includes", + cl::desc("If set, overrides the include sorting behavior\n" + "determined by the SortIncludes style flag"), + cl::cat(ClangFormatCategory)); static cl::opt<std::string> QualifierAlignment( "qualifier-alignment", - cl::desc( - "If set, overrides the qualifier alignment style determined by the " - "QualifierAlignment style flag"), + cl::desc("If set, overrides the qualifier alignment style\n" + "determined by the QualifierAlignment style flag"), cl::init(""), cl::cat(ClangFormatCategory)); static cl::opt<std::string> @@ -148,8 +158,9 @@ static cl::opt<bool> static cl::opt<unsigned> ErrorLimit( "ferror-limit", - cl::desc("Set the maximum number of clang-format errors to emit before " - "stopping (0 = no limit). Used only with --dry-run or -n"), + cl::desc("Set the maximum number of clang-format errors to emit\n" + "before stopping (0 = no limit).\n" + "Used only with --dry-run or -n"), cl::init(0), cl::cat(ClangFormatCategory)); static cl::opt<bool> @@ -358,9 +369,10 @@ static void outputXML(const Replacements &Replaces, if (!Status.FormatComplete) outs() << " line='" << Status.Line << "'"; outs() << ">\n"; - if (Cursor.getNumOccurrences() != 0) + if (Cursor.getNumOccurrences() != 0) { outs() << "<cursor>" << FormatChanges.getShiftedCodePosition(CursorPosition) << "</cursor>\n"; + } outputReplacementsXML(Replaces); outs() << "</replacements>\n"; @@ -436,11 +448,11 @@ static bool format(StringRef FileName) { .Case("left", FormatStyle::QAS_Left) .Default(FormatStyle->QualifierAlignment); - if (FormatStyle->QualifierAlignment == FormatStyle::QAS_Left) + if (FormatStyle->QualifierAlignment == FormatStyle::QAS_Left) { FormatStyle->QualifierOrder = {"const", "volatile", "type"}; - else if (FormatStyle->QualifierAlignment == FormatStyle::QAS_Right) + } else if (FormatStyle->QualifierAlignment == FormatStyle::QAS_Right) { FormatStyle->QualifierOrder = {"type", "const", "volatile"}; - else if (QualifierAlignmentOrder.contains("type")) { + } else if (QualifierAlignmentOrder.contains("type")) { FormatStyle->QualifierAlignment = FormatStyle::QAS_Custom; SmallVector<StringRef> Qualifiers; QualifierAlignmentOrder.split(Qualifiers, " ", /*MaxSplit=*/-1, @@ -463,9 +475,8 @@ static bool format(StringRef FileName) { if (FormatStyle->isJson() && !FormatStyle->DisableFormat) { auto Err = Replaces.add(tooling::Replacement( tooling::Replacement(AssumedFileName, 0, 0, "x = "))); - if (Err) { + if (Err) llvm::errs() << "Bad Json variable insertion\n"; - } } auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replaces); @@ -480,11 +491,10 @@ static bool format(StringRef FileName) { reformat(*FormatStyle, *ChangedCode, Ranges, AssumedFileName, &Status); Replaces = Replaces.merge(FormatChanges); if (OutputXML || DryRun) { - if (DryRun) { + if (DryRun) return emitReplacementWarnings(Replaces, AssumedFileName, Code); - } else { + else outputXML(Replaces, FormatChanges, Status, Cursor, CursorPosition); - } } else { IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( new llvm::vfs::InMemoryFileSystem); @@ -579,9 +589,8 @@ int main(int argc, const char **argv) { return 0; } - if (DumpConfig) { + if (DumpConfig) return dumpConfig(); - } if (!Files.empty()) { std::ifstream ExternalFileOfFiles{std::string(Files)}; @@ -608,9 +617,10 @@ int main(int argc, const char **argv) { unsigned FileNo = 1; for (const auto &FileName : FileNames) { - if (Verbose) + if (Verbose) { errs() << "Formatting [" << FileNo++ << "/" << FileNames.size() << "] " << FileName << "\n"; + } Error |= clang::format::format(FileName); } return Error ? 1 : 0; |
