MCPcopy Create free account
hub / github.com/Samsung/UTopia / isMacroArgUsedHashHashExpansion

Function isMacroArgUsedHashHashExpansion

lib/utils/ASTUtil.cpp:261–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259}
260
261bool isMacroArgUsedHashHashExpansion(const clang::Expr &E, clang::ASTUnit &U) {
262
263 auto &SrcManager = U.getASTContext().getSourceManager();
264 auto &Preproc = U.getPreprocessor();
265 auto *ExtSrc = Preproc.getExternalSource();
266 if (ExtSrc)
267 ExtSrc->ReadDefinedMacros();
268
269 if (!SrcManager.isMacroArgExpansion(E.getExprLoc()))
270 return false;
271 auto MacroName = Preproc.getImmediateMacroName(E.getExprLoc());
272
273 clang::MacroInfo *MI = nullptr;
274 for (auto &Macro : Preproc.macros(false)) {
275 auto *II = Macro.first;
276 if (!II)
277 continue;
278 if (II->getName() != MacroName)
279 continue;
280
281 auto *EMI = Preproc.getMacroInfo(II);
282 if (!EMI)
283 continue;
284 if (!EMI->isFunctionLike())
285 continue;
286
287 MI = EMI;
288 break;
289 }
290
291 if (!MI)
292 return false;
293
294 std::set<std::string> MacroParams;
295 for (auto *Param : MI->params())
296 MacroParams.insert(Param->getName().str());
297
298 auto Tokens = MI->tokens();
299 auto TokenSize = Tokens.size();
300 for (int I = 0; I < (int)TokenSize - 1; ++I) {
301 if (Tokens[I].isNot(clang::tok::hashhash))
302 continue;
303 if (Tokens[I + 1].isNot(clang::tok::identifier))
304 continue;
305
306 auto *II = Tokens[I + 1].getIdentifierInfo();
307 if (!II)
308 continue;
309 if (MacroParams.find(II->getName().str()) == MacroParams.end())
310 continue;
311
312 return true;
313 }
314
315 return false;
316}
317
318std::set<clang::FunctionDecl *>

Callers 2

isInvalidRDNodeMethod · 0.85
TEST_FFunction · 0.85

Calls 4

sizeMethod · 0.80
endMethod · 0.80
getNameMethod · 0.45
findMethod · 0.45

Tested by 1

TEST_FFunction · 0.68