misc cleanup.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5045 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2003-09-01 17:03:29 +00:00
commit 48ad8e3946
3 changed files with 286 additions and 257 deletions

View file

@ -145,35 +145,6 @@ SwigType *NewSwigType(int t) {
}
}
/* -----------------------------------------------------------------------------
* SwigType_add_template()
*
* Adds a template to a type. This template is encoded in the SWIG type
* mechanism and produces a string like this:
*
* vector<int *> ----> "vector<(p.int)>"
* ----------------------------------------------------------------------------- */
void
SwigType_add_template(SwigType *t, ParmList *parms) {
Parm *p;
Append(t,"<(");
p = parms;
for (p = parms; p; p = nextSibling(p)) {
String *v;
if (Getattr(p,"default")) continue;
if (p != parms) Append(t,",");
v = Getattr(p,"value");
if (v) {
Append(t,v);
} else {
Append(t,Getattr(p,"type"));
}
}
Append(t,")>");
}
/* -----------------------------------------------------------------------------
* SwigType_push()
*
@ -293,234 +264,6 @@ int SwigType_issimple(SwigType *t) {
return 1;
}
int SwigType_isvarargs(const SwigType *t) {
if (Strcmp(t,"v(...)") == 0) return 1;
return 0;
}
int SwigType_istemplate(const SwigType *t) {
if (Strstr(t,"<(")) return 1;
return 0;
}
/* -----------------------------------------------------------------------------
* SwigType_base()
*
* Returns the base name of a datatype.
* ----------------------------------------------------------------------------- */
SwigType *SwigType_base(SwigType *t) {
char *c, *d;
c = Char(t);
d = c + strlen(c);
/* Check for a type constructor */
if ((d > c) && (*(d-1) == '.')) d--;
while (d > c) {
d--;
if (*d == '>') {
/* Skip over template--that's part of the base name */
int ntemp = 1;
d--;
while ((d > c) && (ntemp > 0)) {
if (*d == '>') ntemp++;
if (*d == '<') ntemp--;
d--;
}
}
if (*d == ')') {
/* Skip over params */
int nparen = 1;
d--;
while ((d > c) && (nparen > 0)) {
if (*d == ')') nparen++;
if (*d == '(') nparen--;
d--;
}
}
if (*d == '.') return NewString(d+1);
}
return NewString(c);
}
/* -----------------------------------------------------------------------------
* SwigType_prefix()
*
* Returns the prefix of a datatype
* ----------------------------------------------------------------------------- */
String *SwigType_prefix(SwigType *t) {
char *c, *d;
String *r = 0;
c = Char(t);
d = c + strlen(c);
/* Check for a type constructor */
if ((d > c) && (*(d-1) == '.')) d--;
while (d > c) {
d--;
if (*d == '>') {
int nest = 1;
d--;
while ((d > c) && (nest)) {
if (*d == '>') nest++;
if (*d == '<') nest--;
d--;
}
}
if (*d == ')') {
/* Skip over params */
int nparen = 1;
d--;
while ((d > c) && (nparen)) {
if (*d == ')') nparen++;
if (*d == '(') nparen--;
d--;
}
}
if (*d == '.') {
char t = *(d+1);
*(d+1) = 0;
r = NewString(c);
*(d+1) = t;
return r;
}
}
return NewString("");
}
/* -----------------------------------------------------------------------------
* SwigType_templateprefix()
*
* Returns the prefix before the first template definition.
* For example:
*
* Foo<(p.int)>::bar
*
* Results in "Foo"
* ----------------------------------------------------------------------------- */
String *
SwigType_templateprefix(SwigType *t) {
char *c;
String *r;
String *s = NewString(t);
c = Char(s);
while (*c) {
if (*c == '<') {
*c = 0;
r = NewString(Char(s));
Delete(s);
return r;
}
c++;
}
return s;
}
/* -----------------------------------------------------------------------------
* SwigType_templatesuffix()
*
* Returns text after a template substitution. Used to handle scope names
* for example:
*
* Foo<(p.int)>::bar
*
* returns "::bar"
* ----------------------------------------------------------------------------- */
String *
SwigType_templatesuffix(const SwigType *t) {
char *c;
c = Char(t);
while (*c) {
if ((*c == '<') && (*(c+1) == '(')) {
int nest = 1;
c++;
while (*c && nest) {
if (*c == '<') nest++;
if (*c == '>') nest--;
c++;
}
return NewString(c);
}
c++;
}
return NewString("");
}
/* -----------------------------------------------------------------------------
* SwigType_templateargs()
*
* Returns the template part
* ----------------------------------------------------------------------------- */
String *
SwigType_templateargs(SwigType *t) {
String *result = NewString("");
char *c;
c = Char(t);
while (*c) {
if ((*c == '<') && (*(c+1) == '(')) {
int nest = 1;
Putc(*c,result);
c++;
while (*c && nest) {
Putc(*c,result);
if (*c == '<') nest++;
if (*c == '>') nest--;
c++;
}
return result;
}
c++;
}
Delete(result);
return 0;
}
/* -----------------------------------------------------------------------------
* SwigType_strip_qualifiers()
*
* Strip all qualifiers from a type and return a new type
* ----------------------------------------------------------------------------- */
static Hash *memoize_stripped = 0;
SwigType *
SwigType_strip_qualifiers(SwigType *t) {
SwigType *r;
List *l;
SwigType *e;
if (!memoize_stripped) memoize_stripped = NewHash();
r = Getattr(memoize_stripped,t);
if (r) return Copy(r);
l = SwigType_split(t);
r = NewString("");
for (e = Firstitem(l); e; e = Nextitem(l)) {
if (SwigType_isqualifier(e)) continue;
Append(r,e);
}
Delete(l);
{
String *key, *value;
key = Copy(t);
value = Copy(r);
Setattr(memoize_stripped,key,value);
Delete(key);
Delete(value);
}
return r;
}
/* -----------------------------------------------------------------------------
* SwigType_default()
*

View file

@ -1541,6 +1541,7 @@ void replace_embedded_typemap(String *s, Wrapper *f) {
Swig_typemap_attach_parms(method,first,0);
{
String *tm;
int match = 0;
char attr[64];
sprintf(attr,"tmap:%s",Char(method));
@ -1559,8 +1560,12 @@ void replace_embedded_typemap(String *s, Wrapper *f) {
Replace(s,tmp,tm, DOH_REPLACE_ANY);
Delete(tm);
Delete(vars);
match = 1;
}
}
if (!match) {
Swig_error(Getfile(s),Getline(s),"No typemap found for %s\n", tmp);
}
}
}
}

View file

@ -707,3 +707,284 @@ SwigType_function_parms(SwigType *t) {
Delete(l);
return firstp;
}
int SwigType_isvarargs(const SwigType *t) {
if (Strcmp(t,"v(...)") == 0) return 1;
return 0;
}
/* -----------------------------------------------------------------------------
* Templates
*
* SwigType_add_template()
*
* Template handling.
* ----------------------------------------------------------------------------- */
/* -----------------------------------------------------------------------------
* SwigType_add_template()
*
* Adds a template to a type. This template is encoded in the SWIG type
* mechanism and produces a string like this:
*
* vector<int *> ----> "vector<(p.int)>"
* ----------------------------------------------------------------------------- */
void
SwigType_add_template(SwigType *t, ParmList *parms) {
Parm *p;
Append(t,"<(");
p = parms;
for (p = parms; p; p = nextSibling(p)) {
String *v;
if (Getattr(p,"default")) continue;
if (p != parms) Append(t,",");
v = Getattr(p,"value");
if (v) {
Append(t,v);
} else {
Append(t,Getattr(p,"type"));
}
}
Append(t,")>");
}
/* -----------------------------------------------------------------------------
* SwigType_templateprefix()
*
* Returns the prefix before the first template definition.
* For example:
*
* Foo<(p.int)>::bar
*
* Results in "Foo"
* ----------------------------------------------------------------------------- */
String *
SwigType_templateprefix(SwigType *t) {
char *c,*s;
s = Char(t);
c = s;
while (*c) {
if (*c == '<') {
return NewStringWithSize(s,c-s);
}
c++;
}
return NewString(s);
}
/* -----------------------------------------------------------------------------
* SwigType_templatesuffix()
*
* Returns text after a template substitution. Used to handle scope names
* for example:
*
* Foo<(p.int)>::bar
*
* returns "::bar"
* ----------------------------------------------------------------------------- */
String *
SwigType_templatesuffix(const SwigType *t) {
char *c;
c = Char(t);
while (*c) {
if ((*c == '<') && (*(c+1) == '(')) {
int nest = 1;
c++;
while (*c && nest) {
if (*c == '<') nest++;
if (*c == '>') nest--;
c++;
}
return NewString(c);
}
c++;
}
return NewString("");
}
/* -----------------------------------------------------------------------------
* SwigType_templateargs()
*
* Returns the template part
* ----------------------------------------------------------------------------- */
String *
SwigType_templateargs(SwigType *t) {
char *c;
char *start;
c = Char(t);
while (*c) {
if ((*c == '<') && (*(c+1) == '(')) {
int nest = 1;
start = c;
c++;
while (*c && nest) {
if (*c == '<') nest++;
if (*c == '>') nest--;
c++;
}
return NewStringWithSize(start,c-start);
}
c++;
}
return 0;
}
/* -----------------------------------------------------------------------------
* SwigType_istemplate()
*
* Tests a type to see if it includes template parameters
* ----------------------------------------------------------------------------- */
int
SwigType_istemplate(const SwigType *t) {
if (Strstr(t,"<(")) return 1;
return 0;
}
/* -----------------------------------------------------------------------------
* SwigType_base()
*
* This function returns the base of a type. For example, if you have a
* type "p.p.int", the function would return "int".
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_base(SwigType *t) {
char *c;
char *lastop = 0;
c = Char(t);
lastop = c;
/* Search for the last type constructor separator '.' */
while (*c) {
if (*c == '.') {
if (*(c+1)) {
lastop = c+1;
}
c++;
continue;
}
if (*c == '<') {
/* Skip over template---it's part of the base name */
int ntemp = 1;
c++;
while ((*c) && (ntemp > 0)) {
if (*c == '>') ntemp--;
else if (*c == '<') ntemp++;
c++;
}
if (ntemp) break;
continue;
}
if (*c == '(') {
/* Skip over params */
int nparen = 1;
c++;
while ((*c) && (nparen > 0)) {
if (*c == '(') nparen++;
else if (*c == ')') nparen--;
c++;
}
if (nparen) break;
continue;
}
c++;
}
return NewString(lastop);
}
/* -----------------------------------------------------------------------------
* SwigType_prefix()
*
* Returns the prefix of a datatype. For example, the prefix of the
* type "p.p.int" is "p.p.".
* ----------------------------------------------------------------------------- */
String *
SwigType_prefix(SwigType *t) {
char *c, *d;
String *r = 0;
c = Char(t);
d = c + strlen(c);
/* Check for a type constructor */
if ((d > c) && (*(d-1) == '.')) d--;
while (d > c) {
d--;
if (*d == '>') {
int nest = 1;
d--;
while ((d > c) && (nest)) {
if (*d == '>') nest++;
if (*d == '<') nest--;
d--;
}
}
if (*d == ')') {
/* Skip over params */
int nparen = 1;
d--;
while ((d > c) && (nparen)) {
if (*d == ')') nparen++;
if (*d == '(') nparen--;
d--;
}
}
if (*d == '.') {
char t = *(d+1);
*(d+1) = 0;
r = NewString(c);
*(d+1) = t;
return r;
}
}
return NewString("");
}
/* -----------------------------------------------------------------------------
* SwigType_strip_qualifiers()
*
* Strip all qualifiers from a type and return a new type
* ----------------------------------------------------------------------------- */
SwigType *
SwigType_strip_qualifiers(SwigType *t) {
static Hash *memoize_stripped = 0;
SwigType *r;
List *l;
SwigType *e;
if (!memoize_stripped) memoize_stripped = NewHash();
r = Getattr(memoize_stripped,t);
if (r) return Copy(r);
l = SwigType_split(t);
r = NewString("");
for (e = Firstitem(l); e; e = Nextitem(l)) {
if (SwigType_isqualifier(e)) continue;
Append(r,e);
}
Delete(l);
{
String *key, *value;
key = Copy(t);
value = Copy(r);
Setattr(memoize_stripped,key,value);
Delete(key);
Delete(value);
}
return r;
}