Properly handle C99 complex types even in C++ mode

Use the `_Complex` keyword rather than the `complex` macro.

Fixes #1487.
This commit is contained in:
Leo Singer 2020-04-02 15:08:08 -04:00
commit 13260f95b0
6 changed files with 24 additions and 20 deletions

View file

@ -16,11 +16,11 @@
/* C complex constructor */ /* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i)) #define CCplxConst(r, i) ((r) + I*(i))
%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag); %swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag); %swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag); %swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
/* declaring the typemaps */ /* declaring the typemaps */
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex); %typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex); %typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex); %typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);

View file

@ -16,11 +16,11 @@
/* C complex constructor */ /* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i)) #define CCplxConst(r, i) ((r) + I*(i))
%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag); %swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag); %swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag); %swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
/* declaring the typemaps */ /* declaring the typemaps */
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex); %typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex); %typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex); %typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);

View file

@ -16,11 +16,11 @@
/* C complex constructor */ /* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i)) #define CCplxConst(r, i) ((r) + I*(i))
%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag); %swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag); %swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag); %swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
/* declaring the typemaps */ /* declaring the typemaps */
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex); %typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex); %typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex); %typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);

View file

@ -912,6 +912,10 @@ int yylex(void) {
yylval.type = NewSwigType(T_COMPLEX); yylval.type = NewSwigType(T_COMPLEX);
return (TYPE_COMPLEX); return (TYPE_COMPLEX);
} }
if (strcmp(yytext, "_Complex") == 0) {
yylval.type = NewSwigType(T_COMPLEX);
return (TYPE_COMPLEX);
}
if (strcmp(yytext, "restrict") == 0) if (strcmp(yytext, "restrict") == 0)
return (yylex()); return (yylex());
} }

View file

@ -6232,19 +6232,19 @@ primitive_type_list : type_specifier {
} else if (Cmp($1.type,"double") == 0) { } else if (Cmp($1.type,"double") == 0) {
if (Cmp($2.type,"long") == 0) { if (Cmp($2.type,"long") == 0) {
$$.type = NewString("long double"); $$.type = NewString("long double");
} else if (Cmp($2.type,"complex") == 0) { } else if (Cmp($2.type,"complex") == 0 || Cmp($2.type,"_Complex") == 0) {
$$.type = NewString("double complex"); $$.type = NewString("double _Complex");
} else { } else {
err = 1; err = 1;
} }
} else if (Cmp($1.type,"float") == 0) { } else if (Cmp($1.type,"float") == 0) {
if (Cmp($2.type,"complex") == 0) { if (Cmp($2.type,"complex") == 0 || Cmp($2.type,"_Complex") == 0) {
$$.type = NewString("float complex"); $$.type = NewString("float _Complex");
} else { } else {
err = 1; err = 1;
} }
} else if (Cmp($1.type,"complex") == 0) { } else if (Cmp($1.type,"complex") == 0 || Cmp($1.type,"_Complex") == 0) {
$$.type = NewStringf("%s complex", $2.type); $$.type = NewStringf("%s _Complex", $2.type);
} else { } else {
err = 1; err = 1;
} }

View file

@ -1453,9 +1453,9 @@ int SwigType_type(const SwigType *t) {
return T_DOUBLE; return T_DOUBLE;
if (strcmp(c, "long double") == 0) if (strcmp(c, "long double") == 0)
return T_LONGDOUBLE; return T_LONGDOUBLE;
if (!cparse_cplusplus && (strcmp(c, "float complex") == 0)) if (!cparse_cplusplus && (strcmp(c, "float _Complex") == 0))
return T_FLTCPLX; return T_FLTCPLX;
if (!cparse_cplusplus && (strcmp(c, "double complex") == 0)) if (!cparse_cplusplus && (strcmp(c, "double _Complex") == 0))
return T_DBLCPLX; return T_DBLCPLX;
if (!cparse_cplusplus && (strcmp(c, "complex") == 0)) if (!cparse_cplusplus && (strcmp(c, "complex") == 0))
return T_COMPLEX; return T_COMPLEX;