diff --git a/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp index 093e5dde..c0592725 100644 --- a/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/ClassVisitor.cpp @@ -61,7 +61,7 @@ bool CXXRecordVisitor::TraverseDecl(clang::Decl *d) { process embedded classes that have public access. */ clang::RecordDecl * rd = crd->getDefinition() ; 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) ; embedded_cvis.TraverseCXXRecordDecl(static_cast(d)) ; pa.printClass(embedded_cvis.get_class_data()) ; @@ -149,7 +149,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { 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()) ; if ( rp == NULL ) { return false ; @@ -178,13 +178,13 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { clang::RecordDecl * rd = rt->getDecl() ; //std::cout << " " << cval.getName() << " inherits from " << rd->getNameAsString() << "" << 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); unsigned int inherit_class_offset ; inherit_class_offset = record_layout.getBaseClassOffset(llvm::cast(rd)).getQuantity() ; //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) ; inherit_cvis.TraverseCXXRecordDecl(static_cast(rd)) ; cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription()) ; @@ -220,7 +220,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { clang::RecordDecl * rd = rt->getDecl() ; //std::cout << " " << cval.getName() << " virtually inherits from " << rd->getNameAsString() << "" << 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); unsigned int inherit_class_offset ; @@ -229,7 +229,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) { inherit_class_offset = record_layout.getVBaseClassOffset(llvm::cast(rd)).getQuantity() ; //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) ; inherit_cvis.TraverseCXXRecordDecl(static_cast(rd)) ; cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription()) ; diff --git a/trick_source/codegen/Interface_Code_Gen/EnumVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/EnumVisitor.cpp index f99fc72c..31c3edc2 100644 --- a/trick_source/codegen/Interface_Code_Gen/EnumVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/EnumVisitor.cpp @@ -26,7 +26,7 @@ bool EnumVisitor::VisitType(clang::Type *t) { } bool EnumVisitor::VisitEnumDecl(clang::EnumDecl *ed) { - eval.setFileName(getFileName(ci , ed->getRBraceLoc(), hsd)) ; + eval.setFileName(getFileName(ci , ed->getSourceRange().getEnd(), hsd)) ; return true; } diff --git a/trick_source/codegen/Interface_Code_Gen/TranslationUnitVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/TranslationUnitVisitor.cpp index 327ae9d6..f7093cc7 100644 --- a/trick_source/codegen/Interface_Code_Gen/TranslationUnitVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/TranslationUnitVisitor.cpp @@ -46,29 +46,33 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) { In this case the CXXRecordDecl file name will not match the current file name, and is in fact empty */ clang::RecordDecl * rd = crd->getDefinition() ; - if ( rd != NULL and ! getFileName(ci , crd->getRBraceLoc(), hsd).empty() ) { - //crd->dump() ; std::cout << std::endl ; - if ( isInUserCode(ci , crd->getRBraceLoc(), hsd) ) { - CXXRecordVisitor cvis(ci , cs, hsd , pa, false, false, true) ; + 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 ; + if ( isInUserCode(ci , crd->getSourceRange().getEnd(), hsd) ) { + CXXRecordVisitor cvis(ci , cs, hsd , pa, false, false, true) ; - cvis.TraverseCXXRecordDecl(static_cast(d)) ; - pa.printClass(cvis.get_class_data()) ; + cvis.TraverseCXXRecordDecl(static_cast(d)) ; + pa.printClass(cvis.get_class_data()) ; - /* Check to see if the struct/class is forward declared in the same file. - If it is, then remove the notation that it is forward declared. This - is to allow C structs to be forward declared and typedeffed and io_src - code will be generated for both the original structure name and typedeffed - name. + /* Check to see if the struct/class is forward declared in the same file. + If it is, then remove the notation that it is forward declared. This + is to allow C structs to be forward declared and typedeffed and io_src + code will be generated for both the original structure name and typedeffed + name. - struct Astruct ; - typedef struct Astruct {} Bstruct ; - */ - std::set< std::string >::iterator it ; - std::string file_name = getFileName(ci , d->getLocEnd(), hsd) ; - std::string source_type = cvis.get_class_data()->getName() ; - it = fwd_declared_classes[file_name].find(source_type) ; - if ( it != fwd_declared_classes[file_name].end() ) { - fwd_declared_classes[file_name].erase(it) ; + struct Astruct ; + typedef struct Astruct {} Bstruct ; + */ + std::set< std::string >::iterator it ; + std::string file_name = getFileName(ci , d->getLocEnd(), hsd) ; + std::string source_type = cvis.get_class_data()->getName() ; + it = fwd_declared_classes[file_name].find(source_type) ; + if ( it != fwd_declared_classes[file_name].end() ) { + fwd_declared_classes[file_name].erase(it) ; + } } } } else { @@ -81,7 +85,7 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) { break ; case clang::Decl::Enum : { clang::EnumDecl * ed = static_cast(d) ; - if ( isInUserCode(ci , ed->getRBraceLoc(), hsd) ) { + if ( isInUserCode(ci , ed->getSourceRange().getEnd(), hsd) ) { EnumVisitor evis(ci, hsd) ; evis.TraverseDecl(ed) ; //if ( evis.get_enum_data() != NULL ) { diff --git a/trick_source/codegen/Interface_Code_Gen/main.cpp b/trick_source/codegen/Interface_Code_Gen/main.cpp index b859ca82..05a942b3 100644 --- a/trick_source/codegen/Interface_Code_Gen/main.cpp +++ b/trick_source/codegen/Interface_Code_Gen/main.cpp @@ -100,6 +100,9 @@ int main( int argc , char * argv[] ) { ci.createFileManager(); ci.createSourceManager(ci.getFileManager()); + clang::PreprocessorOptions & ppo = ci.getPreprocessorOpts() ; + ppo.UsePredefines = true; + #if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) clang::TargetOptions to; to.Triple = llvm::sys::getDefaultTargetTriple(); diff --git a/trick_source/codegen/Interface_Code_Gen/makefile b/trick_source/codegen/Interface_Code_Gen/makefile index 63c4e0a9..561f0590 100644 --- a/trick_source/codegen/Interface_Code_Gen/makefile +++ b/trick_source/codegen/Interface_Code_Gen/makefile @@ -50,6 +50,7 @@ endif endif ifeq ($(TRICK_HOST_TYPE),Darwin) +CXXFLAGS += -std=c++11 CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --libs) CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --system-libs) CLANGLIBS += -lc++abi