diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 285e7e5c..47039909 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -68,6 +68,11 @@ sub read_files_to_process() { outer: foreach my $word ( split ) { next if ( $word eq "\\" or $word =~ /o:/ ) ; + + # skip unsupported extensions + next if not $word =~ /\.(H|h|hh|hxx|h++|hpp)$/ ; + + # get the absolute path if ( $word !~ /^\// and $dir ne "\/" ) { $word = "$dir/$word" ; } @@ -76,15 +81,15 @@ sub read_files_to_process() { # skip duplicate files next if (exists($md5s{$word})) ; - # remove system headers that are missed by the compiler -MM flag + # skip system headers that are missed by the compiler -MM flag next if ( $word =~ /^\/usr\/include/ ) ; - # remove Trick headers + # skip Trick headers my $trick_home = $ENV{'TRICK_HOME'} ; next if ( $word =~ /^\Q$trick_home\/include/ ) ; next if ( $word =~ /^\Q$trick_home\/trick_source/ ) ; - # remove paths in TRICK_EXCLUDE + # skip paths in TRICK_EXCLUDE foreach my $path ( @exclude_paths ) { if ( $word =~ /^\Q$path\E(.*)/ ) { print "SWIG Skip TRICK_EXCLUDE: $path$1\n" if $verbose_build ; @@ -92,7 +97,7 @@ sub read_files_to_process() { } } - # remove paths in TRICK_SWIG_EXCLUDE + # skip paths in TRICK_SWIG_EXCLUDE foreach my $path ( @swig_exclude_paths ) { if ( $word =~ /^\Q$path\E(.*)/ ) { print "SWIG Skip TRICK_SWIG_EXCLUDE: $path$1\n" if $verbose_build ; @@ -120,10 +125,11 @@ sub read_files_to_process() { sub write_makefile_swig_deps() { open DEPENDENCIES_FILE , ">build/Makefile_swig_deps" or return ; - print DEPENDENCIES_FILE "build/Makefile_swig: \\\n" ; + print DEPENDENCIES_FILE "build/Makefile_swig:" ; foreach my $file ( @files_to_process, @ext_lib_files ) { - print DEPENDENCIES_FILE " " . $file . " \\\n" ; + print DEPENDENCIES_FILE " \\\n " . $file ; } + close DEPENDENCIES_FILE ; } sub has_swig_no($) { @@ -187,12 +193,11 @@ all: \$(TRICK_FIXED_PYTHON) SWIG_I =" ; - foreach my $f ( @files_to_process ) { - my ($swig_dir, $swig_object_dir , $swig_module_dir , $swig_file_only) ; - my ($swig_f) = $f ; - $swig_object_dir = dirname($f) ; - ($swig_file_only) = ($f =~ /([^\/]*)(?:\.h|\.H|\.hh|\.h\+\+|\.hxx|\.hpp)$/) ; - print MAKEFILE" \\\n build$swig_object_dir/${swig_file_only}_py.i" ; + foreach my $file ( @files_to_process ) { + (my $swig_file = $file) =~ s/\.[^.]*/_py.i/ ; + print MAKEFILE " \\\n build$swig_file" ; + $swig_file =~ s/i$/o/ ; + print PY_LINK_LIST "build$swig_file\n" ; } print MAKEFILE " @@ -221,53 +226,8 @@ SWIG_SRC = \$(subst .i,.cpp,\$(SWIG_I)) $swig_src_dir/top.cpp # SWIG_OBJECTS ================================================================= -SWIG_OBJECTS = \$(subst .cpp,.o,\$(SWIG_SRC)) $swig_src_dir/init_swig_modules.o\n" ; +SWIG_OBJECTS = \$(subst .cpp,.o,\$(SWIG_SRC)) $swig_src_dir/init_swig_modules.o - my %python_modules ; - $ii = 0 ; - foreach my $f ( @files_to_process ) { - - my ($swig_module_dir , $swig_file_only) ; - my ($swig_f) = $f ; - -# TODO: Add back python modules -# if ( $$sim_ref{python_module}{$f} ne "" ) { -# #print "python module for $f = $$sim_ref{python_module}{$f}\n" ; -# my ($temp_str) = $$sim_ref{python_module}{$f} ; -# $temp_str =~ s/\./\//g ; -# $swig_module_dir = "$temp_str/" ; -# $temp_str =~ $$sim_ref{python_module}{$f} ; -# $temp_str =~ s/\\/\./g ; -# push @{$python_modules{$temp_str}} , $f ; -# } else { -# $swig_module_dir = "" ; - push @{$python_modules{"root"}} , $f ; -# } - - # check if .sm file was accidentally ##included instead of #included - if ( rindex($swig_f,".sm") != -1 ) { - #trick_print($$sim_ref{fh}, "\nError: $swig_f should be in a #include not a ##include \n\n", "title_red", $$sim_ref{args}{v}) ; - exit -1 ; - } - $swig_f =~ s/([^\/]*)(?:\.h|\.H|\.hh|\.h\+\+|\.hxx|\.hpp)$/$1.i/ ; - $swig_file_only = $1 ; - my $link_py_obj = "build" . dirname($swig_f) . "/${swig_file_only}_py.o"; - print PY_LINK_LIST "$link_py_obj\n" ; - - $ii++ ; - } - - foreach $m ( keys %python_modules ) { - next if ( $m eq "root") ; - my ($temp_str) = $m ; - $temp_str =~ s/\./\//g ; - print MAKEFILE "$swig_sim_dir/$m:\n" ; - print MAKEFILE "\tmkdir -p \$@\n\n" ; - } - - my $wd = abs_path(cwd()) ; - - print MAKEFILE " \$(SWIG_OBJECTS): %.o: %.cpp \t\$(PRINT_COMPILE_SWIG) \t\@echo \$(TRICK_CPPC) \$(TRICK_CXXFLAGS) \$(TRICK_SYSTEM_CXXFLAGS) \$(SWIG_CFLAGS) -Wno-unused-parameter -c -o \$@ \$< >> \$(MAKE_OUT) @@ -354,12 +314,6 @@ LINK_LISTS += \$(LD_FILELIST)build/py_link_list print INITFILE "import os\n" ; print INITFILE "sys.path.append(os.getcwd() + \"/trick\")\n" ; - foreach $m ( keys %python_modules ) { - next if ( $m eq "root") ; - my ($temp_str) = $m ; - $temp_str =~ s/\./\//g ; - print INITFILE "sys.path.append(os.getcwd() + \"/trick/$temp_str\")\n" ; - } print INITFILE "\n" ; print INITFILE "import _sim_services\n" ; print INITFILE "from sim_services import *\n\n" ; @@ -369,25 +323,7 @@ LINK_LISTS += \$(LD_FILELIST)build/py_link_list print INITFILE "combine_cvars(all_cvars, cvar)\n" ; print INITFILE "cvar = None\n\n" ; - foreach $m ( keys %python_modules ) { - next if ( $m eq "root") ; - my ($temp_str) = $m ; - $temp_str =~ s/\//\./g ; - print INITFILE "import $temp_str\n" ; - } - print INITFILE "\n" ; - - foreach $f ( @{$python_modules{"root"}} ) { - next if ( $f =~ /S_source.hh/ ) ; - my $md5_sum = md5_hex($f) ; - print INITFILE "# $f\n" ; - print INITFILE "import _m${md5_sum}\n" ; - print INITFILE "from m${md5_sum} import *\n" ; - print INITFILE "combine_cvars(all_cvars, cvar)\n" ; - print INITFILE "cvar = None\n\n" ; - } - - foreach $f ( @ext_lib_files ) { + foreach $f ( @files_to_process, @ext_lib_files ) { print INITFILE "# $f\n" ; print INITFILE "import _m$md5s{$f}\n" ; print INITFILE "from m$md5s{$f} import *\n" ; @@ -411,29 +347,6 @@ LINK_LISTS += \$(LD_FILELIST)build/py_link_list print INITFILE "cvar = all_cvars\n\n" ; close INITFILE ; - foreach $m ( keys %python_modules ) { - next if ( $m eq "root") ; - my ($temp_str) = $m ; - $temp_str =~ s/\./\//g ; - if ( ! -e "trick/$temp_str" ) { - mkpath("trick/$temp_str", {mode=>0775}) ; - } - open INITFILE , ">trick/$temp_str/__init__.py" or return ; - foreach $f ( @{$python_modules{$m}} ) { - next if ( $f =~ /S_source.hh/ ) ; - my $md5_sum = md5_hex($f) ; - print INITFILE "# $f\n" ; - print INITFILE "import _m${md5_sum}\n" ; - print INITFILE "from m${md5_sum} import *\n\n" ; - } - close INITFILE ; - - while ( $temp_str =~ s/\/.*?$// ) { - open INITFILE , ">trick/$temp_str/__init__.py" or return ; - close initfile ; - } - } - return ; } diff --git a/share/trick/makefiles/Makefile.common b/share/trick/makefiles/Makefile.common index 7d2fcedb..3f5b4e56 100644 --- a/share/trick/makefiles/Makefile.common +++ b/share/trick/makefiles/Makefile.common @@ -1,4 +1,4 @@ -SHELL := /bin/sh +SHELL := /bin/bash CD := cd MV := /bin/mv RM := /bin/rm diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp index 359b9463..f1cd4784 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp @@ -398,6 +398,26 @@ unsigned int FieldDescription::getIO() { return io ; } +unsigned int FieldDescription::getChkpntIO() { + return io >> 2 & 3 ; +} + +bool FieldDescription::isWriteable() { + return io & 1; +} + +bool FieldDescription::isReadable() { + return io & 2; +} + +bool FieldDescription::isCheckpointable() { + return io & 4; +} + +bool FieldDescription::isRestorable() { + return io & 8; +} + std::string FieldDescription::getDescription() { return description ; } diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh index 811398ea..dff5fe86 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh @@ -58,6 +58,11 @@ class FieldDescription : public ConstructValues { bool isDashDashUnits() ; void setIO(unsigned int) ; unsigned int getIO() ; + unsigned int getChkpntIO() ; + bool isReadable() ; + bool isWriteable(); + bool isCheckpointable(); + bool isRestorable(); std::string getDescription() ; void setEnumString(std::string) ; std::string getEnumString() ; diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index de315d8b..1223114b 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -252,22 +252,6 @@ bool FieldVisitor::VisitPointerType(clang::PointerType *p) { return true; } -static std::string mangle_string( std::string in_name ) { - // convert characters not valid in a function name to underscores - std::string mangled_name = in_name ; - // Create a mangled type name, some characters have to converted to underscores. - std::replace( mangled_name.begin(), mangled_name.end(), '<', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), '>', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ' ', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ',', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ':', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), '*', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), ']', '_') ; - std::replace( mangled_name.begin(), mangled_name.end(), '[', '_') ; - - return mangled_name ; -} - std::map < std::string , std::string > FieldVisitor::processed_templates ; bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * crd ) { @@ -284,7 +268,7 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl * // Check to see if we've processed this template before // If not we need to create attributes for this template if ( processed_templates.find(in_name) == processed_templates.end() ) { - std::string mangled_name = mangle_string(in_name) ; + std::string mangled_name = sanitize(in_name) ; // save off the mangled name of this template to be used if another variable is the same template type processed_templates[in_name] = fdes->getContainerClass() + "_" + diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp index 211a78ae..4ba5d12a 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp @@ -1,4 +1,4 @@ - +#include #include #include "PrintFileContents10.hh" @@ -54,51 +54,51 @@ void PrintFileContents10::print_enum_attr(std::ostream & ostream , EnumValues * } /** Prints attributes for a field */ -void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescription * fdes ) { +void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescription & fdes ) { int array_dim ; - ostream << "{\"" << fdes->getName() << "\"" // name - << ", \"" << fdes->getFullyQualifiedMangledTypeName("__") << "\"" // type_name - << ", \"" << fdes->getUnits() << "\"" // units + ostream << "{\"" << fdes.getName() << "\"" // name + << ", \"" << fdes.getFullyQualifiedMangledTypeName("__") << "\"" // type_name + << ", \"" << fdes.getUnits() << "\"" // units << ", \"\", \"\"," << std::endl // alias, user_defined - << " \"" << fdes->getDescription() << "\"," << std::endl // description - << " " << fdes->getIO() // io - << "," << fdes->getEnumString() ; // type + << " \"" << fdes.getDescription() << "\"," << std::endl // description + << " " << fdes.getIO() // io + << "," << fdes.getEnumString() ; // type // There are several cases when printing the size of a variable. - if ( fdes->isBitField() ) { + if ( fdes.isBitField() ) { // bitfields are handled in 4 byte (32 bit) chunks ostream << ", 4" ; - } else if ( fdes->isRecord() or fdes->isEnum() or fdes->getTypeName().empty() ) { + } else if ( fdes.isRecord() or fdes.isEnum() or fdes.getTypeName().empty() ) { // records enums use io_src_get_size. The sentinel has no typename ostream << ", 0" ; } else { // print size of the underlying type - ostream << ", sizeof(" << fdes->getTypeName() << ")" ; + ostream << ", sizeof(" << fdes.getTypeName() << ")" ; } ostream << ", 0, 0, Language_CPP" ; // range_min, range_max, language - ostream << ", " << (fdes->isStatic() << 1) + (fdes->isDashDashUnits() << 2) << "," << std::endl ; // mods - if ( fdes->isBitField() ) { + ostream << ", " << (fdes.isStatic() << 1) + (fdes.isDashDashUnits() << 2) << "," << std::endl ; // mods + if ( fdes.isBitField() ) { // For bitfields we need the offset to start on 4 byte boundaries because that is what our // insert and extract bitfield routines work with. - ostream << " " << (fdes->getFieldOffset() - (fdes->getFieldOffset() % 32)) / 8 ; // offset + ostream << " " << (fdes.getFieldOffset() - (fdes.getFieldOffset() % 32)) / 8 ; // offset } else { - ostream << " " << (fdes->getFieldOffset() / 8) ; // offset + ostream << " " << (fdes.getFieldOffset() / 8) ; // offset } ostream << ", NULL" ; // attr - ostream << ", " << fdes->getNumDims() ; // num_index + ostream << ", " << fdes.getNumDims() ; // num_index ostream << ", {" ; - if ( fdes->isBitField() ) { - ostream << "{" << fdes->getBitFieldWidth() ; // size of bitfield - ostream << ", " << 32 - (fdes->getFieldOffset() % 32) - fdes->getBitFieldWidth() << "}" ; // start bit + if ( fdes.isBitField() ) { + ostream << "{" << fdes.getBitFieldWidth() ; // size of bitfield + ostream << ", " << 32 - (fdes.getFieldOffset() % 32) - fdes.getBitFieldWidth() << "}" ; // start bit } else { - array_dim = fdes->getArrayDim(0) ; + array_dim = fdes.getArrayDim(0) ; if ( array_dim < 0 ) array_dim = 0 ; ostream << "{" << array_dim << ", 0}" ; // index 0 } unsigned int ii ; for ( ii = 1 ; ii < 8 ; ii++ ) { - array_dim = fdes->getArrayDim(ii) ; + array_dim = fdes.getArrayDim(ii) ; if ( array_dim < 0 ) array_dim = 0 ; ostream << ", {" << array_dim << ", 0}" ; // indexes 1 through 7 } @@ -113,17 +113,14 @@ void PrintFileContents10::print_class_attr(std::ostream & ostream , ClassValues print_open_extern_c(ostream) ; ostream << "ATTRIBUTES attr" << c->getFullyQualifiedMangledTypeName("__") << "[] = {" << std::endl ; - for (auto& fieldDescription : c->getFieldDescriptions()) { - if ( determinePrintAttr(c , fieldDescription) ) { - print_field_attr(ostream, fieldDescription) ; + for (FieldDescription* fieldDescription : getPrintableFields(*c)) { + print_field_attr(ostream, *fieldDescription) ; ostream << "," << std::endl ; - } } // Print an empty sentinel attribute at the end of the class. - FieldDescription * new_fdes = new FieldDescription(std::string("")) ; + FieldDescription new_fdes(std::string("")) ; print_field_attr(ostream, new_fdes) ; ostream << " };" << std::endl ; - delete new_fdes ; print_close_extern_c(ostream) ; } @@ -163,15 +160,19 @@ void PrintFileContents10::print_field_init_attr_stmts( std::ostream & ostream , if ( fdes->isSTL() ) { auto print = [&](const std::string& field) { - ostream << prefix << field << " = " << field << "_" << fullyQualifiedMangledClassNameUnderscores + "_" + fieldName + " ;\n"; + ostream << prefix << field << " = " << field << "_" << fullyQualifiedMangledClassNameUnderscores + "_" + sanitize(fieldName) + " ;\n"; }; - print("checkpoint_stl"); - print("post_checkpoint_stl"); - print("restore_stl"); + if ( fdes->isCheckpointable() ) { + print("checkpoint_stl"); + print("post_checkpoint_stl"); + } - if ( fdes->hasSTLClear() ) { - print("clear_stl"); + if ( fdes->isRestorable() ) { + print("restore_stl"); + if ( fdes->hasSTLClear() ) { + print("clear_stl"); + } } } @@ -202,10 +203,8 @@ void PrintFileContents10::print_init_attr_func( std::ostream & ostream , ClassVa << " initialized = 1;\n\n" ; unsigned int ii = 0; - for ( auto field : cv->getFieldDescriptions() ) { - if ( determinePrintAttr(cv, field) ) { - print_field_init_attr_stmts(ostream, field, cv, ii++) ; - } + for ( FieldDescription* field : getPrintableFields(*cv) ) { + print_field_init_attr_stmts(ostream, field, cv, ii++) ; } print_inherited_add_attr_info(ostream, cv ) ; ostream << "}\n" ; @@ -299,37 +298,6 @@ void PrintFileContents10::print_io_src_delete( std::ostream & ostream , ClassVal } } -void PrintFileContents10::print_stl_helper_proto(std::ostream & ostream , ClassValues * cv ) { - auto& fieldDescriptions = cv->getFieldDescriptions(); - - if (!fieldDescriptions.size()) { - return; - } - - print_open_extern_c(ostream) ; - - for (auto& field : cv->getFieldDescriptions()) { - if ( field->isSTL() and determinePrintAttr(cv, field) ) { - const std::string classAndFieldName = cv->getFullyQualifiedMangledTypeName("__") + "_" + field->getName(); - - auto print = [&](const std::string& name) { - ostream << "void " << name << "_" << classAndFieldName - << "(void* start_address, const char* obj_name , const char* var_name);" << std::endl ; - }; - - print("checkpoint_stl"); - print("post_checkpoint_stl"); - print("restore_checkpoint_stl"); - - if ( field->hasSTLClear() ) { - ostream << "void clear_stl_" << classAndFieldName << "(void* start_address);" << std::endl ; - } - } - } - - print_close_extern_c(ostream) ; -} - void PrintFileContents10::print_checkpoint_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) { printStlFunction("checkpoint", "void* start_address, const char* obj_name , const char* var_name", "checkpoint_stl(*stl, obj_name, var_name)", ostream, *fdes, *cv); } @@ -347,7 +315,8 @@ void PrintFileContents10::print_clear_stl(std::ostream & ostream , FieldDescript } void PrintFileContents10::print_stl_helper(std::ostream & ostream , ClassValues * cv ) { - auto& fieldDescriptions = cv->getFieldDescriptions(); + std::vector fieldDescriptions = getPrintableFields(*cv, 0x3 << 2); + fieldDescriptions.erase(std::remove_if(fieldDescriptions.begin(), fieldDescriptions.end(), [](FieldDescription* field) {return !field->isSTL();}), fieldDescriptions.end()); if (!fieldDescriptions.size()) { return; @@ -355,10 +324,12 @@ void PrintFileContents10::print_stl_helper(std::ostream & ostream , ClassValues print_open_extern_c(ostream) ; - for (auto& field : fieldDescriptions) { - if ( field->isSTL() and determinePrintAttr(cv, field) ) { + for (FieldDescription* field : fieldDescriptions) { + if (field->isCheckpointable()) { print_checkpoint_stl(ostream, field, cv) ; print_post_checkpoint_stl(ostream, field, cv) ; + } + if (field->isRestorable()) { print_restore_stl(ostream, field, cv) ; if (field->hasSTLClear()) { print_clear_stl(ostream, field, cv) ; @@ -370,7 +341,6 @@ void PrintFileContents10::print_stl_helper(std::ostream & ostream , ClassValues } void PrintFileContents10::printClass( std::ostream & ostream , ClassValues * cv ) { - print_stl_helper_proto(ostream, cv) ; print_class_attr(ostream, cv) ; print_stl_helper(ostream, cv) ; print_init_attr_func(ostream, cv) ; @@ -434,7 +404,7 @@ void PrintFileContents10::printEnumMapFooter( std::ostream & ostream ) { void PrintFileContents10::printStlFunction(const std::string& name, const std::string& parameters, const std::string& call, std::ostream& ostream, FieldDescription& fieldDescription, ClassValues& classValues) { const std::string typeName = fieldDescription.getTypeName(); const std::string functionName = name + "_stl"; - ostream << "void " << functionName << "_" << classValues.getFullyQualifiedMangledTypeName("__") << "_" << fieldDescription.getName() + ostream << "void " << functionName << "_" << classValues.getFullyQualifiedMangledTypeName("__") << "_" << sanitize(fieldDescription.getName()) << "(" << parameters << ") {" << std::endl << " " << typeName << "* stl = reinterpret_cast<" << typeName << "*>(start_address);" << std::endl << " " << call << ";" << std::endl diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh index 96df008c..6802f43d 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.hh @@ -53,7 +53,7 @@ class PrintFileContents10 : public PrintFileContentsBase { void print_enum_attr(std::ostream & outfile , EnumValues * in_enum) ; /** Prints attributes for a field */ - void print_field_attr(std::ostream & outfile , FieldDescription * fdes ) ; + void print_field_attr(std::ostream & outfile , FieldDescription & fdes ) ; /** Prints class attributes */ void print_class_attr(std::ostream & outfile , ClassValues * in_class) ; @@ -86,9 +86,6 @@ class PrintFileContents10 : public PrintFileContentsBase { /** Prints the io_src_delete function */ void print_io_src_delete(std::ostream & outfile , ClassValues * cv ) ; - /** Prints stl helper function prototypes */ - void print_stl_helper_proto(std::ostream & outfile , ClassValues * in_class) ; - /** Prints stl helper function */ void print_stl_helper(std::ostream & outfile , ClassValues * in_class) ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.cpp b/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.cpp index 0404b66e..258b54e8 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.cpp @@ -41,7 +41,7 @@ void PrintFileContentsBase::print_units_map(std::ostream & ostream, ClassValues ostream << " }\n" ; } - ostream << "} um" << name << ";\n" ; + ostream << "} um" << name << ";\n\n" ; } /* Utility routines for printing */ @@ -56,38 +56,20 @@ void PrintFileContentsBase::print_close_extern_c(std::ostream & ostream) { /* internal function determines if a particular field is printable based on access to the field and the presense of init_attr friends. */ -bool PrintFileContentsBase::determinePrintAttr( ClassValues * c , FieldDescription * fdes ) { - if ( fdes->getTypeName().compare("void") and fdes->getIO() != 0 and fdes->getEnumString().compare("TRICK_VOID")) { - if ( global_compat15 or c->isCompat15()) { - if ( fdes->isInherited() ) { - return ((c->getHasInitAttrFriend() && fdes->getAccess() == clang::AS_protected) - || (fdes->getAccess() == clang::AS_public)) ; - } else { - return (c->getHasInitAttrFriend() - || (fdes->getAccess() == clang::AS_public)) ; - } - } else { - if ( fdes->isStatic() ) { - if ( fdes->isInherited() ) { - return ((c->getHasInitAttrFriend() && fdes->getAccess() == clang::AS_protected) - || (fdes->getAccess() == clang::AS_public)) ; - } else { - return (c->getHasInitAttrFriend() - || (fdes->getAccess() == clang::AS_public)) ; - } - } else { - return true ; - } - - } +bool PrintFileContentsBase::isPrintable( ClassValues * c , FieldDescription * fdes , unsigned int ioMask) { + if ( !(fdes->getIO() & ioMask) || !fdes->getTypeName().compare("void") || !fdes->getEnumString().compare("TRICK_VOID")) { + return false; } - return false ; + if ( fdes->getAccess() == clang::AS_public || (!fdes->isStatic() && !global_compat15 && !c->isCompat15())) { + return true; + } + return c->getHasInitAttrFriend() && ( !fdes->isInherited() || fdes->getAccess() == clang::AS_protected ) ; } -std::vector PrintFileContentsBase::getPrintableFields(ClassValues& classValues) { +std::vector PrintFileContentsBase::getPrintableFields(ClassValues& classValues, unsigned int ioMask) { std::vector results; for (auto& field : classValues.getFieldDescriptions()) { - if (determinePrintAttr(&classValues, field) and field->getUnits().compare("1")) { + if (isPrintable(&classValues, field)) { results.push_back(field); } } diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.hh b/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.hh index b985f8d3..14f25dac 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.hh +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.hh @@ -53,10 +53,10 @@ class PrintFileContentsBase { void print_close_extern_c(std::ostream & ostream) ; /* internal function determines if a particular field is printable */ - bool determinePrintAttr(ClassValues * c , FieldDescription *fdes) ; + bool isPrintable(ClassValues * c , FieldDescription *fdes , unsigned int ioMask = 0xFFFFFFF) ; /* gets a vector of fields that can be printed */ - std::vector getPrintableFields(ClassValues& classValues); + std::vector getPrintableFields(ClassValues& classValues, unsigned int ioMask = 0xFFFFFFF); } ; diff --git a/trick_source/codegen/Interface_Code_Gen/Utilities.cpp b/trick_source/codegen/Interface_Code_Gen/Utilities.cpp index 1a68baa8..bd9d2e0c 100644 --- a/trick_source/codegen/Interface_Code_Gen/Utilities.cpp +++ b/trick_source/codegen/Interface_Code_Gen/Utilities.cpp @@ -6,6 +6,14 @@ #include "Utilities.hh" +std::string sanitize(const std::string& text) { + std::string result = text; + for (char c : {'<', '>', ' ', ',', ':', '*', '[', ']'}) { + std::replace(result.begin(), result.end(), c, '_'); + } + return result ; +} + // removes leading and trailing whitespace from a string std::string trim(const std::string& str, const std::string& whitespace ) { size_t strBegin = str.find_first_not_of(whitespace); diff --git a/trick_source/codegen/Interface_Code_Gen/Utilities.hh b/trick_source/codegen/Interface_Code_Gen/Utilities.hh index d1772a0f..6c05cc04 100644 --- a/trick_source/codegen/Interface_Code_Gen/Utilities.hh +++ b/trick_source/codegen/Interface_Code_Gen/Utilities.hh @@ -14,6 +14,7 @@ enum Color { SKIP = 95 }; +std::string sanitize(const std::string&); std::string trim( const std::string& str, const std::string& whitespace = " \t\n\r" ) ; bool isInUserCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) ; bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) ;