ICG processing files it is supposed to skip

We pull file names out of the clang infrastructure to match where
classes are defined.  We use the file name to pull comments and find
and process Trick header comments.  Up to now clang gave us the realpath
of files and when we looked up comments we already had the realpath and
everything worked.  In clang 3.6 in some places we are not getting the
realpath anymore which confuses ICG.  Added code to get the realpath of
any file name we use throughout the code.

refs #167

Conflicts:
	trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp
	trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp
This commit is contained in:
Alex Lin 2016-02-04 15:43:14 -06:00
parent 49de908a30
commit 2661835797
3 changed files with 34 additions and 22 deletions

View File

@ -7,16 +7,20 @@
#include "clang/Basic/FileManager.h"
#include "CommentSaver.hh"
#include "Utilities.hh"
CommentSaver::CommentSaver(clang::SourceManager & in_sm ) : sm(in_sm) {}
bool CommentSaver::HandleComment(clang::Preprocessor &PP, clang::SourceRange Comment) {
//Comment.getBegin().dump(sm) ;
if ( ! sm.isInSystemHeader(Comment.getBegin()) ) {
std::string file_name = sm.getBufferName(Comment.getBegin()) ;
unsigned int line_no = sm.getSpellingLineNumber(Comment.getBegin()) ;
comment_map[file_name][line_no] = Comment ;
char * resolved_path = almostRealPath( file_name.c_str() ) ;
if ( resolved_path != NULL ) {
unsigned int line_no = sm.getSpellingLineNumber(Comment.getBegin()) ;
comment_map[file_name][line_no] = Comment ;
free(resolved_path) ;
}
}
// returning false means we did not push any text back to the stream for further reads.
@ -46,19 +50,26 @@ std::string CommentSaver::getTrickHeaderComment( std::string file_name ) {
std::map < unsigned int , clang::SourceRange >::iterator cit ;
if ( trick_header_comments.find(file_name) == trick_header_comments.end() ) {
trick_header_comments[file_name] = std::string() ;
for ( cit = comment_map[file_name].begin() ; cit != comment_map[file_name].end() ; cit++ ) {
std::string comment_str = getComment((*cit).second) ;
std::transform(comment_str.begin(), comment_str.end(), comment_str.begin(), ::toupper) ;
if ( comment_str.find("PURPOSE") != std::string::npos ) {
trick_header_comments[file_name] = comment_str ;
break ;
std::string ret ;
char * resolved_path = almostRealPath( file_name.c_str() ) ;
if ( resolved_path != NULL ) {
if ( trick_header_comments.find(file_name) == trick_header_comments.end() ) {
trick_header_comments[file_name] = std::string() ;
for ( cit = comment_map[file_name].begin() ; cit != comment_map[file_name].end() ; cit++ ) {
std::string comment_str = getComment((*cit).second) ;
std::transform(comment_str.begin(), comment_str.end(), comment_str.begin(), ::toupper) ;
if ( comment_str.find("PURPOSE") != std::string::npos ) {
trick_header_comments[file_name] = comment_str ;
break ;
}
}
}
ret = trick_header_comments[resolved_path] ;
free(resolved_path) ;
}
return trick_header_comments[file_name] ;
return ret ;
}
void CommentSaver::getICGField( std::string file_name ) {

View File

@ -144,14 +144,18 @@ bool FieldVisitor::VisitDeclaratorDecl( clang::DeclaratorDecl *dd ) {
/* Get the source location of this field. */
clang::SourceRange dd_range = dd->getSourceRange() ;
if ( ! ci.getSourceManager().isInSystemHeader(dd_range.getEnd()) ) {
std::string file_name = ci.getSourceManager().getBufferName(dd_range.getEnd()) ;
fdes->setLineNo(ci.getSourceManager().getSpellingLineNumber(dd_range.getEnd())) ;
/* process comment if neither ICG:(No) or ICG:(NoComment) is present */
if ( ! 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())) ;
std::string file_name = ci.getSourceManager().getBufferName(dd_range.getEnd()) ;
char * resolved_path = almostRealPath( file_name.c_str() ) ;
if ( resolved_path ) {
if ( ! ci.getSourceManager().isInSystemHeader(dd_range.getEnd()) ) {
fdes->setLineNo(ci.getSourceManager().getSpellingLineNumber(dd_range.getEnd())) ;
/* process comment if neither ICG:(No) or ICG:(NoComment) is present */
if ( ! 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())) ;
}
}
free(resolved_path) ;
}
if ( debug_level >= 3 ) {

View File

@ -58,13 +58,10 @@ std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl
if ( ! fid.isInvalid() ) {
const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ;
if ( fe != NULL ) {
return std::string(fe->getName()) ;
/*
char * resolved_path = almostRealPath( fe->getName() ) ;
if ( resolved_path != NULL and hsd.isPathInUserDir(resolved_path)) {
return std::string(resolved_path) ;
}
*/
}
}
return std::string() ;