Make sure sequence diagram messages generated during static variable initialization are rendered only once
This commit is contained in:
@@ -936,6 +936,8 @@ bool translation_unit_visitor::VisitCallExpr(clang::CallExpr *expr)
|
||||
|
||||
message m{message_t::kCall, context().caller_id()};
|
||||
|
||||
m.in_static_declaration_context(within_static_variable_declaration_ > 0);
|
||||
|
||||
set_source_location(*expr, m);
|
||||
|
||||
// If we're currently inside a lambda expression, set it's id as
|
||||
@@ -1031,6 +1033,27 @@ bool translation_unit_visitor::VisitCallExpr(clang::CallExpr *expr)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool translation_unit_visitor::TraverseVarDecl(clang::VarDecl *decl)
|
||||
{
|
||||
LOG_TRACE("Traversing cxx variable declaration at {} [caller_id = {}]",
|
||||
decl->getBeginLoc().printToString(source_manager()),
|
||||
context().caller_id());
|
||||
|
||||
decl->dump();
|
||||
|
||||
decl->getInit()->dump();
|
||||
|
||||
if (decl->isStaticLocal())
|
||||
within_static_variable_declaration_++;
|
||||
|
||||
RecursiveASTVisitor::TraverseVarDecl(decl);
|
||||
|
||||
if (decl->isStaticLocal())
|
||||
within_static_variable_declaration_--;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool translation_unit_visitor::VisitCXXConstructExpr(
|
||||
clang::CXXConstructExpr *expr)
|
||||
{
|
||||
@@ -1051,8 +1074,12 @@ bool translation_unit_visitor::VisitCXXConstructExpr(
|
||||
expr->getBeginLoc().printToString(source_manager()),
|
||||
context().caller_id());
|
||||
|
||||
expr->dump();
|
||||
|
||||
message m{message_t::kCall, context().caller_id()};
|
||||
|
||||
m.in_static_declaration_context(within_static_variable_declaration_ > 0);
|
||||
|
||||
set_source_location(*expr, m);
|
||||
|
||||
if (context().lambda_caller_id() != 0) {
|
||||
@@ -2427,6 +2454,7 @@ bool translation_unit_visitor::should_include(const clang::CallExpr *expr) const
|
||||
return false;
|
||||
|
||||
const auto expr_file = expr->getBeginLoc().printToString(source_manager());
|
||||
|
||||
return diagram().should_include(common::model::source_file{expr_file});
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ public:
|
||||
|
||||
bool TraverseCallExpr(clang::CallExpr *expr);
|
||||
|
||||
bool TraverseVarDecl(clang::VarDecl *VD);
|
||||
|
||||
bool TraverseCXXMemberCallExpr(clang::CXXMemberCallExpr *expr);
|
||||
|
||||
bool TraverseCXXOperatorCallExpr(clang::CXXOperatorCallExpr *expr);
|
||||
@@ -540,5 +542,9 @@ private:
|
||||
std::tuple<std::string /* field name */, common::model::relationship_t,
|
||||
common::model::access_t>>
|
||||
anonymous_struct_relationships_;
|
||||
|
||||
mutable unsigned within_static_variable_declaration_{0};
|
||||
mutable std::set<const clang::Expr *>
|
||||
already_visited_in_static_declaration_{};
|
||||
};
|
||||
} // namespace clanguml::sequence_diagram::visitor
|
||||
|
||||
Reference in New Issue
Block a user