Various performance improvements

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@287 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-02-28 17:12:43 +00:00
commit cc6114917e
2 changed files with 268 additions and 203 deletions

View file

@ -73,7 +73,7 @@ static int map[][2] = {
static int remap[SWIG_MAXTOKENS]; static int remap[SWIG_MAXTOKENS];
static int cscan_init = 0; static int cscan_init = 0;
static int cplusplus_mode = 0; static int cplusplus_mode = 1;
static int objc_mode = 0; static int objc_mode = 0;
static int strict_type = 0; static int strict_type = 0;
@ -341,7 +341,7 @@ yylex1(void) {
/* C++ keywords */ /* C++ keywords */
if (1 || cplusplus_mode) { if (cplusplus_mode) {
if (strcmp(yytext,"class") == 0) { if (strcmp(yytext,"class") == 0) {
yylval.tok.text = NewString(yytext); yylval.tok.text = NewString(yytext);
return(CLASS); return(CLASS);

View file

@ -30,13 +30,28 @@ void yyerror (char *s);
static DOH *top = 0; static DOH *top = 0;
/* Pre-created attribute name objects. Used to improve parsing performance */
static DOH *ATTR_TAG = 0;
static DOH *ATTR_CHILD = 0;
static DOH *ATTR_PARENT = 0;
static DOH *ATTR_SIBLING = 0;
static DOH *ATTR_NAME = 0;
static DOH *ATTR_VALUE = 0;
static DOH *ATTR_TYPE = 0;
static DOH *ATTR_PARMS = 0;
static DOH *ATTR_STORAGE = 0;
static DOH *TAG_ENUMVALUE = 0;
static DOH *TAG_FUNCTION = 0;
static DOH *TAG_VARIABLE = 0;
/* Set parent node of a collection of children */ /* Set parent node of a collection of children */
static void setparent(DOH *parent, DOH *child) { static void setparent(DOH *parent, DOH *child) {
DOH *o; DOH *o;
o = child; o = child;
while (o) { while (o) {
Setattr(o,"parent",parent); Setattr(o,ATTR_PARENT,parent);
o = Getattr(o,"sibling"); o = Getattr(o,ATTR_SIBLING);
} }
} }
@ -44,13 +59,41 @@ static DOH *top = 0;
DOH *LParse_parse(DOH *str) { DOH *LParse_parse(DOH *str) {
int yyparse(); int yyparse();
DOH *tp; DOH *tp;
if (!ATTR_SIBLING) {
ATTR_PARENT = NewString("parent");
DohIntern(ATTR_PARENT);
ATTR_SIBLING = NewString("sibling");
DohIntern(ATTR_SIBLING);
ATTR_CHILD = NewString("child");
DohIntern(ATTR_CHILD);
ATTR_TAG = NewString("tag");
DohIntern(ATTR_TAG);
ATTR_NAME = NewString("name");
DohIntern(ATTR_NAME);
ATTR_VALUE = NewString("value");
DohIntern(ATTR_VALUE);
ATTR_TYPE = NewString("type");
DohIntern(ATTR_TYPE);
ATTR_PARMS = NewString("parms");
DohIntern(ATTR_PARMS);
ATTR_STORAGE = NewString("storage");
DohIntern(ATTR_STORAGE);
TAG_ENUMVALUE = NewString("enumvalue");
DohIntern(TAG_ENUMVALUE);
TAG_FUNCTION = NewString("function");
DohIntern(TAG_FUNCTION);
TAG_VARIABLE = NewString("variable");
DohIntern(TAG_VARIABLE);
}
LParse_push(str); LParse_push(str);
top = 0; top = 0;
tp = NewHash(); tp = NewHash();
Setattr(tp, "tag", "includefile"); Setattr(tp, "tag", "includefile");
Setattr(tp, "name", Getfile(str)); Setattr(tp, ATTR_NAME, Getfile(str));
yyparse(); yyparse();
Setattr(tp, "child", top); Setattr(tp, ATTR_CHILD, top);
setparent(tp,top); setparent(tp,top);
return tp; return tp;
} }
@ -58,7 +101,7 @@ static DOH *top = 0;
static DOH *new_node(char *tag, DOH *file, int line) { static DOH *new_node(char *tag, DOH *file, int line) {
DOH *o; DOH *o;
o = NewHash(); o = NewHash();
Setattr(o,"tag",tag); Setattr(o,ATTR_TAG,tag);
Setline(o,line); Setline(o,line);
Setfile(o,file); Setfile(o,file);
return o; return o;
@ -72,7 +115,7 @@ static DOH *top = 0;
l = Len(parms); l = Len(parms);
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
p = Getitem(parms,i); p = Getitem(parms,i);
Append(r,Getattr(p,"type")); Append(r,Getattr(p,ATTR_TYPE));
if (i < (l-1)) if (i < (l-1))
Append(r,","); Append(r,",");
} }
@ -120,6 +163,10 @@ static int promote(int t1, int t2) {
void *data; void *data;
} tok; } tok;
DOH *node; DOH *node;
struct {
DOH *node;
DOH *last;
} nodelist;
struct { struct {
DOH *id; DOH *id;
DOH *decl; DOH *decl;
@ -186,9 +233,10 @@ static int promote(int t1, int t2) {
%type <node> tm_args tm_parm tm_tail tm_list %type <node> tm_args tm_parm tm_tail tm_list
%type <tmname> tm_name %type <tmname> tm_name
%type <tok> tm_method %type <tok> tm_method
%type <node> interface statement swig_directive c_declaration %type <node> statement swig_directive c_declaration
%type <node> file_include code_block doc_directive except_directive pragma_directive modifier_directive native_directive typemap_directive %type <node> file_include code_block doc_directive except_directive pragma_directive modifier_directive native_directive typemap_directive
%type <node> variable_decl function_decl enum_decl typedef_decl stail enumlist edecl typedeflist %type <node> variable_decl function_decl enum_decl typedef_decl stail edecl typedeflist
%type <nodelist> enumlist interface
%type <node> inherit base_list %type <node> inherit base_list
%type <tok> base_specifier access_specifier cpp_end ctor_end opt_id %type <tok> base_specifier access_specifier cpp_end ctor_end opt_id
%type <node> cpp_decl cpp_class cpp_other %type <node> cpp_decl cpp_class cpp_other
@ -199,49 +247,48 @@ static int promote(int t1, int t2) {
associated semantic actions. */ associated semantic actions. */
program : interface { program : interface {
top = $1; top = $1.node;
} }
; ;
interface : interface statement { interface : interface statement {
DOH *o, *o2; DOH *o, *o2;
if (!$1) { if (!$1.node) {
$$ = $2; $$.node = $2;
o = $2; o = $2;
while (o) { while (o) {
o2 = o; o2 = o;
o = Getattr(o,"sibling"); o = Getattr(o,ATTR_SIBLING);
} }
if ($2 != o2) $$.last = o2;
Setattr($2,"lastsibling",o2);
} else { } else {
if ($2) { if ($2) {
o = Getattr($1,"lastsibling"); o = $1.last;
if (o) { if (o) {
Setattr(o,"sibling",$2); Setattr(o,ATTR_SIBLING,$2);
} else { } else {
Setattr($1,"sibling",$2); Setattr($1.node,ATTR_SIBLING,$2);
} }
o = $2; o = $2;
while (o) { while (o) {
o2 = o; o2 = o;
o = Getattr(o,"sibling"); o = Getattr(o,ATTR_SIBLING);
} }
Setattr($1, "lastsibling", o2); $1.last = o2;
} }
$$ = $1; $$ = $1;
} }
} }
| empty { $$ = 0; } | empty { $$.node = 0; $$.last = 0; }
; ;
statement : swig_directive { $$ = $1; } statement : swig_directive { $$ = $1; }
| c_declaration { $$ = $1; } | c_declaration { $$ = $1; }
| LBRACE interface RBRACE { | LBRACE interface RBRACE {
$$ = new_node("scope",$1.filename,$1.line); $$ = new_node("scope",$1.filename,$1.line);
if ($2) { if ($2.node) {
Setattr($$,"child",$2); Setattr($$,ATTR_CHILD,$2.node);
setparent($$,$2); setparent($$,$2.node);
} }
} }
| SEMI { $$ = 0; } | SEMI { $$ = 0; }
@ -253,7 +300,7 @@ statement : swig_directive { $$ = $1; }
* ============================================================================= */ * ============================================================================= */
swig_directive : MODULE idstring { swig_directive : MODULE idstring {
$$ = new_node("moduledirective",$1.filename,$1.line); $$ = new_node("moduledirective",$1.filename,$1.line);
Setattr($$,"name",$2.text); Setattr($$,ATTR_NAME,$2.text);
} }
| MACRO ID COMMA STRING COMMA NUM_INT LBRACE { | MACRO ID COMMA STRING COMMA NUM_INT LBRACE {
LParse_macro_location($2.text,$1.filename,$1.line); LParse_macro_location($2.text,$1.filename,$1.line);
@ -261,7 +308,7 @@ swig_directive : MODULE idstring {
} interface RBRACE { } interface RBRACE {
LParse_macro_location(0,0,0); LParse_macro_location(0,0,0);
LParse_set_location($7.filename,$7.line-1); LParse_set_location($7.filename,$7.line-1);
$$ = $9; $$ = $9.node;
} }
| RENAME ID ID SEMI { | RENAME ID ID SEMI {
$$ = new_node("renamedirective",$2.filename,$2.line); $$ = new_node("renamedirective",$2.filename,$2.line);
@ -270,41 +317,41 @@ swig_directive : MODULE idstring {
} }
| CONSTANT ID definetype SEMI { | CONSTANT ID definetype SEMI {
$$ = new_node("constant",$2.filename, $2.line); $$ = new_node("constant",$2.filename, $2.line);
Setattr($$,"name",$2.text); Setattr($$,ATTR_NAME,$2.text);
Setattr($$,"value",$3.text); Setattr($$,ATTR_VALUE,$3.text);
switch($3.ivalue) { switch($3.ivalue) {
case LPARSE_T_DOUBLE: case LPARSE_T_DOUBLE:
Setattr($$,"type","double"); Setattr($$,ATTR_TYPE,"double");
break; break;
case LPARSE_T_FLOAT: case LPARSE_T_FLOAT:
Setattr($$,"type","float"); Setattr($$,ATTR_TYPE,"float");
break; break;
case LPARSE_T_ULONG: case LPARSE_T_ULONG:
Setattr($$,"type","unsigned long"); Setattr($$,ATTR_TYPE,"unsigned long");
break; break;
case LPARSE_T_LONG: case LPARSE_T_LONG:
Setattr($$,"type","long"); Setattr($$,ATTR_TYPE,"long");
break; break;
case LPARSE_T_UINT: case LPARSE_T_UINT:
Setattr($$,"type","unsigned int"); Setattr($$,ATTR_TYPE,"unsigned int");
break; break;
case LPARSE_T_INT: case LPARSE_T_INT:
Setattr($$,"type","int"); Setattr($$,ATTR_TYPE,"int");
break; break;
case LPARSE_T_USHORT: case LPARSE_T_USHORT:
Setattr($$,"type","unsigned short"); Setattr($$,ATTR_TYPE,"unsigned short");
break; break;
case LPARSE_T_SHORT: case LPARSE_T_SHORT:
Setattr($$,"type","short"); Setattr($$,ATTR_TYPE,"short");
break; break;
case LPARSE_T_UCHAR: case LPARSE_T_UCHAR:
Setattr($$,"type","unsigned char"); Setattr($$,ATTR_TYPE,"unsigned char");
break; break;
case LPARSE_T_CHAR: case LPARSE_T_CHAR:
Setattr($$,"type","char"); Setattr($$,ATTR_TYPE,"char");
break; break;
case LPARSE_T_STRING: case LPARSE_T_STRING:
Setattr($$,"type","*.char"); Setattr($$,ATTR_TYPE,"*.char");
break; break;
default: default:
break; break;
@ -329,14 +376,14 @@ echo_directive: ECHO HBLOCK { Printf(stderr,"%s\n", $2.text); }
/* -- File inclusion directives -- */ /* -- File inclusion directives -- */
file_include : file_include_type STRING LBRACE { file_include : file_include_type STRING LBRACE {
Setattr($1,"name",$2.text); Setattr($1,ATTR_NAME,$2.text);
$$ = $1; $$ = $1;
LParse_set_location($2.text,0); LParse_set_location($2.text,0);
} interface RBRACE { } interface RBRACE {
LParse_set_location($3.filename,$3.line + 1); LParse_set_location($3.filename,$3.line + 1);
if ($5) { if ($5.node) {
Setattr($$,"child",$5); Setattr($$,ATTR_CHILD,$5.node);
setparent($$,$5); setparent($$,$5.node);
} }
} }
@ -351,7 +398,7 @@ modifier_directive : READONLY { $$ = new_node("readonlydirective",$1.filename, $
| READWRITE { $$ = new_node("readwritedirective",$1.filename,$1.line); } | READWRITE { $$ = new_node("readwritedirective",$1.filename,$1.line); }
| NAME LPAREN idstring RPAREN { | NAME LPAREN idstring RPAREN {
$$ = new_node("namedirective",$3.filename,$3.line); $$ = new_node("namedirective",$3.filename,$3.line);
Setattr($$,"name",$3.text); Setattr($$,ATTR_NAME,$3.text);
} }
| NEW { | NEW {
$$ = new_node("newdirective",$1.filename,$1.line); $$ = new_node("newdirective",$1.filename,$1.line);
@ -468,14 +515,14 @@ except_directive: EXCEPT LPAREN ID RPAREN LBRACE {
pragma_directive : PRAGMA ID pragma_arg { pragma_directive : PRAGMA ID pragma_arg {
$$ = new_node("pragmadirective",$1.filename,$1.line); $$ = new_node("pragmadirective",$1.filename,$1.line);
Setattr($$,"name",$2.text); Setattr($$,ATTR_NAME,$2.text);
Setattr($$,"value",$3.text); Setattr($$,ATTR_VALUE,$3.text);
} }
| PRAGMA LPAREN ID RPAREN ID pragma_arg { | PRAGMA LPAREN ID RPAREN ID pragma_arg {
$$ = new_node("pragmadirective",$1.filename,$1.line); $$ = new_node("pragmadirective",$1.filename,$1.line);
Setattr($$,"name",$5.text); Setattr($$,ATTR_NAME,$5.text);
Setattr($$,"lang",$3.text); Setattr($$,"lang",$3.text);
Setattr($$,"value",$6.text); Setattr($$,ATTR_VALUE,$6.text);
} }
; ;
@ -492,9 +539,9 @@ pragma_arg : EQUAL definetype {
native_directive : NATIVE LBRACE interface RBRACE { native_directive : NATIVE LBRACE interface RBRACE {
$$ = new_node("nativedirective",$1.filename,$1.line); $$ = new_node("nativedirective",$1.filename,$1.line);
if ($3) { if ($3.node) {
Setattr($$,"child",$3); Setattr($$,ATTR_CHILD,$3.node);
setparent($$,$3); setparent($$,$3.node);
} }
} }
; ;
@ -514,12 +561,12 @@ typemap_directive: TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list LBRACE {
Setattr(o,"lang",$3.text); Setattr(o,"lang",$3.text);
Setattr(o,"method",$5.text); Setattr(o,"method",$5.text);
Setattr(o,"code",t); Setattr(o,"code",t);
Setattr(o,"name",Getattr(l,"name")); Setattr(o,ATTR_NAME,Getattr(l,ATTR_NAME));
Setattr(o,"type",Getattr(l,"type")); Setattr(o,ATTR_TYPE,Getattr(l,ATTR_TYPE));
Setattr(o,"parms",Getattr(l,"parms")); Setattr(o,ATTR_PARMS,Getattr(l,ATTR_PARMS));
if (!$$) $$ = o; if (!$$) $$ = o;
if (prev) { if (prev) {
Setattr(prev,"sibling",o); Setattr(prev,ATTR_SIBLING,o);
} }
prev = o; prev = o;
} }
@ -536,11 +583,11 @@ typemap_directive: TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list LBRACE {
o = new_node("typemap",$1.filename, $1.line); o = new_node("typemap",$1.filename, $1.line);
Setattr(o,"method",$3.text); Setattr(o,"method",$3.text);
Setattr(o,"code",t); Setattr(o,"code",t);
Setattr(o,"name",Getattr(l,"name")); Setattr(o,ATTR_NAME,Getattr(l,ATTR_NAME));
Setattr(o,"type",Getattr(l,"type")); Setattr(o,ATTR_TYPE,Getattr(l,ATTR_TYPE));
Setattr(o,"parms",Getattr(l,"parms")); Setattr(o,ATTR_PARMS,Getattr(l,ATTR_PARMS));
if (!$$) $$ = o; if (!$$) $$ = o;
if (prev) Setattr(prev,"sibling",o); if (prev) Setattr(prev,ATTR_SIBLING,o);
prev = o; prev = o;
} }
} }
@ -556,10 +603,10 @@ typemap_directive: TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list LBRACE {
o = new_node("typemap",$1.filename, $1.line); o = new_node("typemap",$1.filename, $1.line);
Setattr(o,"lang",$3.text); Setattr(o,"lang",$3.text);
Setattr(o,"method",$5.text); Setattr(o,"method",$5.text);
Setattr(o,"name",Getattr(l,"name")); Setattr(o,ATTR_NAME,Getattr(l,ATTR_NAME));
Setattr(o,"type",Getattr(l,"type")); Setattr(o,ATTR_TYPE,Getattr(l,ATTR_TYPE));
if (!$$) $$ = o; if (!$$) $$ = o;
if (prev) Setattr(prev,"sibling",o); if (prev) Setattr(prev,ATTR_SIBLING,o);
prev = o; prev = o;
} }
} }
@ -574,10 +621,10 @@ typemap_directive: TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list LBRACE {
l = Getitem($5,i); l = Getitem($5,i);
o = new_node("typemap",$1.filename, $1.line); o = new_node("typemap",$1.filename, $1.line);
Setattr(o,"method",$3.text); Setattr(o,"method",$3.text);
Setattr(o,"name",Getattr(l,"name")); Setattr(o,ATTR_NAME,Getattr(l,ATTR_NAME));
Setattr(o,"type",Getattr(l,"type")); Setattr(o,ATTR_TYPE,Getattr(l,ATTR_TYPE));
if (!$$) $$ = o; if (!$$) $$ = o;
if (prev) Setattr(prev,"sibling",o); if (prev) Setattr(prev,ATTR_SIBLING,o);
prev = o; prev = o;
} }
} }
@ -593,13 +640,13 @@ typemap_directive: TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list LBRACE {
o = new_node("typemapcopy",$1.filename, $1.line); o = new_node("typemapcopy",$1.filename, $1.line);
Setattr(o,"method", $5.text); Setattr(o,"method", $5.text);
Setattr(o,"lang", $3.text); Setattr(o,"lang", $3.text);
Setattr(o,"name", Getattr(l,"name")); Setattr(o,ATTR_NAME, Getattr(l,ATTR_NAME));
Setattr(o,"type", Getattr(l,"type")); Setattr(o,ATTR_TYPE, Getattr(l,ATTR_TYPE));
Setattr(o,"parms",Getattr(l,"parms")); Setattr(o,ATTR_PARMS,Getattr(l,ATTR_PARMS));
Setattr(o,"srcname",Getattr($9,"name")); Setattr(o,"srcname",Getattr($9,ATTR_NAME));
Setattr(o,"srctype",Getattr($9,"type")); Setattr(o,"srctype",Getattr($9,ATTR_TYPE));
if (!$$) $$ = o; if (!$$) $$ = o;
if (prev) Setattr(prev,"sibling",o); if (prev) Setattr(prev,ATTR_SIBLING,o);
prev = o; prev = o;
} }
} }
@ -614,13 +661,13 @@ typemap_directive: TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list LBRACE {
l = Getitem($5,i); l = Getitem($5,i);
o = new_node("typemapcopy",$1.filename, $1.line); o = new_node("typemapcopy",$1.filename, $1.line);
Setattr(o,"method", $3.text); Setattr(o,"method", $3.text);
Setattr(o,"name", Getattr(l,"name")); Setattr(o,ATTR_NAME, Getattr(l,ATTR_NAME));
Setattr(o,"type", Getattr(l,"type")); Setattr(o,ATTR_TYPE, Getattr(l,ATTR_TYPE));
Setattr(o,"parms",Getattr(l,"parms")); Setattr(o,ATTR_PARMS,Getattr(l,ATTR_PARMS));
Setattr(o,"srcname",Getattr($7,"name")); Setattr(o,"srcname",Getattr($7,ATTR_NAME));
Setattr(o,"srctype",Getattr($7,"type")); Setattr(o,"srctype",Getattr($7,ATTR_TYPE));
if (!$$) $$ = o; if (!$$) $$ = o;
if (prev) Setattr(prev,"sibling",o); if (prev) Setattr(prev,ATTR_SIBLING,o);
prev = o; prev = o;
} }
} }
@ -629,16 +676,16 @@ typemap_directive: TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list LBRACE {
| APPLY tm_parm LBRACE tm_list RBRACE { | APPLY tm_parm LBRACE tm_list RBRACE {
$$ = new_node("applydirective",$1.filename, $1.line); $$ = new_node("applydirective",$1.filename, $1.line);
Setattr($$,"name",Getattr($2,"name")); Setattr($$,ATTR_NAME,Getattr($2,ATTR_NAME));
Setattr($$,"type",Getattr($2,"type")); Setattr($$,ATTR_TYPE,Getattr($2,ATTR_TYPE));
Setattr($$,"parms",$4); Setattr($$,ATTR_PARMS,$4);
} }
/* Clear directive */ /* Clear directive */
| CLEAR tm_list SEMI { | CLEAR tm_list SEMI {
$$ = new_node("cleardirective",$1.filename, $1.line); $$ = new_node("cleardirective",$1.filename, $1.line);
Setattr($$,"parms",$2); Setattr($$,ATTR_PARMS,$2);
} }
; ;
@ -669,11 +716,11 @@ tm_parm : type tm_name {
if ($2.array) { if ($2.array) {
SwigType_push($1,$2.array); SwigType_push($1,$2.array);
} }
Setattr($$,"type",$1); Setattr($$,ATTR_TYPE,$1);
if ($2.name) if ($2.name)
Setattr($$,"name",$2.name); Setattr($$,ATTR_NAME,$2.name);
if ($2.parms) if ($2.parms)
Setattr($$,"parms",$2.parms); Setattr($$,ATTR_PARMS,$2.parms);
} }
| type stars tm_name { | type stars tm_name {
$$ = NewHash(); $$ = NewHash();
@ -681,11 +728,11 @@ tm_parm : type tm_name {
if ($3.array) { if ($3.array) {
SwigType_push($1,$3.array); SwigType_push($1,$3.array);
} }
Setattr($$,"type",$1); Setattr($$,ATTR_TYPE,$1);
if ($3.name) if ($3.name)
Setattr($$,"name",$3.name); Setattr($$,ATTR_NAME,$3.name);
if ($3.parms) if ($3.parms)
Setattr($$,"parms",$3.parms); Setattr($$,ATTR_PARMS,$3.parms);
} }
| type AND tm_name { | type AND tm_name {
$$ = NewHash(); $$ = NewHash();
@ -693,11 +740,11 @@ tm_parm : type tm_name {
if ($3.array) { if ($3.array) {
SwigType_push($1,$3.array); SwigType_push($1,$3.array);
} }
Setattr($$,"type",$1); Setattr($$,ATTR_TYPE,$1);
if ($3.name) if ($3.name)
Setattr($$,"name",$3.name); Setattr($$,ATTR_NAME,$3.name);
if ($3.parms) if ($3.parms)
Setattr($$,"parms",$3.parms); Setattr($$,ATTR_PARMS,$3.parms);
} }
; ;
@ -749,29 +796,29 @@ c_declaration : variable_decl { $$ = $1; }
variable_decl : storage_spec type declaration array2 def_args stail { variable_decl : storage_spec type declaration array2 def_args stail {
DOH *o, *t; DOH *o, *t;
$$ = new_node("variable",Getfile($3.id),Getline($3.id)); $$ = new_node(TAG_VARIABLE,Getfile($3.id),Getline($3.id));
t = Copy($2); t = Copy($2);
SwigType_push(t,$3.decl); SwigType_push(t,$3.decl);
SwigType_push(t,$4); SwigType_push(t,$4);
Setattr($$,"name",$3.id); Setattr($$,ATTR_NAME,$3.id);
Setattr($$,"type",t); Setattr($$,ATTR_TYPE,t);
if ($1.ivalue) { if ($1.ivalue) {
Setattr($$,"storage",$1.text); Setattr($$,ATTR_STORAGE,$1.text);
} }
if ($5.text) { if ($5.text) {
Setattr($$,"value",$5.text); Setattr($$,ATTR_VALUE,$5.text);
} }
if ($6) { if ($6) {
Setattr($$,"sibling",$6); Setattr($$,ATTR_SIBLING,$6);
o = $6; o = $6;
while (o) { while (o) {
t = Copy($2); t = Copy($2);
SwigType_push(t,Getattr(o,"type")); SwigType_push(t,Getattr(o,ATTR_TYPE));
Setattr(o,"type",t); Setattr(o,ATTR_TYPE,t);
if ($1.ivalue) { if ($1.ivalue) {
Setattr(o,"storage",$1.text); Setattr(o,ATTR_STORAGE,$1.text);
} }
o = Getattr(o,"sibling"); o = Getattr(o,ATTR_SIBLING);
} }
} }
} }
@ -792,24 +839,24 @@ function_decl : storage_spec type declaration LPAREN parms RPAREN cpp_const sta
DOH *o, *t; DOH *o, *t;
t = Copy($2); t = Copy($2);
SwigType_push(t,$3.decl); SwigType_push(t,$3.decl);
$$ = new_node("function",Getfile($3.id),Getline($3.id)); $$ = new_node(TAG_FUNCTION,Getfile($3.id),Getline($3.id));
Setattr($$,"name",$3.id); Setattr($$,ATTR_NAME,$3.id);
Setattr($$,"type",t); Setattr($$,ATTR_TYPE,t);
Setattr($$,"parms",$5); Setattr($$,ATTR_PARMS,$5);
if ($1.ivalue) { if ($1.ivalue) {
Setattr($$,"storage", $1.text); Setattr($$,ATTR_STORAGE, $1.text);
} }
if ($8) { if ($8) {
Setattr($$,"sibling",$8); Setattr($$,ATTR_SIBLING,$8);
o = $8; o = $8;
while (o) { while (o) {
t = Copy($2); t = Copy($2);
SwigType_push(t,Getattr(o,"type")); SwigType_push(t,Getattr(o,ATTR_TYPE));
Setattr(o,"type",t); Setattr(o,ATTR_TYPE,t);
if ($1.ivalue) { if ($1.ivalue) {
Setattr(o,"storage",$1.text); Setattr(o,ATTR_STORAGE,$1.text);
} }
o = Getattr(o,"sibling"); o = Getattr(o,ATTR_SIBLING);
} }
} }
} }
@ -818,12 +865,12 @@ function_decl : storage_spec type declaration LPAREN parms RPAREN cpp_const sta
| storage_spec type declaration LPAREN parms RPAREN cpp_end { | storage_spec type declaration LPAREN parms RPAREN cpp_end {
SwigType_push($2,$3.decl); SwigType_push($2,$3.decl);
$$ = new_node("function",Getfile($3.id),Getline($3.id)); $$ = new_node(TAG_FUNCTION,Getfile($3.id),Getline($3.id));
Setattr($$,"name",$3.id); Setattr($$,ATTR_NAME,$3.id);
Setattr($$,"type",$2); Setattr($$,ATTR_TYPE,$2);
Setattr($$,"parms",$5); Setattr($$,ATTR_PARMS,$5);
if ($1.ivalue) { if ($1.ivalue) {
Setattr($$,"storage", $1.text); Setattr($$,ATTR_STORAGE, $1.text);
} }
if ($7.text) if ($7.text)
Setattr($$,"code",$7.text); Setattr($$,"code",$7.text);
@ -832,12 +879,12 @@ function_decl : storage_spec type declaration LPAREN parms RPAREN cpp_const sta
/* Possibly a constructor */ /* Possibly a constructor */
| storage_spec ID LPAREN parms RPAREN ctor_end { | storage_spec ID LPAREN parms RPAREN ctor_end {
DOH *t = NewString("int"); DOH *t = NewString("int");
$$ = new_node("function",$2.filename,$2.line); $$ = new_node(TAG_FUNCTION,$2.filename,$2.line);
Setattr($$,"name",$2.text); Setattr($$,ATTR_NAME,$2.text);
Setattr($$,"type",t); Setattr($$,ATTR_TYPE,t);
Setattr($$,"parms",$4); Setattr($$,ATTR_PARMS,$4);
if ($1.ivalue) { if ($1.ivalue) {
Setattr($$,"storage",$1.text); Setattr($$,ATTR_STORAGE,$1.text);
} }
if ($6.text) { if ($6.text) {
Setattr($$,"code",$6.text); Setattr($$,"code",$6.text);
@ -847,14 +894,14 @@ function_decl : storage_spec type declaration LPAREN parms RPAREN cpp_const sta
/* A C++ destructor */ /* A C++ destructor */
| NOT ID LPAREN parms RPAREN cpp_end { | NOT ID LPAREN parms RPAREN cpp_end {
$$ = new_node("destructor",$2.filename,$2.line); $$ = new_node("destructor",$2.filename,$2.line);
Setattr($$,"name",$2.text); Setattr($$,ATTR_NAME,$2.text);
if ($6.text) { if ($6.text) {
Setattr($$,"code",$6.text); Setattr($$,"code",$6.text);
} }
} }
| NOT ID LPAREN parms RPAREN cpp_const SEMI { | NOT ID LPAREN parms RPAREN cpp_const SEMI {
$$ = new_node("destructor",$2.filename,$2.line); $$ = new_node("destructor",$2.filename,$2.line);
Setattr($$,"name",$2.text); Setattr($$,ATTR_NAME,$2.text);
} }
; ;
@ -866,23 +913,23 @@ stail : SEMI { $$ = 0; }
DOH *t = NewString(""); DOH *t = NewString("");
SwigType_push(t,$2.decl); SwigType_push(t,$2.decl);
SwigType_push(t,$3); SwigType_push(t,$3);
$$ = new_node("variable", Getfile($2.id),Getline($2.id)); $$ = new_node(TAG_VARIABLE, Getfile($2.id),Getline($2.id));
Setattr($$,"name",$2.id); Setattr($$,ATTR_NAME,$2.id);
Setattr($$,"type",t); Setattr($$,ATTR_TYPE,t);
if ($4.text) if ($4.text)
Setattr($$,"value",$4.text); Setattr($$,ATTR_VALUE,$4.text);
if ($5) if ($5)
Setattr($$,"sibling", $5); Setattr($$,ATTR_SIBLING, $5);
} }
| COMMA declaration LPAREN parms RPAREN stail { | COMMA declaration LPAREN parms RPAREN stail {
DOH *t = NewString(""); DOH *t = NewString("");
SwigType_push(t,$2.decl); SwigType_push(t,$2.decl);
$$ = new_node("function", Getfile($2.id), Getline($2.id)); $$ = new_node(TAG_FUNCTION, Getfile($2.id), Getline($2.id));
Setattr($$,"name",$2.id); Setattr($$,ATTR_NAME,$2.id);
Setattr($$,"parms",$4); Setattr($$,ATTR_PARMS,$4);
Setattr($$,"type", t); Setattr($$,ATTR_TYPE, t);
if ($6) if ($6)
Setattr($$,"sibling",$6); Setattr($$,ATTR_SIBLING,$6);
} }
; ;
@ -914,9 +961,9 @@ cpp_const : CONST {}
enum_decl : storage_spec ENUM ename LBRACE enumlist RBRACE SEMI { enum_decl : storage_spec ENUM ename LBRACE enumlist RBRACE SEMI {
$$ = new_node("enum", $2.filename,$2.line); $$ = new_node("enum", $2.filename,$2.line);
Setattr($$,"name",$2.text); Setattr($$,ATTR_NAME,$2.text);
Setattr($$,"child",$5); Setattr($$,ATTR_CHILD,$5.node);
setparent($$,$5); setparent($$,$5.node);
/* Add typename */ /* Add typename */
} }
@ -924,16 +971,16 @@ enum_decl : storage_spec ENUM ename LBRACE enumlist RBRACE SEMI {
| TYPEDEF ENUM ename LBRACE enumlist RBRACE ID SEMI { | TYPEDEF ENUM ename LBRACE enumlist RBRACE ID SEMI {
$$ = new_node("enum",$2.filename,$2.line); $$ = new_node("enum",$2.filename,$2.line);
Setattr($$,"name",$3.text); Setattr($$,ATTR_NAME,$3.text);
Setattr($$,"child",$5); Setattr($$,ATTR_CHILD,$5.node);
setparent($$,$5); setparent($$,$5.node);
/* Add typedef for enum */ /* Add typedef for enum */
{ {
DOH *o; DOH *o;
o = new_node("typedef",$7.filename,$7.line); o = new_node("typedef",$7.filename,$7.line);
Setattr(o,"name",$7.text); Setattr(o,ATTR_NAME,$7.text);
Setattr(o,"type",$3.text); Setattr(o,ATTR_TYPE,$3.text);
Setattr($$,"sibling",o); Setattr($$,ATTR_SIBLING,o);
} }
} }
; ;
@ -945,29 +992,37 @@ ename : ID { $$ = $1; }
; ;
enumlist : enumlist COMMA edecl { enumlist : enumlist COMMA edecl {
DOH *o; Setattr($1.last,ATTR_SIBLING,$3);
$1.last = $3;
$$ = $1;
/*
DOH *o;
if ($3) { if ($3) {
o = Getattr($1,"lastsibling"); o = Getattr($1,LASTATTR_SIBLING);
if (o) { if (o) {
Setattr(o,"sibling",$3); Setattr(o,ATTR_SIBLING,$3);
} else { } else {
Setattr($1,"sibling",$3); Setattr($1,ATTR_SIBLING,$3);
} }
Setattr($1,"lastsibling",$3);; Setattr($1,LASTSIBLING,$3);;
} }
$$ = $1; $$ = $1;
*/
}
| edecl {
$$.node = $1;
$$.last = $1;
} }
| edecl { $$ = $1; }
; ;
edecl : ID { edecl : ID {
$$ = new_node("enumvalue",$1.filename,$1.line); $$ = new_node(TAG_ENUMVALUE,$1.filename,$1.line);
Setattr($$,"name",$1.text); Setattr($$,ATTR_NAME,$1.text);
} }
| ID EQUAL expr { | ID EQUAL expr {
$$ = new_node("enumvalue",$1.filename,$1.line); $$ = new_node(TAG_ENUMVALUE,$1.filename,$1.line);
Setattr($$,"name",$1.text); Setattr($$,ATTR_NAME,$1.text);
Setattr($$,"value",$1.text); Setattr($$,ATTR_VALUE,$1.text);
} }
| empty { $$ = 0; } | empty { $$ = 0; }
; ;
@ -979,8 +1034,8 @@ typedef_decl : TYPEDEF type declaration array2 typedeflist SEMI {
t = Copy($2); t = Copy($2);
SwigType_push($2,$3.decl); SwigType_push($2,$3.decl);
if ($4) SwigType_push($2,$4); if ($4) SwigType_push($2,$4);
Setattr($$,"name",$3.id); Setattr($$,ATTR_NAME,$3.id);
Setattr($$,"type",$2); Setattr($$,ATTR_TYPE,$2);
/* Go create more typedefs */ /* Go create more typedefs */
prev = $$; prev = $$;
for (i = 0; i < Len($5); i++) { for (i = 0; i < Len($5); i++) {
@ -990,9 +1045,9 @@ typedef_decl : TYPEDEF type declaration array2 typedeflist SEMI {
ty = Copy(t); ty = Copy(t);
SwigType_push(ty,Getattr(d,"decl")); SwigType_push(ty,Getattr(d,"decl"));
SwigType_push(ty,Getattr(d,"array")); SwigType_push(ty,Getattr(d,"array"));
Setattr(o,"type",ty); Setattr(o,ATTR_TYPE,ty);
Setattr(o,"name",Getattr(d,"name")); Setattr(o,ATTR_NAME,Getattr(d,ATTR_NAME));
Setattr(prev,"sibling",o); Setattr(prev,ATTR_SIBLING,o);
prev = o; prev = o;
} }
Delete($5); Delete($5);
@ -1006,8 +1061,8 @@ typedef_decl : TYPEDEF type declaration array2 typedeflist SEMI {
SwigType_push($2,$4); SwigType_push($2,$4);
if ($5.array) if ($5.array)
SwigType_push($2,$5.array); SwigType_push($2,$5.array);
Setattr($$,"name",$5.name); Setattr($$,ATTR_NAME,$5.name);
Setattr($$,"type",$2); Setattr($$,ATTR_TYPE,$2);
} }
/* A typedef involving function pointers again */ /* A typedef involving function pointers again */
@ -1019,14 +1074,14 @@ typedef_decl : TYPEDEF type declaration array2 typedeflist SEMI {
SwigType_push($2,$5); SwigType_push($2,$5);
if ($6.array) if ($6.array)
SwigType_push($2,$6.array); SwigType_push($2,$6.array);
Setattr($$,"name",$6.name); Setattr($$,ATTR_NAME,$6.name);
Setattr($$,"type",$2); Setattr($$,ATTR_TYPE,$2);
} }
; ;
typedeflist : COMMA declaration typedeflist { typedeflist : COMMA declaration typedeflist {
DOH *o = NewHash(); DOH *o = NewHash();
Setattr(o,"name",$2.id); Setattr(o,ATTR_NAME,$2.id);
Setattr(o,"decl",$2.decl); Setattr(o,"decl",$2.decl);
Insert($3,0,o); Insert($3,0,o);
$$ = $3; $$ = $3;
@ -1035,7 +1090,7 @@ typedeflist : COMMA declaration typedeflist {
DOH *o; DOH *o;
$$ = $4; $$ = $4;
o = NewHash(); o = NewHash();
Setattr(o,"name",$2.id); Setattr(o,ATTR_NAME,$2.id);
Setattr(o,"decl",$2.decl); Setattr(o,"decl",$2.decl);
if ($3) if ($3)
Setattr(o,"array",$3); Setattr(o,"array",$3);
@ -1059,22 +1114,26 @@ cpp_decl : cpp_class { $$ = $1; }
cpp_class : storage_spec cpptype ID inherit LBRACE interface RBRACE opt_id SEMI { cpp_class : storage_spec cpptype ID inherit LBRACE interface RBRACE opt_id SEMI {
$$ = new_node("class",$3.filename,$3.line); $$ = new_node("class",$3.filename,$3.line);
Setattr($$,"classtype",$2.text); Setattr($$,"classtype",$2.text);
Setattr($$,"name",$3.text); Setattr($$,ATTR_NAME,$3.text);
Setattr($$,"bases", $4); Setattr($$,"bases", $4);
Setattr($$,"child",$6); if ($6.node) {
setparent($$,$6); Setattr($$,ATTR_CHILD,$6.node);
setparent($$,$6.node);
}
if ($8.text) { if ($8.text) {
Setattr($$,"variable",$8.text); Setattr($$,TAG_VARIABLE,$8.text);
} }
} }
| storage_spec cpptype LBRACE interface RBRACE opt_id SEMI { | storage_spec cpptype LBRACE interface RBRACE opt_id SEMI {
$$ = new_node("class",$3.filename,$3.line); $$ = new_node("class",$3.filename,$3.line);
Setattr($$,"classtype",$2.text); Setattr($$,"classtype",$2.text);
Setattr($$,"child",$4); if ($4.node) {
setparent($$,$4); Setattr($$,ATTR_CHILD,$4.node);
setparent($$,$4.node);
}
if ($6.text) if ($6.text)
Setattr($$,"variable",$6.text); Setattr($$,TAG_VARIABLE,$6.text);
} }
/* Class with a typedef */ /* Class with a typedef */
@ -1082,10 +1141,12 @@ cpp_class : storage_spec cpptype ID inherit LBRACE interface RBRACE opt_id S
| TYPEDEF cpptype ID inherit LBRACE interface RBRACE declaration typedeflist { | TYPEDEF cpptype ID inherit LBRACE interface RBRACE declaration typedeflist {
$$ = new_node("class",$3.filename,$3.line); $$ = new_node("class",$3.filename,$3.line);
Setattr($$,"classtype",$2.text); Setattr($$,"classtype",$2.text);
Setattr($$,"name",$3.text); Setattr($$,ATTR_NAME,$3.text);
Setattr($$,"bases",$4); Setattr($$,"bases",$4);
Setattr($$,"child",$6); if ($6.node) {
setparent($$,$6); Setattr($$,ATTR_CHILD,$6.node);
setparent($$,$6.node);
}
if (Len($8.decl) == 0) if (Len($8.decl) == 0)
Setattr($$,"altname",$8.id); Setattr($$,"altname",$8.id);
@ -1094,11 +1155,11 @@ cpp_class : storage_spec cpptype ID inherit LBRACE interface RBRACE opt_id S
DOH *o, *t, *prev, *d; DOH *o, *t, *prev, *d;
int i; int i;
o = new_node("typedef",$3.filename,$3.line); o = new_node("typedef",$3.filename,$3.line);
Setattr(o,"name",$8.id); Setattr(o,ATTR_NAME,$8.id);
t = Copy($3.text); t = Copy($3.text);
SwigType_push(t,$8.decl); SwigType_push(t,$8.decl);
Setattr(o,"type",t); Setattr(o,ATTR_TYPE,t);
Setattr($$,"sibling",o); Setattr($$,ATTR_SIBLING,o);
prev = o; prev = o;
for (i = 0; i < Len($9); i++) { for (i = 0; i < Len($9); i++) {
d = Getitem($9,i); d = Getitem($9,i);
@ -1106,9 +1167,9 @@ cpp_class : storage_spec cpptype ID inherit LBRACE interface RBRACE opt_id S
t = Copy($3.text); t = Copy($3.text);
SwigType_push(t,Getattr(d,"decl")); SwigType_push(t,Getattr(d,"decl"));
SwigType_push(t,Getattr(d,"array")); SwigType_push(t,Getattr(d,"array"));
Setattr(o,"type",t); Setattr(o,ATTR_TYPE,t);
Setattr(o,"name",Getattr(d,"name")); Setattr(o,ATTR_NAME,Getattr(d,ATTR_NAME));
Setattr(prev,"sibling",o); Setattr(prev,ATTR_SIBLING,o);
prev = o; prev = o;
} }
Delete($9); Delete($9);
@ -1120,8 +1181,10 @@ cpp_class : storage_spec cpptype ID inherit LBRACE interface RBRACE opt_id S
| TYPEDEF cpptype LBRACE interface RBRACE declaration typedeflist { | TYPEDEF cpptype LBRACE interface RBRACE declaration typedeflist {
$$ = new_node("class",$3.filename,$3.line); $$ = new_node("class",$3.filename,$3.line);
Setattr($$,"classtype",$2.text); Setattr($$,"classtype",$2.text);
Setattr($$,"child",$4); if ($4.node) {
setparent($$,$4); Setattr($$,ATTR_CHILD,$4.node);
setparent($$,$4.node);
}
if (Len($6.decl) == 0) if (Len($6.decl) == 0)
Setattr($$,"altname",$6.id); Setattr($$,"altname",$6.id);
} }
@ -1203,7 +1266,7 @@ mem_initializer : ID LPAREN { LParse_skip_balanced('(',')'); }
cpp_other :/* A dummy class name */ cpp_other :/* A dummy class name */
storage_spec cpptype ID SEMI { storage_spec cpptype ID SEMI {
DOH *o = new_node("ClassDecl",$4.filename,$4.line); DOH *o = new_node("ClassDecl",$4.filename,$4.line);
Setattr(o,"name",$3.text); Setattr(o,ATTR_NAME,$3.text);
} }
| PUBLIC COLON { $$ = new_node("public",$1.filename,$1.line); } | PUBLIC COLON { $$ = new_node("public",$1.filename,$1.line); }
@ -1234,9 +1297,11 @@ cpp_other :/* A dummy class name */
| ADDMETHODS opt_id LBRACE interface RBRACE { | ADDMETHODS opt_id LBRACE interface RBRACE {
$$ = new_node("addmethods",$1.filename,$1.line); $$ = new_node("addmethods",$1.filename,$1.line);
if ($1.text) if ($1.text)
Setattr($$,"name",$1.text); Setattr($$,ATTR_NAME,$1.text);
Setattr($$,"child",$4); if ($4.node) {
setparent($$,$4); Setattr($$,ATTR_CHILD,$4.node);
setparent($$,$4.node);
}
} }
opt_id : ID { $$ = $1; } opt_id : ID { $$ = $1; }
@ -1265,31 +1330,31 @@ ptail : COMMA parm ptail {
parm : type pname { parm : type pname {
$$ = NewHash(); $$ = NewHash();
Setattr($$,"name",$2.name); Setattr($$,ATTR_NAME,$2.name);
SwigType_push($1,$2.array); SwigType_push($1,$2.array);
if ($2.value) if ($2.value)
Setattr($$,"value",$2.value); Setattr($$,ATTR_VALUE,$2.value);
Setattr($$,"type",$1); Setattr($$,ATTR_TYPE,$1);
} }
| type stars pname { | type stars pname {
$$ = NewHash(); $$ = NewHash();
Setattr($$,"name",$3.name); Setattr($$,ATTR_NAME,$3.name);
SwigType_push($1,$2); SwigType_push($1,$2);
SwigType_push($1,$3.array); SwigType_push($1,$3.array);
if ($3.value) { if ($3.value) {
Setattr($$,"value",$3.value); Setattr($$,ATTR_VALUE,$3.value);
} }
Setattr($$,"type",$1); Setattr($$,ATTR_TYPE,$1);
} }
| type AND pname { | type AND pname {
$$ = NewHash(); $$ = NewHash();
SwigType_add_reference($1); SwigType_add_reference($1);
SwigType_push($1,$3.array); SwigType_push($1,$3.array);
Setattr($$,"name",$3.name); Setattr($$,ATTR_NAME,$3.name);
if ($3.value) { if ($3.value) {
Setattr($$,"value",$3.value); Setattr($$,ATTR_VALUE,$3.value);
} }
Setattr($$,"type",$1); Setattr($$,ATTR_TYPE,$1);
} }
| type LPAREN stars pname RPAREN LPAREN parms RPAREN { | type LPAREN stars pname RPAREN LPAREN parms RPAREN {
$$ = NewHash(); $$ = NewHash();
@ -1297,10 +1362,10 @@ parm : type pname {
SwigType_push($1,$3); SwigType_push($1,$3);
if ($4.array) if ($4.array)
SwigType_push($1,$4.array); SwigType_push($1,$4.array);
Setattr($$,"name",$4.name); Setattr($$,ATTR_NAME,$4.name);
if ($4.value) if ($4.value)
Setattr($$,"value",$4.value); Setattr($$,ATTR_VALUE,$4.value);
Setattr($$,"type",$1); Setattr($$,ATTR_TYPE,$1);
} }
| type stars LPAREN stars pname RPAREN LPAREN parms RPAREN { | type stars LPAREN stars pname RPAREN LPAREN parms RPAREN {
$$ = NewHash(); $$ = NewHash();
@ -1309,15 +1374,15 @@ parm : type pname {
SwigType_push($1,$4); SwigType_push($1,$4);
if ($5.array) if ($5.array)
SwigType_push($1,$5.array); SwigType_push($1,$5.array);
Setattr($$,"name",$5.name); Setattr($$,ATTR_NAME,$5.name);
if ($5.value) if ($5.value)
Setattr($$,"value",$5.value); Setattr($$,ATTR_VALUE,$5.value);
Setattr($$,"type",$1); Setattr($$,ATTR_TYPE,$1);
} }
| PERIOD PERIOD PERIOD { | PERIOD PERIOD PERIOD {
$$ = NewHash(); $$ = NewHash();
Setattr($$,"name","..."); Setattr($$,ATTR_NAME,"...");
Setattr($$,"type","?"); Setattr($$,ATTR_TYPE,"?");
} }
; ;