Skip to content

Commit

Permalink
ASTVisitor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed May 29, 2023
1 parent 9d909e3 commit ceb5fd3
Show file tree
Hide file tree
Showing 9 changed files with 616 additions and 475 deletions.
13 changes: 12 additions & 1 deletion include/mrdox/Metadata/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ struct Param
struct FunctionInfo
: SymbolInfo
{
friend class ASTVisitor;

TypeInfo ReturnType; // Info about the return type of this function.
std::vector<Param> Params; // List of parameters.

// When present, this function is a template or specialization.
std::optional<TemplateInfo> Template;
std::unique_ptr<TemplateInfo> Template;

FnFlags0 specs0{.raw{0}};
FnFlags1 specs1{.raw{0}};
Expand All @@ -126,6 +128,15 @@ struct FunctionInfo
: SymbolInfo(InfoType::IT_function, id_)
{
}

private:
explicit
FunctionInfo(
std::unique_ptr<TemplateInfo>&& T)
: SymbolInfo(InfoType::IT_function)
, Template(std::move(T))
{
}
};

//------------------------------------------------
Expand Down
13 changes: 12 additions & 1 deletion include/mrdox/Metadata/Record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ struct RecordScope
struct RecordInfo
: SymbolInfo
{
friend class ASTVisitor;

// VFALCO Use our own enumeration for this
// Type of this record (struct, class, union, interface).
TagTypeKind TagType = TagTypeKind::TTK_Struct;

// When present, this record is a template or specialization.
std::optional<TemplateInfo> Template;
std::unique_ptr<TemplateInfo> Template;

// Indicates if the record was declared using a typedef. Things like anonymous
// structs in a typedef:
Expand Down Expand Up @@ -119,6 +121,15 @@ struct RecordInfo
: SymbolInfo(InfoType::IT_record, id, Name)
{
}

private:
explicit
RecordInfo(
std::unique_ptr<TemplateInfo>&& T)
: SymbolInfo(InfoType::IT_record)
, Template(std::move(T))
{
}
};

} // mrdox
Expand Down
21 changes: 10 additions & 11 deletions source/-XML/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ writeFunction(

writeSymbol(I);

writeTemplate(I.Template);
if(I.Template)
writeTemplate(*I.Template);

write(I.specs0, tags_);
write(I.specs1, tags_);
Expand Down Expand Up @@ -386,7 +387,8 @@ writeRecord(

writeSymbol(I);

writeTemplate(I.Template);
if(I.Template)
writeTemplate(*I.Template);

write(I.specs, tags_);

Expand Down Expand Up @@ -535,13 +537,10 @@ writeLocation(
void
XMLWriter::
writeTemplate(
const std::optional<TemplateInfo>& I)
const TemplateInfo& I)
{
if(! I)
return;

const char* spec = nullptr;
switch(I->specializationKind())
switch(I.specializationKind())
{
case TemplateSpecKind::Explicit:
spec = "explicit";
Expand All @@ -552,17 +551,17 @@ writeTemplate(
default:
break;
}
const SymbolID& id = I->Primary ?
*I->Primary : SymbolID::zero;
const SymbolID& id = I.Primary ?
*I.Primary : SymbolID::zero;

tags_.open(templateTagName, {
{"class", spec, !! spec},
{id}
});

for(const TParam& tparam : I->Params)
for(const TParam& tparam : I.Params)
writeTemplateParam(tparam, tags_);
for(const TArg& targ : I->Args)
for(const TArg& targ : I.Args)
writeTemplateArg(targ, tags_);

tags_.close(templateTagName);
Expand Down
2 changes: 1 addition & 1 deletion source/-XML/XMLWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class XMLWriter
void writeSymbol(SymbolInfo const& I);
void writeLocation(Location const& loc, bool def = false);
void writeJavadoc(std::optional<Javadoc> const& javadoc);
void writeTemplate(const std::optional<TemplateInfo>& I);
void writeTemplate(const TemplateInfo& I);

template<class T>
void writeNodes(AnyList<T> const& list);
Expand Down
Loading

0 comments on commit ceb5fd3

Please sign in to comment.