PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 1ms

/Source/Swig/symbol.c

https://github.com/sunaku/swig-ruby-ffi
C | 1995 lines | 1335 code | 162 blank | 498 comment | 332 complexity | 10dc230c7cb29f9ee8ebfa40d22c9a46 MD5 | raw file
Possible License(s): 0BSD, GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file