// // Created by erki on 02.03.21. // #ifndef C_ANALYZER_ASTHELPERS_HPP #define C_ANALYZER_ASTHELPERS_HPP #include template clang::StringRef getOpcode(const TOp *op) { return op->getOpcodeStr(op->getOpcode()); } inline clang::SourceLocation resolveOperationSourceLocation(const clang::SourceManager& source_manager, const clang::SourceLocation& original) { if (source_manager.isMacroBodyExpansion(original)) { return source_manager.getExpansionLoc(original); } return original; } inline std::tuple resolveLocationsWithLoc(const clang::SourceLocation& loc, const clang::SourceManager& source_manager) { const auto& loc_resolved = resolveOperationSourceLocation(source_manager, loc); return { source_manager.getFilename(loc_resolved).str(), source_manager.getSpellingLineNumber(loc_resolved), source_manager.getSpellingColumnNumber(loc_resolved) }; } template std::tuple resolveLocations(const TStmt* op, const clang::SourceManager& source_manager) { const auto& loc = resolveOperationSourceLocation(source_manager, op->getBeginLoc()); return { source_manager.getFilename(loc).str(), source_manager.getSpellingLineNumber(loc), source_manager.getSpellingColumnNumber(loc) }; } #endif //C_ANALYZER_ASTHELPERS_HPP