From: Marcelo M. <mar...@us...> - 2004-11-03 08:07:19
|
Update of /cvsroot/swig/SWIG/Source/CParse In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14777/Source/CParse Modified Files: parser.y Log Message: making sure the resolve_scope_node is working fine before release, and fix for unnamed namespace Index: parser.y =================================================================== RCS file: /cvsroot/swig/SWIG/Source/CParse/parser.y,v retrieving revision 1.83 retrieving revision 1.84 diff -C2 -d -r1.83 -r1.84 *** parser.y 3 Nov 2004 00:59:38 -0000 1.83 --- parser.y 3 Nov 2004 08:07:00 -0000 1.84 *************** *** 719,723 **** static Symtab *get_global_scope() { ! Symtab *symtab = Swig_symbol_current(); Node *pn = parentNode(symtab); while (pn) { --- 719,723 ---- static Symtab *get_global_scope() { ! Symtab *symtab = Swig_symbol_current(); Node *pn = parentNode(symtab); while (pn) { *************** *** 726,730 **** if (!pn) break; } - Namespaceprefix = 0; Swig_symbol_setscope(symtab); return symtab; --- 726,729 ---- *************** *** 750,757 **** } if (!prefix || (Len(prefix) == 0)) { ! /* Use the global scope */ if (!gscope) gscope = get_global_scope(); nscope = new_node("namespace"); ! Setattr(nscope,"symtab", gscope); nscope_inner = nscope; return base; --- 749,759 ---- } if (!prefix || (Len(prefix) == 0)) { ! /* Use the global scope, but we need to add a 'global' namespace. */ if (!gscope) gscope = get_global_scope(); + /* note that this namespace is not the "unnamed" one, + and we don't use Setattr(nscope,"name", ""), + because the unnamed namespace is private */ nscope = new_node("namespace"); ! Setattr(nscope,"symtab", gscope);; nscope_inner = nscope; return base; *************** *** 762,770 **** Swig_error(cparse_file,cparse_line,"Undefined scope '%s'\n", prefix); } else { ! if (Getattr(ns,"symtab") == 0) { ! Swig_error(cparse_file,cparse_line,"'%s' is not defined as a valid scope.\n", prefix); ns = 0; } else { ! Symtab *nstab = Getattr(ns,"symtab"); String *tname = Swig_symbol_qualifiedscopename(0); String *nname = Swig_symbol_qualifiedscopename(nstab); --- 764,774 ---- Swig_error(cparse_file,cparse_line,"Undefined scope '%s'\n", prefix); } else { ! Symtab *nstab = Getattr(ns,"symtab"); ! if (!nstab) { ! Swig_error(cparse_file,cparse_line, ! "'%s' is not defined as a valid scope.\n", prefix); ns = 0; } else { ! /* Check if the node scope is the current scope */ String *tname = Swig_symbol_qualifiedscopename(0); String *nname = Swig_symbol_qualifiedscopename(nstab); *************** *** 777,780 **** --- 781,786 ---- } if (ns) { + /* we will to try to create a new node using the namespaces we + can find in the scope name */ List *scopes; String *sname; *************** *** 799,805 **** } } else { ! /* this is a class, or nested classes */ si = Next(si); ns1 = Swig_symbol_clookup(sname,0); for (; si.item; si = Next(si)) { if (si.item) { --- 805,812 ---- } } else { ! /* now this last part is a class */ si = Next(si); ns1 = Swig_symbol_clookup(sname,0); + /* or a nested class tree, which is unrolled here */ for (; si.item; si = Next(si)) { if (si.item) { *************** *** 807,823 **** } } ! if (!nscope) { ! nscope = new_node("namespace"); ! Setattr(nscope,"symtab", get_global_scope()); ! } nscope_inner = Swig_symbol_clookup(sname,0); ! Printf(sname,"::%s",base); Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); ! Delete(base); base = sname; - break; } ns2 = new_node("namespace"); Setattr(ns2,"name",sname); --- 814,830 ---- } } ! /* we get the 'inner' class */ nscope_inner = Swig_symbol_clookup(sname,0); ! /* save the last namespace prefix */ ! Namespaceprefix = Swig_symbol_qualifiedscopename(0); ! /* set the scope to the inner class */ Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); ! /* and return the node name, including the inner class prefix */ ! Printf(sname,"::%s",base); Delete(base); base = sname; break; } + /* here we just populate the namespace tree as usual */ ns2 = new_node("namespace"); Setattr(ns2,"name",sname); *************** *** 827,831 **** Namespaceprefix = Swig_symbol_qualifiedscopename(0); if (nscope_inner) { ! if (Getattr(nscope_inner,"symtab") != Getattr(ns2,"symtab")) { appendChild(nscope_inner,ns2); } --- 834,838 ---- Namespaceprefix = Swig_symbol_qualifiedscopename(0); if (nscope_inner) { ! if (Getattr(nscope_inner,"symtab") != Getattr(ns2,"symtab")) { appendChild(nscope_inner,ns2); } *************** *** 2393,2401 **** /* all the overloaded templated functions are added into a linked list */ ! if (nscope) { /* non-global namespace */ if (templnode) { appendChild(nscope_inner,templnode); ! $$ = nscope; } } else { --- 2400,2408 ---- /* all the overloaded templated functions are added into a linked list */ ! if (nscope_inner) { /* non-global namespace */ if (templnode) { appendChild(nscope_inner,templnode); ! if (nscope) $$ = nscope; } } else { *************** *** 2875,2884 **** Classprefix = 0; ! if (nscope) { appendChild(nscope_inner,$$); Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); Namespaceprefix = Swig_symbol_qualifiedscopename(0); add_symbols($$); ! $$ = nscope; Swig_symbol_setscope(cscope); Namespaceprefix = Swig_symbol_qualifiedscopename(0); --- 2882,2894 ---- Classprefix = 0; ! if (nscope_inner) { ! /* this is tricky */ ! /* we add the declaration in the original namespace */ appendChild(nscope_inner,$$); Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); Namespaceprefix = Swig_symbol_qualifiedscopename(0); add_symbols($$); ! if (nscope) $$ = nscope; ! /* but the variable definition in the current scope */ Swig_symbol_setscope(cscope); Namespaceprefix = Swig_symbol_qualifiedscopename(0); *************** *** 3382,3393 **** Hash *h; $1 = Swig_symbol_current(); ! h = Swig_symbol_clookup((char *)"",0); if (h && (Strcmp(nodeType(h),"namespace") == 0)) { Swig_symbol_setscope(Getattr(h,"symtab")); } else { Swig_symbol_newscope(); ! Swig_symbol_setscopename("__unnamed__"); } ! Namespaceprefix = Swig_symbol_qualifiedscopename(0); } interface RBRACE { $$ = $4; --- 3392,3404 ---- Hash *h; $1 = Swig_symbol_current(); ! h = Swig_symbol_clookup((char *)" ",0); if (h && (Strcmp(nodeType(h),"namespace") == 0)) { Swig_symbol_setscope(Getattr(h,"symtab")); } else { Swig_symbol_newscope(); ! /* we don't use "__unnamed__", but a long 'empty' name */ ! Swig_symbol_setscopename(" "); } ! Namespaceprefix = 0; } interface RBRACE { $$ = $4; |