PageRenderTime 305ms CodeModel.GetById 21ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Source/Swig/symbol.c

#
C | 2016 lines | 1339 code | 164 blank | 513 comment | 335 complexity | 96bcfc571e5015b213f27a0279366e5e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * This file is part of SWIG, which is licensed as a whole under version 3
  3. * (or any later version) of the GNU General Public License. Some additional
  4. * terms also apply to certain portions of SWIG. The full details of the SWIG
  5. * license and copyrights can be found in the LICENSE and COPYRIGHT files
  6. * included with the SWIG source code as distributed by the SWIG developers
  7. * and at http://www.swig.org/legal.html.
  8. *
  9. * symbol.c
  10. *
  11. * This file implements the SWIG symbol table. See details below.
  12. * ----------------------------------------------------------------------------- */
  13. char cvsroot_symbol_c[] = "$Id: symbol.c 12831 2011-11-01 23:06:53Z wsfulton $";
  14. #include "swig.h"
  15. #include "swigwarn.h"
  16. #include <ctype.h>
  17. /* #define SWIG_DEBUG*/
  18. /* -----------------------------------------------------------------------------
  19. * Synopsis
  20. *
  21. * This module provides symbol table management for all of SWIG. In previous
  22. * releases, the management of symbols was rather haphazard. This module tries
  23. * to correct that.
  24. *
  25. * All symbols are associated with simple identifiers. For example, here are some
  26. * declarations that generate symbol table entries:
  27. *
  28. * decl symbol
  29. * -------------- ------------
  30. * void foo(int); foo
  31. * int x; x
  32. * typedef int *blah; blah
  33. *
  34. * Associated with each symbol is a Hash table that can contain any set of
  35. * attributes that make sense for that object. For example:
  36. *
  37. * typedef int *blah; ----> "name" : 'blah'
  38. * "type" : 'int'
  39. * "decl" : 'p.'
  40. * "storage" : 'typedef'
  41. *
  42. * In some cases, the symbol table needs to manage overloaded entries. For instance,
  43. * overloaded functions. In this case, a linked list is built. The "sym:nextSibling"
  44. * attribute is reserved to hold a link to the next entry. For example:
  45. *
  46. * int foo(int); --> "name" : "foo" "name" : "foo"
  47. * int foo(int,double); "type" : "int" "type" : "int"
  48. * "decl" : "f(int)." "decl" : "f(int,double)."
  49. * ... ...
  50. * "sym:nextSibling" : --------> "sym:nextSibling": --------> ...
  51. *
  52. * When more than one symbol has the same name, the symbol declarator is
  53. * used to detect duplicates. For example, in the above case, foo(int) and
  54. * foo(int,double) are different because their "decl" attribute is different.
  55. * However, if a third declaration "foo(int)" was made, it would generate a
  56. * conflict (due to having a declarator that matches a previous entry).
  57. *
  58. * Structures and classes:
  59. *
  60. * C/C++ symbol tables are normally managed in a few different spaces. The
  61. * most visible namespace is reserved for functions, variables, typedef, enum values
  62. * and such. In C, a separate tag-space is reserved for 'struct name', 'class name',
  63. * and 'union name' declarations. In SWIG, a single namespace is used for everything
  64. * this means that certain incompatibilities will arise with some C programs. For instance:
  65. *
  66. * struct Foo {
  67. * ...
  68. * }
  69. *
  70. * int Foo(); // Error. Name clash. Works in C though
  71. *
  72. * Due to the unified namespace for structures, special handling is performed for
  73. * the following:
  74. *
  75. * typedef struct Foo {
  76. *
  77. * } Foo;
  78. *
  79. * In this case, the symbol table contains an entry for the structure itself. The
  80. * typedef is left out of the symbol table.
  81. *
  82. * Target language vs C:
  83. *
  84. * The symbol tables are normally managed *in the namespace of the target language*.
  85. * This means that name-collisions can be resolved using %rename and related
  86. * directives. A quirk of this is that sometimes the symbol tables need to
  87. * be used for C type resolution as well. To handle this, each symbol table
  88. * also has a C-symbol table lurking behind the scenes. This is used to locate
  89. * symbols in the C namespace. However, this symbol table is not used for error
  90. * reporting nor is it used for anything else during code generation.
  91. *
  92. * Symbol table structure:
  93. *
  94. * Symbol tables themselves are a special kind of node that is organized just like
  95. * a normal parse tree node. Symbol tables are organized in a tree that can be
  96. * traversed using the SWIG-DOM API. The following attributes names are reserved.
  97. *
  98. * name -- Name of the scope defined by the symbol table (if any)
  99. * This name is the C-scope name and is not affected by
  100. * %renaming operations
  101. * symtab -- Hash table mapping identifiers to nodes.
  102. * csymtab -- Hash table mapping C identifiers to nodes.
  103. *
  104. * Reserved attributes on symbol objects:
  105. *
  106. * When a symbol is placed in the symbol table, the following attributes
  107. * are set:
  108. *
  109. * sym:name -- Symbol name
  110. * sym:nextSibling -- Next symbol (if overloaded)
  111. * sym:previousSibling -- Previous symbol (if overloaded)
  112. * sym:symtab -- Symbol table object holding the symbol
  113. * sym:overloaded -- Set to the first symbol if overloaded
  114. *
  115. * These names are modeled after XML namespaces. In particular, every attribute
  116. * pertaining to symbol table management is prefaced by the "sym:" prefix.
  117. *
  118. * An example dump of the parse tree showing symbol table entries for the
  119. * following code should clarify this:
  120. *
  121. * namespace OuterNamespace {
  122. * namespace InnerNamespace {
  123. * class Class {
  124. * };
  125. * struct Struct {
  126. * int Var;
  127. * };
  128. * }
  129. * }
  130. *
  131. * +++ namespace ----------------------------------------
  132. * | sym:name - "OuterNamespace"
  133. * | symtab - 0xa064bf0
  134. * | sym:symtab - 0xa041690
  135. * | sym:overname - "__SWIG_0"
  136. *
  137. * +++ namespace ----------------------------------------
  138. * | sym:name - "InnerNamespace"
  139. * | symtab - 0xa064cc0
  140. * | sym:symtab - 0xa064bf0
  141. * | sym:overname - "__SWIG_0"
  142. *
  143. * +++ class ----------------------------------------
  144. * | sym:name - "Class"
  145. * | symtab - 0xa064d80
  146. * | sym:symtab - 0xa064cc0
  147. * | sym:overname - "__SWIG_0"
  148. * |
  149. * +++ class ----------------------------------------
  150. * | sym:name - "Struct"
  151. * | symtab - 0xa064f00
  152. * | sym:symtab - 0xa064cc0
  153. * | sym:overname - "__SWIG_0"
  154. *
  155. * +++ cdecl ----------------------------------------
  156. * | sym:name - "Var"
  157. * | sym:symtab - 0xa064f00
  158. * | sym:overname - "__SWIG_0"
  159. * |
  160. *
  161. *
  162. * Each class and namespace has its own scope and thus a new symbol table (sym)
  163. * is created. The sym attribute is only set for the first entry in the symbol
  164. * table. The sym:symtab entry points to the symbol table in which the symbol
  165. * exists, so for example, Struct is in the scope OuterNamespace::InnerNamespace
  166. * so sym:symtab points to this symbol table (0xa064cc0).
  167. *
  168. * ----------------------------------------------------------------------------- */
  169. static Hash *current = 0; /* The current symbol table hash */
  170. static Hash *ccurrent = 0; /* The current c symbol table hash */
  171. static Hash *current_symtab = 0; /* Current symbol table node */
  172. static Hash *symtabs = 0; /* Hash of all symbol tables by fully-qualified name */
  173. static Hash *global_scope = 0; /* Global scope */
  174. /* common attribute keys, to avoid calling find_key all the times */
  175. /* -----------------------------------------------------------------------------
  176. * Swig_symbol_print_tables()
  177. *
  178. * Debug display of symbol tables
  179. * ----------------------------------------------------------------------------- */
  180. void Swig_symbol_print_tables(Symtab *symtab) {
  181. if (!symtab)
  182. symtab = current_symtab;
  183. Printf(stdout, "SYMBOL TABLES start =======================================\n");
  184. Swig_print_tree(symtab);
  185. Printf(stdout, "SYMBOL TABLES finish =======================================\n");
  186. }
  187. /* -----------------------------------------------------------------------------
  188. * Swig_symbol_print_tables_summary()
  189. *
  190. * Debug summary display of all symbol tables by fully-qualified name
  191. * ----------------------------------------------------------------------------- */
  192. void Swig_symbol_print_tables_summary(void) {
  193. Printf(stdout, "SYMBOL TABLES SUMMARY start =======================================\n");
  194. Swig_print_node(symtabs);
  195. Printf(stdout, "SYMBOL TABLES SUMMARY finish =======================================\n");
  196. }
  197. /* -----------------------------------------------------------------------------
  198. * symbol_print_symbols()
  199. * ----------------------------------------------------------------------------- */
  200. static void symbol_print_symbols(const char *symboltabletype) {
  201. Node *table = symtabs;
  202. Iterator ki = First(table);
  203. while (ki.key) {
  204. String *k = ki.key;
  205. Printf(stdout, "===================================================\n");
  206. Printf(stdout, "%s -\n", k);
  207. {
  208. Symtab *symtab = Getattr(Getattr(table, k), symboltabletype);
  209. Iterator it = First(symtab);
  210. while (it.key) {
  211. String *symname = it.key;
  212. Printf(stdout, " %s\n", symname);
  213. /*
  214. Printf(stdout, " %s - %p (%s)\n", symname, it.item, Getattr(it.item, "name"));
  215. */
  216. it = Next(it);
  217. }
  218. }
  219. ki = Next(ki);
  220. }
  221. }
  222. /* -----------------------------------------------------------------------------
  223. * Swig_symbol_print_symbols()
  224. *
  225. * Debug display of all the target language symbols
  226. * ----------------------------------------------------------------------------- */
  227. void Swig_symbol_print_symbols(void) {
  228. Printf(stdout, "SYMBOLS start =======================================\n");
  229. symbol_print_symbols("symtab");
  230. Printf(stdout, "SYMBOLS finish =======================================\n");
  231. }
  232. /* -----------------------------------------------------------------------------
  233. * Swig_symbol_print_csymbols()
  234. *
  235. * Debug display of all the C symbols
  236. * ----------------------------------------------------------------------------- */
  237. void Swig_symbol_print_csymbols(void) {
  238. Printf(stdout, "CSYMBOLS start =======================================\n");
  239. symbol_print_symbols("csymtab");
  240. Printf(stdout, "CSYMBOLS finish =======================================\n");
  241. }
  242. /* -----------------------------------------------------------------------------
  243. * Swig_symbol_init()
  244. *
  245. * Create a new symbol table object
  246. * ----------------------------------------------------------------------------- */
  247. void Swig_symbol_init(void) {
  248. current = NewHash();
  249. current_symtab = NewHash();
  250. ccurrent = NewHash();
  251. set_nodeType(current_symtab, "symboltable");
  252. Setattr(current_symtab, "symtab", current);
  253. Delete(current);
  254. Setattr(current_symtab, "csymtab", ccurrent);
  255. Delete(ccurrent);
  256. /* Set the global scope */
  257. symtabs = NewHash();
  258. Setattr(symtabs, "", current_symtab);
  259. Delete(current_symtab);
  260. global_scope = current_symtab;
  261. }
  262. /* -----------------------------------------------------------------------------
  263. * Swig_symbol_setscopename()
  264. *
  265. * Set the C scopename of the current symbol table.
  266. * ----------------------------------------------------------------------------- */
  267. void Swig_symbol_setscopename(const_String_or_char_ptr name) {
  268. String *qname;
  269. /* assert(!Getattr(current_symtab,"name")); */
  270. Setattr(current_symtab, "name", name);
  271. /* Set nested scope in parent */
  272. qname = Swig_symbol_qualifiedscopename(current_symtab);
  273. /* Save a reference to this scope */
  274. Setattr(symtabs, qname, current_symtab);
  275. Delete(qname);
  276. }
  277. /* -----------------------------------------------------------------------------
  278. * Swig_symbol_getscopename()
  279. *
  280. * Get the C scopename of the current symbol table
  281. * ----------------------------------------------------------------------------- */
  282. String *Swig_symbol_getscopename(void) {
  283. return Getattr(current_symtab, "name");
  284. }
  285. /* -----------------------------------------------------------------------------
  286. * Swig_symbol_getscope()
  287. *
  288. * Given a fully qualified C scopename, this function returns a symbol table
  289. * ----------------------------------------------------------------------------- */
  290. Symtab *Swig_symbol_getscope(const_String_or_char_ptr name) {
  291. if (!symtabs)
  292. return 0;
  293. if (Equal("::", (const_String_or_char_ptr ) name))
  294. name = "";
  295. return Getattr(symtabs, name);
  296. }
  297. /* -----------------------------------------------------------------------------
  298. * Swig_symbol_qualifiedscopename()
  299. *
  300. * Get the fully qualified C scopename of a symbol table. Note, this only pertains
  301. * to the C/C++ scope name. It is not affected by renaming.
  302. * ----------------------------------------------------------------------------- */
  303. String *Swig_symbol_qualifiedscopename(Symtab *symtab) {
  304. String *result = 0;
  305. Hash *parent;
  306. String *name;
  307. if (!symtab)
  308. symtab = current_symtab;
  309. parent = Getattr(symtab, "parentNode");
  310. if (parent) {
  311. result = Swig_symbol_qualifiedscopename(parent);
  312. }
  313. name = Getattr(symtab, "name");
  314. if (name) {
  315. if (!result) {
  316. result = NewStringEmpty();
  317. }
  318. if (Len(result)) {
  319. Printv(result, "::", name, NIL);
  320. } else {
  321. Append(result, name);
  322. }
  323. }
  324. return result;
  325. }
  326. /* -----------------------------------------------------------------------------
  327. * Swig_symbol_qualified_language_scopename()
  328. *
  329. * Get the fully qualified C scopename of a symbol table but using a language
  330. * specific separator for the scopenames. Basically the same as
  331. * Swig_symbol_qualifiedscopename() but using the different separator.
  332. * ----------------------------------------------------------------------------- */
  333. String *Swig_symbol_qualified_language_scopename(Symtab *n) {
  334. /* TODO: fix for %rename to work */
  335. String *result = Swig_symbol_qualifiedscopename(n);
  336. Replaceall(result, "::", NSPACE_SEPARATOR);
  337. return result;
  338. }
  339. /* -----------------------------------------------------------------------------
  340. * Swig_symbol_newscope()
  341. *
  342. * Create a new scope. Returns the newly created scope.
  343. * ----------------------------------------------------------------------------- */
  344. Symtab *Swig_symbol_newscope(void) {
  345. Hash *n;
  346. Hash *hsyms, *h;
  347. hsyms = NewHash();
  348. h = NewHash();
  349. set_nodeType(h, "symboltable");
  350. Setattr(h, "symtab", hsyms);
  351. Delete(hsyms);
  352. set_parentNode(h, current_symtab);
  353. n = lastChild(current_symtab);
  354. if (!n) {
  355. set_firstChild(current_symtab, h);
  356. } else {
  357. set_nextSibling(n, h);
  358. Delete(h);
  359. }
  360. set_lastChild(current_symtab, h);
  361. current = hsyms;
  362. ccurrent = NewHash();
  363. Setattr(h, "csymtab", ccurrent);
  364. Delete(ccurrent);
  365. current_symtab = h;
  366. return h;
  367. }
  368. /* -----------------------------------------------------------------------------
  369. * Swig_symbol_setscope()
  370. *
  371. * Set the current scope. Returns the previous current scope.
  372. * ----------------------------------------------------------------------------- */
  373. Symtab *Swig_symbol_setscope(Symtab *sym) {
  374. Symtab *ret = current_symtab;
  375. current_symtab = sym;
  376. current = Getattr(sym, "symtab");
  377. assert(current);
  378. ccurrent = Getattr(sym, "csymtab");
  379. assert(ccurrent);
  380. return ret;
  381. }
  382. /* -----------------------------------------------------------------------------
  383. * Swig_symbol_popscope()
  384. *
  385. * Pop out of the current scope. Returns the popped scope and sets the
  386. * scope to the parent scope.
  387. * ----------------------------------------------------------------------------- */
  388. Symtab *Swig_symbol_popscope(void) {
  389. Hash *h = current_symtab;
  390. current_symtab = Getattr(current_symtab, "parentNode");
  391. assert(current_symtab);
  392. current = Getattr(current_symtab, "symtab");
  393. assert(current);
  394. ccurrent = Getattr(current_symtab, "csymtab");
  395. assert(ccurrent);
  396. return h;
  397. }
  398. /* -----------------------------------------------------------------------------
  399. * Swig_symbol_global_scope()
  400. *
  401. * Return the symbol table for the global scope.
  402. * ----------------------------------------------------------------------------- */
  403. Symtab *Swig_symbol_global_scope(void) {
  404. return global_scope;
  405. }
  406. /* -----------------------------------------------------------------------------
  407. * Swig_symbol_current()
  408. *
  409. * Return the current symbol table.
  410. * ----------------------------------------------------------------------------- */
  411. Symtab *Swig_symbol_current(void) {
  412. return current_symtab;
  413. }
  414. /* -----------------------------------------------------------------------------
  415. * Swig_symbol_alias()
  416. *
  417. * Makes an alias for a symbol in the global symbol table.
  418. * ----------------------------------------------------------------------------- */
  419. void Swig_symbol_alias(const_String_or_char_ptr aliasname, Symtab *s) {
  420. String *qname = Swig_symbol_qualifiedscopename(current_symtab);
  421. if (qname) {
  422. Printf(qname, "::%s", aliasname);
  423. } else {
  424. qname = NewString(aliasname);
  425. }
  426. if (!Getattr(symtabs, qname)) {
  427. Setattr(symtabs, qname, s);
  428. }
  429. Delete(qname);
  430. }
  431. /* -----------------------------------------------------------------------------
  432. * Swig_symbol_inherit()
  433. *
  434. * Inherit symbols from another scope.
  435. * ----------------------------------------------------------------------------- */
  436. void Swig_symbol_inherit(Symtab *s) {
  437. int i, ilen;
  438. List *inherit = Getattr(current_symtab, "inherit");
  439. if (!inherit) {
  440. inherit = NewList();
  441. Setattr(current_symtab, "inherit", inherit);
  442. Delete(inherit);
  443. }
  444. if (s == current_symtab) {
  445. Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(s), Getline(s), "Recursive scope inheritance of '%s'.\n", Getattr(s, "name"));
  446. return;
  447. }
  448. assert(s != current_symtab);
  449. ilen = Len(inherit);
  450. for (i = 0; i < ilen; i++) {
  451. Node *n = Getitem(inherit, i);
  452. if (n == s)
  453. return; /* Already inherited */
  454. }
  455. Append(inherit, s);
  456. }
  457. /* -----------------------------------------------------------------------------
  458. * Swig_symbol_cadd()
  459. *
  460. * Adds a node to the C symbol table only.
  461. * ----------------------------------------------------------------------------- */
  462. void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
  463. Node *append = 0;
  464. Node *cn;
  465. /* There are a few options for weak symbols. A "weak" symbol
  466. is any symbol that can be replaced by another symbol in the C symbol
  467. table. An example would be a forward class declaration. A forward
  468. class sits in the symbol table until a real class declaration comes along.
  469. Certain symbols are marked as "sym:typename". These are important
  470. symbols related to the C++ type-system and take precedence in the C
  471. symbol table. An example might be code like this:
  472. template<class T> T foo(T x);
  473. int foo(int);
  474. In this case, the template is marked with "sym:typename" so that it
  475. stays in the C symbol table (so that it can be expanded using %template).
  476. */
  477. if (!name)
  478. return;
  479. if (SwigType_istemplate(name)) {
  480. String *cname = NewString(name);
  481. String *dname = Swig_symbol_template_deftype(cname, 0);
  482. if (!Equal(dname, name)) {
  483. Swig_symbol_cadd(dname, n);
  484. }
  485. Delete(dname);
  486. Delete(cname);
  487. }
  488. #ifdef SWIG_DEBUG
  489. Printf(stderr, "symbol_cadd %s %x\n", name, n);
  490. #endif
  491. cn = Getattr(ccurrent, name);
  492. if (cn && (Getattr(cn, "sym:typename"))) {
  493. /* The node in the C symbol table is a typename. Do nothing */
  494. /* We might append the symbol at the end */
  495. append = n;
  496. } else if (cn && (Getattr(cn, "sym:weak"))) {
  497. /* The node in the symbol table is weak. Replace it */
  498. if (checkAttribute(cn, "nodeType", "template")
  499. && checkAttribute(cn, "templatetype", "classforward")) {
  500. /* The node is a template classforward declaration, and the
  501. default template parameters here take precedence. */
  502. ParmList *pc = Getattr(cn, "templateparms");
  503. ParmList *pn = Getattr(n, "templateparms");
  504. #ifdef SWIG_DEBUG
  505. Printf(stderr, "found template classforward %s\n", Getattr(cn, "name"));
  506. #endif
  507. while (pc && pn) {
  508. String *value = Getattr(pc, "value");
  509. if (value) {
  510. #ifdef SWIG_DEBUG
  511. Printf(stderr, "add default template value %s %s\n", Getattr(pc, "name"), value);
  512. #endif
  513. Setattr(pn, "value", value);
  514. }
  515. pc = nextSibling(pc);
  516. pn = nextSibling(pn);
  517. }
  518. Setattr(n, "templateparms", Getattr(cn, "templateparms"));
  519. }
  520. Setattr(ccurrent, name, n);
  521. } else if (cn && (Getattr(n, "sym:weak"))) {
  522. /* The node being added is weak. Don't worry about it */
  523. } else if (cn && (Getattr(n, "sym:typename"))) {
  524. /* The node being added is a typename. We definitely add it */
  525. Setattr(ccurrent, name, n);
  526. append = cn;
  527. } else if (cn && (Checkattr(cn, "nodeType", "templateparm"))) {
  528. Swig_error(Getfile(n), Getline(n), "Declaration of '%s' shadows template parameter,\n", name);
  529. Swig_error(Getfile(cn), Getline(cn), "previous template parameter declaration '%s'.\n", name);
  530. return;
  531. } else if (cn) {
  532. append = n;
  533. } else if (!cn) {
  534. /* No conflict. Add the symbol */
  535. Setattr(ccurrent, name, n);
  536. }
  537. /* Multiple entries in the C symbol table. We append to to the symbol table */
  538. if (append) {
  539. Node *fn, *pn = 0;
  540. cn = Getattr(ccurrent, name);
  541. fn = cn;
  542. while (fn) {
  543. pn = fn;
  544. if (fn == append) {
  545. /* already added. Bail */
  546. return;
  547. }
  548. fn = Getattr(fn, "csym:nextSibling");
  549. }
  550. if (pn) {
  551. Setattr(pn, "csym:nextSibling", append);
  552. }
  553. }
  554. /* Special typedef handling. When a typedef node is added to the symbol table, we
  555. might have to add a type alias. This would occur if the typedef mapped to another
  556. scope in the system. For example:
  557. class Foo {
  558. };
  559. typedef Foo OtherFoo;
  560. In this case, OtherFoo becomes an alias for Foo. */
  561. {
  562. Node *td = n;
  563. while (td && Checkattr(td, "nodeType", "cdecl") && Checkattr(td, "storage", "typedef")) {
  564. SwigType *type;
  565. Node *td1;
  566. type = Copy(Getattr(td, "type"));
  567. SwigType_push(type, Getattr(td, "decl"));
  568. td1 = Swig_symbol_clookup(type, 0);
  569. /* Fix pathetic case #1214313:
  570. class Foo
  571. {
  572. };
  573. typedef Foo FooBar;
  574. class CBaz
  575. {
  576. public:
  577. typedef FooBar Foo;
  578. };
  579. ie, when Foo -> FooBar -> Foo, jump one scope up when possible.
  580. */
  581. if (td1 && Checkattr(td1, "storage", "typedef")) {
  582. String *st = Getattr(td1, "type");
  583. String *sn = Getattr(td, "name");
  584. if (st && sn && Equal(st, sn)) {
  585. Symtab *sc = Getattr(current_symtab, "parentNode");
  586. if (sc)
  587. td1 = Swig_symbol_clookup(type, sc);
  588. }
  589. }
  590. Delete(type);
  591. if (td1 == td)
  592. break;
  593. td = td1;
  594. if (td) {
  595. Symtab *st = Getattr(td, "symtab");
  596. if (st) {
  597. Swig_symbol_alias(Getattr(n, "name"), st);
  598. break;
  599. }
  600. }
  601. }
  602. }
  603. }
  604. /* -----------------------------------------------------------------------------
  605. * Swig_symbol_add()
  606. *
  607. * Adds a node to the symbol table. Returns the node itself if successfully
  608. * added. Otherwise, it returns the symbol table entry of the conflicting node.
  609. *
  610. * Also places the symbol in a behind-the-scenes C symbol table. This is needed
  611. * for namespace support, type resolution, and other issues.
  612. * ----------------------------------------------------------------------------- */
  613. Node *Swig_symbol_add(const_String_or_char_ptr symname, Node *n) {
  614. Hash *c, *cn, *cl = 0;
  615. SwigType *decl, *ndecl;
  616. String *cstorage, *nstorage;
  617. int nt = 0, ct = 0;
  618. int pn = 0;
  619. int u1 = 0, u2 = 0;
  620. String *name, *overname;
  621. /* See if the node has a name. If so, we place in the C symbol table for this
  622. scope. We don't worry about overloading here---the primary purpose of this
  623. is to record information for type/name resolution for later. Conflicts
  624. in C namespaces are errors, but these will be caught by the C++ compiler
  625. when compiling the wrapper code */
  626. /* There are a few options for weak symbols. A "weak" symbol
  627. is any symbol that can be replaced by another symbol in the C symbol
  628. table. An example would be a forward class declaration. A forward
  629. class sits in the symbol table until a real class declaration comes along.
  630. Certain symbols are marked as "sym:typename". These are important
  631. symbols related to the C++ type-system and take precedence in the C
  632. symbol table. An example might be code like this:
  633. template<class T> T foo(T x);
  634. int foo(int);
  635. In this case, the template is marked with "sym:typename" so that it
  636. stays in the C symbol table (so that it can be expanded using %template).
  637. */
  638. name = Getattr(n, "name");
  639. if (name && Len(name)) {
  640. Swig_symbol_cadd(name, n);
  641. }
  642. /* No symbol name defined. We return. */
  643. if (!symname) {
  644. Setattr(n, "sym:symtab", current_symtab);
  645. return n;
  646. }
  647. /* If node is ignored. We don't proceed any further */
  648. if (GetFlag(n, "feature:ignore"))
  649. return n;
  650. /* See if the symbol already exists in the table */
  651. c = Getattr(current, symname);
  652. /* Check for a weak symbol. A weak symbol is allowed to be in the
  653. symbol table, but is silently overwritten by other symbols. An example
  654. would be a forward class declaration. For instance:
  655. class Foo;
  656. In this case, "Foo" sits in the symbol table. However, the
  657. definition of Foo would replace the entry if it appeared later. */
  658. if (c && Getattr(c, "sym:weak")) {
  659. c = 0;
  660. }
  661. if (c) {
  662. /* There is a symbol table conflict. There are a few cases to consider here:
  663. (1) A conflict between a class/enum and a typedef declaration is okay.
  664. In this case, the symbol table entry is set to the class/enum declaration
  665. itself, not the typedef.
  666. (2) A conflict between namespaces is okay--namespaces are open
  667. (3) Otherwise, overloading is only allowed for functions
  668. */
  669. /* Check for namespaces */
  670. String *ntype = Getattr(n, "nodeType");
  671. if ((Equal(ntype, Getattr(c, "nodeType"))) && ((Equal(ntype, "namespace")))) {
  672. Node *cl, *pcl = 0;
  673. cl = c;
  674. while (cl) {
  675. pcl = cl;
  676. cl = Getattr(cl, "sym:nextSibling");
  677. }
  678. Setattr(pcl, "sym:nextSibling", n);
  679. Setattr(n, "sym:symtab", current_symtab);
  680. Setattr(n, "sym:name", symname);
  681. Setattr(n, "sym:previousSibling", pcl);
  682. return n;
  683. }
  684. if (Getattr(n, "allows_typedef"))
  685. nt = 1;
  686. if (Getattr(c, "allows_typedef"))
  687. ct = 1;
  688. if (nt || ct) {
  689. Node *td, *other;
  690. String *s;
  691. /* At least one of the nodes allows typedef overloading. Make sure that
  692. both don't--this would be a conflict */
  693. if (nt && ct)
  694. return c;
  695. /* Figure out which node allows the typedef */
  696. if (nt) {
  697. td = n;
  698. other = c;
  699. } else {
  700. td = c;
  701. other = n;
  702. }
  703. /* Make sure the other node is a typedef */
  704. s = Getattr(other, "storage");
  705. if (!s || (!Equal(s, "typedef")))
  706. return c; /* No. This is a conflict */
  707. /* Hmmm. This appears to be okay. Make sure the symbol table refers to the allow_type node */
  708. if (td != c) {
  709. Setattr(current, symname, td);
  710. Setattr(td, "sym:symtab", current_symtab);
  711. Setattr(td, "sym:name", symname);
  712. }
  713. return n;
  714. }
  715. decl = Getattr(c, "decl");
  716. ndecl = Getattr(n, "decl");
  717. {
  718. String *nt1, *nt2;
  719. nt1 = Getattr(n, "nodeType");
  720. if (Equal(nt1, "template"))
  721. nt1 = Getattr(n, "templatetype");
  722. nt2 = Getattr(c, "nodeType");
  723. if (Equal(nt2, "template"))
  724. nt2 = Getattr(c, "templatetype");
  725. if (Equal(nt1, "using"))
  726. u1 = 1;
  727. if (Equal(nt2, "using"))
  728. u2 = 1;
  729. if ((!Equal(nt1, nt2)) && !(u1 || u2))
  730. return c;
  731. }
  732. if (!(u1 || u2)) {
  733. if ((!SwigType_isfunction(decl)) || (!SwigType_isfunction(ndecl))) {
  734. /* Symbol table conflict */
  735. return c;
  736. }
  737. }
  738. /* Hmmm. Declarator seems to indicate that this is a function */
  739. /* Look at storage class to see if compatible */
  740. cstorage = Getattr(c, "storage");
  741. nstorage = Getattr(n, "storage");
  742. /* If either one is declared as typedef, forget it. We're hosed */
  743. if (Cmp(cstorage, "typedef") == 0) {
  744. return c;
  745. }
  746. if (Cmp(nstorage, "typedef") == 0) {
  747. return c;
  748. }
  749. /* Okay. Walk down the list of symbols and see if we get a declarator match */
  750. {
  751. String *nt = Getattr(n, "nodeType");
  752. int n_template = Equal(nt, "template") && Checkattr(n, "templatetype", "cdecl");
  753. int n_plain_cdecl = Equal(nt, "cdecl");
  754. cn = c;
  755. pn = 0;
  756. while (cn) {
  757. decl = Getattr(cn, "decl");
  758. if (!(u1 || u2)) {
  759. if (Cmp(ndecl, decl) == 0) {
  760. /* Declarator conflict */
  761. /* Now check we don't have a non-templated function overloaded by a templated function with same params,
  762. * eg void foo(); template<typename> void foo(); */
  763. String *cnt = Getattr(cn, "nodeType");
  764. int cn_template = Equal(cnt, "template") && Checkattr(cn, "templatetype", "cdecl");
  765. int cn_plain_cdecl = Equal(cnt, "cdecl");
  766. if (!((n_template && cn_plain_cdecl) || (cn_template && n_plain_cdecl))) {
  767. /* found a conflict */
  768. return cn;
  769. }
  770. }
  771. }
  772. cl = cn;
  773. cn = Getattr(cn, "sym:nextSibling");
  774. pn++;
  775. }
  776. }
  777. /* Well, we made it this far. Guess we can drop the symbol in place */
  778. Setattr(n, "sym:symtab", current_symtab);
  779. Setattr(n, "sym:name", symname);
  780. /* Printf(stdout,"%s %x\n", Getattr(n,"sym:overname"), current_symtab); */
  781. assert(!Getattr(n, "sym:overname"));
  782. overname = NewStringf("__SWIG_%d", pn);
  783. Setattr(n, "sym:overname", overname);
  784. /*Printf(stdout,"%s %s %s\n", symname, Getattr(n,"decl"), Getattr(n,"sym:overname")); */
  785. Setattr(cl, "sym:nextSibling", n);
  786. Setattr(n, "sym:previousSibling", cl);
  787. Setattr(cl, "sym:overloaded", c);
  788. Setattr(n, "sym:overloaded", c);
  789. Delete(overname);
  790. return n;
  791. }
  792. /* No conflict. Just add it */
  793. Setattr(n, "sym:symtab", current_symtab);
  794. Setattr(n, "sym:name", symname);
  795. /* Printf(stdout,"%s\n", Getattr(n,"sym:overname")); */
  796. overname = NewStringf("__SWIG_%d", pn);
  797. Setattr(n, "sym:overname", overname);
  798. Delete(overname);
  799. /* Printf(stdout,"%s %s %s\n", symname, Getattr(n,"decl"), Getattr(n,"sym:overname")); */
  800. Setattr(current, symname, n);
  801. return n;
  802. }
  803. /* -----------------------------------------------------------------------------
  804. * symbol_lookup()
  805. *
  806. * Internal function to handle fully qualified symbol table lookups. This
  807. * works from the symbol table supplied in symtab and unwinds its way out
  808. * towards the global scope.
  809. *
  810. * This function operates in the C namespace, not the target namespace.
  811. *
  812. * The check function is an optional callback that can be used to verify a particular
  813. * symbol match. This is only used in some of the more exotic parts of SWIG. For instance,
  814. * verifying that a class hierarchy implements all pure virtual methods.
  815. * ----------------------------------------------------------------------------- */
  816. static Node *_symbol_lookup(const String *name, Symtab *symtab, int (*check) (Node *n)) {
  817. Node *n;
  818. List *inherit;
  819. Hash *sym = Getattr(symtab, "csymtab");
  820. if (Getmark(symtab))
  821. return 0;
  822. Setmark(symtab, 1);
  823. n = Getattr(sym, name);
  824. #ifdef SWIG_DEBUG
  825. Printf(stderr, "symbol_look %s %x %x %s\n", name, n, symtab, Getattr(symtab, "name"));
  826. #endif
  827. if (n) {
  828. /* if a check-function is defined. Call it to determine a match */
  829. if (check) {
  830. int c = check(n);
  831. if (c == 1) {
  832. Setmark(symtab, 0);
  833. return n;
  834. }
  835. if (c < 0) {
  836. /* Terminate the search right away */
  837. Setmark(symtab, 0);
  838. return 0;
  839. }
  840. } else {
  841. Setmark(symtab, 0);
  842. return n;
  843. }
  844. }
  845. if (!n && SwigType_istemplate(name)) {
  846. String *dname = 0;
  847. Setmark(symtab, 0);
  848. dname = Swig_symbol_template_deftype(name, symtab);
  849. if (!Equal(dname, name)) {
  850. n = _symbol_lookup(dname, symtab, check);
  851. }
  852. Delete(dname);
  853. if (n)
  854. return n;
  855. Setmark(symtab, 1);
  856. }
  857. inherit = Getattr(symtab, "inherit");
  858. if (inherit) {
  859. int i, len;
  860. len = Len(inherit);
  861. for (i = 0; i < len; i++) {
  862. n = _symbol_lookup(name, Getitem(inherit, i), check);
  863. if (n) {
  864. Setmark(symtab, 0);
  865. return n;
  866. }
  867. }
  868. }
  869. Setmark(symtab, 0);
  870. return 0;
  871. }
  872. static Node *symbol_lookup(const_String_or_char_ptr name, Symtab *symtab, int (*check) (Node *n)) {
  873. Node *n = 0;
  874. if (DohCheck(name)) {
  875. n = _symbol_lookup(name, symtab, check);
  876. } else {
  877. String *sname = NewString(name);
  878. n = _symbol_lookup(sname, symtab, check);
  879. Delete(sname);
  880. }
  881. return n;
  882. }
  883. /* -----------------------------------------------------------------------------
  884. * symbol_lookup_qualified()
  885. * ----------------------------------------------------------------------------- */
  886. static Node *symbol_lookup_qualified(const_String_or_char_ptr name, Symtab *symtab, const String *prefix, int local, int (*checkfunc) (Node *n)) {
  887. /* This is a little funky, we search by fully qualified names */
  888. if (!symtab)
  889. return 0;
  890. if (!prefix) {
  891. Node *n;
  892. String *bname;
  893. String *prefix;
  894. Swig_scopename_split(name, &prefix, &bname);
  895. n = symbol_lookup_qualified(bname, symtab, prefix, local, checkfunc);
  896. Delete(bname);
  897. Delete(prefix);
  898. return n;
  899. } else {
  900. Symtab *st;
  901. Node *n = 0;
  902. /* Make qualified name of current scope */
  903. String *qalloc = 0;
  904. String *qname = Swig_symbol_qualifiedscopename(symtab);
  905. const String *cqname;
  906. if (qname) {
  907. if (Len(qname)) {
  908. if (prefix && Len(prefix)) {
  909. Printv(qname, "::", prefix, NIL);
  910. }
  911. } else {
  912. Append(qname, prefix);
  913. }
  914. qalloc = qname;
  915. cqname = qname;
  916. } else {
  917. cqname = prefix;
  918. }
  919. st = Getattr(symtabs, cqname);
  920. /* Found a scope match */
  921. if (st) {
  922. if (!name) {
  923. if (qalloc)
  924. Delete(qalloc);
  925. return st;
  926. }
  927. n = symbol_lookup(name, st, checkfunc);
  928. }
  929. if (qalloc)
  930. Delete(qalloc);
  931. if (!n) {
  932. if (!local) {
  933. Node *pn = Getattr(symtab, "parentNode");
  934. if (pn)
  935. n = symbol_lookup_qualified(name, pn, prefix, local, checkfunc);
  936. } else {
  937. n = 0;
  938. }
  939. }
  940. return n;
  941. }
  942. }
  943. /* -----------------------------------------------------------------------------
  944. * Swig_symbol_clookup()
  945. *
  946. * Look up a symbol in the symbol table. This uses the C name, not scripting
  947. * names. Note: If we come across a using a directive, we follow it to
  948. * to get the real node.
  949. * ----------------------------------------------------------------------------- */
  950. Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) {
  951. Hash *hsym = 0;
  952. Node *s = 0;
  953. if (!n) {
  954. hsym = current_symtab;
  955. } else {
  956. if (!Checkattr(n, "nodeType", "symboltable")) {
  957. n = Getattr(n, "sym:symtab");
  958. }
  959. assert(n);
  960. if (n) {
  961. hsym = n;
  962. }
  963. }
  964. if (Swig_scopename_check(name)) {
  965. char *cname = Char(name);
  966. if (strncmp(cname, "::", 2) == 0) {
  967. String *nname = NewString(cname + 2);
  968. if (Swig_scopename_check(nname)) {
  969. s = symbol_lookup_qualified(nname, global_scope, 0, 0, 0);
  970. } else {
  971. s = symbol_lookup(nname, global_scope, 0);
  972. }
  973. Delete(nname);
  974. } else {
  975. String *prefix = Swig_scopename_prefix(name);
  976. if (prefix) {
  977. s = symbol_lookup_qualified(name, hsym, 0, 0, 0);
  978. Delete(prefix);
  979. if (!s) {
  980. return 0;
  981. }
  982. }
  983. }
  984. }
  985. if (!s) {
  986. while (hsym) {
  987. s = symbol_lookup(name, hsym, 0);
  988. if (s)
  989. break;
  990. hsym = Getattr(hsym, "parentNode");
  991. if (!hsym)
  992. break;
  993. }
  994. }
  995. if (!s) {
  996. return 0;
  997. }
  998. /* Check if s is a 'using' node */
  999. while (s && Checkattr(s, "nodeType", "using")) {
  1000. String *uname = Getattr(s, "uname");
  1001. Symtab *un = Getattr(s, "sym:symtab");
  1002. Node *ss = (!Equal(name, uname) || (un != n)) ? Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */
  1003. if (!ss) {
  1004. Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
  1005. }
  1006. s = ss;
  1007. }
  1008. return s;
  1009. }
  1010. /* -----------------------------------------------------------------------------
  1011. * Swig_symbol_clookup_check()
  1012. *
  1013. * This function is identical to Swig_symbol_clookup() except that it
  1014. * accepts a callback function that is invoked to determine a symbol match.
  1015. * The purpose of this function is to support complicated algorithms that need
  1016. * to examine multiple definitions of the same symbol that might appear in an
  1017. * inheritance hierarchy.
  1018. * ----------------------------------------------------------------------------- */
  1019. Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (*checkfunc) (Node *n)) {
  1020. Hash *hsym = 0;
  1021. Node *s = 0;
  1022. if (!n) {
  1023. hsym = current_symtab;
  1024. } else {
  1025. if (!Checkattr(n, "nodeType", "symboltable")) {
  1026. n = Getattr(n, "sym:symtab");
  1027. }
  1028. assert(n);
  1029. if (n) {
  1030. hsym = n;
  1031. }
  1032. }
  1033. if (Swig_scopename_check(name)) {
  1034. char *cname = Char(name);
  1035. if (strncmp(cname, "::", 2) == 0) {
  1036. String *nname = NewString(cname + 2);
  1037. if (Swig_scopename_check(nname)) {
  1038. s = symbol_lookup_qualified(nname, global_scope, 0, 0, checkfunc);
  1039. } else {
  1040. s = symbol_lookup(nname, global_scope, checkfunc);
  1041. }
  1042. Delete(nname);
  1043. } else {
  1044. String *prefix = Swig_scopename_prefix(name);
  1045. if (prefix) {
  1046. s = symbol_lookup_qualified(name, hsym, 0, 0, checkfunc);
  1047. Delete(prefix);
  1048. if (!s) {
  1049. return 0;
  1050. }
  1051. }
  1052. }
  1053. }
  1054. if (!s) {
  1055. while (hsym) {
  1056. s = symbol_lookup(name, hsym, checkfunc);
  1057. if (s)
  1058. break;
  1059. hsym = Getattr(hsym, "parentNode");
  1060. if (!hsym)
  1061. break;
  1062. }
  1063. }
  1064. if (!s) {
  1065. return 0;
  1066. }
  1067. /* Check if s is a 'using' node */
  1068. while (s && Checkattr(s, "nodeType", "using")) {
  1069. Node *ss;
  1070. ss = Swig_symbol_clookup(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
  1071. if (!ss && !checkfunc) {
  1072. Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
  1073. }
  1074. s = ss;
  1075. }
  1076. return s;
  1077. }
  1078. /* -----------------------------------------------------------------------------
  1079. * Swig_symbol_clookup_local()
  1080. * ----------------------------------------------------------------------------- */
  1081. Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) {
  1082. Hash *hsym;
  1083. Node *s = 0;
  1084. if (!n) {
  1085. hsym = current_symtab;
  1086. } else {
  1087. if (!Checkattr(n, "nodeType", "symboltable")) {
  1088. n = Getattr(n, "sym:symtab");
  1089. }
  1090. assert(n);
  1091. hsym = n;
  1092. }
  1093. if (Swig_scopename_check(name)) {
  1094. char *cname = Char(name);
  1095. if (strncmp(cname, "::", 2) == 0) {
  1096. String *nname = NewString(cname + 2);
  1097. if (Swig_scopename_check(nname)) {
  1098. s = symbol_lookup_qualified(nname, global_scope, 0, 0, 0);
  1099. } else {
  1100. s = symbol_lookup(nname, global_scope, 0);
  1101. }
  1102. Delete(nname);
  1103. } else {
  1104. s = symbol_lookup_qualified(name, hsym, 0, 0, 0);
  1105. }
  1106. }
  1107. if (!s) {
  1108. s = symbol_lookup(name, hsym, 0);
  1109. }
  1110. if (!s)
  1111. return 0;
  1112. /* Check if s is a 'using' node */
  1113. while (s && Checkattr(s, "nodeType", "using")) {
  1114. Node *ss = Swig_symbol_clookup_local(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
  1115. if (!ss) {
  1116. Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
  1117. }
  1118. s = ss;
  1119. }
  1120. return s;
  1121. }
  1122. /* -----------------------------------------------------------------------------
  1123. * Swig_symbol_clookup_local_check()
  1124. * ----------------------------------------------------------------------------- */
  1125. Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n, int (*checkfunc) (Node *)) {
  1126. Hash *hsym;
  1127. Node *s = 0;
  1128. if (!n) {
  1129. hsym = current_symtab;
  1130. } else {
  1131. if (!Checkattr(n, "nodeType", "symboltable")) {
  1132. n = Getattr(n, "sym:symtab");
  1133. }
  1134. assert(n);
  1135. hsym = n;
  1136. }
  1137. if (Swig_scopename_check(name)) {
  1138. char *cname = Char(name);
  1139. if (strncmp(cname, "::", 2) == 0) {
  1140. String *nname = NewString(cname + 2);
  1141. if (Swig_scopename_check(nname)) {
  1142. s = symbol_lookup_qualified(nname, global_scope, 0, 0, checkfunc);
  1143. } else {
  1144. s = symbol_lookup(nname, global_scope, checkfunc);
  1145. }
  1146. Delete(nname);
  1147. } else {
  1148. s = symbol_lookup_qualified(name, hsym, 0, 0, checkfunc);
  1149. }
  1150. }
  1151. if (!s) {
  1152. s = symbol_lookup(name, hsym, checkfunc);
  1153. }
  1154. if (!s)
  1155. return 0;
  1156. /* Check if s is a 'using' node */
  1157. while (s && Checkattr(s, "nodeType", "using")) {
  1158. Node *ss = Swig_symbol_clookup_local_check(Getattr(s, "uname"), Getattr(s, "sym:symtab"), checkfunc);
  1159. if (!ss && !checkfunc) {
  1160. Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", Getattr(s, "uname"));
  1161. }
  1162. s = ss;
  1163. }
  1164. return s;
  1165. }
  1166. /* -----------------------------------------------------------------------------
  1167. * Swig_symbol_cscope()
  1168. *
  1169. * Look up a scope name.
  1170. * ----------------------------------------------------------------------------- */
  1171. Symtab *Swig_symbol_cscope(const_String_or_char_ptr name, Symtab *symtab) {
  1172. char *cname = Char(name);
  1173. if (strncmp(cname, "::", 2) == 0)
  1174. return symbol_lookup_qualified(0, global_scope, name, 0, 0);
  1175. return symbol_lookup_qualified(0, symtab, name, 0, 0);
  1176. }
  1177. /* -----------------------------------------------------------------------------
  1178. * Swig_symbol_remove()
  1179. *
  1180. * Remove a symbol. If the symbol is an overloaded function and the symbol removed
  1181. * is not the last in the list of overloaded functions, then the overloaded
  1182. * names (sym:overname attribute) are changed to start from zero, eg __SWIG_0.
  1183. * ----------------------------------------------------------------------------- */
  1184. void Swig_symbol_remove(Node *n) {
  1185. Symtab *symtab;
  1186. String *symname;
  1187. String *overname;
  1188. Node *symprev;
  1189. Node *symnext;
  1190. Node *fixovername = 0;
  1191. symtab = Getattr(n, "sym:symtab"); /* Get symbol table object */
  1192. symtab = Getattr(symtab, "symtab"); /* Get actual hash table of symbols */
  1193. symname = Getattr(n, "sym:name");
  1194. symprev = Getattr(n, "sym:previousSibling");
  1195. symnext = Getattr(n, "sym:nextSibling");
  1196. /* If previous symbol, just fix the links */
  1197. if (symprev) {
  1198. if (symnext) {
  1199. Setattr(symprev, "sym:nextSibling", symnext);
  1200. fixovername = symprev; /* fix as symbol to remove is somewhere in the middle of the linked list */
  1201. } else {
  1202. Delattr(symprev, "sym:nextSibling");
  1203. }
  1204. } else {
  1205. /* If no previous symbol, see if there is a next symbol */
  1206. if (symnext) {
  1207. Setattr(symtab, symname, symnext);
  1208. fixovername = symnext; /* fix as symbol to remove is at head of linked list */
  1209. } else {
  1210. if (symname)
  1211. Delattr(symtab, symname);
  1212. }
  1213. }
  1214. if (symnext) {
  1215. if (symprev) {
  1216. Setattr(symnext, "sym:previousSibling", symprev);
  1217. } else {
  1218. Delattr(symnext, "sym:previousSibling");
  1219. }
  1220. }
  1221. Delattr(n, "sym:symtab");
  1222. Delattr(n, "sym:previousSibling");
  1223. Delattr(n, "sym:nextSibling");
  1224. Delattr(n, "csym:nextSibling");
  1225. Delattr(n, "sym:overname");
  1226. Delattr(n, "csym:previousSibling");
  1227. Delattr(n, "sym:overloaded");
  1228. n = 0;
  1229. if (fixovername) {
  1230. Node *nn = fixovername;
  1231. Node *head = fixovername;
  1232. int pn = 0;
  1233. /* find head of linked list */
  1234. while (nn) {
  1235. head = nn;
  1236. nn = Getattr(nn, "sym:previousSibling");
  1237. }
  1238. /* adjust all the sym:overname strings to start from 0 and increment by one */
  1239. nn = head;
  1240. while (nn) {
  1241. assert(Getattr(nn, "sym:overname"));
  1242. Delattr(nn, "sym:overname");
  1243. overname = NewStringf("__SWIG_%d", pn);
  1244. Setattr(nn, "sym:overname", overname);
  1245. Delete(overname);
  1246. pn++;
  1247. nn = Getattr(nn, "sym:nextSibling");
  1248. }
  1249. }
  1250. }
  1251. /* -----------------------------------------------------------------------------
  1252. * Swig_symbol_qualified()
  1253. *
  1254. * Return the qualified name of a symbol
  1255. * ----------------------------------------------------------------------------- */
  1256. String *Swig_symbol_qualified(Node *n) {
  1257. Hash *symtab;
  1258. if (Checkattr(n, "nodeType", "symboltable")) {
  1259. symtab = n;
  1260. } else {
  1261. symtab = Getattr(n, "sym:symtab");
  1262. }
  1263. if (!symtab)
  1264. return NewStringEmpty();
  1265. #ifdef SWIG_DEBUG
  1266. Printf(stderr, "symbol_qscope %s %x %s\n", Getattr(n, "name"), symtab, Getattr(symtab, "name"));
  1267. #endif
  1268. return Swig_symbol_qualifiedscopename(symtab);
  1269. }
  1270. /* -----------------------------------------------------------------------------
  1271. * Swig_symbol_isoverloaded()
  1272. *
  1273. * Check if a symbol is overloaded. Returns the first symbol if so.
  1274. * ----------------------------------------------------------------------------- */
  1275. Node *Swig_symbol_isoverloaded(Node *n) {
  1276. return Getattr(n, "sym:overloaded");
  1277. }
  1278. /* -----------------------------------------------------------------------------
  1279. * Swig_symbol_type_qualify()
  1280. *
  1281. * Create a fully qualified type name
  1282. * ----------------------------------------------------------------------------- */
  1283. /* This cache produces problems with OSS, don't active it */
  1284. /* #define SWIG_TEMPLATE_QUALIFY_CACHE */
  1285. static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) {
  1286. String *tprefix, *tsuffix;
  1287. SwigType *qprefix;
  1288. List *targs;
  1289. Node *tempn;
  1290. Symtab *tscope;
  1291. Iterator ti;
  1292. #ifdef SWIG_TEMPLATE_QUALIFY_CACHE
  1293. static Hash *qualify_cache = 0;
  1294. String *scopetype = st ? NewStringf("%s::%s", Getattr(st, "name"), e)
  1295. : NewStringf("%s::%s", Swig_symbol_getscopename(), e);
  1296. if (!qualify_cache) {
  1297. qualify_cache = NewHash();
  1298. }
  1299. if (scopetype) {
  1300. String *cres = Getattr(qualify_cache, scopetype);
  1301. if (cres) {
  1302. Delete(scopetype);
  1303. return Copy(cres);
  1304. }
  1305. }
  1306. #endif
  1307. tprefix = SwigType_templateprefix(e);
  1308. tsuffix = SwigType_templatesuffix(e);
  1309. qprefix = Swig_symbol_type_qualify(tprefix, st);
  1310. targs = SwigType_parmlist(e);
  1311. tempn = Swig_symbol_clookup_local(tprefix, st);
  1312. tscope = tempn ? Getattr(tempn, "sym:symtab") : 0;
  1313. Append(qprefix, "<(");
  1314. for (ti = First(targs); ti.item;) {
  1315. String *vparm;
  1316. String *qparm = Swig_symbol_type_qualify(ti.item, st);
  1317. if (tscope && (tscope != st)) {
  1318. String *ty = Swig_symbol_type_qualify(qparm, tscope);
  1319. Delete(qparm);
  1320. qparm = ty;
  1321. }
  1322. vparm = Swig_symbol_template_param_eval(qparm, st);
  1323. Append(qprefix, vparm);
  1324. ti = Next(ti);
  1325. if (ti.item) {
  1326. Putc(',', qprefix);
  1327. }
  1328. Delete(qparm);
  1329. Delete(vparm);
  1330. }
  1331. Append(qprefix, ")>");
  1332. Append(qprefix, tsuffix);
  1333. Delete(tprefix);
  1334. Delete(tsuffix);
  1335. Delete(targs);
  1336. #ifdef SWIG_DEBUG
  1337. Printf(stderr, "symbol_temp_qual %s %s\n", e, qprefix);
  1338. #endif
  1339. #ifdef SWIG_TEMPLATE_QUALIFY_CACHE
  1340. Setattr(qualify_cache, scopetype, qprefix);
  1341. Delete(scopetype);
  1342. #endif
  1343. return qprefix;
  1344. }
  1345. static int no_constructor(Node *n) {
  1346. return !Checkattr(n, "nodeType", "constructor");
  1347. }
  1348. SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) {
  1349. List *elements;
  1350. String *result = NewStringEmpty();
  1351. int i, len;
  1352. char *c = Char(t);
  1353. if (strncmp(c, "::", 2) == 0) {
  1354. Append(result, t);
  1355. return result;
  1356. }
  1357. elements = SwigType_split(t);
  1358. len = Len(elements);
  1359. for (i = 0; i < len; i++) {
  1360. String *e = Getitem(elements, i);
  1361. if (SwigType_issimple(e)) {
  1362. Node *n = Swig_symbol_clookup_check(e, st, no_constructor);
  1363. if (n) {
  1364. String *name = Getattr(n, "name");
  1365. Clear(e);
  1366. Append(e, name);
  1367. #ifdef SWIG_DEBUG
  1368. Printf(stderr, "symbol_qual_ei %d %s %s %x\n", i, name, e, st);
  1369. #endif
  1370. if (!Swig_scopename_check(name)) {
  1371. String *qname = Swig_symbol_qualified(n);
  1372. if (qname && Len(qname)) {
  1373. Insert(e, 0, "::");
  1374. Insert(e, 0, qname);
  1375. }
  1376. #ifdef SWIG_DEBUG
  1377. Printf(stderr, "symbol_qual_sc %d %s %s %x\n", i, qname, e, st);
  1378. #endif
  1379. Delete(qname);
  1380. }
  1381. } else if (SwigType_istemplate(e)) {
  1382. SwigType *ty = Swig_symbol_template_qualify(e, st);
  1383. Clear(e);
  1384. Append(e, ty);
  1385. Delete(ty);
  1386. }
  1387. if (strncmp(Char(e), "::", 2) == 0) {
  1388. Delitem(e, 0);
  1389. Delitem(e, 0);
  1390. }
  1391. Append(result, e);
  1392. } else if (SwigType_isfunction(e)) {
  1393. List *parms = SwigType_parmlist(e);
  1394. String *s = NewString("f(");
  1395. Iterator pi = First(parms);
  1396. while (pi.item) {
  1397. String *pf = Swig_symbol_type_qualify(pi.item, st);
  1398. Append(s, pf);
  1399. pi = Next(pi);
  1400. if (pi.item) {
  1401. Append(s, ",");
  1402. }
  1403. Delete(pf);
  1404. }
  1405. Append(s, ").");
  1406. Append(result, s);
  1407. Delete(parms);
  1408. Delete(s);
  1409. } else {
  1410. Append(result, e);
  1411. }
  1412. }
  1413. Delete(elements);
  1414. #ifdef SWIG_DEBUG
  1415. Printf(stderr, "symbol_qualify %s %s %x %s\n", t, result, st, st ? Getattr(st, "name") : 0);
  1416. #endif
  1417. return result;
  1418. }
  1419. /* -----------------------------------------------------------------------------
  1420. * Swig_symbol_template_reduce()
  1421. * Resolves template parameter types
  1422. * For example:
  1423. * typedef int Int;
  1424. * typedef Int Integer;
  1425. * with input:
  1426. * Foo<(Int,Integer)>
  1427. * returns:
  1428. * Foo<(int,int)>
  1429. * ----------------------------------------------------------------------------- */
  1430. static
  1431. SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab) {
  1432. Parm *p;
  1433. String *templateargs = SwigType_templateargs(qt);
  1434. List *parms = SwigType_parmlist(templateargs);
  1435. Iterator pi = First(parms);
  1436. String *tprefix = SwigType_templateprefix(qt);
  1437. String *tsuffix = SwigType_templatesuffix(qt);
  1438. String *qprefix = SwigType_typedef_qualified(tprefix);
  1439. Append(qprefix, "<(");
  1440. while ((p = pi.item)) {
  1441. String *np;
  1442. String *tp = Swig_symbol_typedef_reduce(p, ntab);
  1443. String *qp = Swig_symbol_type_qualify(tp, ntab);
  1444. Node *n = Swig_symbol_clookup(qp, ntab);
  1445. if (n) {
  1446. String *qual = Swig_symbol_qualified(n);
  1447. np = Copy(Getattr(n, "name"));
  1448. Delete(tp);
  1449. tp = np;
  1450. if (qual && Len(qual)) {
  1451. Insert(np, 0, "::");
  1452. Insert(np, 0, qual);
  1453. }
  1454. Delete(qual);
  1455. } else {
  1456. np = qp;
  1457. }
  1458. Append(qprefix, np);
  1459. pi = Next(pi);
  1460. if (pi.item) {
  1461. Append(qprefix, ",");
  1462. }
  1463. Delete(qp);
  1464. Delete(tp);
  1465. }
  1466. Append(qprefix, ")>");
  1467. Append(qprefix, tsuffix);
  1468. Delete(parms);
  1469. Delete(tprefix);
  1470. Delete(tsuffix);
  1471. Delete(templateargs);
  1472. return qprefix;
  1473. }
  1474. /* -----------------------------------------------------------------------------
  1475. * Swig_symbol_typedef_reduce()
  1476. *
  1477. * Chase a typedef through symbol tables looking for a match.
  1478. * ----------------------------------------------------------------------------- */
  1479. SwigType *Swig_symbol_typedef_reduce(const SwigType *ty, Symtab *tab) {
  1480. SwigType *prefix, *base;
  1481. Node *n;
  1482. String *nt;
  1483. base = SwigType_base(ty);
  1484. prefix = SwigType_prefix(ty);
  1485. n = Swig_symbol_clookup(base, tab);
  1486. if (!n) {
  1487. if (SwigType_istemplate(ty)) {
  1488. SwigType *qt = Swig_symbol_template_reduce(base, tab);
  1489. Append(prefix, qt);
  1490. Delete(qt);
  1491. #ifdef SWIG_DEBUG
  1492. Printf(stderr, "symbol_reduce (a) %s %s\n", ty, prefix);
  1493. #endif
  1494. Delete(base);
  1495. return prefix;
  1496. } else {
  1497. Delete(prefix);
  1498. #ifdef SWIG_DEBUG
  1499. Printf(stderr, "symbol_reduce (b) %s %s\n", ty, ty);
  1500. #endif
  1501. return Copy(ty);
  1502. }
  1503. }
  1504. nt = Getattr(n, "nodeType");
  1505. if (Equal(nt, "using")) {
  1506. String *uname = Getattr(n, "uname");
  1507. if (uname) {
  1508. n = Swig_symbol_clookup(base, Getattr(n, "sym:symtab"));
  1509. if (!n) {
  1510. Delete(base);
  1511. Delete(prefix);
  1512. #ifdef SWIG_DEBUG
  1513. Printf(stderr, "symbol_reduce (c) %s %s\n", ty, ty);
  1514. #endif
  1515. return Copy(ty);
  1516. }
  1517. }
  1518. }
  1519. if (Equal(nt, "cdecl")) {
  1520. String *storage = Getattr(n, "storage");
  1521. if (storage && (Equal(storage, "typedef"))) {
  1522. SwigType *decl;
  1523. SwigType *rt;
  1524. SwigType *qt;
  1525. Symtab *ntab;
  1526. SwigType *nt = Copy(Getattr(n, "type"));
  1527. /* Fix for case 'typedef struct Hello hello;' */
  1528. {
  1529. const char *dclass[3] = { "struct ", "union ", "class " };
  1530. int i;
  1531. char *c = Char(nt);
  1532. for (i = 0; i < 3; i++) {
  1533. if (strstr(c, dclass[i]) == c) {
  1534. Replace(nt, dclass[i], "", DOH_REPLACE_FIRST);
  1535. }
  1536. }
  1537. }
  1538. decl = Getattr(n, "decl");
  1539. if (decl) {
  1540. SwigType_push(nt, decl);
  1541. }
  1542. SwigType_push(nt, prefix);
  1543. Delete(base);
  1544. Delete(prefix);
  1545. ntab = Getattr(n, "sym:symtab");
  1546. rt = Swig_symbol_typedef_reduce(nt, ntab);
  1547. qt = Swig_symbol_type_qualify(rt, ntab);
  1548. if (SwigType_istemplate(qt)) {
  1549. SwigType *qtr = Swig_symbol_template_reduce(qt, ntab);
  1550. Delete(qt);
  1551. qt = qtr;
  1552. }
  1553. Delete(nt);
  1554. Delete(rt);
  1555. #ifdef SWIG_DEBUG
  1556. Printf(stderr, "symbol_reduce (d) %s %s\n", qt, ty);
  1557. #endif
  1558. return qt;
  1559. }
  1560. }
  1561. Delete(base);
  1562. Delete(prefix);
  1563. #ifdef SWIG_DEBUG
  1564. Printf(stderr, "symbol_reduce (e) %s %s\n", ty, ty);
  1565. #endif
  1566. return Copy(ty);
  1567. }
  1568. /* -----------------------------------------------------------------------------
  1569. * Swig_symbol_string_qualify()
  1570. *
  1571. * This function takes a string and looks for identifiers. Identifiers are
  1572. * then qualified according to scope rules. This function is used in a number
  1573. * of settings including expression evaluation, scoping of conversion operators,
  1574. * and so forth.
  1575. * ----------------------------------------------------------------------------- */
  1576. String *Swig_symbol_string_qualify(String *s, Symtab *st) {
  1577. int have_id = 0;
  1578. String *id = NewStringEmpty();
  1579. String *r = NewStringEmpty();
  1580. char *c = Char(s);
  1581. int first_char = 1;
  1582. while (*c) {
  1583. if (isalpha((int) *c) || (*c == '_') || (*c == ':') || (isdigit((int) *c) && !first_char)) {
  1584. Putc(*c, id);
  1585. have_id = 1;
  1586. } else {
  1587. if (have_id) {
  1588. String *qid = Swig_symbol_type_qualify(id, st);
  1589. Append(r, qid);
  1590. Clear(id);
  1591. Delete(qid);
  1592. have_id = 0;
  1593. }
  1594. Putc(*c, r);
  1595. }
  1596. first_char = (*c == ':');
  1597. c++;
  1598. }
  1599. if (have_id) {
  1600. String *qid = Swig_symbol_type_qualify(id, st);
  1601. Append(r, qid);
  1602. Delete(qid);
  1603. }
  1604. Delete(id);
  1605. return r;
  1606. }
  1607. /* -----------------------------------------------------------------------------
  1608. * Swig_symbol_template_defargs()
  1609. *
  1610. * Apply default arg from generic template default args
  1611. * Returns a parameter list which contains missing default arguments (if any)
  1612. * Note side effects: parms will also contain the extra parameters in its list
  1613. * (but only if non-zero).
  1614. * ----------------------------------------------------------------------------- */
  1615. ParmList *Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl) {
  1616. ParmList *expandedparms = parms;
  1617. if (Len(parms) < Len(targs)) {
  1618. Parm *lp = parms;
  1619. Parm *p = lp;
  1620. Parm *tp = targs;
  1621. while (p && tp) {
  1622. p = nextSibling(p);
  1623. tp = nextSibling(tp);
  1624. if (p)
  1625. lp = p;
  1626. }
  1627. while (tp) {
  1628. String *value = Getattr(tp, "value");
  1629. if (value) {
  1630. Parm *cp;
  1631. Parm *ta = targs;
  1632. Parm *p = parms;
  1633. SwigType *nt = Swig_symbol_string_qualify(value, tsdecl);
  1634. SwigType *ntq = 0;
  1635. #ifdef SWIG_DEBUG
  1636. Printf(stderr, "value %s %s %s\n", value, nt, tsdecl ? Getattr(tsdecl, "name") : tsdecl);
  1637. #endif
  1638. while (p && ta) {
  1639. String *name = Getattr(ta, "name");
  1640. String *pvalue = Getattr(p, "value");
  1641. String *value = pvalue ? pvalue : Getattr(p, "type");
  1642. String *ttq = Swig_symbol_type_qualify(value, tscope);
  1643. /* value = SwigType_typedef_resolve_all(value); */
  1644. Replaceid(nt, name, ttq);
  1645. p = nextSibling(p);
  1646. ta = nextSibling(ta);
  1647. Delete(ttq);
  1648. }
  1649. ntq = Swig_symbol_type_qualify(nt, tsdecl);
  1650. if (SwigType_istemplate(ntq)) {
  1651. String *ty = Swig_symbol_template_deftype(ntq, tscope);
  1652. Delete(ntq);
  1653. ntq = ty;
  1654. }
  1655. /* Printf(stderr,"value %s %s %s\n",value,ntr,ntq); */
  1656. cp = NewParmWithoutFileLineInfo(ntq, 0);
  1657. if (lp)
  1658. set_nextSibling(lp, cp);
  1659. else
  1660. expandedparms = CopyParm(cp);
  1661. lp = cp;
  1662. tp = nextSibling(tp);
  1663. Delete(cp);
  1664. Delete(nt);
  1665. Delete(ntq);
  1666. } else {
  1667. tp = 0;
  1668. }
  1669. }
  1670. }
  1671. return expandedparms;
  1672. }
  1673. /* -----------------------------------------------------------------------------
  1674. * Swig_symbol_template_deftype()
  1675. *
  1676. * Apply default args to generic template type
  1677. * ----------------------------------------------------------------------------- */
  1678. #define SWIG_TEMPLATE_DEFTYPE_CACHE
  1679. SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) {
  1680. String *result = NewStringEmpty();
  1681. List *elements = SwigType_split(type);
  1682. int len = Len(elements);
  1683. int i;
  1684. #ifdef SWIG_TEMPLATE_DEFTYPE_CACHE
  1685. static Hash *deftype_cache = 0;
  1686. String *scopetype = tscope ? NewStringf("%s::%s", Getattr(tscope, "name"), type)
  1687. : NewStringf("%s::%s", Swig_symbol_getscopename(), type);
  1688. if (!deftype_cache) {
  1689. deftype_cache = NewHash();
  1690. }
  1691. if (scopetype) {
  1692. String *cres = Getattr(deftype_cache, scopetype);
  1693. if (cres) {
  1694. Append(result, cres);
  1695. Delete(scopetype);
  1696. return result;
  1697. }
  1698. }
  1699. #endif
  1700. #ifdef SWIG_DEBUG
  1701. Printf(stderr, "finding deftype %s\n", type);
  1702. #endif
  1703. for (i = 0; i < len; i++) {
  1704. String *e = Getitem(elements, i);
  1705. if (SwigType_isfunction(e)) {
  1706. String *s = NewString("f(");
  1707. List *parms = SwigType_parmlist(e);
  1708. Iterator pi = First(parms);
  1709. while (pi.item) {
  1710. String *pf = SwigType_istemplate(e) ? Swig_symbol_template_deftype(pi.item, tscope)
  1711. : Swig_symbol_type_qualify(pi.item, tscope);
  1712. Append(s, pf);
  1713. pi = Next(pi);
  1714. if (pi.item) {
  1715. Append(s, ",");
  1716. }
  1717. Delete(pf);
  1718. }
  1719. Append(s, ").");
  1720. Append(result, s);
  1721. Delete(s);
  1722. Delete(parms);
  1723. } else if (SwigType_istemplate(e)) {
  1724. String *prefix = SwigType_prefix(e);
  1725. String *base = SwigType_base(e);
  1726. String *tprefix = SwigType_templateprefix(base);
  1727. String *targs = SwigType_templateargs(base);
  1728. String *tsuffix = SwigType_templatesuffix(base);
  1729. ParmList *tparms = SwigType_function_parms(targs, 0);
  1730. Node *tempn = Swig_symbol_clookup_local(tprefix, tscope);
  1731. if (!tempn && tsuffix && Len(tsuffix)) {
  1732. tempn = Swig_symbol_clookup(tprefix, 0);
  1733. }
  1734. #ifdef SWIG_DEBUG
  1735. Printf(stderr, "deftype type %s %s %d\n", e, tprefix, (long) tempn);
  1736. #endif
  1737. if (tempn) {
  1738. ParmList *tnargs = Getattr(tempn, "templateparms");
  1739. ParmList *expandedparms;
  1740. Parm *p;
  1741. Symtab *tsdecl = Getattr(tempn, "sym:symtab");
  1742. #ifdef SWIG_DEBUG
  1743. Printf(stderr, "deftype type %s %s %s\n", tprefix, targs, tsuffix);
  1744. #endif
  1745. Append(tprefix, "<(");
  1746. expandedparms = Swig_symbol_template_defargs(tparms, tnargs, tscope, tsdecl);
  1747. p = expandedparms;
  1748. tscope = tsdecl;
  1749. while (p) {
  1750. SwigType *ptype = Getattr(p, "type");
  1751. SwigType *ttr = ptype ? ptype : Getattr(p, "value");
  1752. SwigType *ttf = Swig_symbol_type_qualify(ttr, tscope);
  1753. SwigType *ttq = Swig_symbol_template_param_eval(ttf, tscope);
  1754. #ifdef SWIG_DEBUG
  1755. Printf(stderr, "arg type %s\n", ttq);
  1756. #endif
  1757. if (SwigType_istemplate(ttq)) {
  1758. SwigType *ttd = Swig_symbol_template_deftype(ttq, tscope);
  1759. Delete(ttq);
  1760. ttq = ttd;
  1761. #ifdef SWIG_DEBUG
  1762. Printf(stderr, "arg deftype %s\n", ttq);
  1763. #endif
  1764. }
  1765. Append(tprefix, ttq);
  1766. p = nextSibling(p);
  1767. if (p)
  1768. Putc(',', tprefix);
  1769. Delete(ttf);
  1770. Delete(ttq);
  1771. }
  1772. Append(tprefix, ")>");
  1773. Append(tprefix, tsuffix);
  1774. Append(prefix, tprefix);
  1775. #ifdef SWIG_DEBUG
  1776. Printf(stderr, "deftype %s %s \n", type, tprefix);
  1777. #endif
  1778. Append(result, prefix);
  1779. } else {
  1780. Append(result, e);
  1781. }
  1782. Delete(prefix);
  1783. Delete(base);
  1784. Delete(tprefix);
  1785. Delete(tsuffix);
  1786. Delete(targs);
  1787. Delete(tparms);
  1788. } else {
  1789. Append(result, e);
  1790. }
  1791. }
  1792. Delete(elements);
  1793. #ifdef SWIG_TEMPLATE_DEFTYPE_CACHE
  1794. Setattr(deftype_cache, scopetype, result);
  1795. Delete(scopetype);
  1796. #endif
  1797. return result;
  1798. }
  1799. SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab) {
  1800. String *value = Copy(p);
  1801. Node *lastnode = 0;
  1802. while (1) {
  1803. Node *n = Swig_symbol_clookup(value, symtab);
  1804. if (n == lastnode)
  1805. break;
  1806. lastnode = n;
  1807. if (n) {
  1808. String *nt = Getattr(n, "nodeType");
  1809. if (Equal(nt, "enumitem")) {
  1810. /* An enum item. Generate a fully qualified name */
  1811. String *qn = Swig_symbol_qualified(n);
  1812. if (qn && Len(qn)) {
  1813. Append(qn, "::");
  1814. Append(qn, Getattr(n, "name"));
  1815. Delete(value);
  1816. value = qn;
  1817. continue;
  1818. } else {
  1819. Delete(qn);
  1820. break;
  1821. }
  1822. } else if ((Equal(nt, "cdecl"))) {
  1823. String *nv = Getattr(n, "value");
  1824. if (nv) {
  1825. Delete(value);
  1826. value = Copy(nv);
  1827. continue;
  1828. }
  1829. }
  1830. }
  1831. break;
  1832. }
  1833. return value;
  1834. }