Skip to content

Commit

Permalink
attach javadoc to Info
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Apr 16, 2023
1 parent a6ac939 commit 95c8da3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion source/lib/ast/CommentVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ parseComment(
*/
Javadoc
parseJavadoc(
RawComment const& RC,
RawComment const* RC,
ASTContext const& Ctx,
Decl const* D);

Expand Down
3 changes: 2 additions & 1 deletion source/lib/ast/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ mapDecl(T const* D)

// VFALCO is this right?
bool const IsFileInRootDir = true;
auto I = preEmitInfo(

auto I = buildInfoPair(
D,
getComment(D, D->getASTContext()),
getLine(D, D->getASTContext()),
Expand Down
6 changes: 3 additions & 3 deletions source/lib/ast/ParseJavadoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ class JavadocVisitor

public:
JavadocVisitor(
RawComment const& RC,
RawComment const* RC,
ASTContext const& ctx,
Decl const* D)
: FC_(RC.parse(ctx, nullptr, D))
: FC_(RC->parse(ctx, nullptr, D))
, ctx_(ctx)
{
}
Expand Down Expand Up @@ -661,7 +661,7 @@ dumpJavadoc(

Javadoc
parseJavadoc(
RawComment const& RC,
RawComment const* RC,
ASTContext const& Ctx,
Decl const* D)
{
Expand Down
25 changes: 16 additions & 9 deletions source/lib/ast/Serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include <llvm/Support/Path.h>
#include <llvm/Support/SHA1.h>

using clang::comments::FullComment;

namespace clang {
namespace mrdox {

using clang::comments::FullComment;

SymbolID hashUSR(llvm::StringRef USR) {
return llvm::SHA1::hash(arrayRefFromStringRef(USR));
}
Expand Down Expand Up @@ -699,8 +699,9 @@ parseBases(
std::pair<
std::unique_ptr<Info>,
std::unique_ptr<Info>>
emitInfo(
buildInfo(
NamespaceDecl const* D,
Javadoc jd,
FullComment const* FC,
int LineNumber,
llvm::StringRef File,
Expand Down Expand Up @@ -728,8 +729,9 @@ emitInfo(
std::pair<
std::unique_ptr<Info>,
std::unique_ptr<Info>>
emitInfo(
buildInfo(
RecordDecl const* D,
Javadoc jd,
FullComment const* FC,
int LineNumber,
llvm::StringRef File,
Expand Down Expand Up @@ -817,8 +819,9 @@ emitInfo(
std::pair<
std::unique_ptr<Info>,
std::unique_ptr<Info>>
emitInfo(
buildInfo(
FunctionDecl const* D,
Javadoc jd,
FullComment const* FC,
int LineNumber,
llvm::StringRef File,
Expand All @@ -843,8 +846,9 @@ emitInfo(
std::pair<
std::unique_ptr<Info>,
std::unique_ptr<Info>>
emitInfo(
buildInfo(
CXXMethodDecl const* D,
Javadoc jd,
FullComment const* FC,
int LineNumber,
llvm::StringRef File,
Expand Down Expand Up @@ -882,8 +886,9 @@ emitInfo(
std::pair<
std::unique_ptr<Info>,
std::unique_ptr<Info>>
emitInfo(
buildInfo(
TypedefDecl const* D,
Javadoc jd,
FullComment const* FC,
int LineNumber,
StringRef File,
Expand Down Expand Up @@ -921,8 +926,9 @@ emitInfo(
std::pair<
std::unique_ptr<Info>,
std::unique_ptr<Info>>
emitInfo(
buildInfo(
TypeAliasDecl const* D,
Javadoc jd,
FullComment const* FC,
int LineNumber,
StringRef File,
Expand All @@ -948,8 +954,9 @@ emitInfo(
std::pair<
std::unique_ptr<Info>,
std::unique_ptr<Info>>
emitInfo(
buildInfo(
EnumDecl const* D,
Javadoc jd,
FullComment const* FC,
int LineNumber,
llvm::StringRef File,
Expand Down
38 changes: 21 additions & 17 deletions source/lib/ast/Serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,50 +39,54 @@ namespace mrdox {
// its parent scope. For NamespaceDecl and RecordDecl both elements are not
// nullptr.
std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
emitInfo(const NamespaceDecl *D, const comments::FullComment *FC, int LineNumber,
buildInfo(NamespaceDecl const* D, Javadoc jd, comments::FullComment const* FC, int LineNumber,
StringRef File, bool IsFileInRootDir, bool PublicOnly, Reporter& R);

std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
emitInfo(const RecordDecl *D, const comments::FullComment *FC, int LineNumber,
buildInfo(RecordDecl const* D, Javadoc jd, comments::FullComment const* FC, int LineNumber,
StringRef File, bool IsFileInRootDir, bool PublicOnly, Reporter& R);

std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
emitInfo(const EnumDecl *D, const comments::FullComment *FC, int LineNumber,
buildInfo(EnumDecl const* D, Javadoc jd, comments::FullComment const* FC, int LineNumber,
StringRef File, bool IsFileInRootDir, bool PublicOnly, Reporter& R);

std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
emitInfo(const FunctionDecl *D, const comments::FullComment *FC, int LineNumber,
buildInfo(FunctionDecl const* D, Javadoc jd, comments::FullComment const* FC, int LineNumber,
StringRef File, bool IsFileInRootDir, bool PublicOnly, Reporter& R);

std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
emitInfo(const CXXMethodDecl *D, const comments::FullComment *FC, int LineNumber,
buildInfo(CXXMethodDecl const* D, Javadoc jd, comments::FullComment const* FC, int LineNumber,
StringRef File, bool IsFileInRootDir, bool PublicOnly, Reporter& R);

std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
emitInfo(const TypedefDecl *D, const comments::FullComment *FC, int LineNumber,
buildInfo(TypedefDecl const* D, Javadoc jd, comments::FullComment const* FC, int LineNumber,
StringRef File, bool IsFileInRootDir, bool PublicOnly, Reporter& R);

std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
emitInfo(const TypeAliasDecl *D, const comments::FullComment *FC, int LineNumber,
buildInfo(TypeAliasDecl const* D, Javadoc jd, comments::FullComment const* FC, int LineNumber,
StringRef File, bool IsFileInRootDir, bool PublicOnly, Reporter& R);


template<class Decl, class... Args>
std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
preEmitInfo(
std::pair<
std::unique_ptr<Info>,
std::unique_ptr<Info>>
buildInfoPair(
Decl const* D,
Args&&... args)
{
// TODO investigate whether we can use ASTContext::getCommentForDecl instead
// of this logic. See also similar code in Mapper.cpp.
RawComment* raw = D->getASTContext().getRawCommentForDeclNoCache(D);
if(raw)
Javadoc jd;

// TODO investigate whether we can use
// ASTContext::getCommentForDecl instead of
// this logic. See also similar code in Mapper.cpp.
RawComment* RC = D->getASTContext().getRawCommentForDeclNoCache(D);
if(RC)
{
raw->setAttached();
auto jd = parseJavadoc(*raw, D->getASTContext(), D);
RC->setAttached();
jd = parseJavadoc(RC, D->getASTContext(), D);
}

return emitInfo(D, std::forward<Args>(args)...);
return buildInfo(D, std::move(jd), std::forward<Args>(args)...);
}

// Function to hash a given USR value for storage.
Expand Down

0 comments on commit 95c8da3

Please sign in to comment.