18#define DEBUG_TYPE "format-formatter"
33 llvm::errs() << Message <<
"\n";
43std::unique_ptr<Environment>
46 unsigned NextStartColumn,
unsigned LastStartColumn) {
47 auto Env = std::make_unique<Environment>(Code,
FileName, FirstStartColumn,
48 NextStartColumn, LastStartColumn);
50 Env->SM.getDiagnostics().setClient(&Diags,
false);
58 Env->SM.getBufferData(
Env->ID);
65 unsigned FirstStartColumn,
unsigned NextStartColumn,
66 unsigned LastStartColumn)
68 ID(VirtualSM->get().getMainFileID()), FirstStartColumn(FirstStartColumn),
69 NextStartColumn(NextStartColumn), LastStartColumn(LastStartColumn) {}
73 AffectedRangeMgr(
Env.getSourceManager(),
Env.getCharRanges()),
75 Encoding(encoding::detectEncoding(
76 Env.getSourceManager().getBufferData(
Env.getFileID()))) {
78 llvm::dbgs() <<
"File encoding: "
85std::pair<tooling::Replacements, unsigned>
88 llvm::SpecificBumpPtrAllocator<FormatToken> Allocator;
97 Allocator, IdentTable);
100 unsigned Penalty = 0;
101 for (
unsigned Run = 0, RunE =
UnwrappedLines.size(); Run + 1 != RunE; ++Run) {
103 LLVM_DEBUG(llvm::dbgs() <<
"Run " << Run <<
"...\n");
105 AnnotatedLines.reserve(Lines.size());
111 Annotator.
annotate(*AnnotatedLines.back());
114 std::pair<tooling::Replacements, unsigned> RunResult =
115 analyze(Annotator, AnnotatedLines, Lex);
118 llvm::dbgs() <<
"Replacements for run " << Run <<
":\n";
120 llvm::dbgs() << Fix.
toString() <<
"\n";
125 Penalty += RunResult.second;
126 for (
const auto &R : RunResult.first) {
131 llvm::errs() << llvm::toString(std::move(Err)) <<
"\n";
This file declares an abstract TokenAnalyzer, and associated helper classes.
static CharSourceRange getCharRange(SourceRange R)
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
void FormatDiagnostic(SmallVectorImpl< char > &OutStr) const
Format this diagnostic into a string, substituting the formal arguments into the %0 slots.
Level
The level of the diagnostic, after it has been through mapping.
Implements an efficient mapping from strings to IdentifierInfo nodes.
Parser - This implements a parser for the C family of languages.
Encodes a location in the source.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
SourceManager and necessary dependencies (e.g.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.