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:
parent
85ae38ccee
commit
2e01562965
2 changed files with 107 additions and 11 deletions
|
|
@ -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
|
%module cpp0x_variadic_templates
|
||||||
|
|
||||||
|
////////////////////////
|
||||||
|
// Variadic templates //
|
||||||
|
////////////////////////
|
||||||
%inline %{
|
%inline %{
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
template<typename... Values>
|
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>;
|
||||||
|
|
|
||||||
|
|
@ -4814,6 +4814,7 @@ declarator : pointer notso_direct_declarator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| LAND notso_direct_declarator {
|
| LAND notso_direct_declarator {
|
||||||
|
/* Introduced in C++0x, move operator && */
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
$$.type = NewStringEmpty();
|
$$.type = NewStringEmpty();
|
||||||
SwigType_add_reference($$.type);
|
SwigType_add_reference($$.type);
|
||||||
|
|
@ -5538,6 +5539,11 @@ valexpr : exprnum { $$ = $1; }
|
||||||
$$.val = NewStringf("sizeof(%s)",SwigType_str($3,0));
|
$$.val = NewStringf("sizeof(%s)",SwigType_str($3,0));
|
||||||
$$.type = T_ULONG;
|
$$.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; }
|
| exprcompound { $$ = $1; }
|
||||||
| CHARCONST {
|
| CHARCONST {
|
||||||
$$.val = NewString($1);
|
$$.val = NewString($1);
|
||||||
|
|
@ -5792,6 +5798,30 @@ base_specifier : opt_virtual idcolon {
|
||||||
cparse_line,"%s inheritance ignored.\n", $2);
|
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"; }
|
access_specifier : PUBLIC { $$ = (char*)"public"; }
|
||||||
|
|
@ -5903,21 +5933,24 @@ mem_initializer_list : mem_initializer
|
||||||
| mem_initializer_list COMMA mem_initializer
|
| mem_initializer_list COMMA mem_initializer
|
||||||
;
|
;
|
||||||
|
|
||||||
mem_initializer : idcolon LPAREN {
|
mem_initializer : idcolon LPAREN parms RPAREN {
|
||||||
skip_balanced('(',')');
|
/* skip_balanced('(',')');
|
||||||
Clear(scanner_ccode);
|
Clear(scanner_ccode);
|
||||||
}
|
*/ }
|
||||||
| idcolon LBRACE {
|
| idcolon LBRACE parms RBRACE {
|
||||||
/* Uniform initialization. eg.
|
/* Uniform initialization in C++0x.
|
||||||
|
Example:
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
MyStruct(int x, double y) : x_{x}, y_{y} {}
|
MyStruct(int x, double y) : x_{x}, y_{y} {}
|
||||||
int x_;
|
int x_;
|
||||||
double y_;
|
double y_;
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
skip_balanced('{','}');
|
/* skip_balanced('{','}');
|
||||||
Clear(scanner_ccode);
|
Clear(scanner_ccode);
|
||||||
}
|
*/ }
|
||||||
|
| idcolon LPAREN parms RPAREN PERIOD PERIOD PERIOD { }
|
||||||
|
| idcolon LBRACE parms RBRACE PERIOD PERIOD PERIOD { }
|
||||||
;
|
;
|
||||||
|
|
||||||
template_decl : LESSTHAN valparms GREATERTHAN {
|
template_decl : LESSTHAN valparms GREATERTHAN {
|
||||||
|
|
@ -5946,6 +5979,10 @@ idcolon : idtemplate idcolontail {
|
||||||
$$ = NewStringf("::%s%s",$3,$4);
|
$$ = NewStringf("::%s%s",$3,$4);
|
||||||
Delete($4);
|
Delete($4);
|
||||||
}
|
}
|
||||||
|
| PERIOD PERIOD PERIOD idtemplate {
|
||||||
|
/* Introduced in C++0x, variadic constructor args */
|
||||||
|
$$ = NewString($4);
|
||||||
|
}
|
||||||
| idtemplate {
|
| idtemplate {
|
||||||
$$ = NewString($1);
|
$$ = NewString($1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue