Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions clang-tools-extra/clang-doc/Representation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ llvm::StringRef commentKindToString(CommentKind Kind) {
llvm_unreachable("Unhandled CommentKind");
}

namespace {

const SymbolID EmptySID = SymbolID();

template <typename T>
llvm::Expected<std::unique_ptr<Info>>
static llvm::Expected<std::unique_ptr<Info>>
reduce(std::vector<std::unique_ptr<Info>> &Values) {
if (Values.empty() || !Values[0])
return llvm::createStringError(llvm::inconvertibleErrorCode(),
Expand All @@ -102,7 +100,7 @@ reduce(std::vector<std::unique_ptr<Info>> &Values) {
// Return the index of the matching child in the vector, or -1 if merge is not
// necessary.
template <typename T>
int getChildIndexIfExists(std::vector<T> &Children, T &ChildToMerge) {
static int getChildIndexIfExists(std::vector<T> &Children, T &ChildToMerge) {
for (unsigned long I = 0; I < Children.size(); I++) {
if (ChildToMerge.USR == Children[I].USR)
return I;
Expand All @@ -111,8 +109,8 @@ int getChildIndexIfExists(std::vector<T> &Children, T &ChildToMerge) {
}

template <typename T>
void reduceChildren(std::vector<T> &Children,
std::vector<T> &&ChildrenToMerge) {
static void reduceChildren(std::vector<T> &Children,
std::vector<T> &&ChildrenToMerge) {
for (auto &ChildToMerge : ChildrenToMerge) {
int MergeIdx = getChildIndexIfExists(Children, ChildToMerge);
if (MergeIdx == -1) {
Expand All @@ -123,8 +121,6 @@ void reduceChildren(std::vector<T> &Children,
}
}

} // namespace

// Dispatch function.
llvm::Expected<std::unique_ptr<Info>>
mergeInfos(std::vector<std::unique_ptr<Info>> &Values) {
Expand Down Expand Up @@ -402,7 +398,7 @@ BaseRecordInfo::BaseRecordInfo() : RecordInfo() {}
BaseRecordInfo::BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path,
bool IsVirtual, AccessSpecifier Access,
bool IsParent)
: RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
: RecordInfo(USR, Name, Path), Access(Access), IsVirtual(IsVirtual),
IsParent(IsParent) {}

llvm::SmallString<16> Info::extractName() const {
Expand Down
124 changes: 66 additions & 58 deletions clang-tools-extra/clang-doc/Representation.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,29 @@ struct CommentInfo {
// the vector.
bool operator<(const CommentInfo &Other) const;

CommentKind Kind = CommentKind::
CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
// TextComment, InlineCommandComment, HTMLStartTagComment,
// HTMLEndTagComment, BlockCommandComment,
// ParamCommandComment, TParamCommandComment,
// VerbatimBlockComment, VerbatimBlockLineComment,
// VerbatimLineComment).
SmallString<64> Text; // Text of the comment.
SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
std::vector<std::unique_ptr<CommentInfo>>
Children; // List of child comments for this CommentInfo.
SmallString<8> Direction; // Parameter direction (for (T)ParamCommand).
SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
SmallString<16> ParamName; // Parameter name (for (T)ParamCommand).
SmallString<16> CloseName; // Closing tag name (for VerbatimBlock).
bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
bool Explicit = false; // Indicates if the direction of a param is explicit
// (for (T)ParamCommand).
SmallString<64> Text; // Text of the comment.
llvm::SmallVector<SmallString<16>, 4>
AttrKeys; // List of attribute keys (for HTML).
llvm::SmallVector<SmallString<16>, 4>
AttrValues; // List of attribute values for each key (for HTML).
llvm::SmallVector<SmallString<16>, 4>
Args; // List of arguments to commands (for InlineCommand).
std::vector<std::unique_ptr<CommentInfo>>
Children; // List of child comments for this CommentInfo.
CommentKind Kind = CommentKind::
CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
// TextComment, InlineCommandComment, HTMLStartTagComment,
// HTMLEndTagComment, BlockCommandComment,
// ParamCommandComment, TParamCommandComment,
// VerbatimBlockComment, VerbatimBlockLineComment,
// VerbatimLineComment).
bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
bool Explicit = false; // Indicates if the direction of a param is explicit
// (for (T)ParamCommand).
};

struct Reference {
Expand All @@ -119,13 +119,13 @@ struct Reference {
// "GlobalNamespace" as the name, but an empty QualName).
Reference(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
InfoType IT = InfoType::IT_default)
: USR(USR), Name(Name), QualName(Name), RefType(IT) {}
: USR(USR), RefType(IT), Name(Name), QualName(Name) {}
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
StringRef Path = StringRef())
: USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path) {}
: USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path) {}
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
StringRef Path, SmallString<16> DocumentationFileName)
: USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path),
: USR(USR), RefType(IT), Name(Name), QualName(QualName), Path(Path),
DocumentationFileName(DocumentationFileName) {}

bool operator==(const Reference &Other) const {
Expand All @@ -145,6 +145,10 @@ struct Reference {

SymbolID USR = SymbolID(); // Unique identifier for referenced decl

InfoType RefType = InfoType::IT_default; // Indicates the type of this
// Reference (namespace, record,
// function, enum, default).

// Name of type (possibly unresolved). Not including namespaces or template
// parameters (so for a std::vector<int> this would be "vector"). See also
// QualName.
Expand All @@ -155,9 +159,6 @@ struct Reference {
// Name.
SmallString<16> QualName;

InfoType RefType = InfoType::IT_default; // Indicates the type of this
// Reference (namespace, record,
// function, enum, default).
// Path of directory where the clang-doc generated file will be saved
// (possibly unresolved)
llvm::SmallString<128> Path;
Expand Down Expand Up @@ -277,21 +278,21 @@ struct MemberTypeInfo : public FieldTypeInfo {
Other.Description);
}

std::vector<CommentInfo> Description;

// Access level associated with this info (public, protected, private, none).
// AS_public is set as default because the bitcode writer requires the enum
// with value 0 to be used as the default.
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
AccessSpecifier Access = AccessSpecifier::AS_public;

std::vector<CommentInfo> Description; // Comment description of this field.
bool IsStatic = false;
};

struct Location {
Location(int StartLineNumber = 0, int EndLineNumber = 0,
StringRef Filename = StringRef(), bool IsFileInRootDir = false)
: StartLineNumber(StartLineNumber), EndLineNumber(EndLineNumber),
Filename(Filename), IsFileInRootDir(IsFileInRootDir) {}
: Filename(Filename), StartLineNumber(StartLineNumber),
EndLineNumber(EndLineNumber), IsFileInRootDir(IsFileInRootDir) {}

bool operator==(const Location &Other) const {
return std::tie(StartLineNumber, EndLineNumber, Filename) ==
Expand All @@ -309,40 +310,24 @@ struct Location {
std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
}

int StartLineNumber = 0; // Line number of this Location.
SmallString<32> Filename;
int StartLineNumber = 0;
int EndLineNumber = 0;
SmallString<32> Filename; // File for this Location.
bool IsFileInRootDir = false; // Indicates if file is inside root directory
bool IsFileInRootDir = false;
};

/// A base struct for Infos.
struct Info {
Info(InfoType IT = InfoType::IT_default, SymbolID USR = SymbolID(),
StringRef Name = StringRef(), StringRef Path = StringRef())
: USR(USR), IT(IT), Name(Name), Path(Path) {}
: Path(Path), Name(Name), USR(USR), IT(IT) {}

Info(const Info &Other) = delete;
Info(Info &&Other) = default;

virtual ~Info() = default;

Info &operator=(Info &&Other) = default;

SymbolID USR =
SymbolID(); // Unique identifier for the decl described by this Info.
InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
SmallString<16> Name; // Unqualified name of the decl.
llvm::SmallVector<Reference, 4>
Namespace; // List of parent namespaces for this decl.
std::vector<CommentInfo> Description; // Comment description of this decl.
llvm::SmallString<128> Path; // Path of directory where the clang-doc
// generated file will be saved

// The name used for the file that this info is documented in.
// In the JSON generator, infos are documented in files with mangled names.
// Thus, we keep track of the physical filename for linking purposes.
SmallString<16> DocumentationFileName;

void mergeBase(Info &&I);
bool mergeable(const Info &Other);

Expand All @@ -353,6 +338,29 @@ struct Info {

/// Returns the basename that should be used for this Info.
llvm::SmallString<16> getFileBaseName() const;

// Path of directory where the clang-doc generated file will be saved.
llvm::SmallString<128> Path;

// Unqualified name of the decl.
SmallString<16> Name;

// The name used for the file that this info is documented in.
// In the JSON generator, infos are documented in files with mangled names.
// Thus, we keep track of the physical filename for linking purposes.
SmallString<16> DocumentationFileName;

// List of parent namespaces for this decl.
llvm::SmallVector<Reference, 4> Namespace;

// Unique identifier for the decl described by this Info.
SymbolID USR = SymbolID();

// InfoType of this particular Info.
InfoType IT = InfoType::IT_default;

// Comment description of this decl.
std::vector<CommentInfo> Description;
};

// Info for namespaces.
Expand Down Expand Up @@ -426,21 +434,21 @@ struct FunctionInfo : public SymbolInfo {

void merge(FunctionInfo &&I);

bool IsMethod = false; // Indicates whether this function is a class method.
Reference Parent; // Reference to the parent class decl for this method.
TypeInfo ReturnType; // Info about the return type of this function.
llvm::SmallVector<FieldTypeInfo, 4> Params; // List of parameters.
Reference Parent;
TypeInfo ReturnType;
llvm::SmallVector<FieldTypeInfo, 4> Params;
SmallString<256> Prototype;

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

// Access level for this method (public, private, protected, none).
// AS_public is set as default because the bitcode writer requires the enum
// with value 0 to be used as the default.
// (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
AccessSpecifier Access = AccessSpecifier::AS_public;

// Function Prototype
SmallString<256> Prototype;

// When present, this function is a template or specialization.
std::optional<TemplateInfo> Template;
bool IsMethod = false;
};

// TODO: Expand to allow for documenting templating, inheritance access,
Expand All @@ -455,15 +463,15 @@ struct RecordInfo : public SymbolInfo {
// Type of this record (struct, class, union, interface).
TagTypeKind TagType = TagTypeKind::Struct;

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

// Indicates if the record was declared using a typedef. Things like anonymous
// structs in a typedef:
// typedef struct { ... } foo_t;
// are converted into records with the typedef as the Name + this flag set.
bool IsTypeDef = false;

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

llvm::SmallVector<MemberTypeInfo, 4>
Members; // List of info about record members.
llvm::SmallVector<Reference, 4> Parents; // List of base/parent records
Expand Down Expand Up @@ -508,11 +516,11 @@ struct BaseRecordInfo : public RecordInfo {
BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, bool IsVirtual,
AccessSpecifier Access, bool IsParent);

// Indicates if base corresponds to a virtual inheritance
bool IsVirtual = false;
// Access level associated with this inherited info (public, protected,
// private).
AccessSpecifier Access = AccessSpecifier::AS_public;
// Indicates if base corresponds to a virtual inheritance
bool IsVirtual = false;
bool IsParent = false; // Indicates if this base is a direct parent
};

Expand Down
Loading