Exemplo n.º 1
0
bool lineBasedShouldSuppress(int beginLine, clang::ASTContext &context)
{
    std::string filePath = getMainFilePath(context);
    auto commentLinesIt = singleLineMapping.find(filePath);
    std::set<int> commentLines;
    if (commentLinesIt == singleLineMapping.end())
    {
        clang::RawCommentList commentList = context.getRawCommentList();
        clang::ArrayRef<clang::RawComment *> commentArray = commentList.getComments();

        for (auto comment : commentArray)
        {

            if (std::string::npos !=
                comment->getRawText(context.getSourceManager()).find("//!OCLINT"))
            {
                clang::SourceLocation startLocation = comment->getLocStart();
                int startLocationLine =
                    context.getSourceManager().getPresumedLineNumber(startLocation);
                commentLines.insert(startLocationLine);
            }
        }
        singleLineMapping[filePath] = commentLines;
    }
    else
    {
        commentLines = commentLinesIt->second;
    }

    return commentLines.find(beginLine) != commentLines.end();
}
Exemplo n.º 2
0
bool lineBasedShouldSuppress(int beginLine, clang::ASTContext &context)
{
    std::string filePath = getMainFilePath(context);
    auto commentLinesIt = singleLineMapping.find(filePath);
    std::set<int> commentLines;
    if (commentLinesIt == singleLineMapping.end())
    {
        clang::RawCommentList commentList = context.getRawCommentList();
        clang::ArrayRef<clang::RawComment *> commentArray = commentList.getComments();

        for (auto comment : commentArray)
        {
// g++ 4.8 on Ubuntu 14.04 LTS doesn't support regex yet,
// so we will ship this once Ubuntu 16.04 releases
#if defined(__APPLE__) || defined(__MACH__)
            std::string commentString = comment->getRawText(context.getSourceManager()).str();
            std::regex CAPARegex =
                std::regex("//! *CAPA", std::regex::basic | std::regex::icase);
            if (std::regex_search(commentString, CAPARegex))
#else
            if (std::string::npos !=
                comment->getRawText(context.getSourceManager()).find("//!CAPA"))
#endif
            {
                clang::SourceLocation startLocation = comment->getLocStart();
                int startLocationLine =
                    context.getSourceManager().getPresumedLineNumber(startLocation);
                commentLines.insert(startLocationLine);
            }
        }
        singleLineMapping[filePath] = commentLines;
    }
    else
    {
        commentLines = commentLinesIt->second;
    }

    return commentLines.find(beginLine) != commentLines.end();
}