Exemple #1
0
bool markedParentsAsSuppress(const T &node, clang::ASTContext &context, oclint::RuleBase *rule)
{
    const auto &parents = context.getParents(node);
    if (parents.empty())
    {
        return false;
    }

    clang::ast_type_traits::DynTypedNode dynTypedNode = parents.front();
    const clang::Decl *aDecl = dynTypedNode.get<clang::Decl>();
    if (aDecl)
    {
        if (markedAsSuppress(aDecl, rule))
        {
            return true;
        }
        return markedParentsAsSuppress(*aDecl, context, rule);
    }
    const clang::Stmt *aStmt = dynTypedNode.get<clang::Stmt>();
    if (aStmt)
    {
        return markedParentsAsSuppress(*aStmt, context, rule);
    }

    return false;
}
 void applyDecl(T *decl)
 {
     unsigned numOfParams = decl->param_size();
     if (!markedAsSuppress(decl, this) && decl->hasBody()
         && numOfParams > _threshold)
     {
         string description = "Method with " + toString<int>(numOfParams) +
             " parameters exceeds limit of " + toString<int>(_threshold);
         addViolation(decl, this, description);
     }
 }
Exemple #3
0
    bool VisitDecl(clang::Decl *decl)
    {
        if (markedAsSuppress(decl, _rule))
        {
            clang::SourceLocation startLocation = decl->getLocStart();
            clang::SourceLocation endLocation = decl->getLocEnd();
            unsigned startLineNumber = _sourceManager->getPresumedLineNumber(startLocation);
            unsigned endLineNumber = _sourceManager->getPresumedLineNumber(endLocation);
            _range.insert(std::make_pair(startLineNumber, endLineNumber));
        }

        return true;
    }
    bool VisitParmVarDecl(ParmVarDecl *varDecl)
    {
        if (markedAsSuppress(varDecl, this))
        {
            return true;
        }

        if (!varDecl->isUsed() && hasVariableName(varDecl) && !isExistingByContract(varDecl))
        {
            addViolation(varDecl, this);
        }

        return true;
    }
    void applyDecl(Decl *decl)
    {
        if (markedAsSuppress(decl, this))
        {
            return;
        }

        int ccn = getCyclomaticComplexity(decl);

        // In McBABE, 1976, A Complexity Measure, he suggested a reasonable number of 10
        int threshold = RuleConfiguration::intForKey("CYCLOMATIC_COMPLEXITY", 10);
        if (ccn > threshold)
        {
            string description = "Cyclomatic Complexity Number " +
                toString<int>(ccn) + " exceeds limit of " + toString<int>(threshold);
            addViolation(decl, this, description);
        }
    }
Exemple #6
0
bool shouldSuppress(const clang::Decl *decl, clang::ASTContext &context, oclint::RuleBase *rule)
{
    return markedAsSuppress(decl, rule) || markedParentsAsSuppress(*decl, context, rule);
}