Skip to content

Commit d428e5f

Browse files
committed
refactor adoc output and bitcode
1 parent a672ff8 commit d428e5f

17 files changed

+320
-76
lines changed

include/mrdox/Metadata/Overloads.hpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <mrdox/Metadata/Function.hpp>
1717
#include <clang/Basic/Specifiers.h>
1818
#include <llvm/ADT/StringRef.h>
19+
#include <span>
20+
#include <string_view>
1921

2022
namespace clang {
2123
namespace mrdox {
@@ -61,6 +63,56 @@ makeOverloadsSet(
6163
Scope const& scope,
6264
AccessSpecifier access);
6365

66+
//------------------------------------------------
67+
68+
struct Overloads_
69+
{
70+
/** The name for this set of functions.
71+
*/
72+
std::string_view name;
73+
74+
/** The list of overloads.
75+
*/
76+
std::span<FunctionInfo const*> list;
77+
};
78+
79+
class MRDOX_VISIBLE
80+
NamespaceOverloads
81+
{
82+
public:
83+
std::vector<Overloads_> list;
84+
85+
/** Constructor.
86+
87+
@par Complexity
88+
`O(N * log(N))` in `data.size()`.
89+
*/
90+
MRDOX_DECL
91+
explicit
92+
NamespaceOverloads(
93+
std::vector<FunctionInfo const*> data);
94+
95+
private:
96+
std::vector<FunctionInfo const*> data_;
97+
};
98+
99+
/** Create an overload set for all functions in a namespace.
100+
101+
This function organizes all functions in the
102+
specified list into an overload set. The top
103+
level set is sorted alphabetically using a
104+
display sort.
105+
106+
@return The overload set.
107+
108+
@param list The list of function references to use.
109+
*/
110+
MRDOX_DECL
111+
NamespaceOverloads
112+
makeNamespaceOverloads(
113+
std::vector<Reference> const& list,
114+
Corpus const& corpus);
115+
64116
} // mrdox
65117
} // clang
66118

include/mrdox/Platform.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace mrdox {
2121

2222
//------------------------------------------------
2323
//
24-
// static/dynamic linking
24+
// Shared Libraries
25+
//
2526
//------------------------------------------------
2627

2728
// static linking
@@ -54,6 +55,12 @@ namespace mrdox {
5455

5556
//------------------------------------------------
5657

58+
template<class T>
59+
T&& _access(T&& t) noexcept
60+
{
61+
return static_cast<T&&>(t);
62+
}
63+
5764
} // mrdox
5865
} // clang
5966

source/api/AST/ASTVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "ASTVisitor.hpp"
1313
#include "Commands.hpp"
14-
#include "Serialize.hpp"
14+
#include "Serializer.hpp"
1515
#include "Support/Path.hpp"
1616
#include <mrdox/Debug.hpp>
1717
#include <clang/Index/USRGeneration.h>

source/api/AST/Bitcode.hpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <mrdox/MetadataFwd.hpp>
1717
#include <mrdox/Reporter.hpp>
1818
#include <clang/Tooling/Execution.h>
19-
#include <llvm/ADT/SmallString.h>
19+
#include <llvm/ADT/SmallVector.h>
2020
#include <llvm/ADT/StringMap.h>
2121
#include <llvm/ADT/StringRef.h>
2222
#include <llvm/Support/Error.h>
@@ -40,8 +40,26 @@ namespace mrdox {
4040
*/
4141
struct Bitcode
4242
{
43+
/** The symbol ID for this bitcode.
44+
*/
4345
SymbolID id;
44-
std::string data;
46+
47+
/** The serialized bitcode.
48+
49+
We use small string here to avoid
50+
making needless copies.
51+
*/
52+
llvm::SmallString<0> data;
53+
54+
Bitcode() noexcept = default;
55+
56+
Bitcode(
57+
SymbolID const& id_,
58+
llvm::SmallString<0>&& data_) noexcept
59+
: id(id_)
60+
, data(std::move(data_))
61+
{
62+
}
4563

4664
bool empty() const noexcept
4765
{
@@ -55,7 +73,7 @@ using Bitcodes = llvm::StringMap<std::vector<StringRef>>;
5573

5674
/** Return the serialized bitcode for a metadata node.
5775
*/
58-
llvm::SmallString<2048>
76+
Bitcode
5977
writeBitcode(
6078
Info const& I);
6179

source/api/AST/BitcodeReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ parseRecord(
11101110
return decodeRecord(R, I->IsMethod, Blob);
11111111
case FUNCTION_BITS:
11121112
{
1113-
std::uint32_t v;
1113+
std::uint32_t v = 0;
11141114
if(auto err = decodeRecord(R, &v, 1, Blob))
11151115
return err;
11161116
I->specs.load(v);

source/api/AST/BitcodeWriter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111

1212
#include "BitcodeWriter.hpp"
13+
#include "Bitcode.hpp"
1314
#include "ParseJavadoc.hpp"
1415
#include <mrdox/Debug.hpp>
1516
#include <mrdox/Metadata.hpp>
@@ -1021,15 +1022,15 @@ emitBlock(
10211022

10221023
/** Write an Info variant to the buffer as bitcode.
10231024
*/
1024-
llvm::SmallString<2048>
1025+
Bitcode
10251026
writeBitcode(
10261027
Info const& I)
10271028
{
1028-
SmallString<2048> Buffer;
1029+
SmallString<0> Buffer;
10291030
llvm::BitstreamWriter Stream(Buffer);
10301031
BitcodeWriter writer(Stream);
10311032
writer.dispatchInfoForWrite(&I);
1032-
return Buffer;
1033+
return Bitcode{ I.id, std::move(Buffer) };
10331034
}
10341035

10351036
} // mrdox

source/api/AST/Serialize.cpp renamed to source/api/AST/Serializer.cpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Official repository: https://github.com/cppalliance/mrdox
1010
//
1111

12-
#include "Serialize.hpp"
12+
#include "Serializer.hpp"
1313
#include "Bitcode.hpp"
1414
#include "ParseJavadoc.hpp"
1515
#include <mrdox/Debug.hpp>
@@ -481,15 +481,6 @@ insertChild(Parent& parent, Child&& I)
481481
}
482482
}
483483

484-
// Return the serialized bitcode for a metadata node
485-
static
486-
Bitcode
487-
serialize(
488-
Info const& I)
489-
{
490-
return { I.id, writeBitcode(I).str().str() };
491-
}
492-
493484
// Create an empty parent for the child with the
494485
// child inserted either as a reference or by moving
495486
// the entire record. Then return the parent as a
@@ -498,7 +489,7 @@ template<class Child>
498489
requires std::derived_from<Child, Info>
499490
static
500491
Bitcode
501-
serializeParent(Child&& I)
492+
writeParent(Child&& I)
502493
{
503494
if(I.Namespace.empty())
504495
{
@@ -512,19 +503,19 @@ serializeParent(Child&& I)
512503
NamespaceInfo P;
513504
Assert(P.id == globalNamespaceID);
514505
insertChild(P, std::move(I));
515-
return serialize(P);
506+
return writeBitcode(P);
516507
}
517508
if(I.Namespace[0].RefType == InfoType::IT_namespace)
518509
{
519510
NamespaceInfo P(I.Namespace[0].id);
520511
insertChild(P, std::move(I));
521-
return serialize(P);
512+
return writeBitcode(P);
522513
}
523514
Assert(I.Namespace[0].RefType == InfoType::IT_record);
524515
Assert(Child::type_id != InfoType::IT_namespace);
525516
RecordInfo P(I.Namespace[0].id);
526517
insertChild(P, std::move(I));
527-
return serialize(P);
518+
return writeBitcode(P);
528519
}
529520

530521
// There are two uses for this function.
@@ -861,8 +852,8 @@ build(
861852
I.Name = "@nonymous_namespace";
862853

863854
return {
864-
serialize(I),
865-
serializeParent(std::move(I)) };
855+
writeBitcode(I),
856+
writeParent(std::move(I)) };
866857
}
867858

868859
SerializeResult
@@ -946,7 +937,7 @@ build(
946937
}
947938
}
948939

949-
return { serialize(I), serializeParent(std::move(I)) };
940+
return { writeBitcode(I), writeParent(std::move(I)) };
950941
}
951942

952943
//------------------------------------------------
@@ -1038,7 +1029,7 @@ build(
10381029

10391030
getFunctionSpecs(I, D);
10401031

1041-
return { serialize(I), serializeParent(std::move(I)) };
1032+
return { writeBitcode(I), writeParent(std::move(I)) };
10421033
}
10431034

10441035
SerializeResult
@@ -1068,19 +1059,21 @@ build(
10681059
bool isInAnonymous;
10691060
getParentNamespaces(P.Namespace, ND, isInAnonymous);
10701061
return {
1071-
serialize(I),
1072-
serializeParent(std::move(I)),
1073-
serialize(P),
1074-
serializeParent(std::move(P)) };
1062+
writeBitcode(I),
1063+
writeParent(std::move(I)),
1064+
writeBitcode(P),
1065+
writeParent(std::move(P)) };
10751066
}
10761067
if(FunctionTemplateDecl const* FT = dyn_cast<FunctionTemplateDecl>(ND))
10771068
{
10781069
// VFALCO TODO
1070+
(void)FT;
10791071
return {};
10801072
}
10811073
if(ClassTemplateDecl const* CT = dyn_cast<ClassTemplateDecl>(ND))
10821074
{
10831075
// VFALCO TODO
1076+
(void)CT;
10841077
return {};
10851078
}
10861079

@@ -1089,6 +1082,7 @@ build(
10891082
}
10901083
else if(TypeSourceInfo const* TS = D->getFriendType())
10911084
{
1085+
(void)TS;
10921086
return {};
10931087
}
10941088
else
@@ -1131,7 +1125,7 @@ build(
11311125
FunctionInfo I;
11321126
if(! buildFunctionInfo(*this, I, D))
11331127
return {};
1134-
return { serialize(I), serializeParent(std::move(I)) };
1128+
return { writeBitcode(I), writeParent(std::move(I)) };
11351129
}
11361130

11371131
SerializeResult
@@ -1155,7 +1149,7 @@ build(
11551149
I.DefLoc.emplace(LineNumber, File, IsFileInRootDir);
11561150
I.IsUsing = false;
11571151

1158-
return { serialize(I), serializeParent(std::move(I)) };
1152+
return { writeBitcode(I), writeParent(std::move(I)) };
11591153
}
11601154

11611155
// VFALCO This is basically a copy of the typedef
@@ -1183,7 +1177,7 @@ build(
11831177
I.DefLoc.emplace(LineNumber, File, IsFileInRootDir);
11841178
I.IsUsing = true;
11851179

1186-
return { serialize(I), serializeParent(std::move(I)) };
1180+
return { writeBitcode(I), writeParent(std::move(I)) };
11871181
}
11881182

11891183
SerializeResult
@@ -1202,7 +1196,7 @@ build(
12021196
}
12031197
parseEnumerators(I, D);
12041198

1205-
return { serializeParent(std::move(I)) };
1199+
return { writeParent(std::move(I)) };
12061200
}
12071201

12081202
} // mrdox

source/api/AST/Serialize.hpp renamed to source/api/AST/Serializer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// Official repository: https://github.com/cppalliance/mrdox
1010
//
1111

12-
#ifndef MRDOX_API_AST_SERIALIZE_HPP
13-
#define MRDOX_API_AST_SERIALIZE_HPP
12+
#ifndef MRDOX_API_AST_SERIALIZER_HPP
13+
#define MRDOX_API_AST_SERIALIZER_HPP
1414

1515
#include <mrdox/Platform.hpp>
1616
#include "clangASTComment.hpp"

source/api/Corpus.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ build(
285285
R.print("warning: mapping failed because ", toString(std::move(err)));
286286
}
287287

288+
// Inject the global namespace
289+
{
290+
NamespaceInfo I;
291+
insertBitcode(
292+
*ex.getExecutionContext(),
293+
writeBitcode(I));
294+
295+
}
296+
288297
// Collect the symbols. Each symbol will have
289298
// a vector of one or more bitcodes. These will
290299
// be merged later.

0 commit comments

Comments
 (0)