<commit_before>
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Parse/ParseAST.h"
#include "clang/AST/Mangle.h"
#include "clang/Rewrite/Frontend/Rewriters.h"
#include "clang/Rewrite/Core/Rewriter.h"

#include "utilsllvm.h"
#include "fileutils.h"

#include <iostream>
#include <vector>
#include <string>

using namespace clang;
using namespace clang::ast_matchers;
using namespace clang::tooling;
using namespace llvm;

std::vector<std::string> excludedPathPatterns={"extlibs/", "/usr/include/qt4/", "framework/sofa/helper", "framework/sofa/defaulttype", "framework/sofa/core"};

bool isInExcludedPath(const std::string& path){
    for(auto pattern : excludedPathPatterns)
    {
        if( path.find(pattern) != std::string::npos )
        {
            return true ;
        }
    }
    return false ;
}

class StyleChecker : public RecursiveASTVisitor<StyleChecker> {
public:

    void setContext(const ASTContext* ctx){
        Context=ctx;
    }

    // http://clang.llvm.org/doxygen/classclang_1_1Stmt.html
    // For each declaration
    // http://clang.llvm.org/doxygen/classclang_1_1Decl.html
    // http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html
    // and
    // http://clang.llvm.org/doxygen/classclang_1_1RecursiveASTVisitor.html
    bool VisitCXXRecordDecl(CXXRecordDecl *record) {
        if(Context==NULL)
            return true ;

        FullSourceLoc FullLocation = Context->getFullLoc(record->getLocStart());
        // Check this declaration is not in the system headers...
        if ( FullLocation.isValid() && !exclude(FullLocation.getManager() , record) )
        {
            const SourceManager& smanager=Context->getSourceManager();

            // Now check the attributes...
            RecordDecl::field_iterator it=record->field_begin() ;
            for(;it!=record->field_end();it++){
                clang::FieldDecl* ff=*it;

                SourceRange declsr=ff->getMostRecentDecl()->getSourceRange() ;
                SourceLocation sl=declsr.getBegin();
                std::string name=ff->getName() ;

                if( smanager.getFileEntryForID(smanager.getFileID(sl)) == NULL ){
                    continue ;
                }

                if(isInExcludedPath(smanager.getFileEntryForID(smanager.getFileID(sl))->getName())){
                    continue ;
                }

                if(ff->getAccess()==AS_public){
                    continue ;
                }

                CXXRecordDecl* rd=ff->getType()->getAsCXXRecordDecl() ;
                if(rd){

                    std::string type=rd->getNameAsString() ;
                    if(type.find("Data")!=std::string::npos){
                        if(name.find("d_")==0){
                        }else{
                            std::cerr << smanager.getFileEntryForID(smanager.getFileID(sl))->getName()
                                      << ":" << smanager.getPresumedLineNumber(sl)
                                      << ":" << smanager.getPresumedColumnNumber(sl)
                                      << ": warning: variable [" << record->getNameAsString() << ":" <<name << "] is violating the sofa coding style http://www.sofa.../codingstyle.html...all Data attributes should start with d_ " << std::endl;
                        }
                    }
                    else if(type.find("SingleLink")!=std::string::npos || type.find("DualLink")!=std::string::npos){
                        if(name.find("d_")==0){
                        }else{
                            std::cerr << smanager.getFileEntryForID(smanager.getFileID(sl))->getName()
                                      << ":" << smanager.getPresumedLineNumber(sl)
                                      << ":" << smanager.getPresumedColumnNumber(sl)
                                      << ": warning: variable [" << record->getNameAsString() << ":" <<name << "] is violating the sofa coding style http://www.sofa.../codingstyle.html...all Link attributes should start with l_ " << std::endl;
                        }
                    }
                }else{
                    if(name.find("m_")==0){
                    }else{
                        std::cerr << smanager.getFileEntryForID(smanager.getFileID(sl))->getName()
                                  << ":" << smanager.getPresumedLineNumber(sl)
                                  << ":" << smanager.getPresumedColumnNumber(sl)
                                  << ": warning: variable [" << record->getNameAsString() << ":" << name << "] is violating the sofa coding style http://www.sofa.../codingstyle.html...all private attributes should start with m_ " << std::endl;<commit_msg>Minor change<commit_after>
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Parse/ParseAST.h"
#include "clang/AST/Mangle.h"
#include "clang/Rewrite/Frontend/Rewriters.h"
#include "clang/Rewrite/Core/Rewriter.h"

#include "utilsllvm.h"
#include "fileutils.h"

#include <iostream>
#include <vector>
#include <string>

using namespace clang;
using namespace clang::ast_matchers;
using namespace clang::tooling;
using namespace llvm;

std::vector<std::string> excludedPathPatterns={"extlibs/",
                                               "/usr/include/qt4/",
                                               "framework/sofa/helper",
                                               "framework/sofa/defaulttype",
                                               "framework/sofa/core",
                                               "simulation/common"};

bool isInExcludedPath(const std::string& path){
    for(auto pattern : excludedPathPatterns)
    {
        if( path.find(pattern) != std::string::npos )
        {
            return true ;
        }
    }
    return false ;
}

class StyleChecker : public RecursiveASTVisitor<StyleChecker> {
public:

    void setContext(const ASTContext* ctx){
        Context=ctx;
    }

    // http://clang.llvm.org/doxygen/classclang_1_1Stmt.html
    // For each declaration
    // http://clang.llvm.org/doxygen/classclang_1_1Decl.html
    // http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html
    // and
    // http://clang.llvm.org/doxygen/classclang_1_1RecursiveASTVisitor.html
    bool VisitCXXRecordDecl(CXXRecordDecl *record) {
        if(Context==NULL)
            return true ;

        FullSourceLoc FullLocation = Context->getFullLoc(record->getLocStart());
        // Check this declaration is not in the system headers...
        if ( FullLocation.isValid() && !exclude(FullLocation.getManager() , record) )
        {
            const SourceManager& smanager=Context->getSourceManager();

            // Now check the attributes...
            RecordDecl::field_iterator it=record->field_begin() ;
            for(;it!=record->field_end();it++){
                clang::FieldDecl* ff=*it;

                SourceRange declsr=ff->getMostRecentDecl()->getSourceRange() ;
                SourceLocation sl=declsr.getBegin();
                std::string name=ff->getName() ;

                if( smanager.getFileEntryForID(smanager.getFileID(sl)) == NULL ){
                    continue ;
                }

                if(isInExcludedPath(smanager.getFileEntryForID(smanager.getFileID(sl))->getName())){
                    continue ;
                }

                if(ff->getAccess()==AS_public){
                    continue ;
                }

                CXXRecordDecl* rd=ff->getType()->getAsCXXRecordDecl() ;
                if(rd){

                    std::string type=rd->getNameAsString() ;
                    if(type.find("Data")!=std::string::npos){
                        if(name.find("d_")==0){
                        }else{
                            std::cerr << smanager.getFileEntryForID(smanager.getFileID(sl))->getName()
                                      << ":" << smanager.getPresumedLineNumber(sl)
                                      << ":" << smanager.getPresumedColumnNumber(sl)
                                      << ": warning: variable [" << record->getNameAsString() << ":" <<name << "] is violating the sofa coding style http://www.sofa.../codingstyle.html...all Data<> attributes should start with d_ " << std::endl;
                        }
                    }
                    else if(type.find("SingleLink")!=std::string::npos || type.find("DualLink")!=std::string::npos){
                        if(name.find("d_")==0){
                        }else{
                            std::cerr << smanager.getFileEntryForID(smanager.getFileID(sl))->getName()
                                      << ":" << smanager.getPresumedLineNumber(sl)
                                      << ":" << smanager.getPresumedColumnNumber(sl)
                                      << ": warning: variable [" << record->getNameAsString() << ":" <<name << "] is violating the sofa coding style http://www.sofa.../codingstyle.html...all Link<> attributes should start with l_ " << std::endl;
                        }
                    }
                }else{
                    if(name.find("m_")==0){
                    }else{
                        std::cerr << smanager.getFileEntryForID(smanager.getFileID(sl))->getName()
                                  << ":" << smanager.getPresumedLineNumber(sl)
                                  << ":" << smanager.getPresumedColumnNumber(sl)
                                  << ": warning: variable [" << record->getNameAsString() << ":" << name << "] is violating the sofa coding style http://www.sofa.../codingstyle.html...all non public attributes should start with m_ " << std::endl;
{'fraction_non_alphanumeric': 0.13788611834759956, 'fraction_numerical': 0.002232973576479345, 'mean_word_length': 1.9514003294892917, 'pattern_counts': {'":': 24, '<': 147, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4991362', 'n_tokens_mistral': 3143, 'n_tokens_neox': 3001, 'n_words': 460}