From 6c69202a60ee8ffa6f144c36e37c1dfe89ed6d22 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Fri, 17 Mar 2017 01:14:52 +0330 Subject: the source file --- safercpp/safercpp-arr.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 safercpp/safercpp-arr.cpp (limited to 'safercpp') diff --git a/safercpp/safercpp-arr.cpp b/safercpp/safercpp-arr.cpp new file mode 100644 index 0000000..f040144 --- /dev/null +++ b/safercpp/safercpp-arr.cpp @@ -0,0 +1,98 @@ + +/***************************************************Project Mutator****************************************************/ +//-*-c++-*- +/*first line intentionally left blank.*/ +/*the source code for SaferCPP's automatic refactoring of C/C++ arrays.*/ +/*Copyright (C) 2017 Noah L.,Farzad Sadeghi + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ +/*code structure inspired by Eli Bendersky's tutorial on Rewriters.*/ +/**********************************************************************************************************************/ +/**********************************************************************************************************************/ +/*included modules*/ +/*Project Headers*/ +#include "safercpp-arr.h" +#include "../mutator_aux.h" +/*Standard headers*/ +#include +#include +/*Clang Headers*/ +#include "clang/AST/AST.h" +#include "clang/AST/ASTConsumer.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendActions.h" +#include "clang/Lex/Lexer.h" +#include "clang/Tooling/CommonOptionsParser.h" +#include "clang/Tooling/Tooling.h" +#include "clang/Rewrite/Core/Rewriter.h" +/*LLVM Headers*/ +#include "llvm/Support/raw_ostream.h" +#include "llvm/IR/Function.h" +/**********************************************************************************************************************/ +/*used namespaces*/ +using namespace llvm; +using namespace clang; +using namespace clang::ast_matchers; +using namespace clang::driver; +using namespace clang::tooling; +/**********************************************************************************************************************/ +static llvm::cl::OptionCategory MatcherSampleCategory("TBD"); +/**********************************************************************************************************************/ +/**********************************************************************************************************************/ +class MyASTConsumer : public ASTConsumer { + +public: + MyASTConsumer(Rewriter &R) + { + } + + void HandleTranslationUnit(ASTContext &Context) override + { + Matcher.matchAST(Context); + } + +private: + MatchFinder Matcher; +}; +/**********************************************************************************************************************/ +class MyFrontendAction : public ASTFrontendAction +{ +public: + MyFrontendAction() {} + void EndSourceFileAction() override { + TheRewriter.getEditBuffer(TheRewriter.getSourceMgr().getMainFileID()).write(llvm::outs()); + } + + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef file) override { + TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); + return llvm::make_unique(TheRewriter); + } + +private: + Rewriter TheRewriter; +}; +/**********************************************************************************************************************/ +/*Main*/ +int main(int argc, const char **argv) +{ + CommonOptionsParser op(argc, argv, MatcherSampleCategory); + ClangTool Tool(op.getCompilations(), op.getSourcePathList()); + + return Tool.run(newFrontendActionFactory().get()); +} +/*last line intentionally left blank*/ + -- cgit v1.2.3