From 86b858fee4298d60bc8828ad182e9703760b7c64 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 12 Nov 2018 04:12:27 +0330 Subject: update --- README.md | 1 - cgrep.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2dbd847..63fec2c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ git submodule init git submodule update make ``` - ## Usage A simple usage example:
```bash diff --git a/cgrep.cpp b/cgrep.cpp index 410f5d8..a4855be 100644 --- a/cgrep.cpp +++ b/cgrep.cpp @@ -50,7 +50,7 @@ cl::opt CO_MEMVAR("memvar", cl::desc("match member variables only"), cl::i cl::opt CO_CLASS("class", cl::desc("match class declrations only"), cl::init(false), cl::cat(CGrepCat), cl::Optional); //done cl::opt CO_STRUCT("struct", cl::desc("match structures only"), cl::init(false), cl::cat(CGrepCat), cl::Optional); // done cl::opt CO_UNION("union", cl::desc("match unions only"), cl::init(false), cl::cat(CGrepCat), cl::Optional); // done -cl::opt CO_MACRO("macro", cl::desc("match macro definitions"), cl::init(false), cl::cat(CGrepCat), cl::Optional); +cl::opt CO_MACRO("macro", cl::desc("match macro definitions"), cl::init(false), cl::cat(CGrepCat), cl::Optional); //done cl::opt CO_HEADER("header", cl::desc("match headers in header inclusions"), cl::init(false), cl::cat(CGrepCat), cl::Optional); cl::opt CO_ALL("all", cl::desc("turns on all switches other than nameddecl"), cl::init(false), cl::cat(CGrepCat), cl::Optional); // done cl::opt CO_NAMEDDECL("nameddecl", cl::desc("matches all named declrations"), cl::init(false), cl::cat(CGrepCat), cl::Optional); // done @@ -89,6 +89,28 @@ std::string output_handler(SourceLocation SL, SourceManager &SM) { std::string output_handler(SourceRange SR, SourceManager &SM) { return SR.getBegin().printToString(SM); } + +/** + * @brief Gets the list of all directories and sub-directories starting from a base directory. + * @param _path where the the base directory is. + * @return Returns the list of all found dirs. + */ +std::vector listDirs(std::string _path) { + std::vector dummy_; + DIR* dir_; + struct dirent* ent_; + if ((dir_ = opendir(_path.c_str())) != nullptr) { + while((ent_ = readdir(dir_)) != nullptr) { + std::cout << "name: " << ent_->d_name << "\ttype:" << int(ent_->d_type) << "\n"; + if (ent_->d_type == DT_DIR) {} + dummy_.push_back(ent_->d_name); + } + } + else { + perror("could not open directory."); + } + return dummy_; +} /*************************************************************************************************/ class FunctionHandler : public MatchFinder::MatchCallback { public: @@ -304,7 +326,20 @@ public: : SM(*SM), Rewrite(*Rewrite) {} virtual void MacroDefined(const Token &MacroNameTok, - const MacroDirective *MD) {} + const MacroDirective *MD) { + if (CO_MACRO) { + SourceLocation SL = MD->getLocation(); + CheckSLValidity(SL); + SL = Devi::SourceLocationHasMacro(SL, Rewrite, "start"); + if (Devi::IsTheMatchInSysHeader(CO_SYSHDR, SM, SL)) return void(); + if (!Devi::IsTheMatchInMainFile(CO_MAINFILE, SM, SL)) return void(); + std::string name = MacroNameTok.getIdentifierInfo()->getName().str(); + if (regex_handler(REGEX_PP(CO_REGEX), name)) { + std::cout << name << "\t"; + std::cout << SL.printToString(SM) << "\n"; + } + } + } virtual void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, @@ -326,6 +361,7 @@ public: const clang::Module *Imported, SrcMgr::CharacteristicKind FileType) { #endif + if (CO_HEADER) {} } private: -- cgit v1.2.3