From 71dab9ed450c84cc75ccf201377498ce4fe88db8 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Fri, 29 Jan 2016 09:27:41 -0600 Subject: [PATCH] Introduce Open Dynamics Engine examples I want Trick to parse and understand ODE header files. The ODE header files include some typedef constructs ICG was skipping. Added code to handle the typedefs we did not handle before. Also made a small change the way TRICK_ICG_EXCLDUE and TRICK_EXCLUDE are used so that they support excluding individual files as well as directories. --- .../Interface_Code_Gen/FieldVisitor.cpp | 23 +++++++++++++++++++ .../Interface_Code_Gen/HeaderSearchDirs.cpp | 17 ++++++++++++-- .../Interface_Code_Gen/PrintAttributes.cpp | 4 ++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index 462e6ba8..3409e086 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -429,6 +429,9 @@ bool FieldVisitor::VisitTypedefType(clang::TypedefType *tt) { } if ( tt->isEnumeralType() ) { + if ( debug_level >= 4 ) { + std::cout << " FieldVisitor VisitTypedefType enumerated" << std::endl ; + } fdes->setEnumString("TRICK_ENUMERATED") ; fdes->setEnum(true) ; std::string enum_type_name = tt->desugar().getAsString() ; @@ -534,8 +537,28 @@ bool FieldVisitor::VisitTypedefType(clang::TypedefType *tt) { fdes->setTypeName(type_name) ; fdes->setHasType(true) ; } else if ( tt->isBuiltinType() ) { + if ( debug_level >= 4 ) { + std::cout << " FieldVisitor VisitTypedefType builtintype" << std::endl ; + } const clang::BuiltinType * bt = tt->getAs() ; VisitBuiltinType((clang::BuiltinType *)bt) ; + } else if ( tt->isArrayType() || tt->isPointerType()) { + clang::QualType qt = tt->desugar() ; + if ( debug_level >= 4 ) { + std::cout << "Typedef to constant array type" << std::endl ; + qt->dump() ; + } + // Calling visit type recursively with the typedeffed type + TraverseType(qt) ; + + if ( debug_level >= 4 ) { + std::cout << "After TraverseType" << std::endl ; + std::cout << *fdes << std::endl ; + } + } else { + if ( debug_level >= 4 ) { + std::cout << "Typedef to something we don't handle yet" << std::endl ; + } } return true; } diff --git a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp index 3adf6207..f4ef74e0 100644 --- a/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp +++ b/trick_source/codegen/Interface_Code_Gen/HeaderSearchDirs.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -138,7 +139,13 @@ void HeaderSearchDirs::AddICGExcludeDirs () { if ( ! item.empty() ) { char * resolved_path = realpath(item.c_str(), NULL) ; if ( resolved_path ) { - icg_exclude_dirs.push_back(std::string(resolved_path) + std::string("/")); + std::ifstream file_or_dir(resolved_path) ; + file_or_dir.seekg(0, std::ios::end) ; + if ( !file_or_dir.good()) { + icg_exclude_dirs.push_back(std::string(resolved_path) + std::string("/")); + } else { + icg_exclude_dirs.push_back(std::string(resolved_path)); + } } else { std::cout << "Cannot find TRICK_ICG_EXCLUDE directory " << item << std::endl ; } @@ -160,7 +167,13 @@ void HeaderSearchDirs::AddExcludeDirs () { if ( ! item.empty() ) { char * resolved_path = realpath(item.c_str(), NULL) ; if ( resolved_path ) { - exclude_dirs.push_back(std::string(resolved_path) + std::string("/")); + std::ifstream file_or_dir(resolved_path) ; + file_or_dir.seekg(0, std::ios::end) ; + if ( !file_or_dir.good()) { + exclude_dirs.push_back(std::string(resolved_path) + std::string("/")); + } else { + exclude_dirs.push_back(std::string(resolved_path)); + } } else { std::cout << "Cannot find TRICK_ICG_EXCLUDE directory " << item << std::endl ; } diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index 06ff750b..2c35973f 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -180,11 +180,11 @@ bool PrintAttributes::openIOFile(std::string header_file_name) { icg_no_files.push_back(rp) ; } } else { - std::cout << "ICG skipping " << rp << " (ICG exclude dir " << + std::cout << "ICG skipping " << rp << " (ICG exclude " << hsd.getPathInICGExclude(rp) << ")" << std::endl ; } } else { - std::cout << "ICG skipping " << rp << " (exclude dir " << + std::cout << "ICG skipping " << rp << " (exclude " << hsd.getPathInExclude(rp) << ")" << std::endl ; } } else {