Standardize directory names

Found that on the Mac ICG was ignoring all of header files comments in ${TRICK_HOME}/include because it had the relative directory "include" listed as a system path.  Comments were only processed if it wasn't in a system directory.  Changed the check to use our function that checks to see if a header is in user or Trick code, basically the same check, but it only uses full paths and doesn't get confused with "include".

refs #63
This commit is contained in:
Alex Lin 2015-06-10 14:19:00 -05:00
parent 036b85cae1
commit 77510d0ccd
5 changed files with 23 additions and 19 deletions

View File

@ -7,15 +7,17 @@
#include "clang/Basic/FileManager.h"
#include "CommentSaver.hh"
#include "Utilities.hh"
CommentSaver::CommentSaver(clang::SourceManager & in_sm ) : sm(in_sm) {}
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()) ) {
std::string file_name = sm.getBufferName(Comment.getBegin()) ;
unsigned int line_no = sm.getSpellingLineNumber(Comment.getBegin()) ;
//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 ;
}
@ -27,8 +29,8 @@ std::string CommentSaver::getComment( clang::SourceRange sr ) {
if ( sr.isValid() ) {
/* fsl_begin and fsl_end are two pointers into the header file. We want the text between the two pointers. */
clang::FullSourceLoc fsl_begin(sr.getBegin() , sm) ;
clang::FullSourceLoc fsl_end(sr.getEnd() , sm) ;
clang::FullSourceLoc fsl_begin(sr.getBegin() , ci.getSourceManager()) ;
clang::FullSourceLoc fsl_end(sr.getEnd() , ci.getSourceManager()) ;
std::string comment_text( fsl_begin.getCharacterData() ,
(size_t)(fsl_end.getCharacterData() - fsl_begin.getCharacterData())) ;
return comment_text ;

View File

@ -6,7 +6,7 @@
#include <set>
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/CompilerInstance.h"
#include "HeaderSearchDirs.hh"
@ -24,7 +24,7 @@
class CommentSaver : public clang::CommentHandler {
public:
CommentSaver( clang::SourceManager & in_sm ) ;
CommentSaver( clang::CompilerInstance & in_ci , HeaderSearchDirs & in_hsd ) ;
/** Called by the PreProcessor when a comment is parsed. HandleComment saves
the comment indexed by file name and line number in the comment map
@ -78,7 +78,9 @@ class CommentSaver : public clang::CommentHandler {
private:
/** The compiler's source manager. Holds file/line info for everything. */
clang::SourceManager & sm ;
clang::CompilerInstance & ci ;
HeaderSearchDirs & hsd ;
/** Map of file name to ICG: (No) found */
std::map < std::string , bool > icg_no_found ;

View File

@ -144,8 +144,8 @@ 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()) ;
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.hasICGNoComment(file_name) and ! hsd.isPathInICGNoComment(file_name) ) {

View File

@ -142,7 +142,7 @@ int main( int argc , char * argv[] ) {
hsd.addDefines ( defines ) ;
// Add our comment saver as a comment handler in the preprocessor
CommentSaver cs(ci.getSourceManager()) ;
CommentSaver cs(ci, hsd) ;
pp.addCommentHandler(&cs) ;
PrintAttributes pa( attr_version, hsd, cs, ci, force, sim_services_flag) ;

View File

@ -2,13 +2,13 @@
# The config_${HOST_TYPE}.mk file provides LLVM_HOME
include ${TRICK_HOME}/share/trick/makefiles/Makefile.common
CC := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --bindir)/clang
CXX := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --bindir)/clang++
CC := $(shell $(LLVM_HOME)/bin/llvm-config --bindir)/clang
CXX := $(shell $(LLVM_HOME)/bin/llvm-config --bindir)/clang++
CXXFLAGS := -I${LLVM_HOME}/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti
CLANG_MINOR_GTEQ5 := $(shell expr `$(LLVM_HOME)/bin/$(LLVM_CONFIG) --version | cut -f2 -d. ` \>= 5 )
CLANG_MINOR_GTEQ5 := $(shell expr `$(LLVM_HOME)/bin/llvm-config --version | cut -f2 -d. ` \>= 5 )
LLVMLDFLAGS := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --ldflags)
LLVMLDFLAGS := $(shell $(LLVM_HOME)/bin/llvm-config --ldflags)
OBJ_DIR := object_$(TRICK_HOST_CPU)
@ -39,17 +39,17 @@ CLANGLIBS = \
-lclangBasic \
ifeq ($(TRICK_HOST_TYPE),Linux)
CLANGLIBS += $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --libs)
CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --libs)
ifeq ($(CLANG_MINOR_GTEQ5),1)
CXXFLAGS += -std=c++11
# Fedora 21 adds -ledit as a system lib, but it isn't installed, or required.
CLANGLIBS += $(filter-out -ledit,$(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --system-libs))
CLANGLIBS += $(filter-out -ledit,$(shell $(LLVM_HOME)/bin/llvm-config --system-libs))
endif
endif
ifeq ($(TRICK_HOST_TYPE),Darwin)
CXXFLAGS += -std=c++11
CLANGLIBS += -lLLVMOption -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMSupport $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --system-libs)
CLANGLIBS += -lLLVMOption -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMSupport $(shell $(LLVM_HOME)/bin/llvm-config --system-libs)
endif
all: $(ICG)