================
@@ -133,6 +133,82 @@ const Expr *Expr::skipRValueSubobjectAdjustments(
return E;
}
+static StringLiteral *CloneStringLiteral(const StringLiteral *SL,
+ ASTContext &C) {
+ SourceLocation *SLocs = new (C) SourceLocation[SL->getNumConcatenated()];
+ std::copy(SL->tokloc_begin(), SL->tokloc_end(), SLocs);
+ return StringLiteral::Create(
+ C, SL->getBytes(), SL->getKind(), SL->isPascal(), SL->getType(),
+ ArrayRef<SourceLocation>(SLocs, SL->getNumConcatenated()));
+}
+
+// Exactly follow `IgnoreParensSingleStep` (`AST/IgnoreExpr.h`)
+// We only recursively visit those subexpressions which
`IgnoreParensSingleStep`
+// drills down to.
+Expr *Expr::CloneIfIAmAStringLiteral(ASTContext &C) {
+ if (auto *SL = dyn_cast<StringLiteral>(this)) {
+ return CloneStringLiteral(SL, C);
+ }
+
+ if (auto *PE = dyn_cast<ParenExpr>(this)) {
+ return new (C) ParenExpr(PE->getBeginLoc(), PE->getEndLoc(),
+ PE->getSubExpr()->CloneIfIAmAStringLiteral(C));
+ }
+
+ if (auto *UO = dyn_cast<UnaryOperator>(this)) {
+ if (UO->getOpcode() == UO_Extension) {
+ return UnaryOperator::Create(
+ C, UO->getSubExpr()->CloneIfIAmAStringLiteral(C), UO_Extension,
+ UO->getType(), UO->getValueKind(), UO->getObjectKind(),
+ UO->getBeginLoc(), UO->canOverflow(), UO->getFPOptionsOverride());
+ }
+ }
+
+ else if (auto *GSE = dyn_cast<GenericSelectionExpr>(this)) {
+ if (!GSE->isResultDependent()) {
+ ArrayRef<Expr *> GSEAEs = GSE->getAssocExprs();
+ Expr **NewGSEAEs = new (C) Expr *[GSEAEs.size()];
----------------
ojhunt wrote:
SmallVec?
https://github.com/llvm/llvm-project/pull/172995
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits