Skip to content

Commit ceb5fd3

Browse files
committed
ASTVisitor refactor
1 parent 9d909e3 commit ceb5fd3

File tree

9 files changed

+616
-475
lines changed

9 files changed

+616
-475
lines changed

include/mrdox/Metadata/Function.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ struct Param
107107
struct FunctionInfo
108108
: SymbolInfo
109109
{
110+
friend class ASTVisitor;
111+
110112
TypeInfo ReturnType; // Info about the return type of this function.
111113
std::vector<Param> Params; // List of parameters.
112114

113115
// When present, this function is a template or specialization.
114-
std::optional<TemplateInfo> Template;
116+
std::unique_ptr<TemplateInfo> Template;
115117

116118
FnFlags0 specs0{.raw{0}};
117119
FnFlags1 specs1{.raw{0}};
@@ -126,6 +128,15 @@ struct FunctionInfo
126128
: SymbolInfo(InfoType::IT_function, id_)
127129
{
128130
}
131+
132+
private:
133+
explicit
134+
FunctionInfo(
135+
std::unique_ptr<TemplateInfo>&& T)
136+
: SymbolInfo(InfoType::IT_function)
137+
, Template(std::move(T))
138+
{
139+
}
129140
};
130141

131142
//------------------------------------------------

include/mrdox/Metadata/Record.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ struct RecordScope
8080
struct RecordInfo
8181
: SymbolInfo
8282
{
83+
friend class ASTVisitor;
84+
8385
// VFALCO Use our own enumeration for this
8486
// Type of this record (struct, class, union, interface).
8587
TagTypeKind TagType = TagTypeKind::TTK_Struct;
8688

8789
// When present, this record is a template or specialization.
88-
std::optional<TemplateInfo> Template;
90+
std::unique_ptr<TemplateInfo> Template;
8991

9092
// Indicates if the record was declared using a typedef. Things like anonymous
9193
// structs in a typedef:
@@ -119,6 +121,15 @@ struct RecordInfo
119121
: SymbolInfo(InfoType::IT_record, id, Name)
120122
{
121123
}
124+
125+
private:
126+
explicit
127+
RecordInfo(
128+
std::unique_ptr<TemplateInfo>&& T)
129+
: SymbolInfo(InfoType::IT_record)
130+
, Template(std::move(T))
131+
{
132+
}
122133
};
123134

124135
} // mrdox

source/-XML/XMLWriter.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ writeFunction(
347347

348348
writeSymbol(I);
349349

350-
writeTemplate(I.Template);
350+
if(I.Template)
351+
writeTemplate(*I.Template);
351352

352353
write(I.specs0, tags_);
353354
write(I.specs1, tags_);
@@ -386,7 +387,8 @@ writeRecord(
386387

387388
writeSymbol(I);
388389

389-
writeTemplate(I.Template);
390+
if(I.Template)
391+
writeTemplate(*I.Template);
390392

391393
write(I.specs, tags_);
392394

@@ -535,13 +537,10 @@ writeLocation(
535537
void
536538
XMLWriter::
537539
writeTemplate(
538-
const std::optional<TemplateInfo>& I)
540+
const TemplateInfo& I)
539541
{
540-
if(! I)
541-
return;
542-
543542
const char* spec = nullptr;
544-
switch(I->specializationKind())
543+
switch(I.specializationKind())
545544
{
546545
case TemplateSpecKind::Explicit:
547546
spec = "explicit";
@@ -552,17 +551,17 @@ writeTemplate(
552551
default:
553552
break;
554553
}
555-
const SymbolID& id = I->Primary ?
556-
*I->Primary : SymbolID::zero;
554+
const SymbolID& id = I.Primary ?
555+
*I.Primary : SymbolID::zero;
557556

558557
tags_.open(templateTagName, {
559558
{"class", spec, !! spec},
560559
{id}
561560
});
562561

563-
for(const TParam& tparam : I->Params)
562+
for(const TParam& tparam : I.Params)
564563
writeTemplateParam(tparam, tags_);
565-
for(const TArg& targ : I->Args)
564+
for(const TArg& targ : I.Args)
566565
writeTemplateArg(targ, tags_);
567566

568567
tags_.close(templateTagName);

source/-XML/XMLWriter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class XMLWriter
8585
void writeSymbol(SymbolInfo const& I);
8686
void writeLocation(Location const& loc, bool def = false);
8787
void writeJavadoc(std::optional<Javadoc> const& javadoc);
88-
void writeTemplate(const std::optional<TemplateInfo>& I);
88+
void writeTemplate(const TemplateInfo& I);
8989

9090
template<class T>
9191
void writeNodes(AnyList<T> const& list);

0 commit comments

Comments
 (0)