| 7 | using namespace ftg; |
| 8 | |
| 9 | void CalledFunctionMacroMapper::insertMacroNode(clang::Stmt &S, ASTUnit &U) { |
| 10 | |
| 11 | if (!isa<Expr>(S)) |
| 12 | return; |
| 13 | |
| 14 | auto &E = *dyn_cast<Expr>(&S); |
| 15 | if (!util::isCallRelatedExpr(E)) |
| 16 | return; |
| 17 | |
| 18 | auto *FuncDecl = util::getFunctionDecl(E); |
| 19 | if (!FuncDecl) |
| 20 | return; |
| 21 | |
| 22 | for (auto &MangledName : util::getMangledNames(*FuncDecl)) { |
| 23 | if (MangledName.empty()) |
| 24 | continue; |
| 25 | |
| 26 | auto BaseLoc = util::getDebugLoc(E); |
| 27 | auto Loc = LocIndex(U.getSourceManager(), BaseLoc); |
| 28 | auto Key = |
| 29 | DBKey(Loc.getPath(), Loc.getLine(), Loc.getColumn(), MangledName); |
| 30 | if (DupKey.find(Key) != DupKey.end()) |
| 31 | continue; |
| 32 | |
| 33 | auto CN = |
| 34 | std::make_unique<ASTNode>(ASTNode::CALL, DynTypedNode::create(E), U); |
| 35 | assert(CN && "Unexpected Program State"); |
| 36 | |
| 37 | auto CMInsert = CallMap.emplace(Key, std::move(CN)); |
| 38 | if (!CMInsert.second) { |
| 39 | auto &SrcManager = U.getSourceManager(); |
| 40 | |
| 41 | // if it is not macro arg expansion, then it is duplicates. |
| 42 | if (SrcManager.isMacroBodyExpansion(E.getExprLoc())) { |
| 43 | DupKey.insert(Key); |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | // NOTE: It is not duplicated key if it has same macro caller location if |
| 48 | // it is macro arg expansion |
| 49 | auto &PrevCN = CMInsert.first->second; |
| 50 | auto NewCN = |
| 51 | std::make_unique<ASTNode>(ASTNode::CALL, DynTypedNode::create(E), U); |
| 52 | assert((PrevCN && NewCN) && "Unexpected Program State"); |
| 53 | |
| 54 | auto PrevLoc = util::getTopMacroCallerLoc( |
| 55 | PrevCN->getNode(), PrevCN->getASTUnit().getSourceManager()); |
| 56 | auto NewLoc = util::getTopMacroCallerLoc( |
| 57 | NewCN->getNode(), NewCN->getASTUnit().getSourceManager()); |
| 58 | |
| 59 | auto PrevLI = LocIndex(PrevCN->getASTUnit().getSourceManager(), PrevLoc); |
| 60 | auto NewLI = LocIndex(NewCN->getASTUnit().getSourceManager(), NewLoc); |
| 61 | if (PrevLI != NewLI) |
| 62 | DupKey.insert(Key); |
| 63 | |
| 64 | continue; |
| 65 | } |
| 66 |
no test coverage detected