This class is used to track current context of the call expressions. More...
This class is used to track current context of the call expressions.
When traversing AST for call expressions, we need to keep the state of the current context, for instance whether we are in a for
loop or an if
block, as well as the current parent of the call expression e.g. a class method or function.
Definition at line 41 of file call_expression_context.h.
#include <call_expression_context.h>
Public Types | |
using | callexpr_stack_t = std::variant< std::monostate, clang::CallExpr *, clang::CXXConstructExpr *, clang::ObjCMessageExpr * > |
Public Member Functions | |
call_expression_context () | |
void | reset () |
Reset call expression context to the original state. | |
bool | valid () const |
Verify that the context is in a valid state. | |
clang::ASTContext * | get_ast_context () const |
void | update (clang::CXXRecordDecl *cls) |
Set the current context to a class. | |
void | update (clang::ObjCInterfaceDecl *cls) |
void | update (clang::ObjCProtocolDecl *cls) |
void | update (clang::ClassTemplateSpecializationDecl *clst) |
Set the current context to a class template specialization. | |
void | update (clang::ClassTemplateDecl *clst) |
Set the current context to a class template. | |
void | update (clang::CXXMethodDecl *method) |
Set the current context to a class method. | |
void | update (clang::ObjCMethodDecl *method) |
void | update (clang::FunctionDecl *function) |
Set the current context to a function. | |
void | update (clang::FunctionTemplateDecl *function_template) |
Set the current context to a function template. | |
void | set_caller_id (eid_t id) |
Set current caller to id of the current participant. | |
eid_t | caller_id () const |
Get current caller id. | |
std::optional< eid_t > | lambda_caller_id () const |
Get the id of the current lambda caller. | |
void | enter_lambda_expression (eid_t id) |
Enter a lambda expression. | |
void | leave_lambda_expression () |
Leave current lambda expression. | |
clang::IfStmt * | current_ifstmt () const |
Get current if statement block. | |
void | enter_ifstmt (clang::IfStmt *stmt) |
Enter if statement block. | |
void | leave_ifstmt () |
Leave if statement block. | |
void | enter_elseifstmt (clang::IfStmt *stmt) |
Enter else if statement block. | |
clang::IfStmt * | current_elseifstmt () const |
Get current else if statement block. | |
clang::Stmt * | current_loopstmt () const |
Get current loop statement block. | |
void | enter_loopstmt (clang::Stmt *stmt) |
Enter loop statement block. | |
void | leave_loopstmt () |
Leave loop statement block. | |
clang::Stmt * | current_trystmt () const |
Get current try statement block. | |
void | enter_trystmt (clang::Stmt *stmt) |
Enter try statement block. | |
void | leave_trystmt () |
Leave try statement block. | |
clang::SwitchStmt * | current_switchstmt () const |
Get current switch statement block. | |
void | enter_switchstmt (clang::SwitchStmt *stmt) |
Enter switch statement block. | |
void | leave_switchstmt () |
Leave switch statement block. | |
clang::ConditionalOperator * | current_conditionaloperator () const |
Get current :? statement block. | |
void | enter_conditionaloperator (clang::ConditionalOperator *stmt) |
Enter :? statement block. | |
void | leave_conditionaloperator () |
Leave :? statement block. | |
callexpr_stack_t | current_callexpr () const |
Get current call expression. | |
void | enter_callexpr (clang::CallExpr *expr) |
Enter a call expression. | |
void | enter_callexpr (clang::CXXConstructExpr *expr) |
Enter a constructor call expression. | |
void | enter_callexpr (clang::ObjCMessageExpr *expr) |
void | leave_callexpr () |
Leave call expression. | |
bool | is_expr_in_current_control_statement_condition (const clang::Stmt *stmt) const |
Check, if a statement is contained in a control statement. | |
void | dump () |
Print the current call expression stack for debugging. | |
Public Attributes | |
clang::CXXRecordDecl * | current_class_decl_ {nullptr} |
clang::ClassTemplateDecl * | current_class_template_decl_ {nullptr} |
clang::ClassTemplateSpecializationDecl * | current_class_template_specialization_decl_ {nullptr} |
clang::CXXMethodDecl * | current_method_decl_ {nullptr} |
clang::ObjCMethodDecl * | current_objc_method_decl_ {nullptr} |
clang::FunctionDecl * | current_function_decl_ {nullptr} |
clang::FunctionTemplateDecl * | current_function_template_decl_ {nullptr} |
clang::ObjCInterfaceDecl * | objc_interface_decl_ {nullptr} |
clang::ObjCProtocolDecl * | objc_protocol_decl_ {nullptr} |
Private Attributes | |
eid_t | current_caller_id_ {} |
std::stack< eid_t > | current_lambda_caller_id_ |
std::stack< callexpr_stack_t > | call_expr_stack_ |
std::stack< clang::IfStmt * > | if_stmt_stack_ |
std::map< clang::IfStmt *, std::stack< clang::IfStmt * > > | elseif_stmt_stacks_ |
std::stack< clang::Stmt * > | loop_stmt_stack_ |
std::stack< clang::Stmt * > | try_stmt_stack_ |
std::stack< clang::SwitchStmt * > | switch_stmt_stack_ |
std::stack< clang::ConditionalOperator * > | conditional_operator_stack_ |
using clanguml::sequence_diagram::visitor::call_expression_context::callexpr_stack_t = std::variant<std::monostate, clang::CallExpr *, clang::CXXConstructExpr *, clang::ObjCMessageExpr *> |
In Clang, call to a class constructor is represented by clang::CXXConstructExpr
, which does inherit from clang::CallExpr
. So to enable to track calls to constructors, we need to be able to add to the call stack either type.
Definition at line 48 of file call_expression_context.h.
|
default |
eid_t clanguml::sequence_diagram::visitor::call_expression_context::caller_id | ( | ) | const |
Get current caller id.
Definition at line 169 of file call_expression_context.cc.
call_expression_context::callexpr_stack_t clanguml::sequence_diagram::visitor::call_expression_context::current_callexpr | ( | ) | const |
Get current call expression.
Definition at line 270 of file call_expression_context.cc.
clang::ConditionalOperator * clanguml::sequence_diagram::visitor::call_expression_context::current_conditionaloperator | ( | ) | const |
Get current :?
statement block.
:?
statement block. Definition at line 339 of file call_expression_context.cc.
clang::IfStmt * clanguml::sequence_diagram::visitor::call_expression_context::current_elseifstmt | ( | ) | const |
Get current else if
statement block.
if
statement block. Definition at line 239 of file call_expression_context.cc.
clang::IfStmt * clanguml::sequence_diagram::visitor::call_expression_context::current_ifstmt | ( | ) | const |
Get current if
statement block.
if
statement block. Definition at line 211 of file call_expression_context.cc.
clang::Stmt * clanguml::sequence_diagram::visitor::call_expression_context::current_loopstmt | ( | ) | const |
Get current loop statement block.
Definition at line 250 of file call_expression_context.cc.
clang::SwitchStmt * clanguml::sequence_diagram::visitor::call_expression_context::current_switchstmt | ( | ) | const |
Get current switch
statement block.
switch
statement block. Definition at line 319 of file call_expression_context.cc.
clang::Stmt * clanguml::sequence_diagram::visitor::call_expression_context::current_trystmt | ( | ) | const |
Get current try
statement block.
try
statement block. Definition at line 300 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::dump | ( | ) |
Print the current call expression stack for debugging.
Definition at line 38 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_callexpr | ( | clang::CallExpr * | expr | ) |
Enter a call expression.
expr | Call expression |
Definition at line 278 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_callexpr | ( | clang::CXXConstructExpr * | expr | ) |
Enter a constructor call expression.
expr | Constructor call expression |
Definition at line 283 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_callexpr | ( | clang::ObjCMessageExpr * | expr | ) |
Definition at line 288 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_conditionaloperator | ( | clang::ConditionalOperator * | stmt | ) |
Enter :?
statement block.
stmt | :? statement block |
Definition at line 347 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_elseifstmt | ( | clang::IfStmt * | stmt | ) |
Enter else if
statement block.
stmt | if statement block |
Definition at line 232 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_ifstmt | ( | clang::IfStmt * | stmt | ) |
Enter if
statement block.
stmt | if statement block |
Definition at line 219 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_lambda_expression | ( | eid_t | id | ) |
Enter a lambda expression.
id | Lambda id |
Definition at line 191 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_loopstmt | ( | clang::Stmt * | stmt | ) |
Enter loop statement block.
stmt | Loop statement block |
Definition at line 258 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_switchstmt | ( | clang::SwitchStmt * | stmt | ) |
Enter switch
statement block.
stmt | switch statement block |
Definition at line 327 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::enter_trystmt | ( | clang::Stmt * | stmt | ) |
Enter try
statement block.
stmt | try statement block |
Definition at line 308 of file call_expression_context.cc.
clang::ASTContext * clanguml::sequence_diagram::visitor::call_expression_context::get_ast_context | ( | ) | const |
Definition at line 69 of file call_expression_context.cc.
bool clanguml::sequence_diagram::visitor::call_expression_context::is_expr_in_current_control_statement_condition | ( | const clang::Stmt * | stmt | ) | const |
Check, if a statement is contained in a control statement.
This method is used to check if stmt
is contained in control statement of a block, for instance:
it will return true
for stmt
representing method1()
call expression.
stmt | Statement |
stmt
is contained in control expression of a statement block Definition at line 359 of file call_expression_context.cc.
std::optional< eid_t > clanguml::sequence_diagram::visitor::call_expression_context::lambda_caller_id | ( | ) | const |
Get the id of the current lambda caller.
Since lambdas can be nested within methods and functions, they have a separate caller id field.
Definition at line 177 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_callexpr | ( | ) |
Leave call expression.
Definition at line 293 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_conditionaloperator | ( | ) |
Leave :?
statement block.
Definition at line 353 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_ifstmt | ( | ) |
Leave if
statement block.
Definition at line 224 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_lambda_expression | ( | ) |
Leave current lambda expression.
Definition at line 200 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_loopstmt | ( | ) |
Leave loop statement block.
Definition at line 263 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_switchstmt | ( | ) |
Leave switch
statement block.
Definition at line 332 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_trystmt | ( | ) |
Leave try
statement block.
Definition at line 313 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::reset | ( | ) |
Reset call expression context to the original state.
Definition at line 25 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::set_caller_id | ( | eid_t | id | ) |
Set current caller to id of the current participant.
id | Set current caller id. |
Definition at line 185 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::update | ( | clang::ClassTemplateDecl * | clst | ) |
Set the current context to a class template.
clst | Class template declaration. |
Definition at line 127 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::update | ( | clang::ClassTemplateSpecializationDecl * | clst | ) |
Set the current context to a class template specialization.
clst | Class template specialization declaration. |
Definition at line 121 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::update | ( | clang::CXXMethodDecl * | method | ) |
Set the current context to a class method.
method | Class method declaration. |
Definition at line 132 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::update | ( | clang::CXXRecordDecl * | cls | ) |
Set the current context to a class.
cls | Class declaration. |
Definition at line 106 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::update | ( | clang::FunctionDecl * | function | ) |
Set the current context to a function.
function | Function declaration. |
Definition at line 142 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::update | ( | clang::FunctionTemplateDecl * | function_template | ) |
Set the current context to a function template.
function_template | Function template declaration. |
Definition at line 158 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::update | ( | clang::ObjCInterfaceDecl * | cls | ) |
Definition at line 111 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::update | ( | clang::ObjCMethodDecl * | method | ) |
Definition at line 137 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::update | ( | clang::ObjCProtocolDecl * | cls | ) |
Definition at line 116 of file call_expression_context.cc.
bool clanguml::sequence_diagram::visitor::call_expression_context::valid | ( | ) | const |
Verify that the context is in a valid state.
Context can only be in a single state (for instance inside a function).
Definition at line 56 of file call_expression_context.cc.
|
private |
Definition at line 330 of file call_expression_context.h.
|
private |
Definition at line 338 of file call_expression_context.h.
|
private |
Definition at line 327 of file call_expression_context.h.
clang::CXXRecordDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_class_decl_ {nullptr} |
Definition at line 315 of file call_expression_context.h.
clang::ClassTemplateDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_class_template_decl_ {nullptr} |
Definition at line 316 of file call_expression_context.h.
clang::ClassTemplateSpecializationDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_class_template_specialization_decl_ {nullptr} |
Definition at line 318 of file call_expression_context.h.
clang::FunctionDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_function_decl_ {nullptr} |
Definition at line 321 of file call_expression_context.h.
clang::FunctionTemplateDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_function_template_decl_ {nullptr} |
Definition at line 322 of file call_expression_context.h.
|
private |
Definition at line 328 of file call_expression_context.h.
clang::CXXMethodDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_method_decl_ {nullptr} |
Definition at line 319 of file call_expression_context.h.
clang::ObjCMethodDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_objc_method_decl_ {nullptr} |
Definition at line 320 of file call_expression_context.h.
|
private |
Definition at line 333 of file call_expression_context.h.
|
private |
Definition at line 332 of file call_expression_context.h.
|
private |
Definition at line 335 of file call_expression_context.h.
clang::ObjCInterfaceDecl* clanguml::sequence_diagram::visitor::call_expression_context::objc_interface_decl_ {nullptr} |
Definition at line 323 of file call_expression_context.h.
clang::ObjCProtocolDecl* clanguml::sequence_diagram::visitor::call_expression_context::objc_protocol_decl_ {nullptr} |
Definition at line 324 of file call_expression_context.h.
|
private |
Definition at line 337 of file call_expression_context.h.
|
private |
Definition at line 336 of file call_expression_context.h.