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 74 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 | VisitTypedefDecl (clang::TypedefDecl *decl) |
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) |
virtual bool | VisitObjCCategoryDecl (clang::ObjCCategoryDecl *decl) |
virtual bool | VisitObjCProtocolDecl (clang::ObjCProtocolDecl *decl) |
virtual bool | VisitObjCInterfaceDecl (clang::ObjCInterfaceDecl *decl) |
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_objc_interface (std::unique_ptr< objc_interface > &&c) |
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::enum_ > | create_enum_declaration (const clang::EnumDecl *enm, const clang::TypedefDecl *typedef_decl) |
Create enum element model from enum (e.g. struct) 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::objc_interface > | create_objc_protocol_declaration (clang::ObjCProtocolDecl *decl) |
Create class element model from Objective-C protocol. | |
std::unique_ptr< clanguml::class_diagram::model::objc_interface > | create_objc_interface_declaration (clang::ObjCInterfaceDecl *decl) |
Create class element model from Objective-C interface. | |
std::unique_ptr< clanguml::class_diagram::model::objc_interface > | create_objc_category_declaration (clang::ObjCCategoryDecl *decl) |
Create class element model from Objective-C category. | |
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_objc_category_declaration (const clang::ObjCCategoryDecl &cls, objc_interface &c) |
Process Objective-C category declaration. | |
void | process_objc_protocol_declaration (const clang::ObjCProtocolDecl &cls, objc_interface &c) |
Process Objective-C protocol declaration. | |
void | process_objc_interface_declaration (const clang::ObjCInterfaceDecl &cls, objc_interface &c) |
Process Objective-C interface 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_objc_method (const clang::ObjCMethodDecl &mf, objc_interface &c) |
Process Objective-C 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_objc_ivar (const clang::ObjCIvarDecl &ivar, objc_interface &c) |
Process Objective-C data member. | |
void | process_objc_interface_base (const clang::ObjCInterfaceDecl &cls, objc_interface &c) |
Process Objective-C class base. | |
void | process_function_parameter (const clang::ParmVarDecl ¶m, class_method &method, class_ &c, const std::set< std::string > &template_parameter_names={}) |
Process function/method parameter. | |
void | process_objc_method_parameter (const clang::ParmVarDecl ¶m, objc_method &method, objc_interface &c) |
Process Objective-C class method parameter. | |
void | process_friend (const clang::FriendDecl &f, class_ &c) |
Process class friend. | |
bool | find_relationships (const clang::Decl *decl, const clang::QualType &type, found_relationships_t &, clanguml::common::model::relationship_t relationship_hint) |
Find relationships in a specific type. | |
void | add_relationships (diagram_element &c, const class_member_base &field, const found_relationships_t &relationships, bool break_on_first_aggregation=false) |
Add relationships from relationship list to a diagram element 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. | |
template<typename T > | |
void | process_record_parent_by_type (eid_t parent_id, class_ &c, namespace_ parent_ns, const clang::RecordDecl *decl) |
void | find_record_parent_id (const clang::TagDecl *decl, std::optional< eid_t > &parent_id_opt, namespace_ &parent_ns) const |
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::map< const clang::EnumDecl *, const clang::TypedefDecl * > | typedef_enum_decls_ |
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 () |
std::string | get_file_path (const std::string &file_location) const |
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 81 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 2554 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 2636 of file translation_unit_visitor.cc.
|
overridevirtual |
Reimplemented from clanguml::common::visitor::translation_unit_visitor< ConfigT, DiagramT >.
Definition at line 2548 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 2606 of file translation_unit_visitor.cc.
|
private |
Register incomplete forward declaration to be updated later.
Definition at line 2468 of file translation_unit_visitor.cc.
void clanguml::class_diagram::visitor::translation_unit_visitor::add_objc_interface | ( | std::unique_ptr< objc_interface > && | c | ) |
Definition at line 2584 of file translation_unit_visitor.cc.
|
private |
Register already processed template class name.
qualified_name | Fully qualified template class name |
Definition at line 2536 of file translation_unit_visitor.cc.
|
private |
Add relationships from relationship list to a diagram element 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 | 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 2083 of file translation_unit_visitor.cc.
|
private |
Create class element model from class declaration.
cls | Class declaration |
Definition at line 983 of file translation_unit_visitor.cc.
|
private |
Create concept element model from concept declaration.
cpt | Concept declaration |
Definition at line 908 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 enum element model from enum (e.g. struct) declaration.
rec | Enum declaration |
Definition at line 153 of file translation_unit_visitor.cc.
|
private |
Create class element model from Objective-C category.
decl | Objective-C protocol declaration |
Definition at line 1019 of file translation_unit_visitor.cc.
|
private |
Create class element model from Objective-C interface.
decl | Objective-C protocol declaration |
Definition at line 1077 of file translation_unit_visitor.cc.
|
private |
Create class element model from Objective-C protocol.
decl | Objective-C protocol declaration |
Definition at line 1049 of file translation_unit_visitor.cc.
|
private |
Create class element model from record (e.g. struct) declaration.
rec | Record declaration |
Definition at line 937 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 2509 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 2500 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 2666 of file translation_unit_visitor.cc.
|
private |
Definition at line 2422 of file translation_unit_visitor.cc.
|
private |
Find relationships in a specific type.
decl | Source declaration from which this relationship originates |
type | Type to search for relationships |
relationship_hint | Default relationship type to infer from this type |
Definition at line 1789 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 722 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 2542 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 1331 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 1381 of file translation_unit_visitor.cc.
|
private |
Process class declaration.
cls | Class declaration |
c | Class diagram element returned from create_class_declaration |
Definition at line 1121 of file translation_unit_visitor.cc.
|
private |
Find concept specializations relationships.
c | Concept element model |
concept_specialization | Concept specialization expression |
Definition at line 774 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 593 of file translation_unit_visitor.cc.
|
private |
Process class data member.
field_declaration | Data member declaration |
c | Class diagram element model |
Definition at line 2206 of file translation_unit_visitor.cc.
|
private |
Process class friend.
f | Friend declaration |
c | Class diagram element model |
Definition at line 1463 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 2001 of file translation_unit_visitor.cc.
|
private |
Find relationships in function parameter.
c | Class diagram element model |
atsp | auto type |
Definition at line 1691 of file translation_unit_visitor.cc.
|
private |
Process class method.
mf | Method declaration |
c | Class diagram element model |
Definition at line 1485 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 1663 of file translation_unit_visitor.cc.
|
private |
Process Objective-C category declaration.
cls | Objective-C category declaration |
c | Class diagram element returned from create_objc_category_declaration |
Definition at line 1133 of file translation_unit_visitor.cc.
|
private |
Process Objective-C class base.
cls | Objective-C interface declaration |
c | Class diagram element model |
Definition at line 1199 of file translation_unit_visitor.cc.
|
private |
Process Objective-C interface declaration.
cls | Objective-C interface declaration |
c | Class diagram element returned from create_objc_interface_declaration |
Definition at line 1177 of file translation_unit_visitor.cc.
|
private |
Process Objective-C data member.
field_declaration | Data member declaration |
c | Class diagram element model |
Definition at line 1224 of file translation_unit_visitor.cc.
|
private |
Process Objective-C method.
mf | Method declaration |
c | Class diagram element model |
Definition at line 1604 of file translation_unit_visitor.cc.
|
private |
Process Objective-C class method parameter.
param | Parameter declaration |
method | Class method model |
c | Class diagram element model |
template_parameter_names | Ignored |
Definition at line 1954 of file translation_unit_visitor.cc.
|
private |
Process Objective-C protocol declaration.
cls | Objective-C protocol declaration |
c | Class diagram element returned from create_objc_protocol_declaration |
Definition at line 1162 of file translation_unit_visitor.cc.
|
private |
Process class or record data members.
cls | Class declaration |
c | Class diagram element model |
Definition at line 1371 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 1103 of file translation_unit_visitor.cc.
|
private |
Definition at line 585 of file translation_unit_visitor.h.
|
private |
Process class static data member.
field_declaration | Static data member declaration |
c | Class diagram element model |
Definition at line 2127 of file translation_unit_visitor.cc.
|
private |
Process class template method.
mf | Method declaration |
c | Class diagram element model |
Definition at line 1742 of file translation_unit_visitor.cc.
|
private |
Process class template specialization/instantiation.
cls | Class template specialization declaration |
Definition at line 2165 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 2478 of file translation_unit_visitor.cc.
|
inlineprivate |
Get template builder reference.
Definition at line 551 of file translation_unit_visitor.h.
|
private |
Definition at line 569 of file translation_unit_visitor.h.
|
private |
Definition at line 563 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 581 of file translation_unit_visitor.h.
|
private |
Definition at line 560 of file translation_unit_visitor.h.
|
private |
Definition at line 572 of file translation_unit_visitor.h.