| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H |
| 15 |
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H |
| 16 |
|
| 17 |
#include "clang/AST/Type.h" |
| 18 |
#include "clang/Basic/Specifiers.h" |
| 19 |
#include "clang/Tooling/StandaloneExecution.h" |
| 20 |
#include "llvm/ADT/APSInt.h" |
| 21 |
#include "llvm/ADT/SmallVector.h" |
| 22 |
#include "llvm/ADT/StringExtras.h" |
| 23 |
#include <array> |
| 24 |
#include <optional> |
| 25 |
#include <string> |
| 26 |
|
| 27 |
namespace clang { |
| 28 |
namespace doc { |
| 29 |
|
| 30 |
|
| 31 |
using SymbolID = std::array<uint8_t, 20>; |
| 32 |
|
| 33 |
struct BaseRecordInfo; |
| 34 |
struct EnumInfo; |
| 35 |
struct FunctionInfo; |
| 36 |
struct Info; |
| 37 |
struct TypedefInfo; |
| 38 |
|
| 39 |
enum class InfoType { |
| 40 |
IT_default, |
| 41 |
IT_namespace, |
| 42 |
IT_record, |
| 43 |
IT_function, |
| 44 |
IT_enum, |
| 45 |
IT_typedef |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
struct CommentInfo { |
| 50 |
CommentInfo() = default; |
| 51 |
CommentInfo(CommentInfo &Other) = delete; |
| 52 |
CommentInfo(CommentInfo &&Other) = default; |
| 53 |
CommentInfo &operator=(CommentInfo &&Other) = default; |
| 54 |
|
| 55 |
bool operator==(const CommentInfo &Other) const; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
bool operator<(const CommentInfo &Other) const; |
| 62 |
|
| 63 |
SmallString<16> |
| 64 |
Kind; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
SmallString<64> Text; |
| 70 |
SmallString<16> Name; |
| 71 |
SmallString<8> Direction; |
| 72 |
SmallString<16> ParamName; |
| 73 |
SmallString<16> CloseName; |
| 74 |
bool SelfClosing = false; |
| 75 |
bool Explicit = false; |
| 76 |
|
| 77 |
llvm::SmallVector<SmallString<16>, 4> |
| 78 |
AttrKeys; |
| 79 |
llvm::SmallVector<SmallString<16>, 4> |
| 80 |
AttrValues; |
| 81 |
llvm::SmallVector<SmallString<16>, 4> |
| 82 |
Args; |
| 83 |
std::vector<std::unique_ptr<CommentInfo>> |
| 84 |
Children; |
| 85 |
}; |
| 86 |
|
| 87 |
struct Reference { |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
Reference(SymbolID USR = SymbolID(), StringRef Name = StringRef(), |
| 94 |
InfoType IT = InfoType::IT_default) |
| 95 |
: USR(USR), Name(Name), QualName(Name), RefType(IT) {} |
| 96 |
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName, |
| 97 |
StringRef Path = StringRef()) |
| 98 |
: USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path) {} |
| 99 |
|
| 100 |
bool operator==(const Reference &Other) const { |
| 101 |
return std::tie(USR, Name, QualName, RefType) == |
| 102 |
std::tie(Other.USR, Other.Name, QualName, Other.RefType); |
| 103 |
} |
| 104 |
|
| 105 |
bool mergeable(const Reference &Other); |
| 106 |
void merge(Reference &&I); |
| 107 |
|
| 108 |
|
| 109 |
llvm::SmallString<64> getRelativeFilePath(const StringRef &CurrentPath) const; |
| 110 |
|
| 111 |
|
| 112 |
llvm::SmallString<16> getFileBaseName() const; |
| 113 |
|
| 114 |
SymbolID USR = SymbolID(); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
SmallString<16> Name; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
SmallString<16> QualName; |
| 125 |
|
| 126 |
InfoType RefType = InfoType::IT_default; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
llvm::SmallString<128> Path; |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
struct ScopeChildren { |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
std::vector<Reference> Namespaces; |
| 144 |
std::vector<Reference> Records; |
| 145 |
std::vector<FunctionInfo> Functions; |
| 146 |
std::vector<EnumInfo> Enums; |
| 147 |
std::vector<TypedefInfo> Typedefs; |
| 148 |
}; |
| 149 |
|
| 150 |
|
| 151 |
struct TypeInfo { |
| 152 |
TypeInfo() = default; |
| 153 |
TypeInfo(const Reference &R) : Type(R) {} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
TypeInfo(StringRef Name, StringRef Path = StringRef()) |
| 158 |
: Type(SymbolID(), Name, InfoType::IT_default, Name, Path) {} |
| 159 |
|
| 160 |
bool operator==(const TypeInfo &Other) const { return Type == Other.Type; } |
| 161 |
|
| 162 |
Reference Type; |
| 163 |
}; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
struct TemplateParamInfo { |
| 171 |
TemplateParamInfo() = default; |
| 172 |
explicit TemplateParamInfo(StringRef Contents) : Contents(Contents) {} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
SmallString<16> Contents; |
| 178 |
}; |
| 179 |
|
| 180 |
struct TemplateSpecializationInfo { |
| 181 |
|
| 182 |
SymbolID SpecializationOf; |
| 183 |
|
| 184 |
|
| 185 |
std::vector<TemplateParamInfo> Params; |
| 186 |
}; |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
struct TemplateInfo { |
| 191 |
|
| 192 |
std::vector<TemplateParamInfo> Params; |
| 193 |
|
| 194 |
|
| 195 |
std::optional<TemplateSpecializationInfo> Specialization; |
| 196 |
}; |
| 197 |
|
| 198 |
|
| 199 |
struct FieldTypeInfo : public TypeInfo { |
| 200 |
FieldTypeInfo() = default; |
| 201 |
FieldTypeInfo(const TypeInfo &TI, StringRef Name = StringRef(), |
| 202 |
StringRef DefaultValue = StringRef()) |
| 203 |
: TypeInfo(TI), Name(Name), DefaultValue(DefaultValue) {} |
| 204 |
|
| 205 |
bool operator==(const FieldTypeInfo &Other) const { |
| 206 |
return std::tie(Type, Name, DefaultValue) == |
| 207 |
std::tie(Other.Type, Other.Name, Other.DefaultValue); |
| 208 |
} |
| 209 |
|
| 210 |
SmallString<16> Name; |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
SmallString<16> DefaultValue; |
| 215 |
}; |
| 216 |
|
| 217 |
|
| 218 |
struct MemberTypeInfo : public FieldTypeInfo { |
| 219 |
MemberTypeInfo() = default; |
| 220 |
MemberTypeInfo(const TypeInfo &TI, StringRef Name, AccessSpecifier Access) |
| 221 |
: FieldTypeInfo(TI, Name), Access(Access) {} |
| 222 |
|
| 223 |
bool operator==(const MemberTypeInfo &Other) const { |
| 224 |
return std::tie(Type, Name, Access, Description) == |
| 225 |
std::tie(Other.Type, Other.Name, Other.Access, Other.Description); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
AccessSpecifier Access = AccessSpecifier::AS_public; |
| 233 |
|
| 234 |
std::vector<CommentInfo> Description; |
| 235 |
}; |
| 236 |
|
| 237 |
struct Location { |
| 238 |
Location(int LineNumber = 0, StringRef Filename = StringRef(), |
| 239 |
bool IsFileInRootDir = false) |
| 240 |
: LineNumber(LineNumber), Filename(Filename), |
| 241 |
IsFileInRootDir(IsFileInRootDir) {} |
| 242 |
|
| 243 |
bool operator==(const Location &Other) const { |
| 244 |
return std::tie(LineNumber, Filename) == |
| 245 |
std::tie(Other.LineNumber, Other.Filename); |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
bool operator<(const Location &Other) const { |
| 253 |
return std::tie(LineNumber, Filename) < |
| 254 |
std::tie(Other.LineNumber, Other.Filename); |
| 255 |
} |
| 256 |
|
| 257 |
int LineNumber = 0; |
| 258 |
SmallString<32> Filename; |
| 259 |
bool IsFileInRootDir = false; |
| 260 |
}; |
| 261 |
|
| 262 |
|
| 263 |
struct Info { |
| 264 |
Info(InfoType IT = InfoType::IT_default, SymbolID USR = SymbolID(), |
| 265 |
StringRef Name = StringRef(), StringRef Path = StringRef()) |
| 266 |
: USR(USR), IT(IT), Name(Name), Path(Path) {} |
| 267 |
|
| 268 |
Info(const Info &Other) = delete; |
| 269 |
Info(Info &&Other) = default; |
| 270 |
|
| 271 |
virtual ~Info() = default; |
| 272 |
|
| 273 |
SymbolID USR = |
| 274 |
SymbolID(); |
| 275 |
const InfoType IT = InfoType::IT_default; |
| 276 |
SmallString<16> Name; |
| 277 |
llvm::SmallVector<Reference, 4> |
| 278 |
Namespace; |
| 279 |
std::vector<CommentInfo> Description; |
| 280 |
llvm::SmallString<128> Path; |
| 281 |
|
| 282 |
|
| 283 |
void mergeBase(Info &&I); |
| 284 |
bool mergeable(const Info &Other); |
| 285 |
|
| 286 |
llvm::SmallString<16> extractName() const; |
| 287 |
|
| 288 |
|
| 289 |
llvm::SmallString<64> getRelativeFilePath(const StringRef &CurrentPath) const; |
| 290 |
|
| 291 |
|
| 292 |
llvm::SmallString<16> getFileBaseName() const; |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
llvm::Expected<Reference> getEnclosingScope(); |
| 297 |
}; |
| 298 |
|
| 299 |
|
| 300 |
struct NamespaceInfo : public Info { |
| 301 |
NamespaceInfo(SymbolID USR = SymbolID(), StringRef Name = StringRef(), |
| 302 |
StringRef Path = StringRef()); |
| 303 |
|
| 304 |
void merge(NamespaceInfo &&I); |
| 305 |
|
| 306 |
ScopeChildren Children; |
| 307 |
}; |
| 308 |
|
| 309 |
|
| 310 |
struct SymbolInfo : public Info { |
| 311 |
SymbolInfo(InfoType IT, SymbolID USR = SymbolID(), |
| 312 |
StringRef Name = StringRef(), StringRef Path = StringRef()) |
| 313 |
: Info(IT, USR, Name, Path) {} |
| 314 |
|
| 315 |
void merge(SymbolInfo &&I); |
| 316 |
|
| 317 |
std::optional<Location> DefLoc; |
| 318 |
llvm::SmallVector<Location, 2> Loc; |
| 319 |
}; |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
struct FunctionInfo : public SymbolInfo { |
| 324 |
FunctionInfo(SymbolID USR = SymbolID()) |
| 325 |
: SymbolInfo(InfoType::IT_function, USR) {} |
| 326 |
|
| 327 |
void merge(FunctionInfo &&I); |
| 328 |
|
| 329 |
bool IsMethod = false; |
| 330 |
Reference Parent; |
| 331 |
TypeInfo ReturnType; |
| 332 |
llvm::SmallVector<FieldTypeInfo, 4> Params; |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
AccessSpecifier Access = AccessSpecifier::AS_public; |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
SmallString<16> FullName; |
| 342 |
|
| 343 |
|
| 344 |
std::optional<TemplateInfo> Template; |
| 345 |
}; |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
struct RecordInfo : public SymbolInfo { |
| 351 |
RecordInfo(SymbolID USR = SymbolID(), StringRef Name = StringRef(), |
| 352 |
StringRef Path = StringRef()); |
| 353 |
|
| 354 |
void merge(RecordInfo &&I); |
| 355 |
|
| 356 |
|
| 357 |
TagTypeKind TagType = TagTypeKind::TTK_Struct; |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
SmallString<16> FullName; |
| 362 |
|
| 363 |
|
| 364 |
std::optional<TemplateInfo> Template; |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
bool IsTypeDef = false; |
| 371 |
|
| 372 |
llvm::SmallVector<MemberTypeInfo, 4> |
| 373 |
Members; |
| 374 |
llvm::SmallVector<Reference, 4> Parents; |
| 375 |
|
| 376 |
|
| 377 |
llvm::SmallVector<Reference, 4> |
| 378 |
VirtualParents; |
| 379 |
|
| 380 |
std::vector<BaseRecordInfo> |
| 381 |
Bases; |
| 382 |
|
| 383 |
|
| 384 |
ScopeChildren Children; |
| 385 |
}; |
| 386 |
|
| 387 |
|
| 388 |
struct TypedefInfo : public SymbolInfo { |
| 389 |
TypedefInfo(SymbolID USR = SymbolID()) |
| 390 |
: SymbolInfo(InfoType::IT_typedef, USR) {} |
| 391 |
|
| 392 |
void merge(TypedefInfo &&I); |
| 393 |
|
| 394 |
TypeInfo Underlying; |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
bool IsUsing = false; |
| 401 |
}; |
| 402 |
|
| 403 |
struct BaseRecordInfo : public RecordInfo { |
| 404 |
BaseRecordInfo(); |
| 405 |
BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, bool IsVirtual, |
| 406 |
AccessSpecifier Access, bool IsParent); |
| 407 |
|
| 408 |
|
| 409 |
bool IsVirtual = false; |
| 410 |
|
| 411 |
|
| 412 |
AccessSpecifier Access = AccessSpecifier::AS_public; |
| 413 |
bool IsParent = false; |
| 414 |
}; |
| 415 |
|
| 416 |
|
| 417 |
struct EnumValueInfo { |
| 418 |
explicit EnumValueInfo(StringRef Name = StringRef(), |
| 419 |
StringRef Value = StringRef("0"), |
| 420 |
StringRef ValueExpr = StringRef()) |
| 421 |
: Name(Name), Value(Value), ValueExpr(ValueExpr) {} |
| 422 |
|
| 423 |
bool operator==(const EnumValueInfo &Other) const { |
| 424 |
return std::tie(Name, Value, ValueExpr) == |
| 425 |
std::tie(Other.Name, Other.Value, Other.ValueExpr); |
| 426 |
} |
| 427 |
|
| 428 |
SmallString<16> Name; |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
SmallString<16> Value; |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
SmallString<16> ValueExpr; |
| 438 |
}; |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
struct EnumInfo : public SymbolInfo { |
| 443 |
EnumInfo() : SymbolInfo(InfoType::IT_enum) {} |
| 444 |
EnumInfo(SymbolID USR) : SymbolInfo(InfoType::IT_enum, USR) {} |
| 445 |
|
| 446 |
void merge(EnumInfo &&I); |
| 447 |
|
| 448 |
|
| 449 |
bool Scoped = false; |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
std::optional<TypeInfo> BaseType; |
| 455 |
|
| 456 |
llvm::SmallVector<EnumValueInfo, 4> Members; |
| 457 |
}; |
| 458 |
|
| 459 |
struct Index : public Reference { |
| 460 |
Index() = default; |
| 461 |
Index(StringRef Name) : Reference(SymbolID(), Name) {} |
| 462 |
Index(StringRef Name, StringRef JumpToSection) |
| 463 |
: Reference(SymbolID(), Name), JumpToSection(JumpToSection) {} |
| 464 |
Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path) |
| 465 |
: Reference(USR, Name, IT, Name, Path) {} |
| 466 |
|
| 467 |
bool operator==(const SymbolID &Other) const { return USR == Other; } |
| 468 |
bool operator<(const Index &Other) const; |
| 469 |
|
| 470 |
std::optional<SmallString<16>> JumpToSection; |
| 471 |
std::vector<Index> Children; |
| 472 |
|
| 473 |
void sort(); |
| 474 |
}; |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
llvm::Expected<std::unique_ptr<Info>> |
| 482 |
mergeInfos(std::vector<std::unique_ptr<Info>> &Values); |
| 483 |
|
| 484 |
struct ClangDocContext { |
| 485 |
ClangDocContext() = default; |
| 486 |
ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName, |
| 487 |
bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot, |
| 488 |
StringRef RepositoryUrl, |
| 489 |
std::vector<std::string> UserStylesheets, |
| 490 |
std::vector<std::string> JsScripts); |
| 491 |
tooling::ExecutionContext *ECtx; |
| 492 |
std::string ProjectName; |
| 493 |
bool PublicOnly; |
| 494 |
std::string OutDirectory; |
| 495 |
std::string SourceRoot; |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
std::optional<std::string> RepositoryUrl; |
| 500 |
|
| 501 |
|
| 502 |
std::vector<std::string> UserStylesheets; |
| 503 |
|
| 504 |
std::vector<std::string> JsScripts; |
| 505 |
|
| 506 |
std::vector<std::string> FilesToCopy; |
| 507 |
Index Idx; |
| 508 |
}; |
| 509 |
|
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
#endif |