1212#include " llvm/Support/FileSystem.h"
1313#include " llvm/Support/FormatVariadic.h"
1414#include " llvm/Support/Path.h"
15+ #include " llvm/Support/raw_ostream.h"
1516#include < string>
1617
1718using namespace llvm ;
@@ -67,6 +68,13 @@ static void writeFileDefinition(const ClangDocContext &CDCtx, const Location &L,
6768 OS << " \n\n " ;
6869}
6970
71+ static void createFileDefinition (llvm::raw_ostream &OS,
72+ const ClangDocContext &CDCtx,
73+ const std::optional<Location> &DefLoc) {
74+ if (DefLoc)
75+ writeFileDefinition (CDCtx, *DefLoc, OS);
76+ }
77+
7078static void writeDescription (const CommentInfo &I, raw_ostream &OS) {
7179 if (I.Kind == " FullComment" ) {
7280 for (const auto &Child : I.Children )
@@ -143,8 +151,8 @@ static void genMarkdown(const ClangDocContext &CDCtx, const EnumInfo &I,
143151 for (const auto &N : I.Members )
144152 Members << " | " << N.Name << " |\n " ;
145153 writeLine (Members.str (), OS);
146- if (I. DefLoc )
147- writeFileDefinition ( CDCtx, * I.DefLoc , OS );
154+
155+ createFileDefinition (OS, CDCtx, I.DefLoc );
148156
149157 for (const auto &C : I.Description )
150158 writeDescription (C, OS);
@@ -171,8 +179,8 @@ static void genMarkdown(const ClangDocContext &CDCtx, const FunctionInfo &I,
171179 writeLine (genItalic (I.ReturnType .Type .QualName + " " + I.Name + " (" +
172180 Stream.str () + " )" ),
173181 OS);
174- if (I. DefLoc )
175- writeFileDefinition ( CDCtx, * I.DefLoc , OS );
182+
183+ createFileDefinition (OS, CDCtx, I.DefLoc );
176184
177185 for (const auto &C : I.Description )
178186 writeDescription (C, OS);
@@ -231,8 +239,8 @@ static void genMarkdown(const ClangDocContext &CDCtx, const NamespaceInfo &I,
231239static void genMarkdown (const ClangDocContext &CDCtx, const RecordInfo &I,
232240 llvm::raw_ostream &OS) {
233241 writeHeader (getTagType (I.TagType ) + " " + I.Name , 1 , OS);
234- if (I. DefLoc )
235- writeFileDefinition ( CDCtx, * I.DefLoc , OS );
242+
243+ createFileDefinition (OS, CDCtx, I.DefLoc );
236244
237245 if (!I.Description .empty ()) {
238246 for (const auto &C : I.Description )
0 commit comments