diff --git a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp index fb931e1c..b75dd5af 100644 --- a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp +++ b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp @@ -12,13 +12,16 @@ CommentSaver::CommentSaver(clang::CompilerInstance & in_ci , HeaderSearchDirs & in_hsd ) : ci(in_ci) , hsd(in_hsd) {} bool CommentSaver::HandleComment(clang::Preprocessor &PP, clang::SourceRange Comment) { - //Comment.getBegin().dump(sm) ; - //if ( ! sm.isInSystemHeader(Comment.getBegin()) ) { + //Comment.getBegin().dump(sm) ; 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 ; + char * resolved_path = almostRealPath( file_name.c_str() ) ; + if ( resolved_path != NULL ) { + unsigned int line_no = ci.getSourceManager().getSpellingLineNumber(Comment.getBegin()) ; + comment_map[std::string(resolved_path)][line_no] = Comment ; + free(resolved_path) ; + } } // returning false means we did not push any text back to the stream for further reads. @@ -47,26 +50,33 @@ std::string CommentSaver::getComment( std::string file_name , unsigned int line_ std::string CommentSaver::getTrickHeaderComment( std::string file_name ) { std::map < unsigned int , clang::SourceRange >::iterator cit ; + std::string ret ; - 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) ; - if ( comment_str.find("@trick_parse") != std::string::npos or - comment_str.find("\\trick_parse") != std::string::npos ) { - trick_header_comments[file_name] = getComment((*cit).second) ; - break ; - } else { - 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] = getComment((*cit).second) ; + char * resolved_path = almostRealPath( file_name.c_str() ) ; + if ( resolved_path != NULL ) { + if ( trick_header_comments.find(resolved_path) == trick_header_comments.end() ) { + trick_header_comments[resolved_path] = std::string() ; + for ( cit = comment_map[resolved_path].begin() ; cit != comment_map[resolved_path].end() ; cit++ ) { + std::string comment_str = getComment((*cit).second) ; + if ( comment_str.find("@trick_parse") != std::string::npos or + comment_str.find("\\trick_parse") != std::string::npos ) { + trick_header_comments[resolved_path] = getComment((*cit).second) ; break ; + } else { + std::transform(comment_str.begin(), comment_str.end(), comment_str.begin(), ::toupper) ; + if ( comment_str.find("PURPOSE") != std::string::npos ) { + trick_header_comments[resolved_path] = getComment((*cit).second) ; + 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 ) { diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index 3409e086..5356974c 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -145,15 +145,19 @@ bool FieldVisitor::VisitDeclaratorDecl( clang::DeclaratorDecl *dd ) { /* Get the source location of this field. */ clang::SourceRange dd_range = dd->getSourceRange() ; std::string file_name = ci.getSourceManager().getBufferName(dd_range.getEnd()) ; - 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())) ; + 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 ) { diff --git a/trick_source/codegen/Interface_Code_Gen/Utilities.cpp b/trick_source/codegen/Interface_Code_Gen/Utilities.cpp index 8eccedb0..6c8184bd 100644 --- a/trick_source/codegen/Interface_Code_Gen/Utilities.cpp +++ b/trick_source/codegen/Interface_Code_Gen/Utilities.cpp @@ -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() ;