fix feautures + qual + templates

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6578 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-11-01 18:14:52 +00:00
commit d6e3a92182
2 changed files with 89 additions and 21 deletions

View file

@ -68,3 +68,60 @@ public:
%template(TemplateInt) Template<int>;
%newobject One::getSquare() const;
%inline %{
struct Square
{
Square(int)
{
}
};
struct One {
Square *getSquare() const { return new Square(10); }
};
%}
%newobject Two::getSquare();
%inline %{
struct Two {
Square *getSquare() const { return new Square(10); }
};
char *foo() {return 0;}
%}
%exception {
// default %exception
}
%exception std::Vector::get {
// get %exception
}
%inline %{
namespace std {
template<class T> class Vector {
public:
void push_back(const T& x) {}
#ifdef SWIG
%extend {
T& get(int i) {
throw std::out_of_range("Vector index out of range");
}
}
#endif
};
}
%}
%template(VectorInt) std::Vector<int>;

View file

@ -447,6 +447,17 @@ Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *dec
if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
if (!rn) rn = get_object(n,0);
Delete(tname);
/* A template-based class lookup */
if (SwigType_istemplate(prefix)) {
String *rname = SwigType_templateprefix(prefix);
tname = NewStringf("%s::%s",rname,name);
n = Getattr(namehash,tname);
rn = get_object(n,decl);
if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
if (!rn) rn = get_object(n,0);
Delete(tname);
Delete(rname);
}
}
/* A wildcard-based class lookup */
if (!rn) {
@ -556,12 +567,14 @@ Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl,
SwigType *rname = 0;
if (!features) return;
/* MM: This removed to more tightly control feature/name matching */
/*
if ((decl) && (SwigType_isqualifier(decl))) {
ncdecl = strchr(Char(decl),'.');
ncdecl++;
}
*/
/* very specific hack for template constructors/destructors */
if (name && SwigType_istemplate(name) &&
((Strcmp(nodeType(node),"constructor") == 0)
@ -571,27 +584,9 @@ Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl,
Replaceall(rdecl,name,rname);
decl = rdecl;
name = rname;
}
/*
very specific hack for functions that return pointers/references,
in the long term, %feature should check the entire declaration,
including the returning type, but for now, these declarations
char f(); -> decl: f().
char* f(); -> decl: f().p.
char& f(); -> decl: f().r. ?
are working again, since we get ride of the extra 'p./r.'
*/
if (SwigType_isfunction(decl)) {
rdecl = Copy(decl);
decl = SwigType_pop(rdecl);
Delete(rdecl);
rdecl = decl;
}
/* Printf(stdout,"feature_get: %s %s %s\n", prefix, name, decl); */
/* Printf(stdout,"feature_get: %s %s %s\n", prefix, name, decl);*/
/* Global features */
@ -633,6 +628,22 @@ Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl,
Delete(tname);
/* A specific class lookup */
if (Len(prefix)) {
/* A template-based class lookup */
if (SwigType_istemplate(prefix)) {
String *rname = SwigType_templateprefix(prefix);
tname = NewStringf("%s::%s",rname,name);
n = Getattr(features,tname);
rn = get_object(n,0);
merge_features(rn,node);
if (ncdecl) {
rn = get_object(n,ncdecl);
merge_features(rn,node);
}
rn = get_object(n,decl);
merge_features(rn,node);
Delete(tname);
Delete(rname);
}
tname = NewStringf("%s::%s",prefix,name);
n = Getattr(features,tname);
rn = get_object(n,0);