A bunch of cleanup

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@126 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-01-19 23:35:55 +00:00
commit df7ba1da83
10 changed files with 839 additions and 536 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,17 +1,11 @@
/**************************************************************************** /******************************************************************************
* DOH (Dynamic Object Hack) * DOH
* *
* Author : David Beazley * Author(s) : David Beazley (beazley@cs.uchicago.edu)
* *
* Department of Computer Science * Copyright (C) 1999-2000. The University of Chicago
* University of Chicago * See the file LICENSE for information on usage and redistribution.
* 1100 E 58th Street ******************************************************************************/
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
****************************************************************************/
static char cvsroot[] = "$Header$"; static char cvsroot[] = "$Header$";
@ -28,23 +22,44 @@ typedef struct {
DOH *(*func)(DOH *, DOH *); DOH *(*func)(DOH *, DOH *);
} CallableObj; } CallableObj;
/* -----------------------------------------------------------------------------
* Callable_delete()
*
* Destroy a callable object.
* ----------------------------------------------------------------------------- */
static void static void
Callable_delete(DOH *co) { Callable_delete(DOH *co) {
DohObjFree(co); DohObjFree(co);
} }
/* -----------------------------------------------------------------------------
* Callable_copy()
*
* Copy a callable object.
* ----------------------------------------------------------------------------- */
static DOH * static DOH *
Callable_copy(DOH *co) { Callable_copy(DOH *co) {
CallableObj *c = (CallableObj *) co; CallableObj *c = (CallableObj *) co;
return NewCallable(c->func); return NewCallable(c->func);
} }
/* -----------------------------------------------------------------------------
* Callable_call()
*
* Call an object. The object itself is passed as the first argument and remaining
* arguments are passed as a second argument.
* ----------------------------------------------------------------------------- */
static DOH * static DOH *
Callable_call(DOH *co, DOH *args) { Callable_call(DOH *co, DOH *args) {
CallableObj *c = (CallableObj *) co; CallableObj *c = (CallableObj *) co;
return (*c->func)(c,args); return (*c->func)(c,args);
} }
/* Method tables */
static DohCallableMethods doh_callable_methods = { static DohCallableMethods doh_callable_methods = {
Callable_call Callable_call
}; };
@ -77,6 +92,12 @@ static DohObjInfo DohCallableType = {
0, /* user4 */ 0, /* user4 */
}; };
/* -----------------------------------------------------------------------------
* NewCallable()
*
* Create a new callable object.
* ----------------------------------------------------------------------------- */
DOH * DOH *
NewCallable(DOH *(*func)(DOH *, DOH *)) { NewCallable(DOH *(*func)(DOH *, DOH *)) {
CallableObj *c; CallableObj *c;

View file

@ -1,17 +1,11 @@
/**************************************************************************** /******************************************************************************
* DOH (Dynamic Object Hack) * DOH
* *
* Author : David Beazley * Author(s) : David Beazley (beazley@cs.uchicago.edu)
* *
* Department of Computer Science * Copyright (C) 1999-2000. The University of Chicago
* University of Chicago * See the file LICENSE for information on usage and redistribution.
* 1100 E 58th Street ******************************************************************************/
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which DOH
* can be used and distributed.
****************************************************************************/
static char cvsroot[] = "$Header$"; static char cvsroot[] = "$Header$";

View file

@ -138,26 +138,33 @@ List_scope(DOH *lo, int s) {
static int static int
List_insert(DOH *lo, int pos, DOH *item) List_insert(DOH *lo, int pos, DOH *item)
{ {
List *l; List *l;
DohBase *b; DohBase *b;
int i; int i, no = 0;
if (!item) return -1;
l = (List *) lo;
if (!item) return -1; if (!DohCheck(item)) {
b = (DohBase *) item; DohTrace(DOH_CONVERSION,"Unknown object %x being converted to a string in List_insert.\n", item);
l = (List *) lo; item = NewString(item);
no = 1;
if (pos == DOH_END) pos = l->nitems; }
if (pos < 0) pos = 0; b = (DohBase *) item;
if (pos > l->nitems) pos = l->nitems; if (pos == DOH_END) pos = l->nitems;
if (l->nitems == l->maxitems) more(l); if (pos < 0) pos = 0;
for (i = l->nitems; i > pos; i--) { if (pos > l->nitems) pos = l->nitems;
l->items[i] = l->items[i-1]; if (l->nitems == l->maxitems) more(l);
} for (i = l->nitems; i > pos; i--) {
l->items[pos] = item; l->items[i] = l->items[i-1];
b->refcount++; }
Setscope(b,l->scope); l->items[pos] = item;
l->nitems++; b->refcount++;
return 0; Setscope(b,l->scope);
l->nitems++;
if (no) Delete(item);
return 0;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -219,15 +226,22 @@ static int
List_set(DOH *lo, int n, DOH *val) List_set(DOH *lo, int n, DOH *val)
{ {
List *l; List *l;
int no = 0;
l = (List *) lo; l = (List *) lo;
if ((n < 0) || (n >= l->nitems)) { if ((n < 0) || (n >= l->nitems)) {
printf("List_set : Invalid list index %d\n", n); printf("List_set : Invalid list index %d\n", n);
return -1;
}
if (!DohCheck(val)) {
DohTrace(DOH_CONVERSION,"Unknown object %x being converted to a string in List_setitem.\n", val);
val = NewString(val);
no = 1;
} }
Delete(l->items[n]); Delete(l->items[n]);
l->items[n] = val; l->items[n] = val;
Incref(val); Incref(val);
Setscope(val,l->scope); Setscope(val,l->scope);
Delete(val);
return 0; return 0;
} }

View file

@ -201,7 +201,7 @@ static void real_objfree(DOH *ptr) {
b = (DohBase *) ptr; b = (DohBase *) ptr;
if (!b->objinfo) { if (!b->objinfo) {
DohError(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr); DohTrace(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr);
return; /* Improperly initialized object. leak some more */ return; /* Improperly initialized object. leak some more */
} }
f = (Fragment *) DohMalloc(sizeof(Fragment)); f = (Fragment *) DohMalloc(sizeof(Fragment));
@ -227,7 +227,7 @@ DohGarbageCollect() {
DohBase *b, *b1; DohBase *b, *b1;
int ndeleted = 1; int ndeleted = 1;
DohError(DOH_MEMORY,"Garbage collecting.\n"); DohTrace(DOH_MEMORY,"Garbage collecting.\n");
while (ndeleted) { while (ndeleted) {
ndeleted = 0; ndeleted = 0;
s = nscopes - 1; s = nscopes - 1;
@ -255,7 +255,7 @@ DohGarbageCollect() {
s--; s--;
} }
} }
DohError(DOH_MEMORY,"Done garbage collecting.\n"); DohTrace(DOH_MEMORY,"Done garbage collecting.\n");
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -338,12 +338,12 @@ void DohObjFree(DOH *ptr) {
DohBase *b; DohBase *b;
if (!DohCheck(ptr)) { if (!DohCheck(ptr)) {
DohError(DOH_MEMORY,"DohObjFree. %x not a DOH object!\n", ptr); DohTrace(DOH_MEMORY,"DohObjFree. %x not a DOH object!\n", ptr);
return; /* Oh well. Guess we're leaky */ return; /* Oh well. Guess we're leaky */
} }
b = (DohBase *) ptr; b = (DohBase *) ptr;
if (!b->objinfo) { if (!b->objinfo) {
DohError(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr); DohTrace(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr);
return; /* Improperly initialized object. leak some more */ return; /* Improperly initialized object. leak some more */
} }
} }

View file

@ -425,10 +425,15 @@ String_insert(DOH *so, int pos, DOH *str)
char *c; char *c;
int len; int len;
s = (String *) so; s = (String *) so;
/* assert(s->refcount <= 1); */ if (!DohCheck(str)) {
s1 = (String *) str; DohTrace(DOH_CONVERSION,"Unknown object %x being inserted as char * in String_insert.\n", str);
len = s1->len; c = (char *) str;
c = s1->str; len = strlen(c);
} else {
s1 = (String *) str;
len = s1->len;
c = s1->str;
}
raw_insert(s,pos,c,len); raw_insert(s,pos,c,len);
return 0; return 0;
} }

View file

@ -181,8 +181,6 @@ typedef struct DohObjInfo {
extern void DohDelattr(DOH *obj, DOH *name); extern void DohDelattr(DOH *obj, DOH *name);
extern DOH *DohFirstkey(DOH *obj); extern DOH *DohFirstkey(DOH *obj);
extern DOH *DohNextkey(DOH *obj); extern DOH *DohNextkey(DOH *obj);
extern DOH *DohFirst(DOH *obj);
extern DOH *DohNext(DOH *obj);
extern int DohGetInt(DOH *obj, DOH *name); extern int DohGetInt(DOH *obj, DOH *name);
extern double DohGetDouble(DOH *obj, DOH *name); extern double DohGetDouble(DOH *obj, DOH *name);
extern char *DohGetChar(DOH *obj, DOH *name); extern char *DohGetChar(DOH *obj, DOH *name);
@ -192,9 +190,9 @@ typedef struct DohObjInfo {
/* Sequence methods */ /* Sequence methods */
extern DOH *DohGetitem(DOH *obj, int index); extern DOH *DohGetitem(DOH *obj, int index);
extern void DohSetitem(DOH *obj, int index, DOH *value); extern int DohSetitem(DOH *obj, int index, DOH *value);
extern void DohDelitem(DOH *obj, int index); extern int DohDelitem(DOH *obj, int index);
extern void DohInsertitem(DOH *obj, int index, DOH *value); extern int DohInsertitem(DOH *obj, int index, DOH *value);
extern DOH *DohFirstitem(DOH *obj); extern DOH *DohFirstitem(DOH *obj);
extern DOH *DohNextitem(DOH *obj); extern DOH *DohNextitem(DOH *obj);
@ -230,9 +228,15 @@ typedef struct DohObjInfo {
/* Miscellaneous */ /* Miscellaneous */
extern void DohError(int level, char *fmt,...); extern void DohTrace(int level, char *fmt,...);
extern void DohDebug(int d); extern void DohDebug(int d);
extern int DohIsMapping(DOH *obj);
extern int DohIsSequence(DOH *obj);
extern int DohIsString(DOH *obj);
extern int DohIsFile(DOH *obj);
extern int DohIsCallable(DOH *obj);
#ifndef DOH_LONG_NAMES #ifndef DOH_LONG_NAMES
/* Macros to invoke the above functions. Includes the location of /* Macros to invoke the above functions. Includes the location of
the caller to simplify debugging if something goes wrong */ the caller to simplify debugging if something goes wrong */
@ -254,8 +258,6 @@ typedef struct DohObjInfo {
#define Append(s,x) DohInsertitem(s,DOH_END,x) #define Append(s,x) DohInsertitem(s,DOH_END,x)
#define Push(s,x) DohInsertitem(s,DOH_BEGIN,x) #define Push(s,x) DohInsertitem(s,DOH_BEGIN,x)
#define Len DohLen #define Len DohLen
#define First DohFirst
#define Next DohNext
#define Firstkey DohFirstkey #define Firstkey DohFirstkey
#define Nextkey DohNextkey #define Nextkey DohNextkey
#define Data DohData #define Data DohData
@ -384,15 +386,21 @@ extern DOH *DohSplit(DOH *input, char *chs, int nsplits);
extern DOH *DohNone; extern DOH *DohNone;
/* -----------------------------------------------------------------------------
* Callable
* ----------------------------------------------------------------------------- */
extern DOH *NewCallable(DOH *(*func)(DOH *, DOH *));
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Error handling levels. * Error handling levels.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
#define DOH_UNSUPPORTED 1 #define DOH_UNSUPPORTED 0x01
#define DOH_UNKNOWN 2 #define DOH_UNKNOWN 0x02
#define DOH_MEMORY 3 #define DOH_MEMORY 0x04
#define DOH_CONVERSION 5 #define DOH_CONVERSION 0x08
#define DOH_CALLS 10 #define DOH_CALLS 0x10
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -83,6 +83,8 @@ static int remap[SWIG_MAXTOKENS];
static int cscan_init = 0; static int cscan_init = 0;
static int cplusplus_mode = 0; static int cplusplus_mode = 0;
static int objc_mode = 0; static int objc_mode = 0;
static int strict_type = 1;
static SwigScanner *cscanner = 0; static SwigScanner *cscanner = 0;
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -125,6 +127,10 @@ void LParse_set_location(DOH *file, int line) {
SwigScanner_set_location(cscanner,file,line); SwigScanner_set_location(cscanner,file,line);
} }
void LParse_strict_type(int i) {
strict_type = i;
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* LParse_cplusplus(int i) - Enable C++ scanning * LParse_cplusplus(int i) - Enable C++ scanning
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -371,7 +377,7 @@ yylex1(void) {
/* Have an unknown identifier, as a last step, we'll */ /* Have an unknown identifier, as a last step, we'll */
/* do a typedef lookup on it. */ /* do a typedef lookup on it. */
yylval.tok.text = NewString(yytext); yylval.tok.text = NewString(yytext);
if (LParse_typedef_check(yylval.tok.text)) { if (strict_type && LParse_typedef_check(yylval.tok.text)) {
return TYPE_TYPEDEF; return TYPE_TYPEDEF;
} }
return(ID); return(ID);

View file

@ -29,6 +29,8 @@
#define yynerrs lparse_yynerrs #define yynerrs lparse_yynerrs
extern int lparse_yylex(); extern int lparse_yylex();
extern void LParse_strict_type(int);
void yyerror (char *s); void yyerror (char *s);
#include "lparse.h" #include "lparse.h"

View file

@ -150,7 +150,6 @@ LParseTypeStr(DOH *to) {
int i; int i;
LParseType *t = (LParseType *) to; LParseType *t = (LParseType *) to;
s = NewString(""); s = NewString("");
Printf(s,"(%d) - ", t->type);
if (t->qualifier) if (t->qualifier)
Printf(s,"%s ",t->qualifier); Printf(s,"%s ",t->qualifier);
Printf(s,"%s ",t->name); Printf(s,"%s ",t->name);