Sequence diagram translation unit visitor. More...
Sequence diagram translation unit visitor.
This class implements the clang::RecursiveASTVisitor
interface for selected visitors relevant to generating sequence diagrams.
Definition at line 49 of file translation_unit_visitor.h.
#include <translation_unit_visitor.h>
Public Types | |
using | template_builder_t = common::visitor::template_builder< translation_unit_visitor > |
using | config_t = ConfigT |
using | diagram_t = DiagramT |
![]() | |
using | config_t = ConfigT |
using | diagram_t = DiagramT |
Public Member Functions | |
translation_unit_visitor (clang::SourceManager &sm, clanguml::sequence_diagram::model::diagram &diagram, const clanguml::config::sequence_diagram &config) | |
Constructor. | |
~translation_unit_visitor () override=default | |
bool | shouldVisitTemplateInstantiations () |
bool | VisitCallExpr (clang::CallExpr *expr) |
bool | VisitObjCMessageExpr (clang::ObjCMessageExpr *expr) |
bool | VisitObjCPropertyRefExpr (clang::ObjCPropertyRefExpr *expr) |
bool | TraverseVarDecl (clang::VarDecl *VD) |
bool | TraverseCallExpr (clang::CallExpr *expr) |
bool | TraverseObjCMessageExpr (clang::ObjCMessageExpr *expr) |
bool | TraverseCUDAKernelCallExpr (clang::CUDAKernelCallExpr *expr) |
bool | TraverseCXXMemberCallExpr (clang::CXXMemberCallExpr *expr) |
bool | TraverseCXXOperatorCallExpr (clang::CXXOperatorCallExpr *expr) |
bool | VisitCXXConstructExpr (clang::CXXConstructExpr *expr) |
bool | TraverseCXXConstructExpr (clang::CXXConstructExpr *expr) |
bool | TraverseCXXTemporaryObjectExpr (clang::CXXTemporaryObjectExpr *expr) |
bool | VisitLambdaExpr (clang::LambdaExpr *expr) |
bool | TraverseLambdaExpr (clang::LambdaExpr *expr) |
bool | TraverseCXXMethodDecl (clang::CXXMethodDecl *declaration) |
bool | TraverseObjCMethodDecl (clang::ObjCMethodDecl *declaration) |
bool | VisitObjCMethodDecl (clang::ObjCMethodDecl *declaration) |
bool | VisitCXXMethodDecl (clang::CXXMethodDecl *declaration) |
bool | VisitCXXRecordDecl (clang::CXXRecordDecl *declaration) |
bool | VisitClassTemplateDecl (clang::ClassTemplateDecl *declaration) |
bool | VisitClassTemplateSpecializationDecl (clang::ClassTemplateSpecializationDecl *declaration) |
bool | TraverseFunctionDecl (clang::FunctionDecl *declaration) |
bool | VisitFunctionDecl (clang::FunctionDecl *declaration) |
bool | TraverseFunctionTemplateDecl (clang::FunctionTemplateDecl *declaration) |
bool | VisitFunctionTemplateDecl (clang::FunctionTemplateDecl *function_declaration) |
bool | VisitObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_declaration) |
bool | VisitObjCProtocolDecl (clang::ObjCProtocolDecl *protocol_declaration) |
bool | TraverseCompoundStmt (clang::CompoundStmt *stmt) |
bool | TraverseIfStmt (clang::IfStmt *stmt) |
bool | TraverseWhileStmt (clang::WhileStmt *stmt) |
bool | TraverseDoStmt (clang::DoStmt *stmt) |
bool | TraverseForStmt (clang::ForStmt *stmt) |
bool | TraverseCXXForRangeStmt (clang::CXXForRangeStmt *stmt) |
bool | TraverseCXXTryStmt (clang::CXXTryStmt *stmt) |
bool | TraverseCXXCatchStmt (clang::CXXCatchStmt *stmt) |
bool | TraverseSwitchStmt (clang::SwitchStmt *stmt) |
bool | TraverseCaseStmt (clang::CaseStmt *stmt) |
bool | TraverseDefaultStmt (clang::DefaultStmt *stmt) |
bool | TraverseConditionalOperator (clang::ConditionalOperator *stmt) |
call_expression_context & | context () |
Get current call expression context reference. | |
const call_expression_context & | context () const |
Get current call expression context reference. | |
template<typename T = model::participant> | |
common::optional_ref< T > | get_participant (const clang::Decl *decl) |
Get participant by declaration. | |
template<typename T = model::participant> | |
common::optional_ref< T > | get_participant (const clang::Decl *decl) const |
Get participant by declaration. | |
template<typename T = model::participant> | |
common::optional_ref< T > | get_participant (const eid_t id) |
Get participant by global element id. | |
template<typename T = model::participant> | |
common::optional_ref< T > | get_participant (eid_t id) const |
Get participant by global element id. | |
void | set_unique_id (int64_t local_id, eid_t global_id) |
Store the mapping from local clang entity id (obtained using getID()) method to clang-uml global id. | |
std::optional< eid_t > | get_unique_id (eid_t local_id) const |
Retrieve the global clang-uml entity id based on the Clang local id. | |
void | finalize () |
Finalize diagram model for this translation unit. | |
std::unique_ptr< sequence_diagram::model::class_ > | create_element (const clang::NamedDecl *decl) const |
![]() | |
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 | |
bool | should_include (const clang::TagDecl *decl) const |
Check if the diagram should include a declaration. | |
bool | should_include (const clang::ObjCContainerDecl *decl) const |
Check if the diagram should include an ObjC declaration. | |
bool | should_include (const clang::LambdaExpr *expr) const |
Check if the diagram should include a lambda expression. | |
bool | should_include (const clang::CallExpr *expr) const |
Check if the diagram should include a call expression. | |
bool | should_include (const clang::ObjCMessageExpr *expr) const |
Check if the diagram should include an ObjC message expression. | |
bool | should_include (const clang::CXXMethodDecl *decl) const |
Check if the diagram should include a declaration. | |
bool | should_include (const clang::ObjCMethodDecl *decl) const |
bool | should_include (const clang::FunctionDecl *decl) const |
Check if the diagram should include a declaration. | |
bool | should_include (const clang::FunctionTemplateDecl *decl) const |
Check if the diagram should include a declaration. | |
bool | should_include (const clang::ClassTemplateDecl *decl) const |
Check if the diagram should include a declaration. | |
std::unique_ptr< clanguml::sequence_diagram::model::class_ > | create_objc_interface_model (clang::ObjCInterfaceDecl *cls) |
std::unique_ptr< clanguml::sequence_diagram::model::class_ > | create_objc_protocol_model (clang::ObjCProtocolDecl *cls) |
std::unique_ptr< clanguml::sequence_diagram::model::class_ > | create_class_model (clang::CXXRecordDecl *cls) |
std::unique_ptr< clanguml::sequence_diagram::model::method > | create_method_model (clang::CXXMethodDecl *cls) |
std::unique_ptr< clanguml::sequence_diagram::model::objc_method > | create_objc_method_model (clang::ObjCMethodDecl *cls) |
std::unique_ptr< clanguml::sequence_diagram::model::method > | create_lambda_method_model (clang::CXXMethodDecl *cls) |
std::unique_ptr< model::function_template > | build_function_template_instantiation (const clang::FunctionDecl &pDecl) |
std::unique_ptr< model::function > | build_function_model (const clang::FunctionDecl &declaration) |
std::unique_ptr< model::function_template > | build_function_template (const clang::FunctionTemplateDecl &declaration) |
std::unique_ptr< model::class_ > | process_class_template_specialization (clang::ClassTemplateSpecializationDecl *cls) |
std::string | simplify_system_template (const std::string &full_name) const |
std::string | make_lambda_name (const clang::CXXRecordDecl *cls) const |
Assuming cls is a lambda, create it's full name. | |
std::string | lambda_source_location (const clang::SourceLocation &source_location) const |
Render lambda source location to string. | |
bool | is_smart_pointer (const clang::TemplateDecl *primary_template) const |
Check if template is a smart pointer. | |
bool | is_callee_valid_template_specialization (const clang::CXXDependentScopeMemberExpr *dependent_member_expr) const |
Check, the callee is a template specialization. | |
bool | process_construct_expression (model::message &m, const clang::CXXConstructExpr *construct_expr) |
Handle CXX constructor call. | |
bool | process_operator_call_expression (model::message &m, const clang::CXXOperatorCallExpr *operator_call_expr) |
Handle a operator call expression. | |
bool | process_cuda_kernel_call_expression (model::message &m, const clang::CUDAKernelCallExpr *cuda_call_expr) |
bool | process_class_method_call_expression (model::message &m, const clang::CXXMemberCallExpr *method_call_expr) |
Handle a class method call expresion. | |
bool | process_objc_message_expression (model::message &m, const clang::ObjCMessageExpr *message_expr) |
bool | process_class_template_method_call_expression (model::message &m, const clang::CallExpr *expr) |
Handle a class template method call expresion. | |
bool | process_function_call_expression (model::message &m, const clang::CallExpr *expr) |
Handle a function call expresion. | |
bool | process_unresolved_lookup_call_expression (model::message &m, const clang::CallExpr *expr) const |
Handle an unresolved lookup call expresion. | |
bool | process_lambda_call_expression (model::message &m, const clang::CallExpr *expr) const |
void | push_message (clang::CallExpr *expr, model::message &&m) |
Register a message model m with a call expression. | |
void | push_message (clang::CXXConstructExpr *expr, model::message &&m) |
void | push_message (clang::ObjCMessageExpr *expr, model::message &&m) |
void | pop_message_to_diagram (clang::CallExpr *expr) |
Move a message model to diagram. | |
void | pop_message_to_diagram (clang::CXXConstructExpr *expr) |
void | pop_message_to_diagram (clang::ObjCMessageExpr *expr) |
std::optional< std::pair< unsigned int, std::string > > | get_expression_comment (const clang::SourceManager &sm, const clang::ASTContext &context, eid_t caller_id, const clang::Stmt *stmt) |
bool | generate_message_from_comment (model::message &m) const |
Initializes model message from comment call directive. | |
template_builder_t & | tbuilder () |
Get template builder reference. | |
void | resolve_ids_to_global () |
void | ensure_lambda_messages_have_operator_as_target () |
void | add_callers_to_activities () |
void | ensure_activity_exists (const model::message &m) |
Private Attributes | |
call_expression_context | call_expression_context_ |
std::map< clang::CallExpr *, std::deque< model::message > > | call_expr_message_map_ |
std::map< clang::CXXConstructExpr *, model::message > | construct_expr_message_map_ |
std::map< clang::ObjCMessageExpr *, model::message > | objc_message_map_ |
std::map< eid_t, std::unique_ptr< clanguml::sequence_diagram::model::class_ > > | forward_declarations_ |
std::map< int64_t, std::tuple< std::string, common::model::relationship_t, common::model::access_t > > | anonymous_struct_relationships_ |
std::map< eid_t, std::set< eid_t > > | activity_callers_ |
unsigned | within_static_variable_declaration_ {0} |
std::set< const clang::Expr * > | already_visited_in_static_declaration_ {} |
std::set< std::pair< int64_t, const clang::RawComment * > > | processed_comments_by_caller_id_ |
template_builder_t | template_builder_ |
Additional Inherited Members | |
![]() | |
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::sequence_diagram::visitor::translation_unit_visitor::template_builder_t = common::visitor::template_builder<translation_unit_visitor> |
Definition at line 56 of file translation_unit_visitor.h.
clanguml::sequence_diagram::visitor::translation_unit_visitor::translation_unit_visitor | ( | clang::SourceManager & | sm, |
clanguml::sequence_diagram::model::diagram & | diagram, | ||
const clanguml::config::sequence_diagram & | config | ||
) |
Constructor.
sm | Current source manager reference |
diagram | Diagram model |
config | Diagram configuration |
Definition at line 27 of file translation_unit_visitor.cc.
|
overridevirtualdefault |
Reimplemented from clanguml::common::visitor::translation_unit_visitor< ConfigT, DiagramT >.
|
private |
Definition at line 2492 of file translation_unit_visitor.cc.
|
private |
Definition at line 2207 of file translation_unit_visitor.cc.
|
private |
Definition at line 2159 of file translation_unit_visitor.cc.
|
private |
Definition at line 2185 of file translation_unit_visitor.cc.
call_expression_context & clanguml::sequence_diagram::visitor::translation_unit_visitor::context | ( | ) |
Get current call expression context reference.
Definition at line 48 of file translation_unit_visitor.cc.
const call_expression_context & clanguml::sequence_diagram::visitor::translation_unit_visitor::context | ( | ) | const |
Get current call expression context reference.
Definition at line 53 of file translation_unit_visitor.cc.
|
private |
Definition at line 2021 of file translation_unit_visitor.cc.
std::unique_ptr< sequence_diagram::model::class_ > clanguml::sequence_diagram::visitor::translation_unit_visitor::create_element | ( | const clang::NamedDecl * | decl | ) | const |
Definition at line 36 of file translation_unit_visitor.cc.
|
private |
Definition at line 2520 of file translation_unit_visitor.cc.
|
private |
Definition at line 2623 of file translation_unit_visitor.cc.
|
private |
Definition at line 1993 of file translation_unit_visitor.cc.
|
private |
Definition at line 2561 of file translation_unit_visitor.cc.
|
private |
Definition at line 1965 of file translation_unit_visitor.cc.
|
private |
Definition at line 1513 of file translation_unit_visitor.cc.
|
private |
Definition at line 2443 of file translation_unit_visitor.cc.
void clanguml::sequence_diagram::visitor::translation_unit_visitor::finalize | ( | ) |
Finalize diagram model for this translation unit.
Definition at line 2427 of file translation_unit_visitor.cc.
|
private |
Initializes model message from comment call directive.
m | Message instance |
Definition at line 1524 of file translation_unit_visitor.cc.
|
private |
Definition at line 2823 of file translation_unit_visitor.cc.
|
inline |
Get participant by declaration.
T | Participant type |
decl | Clang entity declaration |
Definition at line 182 of file translation_unit_visitor.h.
|
inline |
Get participant by declaration.
T | Participant type |
decl | Clang entity declaration |
Definition at line 201 of file translation_unit_visitor.h.
|
inline |
Get participant by global element id.
T | Participant type |
id | Global element id |
Definition at line 220 of file translation_unit_visitor.h.
|
inline |
Get participant by global element id.
T | Participant type |
id | Global element id |
Definition at line 237 of file translation_unit_visitor.h.
std::optional< eid_t > clanguml::sequence_diagram::visitor::translation_unit_visitor::get_unique_id | ( | eid_t | local_id | ) | const |
Retrieve the global clang-uml
entity id based on the Clang local id.
local_id | AST local element id |
Definition at line 2149 of file translation_unit_visitor.cc.
|
private |
Check, the callee is a template specialization.
dependent_member_expr | Dependent member expression |
Definition at line 1936 of file translation_unit_visitor.cc.
|
private |
Check if template is a smart pointer.
primary_template | Template declaration |
Definition at line 1954 of file translation_unit_visitor.cc.
|
private |
Render lambda source location to string.
Returns exact source code location of the lambda expression in the form <filepath>:<line>:<column>.
The filepath is relative to the relative_to
config option.
source_location | Clang SourceLocation instance associated with lambda expression |
Definition at line 2278 of file translation_unit_visitor.cc.
|
private |
Assuming cls
is a lambda, create it's full name.
cls | Lambda declaration |
Definition at line 2293 of file translation_unit_visitor.cc.
|
private |
Move a message model to diagram.
expr | Call expression |
Definition at line 2359 of file translation_unit_visitor.cc.
|
private |
Definition at line 2390 of file translation_unit_visitor.cc.
|
private |
Definition at line 2409 of file translation_unit_visitor.cc.
|
private |
Handle a class method call expresion.
m | Message model |
method_call_expr | Operator call expression |
m
contains now a valid call expression model Definition at line 1742 of file translation_unit_visitor.cc.
|
private |
Handle a class template method call expresion.
m | Message model |
expr | Class template method call expression |
m
contains now a valid call expression model Definition at line 1776 of file translation_unit_visitor.cc.
|
private |
Definition at line 2236 of file translation_unit_visitor.cc.
|
private |
Handle CXX constructor call.
m | Message model |
construct_expr | CXX Construct expression |
m
contains a valid constructor call Definition at line 1669 of file translation_unit_visitor.cc.
|
private |
Definition at line 1602 of file translation_unit_visitor.cc.
|
private |
Handle a function call expresion.
m | Message model |
expr | Function call expression |
m
contains now a valid call expression model Definition at line 1861 of file translation_unit_visitor.cc.
|
private |
Definition at line 1890 of file translation_unit_visitor.cc.
|
private |
Definition at line 1695 of file translation_unit_visitor.cc.
|
private |
Handle a operator call expression.
m | Message model |
operator_call_expr | Operator call expression |
m
contains now a valid call expression model Definition at line 1631 of file translation_unit_visitor.cc.
|
private |
Handle an unresolved lookup call expresion.
Unresolved lookup expression is a reference to a name which Clang was not able to look up during parsing but could not resolve to a specific declaration.
m | Message model |
expr | Call expression |
m
contains now a valid call expression model Definition at line 1905 of file translation_unit_visitor.cc.
|
private |
Register a message model m
with a call expression.
This is used to know whether a model for a specific call expression has already been created, but not yet added to the diagram.
expr | Call expresion |
m | Message model |
Definition at line 2341 of file translation_unit_visitor.cc.
|
private |
Definition at line 2347 of file translation_unit_visitor.cc.
|
private |
Definition at line 2353 of file translation_unit_visitor.cc.
|
private |
Definition at line 2463 of file translation_unit_visitor.cc.
void clanguml::sequence_diagram::visitor::translation_unit_visitor::set_unique_id | ( | int64_t | local_id, |
eid_t | global_id | ||
) |
Store the mapping from local clang entity id (obtained using getID()) method to clang-uml global id.
local_id | Local AST element id |
global_id | Globa diagram element id |
Definition at line 2140 of file translation_unit_visitor.cc.
|
private |
Check if the diagram should include a call expression.
expr | Call expression. |
Definition at line 2736 of file translation_unit_visitor.cc.
|
private |
Check if the diagram should include a declaration.
decl | Clang declaration. |
Definition at line 2816 of file translation_unit_visitor.cc.
|
private |
Check if the diagram should include a declaration.
decl | Clang declaration. |
Definition at line 2777 of file translation_unit_visitor.cc.
|
private |
Check if the diagram should include a declaration.
decl | Clang declaration. |
Definition at line 2804 of file translation_unit_visitor.cc.
|
private |
Check if the diagram should include a declaration.
decl | Clang declaration. |
Definition at line 2810 of file translation_unit_visitor.cc.
|
private |
Check if the diagram should include a lambda expression.
expr | Lambda expression. |
Definition at line 2700 of file translation_unit_visitor.cc.
|
private |
Check if the diagram should include an ObjC declaration.
decl | Clang declaration. |
Definition at line 2693 of file translation_unit_visitor.cc.
|
private |
Check if the diagram should include an ObjC message expression.
expr | ObjC message expression. |
Definition at line 2718 of file translation_unit_visitor.cc.
|
private |
Definition at line 2792 of file translation_unit_visitor.cc.
|
private |
Check if the diagram should include a declaration.
decl | Clang declaration. |
Definition at line 2687 of file translation_unit_visitor.cc.
|
private |
Definition at line 2272 of file translation_unit_visitor.cc.
|
inlineprivate |
Get template builder reference.
Definition at line 537 of file translation_unit_visitor.h.
|
private |
Definition at line 566 of file translation_unit_visitor.h.
|
mutableprivate |
Definition at line 570 of file translation_unit_visitor.h.
|
private |
Definition at line 564 of file translation_unit_visitor.h.
|
private |
This is used to generate messages in proper order in case of nested call expressions (e.g. a(b(c(), d())), as they need to be added to the diagram sequence after the visitor leaves the call expression AST node
Definition at line 553 of file translation_unit_visitor.h.
|
private |
Definition at line 545 of file translation_unit_visitor.h.
|
private |
Definition at line 555 of file translation_unit_visitor.h.
|
private |
Definition at line 559 of file translation_unit_visitor.h.
|
private |
Definition at line 556 of file translation_unit_visitor.h.
|
mutableprivate |
Definition at line 573 of file translation_unit_visitor.h.
|
private |
Definition at line 575 of file translation_unit_visitor.h.
|
mutableprivate |
Definition at line 568 of file translation_unit_visitor.h.