Skip to content

Commit 3945563

Browse files
committed
add FlatWriter
1 parent a5277f7 commit 3945563

File tree

10 files changed

+527
-930
lines changed

10 files changed

+527
-930
lines changed

include/mrdox/Corpus.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ class Corpus
124124
llvm::StringRef symbolName0,
125125
llvm::StringRef symbolName1) noexcept;
126126

127+
/** Return the ID of the global namespace.
128+
*/
129+
static
130+
SymbolID
131+
globalNamespaceID() noexcept;
132+
133+
/** Return the metadata for the global namespace.
134+
*/
135+
NamespaceInfo const&
136+
globalNamespace() const noexcept;
137+
127138
/** Return true if an Info with the specified symbol ID exists.
128139
*/
129140
bool

include/mrdox/FlatWriter.hpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// This is a derivative work. originally part of the LLVM Project.
3+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
// Copyright (c) 2023 Vinnie Falco ([email protected])
8+
//
9+
// Official repository: https://github.com/cppalliance/mrdox
10+
//
11+
12+
#ifndef MRDOX_FLAT_WRITER_HPP
13+
#define MRDOX_FLAT_WRITER_HPP
14+
15+
#include <mrdox/Info.hpp>
16+
#include <mrdox/Reporter.hpp>
17+
#include <llvm/ADT/StringRef.h>
18+
#include <llvm/Support/raw_ostream.h>
19+
#include <string>
20+
21+
namespace clang {
22+
namespace mrdox {
23+
24+
//------------------------------------------------
25+
26+
class Corpus;
27+
class Config;
28+
struct NamespaceInfo;
29+
struct RecordInfo;
30+
struct FunctionInfo;
31+
struct EnumInfo;
32+
struct TypedefInfo;
33+
struct Scope;
34+
35+
//------------------------------------------------
36+
37+
/** An abstract writer for flat output formats.
38+
*/
39+
class FlatWriter
40+
{
41+
protected:
42+
llvm::raw_ostream& os_;
43+
Corpus const& corpus_;
44+
Config const& config_;
45+
Reporter& R_;
46+
47+
/** Constructor.
48+
*/
49+
FlatWriter(
50+
llvm::raw_ostream& os,
51+
Corpus const& corpus,
52+
Config const& config,
53+
Reporter& R) noexcept;
54+
55+
public:
56+
/** Destructor.
57+
*/
58+
virtual ~FlatWriter() = default;
59+
60+
void visitAllSymbols();
61+
void visit(SymbolID const& id);
62+
63+
virtual void beginFile();
64+
virtual void endFile();
65+
66+
protected:
67+
virtual void writeNamespace(NamespaceInfo const& I);
68+
virtual void writeRecord(RecordInfo const& I);
69+
virtual void writeFunction(FunctionInfo const& I);
70+
virtual void writeEnum(EnumInfo const& I);
71+
virtual void writeTypedef(TypedefInfo const& I);
72+
73+
private:
74+
void visit(NamespaceInfo const&);
75+
void visit(RecordInfo const&);
76+
void visit(FunctionInfo const&);
77+
void visit(Scope const&);
78+
};
79+
80+
} // mrdox
81+
} // clang
82+
83+
#endif

include/mrdox/RecursiveWriter.hpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,25 @@ struct Scope;
4949
*/
5050
class RecursiveWriter
5151
{
52-
llvm::raw_fd_ostream* fd_os_ = nullptr;
53-
llvm::raw_string_ostream* str_os_ = nullptr;
5452
std::string indentString_;
5553

5654
protected:
55+
llvm::raw_ostream& os_;
5756
Corpus const& corpus_;
5857
Config const& config_;
5958
Reporter& R_;
6059

61-
llvm::raw_ostream& os() noexcept;
6260
llvm::raw_ostream& indent();
6361
void adjustNesting(int levels);
6462

63+
/** Constructor.
64+
*/
65+
RecursiveWriter(
66+
llvm::raw_ostream& os,
67+
Corpus const& corpus,
68+
Config const& config,
69+
Reporter& R) noexcept;
70+
6571
public:
6672
/** Describes an item in the list of all symbols.
6773
*/
@@ -79,44 +85,37 @@ class RecursiveWriter
7985
*/
8086
SymbolID id;
8187

88+
/** Constructor.
89+
*/
8290
AllSymbol(Info const& I);
8391
};
8492

8593
/** Destructor.
8694
*/
87-
~RecursiveWriter() = default;
95+
virtual ~RecursiveWriter() = default;
8896

89-
/** Constructor.
97+
/** Write the contents of the corpus.
9098
*/
91-
RecursiveWriter(
92-
Corpus const& corpus,
93-
Config const& config,
94-
Reporter& R) noexcept;
99+
void write();
100+
101+
protected:
102+
/** Called to write all symbols.
95103
96-
/** Write the contents of the corpus to the output stream.
104+
Each element contains the fully qualified
105+
name and the type of symbol. The list is
106+
canonicalized by a visual sort on symbol.
97107
*/
98-
/** @{ */
99-
void write(llvm::raw_fd_ostream& os);
100-
void write(llvm::raw_string_ostream& os);
101-
/** @} */
108+
virtual void writeAllSymbols(std::vector<AllSymbol> const& list);
102109

103110
/** Called to open and close the document.
104111
105112
The default implementation does nothing.
106113
*/
107114
/** @{ */
108-
virtual void beginDoc();
109-
virtual void endDoc();
115+
virtual void beginFile();
116+
virtual void endFile();
110117
/** @} */
111118

112-
/** Called to write all symbols.
113-
114-
Each element contains the fully qualified
115-
name and the type of symbol. The list is
116-
canonicalized by a visual sort on symbol.
117-
*/
118-
virtual void writeAllSymbols(std::vector<AllSymbol> const& list);
119-
120119
/** Called to open or close a scope.
121120
122121
The default implementation does nothing.
@@ -142,8 +141,8 @@ class RecursiveWriter
142141
private:
143142
void visit(NamespaceInfo const&);
144143
void visit(RecordInfo const&);
145-
void visit(Scope const&);
146144
void visit(FunctionInfo const&);
145+
void visit(Scope const&);
147146

148147
std::vector<AllSymbol> makeAllSymbols();
149148
};

0 commit comments

Comments
 (0)