diff options
author | bloodstalker <thabogre@gmail.com> | 2019-10-13 17:16:17 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2019-10-13 17:16:17 +0000 |
commit | 62a2cabd75bfa543d6c286e1905ca62e1bfcf8f4 (patch) | |
tree | ad7f072e05635bcc7ed92a1a2c80cb5f6f9008e0 | |
parent | added a contributors list (diff) | |
download | cgrep-62a2cabd75bfa543d6c286e1905ca62e1bfcf8f4.tar.gz cgrep-62a2cabd75bfa543d6c286e1905ca62e1bfcf8f4.zip |
added the awk option. need to check correction though. travis now checks for llvm 5,6,8,9 and 10. next up ill add llvm 7 support
-rw-r--r-- | .travis.yml | 172 | ||||
-rw-r--r-- | cgrep.cpp | 83 |
2 files changed, 144 insertions, 111 deletions
diff --git a/.travis.yml b/.travis.yml index 59c3ba0..a2d95f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,78 +1,94 @@ - -matrix: - fast_finish: true - include: - - dist: trusty - name: llvm5 - sudo: required - language: cpp - before_script: - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y - - sudo add-apt-repository ppa:fkrull/deadsnakes -y - - sudo apt-get update -y - - wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add - - - echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main" | sudo tee -a /etc/apt/sources.list - - sudo apt-get update -qq - - travis_retry sudo apt-get install clang-5.0 libclang-5.0-dev libclang-common-5.0-dev libllvm5.0 llvm-5.0-dev llvm-5.0 llvm-5.0-runtime -y - - sudo apt-get install gcc-4.9 g++-4.9 - - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9 - - git submodule init - - git submodule update - script: - - make CXX=clang-5.0 LLVM_CONF=llvm-config-5.0 - after_success: - bash run.sh - - dist: trusty - name: llvm6 - sudo: required - language: cpp - before_script: - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y - - sudo apt-get update -y - - wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add - - - echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main" | sudo tee -a /etc/apt/sources.list - - sudo apt-get update -qq - - travis_retry sudo apt-get install clang-6.0 libclang-6.0-dev libclang-common-6.0-dev libllvm6.0 llvm-6.0-dev llvm-6.0 llvm-6.0-runtime -y - - git submodule init - - git submodule update - script: - - make CXX=clang-6.0 LLVM_CONF=llvm-config-6.0 - after_success: - ./run.sh - - dist: bionic - name: llvm8 - sudo: required - language: cpp - before_script: - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y - - sudo apt-get update -y - - sudo apt-get install libstdc++-7-dev -y - - wget https://apt.llvm.org/llvm.sh - - chmod +x llvm.sh - - sudo ./llvm.sh 8 - - sudo apt-get install llvm-8-dev libclang-common-8-dev libclang-8-dev -y - - git submodule init - - git submodule update - script: - - make CXX=clang-8 LLVM_CONF=llvm-config-8 - after_success: - bash run.sh - allow_failures: - - dist: bionic - name: llvm9 - sudo: required - language: cpp - before_script: - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y - - sudo apt-get update -y - - sudo apt-get install libstdc++-7-dev -y - - wget https://apt.llvm.org/llvm.sh - - chmod +x llvm.sh - - sudo ./llvm.sh 9 - - sudo apt-get install llvm-9-dev libclang-common-9-dev libclang-9-dev -y - - git submodule init - - git submodule update - script: - - make CXX=clang-9 LLVM_CONF=llvm-config-9 - after_success: - bash run.sh +matrix:
+ fast_finish: true
+ include:
+ - dist: trusty
+ name: llvm5
+ sudo: required
+ language: cpp
+ before_script:
+ - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
+ - sudo add-apt-repository ppa:fkrull/deadsnakes -y
+ - sudo apt-get update -y
+ - wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add -
+ - echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main" | sudo tee -a /etc/apt/sources.list
+ - sudo apt-get update -qq
+ - travis_retry sudo apt-get install clang-5.0 libclang-5.0-dev libclang-common-5.0-dev libllvm5.0 llvm-5.0-dev llvm-5.0 llvm-5.0-runtime -y
+ - sudo apt-get install gcc-4.9 g++-4.9
+ - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9
+ - git submodule init
+ - git submodule update
+ script:
+ - make CXX=clang-5.0 LLVM_CONF=llvm-config-5.0
+ after_success:
+ bash run.sh
+ - dist: trusty
+ name: llvm6
+ sudo: required
+ language: cpp
+ before_script:
+ - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
+ - sudo apt-get update -y
+ - wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add -
+ - echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main" | sudo tee -a /etc/apt/sources.list
+ - sudo apt-get update -qq
+ - travis_retry sudo apt-get install clang-6.0 libclang-6.0-dev libclang-common-6.0-dev libllvm6.0 llvm-6.0-dev llvm-6.0 llvm-6.0-runtime -y
+ - git submodule init
+ - git submodule update
+ script:
+ - make CXX=clang-6.0 LLVM_CONF=llvm-config-6.0
+ after_success:
+ ./run.sh
+ - dist: bionic
+ name: llvm8
+ sudo: required
+ language: cpp
+ before_script:
+ - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
+ - sudo apt-get update -y
+ - sudo apt-get install libstdc++-7-dev -y
+ - wget https://apt.llvm.org/llvm.sh
+ - chmod +x llvm.sh
+ - sudo ./llvm.sh 8
+ - sudo apt-get install llvm-8-dev libclang-common-8-dev libclang-8-dev -y
+ - git submodule init
+ - git submodule update
+ script:
+ - make CXX=clang-8 LLVM_CONF=llvm-config-8
+ after_success:
+ bash run.sh
+ - dist: bionic
+ name: llvm9
+ sudo: required
+ language: cpp
+ before_script:
+ - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
+ - sudo apt-get update -y
+ - sudo apt-get install libstdc++-7-dev -y
+ - sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
+ - sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main"
+ - sudo apt-get update
+ - sudo apt-get install clang-9 llvm-9-dev libclang-common-9-dev libclang-9-dev -y
+ - git submodule init
+ - git submodule update
+ script:
+ - make CXX=clang-9 LLVM_CONF=llvm-config-9
+ after_success:
+ bash run.sh
+ - dist: bionic
+ name: llvm10
+ sudo: required
+ language: cpp
+ before_script:
+ - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
+ - sudo apt-get update -y
+ - sudo apt-get install libstdc++-7-dev -y
+ - wget https://apt.llvm.org/llvm.sh
+ - chmod +x llvm.sh
+ - sudo ./llvm.sh 10
+ - sudo apt-get install llvm-10-dev libclang-common-10-dev libclang-10-dev -y
+ - git submodule init
+ - git submodule update
+ script:
+ - make CXX=clang-10 LLVM_CONF=llvm-config-10
+ after_success:
+ bash run.sh
\ No newline at end of file @@ -147,30 +147,36 @@ void output_handler(const MatchFinder::MatchResult &MR, SourceRange SR, MR.SourceManager->getSpellingColumnNumber(SR.getBegin()) - 1; auto columnnumber_end = MR.SourceManager->getSpellingColumnNumber(SR.getEnd()) - 1; - std::cout << MAGENTA << SR.getBegin().printToString(SM) << ":" - << SR.getEnd().printToString(SM) << NORMAL << "\n"; - unsigned line_range_begin = linenumber - CO_B; - unsigned line_range_end = linenumber + CO_A; - std::string line; - unsigned line_nu = 0; - while (getline(mainfile, line)) { - line_nu++; - if (line_nu >= line_range_begin && line_nu <= line_range_end) { - if (line_nu == linenumber) { - std::cout << RED << MR.SourceManager->getFilename(SR.getBegin()).str() - << ":" << linenumber << ":" << columnnumber_start << ":" - << NORMAL; - for (unsigned i = 0; i < line.length(); ++i) { - if (i >= columnnumber_start && i <= columnnumber_end) { - std::cout << RED << line[i] << NORMAL; - } else { - std::cout << line[i]; + if (CO_AWK) { + std::cout << MAGENTA << SR.getBegin().printToString(SM) << ":" + << SR.getEnd().printToString(SM) << NORMAL << "\n"; + std::cout << RED << MR.SourceManager->getFilename(SR.getBegin()).str() + << ":" << linenumber << ":" << columnnumber_start + << NORMAL; + } else { + unsigned line_range_begin = linenumber - CO_B; + unsigned line_range_end = linenumber + CO_A; + std::string line; + unsigned line_nu = 0; + while (getline(mainfile, line)) { + line_nu++; + if (line_nu >= line_range_begin && line_nu <= line_range_end) { + if (line_nu == linenumber) { + std::cout << RED << MR.SourceManager->getFilename(SR.getBegin()).str() + << ":" << linenumber << ":" << columnnumber_start << ":" + << NORMAL; + for (unsigned i = 0; i < line.length(); ++i) { + if (i >= columnnumber_start && i <= columnnumber_end) { + std::cout << RED << line[i] << NORMAL; + } else { + std::cout << line[i]; + } } + if (isdecl) + std::cout << GREEN << "\t<---defined here" << NORMAL << "\n"; + } else { + std::cout << line << "\n"; } - if (isdecl) - std::cout << GREEN << "\t<---defined here" << NORMAL << "\n"; - } else { - std::cout << line << "\n"; } } } @@ -184,23 +190,23 @@ void output_handler(const MatchFinder::MatchResult &MR, SourceRange SR, * @param _path where the the base directory is. * @return Returns the list of all found dirs. */ -std::vector<std::string> listDirs(std::string _path) { - std::vector<std::string> 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) +std::vector<std::string> listDirs(std::string path) { + std::vector<std::string> 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) { - std::cout << ent_->d_name << "\n"; + if (ent->d_type == DT_DIR) { + std::cout << ent->d_name << "\n"; } - dummy_.push_back(ent_->d_name); + dummy.push_back(ent->d_name); } } else { perror("could not open directory."); } - return dummy_; + return dummy; } /*************************************************************************************************/ class FunctionHandler : public MatchFinder::MatchCallback { @@ -731,12 +737,23 @@ public: std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override { +#if __clang_major__ <= 9 CI.getPreprocessor().addPPCallbacks( llvm::make_unique<PPInclusion>(&CI.getSourceManager(), &TheRewriter)); +#endif +#if __clang_major__ >= 10 + CI.getPreprocessor().addPPCallbacks( + std::make_unique<PPInclusion>(&CI.getSourceManager(), &TheRewriter)); +#endif DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); +#if __clang_major__ <= 9 + return llvm::make_unique<MyASTConsumer>(TheRewriter); +#endif +#if __clang_major__ >= 10 return llvm::make_unique<MyASTConsumer>(TheRewriter); +#endif } private: |