2018-06-05 01:22:20 +08:00
|
|
|
///===-- Representation.h - ClangDoc Representation -------------*- C++ -*-===//
|
2018-03-23 07:34:46 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the internal representations of different declaration
|
|
|
|
// types for the clang-doc tool.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
|
|
|
|
|
|
|
|
#include "clang/AST/Type.h"
|
|
|
|
#include "clang/Basic/Specifiers.h"
|
2018-07-21 02:49:55 +08:00
|
|
|
#include "clang/Tooling/StandaloneExecution.h"
|
2018-03-23 07:34:46 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include <array>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace doc {
|
|
|
|
|
2018-06-05 01:22:20 +08:00
|
|
|
// SHA1'd hash of a USR.
|
2018-03-23 07:34:46 +08:00
|
|
|
using SymbolID = std::array<uint8_t, 20>;
|
|
|
|
|
|
|
|
struct Info;
|
2018-08-03 04:10:17 +08:00
|
|
|
struct FunctionInfo;
|
|
|
|
struct EnumInfo;
|
|
|
|
|
2018-03-23 07:34:46 +08:00
|
|
|
enum class InfoType {
|
2018-05-05 01:02:13 +08:00
|
|
|
IT_default,
|
2018-03-23 07:34:46 +08:00
|
|
|
IT_namespace,
|
|
|
|
IT_record,
|
|
|
|
IT_function,
|
2018-05-05 01:02:13 +08:00
|
|
|
IT_enum
|
2018-03-23 07:34:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// A representation of a parsed comment.
|
|
|
|
struct CommentInfo {
|
|
|
|
CommentInfo() = default;
|
2018-06-05 01:22:20 +08:00
|
|
|
CommentInfo(CommentInfo &Other) = delete;
|
|
|
|
CommentInfo(CommentInfo &&Other) = default;
|
2018-03-23 07:34:46 +08:00
|
|
|
|
2018-08-17 07:50:51 +08:00
|
|
|
SmallString<16> Kind; // Kind of comment (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).
|
2018-03-23 07:34:46 +08:00
|
|
|
SmallString<8> Direction; // Parameter direction (for (T)ParamCommand).
|
|
|
|
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).
|
|
|
|
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.
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Reference {
|
|
|
|
Reference() = default;
|
2018-05-05 01:02:13 +08:00
|
|
|
Reference(llvm::StringRef Name) : Name(Name) {}
|
|
|
|
Reference(SymbolID USR, StringRef Name, InfoType IT)
|
|
|
|
: USR(USR), Name(Name), RefType(IT) {}
|
|
|
|
|
2018-06-07 00:13:17 +08:00
|
|
|
bool operator==(const Reference &Other) const {
|
|
|
|
return std::tie(USR, Name, RefType) ==
|
|
|
|
std::tie(Other.USR, Other.Name, Other.RefType);
|
|
|
|
}
|
|
|
|
|
2018-05-05 01:02:13 +08:00
|
|
|
SymbolID USR = SymbolID(); // Unique identifer for referenced decl
|
|
|
|
SmallString<16> Name; // Name of type (possibly unresolved).
|
|
|
|
InfoType RefType = InfoType::IT_default; // Indicates the type of this
|
|
|
|
// Reference (namespace, record,
|
|
|
|
// function, enum, default).
|
2018-03-23 07:34:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// A base struct for TypeInfos
|
|
|
|
struct TypeInfo {
|
|
|
|
TypeInfo() = default;
|
2018-05-05 01:02:13 +08:00
|
|
|
TypeInfo(SymbolID Type, StringRef Field, InfoType IT)
|
|
|
|
: Type(Type, Field, IT) {}
|
2018-03-23 07:34:46 +08:00
|
|
|
TypeInfo(llvm::StringRef RefName) : Type(RefName) {}
|
|
|
|
|
2018-06-07 00:13:17 +08:00
|
|
|
bool operator==(const TypeInfo &Other) const { return Type == Other.Type; }
|
|
|
|
|
2018-03-23 07:34:46 +08:00
|
|
|
Reference Type; // Referenced type in this info.
|
|
|
|
};
|
|
|
|
|
|
|
|
// Info for field types.
|
|
|
|
struct FieldTypeInfo : public TypeInfo {
|
|
|
|
FieldTypeInfo() = default;
|
2018-05-05 01:02:13 +08:00
|
|
|
FieldTypeInfo(SymbolID Type, StringRef Field, InfoType IT,
|
|
|
|
llvm::StringRef Name)
|
|
|
|
: TypeInfo(Type, Field, IT), Name(Name) {}
|
2018-03-23 07:34:46 +08:00
|
|
|
FieldTypeInfo(llvm::StringRef RefName, llvm::StringRef Name)
|
|
|
|
: TypeInfo(RefName), Name(Name) {}
|
|
|
|
|
2018-06-07 00:13:17 +08:00
|
|
|
bool operator==(const FieldTypeInfo &Other) const {
|
|
|
|
return std::tie(Type, Name) == std::tie(Other.Type, Other.Name);
|
|
|
|
}
|
|
|
|
|
2018-03-23 07:34:46 +08:00
|
|
|
SmallString<16> Name; // Name associated with this info.
|
|
|
|
};
|
|
|
|
|
|
|
|
// Info for member types.
|
|
|
|
struct MemberTypeInfo : public FieldTypeInfo {
|
|
|
|
MemberTypeInfo() = default;
|
2018-05-05 01:02:13 +08:00
|
|
|
MemberTypeInfo(SymbolID Type, StringRef Field, InfoType IT,
|
|
|
|
llvm::StringRef Name, AccessSpecifier Access)
|
|
|
|
: FieldTypeInfo(Type, Field, IT, Name), Access(Access) {}
|
|
|
|
MemberTypeInfo(llvm::StringRef RefName, llvm::StringRef Name,
|
|
|
|
AccessSpecifier Access)
|
|
|
|
: FieldTypeInfo(RefName, Name), Access(Access) {}
|
|
|
|
|
2018-06-07 00:13:17 +08:00
|
|
|
bool operator==(const MemberTypeInfo &Other) const {
|
|
|
|
return std::tie(Type, Name, Access) ==
|
|
|
|
std::tie(Other.Type, Other.Name, Other.Access);
|
|
|
|
}
|
|
|
|
|
2018-05-05 01:02:13 +08:00
|
|
|
AccessSpecifier Access = AccessSpecifier::AS_none; // Access level associated
|
|
|
|
// with this info (public,
|
|
|
|
// protected, private,
|
|
|
|
// none).
|
2018-03-23 07:34:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Location {
|
|
|
|
Location() = default;
|
|
|
|
Location(int LineNumber, SmallString<16> Filename)
|
|
|
|
: LineNumber(LineNumber), Filename(std::move(Filename)) {}
|
|
|
|
|
2018-06-07 00:13:17 +08:00
|
|
|
bool operator==(const Location &Other) const {
|
|
|
|
return std::tie(LineNumber, Filename) ==
|
|
|
|
std::tie(Other.LineNumber, Other.Filename);
|
|
|
|
}
|
|
|
|
|
2018-03-23 07:34:46 +08:00
|
|
|
int LineNumber; // Line number of this Location.
|
|
|
|
SmallString<32> Filename; // File for this Location.
|
|
|
|
};
|
|
|
|
|
|
|
|
/// A base struct for Infos.
|
|
|
|
struct Info {
|
|
|
|
Info() = default;
|
2018-06-05 01:22:20 +08:00
|
|
|
Info(InfoType IT) : IT(IT) {}
|
2018-08-03 04:10:17 +08:00
|
|
|
Info(InfoType IT, SymbolID USR) : USR(USR), IT(IT) {}
|
|
|
|
Info(InfoType IT, SymbolID USR, StringRef Name)
|
|
|
|
: USR(USR), IT(IT), Name(Name) {}
|
2018-06-05 01:22:20 +08:00
|
|
|
Info(const Info &Other) = delete;
|
|
|
|
Info(Info &&Other) = default;
|
|
|
|
|
2018-08-25 00:43:46 +08:00
|
|
|
virtual ~Info() = default;
|
|
|
|
|
2018-06-05 01:22:20 +08:00
|
|
|
SymbolID USR =
|
|
|
|
SymbolID(); // Unique identifier for the decl described by this Info.
|
|
|
|
const InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
|
|
|
|
SmallString<16> Name; // Unqualified name of the decl.
|
2018-03-23 07:34:46 +08:00
|
|
|
llvm::SmallVector<Reference, 4>
|
|
|
|
Namespace; // List of parent namespaces for this decl.
|
|
|
|
std::vector<CommentInfo> Description; // Comment description of this decl.
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
void mergeBase(Info &&I);
|
|
|
|
bool mergeable(const Info &Other);
|
2018-08-03 04:10:17 +08:00
|
|
|
|
|
|
|
// Returns a reference to the parent scope (that is, the immediate parent
|
|
|
|
// namespace or class in which this decl resides).
|
|
|
|
llvm::Expected<Reference> getEnclosingScope();
|
2018-03-23 07:34:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Info for namespaces.
|
2018-06-05 01:22:20 +08:00
|
|
|
struct NamespaceInfo : public Info {
|
|
|
|
NamespaceInfo() : Info(InfoType::IT_namespace) {}
|
2018-08-03 04:10:17 +08:00
|
|
|
NamespaceInfo(SymbolID USR) : Info(InfoType::IT_namespace, USR) {}
|
|
|
|
NamespaceInfo(SymbolID USR, StringRef Name)
|
|
|
|
: Info(InfoType::IT_namespace, USR, Name) {}
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
void merge(NamespaceInfo &&I);
|
2018-08-03 04:10:17 +08:00
|
|
|
|
|
|
|
// Namespaces and Records are references because they will be properly
|
|
|
|
// documented in their own info, while the entirety of Functions and Enums are
|
|
|
|
// included here because they should not have separate documentation from
|
|
|
|
// their scope.
|
|
|
|
std::vector<Reference> ChildNamespaces;
|
|
|
|
std::vector<Reference> ChildRecords;
|
|
|
|
std::vector<FunctionInfo> ChildFunctions;
|
|
|
|
std::vector<EnumInfo> ChildEnums;
|
2018-06-05 01:22:20 +08:00
|
|
|
};
|
2018-03-23 07:34:46 +08:00
|
|
|
|
|
|
|
// Info for symbols.
|
|
|
|
struct SymbolInfo : public Info {
|
2018-06-05 01:22:20 +08:00
|
|
|
SymbolInfo(InfoType IT) : Info(IT) {}
|
2018-08-03 04:10:17 +08:00
|
|
|
SymbolInfo(InfoType IT, SymbolID USR) : Info(IT, USR) {}
|
|
|
|
SymbolInfo(InfoType IT, SymbolID USR, StringRef Name) : Info(IT, USR, Name) {}
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
void merge(SymbolInfo &&I);
|
|
|
|
|
2018-03-23 07:34:46 +08:00
|
|
|
llvm::Optional<Location> DefLoc; // Location where this decl is defined.
|
|
|
|
llvm::SmallVector<Location, 2> Loc; // Locations where this decl is declared.
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: Expand to allow for documenting templating and default args.
|
|
|
|
// Info for functions.
|
|
|
|
struct FunctionInfo : public SymbolInfo {
|
2018-06-05 01:22:20 +08:00
|
|
|
FunctionInfo() : SymbolInfo(InfoType::IT_function) {}
|
2018-08-03 04:10:17 +08:00
|
|
|
FunctionInfo(SymbolID USR) : SymbolInfo(InfoType::IT_function, USR) {}
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
void merge(FunctionInfo &&I);
|
|
|
|
|
2018-03-23 07:34:46 +08:00
|
|
|
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.
|
2018-06-07 00:13:17 +08:00
|
|
|
llvm::SmallVector<FieldTypeInfo, 4> Params; // List of parameters.
|
|
|
|
// Access level for this method (public, private, protected, none).
|
|
|
|
AccessSpecifier Access = AccessSpecifier::AS_none;
|
2018-03-23 07:34:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: Expand to allow for documenting templating, inheritance access,
|
|
|
|
// friend classes
|
|
|
|
// Info for types.
|
|
|
|
struct RecordInfo : public SymbolInfo {
|
2018-06-05 01:22:20 +08:00
|
|
|
RecordInfo() : SymbolInfo(InfoType::IT_record) {}
|
2018-08-03 04:10:17 +08:00
|
|
|
RecordInfo(SymbolID USR) : SymbolInfo(InfoType::IT_record, USR) {}
|
|
|
|
RecordInfo(SymbolID USR, StringRef Name)
|
|
|
|
: SymbolInfo(InfoType::IT_record, USR, Name) {}
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
void merge(RecordInfo &&I);
|
|
|
|
|
|
|
|
TagTypeKind TagType = TagTypeKind::TTK_Struct; // Type of this record
|
|
|
|
// (struct, class, union,
|
|
|
|
// interface).
|
2018-03-23 07:34:46 +08:00
|
|
|
llvm::SmallVector<MemberTypeInfo, 4>
|
|
|
|
Members; // List of info about record members.
|
2018-06-05 01:22:20 +08:00
|
|
|
llvm::SmallVector<Reference, 4> Parents; // List of base/parent records
|
|
|
|
// (does not include virtual
|
|
|
|
// parents).
|
2018-03-23 07:34:46 +08:00
|
|
|
llvm::SmallVector<Reference, 4>
|
|
|
|
VirtualParents; // List of virtual base/parent records.
|
2018-08-03 04:10:17 +08:00
|
|
|
|
|
|
|
// Records are references because they will be properly
|
|
|
|
// documented in their own info, while the entirety of Functions and Enums are
|
|
|
|
// included here because they should not have separate documentation from
|
|
|
|
// their scope.
|
|
|
|
std::vector<Reference> ChildRecords;
|
|
|
|
std::vector<FunctionInfo> ChildFunctions;
|
|
|
|
std::vector<EnumInfo> ChildEnums;
|
2018-03-23 07:34:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: Expand to allow for documenting templating.
|
|
|
|
// Info for types.
|
|
|
|
struct EnumInfo : public SymbolInfo {
|
2018-06-05 01:22:20 +08:00
|
|
|
EnumInfo() : SymbolInfo(InfoType::IT_enum) {}
|
2018-08-03 04:10:17 +08:00
|
|
|
EnumInfo(SymbolID USR) : SymbolInfo(InfoType::IT_enum, USR) {}
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
void merge(EnumInfo &&I);
|
|
|
|
|
2018-03-23 07:34:46 +08:00
|
|
|
bool Scoped =
|
|
|
|
false; // Indicates whether this enum is scoped (e.g. enum class).
|
|
|
|
llvm::SmallVector<SmallString<16>, 4> Members; // List of enum members.
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: Add functionality to include separate markdown pages.
|
|
|
|
|
2018-06-05 01:22:20 +08:00
|
|
|
// A standalone function to call to merge a vector of infos into one.
|
|
|
|
// This assumes that all infos in the vector are of the same type, and will fail
|
|
|
|
// if they are different.
|
|
|
|
llvm::Expected<std::unique_ptr<Info>>
|
|
|
|
mergeInfos(std::vector<std::unique_ptr<Info>> &Values);
|
|
|
|
|
2018-07-21 02:49:55 +08:00
|
|
|
struct ClangDocContext {
|
|
|
|
tooling::ExecutionContext *ECtx;
|
|
|
|
bool PublicOnly;
|
|
|
|
};
|
|
|
|
|
2018-03-23 07:34:46 +08:00
|
|
|
} // namespace doc
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
|