Allow <, >, <=, >=, !=, ==, and % in constant expressions.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9329 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Olly Betts 2006-09-23 08:30:46 +00:00
commit 3dca18e4db
4 changed files with 90 additions and 21 deletions

View file

@ -1,6 +1,19 @@
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
Fix %ignore on director methods - Bugs #1546254, #1543533
@ -14,19 +27,11 @@ Version 1.3.30 (in progress)
Fix out of source builds - bug #1544718
09/20/2006: olly
[ALL] 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>;
09/20/2006: olly
[ALL] Treat a nested class definition as a forward declaration rather
Treat a nested class definition as a forward declaration rather
than ignoring it completely, so that we generate correct code for
passing opaque pointers to the nested class (fixes SF bug #909387).
09/20/2006: olly
09/20/2006: olly
*** POTENTIAL INCOMPATIBILITY ***
[php] Overload resolution now works. However to allow this, SWIG
generated wrappers no longer coerce PHP types (which reverts a change
@ -49,7 +54,7 @@ Version 1.3.30 (in progress)
[Python, Ruby, Ocaml] The swig_up flag is no longer used. The required mutexes
wrapping this flag are also no longer needed. The recursive calls going from C++
to the target language and back again etc are now avoided by a subtlely different
approach. Instead of using the swig_up flag in each director method to indicate
approach. Instead of using the swig_up flag in each director method to indicate
whether the explicit C++ call to the appropriate base class method or a normal
polymorphic C++ call should be made, the new approach makes one of these calls
directly from the wrapper method.
@ -180,7 +185,7 @@ Version 1.3.30 (in progress)
06/17/2006: olly
[php] Don't segfault if PHP Null is passed as this pointer (e.g.
Class_method(Null)) - give a PHP Error instead.
06/15/2006: mutandiz
[allegrocl]
Add initial support for std::list container class.

View file

@ -27,6 +27,25 @@ class X {};
%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

View file

@ -572,7 +572,7 @@ int yylook(void) {
num_brace++;
return (LBRACE);
}
else if (c == '=') return (EQUAL);
else if (c == '=') state = 63;
else if (c == '+') return (PLUS);
else if (c == '-') return (MINUS);
else if (c == '&') {
@ -587,7 +587,7 @@ int yylook(void) {
else if (c == '~') {
return (NOT);
}
else if (c == '!') return (LNOT);
else if (c == '!') state = 62;
else if (c == '\\') {
state = 99;
}
@ -802,20 +802,32 @@ int yylook(void) {
}
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 == '<') return LSHIFT;
if (c == '=') return LESSTHANOREQUALTO;
else {
retract(1);
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 == '>') return RSHIFT;
if (c == '=') return GREATERTHANOREQUALTO;
else {
retract(1);
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 */
if ((c = nextchar()) == 0) return(0);
if (isalnum(c) || (c == '_') || (c == '.') || (c == '$')) {

View file

@ -1389,6 +1389,7 @@ static void default_arguments(Node *n) {
%token TYPEMAP EXCEPT ECHO APPLY CLEAR SWIGTEMPLATE FRAGMENT
%token WARN
%token LESSTHAN GREATERTHAN MODULO DELETE_KW
%token LESSTHANOREQUALTO GREATERTHANOREQUALTO EQUALTO NOTEQUALTO
%token TYPES PARMS
%token NONID DSTAR DCNOT
%token <ivalue> TEMPLATE
@ -1402,9 +1403,11 @@ static void default_arguments(Node *n) {
%left OR
%left XOR
%left AND
%left EQUALTO NOTEQUALTO
%left GREATERTHAN LESSTHAN GREATERTHANOREQUALTO LESSTHANOREQUALTO
%left LSHIFT RSHIFT
%left PLUS MINUS
%left STAR SLASH
%left STAR SLASH MODULUS
%left UMINUS NOT LNOT
%left DCOLON
@ -5269,7 +5272,7 @@ etype : expr {
this does allow us to parse many constant declarations.
*/
expr : valexpr { $$ = $1; }
expr : valexpr { $$ = $1; }
| type {
Node *n;
$$.val = $1;
@ -5289,12 +5292,12 @@ expr : valexpr { $$ = $1; }
}
;
valexpr : exprnum { $$ = $1; }
| string {
valexpr : exprnum { $$ = $1; }
| string {
$$.val = NewString($1);
$$.type = T_STRING;
}
| SIZEOF LPAREN type parameter_declarator RPAREN {
| SIZEOF LPAREN type parameter_declarator RPAREN {
SwigType_push($3,$4.type);
$$.val = NewStringf("sizeof(%s)",SwigType_str($3,0));
$$.type = T_ULONG;
@ -5384,6 +5387,10 @@ exprcompound : expr PLUS expr {
$$.val = NewStringf("%s/%s",$1.val,$3.val);
$$.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 {
$$.val = NewStringf("%s&%s",$1.val,$3.val);
$$.type = promote($1.type,$3.type);
@ -5412,6 +5419,32 @@ exprcompound : expr PLUS expr {
$$.val = NewStringf("%s||%s",$1.val,$3.val);
$$.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 {
$$.val = NewStringf("-%s",$2.val);
$$.type = $2.type;