@@ -421,74 +421,6 @@ void StringReplacements::replaceString() {
421421 ReplMap.clear ();
422422}
423423
424- void StringReplacements::adjustSourceStrAndTDRs () {
425- std::vector<size_t > Occurrences;
426- size_t Pos = 0 ;
427- while ((Pos = SourceStr.find (ConstExprExpansionInfoVDStr, Pos)) !=
428- std::string::npos) {
429- Occurrences.push_back (Pos);
430- Pos += ConstExprExpansionInfoVDStr.length ();
431- }
432-
433- int LengthDiff = ConstExprExpansionInfoVDInitStr.length () -
434- ConstExprExpansionInfoVDStr.length ();
435-
436- for (auto Occ : Occurrences) {
437- const auto &Iter = TDRs.find (Occ);
438- if (Iter != TDRs.end ()) {
439- TDRs.erase (Iter);
440- }
441- }
442- std::map<size_t , std::shared_ptr<TemplateDependentReplacement>> NewTDRs;
443- for (const auto &[Pos, Value] : TDRs) {
444- int NewPos = Pos;
445- for (auto Occ : Occurrences) {
446- if (Occ < static_cast <size_t >(Pos)) {
447- NewPos += LengthDiff;
448- } else {
449- break ;
450- }
451- }
452- auto NewValue = std::make_shared<TemplateDependentReplacement>(
453- SourceStr, NewPos, Value->getLength (), Value->getTemplateIndex ());
454- NewTDRs[NewPos] = NewValue;
455- }
456- TDRs = std::move (NewTDRs);
457-
458- std::map<size_t , std::shared_ptr<TemplateDependentReplacement>>
459- NewTDRsInConstExprExpansion;
460- for (const auto &[Pos, Value] : TDRsInConstExprExpansion) {
461- for (auto Occ : Occurrences) {
462- int NewPos = Occ + Pos;
463- for (auto PrevOcc : Occurrences) {
464- if (PrevOcc < static_cast <size_t >(Occ)) {
465- NewPos += LengthDiff;
466- } else {
467- break ;
468- }
469- }
470- auto NewValue = std::make_shared<TemplateDependentReplacement>(
471- SourceStr, NewPos, Value->getLength (), Value->getTemplateIndex ());
472- NewTDRsInConstExprExpansion[NewPos] = NewValue;
473- break ;
474- }
475- }
476- TDRsInConstExprExpansion = std::move (NewTDRsInConstExprExpansion);
477-
478- Pos = 0 ;
479- while ((Pos = SourceStr.find (ConstExprExpansionInfoVDStr, Pos)) !=
480- std::string::npos) {
481- SourceStr.replace (Pos, ConstExprExpansionInfoVDStr.length (),
482- ConstExprExpansionInfoVDInitStr);
483- Pos += ConstExprExpansionInfoVDInitStr.length ();
484- }
485-
486- TDRs.insert (TDRsInConstExprExpansion.begin (), TDRsInConstExprExpansion.end ());
487- for (const auto &[Pos, Value] : TDRs) {
488- Value->alterSource (SourceStr);
489- }
490- }
491-
492424ExprAnalysis::ExprAnalysis (const Expr *Expression)
493425 : Context(DpctGlobalInfo::getContext()),
494426 SM (DpctGlobalInfo::getSourceManager()) {
@@ -622,17 +554,13 @@ void ExprAnalysis::analyzeExpr(const DeclRefExpr *DRE) {
622554 if (auto TemplateDecl = dyn_cast<NonTypeTemplateParmDecl>(DRE ->getDecl ()))
623555 addReplacement (DRE , TemplateDecl->getIndex ());
624556 else if (const auto *VD = dyn_cast<VarDecl>(DRE ->getDecl ());
625- VD && VD ->isConstexpr ()) {
626- if (VD ->getInit () && VD ->getInit ()->getBeginLoc ().isValid () &&
627- !ConstExprExpansion) {
628- ConstExprExpansion = true ;
557+ VD && VD ->isConstexpr () &&
558+ IsAnalyzingCtTypeInfo /* && IsDependent*/ ) {
559+ if (VD ->getInit () && VD ->getInit ()->getBeginLoc ().isValid ()) {
629560 ExprAnalysis EA (VD ->getInit ());
630561 std::string VDInitStr = EA .getReplacedString ();
631562 std::string VDStr = VD ->getNameAsString ();
632- ReplSet.addConstExprExpansionInfo (VDStr, VDInitStr);
633- ReplSet.addTemplateDependentReplacementInConstExprExpansion (
634- EA .getReplSetTDRs ());
635- ConstExprExpansion = false ;
563+ addReplacement (0 , VDStr.size (), VDInitStr);
636564 }
637565 } else if (auto ECD = dyn_cast<EnumConstantDecl>(DRE ->getDecl ())) {
638566 std::unordered_set<std::string> targetStr = {
0 commit comments