Allow <, >, <=, >=, !=, ==, and % in constant expressions.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9329 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
f4bc2780b1
commit
fb93e2ff91
4 changed files with 90 additions and 21 deletions
|
|
@ -1,6 +1,19 @@
|
||||||
Version 1.3.30 (in progress)
|
Version 1.3.30 (in progress)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
09/23/2006: olly
|
||||||
|
Templates can now be instantiated using negative numbers and
|
||||||
|
constant expressions, e.g.:
|
||||||
|
|
||||||
|
template<int q> class x {};
|
||||||
|
%template(x_minus1) x<-1>;
|
||||||
|
%template(x_1plus2) x<1+2>;
|
||||||
|
|
||||||
|
Also, constant expressions can now include comparisons (>, <, >=,
|
||||||
|
<=, !=, ==) and modulus (%).
|
||||||
|
|
||||||
|
Fixes bugs #646275, #925555, #956282.
|
||||||
|
|
||||||
09/22/2006: wsfulton
|
09/22/2006: wsfulton
|
||||||
Fix %ignore on director methods - Bugs #1546254, #1543533
|
Fix %ignore on director methods - Bugs #1546254, #1543533
|
||||||
|
|
||||||
|
|
@ -14,15 +27,7 @@ Version 1.3.30 (in progress)
|
||||||
Fix out of source builds - bug #1544718
|
Fix out of source builds - bug #1544718
|
||||||
|
|
||||||
09/20/2006: olly
|
09/20/2006: olly
|
||||||
[ALL] Templates can now be instantiated using negative numbers and
|
Treat a nested class definition as a forward declaration rather
|
||||||
constant expressions, e.g.:
|
|
||||||
|
|
||||||
template<int q> class x {};
|
|
||||||
%template(x_minus1) x<-1>;
|
|
||||||
%template(x_1plus2) x<1+2>;
|
|
||||||
|
|
||||||
09/20/2006: olly
|
|
||||||
[ALL] Treat a nested class definition as a forward declaration rather
|
|
||||||
than ignoring it completely, so that we generate correct code for
|
than ignoring it completely, so that we generate correct code for
|
||||||
passing opaque pointers to the nested class (fixes SF bug #909387).
|
passing opaque pointers to the nested class (fixes SF bug #909387).
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,25 @@ class X {};
|
||||||
%template(X_1024div8) X<1024/8>;
|
%template(X_1024div8) X<1024/8>;
|
||||||
|
|
||||||
|
|
||||||
|
// bug #646275
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
template<typename Type, short Rank>
|
||||||
|
class Test {
|
||||||
|
/**** conditional return type TestRm1 =
|
||||||
|
Test<Type,Rank-1> oder Type: ****/
|
||||||
|
template<bool cond, class T1, class T2> class
|
||||||
|
CondRetType { typedef T1 TestRm1; };
|
||||||
|
template<class T1, class T2> class
|
||||||
|
CondRetType<false, T1, T2> { typedef T2 TestRm1; };
|
||||||
|
typedef typename CondRetType< Rank!=1,
|
||||||
|
Test<Type,Rank-1>, Type>::TestRm1 TestRm1;
|
||||||
|
public:
|
||||||
|
Test() {};
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
// bug 1338527
|
// bug 1338527
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -572,7 +572,7 @@ int yylook(void) {
|
||||||
num_brace++;
|
num_brace++;
|
||||||
return (LBRACE);
|
return (LBRACE);
|
||||||
}
|
}
|
||||||
else if (c == '=') return (EQUAL);
|
else if (c == '=') state = 63;
|
||||||
else if (c == '+') return (PLUS);
|
else if (c == '+') return (PLUS);
|
||||||
else if (c == '-') return (MINUS);
|
else if (c == '-') return (MINUS);
|
||||||
else if (c == '&') {
|
else if (c == '&') {
|
||||||
|
|
@ -587,7 +587,7 @@ int yylook(void) {
|
||||||
else if (c == '~') {
|
else if (c == '~') {
|
||||||
return (NOT);
|
return (NOT);
|
||||||
}
|
}
|
||||||
else if (c == '!') return (LNOT);
|
else if (c == '!') state = 62;
|
||||||
else if (c == '\\') {
|
else if (c == '\\') {
|
||||||
state = 99;
|
state = 99;
|
||||||
}
|
}
|
||||||
|
|
@ -802,20 +802,32 @@ int yylook(void) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 60: /* shift operators */
|
case 60: /* < - less than or less than or equal to or left shift operator */
|
||||||
if ((c = nextchar()) == 0) return (0);
|
if ((c = nextchar()) == 0) return (0);
|
||||||
if (c == '<') return LSHIFT;
|
if (c == '<') return LSHIFT;
|
||||||
|
if (c == '=') return LESSTHANOREQUALTO;
|
||||||
else {
|
else {
|
||||||
retract(1);
|
retract(1);
|
||||||
return LESSTHAN;
|
return LESSTHAN;
|
||||||
}
|
}
|
||||||
case 61:
|
case 61: /* > - greater than or greater or equal to or right shift operator */
|
||||||
if ((c = nextchar()) == 0) return (0);
|
if ((c = nextchar()) == 0) return (0);
|
||||||
if (c == '>') return RSHIFT;
|
if (c == '>') return RSHIFT;
|
||||||
|
if (c == '=') return GREATERTHANOREQUALTO;
|
||||||
else {
|
else {
|
||||||
retract(1);
|
retract(1);
|
||||||
return GREATERTHAN;
|
return GREATERTHAN;
|
||||||
}
|
}
|
||||||
|
case 62: /* ! - logical not or not equal to */
|
||||||
|
if ((c = nextchar()) == 0) return (0);
|
||||||
|
if (c == '=') return NOTEQUALTO;
|
||||||
|
retract(1);
|
||||||
|
return LNOT;
|
||||||
|
case 63: /* = - equal (assignment) or equal to */
|
||||||
|
if ((c = nextchar()) == 0) return (0);
|
||||||
|
if (c == '=') return EQUALTO;
|
||||||
|
retract(1);
|
||||||
|
return EQUAL;
|
||||||
case 7: /* Identifier */
|
case 7: /* Identifier */
|
||||||
if ((c = nextchar()) == 0) return(0);
|
if ((c = nextchar()) == 0) return(0);
|
||||||
if (isalnum(c) || (c == '_') || (c == '.') || (c == '$')) {
|
if (isalnum(c) || (c == '_') || (c == '.') || (c == '$')) {
|
||||||
|
|
|
||||||
|
|
@ -1389,6 +1389,7 @@ static void default_arguments(Node *n) {
|
||||||
%token TYPEMAP EXCEPT ECHO APPLY CLEAR SWIGTEMPLATE FRAGMENT
|
%token TYPEMAP EXCEPT ECHO APPLY CLEAR SWIGTEMPLATE FRAGMENT
|
||||||
%token WARN
|
%token WARN
|
||||||
%token LESSTHAN GREATERTHAN MODULO DELETE_KW
|
%token LESSTHAN GREATERTHAN MODULO DELETE_KW
|
||||||
|
%token LESSTHANOREQUALTO GREATERTHANOREQUALTO EQUALTO NOTEQUALTO
|
||||||
%token TYPES PARMS
|
%token TYPES PARMS
|
||||||
%token NONID DSTAR DCNOT
|
%token NONID DSTAR DCNOT
|
||||||
%token <ivalue> TEMPLATE
|
%token <ivalue> TEMPLATE
|
||||||
|
|
@ -1402,9 +1403,11 @@ static void default_arguments(Node *n) {
|
||||||
%left OR
|
%left OR
|
||||||
%left XOR
|
%left XOR
|
||||||
%left AND
|
%left AND
|
||||||
|
%left EQUALTO NOTEQUALTO
|
||||||
|
%left GREATERTHAN LESSTHAN GREATERTHANOREQUALTO LESSTHANOREQUALTO
|
||||||
%left LSHIFT RSHIFT
|
%left LSHIFT RSHIFT
|
||||||
%left PLUS MINUS
|
%left PLUS MINUS
|
||||||
%left STAR SLASH
|
%left STAR SLASH MODULUS
|
||||||
%left UMINUS NOT LNOT
|
%left UMINUS NOT LNOT
|
||||||
%left DCOLON
|
%left DCOLON
|
||||||
|
|
||||||
|
|
@ -5269,7 +5272,7 @@ etype : expr {
|
||||||
this does allow us to parse many constant declarations.
|
this does allow us to parse many constant declarations.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
expr : valexpr { $$ = $1; }
|
expr : valexpr { $$ = $1; }
|
||||||
| type {
|
| type {
|
||||||
Node *n;
|
Node *n;
|
||||||
$$.val = $1;
|
$$.val = $1;
|
||||||
|
|
@ -5289,12 +5292,12 @@ expr : valexpr { $$ = $1; }
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
valexpr : exprnum { $$ = $1; }
|
valexpr : exprnum { $$ = $1; }
|
||||||
| string {
|
| string {
|
||||||
$$.val = NewString($1);
|
$$.val = NewString($1);
|
||||||
$$.type = T_STRING;
|
$$.type = T_STRING;
|
||||||
}
|
}
|
||||||
| SIZEOF LPAREN type parameter_declarator RPAREN {
|
| SIZEOF LPAREN type parameter_declarator RPAREN {
|
||||||
SwigType_push($3,$4.type);
|
SwigType_push($3,$4.type);
|
||||||
$$.val = NewStringf("sizeof(%s)",SwigType_str($3,0));
|
$$.val = NewStringf("sizeof(%s)",SwigType_str($3,0));
|
||||||
$$.type = T_ULONG;
|
$$.type = T_ULONG;
|
||||||
|
|
@ -5384,6 +5387,10 @@ exprcompound : expr PLUS expr {
|
||||||
$$.val = NewStringf("%s/%s",$1.val,$3.val);
|
$$.val = NewStringf("%s/%s",$1.val,$3.val);
|
||||||
$$.type = promote($1.type,$3.type);
|
$$.type = promote($1.type,$3.type);
|
||||||
}
|
}
|
||||||
|
| expr MODULUS expr {
|
||||||
|
$$.val = NewStringf("%s%%%s",$1.val,$3.val);
|
||||||
|
$$.type = promote($1.type,$3.type);
|
||||||
|
}
|
||||||
| expr AND expr {
|
| expr AND expr {
|
||||||
$$.val = NewStringf("%s&%s",$1.val,$3.val);
|
$$.val = NewStringf("%s&%s",$1.val,$3.val);
|
||||||
$$.type = promote($1.type,$3.type);
|
$$.type = promote($1.type,$3.type);
|
||||||
|
|
@ -5412,6 +5419,32 @@ exprcompound : expr PLUS expr {
|
||||||
$$.val = NewStringf("%s||%s",$1.val,$3.val);
|
$$.val = NewStringf("%s||%s",$1.val,$3.val);
|
||||||
$$.type = T_INT;
|
$$.type = T_INT;
|
||||||
}
|
}
|
||||||
|
| expr EQUALTO expr {
|
||||||
|
$$.val = NewStringf("%s==%s",$1.val,$3.val);
|
||||||
|
$$.type = T_INT;
|
||||||
|
}
|
||||||
|
| expr NOTEQUALTO expr {
|
||||||
|
$$.val = NewStringf("%s!=%s",$1.val,$3.val);
|
||||||
|
$$.type = T_INT;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
| expr GREATERTHAN expr {
|
||||||
|
$$.val = NewStringf("%s>%s",$1.val,$3.val);
|
||||||
|
$$.type = T_INT;
|
||||||
|
}
|
||||||
|
| expr LESSTHAN expr {
|
||||||
|
$$.val = NewStringf("%s<%s",$1.val,$3.val);
|
||||||
|
$$.type = T_INT;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
| expr GREATERTHANOREQUALTO expr {
|
||||||
|
$$.val = NewStringf("%s>=%s",$1.val,$3.val);
|
||||||
|
$$.type = T_INT;
|
||||||
|
}
|
||||||
|
| expr LESSTHANOREQUALTO expr {
|
||||||
|
$$.val = NewStringf("%s<=%s",$1.val,$3.val);
|
||||||
|
$$.type = T_INT;
|
||||||
|
}
|
||||||
| MINUS expr %prec UMINUS {
|
| MINUS expr %prec UMINUS {
|
||||||
$$.val = NewStringf("-%s",$2.val);
|
$$.val = NewStringf("-%s",$2.val);
|
||||||
$$.type = $2.type;
|
$$.type = $2.type;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue