Support ternary conditionals (a ? b : c) in constant expressions.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9330 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
fb93e2ff91
commit
4c1b1332a5
4 changed files with 22 additions and 3 deletions
|
|
@ -10,9 +10,9 @@ Version 1.3.30 (in progress)
|
|||
%template(x_1plus2) x<1+2>;
|
||||
|
||||
Also, constant expressions can now include comparisons (>, <, >=,
|
||||
<=, !=, ==) and modulus (%).
|
||||
<=, !=, ==), modulus (%), and ternary conditionals (a ? b : c).
|
||||
|
||||
Fixes bugs #646275, #925555, #956282.
|
||||
Fixes bugs #646275, #925555, #956282, #994301.
|
||||
|
||||
09/22/2006: wsfulton
|
||||
Fix %ignore on director methods - Bugs #1546254, #1543533
|
||||
|
|
|
|||
|
|
@ -46,7 +46,17 @@ class X {};
|
|||
%}
|
||||
|
||||
|
||||
// bug 1338527
|
||||
// bug #994301
|
||||
|
||||
|
||||
%inline %{
|
||||
template<int foo> class X994301 {};
|
||||
%}
|
||||
|
||||
%template(X994301_ternary) X<(7 >= 4) ? 1 + 1 : 1>;
|
||||
|
||||
|
||||
// bug #1338527 (still broken)
|
||||
|
||||
|
||||
%inline %{
|
||||
|
|
|
|||
|
|
@ -605,6 +605,7 @@ int yylook(void) {
|
|||
else if (c == '0') state = 83; /* An octal or hex value */
|
||||
else if (c == '\'') state = 9; /* A character constant */
|
||||
else if (c == '.') state = 100; /* Maybe a number, maybe just a period */
|
||||
else if (c == '?') return (QUESTIONMARK); /* Ternary conditional operator */
|
||||
else if (c == '`') {
|
||||
state = 200; /* Back-tick type */
|
||||
yylen = 0;
|
||||
|
|
|
|||
|
|
@ -1390,6 +1390,7 @@ static void default_arguments(Node *n) {
|
|||
%token WARN
|
||||
%token LESSTHAN GREATERTHAN MODULO DELETE_KW
|
||||
%token LESSTHANOREQUALTO GREATERTHANOREQUALTO EQUALTO NOTEQUALTO
|
||||
%token QUESTIONMARK
|
||||
%token TYPES PARMS
|
||||
%token NONID DSTAR DCNOT
|
||||
%token <ivalue> TEMPLATE
|
||||
|
|
@ -1398,6 +1399,7 @@ static void default_arguments(Node *n) {
|
|||
%token PARSETYPE PARSEPARM PARSEPARMS
|
||||
|
||||
%left CAST
|
||||
%left QUESTIONMARK
|
||||
%left LOR
|
||||
%left LAND
|
||||
%left OR
|
||||
|
|
@ -5445,6 +5447,12 @@ exprcompound : expr PLUS expr {
|
|||
$$.val = NewStringf("%s<=%s",$1.val,$3.val);
|
||||
$$.type = T_INT;
|
||||
}
|
||||
| expr QUESTIONMARK expr COLON expr {
|
||||
$$.val = NewStringf("%s?%s:%s", $1.val, $3.val, $5.val);
|
||||
/* This may not be exactly right, but is probably good enough
|
||||
* for the purposes of parsing constant expressions. */
|
||||
$$.type = promote($3.type, $5.type);
|
||||
}
|
||||
| MINUS expr %prec UMINUS {
|
||||
$$.val = NewStringf("-%s",$2.val);
|
||||
$$.type = $2.type;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue