Skip to content

Commit e1bec53

Browse files
committed
Format.
1 parent 6d61256 commit e1bec53

File tree

1 file changed

+45
-32
lines changed

1 file changed

+45
-32
lines changed

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,32 @@ LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
5151

5252
namespace {
5353

54-
/// DeserializedDeclsLineRangePrinter dumps ranges of deserialized declarations to aid debugging and bug minimization.
55-
/// It implements ASTConsumer and ASTDeserializationListener, so that an object of DeserializedDeclsLineRangePrinter registers
56-
/// as its own listener.
57-
/// The ASTDeserializationListener interface provides the DeclRead callback that we use to collect the deserialized Decls.
58-
/// Note that printing or otherwise processing them as this point is dangerous, since that could trigger additional
59-
/// deserialization and crash compilation.
60-
/// Therefore, we process the collected Decls in HandleTranslationUnit method of ASTConsumer.
61-
/// This is a safe point, since we know that by this point all the Decls needed by the compiler frontend have been
62-
/// deserialized. In case our processing causes further deserialization, DeclRead from the listener might be called again.
54+
/// DeserializedDeclsLineRangePrinter dumps ranges of deserialized declarations
55+
/// to aid debugging and bug minimization. It implements ASTConsumer and
56+
/// ASTDeserializationListener, so that an object of
57+
/// DeserializedDeclsLineRangePrinter registers as its own listener. The
58+
/// ASTDeserializationListener interface provides the DeclRead callback that we
59+
/// use to collect the deserialized Decls. Note that printing or otherwise
60+
/// processing them as this point is dangerous, since that could trigger
61+
/// additional deserialization and crash compilation. Therefore, we process the
62+
/// collected Decls in HandleTranslationUnit method of ASTConsumer. This is a
63+
/// safe point, since we know that by this point all the Decls needed by the
64+
/// compiler frontend have been deserialized. In case our processing causes
65+
/// further deserialization, DeclRead from the listener might be called again.
6366
/// However, at that point we don't accept any more Decls for processing.
64-
class DeserializedDeclsLineRangePrinter : public ASTDeserializationListener, public ASTConsumer {
67+
class DeserializedDeclsLineRangePrinter : public ASTDeserializationListener,
68+
public ASTConsumer {
6569
public:
66-
explicit DeserializedDeclsLineRangePrinter(SourceManager &SM, std::unique_ptr<llvm::raw_fd_ostream> OS)
70+
explicit DeserializedDeclsLineRangePrinter(
71+
SourceManager &SM, std::unique_ptr<llvm::raw_fd_ostream> OS)
6772
: ASTDeserializationListener(), SM(SM), OS(std::move(OS)) {}
6873

6974
void DeclRead(GlobalDeclID ID, const Decl *D) override {
7075
if (!IsCollectingDecls) {
7176
return;
7277
}
7378
if (!D || isa<TranslationUnitDecl>(D) || isa<LinkageSpecDecl>(D) ||
74-
isa<NamespaceDecl>(D))
79+
isa<NamespaceDecl>(D))
7580
return;
7681
if (auto *DC = D->getDeclContext(); !DC || !DC->isFileContext())
7782
return;
@@ -81,15 +86,15 @@ class DeserializedDeclsLineRangePrinter : public ASTDeserializationListener, pub
8186

8287
using Position = std::pair<unsigned, unsigned>;
8388
struct RequiredRanges {
84-
StringRef Filename;
85-
std::vector<std::pair<Position, Position>> FromTo;
89+
StringRef Filename;
90+
std::vector<std::pair<Position, Position>> FromTo;
8691
};
8792
void HandleTranslationUnit(ASTContext &Context) override {
8893
IsCollectingDecls = false;
8994
std::vector<const Decl *> Decls = std::move(PendingDecls);
9095
if (!PendingDecls.empty()) {
9196
llvm::errs() << "Deserialized more decls while printing, total of "
92-
<< PendingDecls.size() << "\n";
97+
<< PendingDecls.size() << "\n";
9398
PendingDecls.clear();
9499
}
95100

@@ -112,18 +117,20 @@ class DeserializedDeclsLineRangePrinter : public ASTDeserializationListener, pub
112117

113118
auto &Data = FileToLines[F];
114119
if (!Data.Ref)
115-
Data.Ref =
116-
SM.getFileEntryRefForID(SM.getFileID(R.getBegin()));
117-
Data.FromTo.push_back({{SM.getSpellingLineNumber(R.getBegin()), SM.getSpellingColumnNumber(R.getBegin())},
118-
{SM.getSpellingLineNumber(R.getEnd()), SM.getSpellingColumnNumber(R.getEnd())}});
120+
Data.Ref = SM.getFileEntryRefForID(SM.getFileID(R.getBegin()));
121+
Data.FromTo.push_back({{SM.getSpellingLineNumber(R.getBegin()),
122+
SM.getSpellingColumnNumber(R.getBegin())},
123+
{SM.getSpellingLineNumber(R.getEnd()),
124+
SM.getSpellingColumnNumber(R.getEnd())}});
119125
}
120126

121127
std::vector<RequiredRanges> Result;
122128
for (auto &[F, Data] : FileToLines) {
123-
auto& FromTo = Data.FromTo;
129+
auto &FromTo = Data.FromTo;
124130
assert(!FromTo.empty());
125131

126-
if (!Data.Ref) continue;
132+
if (!Data.Ref)
133+
continue;
127134

128135
llvm::sort(FromTo);
129136

@@ -142,7 +149,7 @@ class DeserializedDeclsLineRangePrinter : public ASTDeserializationListener, pub
142149
printJson(Result);
143150
}
144151

145-
void printJson(const std::vector<RequiredRanges>& Result) {
152+
void printJson(const std::vector<RequiredRanges> &Result) {
146153
*OS << "{\n";
147154
*OS << " \"required_ranges\": [\n";
148155
for (size_t i = 0; i < Result.size(); ++i) {
@@ -182,13 +189,12 @@ class DeserializedDeclsLineRangePrinter : public ASTDeserializationListener, pub
182189
}
183190

184191
private:
185-
std::vector<const Decl *> PendingDecls;
186-
bool IsCollectingDecls = true;
187-
const SourceManager &SM;
188-
std::unique_ptr<llvm::raw_ostream> OS;
192+
std::vector<const Decl *> PendingDecls;
193+
bool IsCollectingDecls = true;
194+
const SourceManager &SM;
195+
std::unique_ptr<llvm::raw_ostream> OS;
189196
};
190197

191-
192198
/// Dumps deserialized declarations.
193199
class DeserializedDeclsDumper : public DelegatingDeserializationListener {
194200
public:
@@ -262,15 +268,22 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
262268
return nullptr;
263269

264270
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
265-
llvm::StringRef DumpDeserializedDeclarationRangesPath = CI.getFrontendOpts().DumpDeserializedDeclarationRangesPath;
271+
llvm::StringRef DumpDeserializedDeclarationRangesPath =
272+
CI.getFrontendOpts().DumpDeserializedDeclarationRangesPath;
266273
if (!DumpDeserializedDeclarationRangesPath.empty()) {
267274
std::error_code ErrorCode;
268-
auto FileStream = std::make_unique<llvm::raw_fd_ostream>(DumpDeserializedDeclarationRangesPath, ErrorCode, llvm::sys::fs::OF_None);
275+
auto FileStream = std::make_unique<llvm::raw_fd_ostream>(
276+
DumpDeserializedDeclarationRangesPath, ErrorCode,
277+
llvm::sys::fs::OF_None);
269278
if (!ErrorCode) {
270-
auto Printer = std::make_unique<DeserializedDeclsLineRangePrinter>(CI.getSourceManager(), std::move(FileStream));
279+
auto Printer = std::make_unique<DeserializedDeclsLineRangePrinter>(
280+
CI.getSourceManager(), std::move(FileStream));
271281
Consumers.push_back(std::move(Printer));
272282
} else {
273-
llvm::errs() << "Failed to create output file for -dump-deserialized-declaration-ranges flag, file path: " << DumpDeserializedDeclarationRangesPath << ", error: " << ErrorCode.message() << "\n";
283+
llvm::errs() << "Failed to create output file for "
284+
"-dump-deserialized-declaration-ranges flag, file path: "
285+
<< DumpDeserializedDeclarationRangesPath
286+
<< ", error: " << ErrorCode.message() << "\n";
274287
}
275288
}
276289

@@ -340,7 +353,7 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
340353
}
341354

342355
assert(Consumers.size() >= 1 && "should have added the main consumer");
343-
if (Consumers.size() == 1)
356+
if (Consumers.size() == 1)
344357
return std::move(Consumers.front());
345358
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
346359
}

0 commit comments

Comments
 (0)