Added variadic '...' syntax for inheritance introduced in C++0x.

Added sizeof... syntax introduced in C++0x.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@11467 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Matevz Jekovec 2009-07-29 13:38:22 +00:00
commit 2e01562965
2 changed files with 107 additions and 11 deletions

View file

@ -1,8 +1,67 @@
/* This testcase checks whether Swig correctly parses and generates the code
for variadic templates. This covers the variadic number of arguments inside
the template brackets, new functions sizeof... and multiple inheritance
using variadic number of classes.
*/
%module cpp0x_variadic_templates
////////////////////////
// Variadic templates //
////////////////////////
%inline %{
#include <vector>
#include <string>
#include <map>
template<typename... Values>
class tuple {
class MultiArgs {
};
class MultiArgs<int, std::vector<int>, std::map<std::string, std::vector<int>>> multiArgs;
%}
// TODO
//%template (MultiArgs) MultiArgs<int, std::vector<int>, std::map<std::string, std::vector<int>>>;
////////////////////////
// Variadic sizeof... //
////////////////////////
%inline %{
template<typename ...Args> struct SizeOf {
static const int size = sizeof...(Args);
};
%}
// TODO
//%template (SizeOf) SizeOf<int, int>;
//////////////////////////
// Variadic inheritance //
//////////////////////////
%inline %{
class A {
public:
A() {
a = 100;
}
int a;
};
class B {
public:
B() {
b = 200;
}
int b;
};
template <typename... BaseClasses> class MultiInherit : public BaseClasses... {
public:
MultiInherit(BaseClasses&&... baseClasses) : BaseClasses(baseClasses)... {}
};
%}
// TODO
//%template (MultiInherit) MultiInherit<A,B>;

View file

@ -1,4 +1,4 @@
/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
@ -1549,7 +1549,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) {
/* Misc */
%type <dtype> initializer cpp_const ;
%type <id> storage_class;
%type <pl> parms ptail rawparms varargs_parms;
%type <pl> parms ptail rawparms varargs_parms ;
%type <pl> templateparameters templateparameterstail;
%type <p> parm valparm rawvalparms valparms valptail ;
%type <p> typemap_parm tm_list tm_tail ;
@ -4814,6 +4814,7 @@ declarator : pointer notso_direct_declarator {
}
}
| LAND notso_direct_declarator {
/* Introduced in C++0x, move operator && */
$$ = $2;
$$.type = NewStringEmpty();
SwigType_add_reference($$.type);
@ -5538,6 +5539,11 @@ valexpr : exprnum { $$ = $1; }
$$.val = NewStringf("sizeof(%s)",SwigType_str($3,0));
$$.type = T_ULONG;
}
| SIZEOF PERIOD PERIOD PERIOD LPAREN type parameter_declarator RPAREN {
SwigType_push($6,$7.type);
$$.val = NewStringf("sizeof...(%s)",SwigType_str($6,0));
$$.type = T_ULONG;
}
| exprcompound { $$ = $1; }
| CHARCONST {
$$.val = NewString($1);
@ -5792,6 +5798,30 @@ base_specifier : opt_virtual idcolon {
cparse_line,"%s inheritance ignored.\n", $2);
}
}
| opt_virtual idcolon PERIOD PERIOD PERIOD { /* Variadic inheritance */
$$ = NewHash();
Setfile($$,cparse_file);
Setline($$,cparse_line);
Setattr($$,"name",$2);
if (last_cpptype && (Strcmp(last_cpptype,"struct") != 0)) {
Setattr($$,"access","private");
Swig_warning(WARN_PARSE_NO_ACCESS,cparse_file,cparse_line,
"No access specifier given for base class %s (ignored).\n",$2);
} else {
Setattr($$,"access","public");
}
}
| opt_virtual access_specifier opt_virtual idcolon PERIOD PERIOD PERIOD { /* Variadic inheritance */
$$ = NewHash();
Setfile($$,cparse_file);
Setline($$,cparse_line);
Setattr($$,"name",$4);
Setattr($$,"access",$2);
if (Strcmp($2,"public") != 0) {
Swig_warning(WARN_PARSE_PRIVATE_INHERIT, cparse_file,
cparse_line,"%s inheritance ignored.\n", $2);
}
}
;
access_specifier : PUBLIC { $$ = (char*)"public"; }
@ -5903,21 +5933,24 @@ mem_initializer_list : mem_initializer
| mem_initializer_list COMMA mem_initializer
;
mem_initializer : idcolon LPAREN {
skip_balanced('(',')');
mem_initializer : idcolon LPAREN parms RPAREN {
/* skip_balanced('(',')');
Clear(scanner_ccode);
}
| idcolon LBRACE {
/* Uniform initialization. eg.
*/ }
| idcolon LBRACE parms RBRACE {
/* Uniform initialization in C++0x.
Example:
struct MyStruct {
MyStruct(int x, double y) : x_{x}, y_{y} {}
int x_;
double y_;
};
*/
skip_balanced('{','}');
/* skip_balanced('{','}');
Clear(scanner_ccode);
}
*/ }
| idcolon LPAREN parms RPAREN PERIOD PERIOD PERIOD { }
| idcolon LBRACE parms RBRACE PERIOD PERIOD PERIOD { }
;
template_decl : LESSTHAN valparms GREATERTHAN {
@ -5936,7 +5969,7 @@ idstring : ID { $$ = $1; }
idstringopt : idstring { $$ = $1; }
| empty { $$ = 0; }
;
idcolon : idtemplate idcolontail {
$$ = 0;
if (!$$) $$ = NewStringf("%s%s", $1,$2);
@ -5946,6 +5979,10 @@ idcolon : idtemplate idcolontail {
$$ = NewStringf("::%s%s",$3,$4);
Delete($4);
}
| PERIOD PERIOD PERIOD idtemplate {
/* Introduced in C++0x, variadic constructor args */
$$ = NewString($4);
}
| idtemplate {
$$ = NewString($1);
}