diff --git a/Examples/test-suite/namespace_class.i b/Examples/test-suite/namespace_class.i index 5de58eeee..91f6f71ca 100644 --- a/Examples/test-suite/namespace_class.i +++ b/Examples/test-suite/namespace_class.i @@ -12,6 +12,12 @@ %inline %{ + template + struct Bar_T + { + }; + + namespace test { enum Hello { @@ -165,6 +171,9 @@ namespace jafar { template void operator < (T& x){} + + template + operator Bar_T () {} }; } @@ -173,8 +182,9 @@ namespace jafar { %template(toFrame) jafar::jmath::EulerT3D::toFrame; %template(callint) jafar::jmath::EulerT3D::operator(); -%template(lessint) jafar::jmath::EulerT3D::operator< ; - +%template(lessint) jafar::jmath::EulerT3D::operator < ; +%template(callfooi) jafar::jmath::EulerT3D::operator() >; +%template(lessfooi) jafar::jmath::EulerT3D::operator < < test::hola::FooT >; %inline %{ @@ -225,3 +235,9 @@ public: }; %template(hi) Ala::hi; + +%extend jafar::jmath::EulerT3D +{ + +} + diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index a9c1995b5..b6ebc2fb9 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -47,6 +47,7 @@ static int num_brace = 0; static int last_brace = 0; static int last_id = 0; static int rename_active = 0; +static int swigtemplate_active = 0; int cparse_cplusplus = 0; /* ----------------------------------------------------------------------------- @@ -527,7 +528,11 @@ int yylook(void) { else if (c == '(') return (LPAREN); else if (c == ')') return (RPAREN); - else if (c == ';') return (SEMI); + else if (c == ';') { + swigtemplate_active = 0; + return (SEMI); + } + else if (c == ',') return (COMMA); else if (c == '*') return (STAR); else if (c == '}') { @@ -1154,8 +1159,16 @@ int yylex(void) { retract(1); break; } - if ((c == '<')) start_template = count; - if ((c == '>')) end_template = count; + if ((c == '<') && !start_template) { + int fcount = 1; + char c = nextchar(); + while (isspace(c)) {c = nextchar(); ++fcount;} + if (isalpha(c)|| c == ':') { + start_template = count; + } + retract(fcount); + } + if ((c == '>') && start_template) end_template = count; count++; if (!isspace(c)) { if ((!state) && (isalpha(c))) { @@ -1172,7 +1185,7 @@ int yylex(void) { } } Chop(s); - if (start_template && end_template) { + if (swigtemplate_active && start_template && end_template) { /* Manage the case: @@ -1191,6 +1204,8 @@ int yylex(void) { retract(count - start_template); Delete(s); s = ns; + count = start_template; + isconversion = 0; } } @@ -1324,7 +1339,11 @@ int yylex(void) { if (strcmp(yytext,"%types") == 0) return(TYPES); if (strcmp(yytext,"%parms") == 0) return(PARMS); if (strcmp(yytext,"%varargs") == 0) return(VARARGS); - if (strcmp(yytext,"%template") == 0) return (SWIGTEMPLATE); + if (strcmp(yytext,"%template") == 0) { + swigtemplate_active = 1; + return (SWIGTEMPLATE); + } + if (strcmp(yytext,"%warn") == 0) return(WARN); } /* Have an unknown identifier, as a last step, we'll do a typedef lookup on it. */ diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index a088c4c98..992f2b905 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -835,7 +835,7 @@ static Node *nscope_inner = 0; static String *resolve_node_scope(String *cname) { Symtab *gscope = 0; nscope = 0; - nscope_inner = 0; + nscope_inner = 0; if (Swig_scopename_check(cname)) { Node *ns; String *prefix = Swig_scopename_prefix(cname); @@ -3484,7 +3484,7 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { template_para /* We also place a fully parameterized version in the symbol table */ { Parm *p; - String *fname = NewStringf("%s<(",Getattr($$,"name")); + String *fname = NewStringf("%s<(", Getattr($$,"name")); p = $3; while (p) { String *n = Getattr(p,"name"); @@ -3522,7 +3522,10 @@ cpp_temp_possible: c_decl { } | cpp_forward_class_decl { $$ = $1; - } + } + | cpp_conversion_operator { + $$ = $1; + } ; template_parms : rawparms {