Skip to content

Commit

Permalink
chore: rename SymbolInfo to SourceInfo, move Location into Source.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Jun 14, 2023
1 parent 711baf4 commit 77729b0
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 118 deletions.
3 changes: 1 addition & 2 deletions include/mrdox/Metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
#include <mrdox/Metadata/Info.hpp>
#include <mrdox/Metadata/Interface.hpp>
#include <mrdox/Metadata/Javadoc.hpp>
#include <mrdox/Metadata/Location.hpp>
#include <mrdox/Metadata/Namespace.hpp>
#include <mrdox/Metadata/Overloads.hpp>
#include <mrdox/Metadata/Record.hpp>
#include <mrdox/Metadata/Specialization.hpp>
#include <mrdox/Metadata/Symbol.hpp>
#include <mrdox/Metadata/Source.hpp>
#include <mrdox/Metadata/Symbols.hpp>
#include <mrdox/Metadata/Template.hpp>
#include <mrdox/Metadata/Type.hpp>
Expand Down
4 changes: 2 additions & 2 deletions include/mrdox/Metadata/Enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <mrdox/Platform.hpp>
#include <mrdox/Metadata/Javadoc.hpp>
#include <mrdox/Metadata/Symbol.hpp>
#include <mrdox/Metadata/Source.hpp>
#include <mrdox/Metadata/Type.hpp>
#include <optional>
#include <string>
Expand Down Expand Up @@ -63,7 +63,7 @@ struct EnumValueInfo
// Info for types.
struct EnumInfo
: IsInfo<InfoKind::Enum>
, SymbolInfo
, SourceInfo
{
// Indicates whether this enum is scoped (e.g. enum class).
bool Scoped = false;
Expand Down
4 changes: 2 additions & 2 deletions include/mrdox/Metadata/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <mrdox/Platform.hpp>
#include <mrdox/Metadata/Info.hpp>
#include <mrdox/Metadata/Symbol.hpp>
#include <mrdox/Metadata/Source.hpp>
#include <mrdox/Metadata/Type.hpp>
#include <mrdox/ADT/BitField.hpp>
#include <utility>
Expand All @@ -40,7 +40,7 @@ union FieldFlags
*/
struct FieldInfo
: IsInfo<InfoKind::Field>
, SymbolInfo
, SourceInfo
{
/** Type of the field */
TypeInfo Type;
Expand Down
4 changes: 2 additions & 2 deletions include/mrdox/Metadata/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <mrdox/Platform.hpp>
#include <mrdox/ADT/BitField.hpp>
#include <mrdox/Metadata/Field.hpp>
#include <mrdox/Metadata/Symbol.hpp>
#include <mrdox/Metadata/Source.hpp>
#include <mrdox/Metadata/Symbols.hpp>
#include <mrdox/Metadata/Template.hpp>
#include <clang/AST/Attr.h>
Expand Down Expand Up @@ -176,7 +176,7 @@ struct Param
// Info for functions.
struct FunctionInfo
: IsInfo<InfoKind::Function>
, SymbolInfo
, SourceInfo
{
friend class ASTVisitor;

Expand Down
44 changes: 0 additions & 44 deletions include/mrdox/Metadata/Location.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions include/mrdox/Metadata/Record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <mrdox/Metadata/Enum.hpp>
#include <mrdox/Metadata/Field.hpp>
#include <mrdox/Metadata/Function.hpp>
#include <mrdox/Metadata/Symbol.hpp>
#include <mrdox/Metadata/Source.hpp>
#include <mrdox/Metadata/Symbols.hpp>
#include <mrdox/Metadata/Template.hpp>
#include <mrdox/Metadata/Typedef.hpp>
Expand Down Expand Up @@ -73,7 +73,7 @@ enum class RecordKeyKind
*/
struct RecordInfo
: IsInfo<InfoKind::Record>
, SymbolInfo
, SourceInfo
{
friend class ASTVisitor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,48 @@
// Official repository: https://github.com/cppalliance/mrdox
//

#ifndef MRDOX_API_METADATA_SYMBOL_HPP
#define MRDOX_API_METADATA_SYMBOL_HPP
#ifndef MRDOX_API_METADATA_SOURCE_HPP
#define MRDOX_API_METADATA_SOURCE_HPP

#include <mrdox/Platform.hpp>
#include <mrdox/Metadata/Info.hpp>
#include <mrdox/Metadata/Location.hpp>
#include <optional>
#include <string>
#include <string_view>

namespace clang {
namespace mrdox {

/** Base class for Info that have source locations.
struct Location
{
/** Name of the file
*/
std::string Filename;

/** Line number within the file
*/
int LineNumber;

/** Whether the file is inside the source root directory
*/
bool IsFileInRootDir;

//--------------------------------------------

Location(
int line = 0,
std::string_view filename = "",
bool in_root_dir = false)
: Filename(filename)
, LineNumber(line)
, IsFileInRootDir(in_root_dir)
{
}
};

/** Stores source information for a declaration.
*/
struct SymbolInfo
struct SourceInfo
{
/** Location where the entity was defined
Expand All @@ -41,7 +69,7 @@ struct SymbolInfo
std::vector<Location> Loc;

protected:
SymbolInfo() = default;
SourceInfo() = default;
};

} // mrdox
Expand Down
4 changes: 2 additions & 2 deletions include/mrdox/Metadata/Typedef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define MRDOX_API_METADATA_TYPEDEF_HPP

#include <mrdox/Platform.hpp>
#include <mrdox/Metadata/Symbol.hpp>
#include <mrdox/Metadata/Source.hpp>
#include <mrdox/Metadata/Template.hpp>
#include <mrdox/Metadata/Type.hpp>
#include <memory>
Expand All @@ -25,7 +25,7 @@ namespace mrdox {
// Info for typedef and using statements.
struct TypedefInfo
: IsInfo<InfoKind::Typedef>
, SymbolInfo
, SourceInfo
{
friend class ASTVisitor;

Expand Down
4 changes: 2 additions & 2 deletions include/mrdox/Metadata/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <mrdox/Platform.hpp>
#include <mrdox/ADT/BitField.hpp>
#include <mrdox/Metadata/Symbol.hpp>
#include <mrdox/Metadata/Source.hpp>
#include <mrdox/Metadata/Template.hpp>
#include <mrdox/Metadata/Type.hpp>
#include <clang/Basic/Specifiers.h>
Expand All @@ -37,7 +37,7 @@ union VariableFlags0
*/
struct VariableInfo
: IsInfo<InfoKind::Variable>
, SymbolInfo
, SourceInfo
{
friend class ASTVisitor;

Expand Down
2 changes: 1 addition & 1 deletion include/mrdox/MetadataFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct RecordInfo;
struct Param;
struct SpecializationInfo;
struct SpecializedMember;
struct SymbolInfo;
struct SourceInfo;
struct TypeInfo;
struct TypedefInfo;
struct VariableInfo;
Expand Down
16 changes: 8 additions & 8 deletions source/-XML/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ writeEnum(
{ I.id }
});

writeSymbol(I);
writeSourceInfo(I);

for(auto const& v : I.Members)
tags_.write("value", {}, {
Expand All @@ -311,7 +311,7 @@ writeFunction(
{ I.id }
});

writeSymbol(I);
writeSourceInfo(I);

write(I.specs0, tags_);
write(I.specs1, tags_);
Expand Down Expand Up @@ -351,7 +351,7 @@ writeRecord(
{ I.id }
});

writeSymbol(I);
writeSourceInfo(I);


write(I.specs, tags_);
Expand Down Expand Up @@ -398,7 +398,7 @@ writeTypedef(
{ I.id }
});

writeSymbol(I);
writeSourceInfo(I);

tags_.write("type", "", {
{ "name", I.Underlying.Name },
Expand All @@ -425,7 +425,7 @@ writeField(
{ "default", I.Default, ! I.Default.empty() }
});

writeSymbol(I);
writeSourceInfo(I);

write(I.specs, tags_);

Expand Down Expand Up @@ -454,7 +454,7 @@ writeVar(
{ I.id }
});

writeSymbol(I);
writeSourceInfo(I);

write(I.specs, tags_);

Expand All @@ -476,8 +476,8 @@ writeVar(

void
XMLWriter::
writeSymbol(
SymbolInfo const& I)
writeSourceInfo(
SourceInfo const& I)
{
if(I.DefLoc)
writeLocation(*I.DefLoc, true);
Expand Down
2 changes: 1 addition & 1 deletion source/-XML/XMLWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class XMLWriter
bool writeVar(VariableInfo const&);
bool writeSpecialization(const SpecializationInfo&);

void writeSymbol(SymbolInfo const& I);
void writeSourceInfo(SourceInfo const& I);
void writeLocation(Location const& loc, bool def = false);
void writeJavadoc(std::unique_ptr<Javadoc> const& javadoc);
void openTemplate(const std::unique_ptr<TemplateInfo>& I);
Expand Down
2 changes: 1 addition & 1 deletion source/-adoc/AdocWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ void
AdocWriter::
writeLocation(
Info const& I,
SymbolInfo const& S)
SourceInfo const& S)
{
Location const* loc = nullptr;
if(S.DefLoc.has_value())
Expand Down
2 changes: 1 addition & 1 deletion source/-adoc/AdocWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AdocWriter
std::unique_ptr<Javadoc> const& javadoc);
void writeLocation(
Info const& I,
SymbolInfo const& S);
SourceInfo const& S);

template<class T>
void writeNodes(doc::List<T> const& list)
Expand Down
24 changes: 13 additions & 11 deletions source/AST/AnyBlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,31 +330,33 @@ class InfoPartBlock

//------------------------------------------------

class SymbolPartBlock
class SourceInfoBlock
: public BitcodeReader::AnyBlock
{
protected:
BitcodeReader& br_;
SymbolInfo& I;
SourceInfo& I;

public:
SymbolPartBlock(
SymbolInfo& I,
SourceInfoBlock(
SourceInfo& I,
BitcodeReader& br) noexcept
: br_(br)
, I(I)
{
}

Error
parseRecord(Record const& R,
unsigned ID, llvm::StringRef Blob) override
parseRecord(
Record const& R,
unsigned ID,
llvm::StringRef Blob) override
{
switch(ID)
{
case SYMBOL_PART_DEFLOC:
case SOURCE_INFO_DEFLOC:
return decodeRecord(R, I.DefLoc, Blob);
case SYMBOL_PART_LOC:
case SOURCE_INFO_LOC:
return decodeRecord(R, I.Loc, Blob);
default:
return AnyBlock::parseRecord(R, ID, Blob);
Expand Down Expand Up @@ -1159,11 +1161,11 @@ readSubBlock(
}
break;
}
case BI_SYMBOL_PART_ID:
case BI_SOURCE_INFO_ID:
{
if constexpr(std::derived_from<T, SymbolInfo>)
if constexpr(std::derived_from<T, SourceInfo>)
{
SymbolPartBlock B(*I.get(), br_);
SourceInfoBlock B(*I.get(), br_);
return br_.readBlock(B, ID);
}
break;
Expand Down
Loading

0 comments on commit 77729b0

Please sign in to comment.