Class diagram translation unit visitor. More...
Class diagram translation unit visitor.
This class implements the clang::RecursiveASTVisitor
interface for selected visitors relevant to generating class diagrams.
Definition at line 68 of file translation_unit_visitor.h.
#include <translation_unit_visitor.h>
Public Types | |
using | template_builder_t = template_builder< translation_unit_visitor > |
using | config_t = ConfigT |
using | diagram_t = DiagramT |
Public Types inherited from clanguml::common::visitor::translation_unit_visitor< ConfigT, DiagramT > | |
using | config_t = ConfigT |
using | diagram_t = DiagramT |
Public Member Functions | |
translation_unit_visitor (clang::SourceManager &sm, clanguml::class_diagram::model::diagram &diagram, const clanguml::config::class_diagram &config) | |
Constructor. | |
bool | shouldVisitTemplateInstantiations () const |
bool | shouldVisitImplicitCode () const |
virtual bool | VisitNamespaceDecl (clang::NamespaceDecl *ns) |
virtual bool | VisitRecordDecl (clang::RecordDecl *D) |
virtual bool | VisitCXXRecordDecl (clang::CXXRecordDecl *d) |
virtual bool | VisitEnumDecl (clang::EnumDecl *e) |
virtual bool | VisitClassTemplateDecl (clang::ClassTemplateDecl *class_template_declaration) |
virtual bool | VisitClassTemplateSpecializationDecl (clang::ClassTemplateSpecializationDecl *cls) |
virtual bool | VisitTypeAliasTemplateDecl (clang::TypeAliasTemplateDecl *cls) |
virtual bool | TraverseConceptDecl (clang::ConceptDecl *cpt) |
void | finalize () |
Finalize diagram model. | |
void | add_class (std::unique_ptr< class_ > &&c) |
Add class (or template class) to the diagram. | |
void | add_enum (std::unique_ptr< enum_ > &&e) |
Add enum to the diagram. | |
void | add_concept (std::unique_ptr< concept_ > &&c) |
Add concept to the diagram. | |
void | add_diagram_element (std::unique_ptr< common::model::template_element > element) override |
std::unique_ptr< class_ > | create_element (const clang::NamedDecl *decl) const |
void | find_instantiation_relationships (common::model::template_element &template_instantiation_base, const std::string &full_name, eid_t templated_decl_id) |
Public Member Functions inherited from clanguml::common::visitor::translation_unit_visitor< ConfigT, DiagramT > | |
translation_unit_visitor (clang::SourceManager &sm, DiagramT &diagram, const ConfigT &config) | |
Constructor. | |
virtual | ~translation_unit_visitor ()=default |
void | set_tu_path (const std::string &translation_unit_path) |
const std::filesystem::path & | tu_path () const |
Return relative path to current translation unit. | |
common::visitor::ast_id_mapper & | id_mapper () const |
Get reference to Clang AST to clang-uml id mapper. | |
clang::SourceManager & | source_manager () const |
Get clang::SourceManager. | |
void | set_source_location (const clang::Decl &decl, clanguml::common::model::source_location &element) |
Set source location in diagram element. | |
void | set_source_location (const clang::Expr &expr, clanguml::common::model::source_location &element) |
Set source location in diagram element. | |
void | set_source_location (const clang::Stmt &stmt, clanguml::common::model::source_location &element) |
void | set_qualified_name (const clang::NamedDecl &decl, clanguml::common::model::element &element) |
void | set_source_location (const clang::SourceLocation &location, clanguml::common::model::source_location &element) |
Set source location in diagram element. | |
void | set_owning_module (const clang::Decl &decl, clanguml::common::model::element &element) |
virtual void | add_diagram_element (std::unique_ptr< common::model::template_element > element) |
void | process_comment (const clang::NamedDecl &decl, clanguml::common::model::decorated_element &e) |
Process comment directives in comment attached to a declaration. | |
std::string | process_comment (const clang::RawComment *comment, clang::DiagnosticsEngine &de, clanguml::common::model::decorated_element &e) |
Process comment directives in raw comment. | |
bool | skip_system_header_decl (const clang::NamedDecl *decl) const |
bool | should_include (const clang::NamedDecl *decl) const |
Check if the diagram should include a declaration. | |
DiagramT & | diagram () |
Get diagram model reference. | |
const DiagramT & | diagram () const |
Get diagram model reference. | |
const ConfigT & | config () const |
Get diagram config instance. | |
Private Member Functions | |
std::unique_ptr< clanguml::class_diagram::model::class_ > | create_class_declaration (clang::CXXRecordDecl *cls) |
Create class element model from class declaration. | |
std::unique_ptr< clanguml::class_diagram::model::class_ > | create_record_declaration (clang::RecordDecl *rec) |
Create class element model from record (e.g. struct) declaration. | |
std::unique_ptr< clanguml::class_diagram::model::concept_ > | create_concept_declaration (clang::ConceptDecl *cpt) |
Create concept element model from concept declaration. | |
void | process_class_declaration (const clang::CXXRecordDecl &cls, clanguml::class_diagram::model::class_ &c) |
Process class declaration. | |
void | process_class_bases (const clang::CXXRecordDecl *cls, clanguml::class_diagram::model::class_ &c) |
Process class declaration bases (parents), if any. | |
void | process_class_children (const clang::CXXRecordDecl *cls, clanguml::class_diagram::model::class_ &c) |
Process class children elements (members and methods) | |
void | process_record_members (const clang::RecordDecl *cls, class_ &c) |
Process class or record data members. | |
std::unique_ptr< clanguml::class_diagram::model::class_ > | process_template_specialization (clang::ClassTemplateSpecializationDecl *cls) |
Process class template specialization/instantiation. | |
void | process_template_specialization_children (const clang::ClassTemplateSpecializationDecl *cls, class_ &c) |
Process template specialization children (members and methods) | |
void | process_method (const clang::CXXMethodDecl &mf, clanguml::class_diagram::model::class_ &c) |
Process class method. | |
void | process_method_properties (const clang::CXXMethodDecl &mf, const class_ &c, const std::string &method_name, class_method &method) const |
Process class method properties. | |
void | process_template_method (const clang::FunctionTemplateDecl &mf, clanguml::class_diagram::model::class_ &c) |
Process class template method. | |
void | process_static_field (const clang::VarDecl &field_declaration, clanguml::class_diagram::model::class_ &c) |
Process class static data member. | |
void | process_field (const clang::FieldDecl &field_declaration, clanguml::class_diagram::model::class_ &c) |
Process class data member. | |
void | process_function_parameter (const clang::ParmVarDecl ¶m, clanguml::class_diagram::model::class_method &method, clanguml::class_diagram::model::class_ &c, const std::set< std::string > &template_parameter_names={}) |
Process function/method parameter. | |
void | process_friend (const clang::FriendDecl &f, clanguml::class_diagram::model::class_ &c) |
Process class friend. | |
bool | find_relationships (const clang::QualType &type, found_relationships_t &, clanguml::common::model::relationship_t relationship_hint) |
Find relationships in a specific type. | |
void | add_relationships (clanguml::class_diagram::model::class_ &c, const clanguml::class_diagram::model::class_member &field, const found_relationships_t &relationships, bool break_on_first_aggregation=false) |
Add relationships from relationship list to a class model. | |
void | process_record_parent (clang::RecordDecl *cls, class_ &c, const namespace_ &ns) |
Process record parent element (e.g. for nested classes) | |
void | process_function_parameter_find_relationships_in_autotype (model::class_ &c, const clang::AutoType *atsp) |
Find relationships in function parameter. | |
void | find_relationships_in_constraint_expression (clanguml::common::model::element &c, const clang::Expr *expr) |
Find relationships in concept constraint expression. | |
void | add_incomplete_forward_declarations () |
Register incomplete forward declaration to be updated later. | |
void | resolve_local_to_global_ids () |
Replace any AST local ids in diagram elements with global ones. | |
void | process_constraint_requirements (const clang::ConceptDecl *cpt, const clang::Expr *expr, model::concept_ &concept_model) const |
Process concept constraint requirements. | |
void | process_concept_specialization_relationships (common::model::element &c, const clang::ConceptSpecializationExpr *concept_specialization) |
Find concept specializations relationships. | |
void | extract_constrained_template_param_name (const clang::ConceptSpecializationExpr *concept_specialization, const clang::ConceptDecl *cpt, std::vector< std::string > &constrained_template_params, size_t argument_index, std::string &type_name) const |
Extract template contraint parameter name from raw source code. | |
void | add_processed_template_class (std::string qualified_name) |
Register already processed template class name. | |
bool | has_processed_template_class (const std::string &qualified_name) const |
Check if template class has already been processed. | |
template_builder_t & | tbuilder () |
Get template builder reference. | |
Private Attributes | |
template_builder_t | template_builder_ |
std::map< eid_t, std::unique_ptr< clanguml::class_diagram::model::class_ > > | forward_declarations_ |
std::map< int64_t, std::tuple< std::string, common::model::relationship_t, common::model::access_t, std::optional< size_t > > > | anonymous_struct_relationships_ |
std::set< std::string > | processed_template_qualified_names_ |
Additional Inherited Members | |
Protected Member Functions inherited from clanguml::common::visitor::translation_unit_visitor< ConfigT, DiagramT > | |
std::set< const clang::RawComment * > & | processed_comments () |
using clanguml::common::visitor::translation_unit_visitor< ConfigT, DiagramT >::config_t = ConfigT |
Definition at line 56 of file translation_unit_visitor.h.
using clanguml::common::visitor::translation_unit_visitor< ConfigT, DiagramT >::diagram_t = DiagramT |
Definition at line 57 of file translation_unit_visitor.h.
using clanguml::class_diagram::visitor::translation_unit_visitor::template_builder_t = template_builder<translation_unit_visitor> |
Definition at line 75 of file translation_unit_visitor.h.
|
explicit |
Constructor.
sm | Current source manager reference |
diagram | Diagram model |
config | Diagram configuration |
Definition at line 29 of file translation_unit_visitor.cc.
void clanguml::class_diagram::visitor::translation_unit_visitor::add_class | ( | std::unique_ptr< class_ > && | c | ) |
Add class (or template class) to the diagram.
c | Class model |
Definition at line 2018 of file translation_unit_visitor.cc.
void clanguml::class_diagram::visitor::translation_unit_visitor::add_concept | ( | std::unique_ptr< concept_ > && | c | ) |
Add concept to the diagram.
c | Concept model |
Definition at line 2074 of file translation_unit_visitor.cc.
|
overridevirtual |
Reimplemented from clanguml::common::visitor::translation_unit_visitor< ConfigT, DiagramT >.
Definition at line 2012 of file translation_unit_visitor.cc.
void clanguml::class_diagram::visitor::translation_unit_visitor::add_enum | ( | std::unique_ptr< enum_ > && | e | ) |
Add enum to the diagram.
e | Enum model |
Definition at line 2046 of file translation_unit_visitor.cc.
|
private |
Register incomplete forward declaration to be updated later.
Definition at line 1906 of file translation_unit_visitor.cc.
|
private |
Register already processed template class name.
qualified_name | Fully qualified template class name |
Definition at line 2000 of file translation_unit_visitor.cc.
|
private |
Add relationships from relationship list to a class model.
This method takes a list of relationships whose originating element is class c
and adds them to it, ignoring any duplicates and skipping relationships that should be excluded from the diagram.
c | Class diagram element model |
field | Class member model |
relationships | List of found relationships |
break_on_first_aggregation | Stop adding relatinoships, after first aggregation is found |
Definition at line 1578 of file translation_unit_visitor.cc.
|
private |
Create class element model from class declaration.
cls | Class declaration |
Definition at line 826 of file translation_unit_visitor.cc.
|
private |
Create concept element model from concept declaration.
cpt | Concept declaration |
Definition at line 751 of file translation_unit_visitor.cc.
std::unique_ptr< class_ > clanguml::class_diagram::visitor::translation_unit_visitor::create_element | ( | const clang::NamedDecl * | decl | ) | const |
Definition at line 37 of file translation_unit_visitor.cc.
|
private |
Create class element model from record (e.g. struct) declaration.
rec | Record declaration |
Definition at line 780 of file translation_unit_visitor.cc.
|
private |
Extract template contraint parameter name from raw source code.
concept_specialization | Concept specialization expression |
cpt | Concept declaration |
constrained_template_params | Found constraint template param names |
argument_index | Argument index |
type_name | Type parameter name - used if extraction fails |
Definition at line 1973 of file translation_unit_visitor.cc.
void clanguml::class_diagram::visitor::translation_unit_visitor::finalize | ( | ) |
Finalize diagram model.
This method is called after the entire AST has been visited by this visitor. It is used to perform necessary post processing on the diagram (e.g. resolve translation unit local element ID's into global ID's based on elements full names).
Definition at line 1964 of file translation_unit_visitor.cc.
void clanguml::class_diagram::visitor::translation_unit_visitor::find_instantiation_relationships | ( | common::model::template_element & | template_instantiation_base, |
const std::string & | full_name, | ||
eid_t | templated_decl_id | ||
) |
Definition at line 2102 of file translation_unit_visitor.cc.
|
private |
Find relationships in a specific type.
type | Type to search for relationships |
relationship_hint | Default relationship type to infer from this type |
Definition at line 1339 of file translation_unit_visitor.cc.
|
private |
Find relationships in concept constraint expression.
c | Diagram element model (concept) |
expr | Concept constraint expression |
Definition at line 570 of file translation_unit_visitor.cc.
|
private |
Check if template class has already been processed.
qualified_name | Fully qualified template class name |
Definition at line 2006 of file translation_unit_visitor.cc.
|
private |
Process class declaration bases (parents), if any.
cls | Class declaration |
c | Class diagram element model |
Definition at line 955 of file translation_unit_visitor.cc.
|
private |
Process class children elements (members and methods)
cls | Class declaration |
c | Class diagram element model |
Definition at line 1012 of file translation_unit_visitor.cc.
|
private |
Process class declaration.
cls | Class declaration |
c | Class diagram element return from create_class_declaration |
Definition at line 943 of file translation_unit_visitor.cc.
|
private |
Find concept specializations relationships.
c | Concept element model |
concept_specialization | Concept specialization expression |
Definition at line 613 of file translation_unit_visitor.cc.
|
private |
Process concept constraint requirements.
cpt | Concept declaration |
expr | Requires expression |
concept_model | Concept diagram element model |
Definition at line 441 of file translation_unit_visitor.cc.
|
private |
Process class data member.
field_declaration | Data member declaration |
c | Class diagram element model |
Definition at line 1697 of file translation_unit_visitor.cc.
|
private |
Process class friend.
f | Friend declaration |
c | Class diagram element model |
Definition at line 1080 of file translation_unit_visitor.cc.
|
private |
Process function/method parameter.
param | Parameter declaration |
method | Class method model |
c | Class diagram element model |
template_parameter_names | Ignored |
Definition at line 1502 of file translation_unit_visitor.cc.
|
private |
Find relationships in function parameter.
c | Class diagram element model |
atsp | auto type |
Definition at line 1241 of file translation_unit_visitor.cc.
|
private |
Process class method.
mf | Method declaration |
c | Class diagram element model |
Definition at line 1102 of file translation_unit_visitor.cc.
|
private |
Process class method properties.
mf | Method declaration |
c | Class diagram element model |
method_name | Method name |
method | Method model |
Definition at line 1213 of file translation_unit_visitor.cc.
|
private |
Process class or record data members.
cls | Class declaration |
c | Class diagram element model |
Definition at line 1002 of file translation_unit_visitor.cc.
|
private |
Process record parent element (e.g. for nested classes)
This method handles nested classes or structs.
cls | Record declaration |
c | Class diagram element model |
ns | Package in the diagram to which the class c should belong |
Definition at line 861 of file translation_unit_visitor.cc.
|
private |
Process class static data member.
field_declaration | Static data member declaration |
c | Class diagram element model |
Definition at line 1620 of file translation_unit_visitor.cc.
|
private |
Process class template method.
mf | Method declaration |
c | Class diagram element model |
Definition at line 1292 of file translation_unit_visitor.cc.
|
private |
Process class template specialization/instantiation.
cls | Class template specialization declaration |
Definition at line 1656 of file translation_unit_visitor.cc.
|
private |
Process template specialization children (members and methods)
cls | Class template specialization declaration |
c | Class diagram element model |
|
private |
Replace any AST local ids in diagram elements with global ones.
Not all elements global ids can be set in relationships during traversal of the AST. In such cases, a local id (obtained from getID()
) and at after the traversal is complete, the id is replaced with the global diagram id.
Definition at line 1916 of file translation_unit_visitor.cc.
|
inlineprivate |
Get template builder reference.
Definition at line 432 of file translation_unit_visitor.h.
|
private |
Definition at line 443 of file translation_unit_visitor.h.
|
private |
Definition at line 437 of file translation_unit_visitor.h.
|
private |
When visiting CXX records we need to know if they have already been process in VisitClassTemplateDecl or VisitClassTemplateSpecializationDecl. If yes, then we need to skip it
Definition at line 452 of file translation_unit_visitor.h.
|
private |
Definition at line 434 of file translation_unit_visitor.h.