Skip to content

Commit

Permalink
adoc work and single-page config item
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Apr 25, 2023
1 parent 4ab9ea7 commit e9c1b1e
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 127 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ else()
endif()
target_include_directories(mrdox-api SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})


# Windows, Win64
if (WIN32)
target_compile_definitions(
Expand Down
23 changes: 16 additions & 7 deletions include/mrdox/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
#include <memory>
#include <string>

namespace llvm {
namespace yaml {
template<class T>
struct MappingTraits;
} // yaml
} // llvm

namespace clang {
namespace mrdox {

Expand All @@ -53,6 +46,7 @@ class MRDOX_VISIBLE
llvm::SmallString<0> outputPath_;
std::string sourceRoot_;
bool includePrivate_ = false;
bool singlePage_ = false;
bool verbose_ = true;

explicit
Expand Down Expand Up @@ -129,6 +123,14 @@ class MRDOX_VISIBLE
return includePrivate_;
}

/** Return true if the output is single-page output.
*/
bool
singlePage() const noexcept
{
return singlePage_;
}

/** Call a function for each element of a range.
The function is invoked with a reference
Expand Down Expand Up @@ -159,6 +161,13 @@ class MRDOX_VISIBLE
verbose_ = verbose;
}

void
setSinglePage(
bool singlePage) noexcept
{
singlePage_ = singlePage;
}

/** Set whether or not to include private members.
*/
void
Expand Down
3 changes: 3 additions & 0 deletions source/api/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Config::Options
bool verbose = true;
bool include_private = false;
std::string source_root;
bool single_page = false;
FileFilter input;
};

Expand Down Expand Up @@ -64,6 +65,7 @@ struct llvm::yaml::MappingTraits<
io.mapOptional("verbose", opt.verbose);
io.mapOptional("private", opt.include_private);
io.mapOptional("source-root", opt.source_root);
io.mapOptional("single-page", opt.single_page);
io.mapOptional("input", opt.input);
}
};
Expand Down Expand Up @@ -258,6 +260,7 @@ loadFromFile(
(*config)->setIncludePrivate(opt.include_private);
(*config)->setSourceRoot(opt.source_root);
(*config)->setInputFileIncludes(opt.input.include);
(*config)->setSinglePage(opt.single_page);

return config;
}
Expand Down
7 changes: 7 additions & 0 deletions source/api/ConfigImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
#include <llvm/Support/ThreadPool.h>
#include <memory>

namespace llvm {
namespace yaml {
template<class T>
struct MappingTraits;
} // yaml
} // llvm

namespace clang {
namespace mrdox {

Expand Down
134 changes: 116 additions & 18 deletions source/api/_adoc/AdocSinglePageWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,131 @@ build()
"= Reference\n"
":role: mrdox\n";
corpus_.visit(globalNamespaceID, *this);
closeSection();
endSection();
return llvm::Error::success();
}

//------------------------------------------------

template<class Type>
std::vector<Type const*>
AdocSinglePageWriter::
buildSortedList(
std::vector<Reference> const& from) const
{
std::vector<Type const*> result;
result.reserve(from.size());
for(auto const& ref : from)
result.push_back(&corpus_.get<Type>(ref.id));
llvm::sort(result,
[&](Info const* I0, Info const* I1)
{
return compareSymbolNames(
I0->Name, I1->Name) < 0;
});
return result;
}

/* Write a namespace.
This will index all individual
symbols except child namespaces,
sorted by group.
*/
bool
AdocSinglePageWriter::
visit(
NamespaceInfo const& I)
{
write(I);
if(! corpus_.visit(I.Children.Namespaces, *this))
return false;

// Visit records in alphabetical display order
std::vector<RecordInfo const*> list;
list.reserve(I.Children.Records.size());
for(auto const& ref : I.Children.Records)
list.push_back(&corpus_.get<RecordInfo>(ref.id));
std::string s0, s1;
llvm::sort(list,
[&s0, &s1](Info const* I0, Info const* I1)
//if(! corpus_.visit(I.Children.Namespaces, *this))
//return false;
/*
if( I.Children.Records.empty() &&
I.Children.Functions.empty() &&
I.Children.Typedefs.empty() &&
I.Children.Enums.empty())
return;
*/
// build sorted list of namespaces,
// this is for visitation not display.
auto namespaceList = buildSortedList<NamespaceInfo>(I.Children.Namespaces);

// don't emit empty namespaces,
// but still visit child namespaces.
if( ! I.Children.Records.empty() ||
! I.Children.Functions.empty() ||
! I.Children.Typedefs.empty() ||
! I.Children.Enums.empty())
{
std::string s;
I.getFullyQualifiedName(s);
s = "namespace " + s;

beginSection(s);

auto recordList = buildSortedList<RecordInfo>(I.Children.Records);
auto functionList = buildSortedList<FunctionInfo>(I.Children.Functions);
//auto typeList = ?
//auto enumList = ?

if(! recordList.empty())
{
return compareSymbolNames(
I0->getFullyQualifiedName(s0),
I1->getFullyQualifiedName(s1)) < 0;
});
for(auto const I : list)
beginSection("Classes");
os_ << "\n"
"[cols=1]\n"
"|===\n";
for(auto const I : recordList)
{
os_ << "\n|" << linkFor(*I) << '\n';
};
os_ << "|===\n";
endSection();
}

if(! functionList.empty())
{
beginSection("Functions");
os_ << "\n"
"[cols=1]\n"
"|===\n";
for(auto const I : functionList)
{
os_ << "\n|" << linkFor(*I) << '\n';
};
os_ << "|===\n";
endSection();
}

//if(! typeList.empty())

//if(! enumList.empty())

// now visit each indexed item
for(auto const& I : recordList)
visit(*I);
recordList.clear();

for(auto const& I : functionList)
visit(*I);
functionList.clear();

/*
for(auto const& I : typeList)
visit(*I);
typeList.clear();
*/

/*
for(auto const& I : enumList)
visit(*I);
typeList.clear();
*/

endSection();
}

// visit child namespaces
for(auto const& I : namespaceList)
if(! visit(*I))
return false;

Expand Down
7 changes: 7 additions & 0 deletions source/api/_adoc/AdocSinglePageWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class AdocSinglePageWriter
llvm::Error build();

private:
/** Return an array of info pointers display-sorted by symbol.
*/
template<class Type>
std::vector<Type const*>
buildSortedList(
std::vector<Reference> const& from) const;

bool visit(NamespaceInfo const&) override;
bool visit(RecordInfo const&) override;
bool visit(FunctionInfo const&) override;
Expand Down
Loading

0 comments on commit e9c1b1e

Please sign in to comment.