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:
parent
25b48a631f
commit
df7ba1da83
10 changed files with 839 additions and 536 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,17 +1,11 @@
|
|||
/****************************************************************************
|
||||
* DOH (Dynamic Object Hack)
|
||||
/******************************************************************************
|
||||
* DOH
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 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.
|
||||
****************************************************************************/
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
******************************************************************************/
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
|
|
@ -28,23 +22,44 @@ typedef struct {
|
|||
DOH *(*func)(DOH *, DOH *);
|
||||
} CallableObj;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Callable_delete()
|
||||
*
|
||||
* Destroy a callable object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
Callable_delete(DOH *co) {
|
||||
DohObjFree(co);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Callable_copy()
|
||||
*
|
||||
* Copy a callable object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Callable_copy(DOH *co) {
|
||||
CallableObj *c = (CallableObj *) co;
|
||||
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 *
|
||||
Callable_call(DOH *co, DOH *args) {
|
||||
CallableObj *c = (CallableObj *) co;
|
||||
return (*c->func)(c,args);
|
||||
}
|
||||
|
||||
/* Method tables */
|
||||
|
||||
static DohCallableMethods doh_callable_methods = {
|
||||
Callable_call
|
||||
};
|
||||
|
|
@ -77,6 +92,12 @@ static DohObjInfo DohCallableType = {
|
|||
0, /* user4 */
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewCallable()
|
||||
*
|
||||
* Create a new callable object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
NewCallable(DOH *(*func)(DOH *, DOH *)) {
|
||||
CallableObj *c;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,11 @@
|
|||
/****************************************************************************
|
||||
* DOH (Dynamic Object Hack)
|
||||
/******************************************************************************
|
||||
* DOH
|
||||
*
|
||||
* Author : David Beazley
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Department of Computer Science
|
||||
* University of Chicago
|
||||
* 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.
|
||||
****************************************************************************/
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
******************************************************************************/
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
|
|
|
|||
|
|
@ -138,26 +138,33 @@ List_scope(DOH *lo, int s) {
|
|||
static int
|
||||
List_insert(DOH *lo, int pos, DOH *item)
|
||||
{
|
||||
List *l;
|
||||
DohBase *b;
|
||||
int i;
|
||||
List *l;
|
||||
DohBase *b;
|
||||
int i, no = 0;
|
||||
|
||||
if (!item) return -1;
|
||||
|
||||
l = (List *) lo;
|
||||
|
||||
if (!item) return -1;
|
||||
b = (DohBase *) item;
|
||||
l = (List *) lo;
|
||||
|
||||
if (pos == DOH_END) pos = l->nitems;
|
||||
if (pos < 0) pos = 0;
|
||||
if (pos > l->nitems) pos = l->nitems;
|
||||
if (l->nitems == l->maxitems) more(l);
|
||||
for (i = l->nitems; i > pos; i--) {
|
||||
l->items[i] = l->items[i-1];
|
||||
}
|
||||
l->items[pos] = item;
|
||||
b->refcount++;
|
||||
Setscope(b,l->scope);
|
||||
l->nitems++;
|
||||
return 0;
|
||||
if (!DohCheck(item)) {
|
||||
DohTrace(DOH_CONVERSION,"Unknown object %x being converted to a string in List_insert.\n", item);
|
||||
item = NewString(item);
|
||||
no = 1;
|
||||
}
|
||||
b = (DohBase *) item;
|
||||
if (pos == DOH_END) pos = l->nitems;
|
||||
if (pos < 0) pos = 0;
|
||||
if (pos > l->nitems) pos = l->nitems;
|
||||
if (l->nitems == l->maxitems) more(l);
|
||||
for (i = l->nitems; i > pos; i--) {
|
||||
l->items[i] = l->items[i-1];
|
||||
}
|
||||
l->items[pos] = item;
|
||||
b->refcount++;
|
||||
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 *l;
|
||||
|
||||
int no = 0;
|
||||
l = (List *) lo;
|
||||
if ((n < 0) || (n >= l->nitems)) {
|
||||
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]);
|
||||
l->items[n] = val;
|
||||
Incref(val);
|
||||
Setscope(val,l->scope);
|
||||
Delete(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ static void real_objfree(DOH *ptr) {
|
|||
b = (DohBase *) ptr;
|
||||
|
||||
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 */
|
||||
}
|
||||
f = (Fragment *) DohMalloc(sizeof(Fragment));
|
||||
|
|
@ -227,7 +227,7 @@ DohGarbageCollect() {
|
|||
DohBase *b, *b1;
|
||||
int ndeleted = 1;
|
||||
|
||||
DohError(DOH_MEMORY,"Garbage collecting.\n");
|
||||
DohTrace(DOH_MEMORY,"Garbage collecting.\n");
|
||||
while (ndeleted) {
|
||||
ndeleted = 0;
|
||||
s = nscopes - 1;
|
||||
|
|
@ -255,7 +255,7 @@ DohGarbageCollect() {
|
|||
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;
|
||||
|
||||
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 */
|
||||
}
|
||||
b = (DohBase *) ptr;
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -425,10 +425,15 @@ String_insert(DOH *so, int pos, DOH *str)
|
|||
char *c;
|
||||
int len;
|
||||
s = (String *) so;
|
||||
/* assert(s->refcount <= 1); */
|
||||
s1 = (String *) str;
|
||||
len = s1->len;
|
||||
c = s1->str;
|
||||
if (!DohCheck(str)) {
|
||||
DohTrace(DOH_CONVERSION,"Unknown object %x being inserted as char * in String_insert.\n", str);
|
||||
c = (char *) str;
|
||||
len = strlen(c);
|
||||
} else {
|
||||
s1 = (String *) str;
|
||||
len = s1->len;
|
||||
c = s1->str;
|
||||
}
|
||||
raw_insert(s,pos,c,len);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,8 +181,6 @@ typedef struct DohObjInfo {
|
|||
extern void DohDelattr(DOH *obj, DOH *name);
|
||||
extern DOH *DohFirstkey(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 double DohGetDouble(DOH *obj, DOH *name);
|
||||
extern char *DohGetChar(DOH *obj, DOH *name);
|
||||
|
|
@ -192,9 +190,9 @@ typedef struct DohObjInfo {
|
|||
/* Sequence methods */
|
||||
|
||||
extern DOH *DohGetitem(DOH *obj, int index);
|
||||
extern void DohSetitem(DOH *obj, int index, DOH *value);
|
||||
extern void DohDelitem(DOH *obj, int index);
|
||||
extern void DohInsertitem(DOH *obj, int index, DOH *value);
|
||||
extern int DohSetitem(DOH *obj, int index, DOH *value);
|
||||
extern int DohDelitem(DOH *obj, int index);
|
||||
extern int DohInsertitem(DOH *obj, int index, DOH *value);
|
||||
extern DOH *DohFirstitem(DOH *obj);
|
||||
extern DOH *DohNextitem(DOH *obj);
|
||||
|
||||
|
|
@ -230,9 +228,15 @@ typedef struct DohObjInfo {
|
|||
|
||||
/* Miscellaneous */
|
||||
|
||||
extern void DohError(int level, char *fmt,...);
|
||||
extern void DohTrace(int level, char *fmt,...);
|
||||
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
|
||||
/* Macros to invoke the above functions. Includes the location of
|
||||
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 Push(s,x) DohInsertitem(s,DOH_BEGIN,x)
|
||||
#define Len DohLen
|
||||
#define First DohFirst
|
||||
#define Next DohNext
|
||||
#define Firstkey DohFirstkey
|
||||
#define Nextkey DohNextkey
|
||||
#define Data DohData
|
||||
|
|
@ -384,15 +386,21 @@ extern DOH *DohSplit(DOH *input, char *chs, int nsplits);
|
|||
|
||||
extern DOH *DohNone;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Callable
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOH *NewCallable(DOH *(*func)(DOH *, DOH *));
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Error handling levels.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#define DOH_UNSUPPORTED 1
|
||||
#define DOH_UNKNOWN 2
|
||||
#define DOH_MEMORY 3
|
||||
#define DOH_CONVERSION 5
|
||||
#define DOH_CALLS 10
|
||||
#define DOH_UNSUPPORTED 0x01
|
||||
#define DOH_UNKNOWN 0x02
|
||||
#define DOH_MEMORY 0x04
|
||||
#define DOH_CONVERSION 0x08
|
||||
#define DOH_CALLS 0x10
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,6 +83,8 @@ static int remap[SWIG_MAXTOKENS];
|
|||
static int cscan_init = 0;
|
||||
static int cplusplus_mode = 0;
|
||||
static int objc_mode = 0;
|
||||
static int strict_type = 1;
|
||||
|
||||
static SwigScanner *cscanner = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -125,6 +127,10 @@ void LParse_set_location(DOH *file, int line) {
|
|||
SwigScanner_set_location(cscanner,file,line);
|
||||
}
|
||||
|
||||
void LParse_strict_type(int i) {
|
||||
strict_type = i;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* LParse_cplusplus(int i) - Enable C++ scanning
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -371,7 +377,7 @@ yylex1(void) {
|
|||
/* Have an unknown identifier, as a last step, we'll */
|
||||
/* do a typedef lookup on it. */
|
||||
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(ID);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
#define yynerrs lparse_yynerrs
|
||||
|
||||
extern int lparse_yylex();
|
||||
extern void LParse_strict_type(int);
|
||||
|
||||
void yyerror (char *s);
|
||||
|
||||
#include "lparse.h"
|
||||
|
|
|
|||
|
|
@ -150,7 +150,6 @@ LParseTypeStr(DOH *to) {
|
|||
int i;
|
||||
LParseType *t = (LParseType *) to;
|
||||
s = NewString("");
|
||||
Printf(s,"(%d) - ", t->type);
|
||||
if (t->qualifier)
|
||||
Printf(s,"%s ",t->qualifier);
|
||||
Printf(s,"%s ",t->name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue