use new native StringEqual

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7884 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-11-27 02:55:00 +00:00
commit 631303638b

View file

@ -142,6 +142,9 @@ static String *k_dinclude = 0;
static String *k_dimport = 0; static String *k_dimport = 0;
static String *k_dextern = 0; static String *k_dextern = 0;
static String *k_LINE = 0;
static String *k_FILE = 0;
void Preprocessor_init(void) { void Preprocessor_init(void) {
Hash *s; Hash *s;
@ -174,6 +177,10 @@ void Preprocessor_init(void) {
k_ddefine = NewString("%define"); k_ddefine = NewString("%define");
k_dline = NewString("%line"); k_dline = NewString("%line");
k_LINE = NewString("__LINE__");
k_FILE = NewString("__FILE__");
cpp = NewHash(); cpp = NewHash();
s = NewHash(); s = NewHash();
Setattr(cpp,k_symbols,s); Setattr(cpp,k_symbols,s);
@ -425,7 +432,7 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro)
} }
symbols = Getattr(cpp,k_symbols); symbols = Getattr(cpp,k_symbols);
if ((m1 = Getattr(symbols,macroname))) { if ((m1 = Getattr(symbols,macroname))) {
if (Cmp(Getattr(m1,k_value),macrovalue)) { if (!StringEqual(Getattr(m1,k_value),macrovalue)) {
Swig_error(Getfile(str),Getline(str),"Macro '%s' redefined,\n",macroname); Swig_error(Getfile(str),Getline(str),"Macro '%s' redefined,\n",macroname);
Swig_error(Getfile(m1),Getline(m1),"previous definition of '%s'.\n",macroname); Swig_error(Getfile(m1),Getline(m1),"previous definition of '%s'.\n",macroname);
goto macro_error; goto macro_error;
@ -851,17 +858,20 @@ List *evaluate_args(List *x) {
* which are then expanded. * which are then expanded.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
/*#define PBUFF*/ /* #define SWIG_PUT_BUFF */
DOH * DOH *
Preprocessor_replace(DOH *s) Preprocessor_replace(DOH *s)
{ {
DOH *ns, *symbols, *m; DOH *ns, *symbols, *m;
int c, i, state = 0; int c, i, state = 0;
#ifndef SWIG_PUT_BUFF
String *id = NewString(""); String *id = NewString("");
#ifdef PBUFF #else
char bid[4096]; char id[4096];
char *cid; char *cid;
cid = bid; *cid = 0; cid = id; *cid = 0;
#endif #endif
assert(cpp); assert(cpp);
@ -876,14 +886,11 @@ Preprocessor_replace(DOH *s)
switch (state) { switch (state) {
case 0: case 0:
if (isidentifier(c) || (c == '%')) { if (isidentifier(c) || (c == '%')) {
#ifndef SWIG_PUT_BUFF
Clear(id); Clear(id);
#ifdef PBUFF
cid = bid; *cid = 0;
#endif
copy_location(s,id);
#ifndef PBUFF
StringPutc(c,id); StringPutc(c,id);
#else #else
cid = id;
*cid = c; ++cid; *cid = 0; *cid = c; ++cid; *cid = 0;
#endif #endif
state = 1; state = 1;
@ -902,23 +909,20 @@ Preprocessor_replace(DOH *s)
break; break;
case 1: /* An identifier */ case 1: /* An identifier */
if (isidchar(c)) { if (isidchar(c)) {
#ifndef PBUFF #ifndef SWIG_PUT_BUFF
StringPutc(c,id); StringPutc(c,id);
#else #else
*cid = c; ++cid; *cid = 0; *cid = c; ++cid; *cid = 0;
#endif #endif
state = 1; state = 1;
} else { } else {
#ifdef PBUFF
/* StringAppend(id,bid); */
#endif
/* We found the end of a valid identifier */ /* We found the end of a valid identifier */
StringUngetc(c,s); StringUngetc(c,s);
/* See if this is the special "defined" macro */ /* See if this is the special "defined" macro */
#ifndef PBUFF #ifndef SWIG_PUT_BUFF
if (Cmp(id,k_defined) == 0) { if (StringEqual(id,k_defined)) {
#else #else
if (strcmp(bid,"defined") == 0) { if (strcmp(id,"defined") == 0) {
#endif #endif
DOH *args = 0; DOH *args = 0;
/* See whether or not a paranthesis has been used */ /* See whether or not a paranthesis has been used */
@ -945,11 +949,7 @@ Preprocessor_replace(DOH *s)
} }
if ((!args) || (!Len(args))) { if ((!args) || (!Len(args))) {
/* This is not a defined() macro. */ /* This is not a defined() macro. */
#ifndef PBUFF
StringAppend(ns,id); StringAppend(ns,id);
#else
StringAppend(ns,bid);
#endif
state = 0; state = 0;
break; break;
} }
@ -965,19 +965,19 @@ Preprocessor_replace(DOH *s)
state = 0; state = 0;
break; break;
} }
#ifndef PBUFF #ifndef SWIG_PUT_BUFF
if (Cmp(id,"__LINE__") == 0) { if (StringEqual(id,k_LINE)) {
#else #else
if (strcmp(bid,"__LINE__") == 0) { if (strcmp(id,"__LINE__") == 0) {
#endif #endif
Printf(ns,"%d",Getline(s)); Printf(ns,"%d",Getline(s));
state = 0; state = 0;
break; break;
} }
#ifndef PBUFF #ifndef SWIG_PUT_BUFF
if (Cmp(id,"__FILE__") == 0) { if (StringEqual(id,k_FILE)) {
#else #else
if (strcmp(bid,"__FILE__") == 0) { if (strcmp(id,"__FILE__") == 0) {
#endif #endif
String *fn = Copy(Getfile(s)); String *fn = Copy(Getfile(s));
Replaceall(fn,"\\","\\\\"); Replaceall(fn,"\\","\\\\");
@ -987,11 +987,7 @@ Preprocessor_replace(DOH *s)
break; break;
} }
/* See if the macro is defined in the preprocessor symbol table */ /* See if the macro is defined in the preprocessor symbol table */
#ifndef PBUFF
if ((m = Getattr(symbols,id))) { if ((m = Getattr(symbols,id))) {
#else
if ((m = Getattr(symbols,bid))) {
#endif
DOH *args = 0; DOH *args = 0;
DOH *e; DOH *e;
/* See if the macro expects arguments */ /* See if the macro expects arguments */
@ -1005,22 +1001,14 @@ Preprocessor_replace(DOH *s)
} else { } else {
args = 0; args = 0;
} }
#ifndef PBUFF
e = expand_macro(id,args); e = expand_macro(id,args);
#else
e = expand_macro(bid,args);
#endif
if (e) { if (e) {
StringAppend(ns,e); StringAppend(ns,e);
} }
Delete(e); Delete(e);
Delete(args); Delete(args);
} else { } else {
#ifndef PBUFF
StringAppend(ns,id); StringAppend(ns,id);
#else
StringAppend(ns,bid);
#endif
} }
state = 0; state = 0;
} }
@ -1056,43 +1044,30 @@ Preprocessor_replace(DOH *s)
/* Identifier at the end */ /* Identifier at the end */
if (state == 1) { if (state == 1) {
#ifdef PBUFF
/* StringAppend(id,bid); */
#endif
/* See if this is the special "defined" macro */ /* See if this is the special "defined" macro */
#ifndef PBUFF #ifndef SWIG_PUT_BUFF
if (Cmp(id,k_defined) == 0) { if (StringEqual(id,k_defined)) {
#else #else
if (strcmp(bid,"defined") == 0) { if (strcmp(id,"defined") == 0) {
#endif #endif
Swig_error(Getfile(id),Getline(id),"No arguments given to defined()\n"); Swig_error(Getfile(s),Getline(s),"No arguments given to defined()\n");
#ifndef PBUFF
} else if ((m = Getattr(symbols,id))) { } else if ((m = Getattr(symbols,id))) {
#else
} else if ((m = Getattr(symbols,bid))) {
#endif
DOH *e; DOH *e;
/* Yes. There is a macro here */ /* Yes. There is a macro here */
/* See if the macro expects arguments */ /* See if the macro expects arguments */
/* if (Getattr(m,"args")) { /* if (Getattr(m,"args")) {
Swig_error(Getfile(id),Getline(id),"Macro arguments expected.\n"); Swig_error(Getfile(id),Getline(id),"Macro arguments expected.\n");
} */ } */
#ifndef PBUFF
e = expand_macro(id,0); e = expand_macro(id,0);
#else
e = expand_macro(bid,0);
#endif
StringAppend(ns,e); StringAppend(ns,e);
Delete(e); Delete(e);
} else { } else {
#ifndef PBUFF
StringAppend(ns,id); StringAppend(ns,id);
#else
StringAppend(ns,bid);
#endif
} }
} }
#ifndef SWIG_PUT_BUFF
Delete(id); Delete(id);
#endif
return ns; return ns;
} }
@ -1398,7 +1373,7 @@ Preprocessor_parse(String *s)
case 50: case 50:
/* Check for various preprocessor directives */ /* Check for various preprocessor directives */
Chop(value); Chop(value);
if (Cmp(id,k_define) == 0) { if (StringEqual(id,k_define)) {
if (allow) { if (allow) {
DOH *m, *v, *v1; DOH *m, *v, *v1;
Seek(value,0,SEEK_SET); Seek(value,0,SEEK_SET);
@ -1423,9 +1398,9 @@ Preprocessor_parse(String *s)
} }
Delete(m); Delete(m);
} }
} else if (Cmp(id,k_undef) == 0) { } else if (StringEqual(id,k_undef)) {
if (allow) Preprocessor_undef(value); if (allow) Preprocessor_undef(value);
} else if (Cmp(id,k_ifdef) == 0) { } else if (StringEqual(id,k_ifdef)) {
cond_lines[level] = Getline(id); cond_lines[level] = Getline(id);
level++; level++;
if (allow) { if (allow) {
@ -1434,7 +1409,7 @@ Preprocessor_parse(String *s)
if (!Getattr(symbols,value)) allow = 0; if (!Getattr(symbols,value)) allow = 0;
mask = 1; mask = 1;
} }
} else if (Cmp(id,k_ifndef) == 0) { } else if (StringEqual(id,k_ifndef)) {
cond_lines[level] = Getline(id); cond_lines[level] = Getline(id);
level++; level++;
if (allow) { if (allow) {
@ -1443,7 +1418,7 @@ Preprocessor_parse(String *s)
if (Getattr(symbols,value)) allow = 0; if (Getattr(symbols,value)) allow = 0;
mask = 1; mask = 1;
} }
} else if (Cmp(id,k_else) == 0) { } else if (StringEqual(id,k_else)) {
if (level <= 0) { if (level <= 0) {
Swig_error(Getfile(s),Getline(id),"Misplaced #else.\n"); Swig_error(Getfile(s),Getline(id),"Misplaced #else.\n");
} else { } else {
@ -1455,7 +1430,7 @@ Preprocessor_parse(String *s)
allow = 1*mask; allow = 1*mask;
} }
} }
} else if (Cmp(id,k_endif) == 0) { } else if (StringEqual(id,k_endif)) {
level--; level--;
if (level < 0) { if (level < 0) {
Swig_error(Getfile(id),Getline(id),"Extraneous #endif.\n"); Swig_error(Getfile(id),Getline(id),"Extraneous #endif.\n");
@ -1466,7 +1441,7 @@ Preprocessor_parse(String *s)
start_level--; start_level--;
} }
} }
} else if (Cmp(id,k_if) == 0) { } else if (StringEqual(id,k_if)) {
cond_lines[level] = Getline(id); cond_lines[level] = Getline(id);
level++; level++;
if (allow) { if (allow) {
@ -1488,7 +1463,7 @@ Preprocessor_parse(String *s)
} }
mask = 1; mask = 1;
} }
} else if (Cmp(id,k_elif) == 0) { } else if (StringEqual(id,k_elif)) {
if (level == 0) { if (level == 0) {
Swig_error(Getfile(s),Getline(id),"Misplaced #elif.\n"); Swig_error(Getfile(s),Getline(id),"Misplaced #elif.\n");
} else { } else {
@ -1515,16 +1490,16 @@ Preprocessor_parse(String *s)
} }
} }
} }
} else if (Cmp(id,k_warning) == 0) { } else if (StringEqual(id,k_warning)) {
if (allow) { if (allow) {
Swig_warning(WARN_PP_CPP_WARNING,Getfile(s),Getline(id),"%s\n", value); Swig_warning(WARN_PP_CPP_WARNING,Getfile(s),Getline(id),"%s\n", value);
} }
} else if (Cmp(id,k_error) == 0) { } else if (StringEqual(id,k_error)) {
if (allow) { if (allow) {
Swig_error(Getfile(s),Getline(id),"%s\n",value); Swig_error(Getfile(s),Getline(id),"%s\n",value);
} }
} else if (Cmp(id,k_line) == 0) { } else if (StringEqual(id,k_line)) {
} else if (Cmp(id,k_include) == 0) { } else if (StringEqual(id,k_include)) {
if (((include_all) || (import_all)) && (allow)) { if (((include_all) || (import_all)) && (allow)) {
String *s1, *s2, *fn; String *s1, *s2, *fn;
char *dirname; int sysfile = 0; char *dirname; int sysfile = 0;
@ -1564,7 +1539,7 @@ Preprocessor_parse(String *s)
Delete(s1); Delete(s1);
Delete(fn); Delete(fn);
} }
} else if (Cmp(id,k_pragma) == 0) { } else if (StringEqual(id,k_pragma)) {
if (Strncmp(value,"SWIG ",5) == 0) { if (Strncmp(value,"SWIG ",5) == 0) {
char *c = Char(value)+5; char *c = Char(value)+5;
while (*c && (isspace((int)*c))) c++; while (*c && (isspace((int)*c))) c++;
@ -1574,7 +1549,7 @@ Preprocessor_parse(String *s)
} }
} }
} }
} else if (Cmp(id,k_level) == 0) { } else if (StringEqual(id,k_level)) {
Swig_error(Getfile(s),Getline(id),"cpp debug: level = %d, startlevel = %d\n", level, start_level); Swig_error(Getfile(s),Getline(id),"cpp debug: level = %d, startlevel = %d\n", level, start_level);
} }
for (i = 0; i < cpp_lines; i++) for (i = 0; i < cpp_lines; i++)
@ -1648,12 +1623,12 @@ Preprocessor_parse(String *s)
if (!isidchar(c)) { if (!isidchar(c)) {
StringUngetc(c,s); StringUngetc(c,s);
/* Look for common Swig directives */ /* Look for common Swig directives */
if ((Cmp(decl,k_dinclude) == 0) || (Cmp(decl,k_dimport) == 0) || (Cmp(decl,k_dextern) == 0)) { if (StringEqual(decl,k_dinclude) || StringEqual(decl,k_dimport) || StringEqual(decl,k_dextern)) {
/* Got some kind of file inclusion directive */ /* Got some kind of file inclusion directive */
if (allow) { if (allow) {
DOH *s1, *s2, *fn, *opt; int sysfile = 0; DOH *s1, *s2, *fn, *opt; int sysfile = 0;
if (Cmp(decl,k_dextern) == 0) { if (StringEqual(decl,k_dextern)) {
Swig_warning(WARN_DEPRECATED_EXTERN, Getfile(s),Getline(s),"%%extern is deprecated. Use %%import instead.\n"); Swig_warning(WARN_DEPRECATED_EXTERN, Getfile(s),Getline(s),"%%extern is deprecated. Use %%import instead.\n");
Clear(decl); Clear(decl);
StringAppend(decl,"%%import"); StringAppend(decl,"%%import");
@ -1666,7 +1641,7 @@ Preprocessor_parse(String *s)
add_chunk(ns,chunk,allow); add_chunk(ns,chunk,allow);
copy_location(s,chunk); copy_location(s,chunk);
Printf(ns,"%sfile%s \"%s\" [\n", decl, opt, Swig_last_file()); Printf(ns,"%sfile%s \"%s\" [\n", decl, opt, Swig_last_file());
if (Cmp(decl,k_dimport) == 0) { if (StringEqual(decl,k_dimport)) {
push_imported(); push_imported();
} }
dirname = Swig_file_dirname(Swig_last_file()); dirname = Swig_file_dirname(Swig_last_file());
@ -1679,7 +1654,7 @@ Preprocessor_parse(String *s)
if (dirname) { if (dirname) {
Swig_pop_directory(); Swig_pop_directory();
} }
if (Cmp(decl,k_dimport) == 0) { if (StringEqual(decl,k_dimport)) {
pop_imported(); pop_imported();
} }
addline(ns,s2,allow); addline(ns,s2,allow);
@ -1690,10 +1665,10 @@ Preprocessor_parse(String *s)
Delete(fn); Delete(fn);
} }
state = 1; state = 1;
} else if (Cmp(decl,k_dline) == 0) { } else if (StringEqual(decl,k_dline)) {
/* Got a line directive */ /* Got a line directive */
state = 1; state = 1;
} else if (Cmp(decl,k_ddefine) == 0) { } else if (StringEqual(decl,k_ddefine)) {
/* Got a define directive */ /* Got a define directive */
dlevel++; dlevel++;
add_chunk(ns,chunk,allow); add_chunk(ns,chunk,allow);