New STL framework doesn't support const #293

So using consts as arguments to STLs causes errors in our io code and SWIG.
Added a check for const template arguments and going to ignore them for
both ICG and what we input to SWIG.
This commit is contained in:
Alex Lin 2016-08-25 08:42:43 -05:00
parent 0072e7d6f0
commit 858602fe01
2 changed files with 60 additions and 22 deletions

View File

@ -629,30 +629,33 @@ sub process_class($$$$$) {
}
if ( $template_var_def_str ne "" ) {
#print "*** template_var = $template_var_def_str ***\n" ;
$template_var_def_str =~ /(.*?)([_A-Za-z]\w*)\s*;/s ;
my ($template_full_type) = $1 ;
my ($var_name) = $2 ;
#print "*** var_name = $var_name ***\n" ;
$$new_contents_ref .= $template_var_def_str ;
# 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 ;
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*</ ;
my ($template_type) = $1 ;
# ignore some STL types and types that involve std::wstring
if ( (( $stls and ! exists $stl_names{$template_type})
or ( !$stls and ! exists $all_stl_names{$template_type} ))
and $template_full_type !~ /(std::)?wstring/ ) {
$template_full_type =~ /([_A-Za-z][:\w]*)\s*</ ;
my ($template_type) = $1 ;
# ignore some STL types and types that involve std::wstring
if ( (( $stls and ! exists $stl_names{$template_type})
or ( !$stls and ! exists $all_stl_names{$template_type} ))
and $template_full_type !~ /(std::)?wstring/ ) {
my ($template_type_no_sp) = $template_full_type ;
$template_type_no_sp =~ s/\s//g ;
#print "*** template_type_no_sp = $template_type_no_sp ***\n" ;
if ( ! exists $processed_templates{$template_type_no_sp} ) {
$$new_contents_ref .= "\n#define TRICK_SWIG_TEMPLATE_$class_name${var_name}_template\n" ;
$template_typedefs .= "\n#ifdef TRICK_SWIG_TEMPLATE_$class_name${var_name}_template\n" ;
$template_typedefs .= "\%template ($class_name${var_name}_template) $template_full_type ;\n" ;
$template_typedefs .= "#undef TRICK_SWIG_TEMPLATE_$class_name${var_name}_template\n" ;
$template_typedefs .= "#endif\n" ;
$processed_templates{$template_type_no_sp} = 1 ;
my ($template_type_no_sp) = $template_full_type ;
$template_type_no_sp =~ s/\s//g ;
#print "*** template_type_no_sp = $template_type_no_sp ***\n" ;
if ( ! exists $processed_templates{$template_type_no_sp} ) {
$$new_contents_ref .= "\n#define TRICK_SWIG_TEMPLATE_$class_name${var_name}_template\n" ;
$template_typedefs .= "\n#ifdef TRICK_SWIG_TEMPLATE_$class_name${var_name}_template\n" ;
$template_typedefs .= "\%template ($class_name${var_name}_template) $template_full_type ;\n" ;
$template_typedefs .= "#undef TRICK_SWIG_TEMPLATE_$class_name${var_name}_template\n" ;
$template_typedefs .= "#endif\n" ;
$processed_templates{$template_type_no_sp} = 1 ;
}
}
}
}

View File

@ -372,6 +372,35 @@ static bool checkForPrivateTemplateArgs( clang::ClassTemplateSpecializationDecl
return false ;
}
static bool checkForConstTemplateArgs( clang::ClassTemplateSpecializationDecl * ctsd ) {
unsigned int ii ;
for ( ii = 0 ; ii < ctsd->getTemplateArgs().size() ; ii++ ) {
const clang::TemplateArgument & ta = ctsd->getTemplateArgs().get(ii) ;
if ( ta.getKind() == clang::TemplateArgument::Type ) {
clang::QualType qt = ta.getAsType() ;
//std::cout << qt.getAsString() << std::endl ;
if ( qt.isConstQualified() ) {
//std::cout << " is const qualified" << std::endl ;
return true ;
} else {
//std::cout << " is public embedded class" << std::endl ;
const clang::Type * t = qt.getTypePtrOrNull() ;
if ( t != NULL ) {
if (t->getTypeClass() == clang::Type::Record ) {
clang::CXXRecordDecl * crd = t->getAsCXXRecordDecl() ;
if ( clang::isa<clang::ClassTemplateSpecializationDecl>(crd) ) {
clang::ClassTemplateSpecializationDecl * inner_ctsd ;
inner_ctsd = clang::cast<clang::ClassTemplateSpecializationDecl>(crd) ;
return checkForConstTemplateArgs(inner_ctsd) ;
}
}
}
}
}
}
return false ;
}
static std::map<std::string, bool> stl_classes = init_stl_classes() ;
bool FieldVisitor::VisitRecordType(clang::RecordType *rt) {
@ -430,6 +459,12 @@ bool FieldVisitor::VisitRecordType(clang::RecordType *rt) {
fdes->setIO(0) ;
}
// If the template is using a const type the STL checkpoint code will not compile,
// we need to ignore the variable.
if ( checkForConstTemplateArgs( ctsd )) {
fdes->setIO(0) ;
}
fdes->setEnumString("TRICK_STL") ;
fdes->setSTL(true) ;
fdes->setTypeName(tst_string) ;