Added option to include if and loop condition text in the diagram (fixes #162)

This commit is contained in:
Bartek Kryza
2023-07-04 23:58:42 +02:00
parent a514532e51
commit 3bd8f7f7a8
20 changed files with 365 additions and 13 deletions

View File

@@ -307,15 +307,25 @@ bool call_expression_context::is_expr_in_current_control_statement_condition(
const clang::Stmt *stmt) const
{
if (current_ifstmt() != nullptr) {
if (common::is_subexpr_of(current_ifstmt()->getCond(), stmt)) {
if (common::is_subexpr_of(current_ifstmt()->getCond(), stmt))
return true;
if (const auto *condition_decl_stmt = current_ifstmt()->getInit();
condition_decl_stmt != nullptr) {
if (common::is_subexpr_of(condition_decl_stmt, stmt))
return true;
}
}
if (current_elseifstmt() != nullptr) {
if (common::is_subexpr_of(current_elseifstmt()->getCond(), stmt)) {
if (common::is_subexpr_of(current_elseifstmt()->getCond(), stmt))
return true;
}
if (current_conditionaloperator() != nullptr) {
if (common::is_subexpr_of(
current_conditionaloperator()->getCond(), stmt))
return true;
}
}
if (const auto *loop_stmt = current_loopstmt(); loop_stmt != nullptr) {

View File

@@ -584,6 +584,10 @@ bool translation_unit_visitor::TraverseIfStmt(clang::IfStmt *stmt)
const auto current_caller_id = context().caller_id();
const auto *current_ifstmt = context().current_ifstmt();
std::string condition_text;
if (config().generate_condition_statements())
condition_text = common::get_condition_text(source_manager(), stmt);
// Check if this is a beginning of a new if statement, or an
// else if condition of the current if statement
if (current_ifstmt != nullptr) {
@@ -601,6 +605,7 @@ bool translation_unit_visitor::TraverseIfStmt(clang::IfStmt *stmt)
message m{message_t::kElseIf, current_caller_id};
set_source_location(*stmt, m);
m.condition_text(condition_text);
diagram().add_block_message(std::move(m));
}
else {
@@ -608,6 +613,7 @@ bool translation_unit_visitor::TraverseIfStmt(clang::IfStmt *stmt)
message m{message_t::kIf, current_caller_id};
set_source_location(*stmt, m);
m.condition_text(condition_text);
diagram().add_block_message(std::move(m));
}
}
@@ -631,10 +637,15 @@ bool translation_unit_visitor::TraverseWhileStmt(clang::WhileStmt *stmt)
const auto current_caller_id = context().caller_id();
std::string condition_text;
if (config().generate_condition_statements())
condition_text = common::get_condition_text(source_manager(), stmt);
if (current_caller_id != 0) {
context().enter_loopstmt(stmt);
message m{message_t::kWhile, current_caller_id};
set_source_location(*stmt, m);
m.condition_text(condition_text);
diagram().add_block_message(std::move(m));
}
RecursiveASTVisitor<translation_unit_visitor>::TraverseWhileStmt(stmt);
@@ -656,10 +667,15 @@ bool translation_unit_visitor::TraverseDoStmt(clang::DoStmt *stmt)
const auto current_caller_id = context().caller_id();
std::string condition_text;
if (config().generate_condition_statements())
condition_text = common::get_condition_text(source_manager(), stmt);
if (current_caller_id != 0) {
context().enter_loopstmt(stmt);
message m{message_t::kDo, current_caller_id};
set_source_location(*stmt, m);
m.condition_text(condition_text);
diagram().add_block_message(std::move(m));
}
@@ -682,10 +698,15 @@ bool translation_unit_visitor::TraverseForStmt(clang::ForStmt *stmt)
const auto current_caller_id = context().caller_id();
std::string condition_text;
if (config().generate_condition_statements())
condition_text = common::get_condition_text(source_manager(), stmt);
if (current_caller_id != 0) {
context().enter_loopstmt(stmt);
message m{message_t::kFor, current_caller_id};
set_source_location(*stmt, m);
m.condition_text(condition_text);
diagram().add_block_message(std::move(m));
}
@@ -761,10 +782,15 @@ bool translation_unit_visitor::TraverseCXXForRangeStmt(
const auto current_caller_id = context().caller_id();
std::string condition_text;
if (config().generate_condition_statements())
condition_text = common::get_condition_text(source_manager(), stmt);
if (current_caller_id != 0) {
context().enter_loopstmt(stmt);
message m{message_t::kFor, current_caller_id};
set_source_location(*stmt, m);
m.condition_text(condition_text);
diagram().add_block_message(std::move(m));
}
@@ -847,10 +873,15 @@ bool translation_unit_visitor::TraverseConditionalOperator(
const auto current_caller_id = context().caller_id();
std::string condition_text;
if (config().generate_condition_statements())
condition_text = common::get_condition_text(source_manager(), stmt);
if (current_caller_id != 0) {
context().enter_conditionaloperator(stmt);
model::message m{message_t::kConditional, current_caller_id};
set_source_location(*stmt, m);
m.condition_text(condition_text);
diagram().add_block_message(std::move(m));
}