20 using namespace asthelpers;
30 {.funcStart = funcStart ? LifetimeEntry::FuncStart::Yes : LifetimeEntry::FuncStart::No, .scope = scopeCounter});
37 if(
auto it = std::ranges::find_if(objects, [&](
const auto& e) {
return e.item == extending; });
38 it != objects.end()) {
39 const auto scope = (*it).scope;
40 objects.insert(std::next(it), {decl, LifetimeEntry::FuncStart::No, scope});
49 QualType type{decl->getType()};
51 RETURN_IF(type->isPointerType() or type->isRValueReferenceType());
55 RETURN_IF(std::ranges::find_if(objects, [&](
const auto& e) {
return e.item == decl; }) != objects.end());
57 objects.push_back({decl, LifetimeEntry::FuncStart::No, scopeCounter});
63 QualType type{vd->getType()};
65 if(
const auto* ar = dyn_cast_or_null<ConstantArrayType>(type)) {
66 type = ar->getElementType();
69 if(type->isLValueReferenceType()) {
70 type = type.getNonReferenceType();
73 if(
const auto& ctx =
GetGlobalAST(); QualType::DK_cxx_destructor != vd->needsDestruction(ctx)) {
74 CodeGeneratorVariant cg{ofm};
80 auto* dtorDecl = type->getAsCXXRecordDecl()->getDestructor();
82 CodeGeneratorVariant cg{ofm};
84 auto insertDtor = [&](Expr* member) {
85 auto* mem =
AccessMember(member, dtorDecl, vd->getType()->isPointerType());
90 if(
const auto* ar = dyn_cast_or_null<ConstantArrayType>(vd->getType()); ar and not
GetInsightsOptions().UseShow2C) {
109 for(
OnceTrue needsSemi{};
auto& e : llvm::reverse(objects)) {
110 if(LifetimeEntry::FuncStart::Yes == e.funcStart) {
114 if(
nullptr == e.item) {
123 InsertDtorCall(e.item, ofm);
135 auto it = std::ranges::remove_if(objects, [&](
const LifetimeEntry& e) {
return (e.
scope == scopeCounter); });
136 objects.erase(it.begin(), it.end());
148 if(not coveredByReturn) {
149 for(
auto& e : llvm::reverse(objects)) {
150 if(e.scope != scopeCounter) {
154 if(
nullptr == e.item) {
158 InsertDtorCall(e.item, ofm);
const ASTContext & GetGlobalAST()
Get access to the ASTContext.
const InsightsOptions & GetInsightsOptions()
Get the global C++ Insights options.
#define RETURN_IF(cond)
! A helper inspired by https://github.com/Microsoft/wil/wiki/Error-handling-helpers
#define RETURN_FALSE_IF(cond)
A special container which creates either a CodeGenerator or a CfrontCodeGenerator depending on the co...
bool EndScope(OutputFormatHelper &ofm, bool clear)
void Add(const VarDecl *decl)
bool Return(OutputFormatHelper &ofm)
void AddExtended(const VarDecl *decl, const ValueDecl *extending)
void StartScope(bool funcStart)
MemberExpr * AccessMember(const Expr *expr, const ValueDecl *vd, bool isArrow)
ArraySubscriptExpr * ArraySubscript(const Expr *lhs, uint64_t index, QualType type)
Stmt * Comment(std::string_view comment)
ImplicitCastExpr * CastLToRValue(const VarDecl *vd)
CXXMemberCallExpr * CallMemberFun(Expr *memExpr, QualType retType)
uint64_t GetSize(const ConstantArrayType *arrayType)
std::string GetName(const NamedDecl &nd, const QualifiedName qualifiedName)
std::string StrCat(const auto &... args)