Skip to content

Commit 565de60

Browse files
author
tobias.gruber
committed
Function to enclose in quotes if needed
1 parent b2b269f commit 565de60

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,13 @@ std::string MemRegion::getDescriptiveName(bool UseQuotes) const {
722722
SmallString<50> buf;
723723
llvm::raw_svector_ostream os(buf);
724724

725+
// Enclose subject with single quotes if needed.
726+
auto QuoteIfNeeded = [UseQuotes](const Twine &Subject) -> std::string {
727+
if (UseQuotes)
728+
return ("'" + Subject + "'").str();
729+
return Subject.str();
730+
};
731+
725732
// Obtain array indices to add them to the variable name.
726733
const ElementRegion *ER = nullptr;
727734
while ((ER = R->getAs<ElementRegion>())) {
@@ -755,22 +762,15 @@ std::string MemRegion::getDescriptiveName(bool UseQuotes) const {
755762
// MemRegion can be pretty printed.
756763
if (R->canPrintPrettyAsExpr()) {
757764
R->printPrettyAsExpr(os);
758-
if (UseQuotes)
759-
return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
760-
return (llvm::Twine(os.str()) + ArrayIndices).str();
765+
return QuoteIfNeeded(llvm::Twine(os.str()) + ArrayIndices);
761766
}
762767

763768
// FieldRegion may have ElementRegion as SuperRegion.
764-
if (const clang::ento::FieldRegion *FR =
765-
R->getAs<clang::ento::FieldRegion>()) {
769+
if (const auto *FR = R->getAs<clang::ento::FieldRegion>()) {
766770
std::string Super = FR->getSuperRegion()->getDescriptiveName(false);
767771
if (Super.empty())
768772
return "";
769-
770-
if (UseQuotes)
771-
return (llvm::Twine("'") + Super + "." + FR->getDecl()->getName() + "'")
772-
.str();
773-
return (llvm::Twine(Super) + "." + FR->getDecl()->getName()).str();
773+
return QuoteIfNeeded(Super + "." + FR->getDecl()->getName());
774774
}
775775
}
776776

0 commit comments

Comments
 (0)