diff options
Diffstat (limited to 'tools/clang-format/ClangFormat.cpp')
-rw-r--r-- | tools/clang-format/ClangFormat.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp index d44d407..5037e90 100644 --- a/tools/clang-format/ClangFormat.cpp +++ b/tools/clang-format/ClangFormat.cpp @@ -225,14 +225,18 @@ static bool format(StringRef FileName) { FormatStyle FormatStyle = getStyle( Style, (FileName == "-") ? AssumeFilename : FileName, FallbackStyle); - tooling::Replacements Replaces = reformat(FormatStyle, Sources, ID, Ranges); + bool IncompleteFormat = false; + tooling::Replacements Replaces = + reformat(FormatStyle, Sources, ID, Ranges, &IncompleteFormat); if (OutputXML) { - llvm::outs() - << "<?xml version='1.0'?>\n<replacements xml:space='preserve'>\n"; + llvm::outs() << "<?xml version='1.0'?>\n<replacements " + "xml:space='preserve' incomplete_format='" + << (IncompleteFormat ? "true" : "false") << "'>\n"; if (Cursor.getNumOccurrences() != 0) llvm::outs() << "<cursor>" << tooling::shiftedCodePosition(Replaces, Cursor) << "</cursor>\n"; + for (tooling::Replacements::const_iterator I = Replaces.begin(), E = Replaces.end(); I != E; ++I) { @@ -247,12 +251,16 @@ static bool format(StringRef FileName) { Rewriter Rewrite(Sources, LangOptions()); tooling::applyAllReplacements(Replaces, Rewrite); if (Inplace) { - if (Rewrite.overwriteChangedFiles()) + if (FileName == "-") + llvm::errs() << "error: cannot use -i when reading from stdin.\n"; + else if (Rewrite.overwriteChangedFiles()) return true; } else { if (Cursor.getNumOccurrences() != 0) outs() << "{ \"Cursor\": " - << tooling::shiftedCodePosition(Replaces, Cursor) << " }\n"; + << tooling::shiftedCodePosition(Replaces, Cursor) + << ", \"IncompleteFormat\": " + << (IncompleteFormat ? "true" : "false") << " }\n"; Rewrite.getEditBuffer(ID).write(outs()); } } @@ -270,15 +278,7 @@ static void PrintVersion() { int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); - // Hide unrelated options. - StringMap<cl::Option*> Options; - cl::getRegisteredOptions(Options); - for (StringMap<cl::Option *>::iterator I = Options.begin(), E = Options.end(); - I != E; ++I) { - if (I->second->Category != &ClangFormatCategory && I->first() != "help" && - I->first() != "version") - I->second->setHiddenFlag(cl::ReallyHidden); - } + cl::HideUnrelatedOptions(ClangFormatCategory); cl::SetVersionPrinter(PrintVersion); cl::ParseCommandLineOptions( |