Class responsible for building all kinds of templates from Clang AST. More...
Class responsible for building all kinds of templates from Clang AST.
Definition at line 49 of file template_builder.h.
#include <template_builder.h>
Public Member Functions | |
template_builder (clanguml::common::model::diagram &diagram_, const clanguml::config::diagram &config_, VisitorT &visitor) | |
Constructor. | |
common::model::diagram & | diagram () |
Get reference to the current diagram model. | |
const config::diagram & | config () const |
Get reference to the current diagram configuration. | |
const namespace_ & | using_namespace () const |
Get diagram relative namespace. | |
bool | simplify_system_template (template_parameter &ct, const std::string &full_name) const |
Simplify system templates. | |
void | build_from_template_declaration (clanguml::common::model::template_trait &template_model, const clang::TemplateDecl &template_declaration, common::optional_ref< common::model::element > templated_element={}) |
void | build_from_template_specialization_type (clanguml::common::model::template_element &template_instantiation, const clang::NamedDecl *cls, const clang::TemplateSpecializationType &template_type_decl, std::optional< clanguml::common::model::template_element * > parent={}) |
Basic template class build method. | |
void | build (clanguml::common::model::template_element &template_instantiation, const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::ArrayRef< clang::TemplateArgument > template_arguments, std::string full_template_specialization_name, std::optional< clanguml::common::model::template_element * > parent={}) |
void | build_from_class_template_specialization (clanguml::common::model::template_element &template_instantiation, const clang::ClassTemplateSpecializationDecl &template_specialization, std::optional< clanguml::common::model::template_element * > parent={}) |
Build template class from class template specialization decl. | |
bool | add_base_classes (clanguml::common::model::template_element &tinst, std::deque< std::tuple< std::string, int, bool > > &template_base_params, int arg_index, bool variadic_params, const clanguml::common::model::template_parameter &ct) |
Add base classes to the template class, if any. | |
void | process_template_arguments (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, std::deque< std::tuple< std::string, int, bool > > &template_base_params, const clang::ArrayRef< clang::TemplateArgument > &template_args, clanguml::common::model::template_element &template_instantiation, const clang::TemplateDecl *template_decl) |
Process template class parameters and arguments. | |
void | argument_process_dispatch (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, clanguml::common::model::template_element &template_instantiation, const clang::TemplateDecl *template_decl, const clang::TemplateArgument &arg, size_t argument_index, std::vector< template_parameter > &argument) |
Process template arguments based on their type. | |
template_parameter | process_expression_argument (const clang::TemplateArgument &arg) |
Process clang::TemplateArgument::Expression | |
template_parameter | process_integral_argument (const clang::TemplateArgument &arg, const clang::ASTContext &ast_context) |
Process clang::TemplateArgument::Integral | |
template_parameter | process_nullptr_argument (const clang::TemplateArgument &arg) |
Process clang::TemplateArgument::NullPtr | |
template_parameter | process_null_argument (const clang::TemplateArgument &arg) |
Process clang::TemplateArgument::Null | |
std::vector< template_parameter > | process_pack_argument (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, clanguml::common::model::template_element &template_instantiation, const clang::TemplateDecl *base_template_decl, const clang::TemplateArgument &arg, size_t argument_index, std::vector< template_parameter > &argument) |
Process clang::TemplateArgument::Pack | |
template_parameter | process_type_argument (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, const clang::TemplateDecl *base_template_decl, clang::QualType type, clanguml::common::model::template_element &template_instantiation, size_t argument_index) |
Process clang::TemplateArgument::Type | |
common::model::template_parameter | process_template_argument (const clang::TemplateArgument &arg) |
Process clang::TemplateArgument::Template | |
common::model::template_parameter | process_template_expansion (const clang::TemplateArgument &arg) |
Process clang::TemplateArgument::TemplateExpansion | |
std::optional< template_parameter > | try_as_function_prototype (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type, clanguml::common::model::template_element &template_instantiation, size_t argument_index) |
Try to process template type argument as function template. | |
std::optional< template_parameter > | try_as_array (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type, clanguml::common::model::template_element &template_instantiation, size_t argument_index) |
Try to process template type argument as array. | |
std::optional< template_parameter > | try_as_template_specialization_type (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type, clanguml::common::model::template_element &template_instantiation, size_t argument_index) |
Try to process template type argument as specialization type. | |
std::optional< template_parameter > | try_as_template_parm_type (const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type) |
Try to process template type argument as template parameter. | |
std::optional< template_parameter > | try_as_lambda (const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type) |
Try to process template type argument as lambda. | |
std::optional< template_parameter > | try_as_record_type (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type, clanguml::common::model::template_element &template_instantiation, size_t argument_index) |
Try to process template type argument as record type. | |
std::optional< template_parameter > | try_as_enum_type (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type, clanguml::common::model::template_element &template_instantiation) |
Try to process template type argument as enum type. | |
std::optional< template_parameter > | try_as_builtin_type (std::optional< clanguml::common::model::template_element * > &parent, clang::QualType &type, const clang::TemplateDecl *template_decl) |
Try to process template type argument as builtin type. | |
std::optional< template_parameter > | try_as_member_pointer (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type, clanguml::common::model::template_element &template_instantiation, size_t argument_index) |
Try to process template type argument as member pointer type. | |
std::optional< template_parameter > | try_as_decl_type (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type, clanguml::common::model::template_element &template_instantiation, size_t argument_index) |
Try to process template type argument as decltype() type. | |
std::optional< template_parameter > | try_as_typedef_type (std::optional< clanguml::common::model::template_element * > &parent, const clang::NamedDecl *cls, const clang::TemplateDecl *template_decl, clang::QualType &type, clanguml::common::model::template_element &template_instantiation, size_t argument_index) |
Try to process template type argument as typedef/using type. | |
clang::QualType | consume_context (clang::QualType type, template_parameter &tp) const |
Remove types context (e.g. const or reference qualifiers) | |
bool | find_relationships_in_unexposed_template_params (const template_parameter &ct, found_relationships_t &relationships) |
Try to find additional relationships in unexposed parameters. | |
void | find_instantiation_relationships (common::model::template_element &template_instantiation, eid_t id, const std::string &qualified_name) const |
common::visitor::ast_id_mapper & | id_mapper () |
Get reference to Clang AST to clang-uml id mapper. | |
clang::SourceManager & | source_manager () const |
Get reference to the current source manager. | |
Private Attributes | |
clanguml::common::model::diagram & | diagram_ |
const clanguml::config::diagram & | config_ |
common::visitor::ast_id_mapper & | id_mapper_ |
clang::SourceManager & | source_manager_ |
VisitorT & | visitor_ |
clanguml::common::visitor::template_builder< VisitorT >::template_builder | ( | clanguml::common::model::diagram & | diagram_, |
const clanguml::config::diagram & | config_, | ||
VisitorT & | visitor | ||
) |
Constructor.
visitor | Reference to class diagram translation_unit_visitor |
Definition at line 558 of file template_builder.h.
bool clanguml::common::visitor::template_builder< VisitorT >::add_base_classes | ( | clanguml::common::model::template_element & | tinst, |
std::deque< std::tuple< std::string, int, bool > > & | template_base_params, | ||
int | arg_index, | ||
bool | variadic_params, | ||
const clanguml::common::model::template_parameter & | ct | ||
) |
Add base classes to the template class, if any.
This method adds base classes to a template declaration or specialization, including inferring whether variadic template parameter bases.
tinst | Class template model |
template_base_params | List of base class template parameters |
arg_index | Index of the template argument used for base class |
variadic_params | Whether the parameter is variadic |
ct | Template parameter model |
Definition at line 1861 of file template_builder.h.
void clanguml::common::visitor::template_builder< VisitorT >::argument_process_dispatch | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
const clang::TemplateDecl * | template_decl, | ||
const clang::TemplateArgument & | arg, | ||
size_t | argument_index, | ||
std::vector< template_parameter > & | argument | ||
) |
Process template arguments based on their type.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_instantiation | Template class model to add template args |
template_decl | Base template declaration |
arg | Template argument |
argument_index | Argument index |
argument | Output list of arguments (can be more than one for variadic parameters) |
Definition at line 1039 of file template_builder.h.
void clanguml::common::visitor::template_builder< VisitorT >::build | ( | clanguml::common::model::template_element & | template_instantiation, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | template_decl, | ||
clang::ArrayRef< clang::TemplateArgument > | template_arguments, | ||
std::string | full_template_specialization_name, | ||
std::optional< clanguml::common::model::template_element * > | parent = {} |
||
) |
Definition at line 768 of file template_builder.h.
void clanguml::common::visitor::template_builder< VisitorT >::build_from_class_template_specialization | ( | clanguml::common::model::template_element & | template_instantiation, |
const clang::ClassTemplateSpecializationDecl & | template_specialization, | ||
std::optional< clanguml::common::model::template_element * > | parent = {} |
||
) |
Build template class from class template specialization decl.
template_specialization | Class template specialization declaration |
parent | Optional class in which this template is contained |
Definition at line 895 of file template_builder.h.
void clanguml::common::visitor::template_builder< VisitorT >::build_from_template_declaration | ( | clanguml::common::model::template_trait & | template_model, |
const clang::TemplateDecl & | template_declaration, | ||
common::optional_ref< common::model::element > | templated_element = {} |
||
) |
Definition at line 619 of file template_builder.h.
void clanguml::common::visitor::template_builder< VisitorT >::build_from_template_specialization_type | ( | clanguml::common::model::template_element & | template_instantiation, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateSpecializationType & | template_type_decl, | ||
std::optional< clanguml::common::model::template_element * > | parent = {} |
||
) |
Basic template class build method.
cls | Clang template declaration |
template_type_decl | Template specialization type |
parent | Optional class in which this template is contained |
Definition at line 736 of file template_builder.h.
const config::diagram & clanguml::common::visitor::template_builder< VisitorT >::config |
Get reference to the current diagram configuration.
Definition at line 576 of file template_builder.h.
clang::QualType clanguml::common::visitor::template_builder< VisitorT >::consume_context | ( | clang::QualType | type, |
template_parameter & | tp | ||
) | const |
Remove types context (e.g. const or reference qualifiers)
This method removes all const and reference/pointer qualifiers from type
, adds them to the template parameter model tp
and returns a type without context.
type | Type to remove context from |
tp | Template model to add context to |
Definition at line 1122 of file template_builder.h.
common::model::diagram & clanguml::common::visitor::template_builder< VisitorT >::diagram |
Get reference to the current diagram model.
Definition at line 570 of file template_builder.h.
void clanguml::common::visitor::template_builder< VisitorT >::find_instantiation_relationships | ( | common::model::template_element & | template_instantiation, |
eid_t | id, | ||
const std::string & | qualified_name | ||
) | const |
Definition at line 937 of file template_builder.h.
bool clanguml::common::visitor::template_builder< VisitorT >::find_relationships_in_unexposed_template_params | ( | const template_parameter & | ct, |
found_relationships_t & | relationships | ||
) |
Try to find additional relationships in unexposed parameters.
Sometimes, Clang will report a template parameter as unexposed, which means all we get a is a string representation of the type, sometimes with template parameter names replaced with type-parameter-X-Y
string.
This method tries to find any type names, which might be relevant for the diagram relationships.
ct | Template argument model |
relationships | List of discovered relationships |
Definition at line 1210 of file template_builder.h.
common::visitor::ast_id_mapper & clanguml::common::visitor::template_builder< VisitorT >::id_mapper |
Get reference to Clang AST to clang-uml id mapper.
Definition at line 588 of file template_builder.h.
template_parameter clanguml::common::visitor::template_builder< VisitorT >::process_expression_argument | ( | const clang::TemplateArgument & | arg | ) |
Process clang::TemplateArgument::Expression
arg | Template argument |
Definition at line 1308 of file template_builder.h.
template_parameter clanguml::common::visitor::template_builder< VisitorT >::process_integral_argument | ( | const clang::TemplateArgument & | arg, |
const clang::ASTContext & | ast_context | ||
) |
Process clang::TemplateArgument::Integral
arg | Template argument |
Definition at line 1248 of file template_builder.h.
template_parameter clanguml::common::visitor::template_builder< VisitorT >::process_null_argument | ( | const clang::TemplateArgument & | arg | ) |
Process clang::TemplateArgument::Null
arg | Template argument |
Definition at line 1288 of file template_builder.h.
template_parameter clanguml::common::visitor::template_builder< VisitorT >::process_nullptr_argument | ( | const clang::TemplateArgument & | arg | ) |
Process clang::TemplateArgument::NullPtr
arg | Template argument |
Definition at line 1297 of file template_builder.h.
std::vector< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::process_pack_argument | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
const clang::TemplateDecl * | base_template_decl, | ||
const clang::TemplateArgument & | arg, | ||
size_t | argument_index, | ||
std::vector< template_parameter > & | argument | ||
) |
Process clang::TemplateArgument::Pack
arg | Template argument |
Definition at line 1318 of file template_builder.h.
template_parameter clanguml::common::visitor::template_builder< VisitorT >::process_template_argument | ( | const clang::TemplateArgument & | arg | ) |
Process clang::TemplateArgument::Template
arg | Template argument |
Definition at line 1092 of file template_builder.h.
void clanguml::common::visitor::template_builder< VisitorT >::process_template_arguments | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
std::deque< std::tuple< std::string, int, bool > > & | template_base_params, | ||
const clang::ArrayRef< clang::TemplateArgument > & | template_args, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
const clang::TemplateDecl * | template_decl | ||
) |
Process template class parameters and arguments.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_base_params | List of base class template parameters |
template_args | List of template arguments |
template_instantiation | Template class model to add template args |
template_decl | Base template declaration |
Definition at line 946 of file template_builder.h.
template_parameter clanguml::common::visitor::template_builder< VisitorT >::process_template_expansion | ( | const clang::TemplateArgument & | arg | ) |
Process clang::TemplateArgument::TemplateExpansion
arg | Template argument |
Definition at line 1103 of file template_builder.h.
template_parameter clanguml::common::visitor::template_builder< VisitorT >::process_type_argument | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | base_template_decl, | ||
clang::QualType | type, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
size_t | argument_index | ||
) |
Process clang::TemplateArgument::Type
arg | Template argument |
Definition at line 1133 of file template_builder.h.
bool clanguml::common::visitor::template_builder< VisitorT >::simplify_system_template | ( | template_parameter & | ct, |
const std::string & | full_name | ||
) | const |
Simplify system templates.
This method tries to simplify all fully qualified template names in the full_name
using substitutions from the configuration file ().
Typical example is replace every std::basic_string<char>
with std::string
.
ct | Template parameter |
full_name | Full template name |
Definition at line 600 of file template_builder.h.
clang::SourceManager & clanguml::common::visitor::template_builder< VisitorT >::source_manager |
Get reference to the current source manager.
Definition at line 594 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_array | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
size_t | argument_index | ||
) |
Try to process template type argument as array.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
template_instantiation | Template class model |
argument_index | Argument index |
Definition at line 1419 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_builtin_type | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
clang::QualType & | type, | ||
const clang::TemplateDecl * | template_decl | ||
) |
Try to process template type argument as builtin type.
parent | Optional class in which this template is contained |
type | Template type |
template_decl | Base template declaration |
Definition at line 1841 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_decl_type | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
size_t | argument_index | ||
) |
Try to process template type argument as decltype()
type.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
template_instantiation | Template class model |
argument_index | Argument index |
decltype()
type template argument if succeeds, or std::nullopt Definition at line 1515 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_enum_type | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type, | ||
clanguml::common::model::template_element & | template_instantiation | ||
) |
Try to process template type argument as enum type.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
template_instantiation | Template class model |
Definition at line 1810 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_function_prototype | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
size_t | argument_index | ||
) |
Try to process template type argument as function template.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
template_instantiation | Template class model |
argument_index | Argument index |
Definition at line 1464 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_lambda | ( | const clang::NamedDecl * | cls, |
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type | ||
) |
Try to process template type argument as lambda.
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
Definition at line 1717 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_member_pointer | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
size_t | argument_index | ||
) |
Try to process template type argument as member pointer type.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
template_instantiation | Template class model |
argument_index | Argument index |
Definition at line 1342 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_record_type | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
size_t | argument_index | ||
) |
Try to process template type argument as record type.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
template_instantiation | Template class model |
argument_index | Argument index |
Definition at line 1739 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_template_parm_type | ( | const clang::NamedDecl * | cls, |
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type | ||
) |
Try to process template type argument as template parameter.
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
Definition at line 1673 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_template_specialization_type | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
size_t | argument_index | ||
) |
Try to process template type argument as specialization type.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
template_instantiation | Template class model |
argument_index | Argument index |
Definition at line 1572 of file template_builder.h.
std::optional< template_parameter > clanguml::common::visitor::template_builder< VisitorT >::try_as_typedef_type | ( | std::optional< clanguml::common::model::template_element * > & | parent, |
const clang::NamedDecl * | cls, | ||
const clang::TemplateDecl * | template_decl, | ||
clang::QualType & | type, | ||
clanguml::common::model::template_element & | template_instantiation, | ||
size_t | argument_index | ||
) |
Try to process template type argument as typedef/using type.
parent | Optional class in which this template is contained |
cls | Template class specialization declaration |
template_decl | Base template declaration |
type | Template type |
template_instantiation | Template class model |
argument_index | Argument index |
Definition at line 1536 of file template_builder.h.
const namespace_ & clanguml::common::visitor::template_builder< VisitorT >::using_namespace |
Get diagram relative namespace.
Definition at line 582 of file template_builder.h.
|
private |
Definition at line 548 of file template_builder.h.
|
private |
Definition at line 545 of file template_builder.h.
|
private |
Definition at line 550 of file template_builder.h.
|
private |
Definition at line 552 of file template_builder.h.
|
private |
Definition at line 554 of file template_builder.h.