add operator aliases
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8277 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
373a1aa719
commit
c4337c7356
4 changed files with 31 additions and 24 deletions
|
|
@ -18,14 +18,15 @@
|
|||
%rename(__mod__) *::operator%;
|
||||
%rename(__gt__) *::operator>;
|
||||
%rename(__lt__) *::operator<;
|
||||
%rename(__and__) *::operator and;
|
||||
%rename(__or__) *::operator or;
|
||||
%rename(__and__) *::operator&&;
|
||||
%rename(__or__) *::operator||;
|
||||
%rename(__not__) *::operator!;
|
||||
|
||||
// These are renamed, but no 'use overload...' is added
|
||||
%rename(__lshift__) *::operator<<;
|
||||
%rename(__rshift__) *::operator>>;
|
||||
%rename(__and__) *::operator&;
|
||||
%rename(__or__) *::operator|;
|
||||
%rename(__band__) *::operator&;
|
||||
%rename(__bor__) *::operator|;
|
||||
%rename(__xor__) *::operator^;
|
||||
%rename(__invert__) *::operator~;
|
||||
%rename(__le__) *::operator<=;
|
||||
|
|
@ -45,9 +46,6 @@
|
|||
%ignoreoperator(ANDEQ) operator&=;
|
||||
%ignoreoperator(OREQ) operator|=;
|
||||
%ignoreoperator(XOREQ) operator^=;
|
||||
%ignoreoperator(LNOT) operator!;
|
||||
%ignoreoperator(LAND) operator&&;
|
||||
%ignoreoperator(LOR) operator||;
|
||||
%ignoreoperator(EQ) operator=;
|
||||
%ignoreoperator(PLUSPLUS) operator++;
|
||||
%ignoreoperator(MINUSMINUS) operator--;
|
||||
|
|
|
|||
|
|
@ -104,23 +104,6 @@
|
|||
%pyinplaceoper(__irshift__, *::operator >>=);
|
||||
|
||||
|
||||
|
||||
/* C++ operator aliases */
|
||||
|
||||
%ignoreoperator(LAND) operator and; // `and' `&&'
|
||||
%ignoreoperator(LNOT) operator not; // `not' `!'
|
||||
%ignoreoperator(LOR) operator or; // `or' `||'
|
||||
|
||||
%pyinplaceoper(__iand__, *::operator and_eq); // `and_eq' `&='
|
||||
%pybinoperator(__and__, *::operator bitand) // `bitand' `&'
|
||||
%pybinoperator(__or__, *::operator bitor); // `bitor' `|'
|
||||
%rename(__invert__) *::operator compl; // `compl' `~'
|
||||
%pybinoperator(__ne__, *::operator not_eq); // `not_eq' `!='
|
||||
%pyinplaceoper(__ior__, *::operator or_eq); // `or_eq' `|='
|
||||
%pybinoperator(__xor__, *::operator xor); // `xor' `^'
|
||||
%pyinplaceoper(__ixor__, *::operator xor_eq); // `xor_eq' `^='
|
||||
|
||||
|
||||
/* Finally, in python we need to mark the binary operations to fail as
|
||||
'maybecall' methods */
|
||||
|
||||
|
|
|
|||
13
Lib/swig.swg
13
Lib/swig.swg
|
|
@ -207,6 +207,19 @@ static int NAME(TYPE x) {
|
|||
%ignoreoperator(NEWARR) operator new[];
|
||||
%ignoreoperator(DELARR) operator delete[];
|
||||
|
||||
/* add C++ operator aliases */
|
||||
%rename("operator &&") operator and; // `and' `&&'
|
||||
%rename("operator ||") operator or; // `or' `||'
|
||||
%rename("operator !") operator not; // `not' `!'
|
||||
%rename("operator &=") operator and_eq; // `and_eq' `&='
|
||||
%rename("operator &") operator bitand; // `bitand' `&'
|
||||
%rename("operator |") operator bitor; // `bitor' `|'
|
||||
%rename("operator ~") operator compl; // `compl' `~'
|
||||
%rename("operator !=") operator not_eq; // `not_eq' `!='
|
||||
%rename("operator |=") operator or_eq; // `or_eq' `|='
|
||||
%rename("operator ^") operator xor; // `xor' `^'
|
||||
%rename("operator ^=") operator xor_eq; // `xor_eq' `^='
|
||||
|
||||
/* Smart pointer handling */
|
||||
|
||||
%rename(__deref__) *::operator->;
|
||||
|
|
|
|||
|
|
@ -1312,6 +1312,19 @@ Swig_name_make(Node *n, String *prefix, String *name, SwigType *decl, String *ol
|
|||
int fullname = GetFlag(rn,k_fullname);
|
||||
result = apply_rename(newname, fullname, prefix, name);
|
||||
}
|
||||
if (result) {
|
||||
/* operators in C++ allow aliases, we look for them */
|
||||
char *cresult = Char(result);
|
||||
if (cresult && (strncmp(cresult,"operator ",9) == 0)) {
|
||||
String *nresult = Swig_name_make(n, prefix, result, decl, oldname);
|
||||
if (!Equal(nresult,result)) {
|
||||
Delete(result);
|
||||
result = nresult;
|
||||
} else {
|
||||
Delete(nresult);
|
||||
}
|
||||
}
|
||||
}
|
||||
nname = result ? result : name;
|
||||
wrn = Swig_name_namewarn_get(n, prefix, nname, decl);
|
||||
if (wrn) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue