Mercurial > hg > CbC > CbC_llvm
comparison clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp @ 173:0572611fdcc8 llvm10 llvm12
reorgnization done
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 11:55:54 +0900 |
parents | 1d019706d866 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
172:9fbae9c8bf63 | 173:0572611fdcc8 |
---|---|
141 const clang::SourceManager &SM) { | 141 const clang::SourceManager &SM) { |
142 std::set<StringRef> Warned; | 142 std::set<StringRef> Warned; |
143 llvm::DenseMap<const FileEntry *, std::vector<tooling::Replacement>> | 143 llvm::DenseMap<const FileEntry *, std::vector<tooling::Replacement>> |
144 GroupedReplacements; | 144 GroupedReplacements; |
145 | 145 |
146 // Deduplicate identical replacements in diagnostics. | 146 // Deduplicate identical replacements in diagnostics unless they are from the |
147 // same TU. | |
147 // FIXME: Find an efficient way to deduplicate on diagnostics level. | 148 // FIXME: Find an efficient way to deduplicate on diagnostics level. |
148 llvm::DenseMap<const FileEntry *, std::set<tooling::Replacement>> | 149 llvm::DenseMap<const FileEntry *, |
150 std::map<tooling::Replacement, | |
151 const tooling::TranslationUnitDiagnostics *>> | |
149 DiagReplacements; | 152 DiagReplacements; |
150 | 153 |
151 auto AddToGroup = [&](const tooling::Replacement &R, bool FromDiag) { | 154 auto AddToGroup = [&](const tooling::Replacement &R, |
155 const tooling::TranslationUnitDiagnostics *SourceTU) { | |
152 // Use the file manager to deduplicate paths. FileEntries are | 156 // Use the file manager to deduplicate paths. FileEntries are |
153 // automatically canonicalized. | 157 // automatically canonicalized. |
154 if (auto Entry = SM.getFileManager().getFile(R.getFilePath())) { | 158 if (auto Entry = SM.getFileManager().getFile(R.getFilePath())) { |
155 if (FromDiag) { | 159 if (SourceTU) { |
156 auto &Replaces = DiagReplacements[*Entry]; | 160 auto &Replaces = DiagReplacements[*Entry]; |
157 if (!Replaces.insert(R).second) | 161 auto It = Replaces.find(R); |
162 if (It == Replaces.end()) | |
163 Replaces.emplace(R, SourceTU); | |
164 else if (It->second != SourceTU) | |
165 // This replacement is a duplicate of one suggested by another TU. | |
158 return; | 166 return; |
159 } | 167 } |
160 GroupedReplacements[*Entry].push_back(R); | 168 GroupedReplacements[*Entry].push_back(R); |
161 } else if (Warned.insert(R.getFilePath()).second) { | 169 } else if (Warned.insert(R.getFilePath()).second) { |
162 errs() << "Described file '" << R.getFilePath() | 170 errs() << "Described file '" << R.getFilePath() |
164 } | 172 } |
165 }; | 173 }; |
166 | 174 |
167 for (const auto &TU : TUs) | 175 for (const auto &TU : TUs) |
168 for (const tooling::Replacement &R : TU.Replacements) | 176 for (const tooling::Replacement &R : TU.Replacements) |
169 AddToGroup(R, false); | 177 AddToGroup(R, nullptr); |
170 | 178 |
171 for (const auto &TU : TUDs) | 179 for (const auto &TU : TUDs) |
172 for (const auto &D : TU.Diagnostics) | 180 for (const auto &D : TU.Diagnostics) |
173 if (const auto *ChoosenFix = tooling::selectFirstFix(D)) { | 181 if (const auto *ChoosenFix = tooling::selectFirstFix(D)) { |
174 for (const auto &Fix : *ChoosenFix) | 182 for (const auto &Fix : *ChoosenFix) |
175 for (const tooling::Replacement &R : Fix.second) | 183 for (const tooling::Replacement &R : Fix.second) |
176 AddToGroup(R, true); | 184 AddToGroup(R, &TU); |
177 } | 185 } |
178 | 186 |
179 // Sort replacements per file to keep consistent behavior when | 187 // Sort replacements per file to keep consistent behavior when |
180 // clang-apply-replacements run on differents machine. | 188 // clang-apply-replacements run on differents machine. |
181 for (auto &FileAndReplacements : GroupedReplacements) { | 189 for (auto &FileAndReplacements : GroupedReplacements) { |