From 5a7ec20606cfbb92b7884322f9824b6cd61e2ce1 Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Wed, 11 Dec 2019 13:43:01 -0600 Subject: [PATCH] Support default member initializer for templates Closes #918 --- libexec/trick/convert_swig | 6 +-- test/SIM_default_member_initializer/S_define | 20 ++++++++++ .../S_overrides.mk | 1 + .../models/Foo.hh | 15 +++++++ test/makefile | 40 +++++++++---------- 5 files changed, 58 insertions(+), 24 deletions(-) create mode 100644 test/SIM_default_member_initializer/S_define create mode 100644 test/SIM_default_member_initializer/S_overrides.mk create mode 100644 test/SIM_default_member_initializer/models/Foo.hh diff --git a/libexec/trick/convert_swig b/libexec/trick/convert_swig index 2e11fa9a..7003c0af 100755 --- a/libexec/trick/convert_swig +++ b/libexec/trick/convert_swig @@ -94,7 +94,7 @@ my $template_def = qr/template\s* # keyword template /sx ; my $template_var_def = qr/(?:\:\:)?[_A-Za-z][:\w]*\s* # template name <[\w\s\*,:<>]*>\s* # template parameters - [_A-Za-z]\w*\s*; # var name ; + [_A-Za-z]\w*\s*(?:[{=].*?)?; # var name ; /sx ; # This list is the list of all STL types to ignore. @@ -619,11 +619,9 @@ sub process_class($$$$$) { if ( $template_var_def_str ne "" ) { # if there is a whiff of const in the template we are punting. if ( $template_var_def_str !~ /^const|[<,\s]const\s/ ) { - #print "*** template_var = $template_var_def_str ***\n" ; - $template_var_def_str =~ /(.*?)([_A-Za-z]\w*)\s*;/s ; + $template_var_def_str =~ /(.*?>)\s*([_A-Za-z]\w*).*?;/s ; my ($template_full_type) = $1 ; my ($var_name) = $2 ; - #print "*** var_name = $var_name ***\n" ; $$new_contents_ref .= $template_var_def_str ; $template_full_type =~ /([_A-Za-z][:\w]*)\s* foo{1}; + Foo foo2 = {2}; + Foo foo3; + + // Functions should not + template void bar(); + + private: + void operator=(const Sandbox&); + +}; + +Sandbox sandbox; diff --git a/test/SIM_default_member_initializer/S_overrides.mk b/test/SIM_default_member_initializer/S_overrides.mk new file mode 100644 index 00000000..84cab458 --- /dev/null +++ b/test/SIM_default_member_initializer/S_overrides.mk @@ -0,0 +1 @@ +TRICK_CXXFLAGS += -Imodels -std=c++11 diff --git a/test/SIM_default_member_initializer/models/Foo.hh b/test/SIM_default_member_initializer/models/Foo.hh new file mode 100644 index 00000000..2ec12170 --- /dev/null +++ b/test/SIM_default_member_initializer/models/Foo.hh @@ -0,0 +1,15 @@ +template +class Foo { + + public: + + Foo() {} + + Foo(int i) { + (void)i; + } + + private: + void operator=(const Foo&); + +}; diff --git a/test/makefile b/test/makefile index c2e8b138..8ccb43a1 100644 --- a/test/makefile +++ b/test/makefile @@ -1,8 +1,22 @@ TRICK_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))..) export TRICK_HOST_CPU := $(shell $(TRICK_HOME)/bin/trick-gte TRICK_HOST_CPU) -# List out sims we want to compile -COMPILE_DIRS = \ +SIMS_TO_COMPILE_ONLY = \ + SIM_alloc_test \ + SIM_default_member_initializer \ + SIM_demo_inputfile \ + SIM_exclusion_mechanisms \ + SIM_isystem \ + SIM_measurement_units \ + SIM_parse_s_define \ + SIM_target_specific_variables \ + SIM_test_abstract \ + SIM_test_inherit \ + SIM_test_ip2 \ + SIM_threads_simple \ + SIM_trickcomm + +SIMS_TO_COMPILE_AND_RUN = \ SIM_demo_sdefine \ SIM_events \ SIM_python_namespace \ @@ -16,20 +30,6 @@ COMPILE_DIRS = \ SIM_test_templates \ SIM_threads -SIMS_NEEDING_TEST = \ - SIM_alloc_test \ - SIM_demo_inputfile \ - SIM_exclusion_mechanisms \ - SIM_isystem \ - SIM_measurement_units \ - SIM_parse_s_define \ - SIM_target_specific_variables \ - SIM_test_abstract \ - SIM_test_inherit \ - SIM_test_ip2 \ - SIM_threads_simple \ - SIM_trickcomm - # Sims with problems, no purpose, or maybe shouldn't be a test # SIM_leaks ( should be deleted ) # SIM_test_varserv ( not sure what it is testing ) @@ -39,20 +39,20 @@ SIMS_NEEDING_TEST = \ # This test is temporarily sitting out until fixed. # SIM_test_varserv -EXECUTABLES = $(addsuffix /T_main_${TRICK_HOST_CPU}_test.exe, $(COMPILE_DIRS) $(SIMS_NEEDING_TEST)) -UNIT_TEST_RESULTS = $(addprefix $(TRICK_HOME)/trick_test/, $(addsuffix .xml, $(COMPILE_DIRS))) +EXECUTABLES = $(addsuffix /T_main_${TRICK_HOST_CPU}_test.exe, $(SIMS_TO_COMPILE_AND_RUN) $(SIMS_TO_COMPILE_ONLY)) +UNIT_TEST_RESULTS = $(addprefix $(TRICK_HOME)/trick_test/, $(addsuffix .xml, $(SIMS_TO_COMPILE_AND_RUN))) test: $(EXECUTABLES) $(UNIT_TEST_RESULTS) data_record_results clean: rm -f $(UNIT_TEST_RESULTS) - - for i in $(COMPILE_DIRS) ; do \ + - for i in $(SIMS_TO_COMPILE_AND_RUN) ; do \ if [ -f "$$i/"[Mm]"akefile" ] ; then \ $(MAKE) -C $$i spotless ; \ fi \ done - - for i in $(SIMS_NEEDING_TEST) ; do \ + - for i in $(SIMS_TO_COMPILE_ONLY) ; do \ if [ -f "$$i/"[Mm]"akefile" ] ; then \ $(MAKE) -C $$i spotless ; \ fi \