From bf2dac06720be34833a407a85c203d46c95130af Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Fri, 4 Nov 2005 16:47:07 +0000 Subject: [PATCH] fix bug #1347853 and better and/or/not operator management git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7799 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/namespace_class.i | 10 ++++ Source/CParse/cscanner.c | 70 +++++++++++++-------------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/Examples/test-suite/namespace_class.i b/Examples/test-suite/namespace_class.i index 50a04b9e1..5de58eeee 100644 --- a/Examples/test-suite/namespace_class.i +++ b/Examples/test-suite/namespace_class.i @@ -159,12 +159,22 @@ namespace jafar { template static void toFrame(const VecFrame& frame_, const Vec&v_,const VecRes& vRes){} + + template + void operator ()(T& x){} + + template + void operator < (T& x){} + }; } } %} %template(toFrame) jafar::jmath::EulerT3D::toFrame; +%template(callint) jafar::jmath::EulerT3D::operator(); +%template(lessint) jafar::jmath::EulerT3D::operator< ; + %inline %{ diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 9e9c881e9..a9c1995b5 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -1021,31 +1021,6 @@ void scanner_next_token(int tok) { * Gets the lexene and returns tokens. *************************************************************/ -static int search_name(char c, const char* ostr) -{ - int count = 0; - int find = 0; - - while (ostr[count]) { - if (c == ostr[count]) { - c = nextchar(); - ++count; - } else { - break; - } - } - if (!ostr[count]) { - if (isalnum(c) || c == '_') { - find = 0; - } else { - find = c; - } - } - if (count) retract(count); - return find; -} - - int yylex(void) { int l; @@ -1172,22 +1147,19 @@ int yylex(void) { int sticky = 0; int isconversion = 0; int count = 0; + int start_template = 0; + int end_template = 0; while ((c = nextchar())) { if (((c == '(') || (c == ';')) && state) { retract(1); break; } + if ((c == '<')) start_template = count; + if ((c == '>')) end_template = count; count++; if (!isspace(c)) { if ((!state) && (isalpha(c))) { - /* we look for the and/not/or operators */ - if (search_name(c, "and") || - search_name(c, "not") || - search_name(c, "or")) { - isconversion = 0; - } else { - isconversion = 1; - } + isconversion = 1; } if (!state && !sticky) Putc(' ',s); @@ -1200,6 +1172,28 @@ int yylex(void) { } } Chop(s); + if (start_template && end_template) { + /* + Manage the case: + + %template(foo) operator(); + + ie, don't count as part of the operator. + */ + int len = Len(s); + char *end = Char(s); + int tlen = end_template - start_template + 1; + int nlen = len - tlen; + if (nlen) { + String *ns = 0; + while (isspace(end[--nlen])); + ns = NewStringWithSize(s, nlen + 1); + retract(count - start_template); + Delete(s); + s = ns; + } + } + yylval.str = s; while(Replaceall(s,"[ ", "[")); if (isconversion) { @@ -1208,8 +1202,14 @@ int yylex(void) { } if (isconversion && !rename_active) { char *t = Char(s) + 9; - if (!((strcmp(t,"new") == 0) || (strcmp(t,"delete") == 0) - || (strcmp(t,"new[]") == 0) || (strcmp(t,"delete[]") == 0))) { + if (!((strcmp(t,"new") == 0) + || (strcmp(t,"delete") == 0) + || (strcmp(t,"new[]") == 0) + || (strcmp(t,"delete[]") == 0) + || (strcmp(t,"and") == 0) + || (strcmp(t,"or") == 0) + || (strcmp(t,"not") == 0) + )) { /* retract(strlen(t));*/ retract(count); return COPERATOR;