MCPcopy Create free account
hub / github.com/andreasfertig/cppinsights / TemporaryDeclFinder

Method TemporaryDeclFinder

CodeGenerator.cpp:942–987  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

940
941public:
942 TemporaryDeclFinder(CodeGenerator& _codeGenerator, const Stmt* stmt, bool inspectReturn = false)
943 : codeGenerator{_codeGenerator}
944 , mPrevStmt{const_cast<Stmt*>(stmt)}
945 {
946 RETURN_IF(not GetInsightsOptions().ShowLifetime);
947
948 Visit(mPrevStmt);
949
950 for(auto d : mDecls) {
951 codeGenerator.InsertArg(d);
952 }
953
954 RETURN_IF(not GetInsightsOptions().UseShow2C or mFound or not inspectReturn);
955
956 if(auto* expr = dyn_cast_or_null<CXXConstructExpr>(stmt)) {
957 mTempName = GetTemporaryName(*expr);
958#if 0
959 auto* dummy = Function("dummy"sv, VoidTy(), {});
960
961 auto* vd = Variable(mTempName, expr->getType(), dummy->getDeclContext());
962 dummy->getDeclContext()->addDecl(vd);
963 vd->setInit(const_cast<CXXConstructExpr*>(expr));
964 vd->setStorageClass(SC_None);
965#else
966 // XXX hack. Our normal VarDecl is at TU level. It then appears in cxa_start...
967 auto& ctx = GetGlobalAST();
968 auto* vd = ImplicitParamDecl::Create(const_cast<ASTContext&>(ctx),
969 ctx.getTranslationUnitDecl(),
970 {},
971 &ctx.Idents.get(mTempName),
972 expr->getType(),
973 ImplicitParamKind::Other);
974
975#endif
976
977 mFound = true;
978 codeGenerator.InsertArg(vd);
979
980 } else if(auto* expr = dyn_cast_or_null<InitListExpr>(stmt)) {
981 mTempName = GetTemporaryName(*expr);
982 auto* vd = Variable(mTempName, expr->getType());
983 vd->setInit(const_cast<InitListExpr*>(expr));
984 mFound = true;
985 codeGenerator.InsertArg(vd);
986 }
987 }
988
989 ~TemporaryDeclFinder()
990 {

Callers

nothing calls this directly

Calls 6

GetTemporaryNameFunction · 0.85
FunctionFunction · 0.85
VoidTyFunction · 0.85
VariableFunction · 0.85
InsertArgMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected