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 * > |
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::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::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 | 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::FunctionDecl * | current_function_decl_ {nullptr} |
clang::FunctionTemplateDecl * | current_function_template_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 *> |
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 133 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 234 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 298 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 203 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 175 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 214 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 278 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 259 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 36 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 242 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 247 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 306 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 196 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 183 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 155 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 222 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 286 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 267 of file call_expression_context.cc.
clang::ASTContext * clanguml::sequence_diagram::visitor::call_expression_context::get_ast_context | ( | ) | const |
Definition at line 60 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 318 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 141 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_callexpr | ( | ) |
Leave call expression.
Definition at line 252 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_conditionaloperator | ( | ) |
Leave :?
statement block.
Definition at line 312 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_ifstmt | ( | ) |
Leave if
statement block.
Definition at line 188 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_lambda_expression | ( | ) |
Leave current lambda expression.
Definition at line 164 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_loopstmt | ( | ) |
Leave loop statement block.
Definition at line 227 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_switchstmt | ( | ) |
Leave switch
statement block.
Definition at line 291 of file call_expression_context.cc.
void clanguml::sequence_diagram::visitor::call_expression_context::leave_trystmt | ( | ) |
Leave try
statement block.
Definition at line 272 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 149 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 96 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 90 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 101 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 85 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 106 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 122 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 50 of file call_expression_context.cc.
|
private |
Definition at line 323 of file call_expression_context.h.
|
private |
Definition at line 331 of file call_expression_context.h.
|
private |
Definition at line 320 of file call_expression_context.h.
clang::CXXRecordDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_class_decl_ {nullptr} |
Definition at line 311 of file call_expression_context.h.
clang::ClassTemplateDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_class_template_decl_ {nullptr} |
Definition at line 312 of file call_expression_context.h.
clang::ClassTemplateSpecializationDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_class_template_specialization_decl_ {nullptr} |
Definition at line 314 of file call_expression_context.h.
clang::FunctionDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_function_decl_ {nullptr} |
Definition at line 316 of file call_expression_context.h.
clang::FunctionTemplateDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_function_template_decl_ {nullptr} |
Definition at line 317 of file call_expression_context.h.
|
private |
Definition at line 321 of file call_expression_context.h.
clang::CXXMethodDecl* clanguml::sequence_diagram::visitor::call_expression_context::current_method_decl_ {nullptr} |
Definition at line 315 of file call_expression_context.h.
|
private |
Definition at line 326 of file call_expression_context.h.
|
private |
Definition at line 325 of file call_expression_context.h.
|
private |
Definition at line 328 of file call_expression_context.h.
|
private |
Definition at line 330 of file call_expression_context.h.
|
private |
Definition at line 329 of file call_expression_context.h.