Skip to content

Commit 53993ca

Browse files
committed
refactor into jad files
1 parent 2f99861 commit 53993ca

39 files changed

+2153
-980
lines changed

include/mrdox/Corpus.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#ifndef MRDOX_CORPUS_HPP
1313
#define MRDOX_CORPUS_HPP
1414

15-
#include "Representation.h"
15+
#include "jad/Index.hpp"
16+
#include <clang/Tooling/Execution.h>
1617

1718
namespace clang {
1819
namespace mrdox {

source/lib/AsciidocGenerator.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
// Official repository: https://github.com/cppalliance/mrdox
1010
//
1111

12-
#include <mrdox/Config.hpp>
13-
#include <mrdox/Corpus.hpp>
1412
#include "Generators.h"
1513
#include "Representation.h"
14+
#include "jad/Namespace.hpp"
15+
#include <mrdox/Config.hpp>
16+
#include <mrdox/Corpus.hpp>
1617
#include "llvm/ADT/StringRef.h"
1718
#include "llvm/Support/FileSystem.h"
1819
#include "llvm/Support/Path.h"

source/lib/BitcodeWriter.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
namespace clang {
1717
namespace mrdox {
1818

19-
// Empty SymbolID for comparison, so we don't have to construct one every time.
20-
static const SymbolID EmptySID = SymbolID();
21-
2219
// Since id enums are not zero-indexed, we need to transform the given id into
2320
// its associated index.
2421
struct BlockIdToIndexFunctor {

source/lib/BitcodeWriter.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_BITCODEWRITER_H
2020

2121
#include "Representation.h"
22+
#include "jad/Namespace.hpp"
2223
#include "clang/AST/AST.h"
2324
#include "llvm/ADT/DenseMap.h"
2425
#include "llvm/ADT/SmallVector.h"

source/lib/Reduce.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
#ifndef MRDOX_REDUCE_HPP
1313
#define MRDOX_REDUCE_HPP
1414

15-
#include <Representation.h>
15+
#include "jad/Info.hpp"
16+
#include <llvm/Support/Error.h>
17+
#include <memory>
18+
#include <vector>
1619

1720
namespace clang {
1821
namespace mrdox {
1922

20-
SymbolID const EmptySID = SymbolID();
2123
template <typename T>
2224
llvm::Expected<std::unique_ptr<Info>>
2325
reduce(

source/lib/Representation.cpp

+5-194
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "Reduce.h"
2727
#include "Representation.h"
28+
#include "jad/Namespace.hpp"
2829
#include <mrdox/Config.hpp>
2930
#include "llvm/Support/Error.h"
3031
#include "llvm/Support/Path.h"
@@ -99,163 +100,6 @@ bool CommentInfo::operator<(const CommentInfo& Other) const {
99100
return false;
100101
}
101102

102-
static llvm::SmallString<64>
103-
calculateRelativeFilePath(const InfoType& Type, const StringRef& Path,
104-
const StringRef& Name, const StringRef& CurrentPath) {
105-
llvm::SmallString<64> FilePath;
106-
107-
if (CurrentPath != Path) {
108-
// iterate back to the top
109-
for (llvm::sys::path::const_iterator I =
110-
llvm::sys::path::begin(CurrentPath);
111-
I != llvm::sys::path::end(CurrentPath); ++I)
112-
llvm::sys::path::append(FilePath, "..");
113-
llvm::sys::path::append(FilePath, Path);
114-
}
115-
116-
// Namespace references have a Path to the parent namespace, but
117-
// the file is actually in the subdirectory for the namespace.
118-
if (Type == mrdox::InfoType::IT_namespace)
119-
llvm::sys::path::append(FilePath, Name);
120-
121-
return llvm::sys::path::relative_path(FilePath);
122-
}
123-
124-
llvm::SmallString<64>
125-
Reference::getRelativeFilePath(const StringRef& CurrentPath) const {
126-
return calculateRelativeFilePath(RefType, Path, Name, CurrentPath);
127-
}
128-
129-
llvm::SmallString<16> Reference::getFileBaseName() const {
130-
if (RefType == InfoType::IT_namespace)
131-
return llvm::SmallString<16>("index");
132-
133-
return Name;
134-
}
135-
136-
llvm::SmallString<64>
137-
Info::getRelativeFilePath(const StringRef& CurrentPath) const {
138-
return calculateRelativeFilePath(IT, Path, extractName(), CurrentPath);
139-
}
140-
141-
llvm::SmallString<16> Info::getFileBaseName() const {
142-
if (IT == InfoType::IT_namespace)
143-
return llvm::SmallString<16>("index");
144-
145-
return extractName();
146-
}
147-
148-
bool Reference::mergeable(const Reference& Other) {
149-
return RefType == Other.RefType && USR == Other.USR;
150-
}
151-
152-
void Reference::merge(Reference&& Other) {
153-
assert(mergeable(Other));
154-
if (Name.empty())
155-
Name = Other.Name;
156-
if (Path.empty())
157-
Path = Other.Path;
158-
}
159-
160-
void Info::mergeBase(Info&& Other)
161-
{
162-
assert(mergeable(Other));
163-
if (USR == EmptySID)
164-
USR = Other.USR;
165-
if (Name == "")
166-
Name = Other.Name;
167-
if (Path == "")
168-
Path = Other.Path;
169-
if (Namespace.empty())
170-
Namespace = std::move(Other.Namespace);
171-
// Unconditionally extend the description, since each decl may have a comment.
172-
std::move(Other.Description.begin(), Other.Description.end(),
173-
std::back_inserter(Description));
174-
llvm::sort(Description);
175-
auto Last = std::unique(Description.begin(), Description.end());
176-
Description.erase(Last, Description.end());
177-
if (javadoc.brief.empty())
178-
javadoc.brief = std::move(Other.javadoc.brief);
179-
if (javadoc.desc.empty())
180-
javadoc.desc = std::move(Other.javadoc.desc);
181-
}
182-
183-
bool Info::mergeable(const Info& Other) {
184-
return IT == Other.IT && USR == Other.USR;
185-
}
186-
187-
void SymbolInfo::merge(SymbolInfo&& Other) {
188-
assert(mergeable(Other));
189-
if (!DefLoc)
190-
DefLoc = std::move(Other.DefLoc);
191-
// Unconditionally extend the list of locations, since we want all of them.
192-
std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(Loc));
193-
llvm::sort(Loc);
194-
auto Last = std::unique(Loc.begin(), Loc.end());
195-
Loc.erase(Last, Loc.end());
196-
mergeBase(std::move(Other));
197-
}
198-
199-
NamespaceInfo::
200-
NamespaceInfo(
201-
SymbolID USR,
202-
StringRef Name,
203-
StringRef Path)
204-
: Info(InfoType::IT_namespace, USR, Name, Path)
205-
// VFALCO Shouldn't this be AS_none? But
206-
// the Bitcode writer expects the
207-
// default to be AS_public...
208-
, Children(clang::AccessSpecifier::AS_public)
209-
{
210-
}
211-
212-
void
213-
NamespaceInfo::
214-
merge(NamespaceInfo&& Other)
215-
{
216-
assert(mergeable(Other));
217-
// Reduce children if necessary.
218-
reduceChildren(Children.Namespaces, std::move(Other.Children.Namespaces));
219-
reduceChildren(Children.Records, std::move(Other.Children.Records));
220-
Children.functions.merge(std::move(Other.Children.functions));
221-
reduceChildren(Children.Enums, std::move(Other.Children.Enums));
222-
reduceChildren(Children.Typedefs, std::move(Other.Children.Typedefs));
223-
mergeBase(std::move(Other));
224-
}
225-
226-
RecordInfo::
227-
RecordInfo(
228-
SymbolID USR,
229-
StringRef Name,
230-
StringRef Path)
231-
: SymbolInfo(InfoType::IT_record, USR, Name, Path)
232-
, scope()
233-
{
234-
}
235-
236-
void RecordInfo::merge(RecordInfo&& Other) {
237-
assert(mergeable(Other));
238-
if (!TagType)
239-
TagType = Other.TagType;
240-
IsTypeDef = IsTypeDef || Other.IsTypeDef;
241-
if (Members.empty())
242-
Members = std::move(Other.Members);
243-
if (Bases.empty())
244-
Bases = std::move(Other.Bases);
245-
if (Parents.empty())
246-
Parents = std::move(Other.Parents);
247-
if (VirtualParents.empty())
248-
VirtualParents = std::move(Other.VirtualParents);
249-
// Reduce children if necessary.
250-
reduceChildren(Children.Records, std::move(Other.Children.Records));
251-
Children.functions.merge(std::move(Other.Children.functions));
252-
reduceChildren(Children.Enums, std::move(Other.Children.Enums));
253-
reduceChildren(Children.Typedefs, std::move(Other.Children.Typedefs));
254-
SymbolInfo::merge(std::move(Other));
255-
if (!Template)
256-
Template = Other.Template;
257-
}
258-
259103
void EnumInfo::merge(EnumInfo&& Other) {
260104
assert(mergeable(Other));
261105
if (!Scoped)
@@ -299,43 +143,10 @@ BaseRecordInfo::BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path,
299143
: RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
300144
IsParent(IsParent) {}
301145

302-
llvm::SmallString<16> Info::extractName() const {
303-
if (!Name.empty())
304-
return Name;
305-
306-
switch (IT) {
307-
case InfoType::IT_namespace:
308-
// Cover the case where the project contains a base namespace called
309-
// 'GlobalNamespace' (i.e. a namespace at the same level as the global
310-
// namespace, which would conflict with the hard-coded global namespace name
311-
// below.)
312-
if (Name == "GlobalNamespace" && Namespace.empty())
313-
return llvm::SmallString<16>("@GlobalNamespace");
314-
// The case of anonymous namespaces is taken care of in serialization,
315-
// so here we can safely assume an unnamed namespace is the global
316-
// one.
317-
return llvm::SmallString<16>("GlobalNamespace");
318-
case InfoType::IT_record:
319-
return llvm::SmallString<16>("@nonymous_record_" +
320-
toHex(llvm::toStringRef(USR)));
321-
case InfoType::IT_enum:
322-
return llvm::SmallString<16>("@nonymous_enum_" +
323-
toHex(llvm::toStringRef(USR)));
324-
case InfoType::IT_typedef:
325-
return llvm::SmallString<16>("@nonymous_typedef_" +
326-
toHex(llvm::toStringRef(USR)));
327-
case InfoType::IT_function:
328-
return llvm::SmallString<16>("@nonymous_function_" +
329-
toHex(llvm::toStringRef(USR)));
330-
case InfoType::IT_default:
331-
return llvm::SmallString<16>("@nonymous_" + toHex(llvm::toStringRef(USR)));
332-
}
333-
llvm_unreachable("Invalid InfoType.");
334-
return llvm::SmallString<16>("");
335-
}
336-
337-
// Order is based on the Name attribute: case insensitive order
338-
bool Index::operator<(const Index& Other) const {
146+
// Order is based on the Name attribute:
147+
// case insensitive order
148+
bool
149+
Index::operator<(const Index& Other) const {
339150
// Loop through each character of both strings
340151
for (unsigned I = 0; I < Name.size() && I < Other.Name.size(); ++I) {
341152
// Compare them after converting both to lower case

0 commit comments

Comments
 (0)