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

Function GetFieldDeclNameForLambda

CodeGenerator.cpp:597–619  ·  view source on GitHub ↗

Get the name of a \c FieldDecl in case this \c FieldDecl is part of a lambda. The name has to be retrieved from the capture fields or can be \c __this.

Source from the content-addressed store, hash-verified

595/// Get the name of a \c FieldDecl in case this \c FieldDecl is part of a lambda. The name has to be retrieved from the
596/// capture fields or can be \c __this.
597static std::optional<std::string> GetFieldDeclNameForLambda(const FieldDecl& fieldDecl,
598 const CXXRecordDecl& cxxRecordDecl)
599{
600 if(cxxRecordDecl.isLambda()) {
601 llvm::DenseMap<const ValueDecl*, FieldDecl*> captures{};
602
603 FieldDecl* thisCapture{};
604
605 cxxRecordDecl.getCaptureFields(captures, thisCapture);
606
607 if(&fieldDecl == thisCapture) {
608 return std::string{kwInternalThis};
609 } else {
610 for(const auto& [key, value] : captures) {
611 if(&fieldDecl == value) {
612 return GetName(*key);
613 }
614 }
615 }
616 }
617
618 return {};
619}
620//-----------------------------------------------------------------------------
621
622void CodeGenerator::InsertArg(const SourceLocExpr* stmt)

Callers 1

InsertArgMethod · 0.85

Calls 1

GetNameFunction · 0.85

Tested by

no test coverage detected