This commit is contained in:
Alex Lin 2016-02-04 16:09:51 -06:00
commit 030f44132c
5 changed files with 48 additions and 32 deletions

View File

@ -10,6 +10,12 @@
%include "trick/swig/cast_as.i"
%include "trick/swig/swig_int_typemap.i"
/*
compactdefaultargs fixes a bug with enumeration default arguments not being
recogized in function calls starting in swig 3.0.x
*/
%feature("compactdefaultargs") ;
/* SWIG can't understand GNU C keyword "__attribute__" */
#ifdef SWIG
#define __attribute__(x)

View File

@ -134,7 +134,6 @@ sub make_swig_makefile() {
my ($n , $f , $k , $m);
my %temp_hash ;
my (@temp_array) ;
my ($ii) ;
my ($swig_sim_dir, $swig_src_dir) ;
my (%py_module_map) ;
@ -160,9 +159,9 @@ sub make_swig_makefile() {
}
}
next if ( $continue == 0 ) ;
push @temp_array , $f ;
$temp_hash{$f} = 1;
}
@files_to_process = @temp_array ;
@files_to_process = sort keys %temp_hash ;
open MAKEFILE , ">build/Makefile_swig" or return ;
open LINK_PY_OBJS , ">build/link_py_objs" or return ;
@ -171,7 +170,7 @@ sub make_swig_makefile() {
print MAKEFILE "\
# SWIG rule
SWIG_FLAGS =
SWIG_FLAGS ?=
SWIG_CFLAGS := -I../include \${PYTHON_INCLUDES} -Wno-shadow -Wno-missing-field-initializers
ifeq (\$(IS_CC_CLANG), 1)
SWIG_CFLAGS += -Wno-self-assign -Wno-sometimes-uninitialized

View File

@ -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 ) {

View File

@ -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 ) {

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() ;