• Home
  • Raw
  • Download

Lines Matching +full:clang +full:- +full:format

1 //===-- clang-format/ClangFormat.cpp - Clang format tool ------------------===//
8 //===----------------------------------------------------------------------===//
11 /// \brief This file implements a clang-format tool that automatically formats
14 //===----------------------------------------------------------------------===//
16 #include "clang/Basic/Diagnostic.h"
17 #include "clang/Basic/DiagnosticOptions.h"
18 #include "clang/Basic/FileManager.h"
19 #include "clang/Basic/SourceManager.h"
20 #include "clang/Basic/Version.h"
21 #include "clang/Format/Format.h"
22 #include "clang/Rewrite/Core/Rewriter.h"
30 using clang::tooling::Replacements;
32 static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden);
34 // Mark all our options with this category, everything else (except for -version
35 // and -help) will be hidden.
36 static cl::OptionCategory ClangFormatCategory("Clang-format options");
40 cl::desc("Format a range starting at this byte offset.\n"
42 "several -offset and -length pairs.\n"
47 cl::desc("Format a range of this length (in bytes).\n"
49 "several -offset and -length pairs.\n"
50 "When only a single -offset is specified without\n"
51 "-length, clang-format will format up to the end\n"
56 LineRanges("lines", cl::desc("<start line>:<end line> - format a range of\n"
57 "lines (both 1-based).\n"
59 "several -lines arguments.\n"
60 "Can't be used with -offset and -length.\n"
65 cl::desc(clang::format::StyleOptionHelpDescription),
68 FallbackStyle("fallback-style",
70 "fallback in case clang-format is invoked with\n"
71 "-style=file, but can not find the .clang-format\n"
73 "Use -fallback-style=none to skip formatting."),
77 AssumeFileName("assume-filename",
78 cl::desc("When reading from stdin, clang-format assumes this\n"
80 "-style=file) and to determine the language."),
87 static cl::opt<bool> OutputXML("output-replacements-xml",
91 DumpConfig("dump-config",
93 "Can be used with -style option."),
98 "clang-format from an editor integration"),
102 "sort-includes",
110 namespace clang { namespace
111 namespace format { namespace
116 MemFS->addFileNoOwn(FileName, 0, Source); in createInMemoryFile()
143 errs() << "error: cannot use -lines with -offset/-length\n"; in fillRanges()
162 unsigned Length = Sources.getFileOffset(End) - Offset; in fillRanges()
172 errs() << "error: number of -offset and -length arguments must match.\n"; in fillRanges()
176 if (Offsets[i] >= Code->getBufferSize()) { in fillRanges()
184 if (Offsets[i] + Lengths[i] > Code->getBufferSize()) { in fillRanges()
195 unsigned Length = Sources.getFileOffset(End) - Offset; in fillRanges()
203 // utf-8. in outputReplacementXML()
207 outs() << Text.substr(From, Index - From); in outputReplacementXML()
240 static bool format(StringRef FileName) { in format() function
248 if (Code->getBufferSize() == 0) in format()
253 StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName; in format()
258 Replacements Replaces = sortIncludes(FormatStyle, Code->getBuffer(), Ranges, in format()
260 auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replaces); in format()
296 if (FileName == "-") in format()
297 errs() << "error: cannot use -i when reading from stdin.\n"; in format()
312 } // namespace format
313 } // namespace clang
317 OS << clang::getClangToolFullVersion("clang-format") << '\n'; in PrintVersion()
328 "A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code.\n\n" in main()
331 "If <file>s are given, it reformats the files. If -i is specified\n" in main()
332 "together with <file>s, the files are edited in-place. Otherwise, the\n" in main()
340 clang::format::configurationAsText(clang::format::getStyle( in main()
350 Error = clang::format::format("-"); in main()
353 Error = clang::format::format(FileNames[0]); in main()
357 errs() << "error: -offset, -length and -lines can only be used for " in main()
362 Error |= clang::format::format(FileNames[i]); in main()