From 9d840f334f8cf73f0699ab745dec64e5caced56a Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Tue, 24 May 2016 13:30:56 -0500 Subject: [PATCH] Symbolic links are my nemesis Found 2 more places where we should be using the absolute path. refs #240 --- bin/pm/parse_s_define.pm | 5 ++-- .../Interface_Code_Gen/CommentSaver.cpp | 5 ++++ .../Interface_Code_Gen/CommentSaver.hh | 6 +++++ .../Interface_Code_Gen/FieldVisitor.cpp | 23 +++++++++++++------ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/bin/pm/parse_s_define.pm b/bin/pm/parse_s_define.pm index 602b0d32..0815943d 100644 --- a/bin/pm/parse_s_define.pm +++ b/bin/pm/parse_s_define.pm @@ -261,8 +261,9 @@ sub parse_s_define ($) { } else { my $found = 0 ; foreach my $inc_path ( @valid_inc_paths ) { - if ( -f "$inc_path/$object_file" ) { - push @{$$sim_ref{mis_entry_files}}, "$inc_path/$object_file" ; + my $f = abs_path(dirname("$inc_path/$object_file")) . "/" . basename("$inc_path/$object_file") ; + if ( -f "$f" ) { + push @{$$sim_ref{mis_entry_files}}, "$f" ; $found = 1 ; last ; } diff --git a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp index b15e78a6..c5462430 100644 --- a/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp +++ b/trick_source/codegen/Interface_Code_Gen/CommentSaver.cpp @@ -134,6 +134,11 @@ void CommentSaver::getICGField( std::string file_name ) { } +bool CommentSaver::hasTrickHeader( std::string file_name ) { + std::string th_str = getTrickHeaderComment(file_name) ; + return (! th_str.empty()) ; +} + bool CommentSaver::hasICGNo( std::string file_name ) { if ( icg_no_found.find(file_name) == icg_no_found.end() ) { diff --git a/trick_source/codegen/Interface_Code_Gen/CommentSaver.hh b/trick_source/codegen/Interface_Code_Gen/CommentSaver.hh index f26314f7..49811f75 100644 --- a/trick_source/codegen/Interface_Code_Gen/CommentSaver.hh +++ b/trick_source/codegen/Interface_Code_Gen/CommentSaver.hh @@ -58,6 +58,12 @@ class CommentSaver : public clang::CommentHandler { */ void getICGField( std::string file_name ) ; + /** Returns if the header has a Trick header comment + @param file_name = File name to search + @return true = if header comment found + */ + bool hasTrickHeader(std::string file_name ) ; + /** Searches the Trick header comment for the ICG:(No) entry. @param file_name = File name to search @return true = ICG:(No) was found. diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index 254e5b64..54245085 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -144,20 +144,29 @@ bool FieldVisitor::VisitDeclaratorDecl( clang::DeclaratorDecl *dd ) { fdes->setName(dd->getNameAsString()) ; fdes->setAccess(dd->getAccess()) ; - /* Get the source location of this field. */ + /* 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 ( ! ci.getSourceManager().isInSystemHeader(dd_range.getEnd()) ) { + clang::PresumedLoc PLoc = ci.getSourceManager().getPresumedLoc(dd_range.getEnd()); + std::string file_name ; + if (!PLoc.isInvalid()) { + char * resolved_path = almostRealPath(PLoc.getFilename()) ; + if ( resolved_path != NULL ) { + file_name = std::string(resolved_path) ; + free(resolved_path) ; + } + } + + 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.hasICGNoComment(file_name) and ! hsd.isPathInICGNoComment(file_name) ) { + 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())) ; } } - free(resolved_path) ; } if ( debug_level >= 3 ) {