MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / alias

Method alias

lib/checkunusedvar.cpp:190–230  ·  view source on GitHub ↗

* Alias the 2 given variables. Either replace the existing aliases if * they exist or merge them. You would replace an existing alias when this * assignment is in the same scope as the previous assignment. You might * merge the aliases when this assignment is in a different scope from the * previous assignment depending on the relationship of the 2 scopes. */

Source from the content-addressed store, hash-verified

188 * previous assignment depending on the relationship of the 2 scopes.
189 */
190void Variables::alias(nonneg int varid1, nonneg int varid2, bool replace)
191{
192 VariableUsage *var1 = find(varid1);
193 VariableUsage *var2 = find(varid2);
194
195 if (!var1 || !var2)
196 return;
197
198 // alias to self
199 if (varid1 == varid2) {
200 var1->use();
201 return;
202 }
203
204 if (replace) {
205 // remove var1 from all aliases
206 for (auto i = var1->_aliases.cbegin(); i != var1->_aliases.cend(); ++i) {
207 VariableUsage *temp = find(*i);
208
209 if (temp)
210 temp->_aliases.erase(var1->_var->declarationId());
211 }
212
213 // remove all aliases from var1
214 var1->_aliases.clear();
215 }
216
217 // var1 gets all var2s aliases
218 for (auto i = var2->_aliases.cbegin(); i != var2->_aliases.cend(); ++i) {
219 if (*i != varid1)
220 var1->_aliases.insert(*i);
221 }
222
223 // var2 is an alias of var1
224 var2->_aliases.insert(varid1);
225 var1->_aliases.insert(varid2);
226
227 if (var2->mType == Variables::pointer) {
228 var2->_read = true;
229 }
230}
231
232void Variables::clearAliases(nonneg int varid)
233{

Callers 1

doAssignmentFunction · 0.80

Calls 3

useMethod · 0.45
eraseMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected