Skip to content

Commit 362fdaa

Browse files
committed
Javadoc is optional
1 parent fe396da commit 362fdaa

File tree

14 files changed

+109
-124
lines changed

14 files changed

+109
-124
lines changed

include/mrdox/meta/Enum.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ struct EnumInfo : SymbolInfo
7070
// Indicates whether this enum is scoped (e.g. enum class).
7171
bool Scoped = false;
7272

73+
// Set to nonempty to the type when this is an explicitly typed enum. For
74+
// enum Foo : short { ... };
75+
// this will be "short".
76+
llvm::Optional<TypeInfo> BaseType;
77+
78+
llvm::SmallVector<EnumValueInfo, 4> Members; // List of enum members.
79+
7380
//--------------------------------------------
7481

7582
static constexpr InfoType type_id = InfoType::IT_enum;
@@ -87,13 +94,6 @@ struct EnumInfo : SymbolInfo
8794
}
8895

8996
void merge(EnumInfo&& I);
90-
91-
// Set to nonempty to the type when this is an explicitly typed enum. For
92-
// enum Foo : short { ... };
93-
// this will be "short".
94-
llvm::Optional<TypeInfo> BaseType;
95-
96-
llvm::SmallVector<EnumValueInfo, 4> Members; // List of enum members.
9797
};
9898

9999
} // mrdox

include/mrdox/meta/Info.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <mrdox/meta/Javadoc.hpp>
1616
#include <mrdox/meta/Reference.hpp>
1717
#include <mrdox/meta/Symbols.hpp>
18+
#include <llvm/ADT/Optional.h>
1819
#include <llvm/ADT/StringRef.h>
1920
#include <llvm/ADT/SmallString.h>
2021
#include <llvm/ADT/SmallVector.h>
@@ -47,7 +48,7 @@ struct Info
4748

4849
/** The extracted javadoc for this declaration.
4950
*/
50-
Javadoc javadoc;
51+
llvm::Optional<Javadoc> javadoc;
5152

5253
//--------------------------------------------
5354

include/mrdox/meta/Javadoc.hpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,6 @@ struct Javadoc
297297
Javadoc(
298298
List<Block> blocks);
299299

300-
/** Return true if this has a value.
301-
302-
A value will exist if a FullComment node
303-
was encountered while visiting the AST.
304-
After post-processing, it is possible for
305-
this function to return `true` even if
306-
there are no top-level blocks remaining.
307-
*/
308-
bool
309-
has_value() const noexcept
310-
{
311-
return has_value_;
312-
}
313-
314300
/** Return true if this is empty
315301
*/
316302
bool
@@ -327,14 +313,6 @@ struct Javadoc
327313
return brief_.get();
328314
}
329315

330-
/** Set the object as having a value.
331-
*/
332-
void
333-
emplace() noexcept
334-
{
335-
has_value_ = true;
336-
}
337-
338316
/** Return the list of top level blocks.
339317
*/
340318
List<Block> const&
@@ -446,7 +424,6 @@ struct Javadoc
446424
private:
447425
std::shared_ptr<Paragraph const> brief_;
448426
List<Block> blocks_;
449-
bool has_value_ = false;
450427
};
451428

452429
} // mrdox

include/mrdox/meta/MemberType.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ struct MemberTypeInfo
2424
: FieldTypeInfo
2525
//, SymbolInfo
2626
{
27+
// VFALCO This is public because 0 values in bitcode are not emitted...
28+
// Access level associated with this info (public, protected, private, none).
29+
// AS_public is set as default because the bitcode writer requires the enum
30+
// with value 0 to be used as the default.
31+
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
32+
AccessSpecifier Access = AccessSpecifier::AS_public;
33+
34+
llvm::Optional<Javadoc> javadoc;
35+
36+
//--------------------------------------------
37+
2738
MemberTypeInfo() = default;
2839

2940
MemberTypeInfo(
@@ -43,15 +54,6 @@ struct MemberTypeInfo
4354
std::tie(Type, Name, Access, javadoc) ==
4455
std::tie(Other.Type, Other.Name, Other.Access, Other.javadoc);
4556
}
46-
47-
// VFALCO Why public?
48-
// Access level associated with this info (public, protected, private, none).
49-
// AS_public is set as default because the bitcode writer requires the enum
50-
// with value 0 to be used as the default.
51-
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
52-
AccessSpecifier Access = AccessSpecifier::AS_public;
53-
54-
Javadoc javadoc;
5557
};
5658

5759
} // mrdox

source/lib/ast/BitcodeReader.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,19 @@ decodeRecord(
249249

250250
//------------------------------------------------
251251

252-
llvm::Expected<Javadoc*>
253-
getJavadoc(...)
252+
template<class T>
253+
llvm::Expected<llvm::Optional<Javadoc>*>
254+
getJavadoc(T I)
254255
{
255-
return makeError("invalid type cannot contain Javadoc");
256-
}
257-
258-
llvm::Expected<Javadoc*>
259-
getJavadoc(Info* I)
260-
{
261-
return &I->javadoc;
262-
}
263-
264-
llvm::Expected<Javadoc*>
265-
getJavadoc(MemberTypeInfo* I)
266-
{
267-
return &I->javadoc;
256+
if constexpr(std::is_pointer_v<T>)
257+
{
258+
using U = std::remove_pointer_t<T>;
259+
if constexpr(std::derived_from<U, Info>)
260+
return &I->javadoc;
261+
else if constexpr(std::derived_from<U, MemberTypeInfo>)
262+
return &I->javadoc;
263+
}
264+
return makeError("wrong type");
268265
}
269266

270267
//------------------------------------------------
@@ -819,7 +816,7 @@ readSubBlock(
819816
return rv.takeError();
820817
javadoc_ = rv.get();
821818
javadoc_->emplace();
822-
if(auto err = readBlock(ID, javadoc_))
819+
if(auto err = readBlock(ID, &*javadoc_))
823820
return err;
824821
javadoc_ = nullptr;
825822
return llvm::Error::success();
@@ -832,7 +829,7 @@ readSubBlock(
832829
return err;
833830
if(! J.isTopLevel())
834831
return J.spliceIntoParent();
835-
return J.spliceInto(javadoc_->getBlocks());
832+
return J.spliceInto((*javadoc_)->getBlocks());
836833
}
837834

838835
case BI_JAVADOC_NODE_BLOCK_ID:
@@ -1316,7 +1313,7 @@ parseRecord(
13161313
Record const& R,
13171314
unsigned ID,
13181315
llvm::StringRef blob,
1319-
Javadoc* I)
1316+
llvm::Optional<Javadoc>* I)
13201317
{
13211318
// VFALCO Should never get here because this
13221319
// only contains sub-blocks and no records (yet).

source/lib/ast/BitcodeReader.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class BitcodeReader
131131
llvm::Error parseRecord(Record const& R, unsigned ID,
132132
llvm::StringRef Blob, TemplateParamInfo* I);
133133
llvm::Error parseRecord(Record const& R, unsigned ID,
134-
llvm::StringRef Blob, Javadoc* I);
134+
llvm::StringRef Blob, llvm::Optional<Javadoc>* I);
135135
llvm::Error parseRecord(Record const& R, unsigned ID,
136136
llvm::StringRef Blob, AnyNodeList* I);
137137
llvm::Error parseRecord(Record const& R, unsigned ID,
@@ -146,7 +146,7 @@ class BitcodeReader
146146
llvm::BitstreamCursor& Stream;
147147
llvm::Optional<llvm::BitstreamBlockInfo> BlockInfo;
148148
FieldId CurrentReferenceField;
149-
Javadoc* javadoc_ = nullptr;
149+
llvm::Optional<Javadoc>* javadoc_ = nullptr;
150150
AnyNodeList* nodes_ = nullptr;
151151
};
152152

source/lib/ast/BitcodeWriter.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ emitBlock(
417417
emitRecord(I.Name, NAMESPACE_NAME);
418418
for (const auto& N : I.Namespace)
419419
emitBlock(N, FieldId::F_namespace);
420-
emitBlock(I.javadoc);
420+
if(I.javadoc)
421+
emitBlock(*I.javadoc);
421422
for (const auto& C : I.Children.Namespaces)
422423
emitBlock(C, FieldId::F_child_namespace);
423424
for (const auto& C : I.Children.Records)
@@ -440,7 +441,8 @@ emitBlock(
440441
emitRecord(I.Name, RECORD_NAME);
441442
for (const auto& N : I.Namespace)
442443
emitBlock(N, FieldId::F_namespace);
443-
emitBlock(I.javadoc);
444+
if(I.javadoc)
445+
emitBlock(*I.javadoc);
444446
if (I.DefLoc)
445447
emitRecord(*I.DefLoc, RECORD_DEFLOCATION);
446448
for (const auto& L : I.Loc)
@@ -494,7 +496,8 @@ emitBlock(
494496
emitRecord(I.Name, FUNCTION_NAME);
495497
for (const auto& N : I.Namespace)
496498
emitBlock(N, FieldId::F_namespace);
497-
emitBlock(I.javadoc);
499+
if(I.javadoc)
500+
emitBlock(*I.javadoc);
498501
emitRecord(I.Access, FUNCTION_ACCESS);
499502
emitRecord(I.IsMethod, FUNCTION_IS_METHOD);
500503
emitRecord(I.specs.bits(), FUNCTION_BITS);
@@ -520,7 +523,8 @@ emitBlock(
520523
emitRecord(I.Name, ENUM_NAME);
521524
for (const auto& N : I.Namespace)
522525
emitBlock(N, FieldId::F_namespace);
523-
emitBlock(I.javadoc);
526+
if(I.javadoc)
527+
emitBlock(*I.javadoc);
524528
if (I.DefLoc)
525529
emitRecord(*I.DefLoc, ENUM_DEFLOCATION);
526530
for (const auto& L : I.Loc)
@@ -562,7 +566,8 @@ emitBlock(
562566
emitRecord(T.Name, TYPEDEF_NAME);
563567
for (const auto& N : T.Namespace)
564568
emitBlock(N, FieldId::F_namespace);
565-
emitBlock(T.javadoc);
569+
if(T.javadoc)
570+
emitBlock(*T.javadoc);
566571
if (T.DefLoc)
567572
emitRecord(*T.DefLoc, TYPEDEF_DEFLOCATION);
568573
emitRecord(T.IsUsing, TYPEDEF_IS_USING);
@@ -589,19 +594,19 @@ emitBlock(
589594
emitBlock(T.Type, FieldId::F_type);
590595
emitRecord(T.Name, MEMBER_TYPE_NAME);
591596
emitRecord(T.Access, MEMBER_TYPE_ACCESS);
592-
emitBlock(T.javadoc);
597+
if(T.javadoc)
598+
emitBlock(*T.javadoc);
593599
}
594600

595601
void
596602
BitcodeWriter::
597603
emitBlock(
598604
Javadoc const& jd)
599605
{
600-
if(jd.has_value())
601-
{
602-
StreamSubBlockGuard Block(Stream, BI_JAVADOC_BLOCK_ID);
603-
emitBlock(jd.getBlocks());
604-
}
606+
// If the optional<Javadoc> has a value then we
607+
// always want to emit it, even if it is empty.
608+
StreamSubBlockGuard Block(Stream, BI_JAVADOC_BLOCK_ID);
609+
emitBlock(jd.getBlocks());
605610
}
606611

607612
template<class T>

source/lib/ast/Serialize.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ getTemplateParams(
293293
static
294294
void
295295
parseJavadoc(
296-
Javadoc& javadoc,
296+
llvm::Optional<Javadoc>& javadoc,
297297
Decl const* D)
298298
{
299299
// VFALCO investigate whether we can use
@@ -303,7 +303,11 @@ parseJavadoc(
303303
if(RC)
304304
{
305305
RC->setAttached();
306-
javadoc = parseJavadoc(RC, D->getASTContext(), D);
306+
javadoc.emplace(parseJavadoc(RC, D->getASTContext(), D));
307+
}
308+
else
309+
{
310+
javadoc.reset();
307311
}
308312
}
309313

0 commit comments

Comments
 (0)