Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 1 | ///===-- Representation.cpp - ClangDoc Representation -----------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the merging of different types of infos. The data in the |
| 10 | // calling Info is preserved during a merge unless that field is empty or |
| 11 | // default. In that case, the data from the parameter Info is used to replace |
| 12 | // the empty or default data. |
| 13 | // |
| 14 | // For most fields, the first decl seen provides the data. Exceptions to this |
| 15 | // include the location and description fields, which are collections of data on |
| 16 | // all decls related to a given definition. All other fields are ignored in new |
| 17 | // decls unless the first seen decl didn't, for whatever reason, incorporate |
| 18 | // data on that field (e.g. a forward declared class wouldn't have information |
| 19 | // on members on the forward declaration, but would have the class name). |
| 20 | // |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | #include "Representation.h" |
| 23 | #include "llvm/Support/Error.h" |
Julie Hockett | d900ef0 | 2019-06-28 19:07:56 | [diff] [blame] | 24 | #include "llvm/Support/Path.h" |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 25 | |
| 26 | namespace clang { |
| 27 | namespace doc { |
| 28 | |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 29 | namespace { |
| 30 | |
| 31 | const SymbolID EmptySID = SymbolID(); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 32 | |
| 33 | template <typename T> |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 34 | llvm::Expected<std::unique_ptr<Info>> |
| 35 | reduce(std::vector<std::unique_ptr<Info>> &Values) { |
Paul Kirth | 30360d8 | 2022-07-22 17:34:58 | [diff] [blame] | 36 | if (Values.empty() || !Values[0]) |
Fangrui Song | 1803806 | 2019-08-28 02:56:03 | [diff] [blame] | 37 | return llvm::createStringError(llvm::inconvertibleErrorCode(), |
| 38 | "no value to reduce"); |
Jonas Devlieghere | 1c705d9 | 2019-08-14 23:52:23 | [diff] [blame] | 39 | std::unique_ptr<Info> Merged = std::make_unique<T>(Values[0]->USR); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 40 | T *Tmp = static_cast<T *>(Merged.get()); |
| 41 | for (auto &I : Values) |
| 42 | Tmp->merge(std::move(*static_cast<T *>(I.get()))); |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 43 | return std::move(Merged); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 44 | } |
| 45 | |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 46 | // Return the index of the matching child in the vector, or -1 if merge is not |
| 47 | // necessary. |
| 48 | template <typename T> |
| 49 | int getChildIndexIfExists(std::vector<T> &Children, T &ChildToMerge) { |
| 50 | for (unsigned long I = 0; I < Children.size(); I++) { |
| 51 | if (ChildToMerge.USR == Children[I].USR) |
| 52 | return I; |
| 53 | } |
| 54 | return -1; |
| 55 | } |
| 56 | |
Paul Kirth | 9470de6 | 2022-07-19 22:55:41 | [diff] [blame] | 57 | template <typename T> |
| 58 | void reduceChildren(std::vector<T> &Children, |
| 59 | std::vector<T> &&ChildrenToMerge) { |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 60 | for (auto &ChildToMerge : ChildrenToMerge) { |
Paul Kirth | 9470de6 | 2022-07-19 22:55:41 | [diff] [blame] | 61 | int MergeIdx = getChildIndexIfExists(Children, ChildToMerge); |
| 62 | if (MergeIdx == -1) { |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 63 | Children.push_back(std::move(ChildToMerge)); |
Diego Astiazaran | e27f778 | 2019-08-12 18:42:46 | [diff] [blame] | 64 | continue; |
| 65 | } |
Paul Kirth | 9470de6 | 2022-07-19 22:55:41 | [diff] [blame] | 66 | Children[MergeIdx].merge(std::move(ChildToMerge)); |
Brett Wilson | 21fb70c | 2022-10-14 21:28:43 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 70 | } // namespace |
| 71 | |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 72 | // Dispatch function. |
| 73 | llvm::Expected<std::unique_ptr<Info>> |
| 74 | mergeInfos(std::vector<std::unique_ptr<Info>> &Values) { |
Paul Kirth | 30360d8 | 2022-07-22 17:34:58 | [diff] [blame] | 75 | if (Values.empty() || !Values[0]) |
Fangrui Song | 1803806 | 2019-08-28 02:56:03 | [diff] [blame] | 76 | return llvm::createStringError(llvm::inconvertibleErrorCode(), |
| 77 | "no info values to merge"); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 78 | |
| 79 | switch (Values[0]->IT) { |
| 80 | case InfoType::IT_namespace: |
| 81 | return reduce<NamespaceInfo>(Values); |
| 82 | case InfoType::IT_record: |
| 83 | return reduce<RecordInfo>(Values); |
| 84 | case InfoType::IT_enum: |
| 85 | return reduce<EnumInfo>(Values); |
| 86 | case InfoType::IT_function: |
| 87 | return reduce<FunctionInfo>(Values); |
Brett Wilson | 21fb70c | 2022-10-14 21:28:43 | [diff] [blame] | 88 | case InfoType::IT_typedef: |
| 89 | return reduce<TypedefInfo>(Values); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 90 | default: |
Fangrui Song | 1803806 | 2019-08-28 02:56:03 | [diff] [blame] | 91 | return llvm::createStringError(llvm::inconvertibleErrorCode(), |
| 92 | "unexpected info type"); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Jens Massberg | f88c6b9 | 2023-01-13 10:37:13 | [diff] [blame] | 96 | bool CommentInfo::operator==(const CommentInfo &Other) const { |
| 97 | auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName, |
| 98 | SelfClosing, Explicit, AttrKeys, AttrValues, Args); |
| 99 | auto SecondCI = |
| 100 | std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction, |
| 101 | Other.ParamName, Other.CloseName, Other.SelfClosing, |
| 102 | Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args); |
| 103 | |
| 104 | if (FirstCI != SecondCI || Children.size() != Other.Children.size()) |
| 105 | return false; |
| 106 | |
| 107 | return std::equal(Children.begin(), Children.end(), Other.Children.begin(), |
| 108 | llvm::deref<std::equal_to<>>{}); |
| 109 | } |
| 110 | |
| 111 | bool CommentInfo::operator<(const CommentInfo &Other) const { |
| 112 | auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName, |
| 113 | SelfClosing, Explicit, AttrKeys, AttrValues, Args); |
| 114 | auto SecondCI = |
| 115 | std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction, |
| 116 | Other.ParamName, Other.CloseName, Other.SelfClosing, |
| 117 | Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args); |
| 118 | |
| 119 | if (FirstCI < SecondCI) |
| 120 | return true; |
| 121 | |
| 122 | if (FirstCI == SecondCI) { |
| 123 | return std::lexicographical_compare( |
| 124 | Children.begin(), Children.end(), Other.Children.begin(), |
| 125 | Other.Children.end(), llvm::deref<std::less<>>()); |
| 126 | } |
| 127 | |
| 128 | return false; |
| 129 | } |
| 130 | |
Petr Hosek | 7003f64 | 2020-03-07 01:33:56 | [diff] [blame] | 131 | static llvm::SmallString<64> |
| 132 | calculateRelativeFilePath(const InfoType &Type, const StringRef &Path, |
| 133 | const StringRef &Name, const StringRef &CurrentPath) { |
| 134 | llvm::SmallString<64> FilePath; |
| 135 | |
| 136 | if (CurrentPath != Path) { |
| 137 | // iterate back to the top |
| 138 | for (llvm::sys::path::const_iterator I = |
| 139 | llvm::sys::path::begin(CurrentPath); |
| 140 | I != llvm::sys::path::end(CurrentPath); ++I) |
| 141 | llvm::sys::path::append(FilePath, ".."); |
| 142 | llvm::sys::path::append(FilePath, Path); |
| 143 | } |
| 144 | |
| 145 | // Namespace references have a Path to the parent namespace, but |
| 146 | // the file is actually in the subdirectory for the namespace. |
| 147 | if (Type == doc::InfoType::IT_namespace) |
| 148 | llvm::sys::path::append(FilePath, Name); |
| 149 | |
| 150 | return llvm::sys::path::relative_path(FilePath); |
| 151 | } |
| 152 | |
| 153 | llvm::SmallString<64> |
| 154 | Reference::getRelativeFilePath(const StringRef &CurrentPath) const { |
| 155 | return calculateRelativeFilePath(RefType, Path, Name, CurrentPath); |
| 156 | } |
| 157 | |
| 158 | llvm::SmallString<16> Reference::getFileBaseName() const { |
| 159 | if (RefType == InfoType::IT_namespace) |
| 160 | return llvm::SmallString<16>("index"); |
| 161 | |
| 162 | return Name; |
| 163 | } |
| 164 | |
| 165 | llvm::SmallString<64> |
| 166 | Info::getRelativeFilePath(const StringRef &CurrentPath) const { |
| 167 | return calculateRelativeFilePath(IT, Path, extractName(), CurrentPath); |
| 168 | } |
| 169 | |
| 170 | llvm::SmallString<16> Info::getFileBaseName() const { |
| 171 | if (IT == InfoType::IT_namespace) |
| 172 | return llvm::SmallString<16>("index"); |
| 173 | |
| 174 | return extractName(); |
| 175 | } |
| 176 | |
Diego Astiazaran | e27f778 | 2019-08-12 18:42:46 | [diff] [blame] | 177 | bool Reference::mergeable(const Reference &Other) { |
| 178 | return RefType == Other.RefType && USR == Other.USR; |
| 179 | } |
| 180 | |
| 181 | void Reference::merge(Reference &&Other) { |
| 182 | assert(mergeable(Other)); |
| 183 | if (Name.empty()) |
| 184 | Name = Other.Name; |
| 185 | if (Path.empty()) |
| 186 | Path = Other.Path; |
Diego Astiazaran | e27f778 | 2019-08-12 18:42:46 | [diff] [blame] | 187 | } |
| 188 | |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 189 | void Info::mergeBase(Info &&Other) { |
| 190 | assert(mergeable(Other)); |
| 191 | if (USR == EmptySID) |
| 192 | USR = Other.USR; |
| 193 | if (Name == "") |
| 194 | Name = Other.Name; |
Julie Hockett | 2c1c9a2 | 2019-07-12 18:32:00 | [diff] [blame] | 195 | if (Path == "") |
| 196 | Path = Other.Path; |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 197 | if (Namespace.empty()) |
| 198 | Namespace = std::move(Other.Namespace); |
| 199 | // Unconditionally extend the description, since each decl may have a comment. |
| 200 | std::move(Other.Description.begin(), Other.Description.end(), |
| 201 | std::back_inserter(Description)); |
Benjamin Kramer | 4065e92 | 2020-03-28 18:19:55 | [diff] [blame] | 202 | llvm::sort(Description); |
Julie Hockett | 93a290f | 2019-06-28 18:17:58 | [diff] [blame] | 203 | auto Last = std::unique(Description.begin(), Description.end()); |
| 204 | Description.erase(Last, Description.end()); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | bool Info::mergeable(const Info &Other) { |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 208 | return IT == Other.IT && USR == Other.USR; |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void SymbolInfo::merge(SymbolInfo &&Other) { |
| 212 | assert(mergeable(Other)); |
| 213 | if (!DefLoc) |
| 214 | DefLoc = std::move(Other.DefLoc); |
| 215 | // Unconditionally extend the list of locations, since we want all of them. |
| 216 | std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(Loc)); |
Benjamin Kramer | 4065e92 | 2020-03-28 18:19:55 | [diff] [blame] | 217 | llvm::sort(Loc); |
Julie Hockett | 93a290f | 2019-06-28 18:17:58 | [diff] [blame] | 218 | auto Last = std::unique(Loc.begin(), Loc.end()); |
| 219 | Loc.erase(Last, Loc.end()); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 220 | mergeBase(std::move(Other)); |
| 221 | } |
| 222 | |
Jens Massberg | f88c6b9 | 2023-01-13 10:37:13 | [diff] [blame] | 223 | NamespaceInfo::NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path) |
| 224 | : Info(InfoType::IT_namespace, USR, Name, Path) {} |
| 225 | |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 226 | void NamespaceInfo::merge(NamespaceInfo &&Other) { |
| 227 | assert(mergeable(Other)); |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 228 | // Reduce children if necessary. |
Brett Wilson | 21fb70c | 2022-10-14 21:28:43 | [diff] [blame] | 229 | reduceChildren(Children.Namespaces, std::move(Other.Children.Namespaces)); |
| 230 | reduceChildren(Children.Records, std::move(Other.Children.Records)); |
| 231 | reduceChildren(Children.Functions, std::move(Other.Children.Functions)); |
| 232 | reduceChildren(Children.Enums, std::move(Other.Children.Enums)); |
| 233 | reduceChildren(Children.Typedefs, std::move(Other.Children.Typedefs)); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 234 | mergeBase(std::move(Other)); |
| 235 | } |
| 236 | |
Jens Massberg | f88c6b9 | 2023-01-13 10:37:13 | [diff] [blame] | 237 | RecordInfo::RecordInfo(SymbolID USR, StringRef Name, StringRef Path) |
| 238 | : SymbolInfo(InfoType::IT_record, USR, Name, Path) {} |
| 239 | |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 240 | void RecordInfo::merge(RecordInfo &&Other) { |
| 241 | assert(mergeable(Other)); |
Vlad Serebrennikov | edd690b | 2023-11-03 17:45:39 | [diff] [blame] | 242 | if (!llvm::to_underlying(TagType)) |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 243 | TagType = Other.TagType; |
Brett Wilson | 6826682 | 2022-08-12 18:38:21 | [diff] [blame] | 244 | IsTypeDef = IsTypeDef || Other.IsTypeDef; |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 245 | if (Members.empty()) |
| 246 | Members = std::move(Other.Members); |
Diego Astiazaran | ba3d595 | 2019-08-16 00:10:49 | [diff] [blame] | 247 | if (Bases.empty()) |
| 248 | Bases = std::move(Other.Bases); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 249 | if (Parents.empty()) |
| 250 | Parents = std::move(Other.Parents); |
| 251 | if (VirtualParents.empty()) |
| 252 | VirtualParents = std::move(Other.VirtualParents); |
Julie Hockett | 8899c29 | 2018-08-02 20:10:17 | [diff] [blame] | 253 | // Reduce children if necessary. |
Brett Wilson | 21fb70c | 2022-10-14 21:28:43 | [diff] [blame] | 254 | reduceChildren(Children.Records, std::move(Other.Children.Records)); |
| 255 | reduceChildren(Children.Functions, std::move(Other.Children.Functions)); |
| 256 | reduceChildren(Children.Enums, std::move(Other.Children.Enums)); |
| 257 | reduceChildren(Children.Typedefs, std::move(Other.Children.Typedefs)); |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 258 | SymbolInfo::merge(std::move(Other)); |
Brett Wilson | 4a68bab | 2022-12-07 18:26:04 | [diff] [blame] | 259 | if (!Template) |
| 260 | Template = Other.Template; |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void EnumInfo::merge(EnumInfo &&Other) { |
| 264 | assert(mergeable(Other)); |
| 265 | if (!Scoped) |
| 266 | Scoped = Other.Scoped; |
| 267 | if (Members.empty()) |
| 268 | Members = std::move(Other.Members); |
| 269 | SymbolInfo::merge(std::move(Other)); |
| 270 | } |
| 271 | |
| 272 | void FunctionInfo::merge(FunctionInfo &&Other) { |
| 273 | assert(mergeable(Other)); |
| 274 | if (!IsMethod) |
| 275 | IsMethod = Other.IsMethod; |
| 276 | if (!Access) |
| 277 | Access = Other.Access; |
| 278 | if (ReturnType.Type.USR == EmptySID && ReturnType.Type.Name == "") |
| 279 | ReturnType = std::move(Other.ReturnType); |
| 280 | if (Parent.USR == EmptySID && Parent.Name == "") |
| 281 | Parent = std::move(Other.Parent); |
| 282 | if (Params.empty()) |
| 283 | Params = std::move(Other.Params); |
| 284 | SymbolInfo::merge(std::move(Other)); |
Brett Wilson | 4a68bab | 2022-12-07 18:26:04 | [diff] [blame] | 285 | if (!Template) |
| 286 | Template = Other.Template; |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 287 | } |
| 288 | |
Brett Wilson | 21fb70c | 2022-10-14 21:28:43 | [diff] [blame] | 289 | void TypedefInfo::merge(TypedefInfo &&Other) { |
| 290 | assert(mergeable(Other)); |
| 291 | if (!IsUsing) |
| 292 | IsUsing = Other.IsUsing; |
| 293 | if (Underlying.Type.Name == "") |
| 294 | Underlying = Other.Underlying; |
| 295 | SymbolInfo::merge(std::move(Other)); |
| 296 | } |
| 297 | |
Jens Massberg | f88c6b9 | 2023-01-13 10:37:13 | [diff] [blame] | 298 | BaseRecordInfo::BaseRecordInfo() : RecordInfo() {} |
| 299 | |
| 300 | BaseRecordInfo::BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, |
| 301 | bool IsVirtual, AccessSpecifier Access, |
| 302 | bool IsParent) |
| 303 | : RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access), |
| 304 | IsParent(IsParent) {} |
| 305 | |
Diego Astiazaran | 7dfe0bc | 2019-08-06 18:31:46 | [diff] [blame] | 306 | llvm::SmallString<16> Info::extractName() const { |
Julie Hockett | d900ef0 | 2019-06-28 19:07:56 | [diff] [blame] | 307 | if (!Name.empty()) |
| 308 | return Name; |
| 309 | |
| 310 | switch (IT) { |
| 311 | case InfoType::IT_namespace: |
| 312 | // Cover the case where the project contains a base namespace called |
| 313 | // 'GlobalNamespace' (i.e. a namespace at the same level as the global |
| 314 | // namespace, which would conflict with the hard-coded global namespace name |
| 315 | // below.) |
| 316 | if (Name == "GlobalNamespace" && Namespace.empty()) |
| 317 | return llvm::SmallString<16>("@GlobalNamespace"); |
| 318 | // The case of anonymous namespaces is taken care of in serialization, |
| 319 | // so here we can safely assume an unnamed namespace is the global |
| 320 | // one. |
| 321 | return llvm::SmallString<16>("GlobalNamespace"); |
| 322 | case InfoType::IT_record: |
| 323 | return llvm::SmallString<16>("@nonymous_record_" + |
| 324 | toHex(llvm::toStringRef(USR))); |
| 325 | case InfoType::IT_enum: |
| 326 | return llvm::SmallString<16>("@nonymous_enum_" + |
| 327 | toHex(llvm::toStringRef(USR))); |
Brett Wilson | 21fb70c | 2022-10-14 21:28:43 | [diff] [blame] | 328 | case InfoType::IT_typedef: |
| 329 | return llvm::SmallString<16>("@nonymous_typedef_" + |
| 330 | toHex(llvm::toStringRef(USR))); |
Julie Hockett | d900ef0 | 2019-06-28 19:07:56 | [diff] [blame] | 331 | case InfoType::IT_function: |
| 332 | return llvm::SmallString<16>("@nonymous_function_" + |
| 333 | toHex(llvm::toStringRef(USR))); |
| 334 | case InfoType::IT_default: |
| 335 | return llvm::SmallString<16>("@nonymous_" + toHex(llvm::toStringRef(USR))); |
| 336 | } |
| 337 | llvm_unreachable("Invalid InfoType."); |
| 338 | return llvm::SmallString<16>(""); |
| 339 | } |
| 340 | |
Diego Astiazaran | b7bb9fb | 2019-08-15 23:32:12 | [diff] [blame] | 341 | // Order is based on the Name attribute: case insensitive order |
| 342 | bool Index::operator<(const Index &Other) const { |
| 343 | // Loop through each character of both strings |
| 344 | for (unsigned I = 0; I < Name.size() && I < Other.Name.size(); ++I) { |
| 345 | // Compare them after converting both to lower case |
| 346 | int D = tolower(Name[I]) - tolower(Other.Name[I]); |
| 347 | if (D == 0) |
| 348 | continue; |
| 349 | return D < 0; |
| 350 | } |
| 351 | // If both strings have the size it means they would be equal if changed to |
| 352 | // lower case. In here, lower case will be smaller than upper case |
| 353 | // Example: string < stRing = true |
| 354 | // This is the opposite of how operator < handles strings |
| 355 | if (Name.size() == Other.Name.size()) |
| 356 | return Name > Other.Name; |
| 357 | // If they are not the same size; the shorter string is smaller |
| 358 | return Name.size() < Other.Name.size(); |
| 359 | } |
| 360 | |
Diego Astiazaran | 7dfe0bc | 2019-08-06 18:31:46 | [diff] [blame] | 361 | void Index::sort() { |
Benjamin Kramer | 4065e92 | 2020-03-28 18:19:55 | [diff] [blame] | 362 | llvm::sort(Children); |
Diego Astiazaran | 7dfe0bc | 2019-08-06 18:31:46 | [diff] [blame] | 363 | for (auto &C : Children) |
| 364 | C.sort(); |
| 365 | } |
| 366 | |
Diego Astiazaran | 665e967 | 2019-08-09 17:49:41 | [diff] [blame] | 367 | ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx, |
Diego Astiazaran | 3550da7 | 2019-08-16 18:38:11 | [diff] [blame] | 368 | StringRef ProjectName, bool PublicOnly, |
| 369 | StringRef OutDirectory, StringRef SourceRoot, |
| 370 | StringRef RepositoryUrl, |
PeterChou1 | f14ad74 | 2024-06-27 20:22:01 | [diff] [blame] | 371 | std::vector<std::string> UserStylesheets) |
Diego Astiazaran | 3550da7 | 2019-08-16 18:38:11 | [diff] [blame] | 372 | : ECtx(ECtx), ProjectName(ProjectName), PublicOnly(PublicOnly), |
PeterChou1 | f14ad74 | 2024-06-27 20:22:01 | [diff] [blame] | 373 | OutDirectory(OutDirectory), UserStylesheets(UserStylesheets) { |
Diego Astiazaran | 77dc05b | 2019-08-15 23:20:42 | [diff] [blame] | 374 | llvm::SmallString<128> SourceRootDir(SourceRoot); |
| 375 | if (SourceRoot.empty()) |
| 376 | // If no SourceRoot was provided the current path is used as the default |
| 377 | llvm::sys::fs::current_path(SourceRootDir); |
Kazu Hirata | 2b00d44 | 2024-01-27 07:46:24 | [diff] [blame] | 378 | this->SourceRoot = std::string(SourceRootDir); |
Diego Astiazaran | 665e967 | 2019-08-09 17:49:41 | [diff] [blame] | 379 | if (!RepositoryUrl.empty()) { |
Benjamin Kramer | adcd026 | 2020-01-28 19:23:46 | [diff] [blame] | 380 | this->RepositoryUrl = std::string(RepositoryUrl); |
Nicolas van Kempen | 5232cec | 2024-04-19 21:00:13 | [diff] [blame] | 381 | if (!RepositoryUrl.empty() && !RepositoryUrl.starts_with("http://") && |
| 382 | !RepositoryUrl.starts_with("https://")) |
Diego Astiazaran | 665e967 | 2019-08-09 17:49:41 | [diff] [blame] | 383 | this->RepositoryUrl->insert(0, "https://"); |
| 384 | } |
| 385 | } |
| 386 | |
Julie Hockett | d0f9a87 | 2018-06-04 17:22:20 | [diff] [blame] | 387 | } // namespace doc |
| 388 | } // namespace clang |