Skip to content

Commit 1229e4b

Browse files
committed
Adoc config options
1 parent 617f4ee commit 1229e4b

File tree

5 files changed

+125
-10
lines changed

5 files changed

+125
-10
lines changed

include/mrdox/Config.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,10 @@ class ConfigImpl;
4141
class MRDOX_VISIBLE
4242
Config
4343
{
44-
Config(Config const&) = delete;
45-
Config& operator=(Config const&) = delete;
46-
4744
protected:
4845
Config() noexcept;
4946

5047
public:
51-
class Options; // private, but for clang-15 bug
52-
5348
/** A resource for running submitted work, possibly concurrent.
5449
*/
5550
class WorkGroup;

source/api/_XML/XMLWriter.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ template<>
5959
struct llvm::yaml::MappingTraits<
6060
clang::mrdox::xml::XMLWriter::XmlKey>
6161
{
62-
static void mapping(
63-
IO& io, clang::mrdox::xml::XMLWriter::XmlKey& opt_)
62+
static void mapping(IO& io,
63+
clang::mrdox::xml::XMLWriter::XmlKey& opt_)
6464
{
6565
auto& opt= opt_.opt;
6666
io.mapOptional("index", opt.index);
@@ -72,8 +72,8 @@ template<>
7272
struct llvm::yaml::MappingTraits<
7373
clang::mrdox::xml::XMLWriter::GenKey>
7474
{
75-
static void mapping(
76-
IO& io, clang::mrdox::xml::XMLWriter::GenKey& opt)
75+
static void mapping(IO& io,
76+
clang::mrdox::xml::XMLWriter::GenKey& opt)
7777
{
7878
clang::mrdox::xml::XMLWriter::XmlKey k(opt.opt);
7979

source/api/_adoc/AdocSinglePageWriter.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ llvm::Error
3030
AdocSinglePageWriter::
3131
build()
3232
{
33+
if(auto Err = AdocWriter::init())
34+
return Err;
3335
Assert(sect_.level == 0);
3436
sect_.level = 1;
3537
sect_.markup = "=";

source/api/_adoc/AdocWriter.cpp

+104
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,88 @@
1010
//
1111

1212
#include "AdocWriter.hpp"
13+
#include "ConfigImpl.hpp"
1314
#include "Support/Validate.hpp"
1415
#include <mrdox/Metadata.hpp>
1516
#include <mrdox/Metadata/Overloads.hpp>
1617
#include <clang/Basic/Specifiers.h>
18+
#include <llvm/Support/YAMLParser.h>
19+
#include <llvm/Support/YAMLTraits.h>
20+
21+
//------------------------------------------------
22+
//
23+
// YAML
24+
//
25+
//------------------------------------------------
26+
27+
namespace clang {
28+
namespace mrdox {
29+
namespace adoc {
30+
31+
struct AdocWriter::Key
32+
{
33+
Options& opt;
34+
35+
explicit
36+
Key(
37+
Options& opt_) noexcept
38+
: opt(opt_)
39+
{
40+
}
41+
};
42+
43+
struct AdocWriter::GenKey
44+
{
45+
Options& opt;
46+
47+
explicit
48+
GenKey(
49+
Options& opt_)
50+
: opt(opt_)
51+
{
52+
}
53+
};
54+
55+
} // adoc
56+
} // mrdox
57+
} // clang
58+
59+
template<>
60+
struct llvm::yaml::MappingTraits<
61+
clang::mrdox::adoc::AdocWriter::Key>
62+
{
63+
static void mapping(IO& io,
64+
clang::mrdox::adoc::AdocWriter::Key& opt_)
65+
{
66+
auto& opt= opt_.opt;
67+
io.mapOptional("safe-names", opt.safe_names);
68+
}
69+
};
70+
71+
template<>
72+
struct llvm::yaml::MappingTraits<
73+
clang::mrdox::adoc::AdocWriter::GenKey>
74+
{
75+
static void mapping(IO& io,
76+
clang::mrdox::adoc::AdocWriter::GenKey& opt)
77+
{
78+
clang::mrdox::adoc::AdocWriter::Key k(opt.opt);
79+
80+
io.mapOptional("adoc", k);
81+
}
82+
};
83+
84+
template<>
85+
struct llvm::yaml::MappingTraits<
86+
clang::mrdox::adoc::AdocWriter::Options>
87+
{
88+
static void mapping(IO& io,
89+
clang::mrdox::adoc::AdocWriter::Options& opt)
90+
{
91+
clang::mrdox::adoc::AdocWriter::GenKey k(opt);
92+
io.mapOptional("generator", k);
93+
}
94+
};
1795

1896
namespace clang {
1997
namespace mrdox {
@@ -97,6 +175,32 @@ AdocWriter(
97175
{
98176
}
99177

178+
llvm::Error
179+
AdocWriter::
180+
init()
181+
{
182+
{
183+
llvm::yaml::Input yin(
184+
corpus_.config()->configYaml().first,
185+
this, ConfigImpl::yamlDiagnostic);
186+
yin.setAllowUnknownKeys(true);
187+
yin >> options_;
188+
if(auto ec = yin.error())
189+
return makeError(ec);
190+
}
191+
{
192+
llvm::yaml::Input yin(
193+
corpus_.config()->configYaml().second,
194+
this, ConfigImpl::yamlDiagnostic);
195+
yin.setAllowUnknownKeys(true);
196+
yin >> options_;
197+
if(auto ec = yin.error())
198+
return makeError(ec);
199+
}
200+
201+
return llvm::Error::success();
202+
}
203+
100204
//------------------------------------------------
101205

102206
/* Write a namespace.

source/api/_adoc/AdocWriter.hpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define MRDOX_API_ADOC_ADOCWRITER_HPP
1414

1515
#include "Support/SafeNames.hpp"
16+
#include "Support/YamlFwd.hpp"
1617
#include <mrdox/Platform.hpp>
1718
#include <mrdox/Corpus.hpp>
1819
#include <mrdox/Metadata.hpp>
@@ -24,9 +25,20 @@ namespace adoc {
2425

2526
class AdocWriter
2627
{
27-
SafeNames const& names_;
28+
template<class T>
29+
friend struct llvm::yaml::MappingTraits;
2830

2931
protected:
32+
struct Options
33+
{
34+
bool safe_names = false;
35+
};
36+
37+
struct Key;
38+
struct GenKey;
39+
Options options_;
40+
SafeNames const& names_;
41+
3042
struct Section
3143
{
3244
int level = 0;
@@ -52,6 +64,8 @@ class AdocWriter
5264
Corpus const& corpus,
5365
Reporter& R) noexcept;
5466

67+
llvm::Error init();
68+
5569
struct FormalParam;
5670
struct TypeName;
5771

0 commit comments

Comments
 (0)