Esempio n. 1
0
/* Both FieldDecl and VarDecl derive from DeclaratorDecl.  We can do
   common things to both node types in this function */
bool FieldVisitor::VisitDeclaratorDecl( clang::DeclaratorDecl *dd ) {

    fdes->setFileName(getFileName(ci , dd->getLocation(), hsd)) ;
    fdes->setName(dd->getNameAsString()) ;
    fdes->setAccess(dd->getAccess()) ;

    /* Get the source location of this field. */
    clang::SourceRange dd_range = dd->getSourceRange() ;
    std::string file_name = ci.getSourceManager().getBufferName(dd_range.getEnd()) ;
    char * resolved_path = almostRealPath( file_name.c_str() ) ;
    if ( resolved_path ) {
        if ( isInUserOrTrickCode( ci , dd_range.getEnd() , hsd ) ) {
            fdes->setLineNo(ci.getSourceManager().getSpellingLineNumber(dd_range.getEnd())) ;
            /* process comment if neither ICG:(No) or ICG:(NoComment) is present */
            if (  cs.hasTrickHeader(resolved_path) and
                 !cs.hasICGNoComment(resolved_path) and
                 !hsd.isPathInICGNoComment(resolved_path) ) {
                /* Get the possible comment on this line and parse it */
                fdes->parseComment(cs.getComment(resolved_path , fdes->getLineNo())) ;
            }
        }
        free(resolved_path) ;
    }

    if ( debug_level >= 3 ) {
        if ( ! ci.getSourceManager().isInSystemHeader(dd_range.getEnd()) ) {
            std::cout << "\nFieldVisitor VisitDeclaratorDecl" << std::endl ;
            dd->dump() ; std::cout << std::endl ;
            std::cout << "    public/private = " << fdes->getAccess() << std::endl ;
        }
    }

    return true ;
}
Esempio n. 2
0
bool CommentSaver::HandleComment(clang::Preprocessor &PP, clang::SourceRange Comment) {
    //Comment.getBegin().dump(sm) ;

    //if ( ! sm.isInSystemHeader(Comment.getBegin()) ) {
    if ( isInUserOrTrickCode( ci , Comment.getBegin() , hsd ) ) {
        std::string file_name = ci.getSourceManager().getBufferName(Comment.getBegin()) ;
        unsigned int line_no = ci.getSourceManager().getSpellingLineNumber(Comment.getBegin()) ;
        comment_map[file_name][line_no] = Comment ;
    }

    // returning false means we did not push any text back to the stream for further reads.
    return false ;
}
Esempio n. 3
0
/* Both FieldDecl and VarDecl derive from DeclaratorDecl.  We can do
   common things to both node types in this function */
bool FieldVisitor::VisitDeclaratorDecl( clang::DeclaratorDecl *dd ) {

    fdes->setFileName(getFileName(ci , dd->getLocation(), hsd)) ;
    fdes->setName(dd->getNameAsString()) ;
    fdes->setAccess(dd->getAccess()) ;

    /* Get the source location of this field. */
    clang::SourceRange dd_range = dd->getSourceRange() ;
    std::string file_name = getFileName(ci, dd_range.getEnd(), hsd) ;
    if ( ! file_name.empty() ) {
        if ( isInUserOrTrickCode( ci , dd_range.getEnd() , hsd ) ) {
            fdes->setLineNo(ci.getSourceManager().getSpellingLineNumber(dd_range.getEnd())) ;
            /* process comment if neither ICG:(No) or ICG:(NoComment) is present */
            if (  cs.hasTrickHeader(file_name) and
                 !cs.hasICGNoComment(file_name) and
                 !hsd.isPathInICGNoComment(file_name) ) {
                /* Get the possible comment on this line and parse it */
                fdes->parseComment(cs.getComment(file_name , fdes->getLineNo())) ;
            }
        }
    }

    if ( debug_level >= 3 ) {
        if ( ! ci.getSourceManager().isInSystemHeader(dd_range.getEnd()) ) {
            std::cout << "FieldVisitor VisitDeclaratorDecl" << std::endl ;
            std::cout << "    file_name = " << file_name << std::endl ;
            std::cout << "    line num = " << fdes->getLineNo() << std::endl ;
            std::cout << "    comment = " << cs.getComment(file_name , fdes->getLineNo()) << std::endl ;
            std::cout << "    public/private = " << fdes->getAccess() << std::endl ;
            std::cout << "    io = " << fdes->getIO() << std::endl ;
        }
    }

    // returns true if any io is allowed. returning false will stop processing of this variable here.
    return fdes->getIO() ;
}