0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
template_builder.cc
Go to the documentation of this file.
1/**
2 * @file src/class_diagram/visitor/template_builder.cc
3 *
4 * Copyright (c) 2021-2024 Bartek Kryza <bkryza@gmail.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "template_builder.h"
20#include "common/clang_utils.h"
21#include <clang/Lex/Lexer.h>
22
24namespace detail {
25
27 const clang::ClassTemplateSpecializationDecl *decl, const std::string &tp)
28{
29 const auto [depth0, index0, qualifier0] =
31
32 for (auto i = 0U; i < decl->getDescribedTemplateParams()->size(); i++) {
33 const auto *param = decl->getDescribedTemplateParams()->getParam(i);
34
35 if (i == index0) {
36 return param->getNameAsString();
37 }
38 }
39
40 return tp;
41}
42
44 const clang::TypeAliasTemplateDecl *decl, const std::string &tp)
45{
46 const auto [depth0, index0, qualifier0] =
48
49 for (auto i = 0U; i < decl->getTemplateParameters()->size(); i++) {
50 const auto *param = decl->getTemplateParameters()->getParam(i);
51
52 if (i == index0) {
53 return param->getNameAsString();
54 }
55 }
56
57 return tp;
58}
59
60} // namespace detail
61
63 const clang::Decl *decl, const std::string &type_parameter)
64{
65 if (type_parameter.find("type-parameter-") != 0)
66 return type_parameter;
67
68 if (const auto *template_decl =
69 llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(decl);
70 template_decl != nullptr) {
72 template_decl, type_parameter);
73 }
74
75 if (const auto *alias_decl =
76 llvm::dyn_cast<clang::TypeAliasTemplateDecl>(decl);
77 alias_decl != nullptr) {
79 alias_decl, type_parameter);
80 }
81
82 // Fallback
83 return type_parameter;
84}
85
86} // namespace clanguml::common::visitor