Skip to content

Commit c2abb69

Browse files
committed
chore: BaseInfo stores type using TypeInfo
1 parent 072f43c commit c2abb69

File tree

10 files changed

+53
-111
lines changed

10 files changed

+53
-111
lines changed

include/mrdox/Metadata/Record.hpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,19 @@ union RecFlags0
4444
*/
4545
struct BaseInfo
4646
{
47-
SymbolID id;
48-
std::string Name;
49-
AccessKind Access;
50-
bool IsVirtual;
47+
TypeInfo Type;
48+
AccessKind Access = AccessKind::Public;
49+
bool IsVirtual = false;
50+
51+
BaseInfo() = default;
5152

5253
BaseInfo(
53-
SymbolID const& id_ = SymbolID::zero,
54-
std::string_view Name_ = "",
55-
AccessKind access = AccessKind::Public,
56-
bool IsVirtual_ = false)
57-
: id(id_)
58-
, Name(Name_)
54+
TypeInfo&& type,
55+
AccessKind access,
56+
bool is_virtual)
57+
: Type(std::move(type))
5958
, Access(access)
60-
, IsVirtual(IsVirtual_)
59+
, IsVirtual(is_virtual)
6160
{
6261
}
6362
};

source/-XML/XMLWriter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ writeRecord(
357357

358358
for(auto const& B : I.Bases)
359359
tags_.write(baseTagName, "", {
360-
{ "name", B.Name },
360+
{ "name", B.Type.Name },
361361
{ B.Access },
362362
{ "class", "virtual", B.IsVirtual },
363-
{ B.id }
363+
{ B.Type.id }
364364
});
365365

366366
// Friends

source/AST/ASTVisitor.cpp

+5-56
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,6 @@ getTypeAsString(
148148
return T.getAsString(astContext_->getPrintingPolicy());
149149
}
150150

151-
TagDecl*
152-
ASTVisitor::
153-
getTagDeclForType(
154-
QualType T)
155-
{
156-
if(TagDecl const* D = T->getAsTagDecl())
157-
return D->getDefinition();
158-
return nullptr;
159-
}
160-
161-
CXXRecordDecl*
162-
ASTVisitor::
163-
getCXXRecordDeclForType(
164-
QualType T)
165-
{
166-
if(CXXRecordDecl const* D = T->getAsCXXRecordDecl())
167-
return D->getDefinition();
168-
return nullptr;
169-
}
170-
171151
SymbolID
172152
ASTVisitor::
173153
getSymbolIDForType(
@@ -784,42 +764,11 @@ extractBases(
784764
// Only direct bases
785765
for(CXXBaseSpecifier const& B : D->bases())
786766
{
787-
auto const isVirtual = B.isVirtual();
788-
// KRYSTIAN NOTE: is this right? a class with a single
789-
// virtual base would be ignored here with ! config_.includePrivate
790-
if(isVirtual && ! config_.includePrivate)
791-
continue;
792-
793-
SymbolID id = SymbolID::zero;
794-
AccessKind access = convertToAccessKind(
795-
B.getAccessSpecifier());
796-
if(auto const* Ty = B.getType()->getAs<TemplateSpecializationType>())
797-
{
798-
TemplateDecl const* TD = Ty->getTemplateName().getAsTemplateDecl();
799-
extractSymbolID(TD, id);
800-
I.Bases.emplace_back(
801-
id,
802-
getTypeAsString(B.getType()),
803-
access,
804-
isVirtual);
805-
}
806-
else if(CXXRecordDecl const* P = getCXXRecordDeclForType(B.getType()))
807-
{
808-
extractSymbolID(P, id);
809-
I.Bases.emplace_back(
810-
id,
811-
P->getNameAsString(),
812-
access,
813-
isVirtual);
814-
}
815-
else
816-
{
817-
I.Bases.emplace_back(
818-
id,
819-
getTypeAsString(B.getType()),
820-
access,
821-
isVirtual);
822-
}
767+
I.Bases.emplace_back(
768+
getTypeInfoForType(B.getType()),
769+
convertToAccessKind(
770+
B.getAccessSpecifier()),
771+
B.isVirtual());
823772
}
824773
}
825774

source/AST/ASTVisitor.hpp

-8
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ class ASTVisitor
103103
getTypeAsString(
104104
QualType T);
105105

106-
TagDecl*
107-
getTagDeclForType(
108-
QualType T);
109-
110-
CXXRecordDecl*
111-
getCXXRecordDeclForType(
112-
QualType T);
113-
114106
SymbolID
115107
getSymbolIDForType(
116108
QualType T);

source/AST/AnyBlock.hpp

+27-15
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,17 @@ class TypeBlock
410410
class BaseBlock
411411
: public BitcodeReader::AnyBlock
412412
{
413-
std::vector<BaseInfo>& v_;
413+
BitcodeReader& br_;
414+
BaseInfo& I_;
414415

415416
public:
416417
explicit
417418
BaseBlock(
418-
std::vector<BaseInfo>& v) noexcept
419-
: v_(v)
419+
BaseInfo& I,
420+
BitcodeReader& br) noexcept
421+
: I_(I)
422+
, br_(br)
420423
{
421-
v_.emplace_back();
422424
}
423425

424426
Error
@@ -429,18 +431,30 @@ class BaseBlock
429431
{
430432
switch(ID)
431433
{
432-
case BASE_ID:
433-
return decodeRecord(R, v_.back().id, Blob);
434-
case BASE_NAME:
435-
return decodeRecord(R, v_.back().Name, Blob);
436434
case BASE_ACCESS:
437-
return decodeRecord(R, v_.back().Access, Blob);
435+
return decodeRecord(R, I_.Access, Blob);
438436
case BASE_IS_VIRTUAL:
439-
return decodeRecord(R, v_.back().IsVirtual, Blob);
437+
return decodeRecord(R, I_.IsVirtual, Blob);
440438
default:
441439
return AnyBlock::parseRecord(R, ID, Blob);
442440
}
443441
}
442+
443+
Error
444+
readSubBlock(
445+
unsigned ID) override
446+
{
447+
switch(ID)
448+
{
449+
case BI_TYPE_BLOCK_ID:
450+
{
451+
TypeBlock B(I_.Type, br_);
452+
return br_.readBlock(B, ID);
453+
}
454+
default:
455+
return AnyBlock::readSubBlock(ID);
456+
}
457+
}
444458
};
445459

446460
//------------------------------------------------
@@ -687,9 +701,8 @@ class FunctionParamBlock
687701
return br_.readBlock(B, ID);
688702
}
689703
default:
690-
break;
704+
return AnyBlock::readSubBlock(ID);
691705
}
692-
return AnyBlock::readSubBlock(ID);
693706
}
694707
};
695708

@@ -795,7 +808,7 @@ class RecordBlock
795808
{
796809
case BI_BASE_BLOCK_ID:
797810
{
798-
BaseBlock B(I->Bases);
811+
BaseBlock B(I->Bases.emplace_back(), br_);
799812
return br_.readBlock(B, ID);
800813
}
801814
case BI_TEMPLATE_BLOCK_ID:
@@ -805,9 +818,8 @@ class RecordBlock
805818
return br_.readBlock(B, ID);
806819
}
807820
default:
808-
break;
821+
return TopLevelBlock::readSubBlock(ID);
809822
}
810-
return TopLevelBlock::readSubBlock(ID);
811823
}
812824
};
813825

source/AST/BitcodeIDs.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ enum RecordID
9292
TYPE_ID,
9393
TYPE_NAME,
9494
BASE_ACCESS,
95-
BASE_ID,
9695
BASE_IS_VIRTUAL,
97-
BASE_NAME,
9896
FIELD_ATTRIBUTES,
9997
FIELD_DEFAULT,
10098
FIELD_NAME,

source/AST/BitcodeWriter.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ RecordIDNameMap = []()
233233
// improvise
234234
static const std::vector<std::pair<RecordID, RecordIDDsc>> Inits = {
235235
{VERSION, {"Version", &Integer32Abbrev}},
236-
{BASE_ID, {"BaseID", &SymbolIDAbbrev}},
237-
{BASE_NAME, {"BaseName", &StringAbbrev}},
238236
{BASE_ACCESS, {"BaseAccess", &Integer32Abbrev}},
239237
{BASE_IS_VIRTUAL, {"BaseIsVirtual", &BoolAbbrev}},
240238
{ENUM_SCOPED, {"Scoped", &BoolAbbrev}},
@@ -306,7 +304,7 @@ RecordsByBlock{
306304
{SOURCE_INFO_DEFLOC, SOURCE_INFO_LOC}},
307305
// BaseInfo
308306
{BI_BASE_BLOCK_ID,
309-
{BASE_ID, BASE_NAME, BASE_ACCESS, BASE_IS_VIRTUAL}},
307+
{BASE_ACCESS, BASE_IS_VIRTUAL}},
310308
// EnumInfo
311309
{BI_ENUM_BLOCK_ID,
312310
{ENUM_SCOPED}},
@@ -761,10 +759,9 @@ emitBlock(
761759
BaseInfo const& I)
762760
{
763761
StreamSubBlockGuard Block(Stream, BI_BASE_BLOCK_ID);
764-
emitRecord(I.id, BASE_ID);
765-
emitRecord(I.Name, BASE_NAME);
766762
emitRecord(I.Access, BASE_ACCESS);
767763
emitRecord(I.IsVirtual, BASE_IS_VIRTUAL);
764+
emitBlock(I.Type);
768765
}
769766

770767
void

source/Dom/DomBase.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <mrdox/Dom/DomBase.hpp>
1212
#include <mrdox/Dom/DomSymbol.hpp>
13+
#include <mrdox/Dom/DomType.hpp>
1314

1415
namespace clang {
1516
namespace mrdox {
@@ -28,14 +29,8 @@ dom::Value
2829
DomBase::
2930
get(std::string_view key) const
3031
{
31-
if(key == "name")
32-
{
33-
// this overrides the name in the Info,
34-
// for the case where the symbolID is zero.
35-
if(B_->id != SymbolID::zero)
36-
return I_->Name;
37-
return B_->Name;
38-
}
32+
if(key == "type")
33+
return dom::makePointer<DomType>(B_->Type, corpus_);
3934
if(key == "base-access")
4035
return toString(B_->Access);
4136
if(key == "is-virtual")
@@ -52,7 +47,7 @@ props() const ->
5247
std::vector<std::string_view> v =
5348
DomSymbol<RecordInfo>::props();
5449
v.insert(v.end(), {
55-
//"name", // already there from Symbol
50+
"type",
5651
"base-access",
5752
"is-virtual"
5853
});

source/Dom/DomBaseArray.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ get(
3838
if(index < list_.size())
3939
return dom::makePointer<DomBase>(
4040
corpus_.get<RecordInfo>(
41-
list_[index].id),
41+
list_[index].Type.id),
4242
list_[index],
4343
corpus_);
4444
return nullptr;

source/Metadata/Interface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class Interface::Build
8181
auto actualAccess = effectiveAccess(access, B.Access);
8282
// VFALCO temporary hack to avoid looking up IDs
8383
// which for metadata that is not emitted.
84-
if(! corpus_.find(B.id))
84+
if(! corpus_.find(B.Type.id))
8585
continue;
86-
append(actualAccess, corpus_.get<RecordInfo>(B.id));
86+
append(actualAccess, corpus_.get<RecordInfo>(B.Type.id));
8787
}
8888

8989
if( includePrivate_ ||

0 commit comments

Comments
 (0)