Esempio 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();
}
    void HandleTranslationUnit(clang::ASTContext &astContext) override {
        const auto &sourceManager = astContext.getSourceManager();
        const auto cursorSourceLocation = sourceManager.translateLineCol(sourceManager.getMainFileID(),
                                                                         line,
                                                                         column);

        if (cursorSourceLocation.isValid())
            collectUnifiedSymbolResoltions(astContext, cursorSourceLocation);
    }
Esempio n. 3
0
PPIncludeCallback::PPIncludeCallback(
  ParserContext& ctx_,
  clang::ASTContext& astContext_,
  MangledNameCache& mangledNameCache_,
  clang::Preprocessor&) :
    _ctx(ctx_),
    _cppSourceType("CPP"),
    _clangSrcMgr(astContext_.getSourceManager()),
    _fileLocUtil(astContext_.getSourceManager()),
    _mangledNameCache(mangledNameCache_)
{
}
Esempio n. 4
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();
}
Esempio n. 5
0
clang::Token GetTokenBeforeLocation(clang::SourceLocation loc,
                                    const clang::ASTContext& ast_context) {
    clang::Token token;
    token.setKind(clang::tok::unknown);
    clang::LangOptions lang_options = ast_context.getLangOpts();
    const clang::SourceManager& source_manager = ast_context.getSourceManager();
    clang::SourceLocation file_start_loc =
        source_manager.getLocForStartOfFile(source_manager.getFileID(loc));
    loc = loc.getLocWithOffset(-1);
    while (loc != file_start_loc) {
        loc = clang::Lexer::GetBeginningOfToken(loc, source_manager, lang_options);
        if (!clang::Lexer::getRawToken(loc, token, source_manager, lang_options)) {
            if (!token.is(clang::tok::comment)) {
                break;
            }
        }
        loc = loc.getLocWithOffset(-1);
    }
    return token;
}
Esempio n. 6
0
    RangeSet collect(clang::ASTContext &astContext, oclint::RuleBase *rule)
    {
        _rule = rule;
        _sourceManager = &astContext.getSourceManager();
        _range.clear();

        clang::DeclContext *decl = astContext.getTranslationUnitDecl();
        for (clang::DeclContext::decl_iterator declIt = decl->decls_begin(),
            declEnd = decl->decls_end(); declIt != declEnd; ++declIt)
        {
            clang::SourceLocation startLocation = (*declIt)->getLocStart();
            if (startLocation.isValid() &&
                _sourceManager->getMainFileID() == _sourceManager->getFileID(startLocation))
            {
                (void) /* explicitly ignore the return of this function */
                    clang::RecursiveASTVisitor<DeclAnnotationRangeCollector>::TraverseDecl(*declIt);
            }
        }

        return _range;
    }
Esempio n. 7
0
 virtual void Initialize(clang::ASTContext& Ctx) override {
     annotator.setSourceMgr(Ctx.getSourceManager(), Ctx.getLangOpts());
     annotator.setMangleContext(Ctx.createMangleContext());
     ci.getPreprocessor().addPPCallbacks(maybe_unique(new PreprocessorCallback(annotator, ci.getPreprocessor())));
     ci.getDiagnostics().setClient(new BrowserDiagnosticClient(annotator), true);
 }
Esempio n. 8
0
 void HandleTranslationUnit(clang::ASTContext& ctx) {
    MyASTVisitor visitor(ctx.getSourceManager(), _db);
    visitor.TraverseDecl(ctx.getTranslationUnitDecl());
 }
Esempio n. 9
0
void MyConsumer::HandleTranslationUnit(clang::ASTContext &Context) {
	visitor->manager = &Context.getSourceManager();
	visitor->TraverseDecl(Context.getTranslationUnitDecl());
	visitor->print_types();
}