Detect when TRICK_ICG is used in header files and compensate for it. #375

So the previous commit broke on the mac.  There were missing changes in
TranslationUnitVisitor.cpp.  Also there are fixes for clang 3.9 that
were not included yet.
This commit is contained in:
Alex Lin 2017-01-12 14:17:43 -06:00
parent bc9102c208
commit cb58e0c770
5 changed files with 36 additions and 28 deletions

View File

@ -61,7 +61,7 @@ bool CXXRecordVisitor::TraverseDecl(clang::Decl *d) {
process embedded classes that have public access. */ process embedded classes that have public access. */
clang::RecordDecl * rd = crd->getDefinition() ; clang::RecordDecl * rd = crd->getDefinition() ;
if ( rd != NULL and rd->getAccess() == clang::AS_public ) { if ( rd != NULL and rd->getAccess() == clang::AS_public ) {
if ( isInUserCode(ci , crd->getRBraceLoc(), hsd) ) { if ( isInUserCode(ci , crd->getSourceRange().getEnd(), hsd) ) {
CXXRecordVisitor embedded_cvis(ci , cs, hsd , pa, false, false, true) ; CXXRecordVisitor embedded_cvis(ci , cs, hsd , pa, false, false, true) ;
embedded_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(d)) ; embedded_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(d)) ;
pa.printClass(embedded_cvis.get_class_data()) ; pa.printClass(embedded_cvis.get_class_data()) ;
@ -149,7 +149,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
cval.setHasPublicDestructor(true) ; cval.setHasPublicDestructor(true) ;
} }
std::string file_name = getFileName(ci , rec->getRBraceLoc(), hsd) ; std::string file_name = getFileName(ci , rec->getSourceRange().getEnd(), hsd) ;
char * rp = almostRealPath(file_name.c_str()) ; char * rp = almostRealPath(file_name.c_str()) ;
if ( rp == NULL ) { if ( rp == NULL ) {
return false ; return false ;
@ -178,13 +178,13 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
clang::RecordDecl * rd = rt->getDecl() ; clang::RecordDecl * rd = rt->getDecl() ;
//std::cout << " " << cval.getName() << " inherits from " << rd->getNameAsString() << "" << std::endl ; //std::cout << " " << cval.getName() << " inherits from " << rd->getNameAsString() << "" << std::endl ;
//rd->dump() ; std::cout << std::endl ; //rd->dump() ; std::cout << std::endl ;
if ( isInUserOrTrickCode(ci , rd->getRBraceLoc(), hsd) ) { if ( isInUserOrTrickCode(ci , rd->getSourceRange().getEnd(), hsd) ) {
const clang::ASTRecordLayout &record_layout = rec->getASTContext().getASTRecordLayout(rec); const clang::ASTRecordLayout &record_layout = rec->getASTContext().getASTRecordLayout(rec);
unsigned int inherit_class_offset ; unsigned int inherit_class_offset ;
inherit_class_offset = record_layout.getBaseClassOffset(llvm::cast<clang::CXXRecordDecl>(rd)).getQuantity() ; inherit_class_offset = record_layout.getBaseClassOffset(llvm::cast<clang::CXXRecordDecl>(rd)).getQuantity() ;
//std::cout << " inherit_class_offset = " << inherit_class_offset << "" << std::endl ; //std::cout << " inherit_class_offset = " << inherit_class_offset << "" << std::endl ;
//std::cout << " " << getFileName(ci , rd->getRBraceLoc(), hsd) << "" << std::endl ; //std::cout << " " << getFileName(ci , rd->getSourceRange().getEnd(), hsd) << "" << std::endl ;
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, true, bcii->isVirtual(), false, inherit_class_offset) ; CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, true, bcii->isVirtual(), false, inherit_class_offset) ;
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ; inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription()) ; cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription()) ;
@ -220,7 +220,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
clang::RecordDecl * rd = rt->getDecl() ; clang::RecordDecl * rd = rt->getDecl() ;
//std::cout << " " << cval.getName() << " virtually inherits from " << rd->getNameAsString() << "" << std::endl ; //std::cout << " " << cval.getName() << " virtually inherits from " << rd->getNameAsString() << "" << std::endl ;
//rd->dump() ; std::cout << std::endl ; //rd->dump() ; std::cout << std::endl ;
if ( isInUserOrTrickCode(ci , rd->getRBraceLoc(), hsd) ) { if ( isInUserOrTrickCode(ci , rd->getSourceRange().getEnd(), hsd) ) {
const clang::ASTRecordLayout &record_layout = rec->getASTContext().getASTRecordLayout(rec); const clang::ASTRecordLayout &record_layout = rec->getASTContext().getASTRecordLayout(rec);
unsigned int inherit_class_offset ; unsigned int inherit_class_offset ;
@ -229,7 +229,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
inherit_class_offset = record_layout.getVBaseClassOffset(llvm::cast<clang::CXXRecordDecl>(rd)).getQuantity() ; inherit_class_offset = record_layout.getVBaseClassOffset(llvm::cast<clang::CXXRecordDecl>(rd)).getQuantity() ;
//std::cout << " inherit_class_offset = " << inherit_class_offset << "" << std::endl ; //std::cout << " inherit_class_offset = " << inherit_class_offset << "" << std::endl ;
//std::cout << " " << getFileName(ci , rd->getRBraceLoc(), hsd) << "" << std::endl ; //std::cout << " " << getFileName(ci , rd->getSourceRange().getEnd(), hsd) << "" << std::endl ;
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, true, bcii->isVirtual(), false, inherit_class_offset) ; CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, true, bcii->isVirtual(), false, inherit_class_offset) ;
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ; inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription()) ; cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription()) ;

View File

@ -26,7 +26,7 @@ bool EnumVisitor::VisitType(clang::Type *t) {
} }
bool EnumVisitor::VisitEnumDecl(clang::EnumDecl *ed) { bool EnumVisitor::VisitEnumDecl(clang::EnumDecl *ed) {
eval.setFileName(getFileName(ci , ed->getRBraceLoc(), hsd)) ; eval.setFileName(getFileName(ci , ed->getSourceRange().getEnd(), hsd)) ;
return true; return true;
} }

View File

@ -46,9 +46,12 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) {
In this case the CXXRecordDecl file name will not match the current file name, and is In this case the CXXRecordDecl file name will not match the current file name, and is
in fact empty */ in fact empty */
clang::RecordDecl * rd = crd->getDefinition() ; clang::RecordDecl * rd = crd->getDefinition() ;
if ( rd != NULL and ! getFileName(ci , crd->getRBraceLoc(), hsd).empty() ) { if ( rd != NULL ) {
std::string rd_file = getFileName(ci , rd->getSourceRange().getEnd(), hsd) ;
std::string crd_file = getFileName(ci , crd->getSourceRange().getEnd(), hsd) ;
if (!crd_file.empty() and !crd_file.compare(rd_file)) {
//crd->dump() ; std::cout << std::endl ; //crd->dump() ; std::cout << std::endl ;
if ( isInUserCode(ci , crd->getRBraceLoc(), hsd) ) { if ( isInUserCode(ci , crd->getSourceRange().getEnd(), hsd) ) {
CXXRecordVisitor cvis(ci , cs, hsd , pa, false, false, true) ; CXXRecordVisitor cvis(ci , cs, hsd , pa, false, false, true) ;
cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(d)) ; cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(d)) ;
@ -71,6 +74,7 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) {
fwd_declared_classes[file_name].erase(it) ; fwd_declared_classes[file_name].erase(it) ;
} }
} }
}
} else { } else {
// These are forward declarations. Insert this into the set of fwd declares keyed by the current file. // These are forward declarations. Insert this into the set of fwd declares keyed by the current file.
if ( ! crd->getNameAsString().empty() ) { if ( ! crd->getNameAsString().empty() ) {
@ -81,7 +85,7 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) {
break ; break ;
case clang::Decl::Enum : { case clang::Decl::Enum : {
clang::EnumDecl * ed = static_cast<clang::EnumDecl *>(d) ; clang::EnumDecl * ed = static_cast<clang::EnumDecl *>(d) ;
if ( isInUserCode(ci , ed->getRBraceLoc(), hsd) ) { if ( isInUserCode(ci , ed->getSourceRange().getEnd(), hsd) ) {
EnumVisitor evis(ci, hsd) ; EnumVisitor evis(ci, hsd) ;
evis.TraverseDecl(ed) ; evis.TraverseDecl(ed) ;
//if ( evis.get_enum_data() != NULL ) { //if ( evis.get_enum_data() != NULL ) {

View File

@ -100,6 +100,9 @@ int main( int argc , char * argv[] ) {
ci.createFileManager(); ci.createFileManager();
ci.createSourceManager(ci.getFileManager()); ci.createSourceManager(ci.getFileManager());
clang::PreprocessorOptions & ppo = ci.getPreprocessorOpts() ;
ppo.UsePredefines = true;
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) #if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
clang::TargetOptions to; clang::TargetOptions to;
to.Triple = llvm::sys::getDefaultTargetTriple(); to.Triple = llvm::sys::getDefaultTargetTriple();

View File

@ -50,6 +50,7 @@ endif
endif endif
ifeq ($(TRICK_HOST_TYPE),Darwin) ifeq ($(TRICK_HOST_TYPE),Darwin)
CXXFLAGS += -std=c++11
CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --libs) CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --libs)
CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --system-libs) CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --system-libs)
CLANGLIBS += -lc++abi CLANGLIBS += -lc++abi