Skip to content

Commit 9dbb505

Browse files
committed
safe names and adoc pagination
1 parent 995e178 commit 9dbb505

18 files changed

+436
-169
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ bin64/
66
build/
77
temp/
88
test/
9+
tests/py
910
tests/**/*.adoc
1011
tests/**/*.bad.xml

include/mrdox/Config.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ class MRDOX_VISIBLE
4949
Config& operator=(Config const&) = delete;
5050

5151
protected:
52-
std::string sourceRoot_;
5352
llvm::SmallString<0> configDir_;
53+
llvm::SmallString<0> outputPath_;
54+
std::string sourceRoot_;
5455
bool includePrivate_ = false;
5556
bool verbose_ = true;
5657

@@ -74,7 +75,6 @@ class MRDOX_VISIBLE
7475
// VFALCO these naked data members are temporary...
7576
//
7677
tooling::ArgumentsAdjuster ArgAdjuster;
77-
std::string OutDirectory;
7878
bool IgnoreMappingFailures = false;
7979

8080
//--------------------------------------------
@@ -113,6 +113,14 @@ class MRDOX_VISIBLE
113113
return sourceRoot_;
114114
}
115115

116+
/** Return the output directory or filename.
117+
*/
118+
llvm::StringRef
119+
outputPath() const noexcept
120+
{
121+
return outputPath_;
122+
}
123+
116124
/** Return true if private members are documented.
117125
*/
118126
bool
@@ -160,6 +168,14 @@ class MRDOX_VISIBLE
160168
includePrivate_ = includePrivate;
161169
}
162170

171+
/** Set the output directory or file path.
172+
*/
173+
MRDOX_DECL
174+
virtual
175+
void
176+
setOutputPath(
177+
llvm::StringRef outputPath) = 0;
178+
163179
/** Set the directory where the input files are stored.
164180
165181
Symbol documentation will not be emitted unless

include/mrdox/Corpus.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,10 @@ class MRDOX_VISIBLE
103103
/** Visit the specified symbol ID or node.
104104
*/
105105
/** @{ */
106-
MRDOX_DECL [[nodiscard]] bool visit(
107-
SymbolID id, Visitor& f) const;
108-
MRDOX_DECL [[nodiscard]] bool visit(
109-
Scope const& I, Visitor& f) const;
110-
MRDOX_DECL [[nodiscard]] bool visitWithOverloads(
111-
Scope const& I, Visitor& f) const;
112-
MRDOX_DECL [[nodiscard]] bool visit(
113-
Info const& I, Visitor& f) const;
106+
MRDOX_DECL bool visit(SymbolID id, Visitor& f) const;
107+
MRDOX_DECL bool visit(Scope const& I, Visitor& f) const;
108+
MRDOX_DECL bool visitWithOverloads(Scope const& I, Visitor& f) const;
109+
MRDOX_DECL bool visit(Info const& I, Visitor& f) const;
114110
/** @} */
115111

116112
//--------------------------------------------

include/mrdox/Metadata/Overloads.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ struct OverloadsSet
4646

4747
/** Create an overload set for all functions in a scope.
4848
*/
49+
MRDOX_DECL
50+
OverloadsSet
51+
makeOverloadsSet(
52+
Corpus const& corpus,
53+
Scope const& scope);
54+
55+
/** Create an overload set for all functions in a scope.
56+
*/
57+
MRDOX_DECL
4958
OverloadsSet
5059
makeOverloadsSet(
5160
Corpus const& corpus,

include/mrdox/Metadata/Symbols.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum class InfoType
5959
are compared with lowercase letters coming
6060
before uppercase letters.
6161
*/
62+
MRDOX_DECL
6263
std::strong_ordering
6364
compareSymbolNames(
6465
llvm::StringRef symbolName0,

include/mrdox/MetadataFwd.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
namespace clang {
2222
namespace mrdox {
2323

24+
class Corpus;
25+
2426
struct BaseRecordInfo;
2527
struct EnumValueInfo;
2628
struct EnumInfo;

source/lib/ConfigImpl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ ConfigImpl(
5555
{
5656
}
5757

58+
void
59+
ConfigImpl::
60+
setOutputPath(
61+
llvm::StringRef outputPath)
62+
{
63+
namespace path = llvm::sys::path;
64+
outputPath_ = outputPath;
65+
path::remove_dots(outputPath_, true);
66+
path::make_preferred(outputPath_);
67+
}
68+
5869
void
5970
ConfigImpl::
6071
setSourceRoot(

source/lib/ConfigImpl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class ConfigImpl
4444
ConfigImpl(
4545
llvm::StringRef configDir);
4646

47+
void
48+
setOutputPath(
49+
llvm::StringRef outputPath) override;
50+
4751
void
4852
setSourceRoot(
4953
llvm::StringRef dirPath) override;

source/lib/Metadata/Overloads.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
namespace clang {
1818
namespace mrdox {
1919

20+
template<class Pred>
21+
static
2022
OverloadsSet
21-
makeOverloadsSet(
23+
makeOverloadsSetImpl(
2224
Corpus const& corpus,
2325
Scope const& scope,
24-
AccessSpecifier access)
26+
Pred&& pred)
2527
{
2628
OverloadsSet result;
27-
result.access = access;
28-
2929
std::vector<FunctionInfo const*> temp;
3030
temp.reserve(scope.Functions.size());
3131
for(auto const& ref : scope.Functions)
3232
{
3333
auto const& I = corpus.get<FunctionInfo>(ref.id);
34-
if(I.Access == access)
34+
if(pred(I))
3535
temp.push_back(&I);
3636
}
3737
if(temp.empty())
@@ -62,5 +62,30 @@ makeOverloadsSet(
6262
return result;
6363
}
6464

65+
OverloadsSet
66+
makeOverloadsSet(
67+
Corpus const& corpus,
68+
Scope const& scope)
69+
{
70+
return makeOverloadsSetImpl(corpus, scope,
71+
[](FunctionInfo const& I)
72+
{
73+
return true;
74+
});
75+
}
76+
77+
OverloadsSet
78+
makeOverloadsSet(
79+
Corpus const& corpus,
80+
Scope const& scope,
81+
AccessSpecifier access)
82+
{
83+
return makeOverloadsSetImpl(corpus, scope,
84+
[access](FunctionInfo const& I)
85+
{
86+
return I.Access == access;
87+
});
88+
}
89+
6590
} // mrdox
6691
} // clang

source/lib/_adoc/AdocGenerator.cpp

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "AdocMultiPageWriter.hpp"
1414
#include "AdocPagesBuilder.hpp"
1515
#include "AdocSinglePageWriter.hpp"
16+
#include "SafeNames.hpp"
1617

1718
namespace clang {
1819
namespace mrdox {
@@ -31,56 +32,7 @@ buildPages(
3132
Corpus const& corpus,
3233
Reporter& R) const
3334
{
34-
namespace fs = llvm::sys::fs;
35-
namespace path = llvm::sys::path;
36-
37-
#if 0
38-
// Track which directories we already tried to create.
39-
llvm::StringSet<> CreatedDirs;
40-
41-
// Collect all output by file name and create the necessary directories.
42-
llvm::StringMap<std::vector<mrdox::Info*>> FileToInfos;
43-
for (const auto& Group : corpus.InfoMap)
44-
{
45-
mrdox::Info* Info = Group.getValue().get();
46-
47-
llvm::SmallString<128> Path;
48-
llvm::sys::path::native(RootDir, Path);
49-
llvm::sys::path::append(Path, Info->getRelativeFilePath(""));
50-
if (!CreatedDirs.contains(Path)) {
51-
if (std::error_code Err = llvm::sys::fs::create_directories(Path);
52-
Err != std::error_code()) {
53-
return llvm::createStringError(Err, "Failed to create directory '%s'.",
54-
Path.c_str());
55-
}
56-
CreatedDirs.insert(Path);
57-
}
58-
59-
llvm::sys::path::append(Path, Info->getFileBaseName() + ".adoc");
60-
FileToInfos[Path].push_back(Info);
61-
}
62-
63-
for (const auto& Group : FileToInfos) {
64-
std::error_code FileErr;
65-
llvm::raw_fd_ostream InfoOS(Group.getKey(), FileErr,
66-
llvm::sys::fs::OF_None);
67-
if (FileErr) {
68-
return llvm::createStringError(FileErr, "Error opening file '%s'",
69-
Group.getKey().str().c_str());
70-
}
71-
72-
for (const auto& Info : Group.getValue()) {
73-
if (llvm::Error Err = generateDocForInfo(Info, InfoOS, config)) {
74-
return Err;
75-
}
76-
}
77-
}
78-
return true;
79-
#endif
80-
AdocPagesBuilder builder(corpus);
81-
builder.scan();
82-
83-
return llvm::Error::success();
35+
return AdocPagesBuilder(outputPath, corpus, R).build();
8436
}
8537

8638
llvm::Error

0 commit comments

Comments
 (0)