Support default member initializer for templates

Closes #918
This commit is contained in:
Derek Bankieris 2019-12-11 13:43:01 -06:00
parent 230bd944ef
commit 5a7ec20606
5 changed files with 58 additions and 24 deletions

View File

@ -94,7 +94,7 @@ my $template_def = qr/template\s* # keyword template
/sx ; /sx ;
my $template_var_def = qr/(?:\:\:)?[_A-Za-z][:\w]*\s* # template name my $template_var_def = qr/(?:\:\:)?[_A-Za-z][:\w]*\s* # template name
<[\w\s\*,:<>]*>\s* # template parameters <[\w\s\*,:<>]*>\s* # template parameters
[_A-Za-z]\w*\s*; # var name ; [_A-Za-z]\w*\s*(?:[{=].*?)?; # var name ;
/sx ; /sx ;
# This list is the list of all STL types to ignore. # 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 ( $template_var_def_str ne "" ) {
# if there is a whiff of const in the template we are punting. # if there is a whiff of const in the template we are punting.
if ( $template_var_def_str !~ /^const|[<,\s]const\s/ ) { if ( $template_var_def_str !~ /^const|[<,\s]const\s/ ) {
#print "*** template_var = $template_var_def_str ***\n" ; $template_var_def_str =~ /(.*?>)\s*([_A-Za-z]\w*).*?;/s ;
$template_var_def_str =~ /(.*?)([_A-Za-z]\w*)\s*;/s ;
my ($template_full_type) = $1 ; my ($template_full_type) = $1 ;
my ($var_name) = $2 ; my ($var_name) = $2 ;
#print "*** var_name = $var_name ***\n" ;
$$new_contents_ref .= $template_var_def_str ; $$new_contents_ref .= $template_var_def_str ;
$template_full_type =~ /([_A-Za-z][:\w]*)\s*</ ; $template_full_type =~ /([_A-Za-z][:\w]*)\s*</ ;

View File

@ -0,0 +1,20 @@
#include "sim_objects/default_trick_sys.sm"
##include "Foo.hh"
class Sandbox : public Trick::SimObject {
public:
// These should get TRICK_SWIG_TEMPLATE lines
Foo<int> foo{1};
Foo<int> foo2 = {2};
Foo<int> foo3;
// Functions should not
template<class T> void bar();
private:
void operator=(const Sandbox&);
};
Sandbox sandbox;

View File

@ -0,0 +1 @@
TRICK_CXXFLAGS += -Imodels -std=c++11

View File

@ -0,0 +1,15 @@
template <class T>
class Foo {
public:
Foo() {}
Foo(int i) {
(void)i;
}
private:
void operator=(const Foo&);
};

View File

@ -1,8 +1,22 @@
TRICK_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))..) TRICK_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))..)
export TRICK_HOST_CPU := $(shell $(TRICK_HOME)/bin/trick-gte TRICK_HOST_CPU) export TRICK_HOST_CPU := $(shell $(TRICK_HOME)/bin/trick-gte TRICK_HOST_CPU)
# List out sims we want to compile SIMS_TO_COMPILE_ONLY = \
COMPILE_DIRS = \ 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_demo_sdefine \
SIM_events \ SIM_events \
SIM_python_namespace \ SIM_python_namespace \
@ -16,20 +30,6 @@ COMPILE_DIRS = \
SIM_test_templates \ SIM_test_templates \
SIM_threads 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 # Sims with problems, no purpose, or maybe shouldn't be a test
# SIM_leaks ( should be deleted ) # SIM_leaks ( should be deleted )
# SIM_test_varserv ( not sure what it is testing ) # SIM_test_varserv ( not sure what it is testing )
@ -39,20 +39,20 @@ SIMS_NEEDING_TEST = \
# This test is temporarily sitting out until fixed. # This test is temporarily sitting out until fixed.
# SIM_test_varserv # SIM_test_varserv
EXECUTABLES = $(addsuffix /T_main_${TRICK_HOST_CPU}_test.exe, $(COMPILE_DIRS) $(SIMS_NEEDING_TEST)) 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, $(COMPILE_DIRS))) UNIT_TEST_RESULTS = $(addprefix $(TRICK_HOME)/trick_test/, $(addsuffix .xml, $(SIMS_TO_COMPILE_AND_RUN)))
test: $(EXECUTABLES) $(UNIT_TEST_RESULTS) data_record_results test: $(EXECUTABLES) $(UNIT_TEST_RESULTS) data_record_results
clean: clean:
rm -f $(UNIT_TEST_RESULTS) 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 \ if [ -f "$$i/"[Mm]"akefile" ] ; then \
$(MAKE) -C $$i spotless ; \ $(MAKE) -C $$i spotless ; \
fi \ fi \
done done
- for i in $(SIMS_NEEDING_TEST) ; do \ - for i in $(SIMS_TO_COMPILE_ONLY) ; do \
if [ -f "$$i/"[Mm]"akefile" ] ; then \ if [ -f "$$i/"[Mm]"akefile" ] ; then \
$(MAKE) -C $$i spotless ; \ $(MAKE) -C $$i spotless ; \
fi \ fi \