PageRenderTime 72ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/tags/rel-1.3.35/Source/Swig/symbol.c

#
C | 1914 lines | 1290 code | 151 blank | 473 comment | 324 complexity | 69bc3ea05f404b26651090f44855d5da MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0

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

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