Skip to content

Commit e65ac0f

Browse files
committed
enum and block fixes
1 parent 7aa2e47 commit e65ac0f

17 files changed

+263
-195
lines changed

include/mrdox/Metadata/Enum.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ struct EnumInfo : SymbolInfo
8888
: SymbolInfo(InfoType::IT_enum, id_)
8989
{
9090
}
91-
92-
void merge(EnumInfo&& I);
9391
};
9492

9593
} // mrdox

include/mrdox/Metadata/Info.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ struct Info
6868
{
6969
}
7070

71-
bool canMerge(const Info& Other);
72-
void mergeBase(Info&& I);
73-
7471
//
7572
// Observers
7673
//

include/mrdox/Metadata/Reference.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ struct Reference
6363
std::tie(id, Name, RefType) ==
6464
std::tie(Other.id, Other.Name, Other.RefType);
6565
}
66-
67-
bool canMerge(Reference const& Other);
68-
void merge(Reference&& I);
6966
};
7067

7168
} // mrdox

include/mrdox/Metadata/Variable.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <mrdox/Platform.hpp>
1515
#include <mrdox/Metadata/Symbol.hpp>
16+
#include <mrdox/Metadata/Type.hpp>
1617

1718
namespace clang {
1819
namespace mrdox {
@@ -26,13 +27,19 @@ struct VariableInfo : SymbolInfo
2627
{
2728
TypeInfo Type;
2829

30+
//--------------------------------------------
31+
32+
static constexpr InfoType type_id = InfoType::IT_variable;
33+
2934
explicit
3035
VariableInfo(
3136
SymbolID ID = SymbolID(),
3237
llvm::StringRef Name = llvm::StringRef())
3338
: SymbolInfo(InfoType::IT_variable, ID, Name)
3439
{
3540
}
41+
42+
void merge(TypedefInfo&& I);
3643
};
3744

3845
} // mrdox

source/api/AST/AnyBlock.hpp

+76-6
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,25 @@ class TypeBlock
400400
{
401401
protected:
402402
BitcodeReader& br_;
403+
TypeInfo* p_;
403404

404405
public:
405406
FieldId F;
406407
TypeInfo I;
407408

409+
TypeBlock(
410+
TypeInfo& I_,
411+
BitcodeReader& br) noexcept
412+
: br_(br)
413+
, p_(&I_)
414+
{
415+
}
416+
408417
explicit
409418
TypeBlock(
410419
BitcodeReader& br) noexcept
411420
: br_(br)
421+
, p_(&I)
412422
{
413423
}
414424

@@ -424,7 +434,7 @@ class TypeBlock
424434
if(auto Err = br_.readBlock(B, ID))
425435
return Err;
426436
F = B.F;
427-
I.Type = std::move(B.I);
437+
p_->Type = std::move(B.I);
428438
return llvm::Error::success();
429439
}
430440
default:
@@ -795,6 +805,17 @@ class TopLevelBlock
795805
}
796806
break;
797807
}
808+
case FieldId::F_child_enum:
809+
{
810+
if constexpr(
811+
std::derived_from<T, NamespaceInfo> ||
812+
std::derived_from<T, RecordInfo>)
813+
{
814+
I->Children.Enums.emplace_back(std::move(R));
815+
return llvm::Error::success();
816+
}
817+
break;
818+
}
798819
default:
799820
return makeWrongFieldError(Id);
800821
}
@@ -1061,10 +1082,41 @@ class TypedefBlock
10611082

10621083
//------------------------------------------------
10631084

1085+
class EnumValueBlock : public BitcodeReader::AnyBlock
1086+
{
1087+
BitcodeReader& br_;
1088+
EnumValueInfo& I_;
1089+
1090+
public:
1091+
EnumValueBlock(
1092+
EnumValueInfo& I,
1093+
BitcodeReader& br) noexcept
1094+
: br_(br)
1095+
, I_(I)
1096+
{
1097+
}
1098+
1099+
llvm::Error
1100+
parseRecord(Record const& R,
1101+
unsigned ID, llvm::StringRef Blob) override
1102+
{
1103+
switch(ID)
1104+
{
1105+
case ENUM_VALUE_NAME:
1106+
return decodeRecord(R, I_.Name, Blob);
1107+
case ENUM_VALUE_VALUE:
1108+
return decodeRecord(R, I_.Value, Blob);
1109+
case ENUM_VALUE_EXPR:
1110+
return decodeRecord(R, I_.ValueExpr, Blob);
1111+
default:
1112+
return AnyBlock::parseRecord(R, ID, Blob);
1113+
}
1114+
}
1115+
};
1116+
10641117
class EnumBlock
10651118
: public TopLevelBlock<EnumInfo>
10661119
{
1067-
10681120
public:
10691121
explicit
10701122
EnumBlock(
@@ -1077,27 +1129,39 @@ class EnumBlock
10771129
parseRecord(Record const& R,
10781130
unsigned ID, llvm::StringRef Blob) override
10791131
{
1080-
#if 0
10811132
switch(ID)
10821133
{
1134+
case ENUM_SCOPED:
1135+
return decodeRecord(R, I->Scoped, Blob);
10831136
default:
10841137
break;
10851138
}
1086-
#endif
10871139
return TopLevelBlock::parseRecord(R, ID, Blob);
10881140
}
10891141

10901142
llvm::Error
10911143
readSubBlock(
10921144
unsigned ID) override
10931145
{
1094-
#if 0
10951146
switch(ID)
10961147
{
1148+
case BI_TYPE_BLOCK_ID:
1149+
{
1150+
I->BaseType.emplace();
1151+
TypeBlock B(*I->BaseType, br_);
1152+
return br_.readBlock(B, ID);
1153+
}
1154+
case BI_ENUM_VALUE_BLOCK_ID:
1155+
{
1156+
I->Members.emplace_back();
1157+
EnumValueBlock B(I->Members.back(), br_);
1158+
if(auto Err = br_.readBlock(B, ID))
1159+
return Err;
1160+
return llvm::Error::success();
1161+
}
10971162
default:
10981163
break;
10991164
}
1100-
#endif
11011165
return TopLevelBlock::readSubBlock(ID);
11021166
}
11031167
};
@@ -1167,6 +1231,12 @@ readChild(
11671231
case FieldId::F_child_function:
11681232
I.Functions.emplace_back(B.I);
11691233
break;
1234+
case FieldId::F_child_typedef:
1235+
I.Typedefs.emplace_back(B.I);
1236+
break;
1237+
case FieldId::F_child_enum:
1238+
I.Enums.emplace_back(B.I);
1239+
break;
11701240
default:
11711241
return makeWrongFieldError(B.F);
11721242
}

source/api/AST/Serializer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ build(
12301230
}
12311231
parseEnumerators(I, D);
12321232

1233-
return { writeParent(std::move(I)) };
1233+
return { writeBitcode(I), writeParent(std::move(I)) };
12341234
}
12351235

12361236
SerializeResult

source/api/CorpusImpl.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ get(
130130
Assert(t->IT == InfoType::IT_record);
131131
else if constexpr(std::is_same_v<T, FunctionInfo>)
132132
Assert(t->IT == InfoType::IT_function);
133-
else if constexpr(std::is_same_v<T, EnumInfo>)
134-
Assert(t->IT == InfoType::IT_enum);
135133
else if constexpr(std::is_same_v<T, TypedefInfo>)
136134
Assert(t->IT == InfoType::IT_typedef);
135+
else if constexpr(std::is_same_v<T, EnumInfo>)
136+
Assert(t->IT == InfoType::IT_enum);
137137
return *t;
138138
}
139139

source/api/Metadata/Enum.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,10 @@
2323
// on members on the forward declaration, but would have the class name).
2424
//
2525

26-
#include <mrdox/Debug.hpp>
2726
#include <mrdox/Metadata/Enum.hpp>
2827

2928
namespace clang {
3029
namespace mrdox {
3130

32-
void
33-
EnumInfo::
34-
merge(
35-
EnumInfo&& Other)
36-
{
37-
Assert(canMerge(Other));
38-
if (!Scoped)
39-
Scoped = Other.Scoped;
40-
if (Members.empty())
41-
Members = std::move(Other.Members);
42-
SymbolInfo::merge(std::move(Other));
43-
}
44-
4531
} // mrdox
4632
} // clang

source/api/Metadata/Function.cpp

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

12-
#include <mrdox/Debug.hpp>
1312
#include <mrdox/Metadata/Function.hpp>
14-
#include <utility>
1513

1614
namespace clang {
1715
namespace mrdox {
1816

19-
void
20-
FunctionInfo::
21-
merge(
22-
FunctionInfo&& Other)
23-
{
24-
Assert(canMerge(Other));
25-
if (!IsMethod)
26-
IsMethod = Other.IsMethod;
27-
if (!Access)
28-
Access = Other.Access;
29-
if (ReturnType.Type.id == EmptySID && ReturnType.Type.Name == "")
30-
ReturnType = std::move(Other.ReturnType);
31-
if (Parent.id == EmptySID && Parent.Name == "")
32-
Parent = std::move(Other.Parent);
33-
if (Params.empty())
34-
Params = std::move(Other.Params);
35-
SymbolInfo::merge(std::move(Other));
36-
if (!Template)
37-
Template = Other.Template;
38-
specs0.merge(std::move(Other).specs0);
39-
specs1.merge(std::move(Other).specs1);
40-
}
41-
4217
} // mrdox
4318
} // clang
4419

source/api/Metadata/Info.cpp

-28
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,6 @@
2121
namespace clang {
2222
namespace mrdox {
2323

24-
bool
25-
Info::
26-
canMerge(
27-
Info const& Other)
28-
{
29-
return
30-
IT == Other.IT &&
31-
id == Other.id;
32-
}
33-
34-
void
35-
Info::
36-
mergeBase(
37-
Info&& Other)
38-
{
39-
Assert(canMerge(Other));
40-
if (id == EmptySID)
41-
id = Other.id;
42-
if (Name == "")
43-
Name = Other.Name;
44-
if (Namespace.empty())
45-
Namespace = std::move(Other.Namespace);
46-
if(! javadoc)
47-
javadoc = std::move(Other.javadoc);
48-
else if(Other.javadoc)
49-
javadoc->merge(std::move(*Other.javadoc));
50-
}
51-
5224
llvm::SmallString<16>
5325
Info::
5426
extractName() const

source/api/Metadata/Namespace.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,5 @@ NamespaceInfo(
3838
{
3939
}
4040

41-
void
42-
NamespaceInfo::
43-
merge(NamespaceInfo&& Other)
44-
{
45-
Assert(canMerge(Other));
46-
// Reduce children if necessary.
47-
reduceChildren(Children.Namespaces, std::move(Other.Children.Namespaces));
48-
reduceChildren(Children.Records, std::move(Other.Children.Records));
49-
reduceChildren(Children.Functions, std::move(Other.Children.Functions));
50-
reduceChildren(Children.Typedefs, std::move(Other.Children.Typedefs));
51-
reduceChildren(Children.Enums, std::move(Other.Children.Enums));
52-
mergeBase(std::move(Other));
53-
}
54-
5541
} // mrdox
5642
} // clang

source/api/Metadata/Record.cpp

-38
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,5 @@ RecordInfo(
2929
{
3030
}
3131

32-
void
33-
RecordInfo::
34-
merge(RecordInfo&& Other)
35-
{
36-
Assert(canMerge(Other));
37-
if (!TagType)
38-
TagType = Other.TagType;
39-
IsTypeDef = IsTypeDef || Other.IsTypeDef;
40-
specs.merge(std::move(Other).specs);
41-
if (Members.empty())
42-
Members = std::move(Other.Members);
43-
if (Bases.empty())
44-
Bases = std::move(Other.Bases);
45-
if (Parents.empty())
46-
Parents = std::move(Other.Parents);
47-
if (VirtualParents.empty())
48-
VirtualParents = std::move(Other.VirtualParents);
49-
// Reduce children if necessary.
50-
reduceChildren(Children.Records, std::move(Other.Children.Records));
51-
reduceChildren(Children.Functions, std::move(Other.Children.Functions));
52-
reduceChildren(Children.Typedefs, std::move(Other.Children.Typedefs));
53-
reduceChildren(Children.Enums, std::move(Other.Children.Enums));
54-
SymbolInfo::merge(std::move(Other));
55-
if (!Template)
56-
Template = Other.Template;
57-
if(! Other.Friends.empty())
58-
{
59-
llvm::append_range(Friends, std::move(Other.Friends));
60-
llvm::sort(Friends,
61-
[](SymbolID const& id0, SymbolID const& id1)
62-
{
63-
return id0 < id1;
64-
});
65-
auto last = std::unique(Friends.begin(), Friends.end());
66-
Friends.erase(last, Friends.end());
67-
}
68-
}
69-
7032
} // mrdox
7133
} // clang

0 commit comments

Comments
 (0)