PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-30rc1-afterbeautify/SWIG/Source/Swig/cwrap.c

#
C | 1431 lines | 1001 code | 155 blank | 275 comment | 190 complexity | 2a1cc5301dd360ae4f50ccbdc7246977 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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. * cwrap.c
  6. *
  7. * This file defines a variety of wrapping rules for C/C++ handling including
  8. * the naming of local variables, calling conventions, and so forth.
  9. * ----------------------------------------------------------------------------- */
  10. char cvsroot_cwrap_c[] = "$Header$";
  11. #include "swig.h"
  12. #include "swigkeys.h"
  13. extern int cparse_cplusplus;
  14. static Parm *nonvoid_parms(Parm *p) {
  15. if (p) {
  16. SwigType *t = Getattr(p, k_type);
  17. if (SwigType_type(t) == T_VOID)
  18. return 0;
  19. }
  20. return p;
  21. }
  22. /* -----------------------------------------------------------------------------
  23. * Swig_parm_name()
  24. *
  25. * Generates a name for the ith argument in an argument list
  26. * ----------------------------------------------------------------------------- */
  27. String *Swig_cparm_name(Parm *p, int i) {
  28. String *name = NewStringf("arg%d", i + 1);
  29. if (p) {
  30. Setattr(p, k_lname, name);
  31. }
  32. return name;
  33. }
  34. /* -----------------------------------------------------------------------------
  35. * Swig_clocal()
  36. *
  37. * Creates a string that declares a C local variable type. Converts references
  38. * and user defined types to pointers.
  39. * ----------------------------------------------------------------------------- */
  40. static String *Swig_clocal(SwigType *t, const String_or_char *name, const String_or_char *value) {
  41. String *decl;
  42. decl = NewStringEmpty();
  43. switch (SwigType_type(t)) {
  44. case T_REFERENCE:
  45. if (value) {
  46. String *lstrname = SwigType_lstr(t, name);
  47. String *lstr = SwigType_lstr(t, 0);
  48. Printf(decl, "%s = (%s) &%s_defvalue", lstrname, lstr, name);
  49. Delete(lstrname);
  50. Delete(lstr);
  51. } else {
  52. String *lstrname = SwigType_lstr(t, name);
  53. Printf(decl, "%s = 0", lstrname);
  54. Delete(lstrname);
  55. }
  56. break;
  57. case T_VOID:
  58. break;
  59. case T_VARARGS:
  60. Printf(decl, "void *%s = 0", name);
  61. break;
  62. default:
  63. if (value) {
  64. String *lcaststr = SwigType_lcaststr(t, value);
  65. String *lstr = SwigType_lstr(t, 0);
  66. String *lstrn = SwigType_lstr(t, name);
  67. Printf(decl, "%s = (%s) %s", lstrn, lstr, lcaststr);
  68. Delete(lcaststr);
  69. Delete(lstr);
  70. Delete(lstrn);
  71. } else {
  72. String *lstrname = SwigType_lstr(t, name);
  73. Append(decl, lstrname);
  74. Delete(lstrname);
  75. }
  76. }
  77. return decl;
  78. }
  79. /* -----------------------------------------------------------------------------
  80. * Swig_wrapped_var_convert()
  81. *
  82. * Converts a member variable for use in the get and set wrapper methods.
  83. * This function only converts user defined types to pointers.
  84. * ----------------------------------------------------------------------------- */
  85. String *Swig_wrapped_var_type(SwigType *t, int varcref) {
  86. SwigType *ty;
  87. if (!Strstr(t, "enum $unnamed")) {
  88. ty = Copy(t);
  89. } else {
  90. /* Change the type for unnamed enum instance variables */
  91. ty = NewString("int");
  92. }
  93. if (SwigType_isclass(t)) {
  94. if (varcref) {
  95. if (cparse_cplusplus) {
  96. if (!SwigType_isconst(ty))
  97. SwigType_add_qualifier(ty, "const");
  98. SwigType_add_reference(ty);
  99. } else {
  100. return Copy(ty);
  101. }
  102. } else {
  103. SwigType_add_pointer(ty);
  104. }
  105. }
  106. return ty;
  107. }
  108. String *Swig_wrapped_member_var_type(SwigType *t, int varcref) {
  109. SwigType *ty;
  110. if (!Strstr(t, "enum $unnamed")) {
  111. ty = Copy(t);
  112. } else {
  113. /* Change the type for unnamed enum instance variables */
  114. ty = NewString("int");
  115. }
  116. if (SwigType_isclass(t)) {
  117. if (varcref) {
  118. if (cparse_cplusplus) {
  119. if (!SwigType_isconst(ty))
  120. SwigType_add_qualifier(ty, "const");
  121. SwigType_add_reference(ty);
  122. } else {
  123. return Copy(ty);
  124. }
  125. } else {
  126. SwigType_add_pointer(ty);
  127. }
  128. }
  129. return ty;
  130. }
  131. static String *Swig_wrapped_var_deref(SwigType *t, String_or_char *name, int varcref) {
  132. if (SwigType_isclass(t)) {
  133. if (varcref) {
  134. if (cparse_cplusplus) {
  135. return NewStringf("*%s", name);
  136. } else {
  137. return NewStringf("%s", name);
  138. }
  139. } else {
  140. return NewStringf("*%s", name);
  141. }
  142. } else {
  143. return SwigType_rcaststr(t, name);
  144. }
  145. }
  146. static String *Swig_wrapped_var_assign(SwigType *t, const String_or_char *name, int varcref) {
  147. if (SwigType_isclass(t)) {
  148. if (varcref) {
  149. return NewStringf("%s", name);
  150. } else {
  151. return NewStringf("&%s", name);
  152. }
  153. } else {
  154. return SwigType_lcaststr(t, name);
  155. }
  156. }
  157. /* -----------------------------------------------------------------------------
  158. * Swig_cargs()
  159. *
  160. * Emit all of the local variables for a list of parameters. Returns the
  161. * number of parameters.
  162. * Default values for the local variables are only emitted if the compact default
  163. * argument behaviour is required.
  164. * ----------------------------------------------------------------------------- */
  165. int Swig_cargs(Wrapper *w, ParmList *p) {
  166. int i = 0;
  167. int compactdefargs = ParmList_is_compactdefargs(p);
  168. while (p != 0) {
  169. String *lname = Swig_cparm_name(p, i);
  170. SwigType *pt = Getattr(p, k_type);
  171. if ((SwigType_type(pt) != T_VOID)) {
  172. String *local = 0;
  173. String *type = Getattr(p, k_type);
  174. /* default values only emitted if in compact default args mode */
  175. String *pvalue = (compactdefargs) ? Getattr(p, k_value) : 0;
  176. SwigType *altty = SwigType_alttype(type, 0);
  177. int tycode = SwigType_type(type);
  178. if (tycode == T_REFERENCE) {
  179. if (pvalue) {
  180. SwigType *tvalue;
  181. String *defname, *defvalue, *rvalue, *qvalue;
  182. rvalue = SwigType_typedef_resolve_all(pvalue);
  183. qvalue = SwigType_typedef_qualified(rvalue);
  184. defname = NewStringf("%s_defvalue", lname);
  185. tvalue = Copy(type);
  186. SwigType_del_reference(tvalue);
  187. tycode = SwigType_type(tvalue);
  188. if (tycode != T_USER) {
  189. /* plain primitive type, we copy the the def value */
  190. String *lstr = SwigType_lstr(tvalue, defname);
  191. defvalue = NewStringf("%s = %s", lstr, qvalue);
  192. Delete(lstr);
  193. } else {
  194. /* user type, we copy the reference value */
  195. String *str = SwigType_str(type, defname);
  196. defvalue = NewStringf("%s = %s", str, qvalue);
  197. Delete(str);
  198. }
  199. Wrapper_add_localv(w, defname, defvalue, NIL);
  200. Delete(tvalue);
  201. Delete(rvalue);
  202. Delete(qvalue);
  203. Delete(defname);
  204. Delete(defvalue);
  205. }
  206. } else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) {
  207. pvalue = (String *) "0";
  208. }
  209. if (!altty) {
  210. local = Swig_clocal(pt, lname, pvalue);
  211. } else {
  212. local = Swig_clocal(altty, lname, pvalue);
  213. Delete(altty);
  214. }
  215. Wrapper_add_localv(w, lname, local, NIL);
  216. Delete(local);
  217. i++;
  218. }
  219. Delete(lname);
  220. p = nextSibling(p);
  221. }
  222. return (i);
  223. }
  224. /* -----------------------------------------------------------------------------
  225. * Swig_cresult()
  226. *
  227. * This function generates the C code needed to set the result of a C
  228. * function call.
  229. * ----------------------------------------------------------------------------- */
  230. String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_char *decl) {
  231. String *fcall;
  232. fcall = NewStringEmpty();
  233. switch (SwigType_type(t)) {
  234. case T_VOID:
  235. break;
  236. case T_REFERENCE:
  237. {
  238. String *str = SwigType_str(t, "_result_ref");
  239. Printf(fcall, "{\n");
  240. Printf(fcall, "%s = ", str);
  241. Delete(str);
  242. }
  243. break;
  244. case T_USER:
  245. Printf(fcall, "%s = ", name);
  246. break;
  247. default:
  248. /* Normal return value */
  249. {
  250. String *lstr = SwigType_lstr(t, 0);
  251. Printf(fcall, "%s = (%s)", name, lstr);
  252. Delete(lstr);
  253. }
  254. break;
  255. }
  256. /* Now print out function call */
  257. Append(fcall, decl);
  258. /* A sick hack */
  259. {
  260. char *c = Char(decl) + Len(decl) - 1;
  261. if (!((*c == ';') || (*c == '}')))
  262. Append(fcall, ";");
  263. }
  264. if (SwigType_type(t) == T_REFERENCE) {
  265. String *lstr = SwigType_lstr(t, 0);
  266. Printf(fcall, "\n%s = (%s) &_result_ref;\n", name, lstr);
  267. Append(fcall, "}");
  268. Delete(lstr);
  269. }
  270. return fcall;
  271. }
  272. /* -----------------------------------------------------------------------------
  273. * Swig_cfunction_call()
  274. *
  275. * Creates a string that calls a C function using the local variable rules
  276. * defined above.
  277. *
  278. * name(arg0, arg1, arg2, ... argn)
  279. *
  280. * ----------------------------------------------------------------------------- */
  281. String *Swig_cfunction_call(String_or_char *name, ParmList *parms) {
  282. String *func;
  283. int i = 0;
  284. int comma = 0;
  285. Parm *p = parms;
  286. String *nname;
  287. func = NewStringEmpty();
  288. nname = SwigType_namestr(name);
  289. /*
  290. SWIGTEMPLATEDISAMBIGUATOR is compiler dependent (swiglabels.swg),
  291. - SUN Studio 9 requires 'template',
  292. - gcc-3.4 forbids the use of 'template'.
  293. the rest seems not caring very much,
  294. */
  295. if (SwigType_istemplate(name)) {
  296. String *prefix = Swig_scopename_prefix(nname);
  297. if (!prefix || Len(prefix) == 0) {
  298. Printf(func, "%s(", nname);
  299. } else {
  300. String *last = Swig_scopename_last(nname);
  301. Printf(func, "%s::SWIGTEMPLATEDISAMBIGUATOR %s(", prefix, last);
  302. Delete(last);
  303. }
  304. Delete(prefix);
  305. } else {
  306. Printf(func, "%s(", nname);
  307. }
  308. Delete(nname);
  309. while (p) {
  310. SwigType *pt = Getattr(p, k_type);
  311. if ((SwigType_type(pt) != T_VOID)) {
  312. SwigType *rpt = SwigType_typedef_resolve_all(pt);
  313. String *pname = Swig_cparm_name(p, i);
  314. String *rcaststr = SwigType_rcaststr(rpt, pname);
  315. if (comma) {
  316. Printv(func, ",", rcaststr, NIL);
  317. } else {
  318. Append(func, rcaststr);
  319. }
  320. Delete(rpt);
  321. Delete(pname);
  322. Delete(rcaststr);
  323. comma = 1;
  324. i++;
  325. }
  326. p = nextSibling(p);
  327. }
  328. Append(func, ")");
  329. return func;
  330. }
  331. /* -----------------------------------------------------------------------------
  332. * Swig_cmethod_call()
  333. *
  334. * Generates a string that calls a C++ method from a list of parameters.
  335. *
  336. * arg0->name(arg1, arg2, arg3, ..., argn)
  337. *
  338. * self is an argument that defines how to handle the first argument. Normally,
  339. * it should be set to "this->". With C++ proxy classes enabled, it could be
  340. * set to "(*this)->" or some similar sequence.
  341. * ----------------------------------------------------------------------------- */
  342. static String *Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self, String *explicit_qualifier, SwigType *director_type) {
  343. String *func, *nname;
  344. int i = 0;
  345. Parm *p = parms;
  346. SwigType *pt;
  347. int comma = 0;
  348. func = NewStringEmpty();
  349. if (!p)
  350. return func;
  351. if (!self)
  352. self = (char *) "(this)->";
  353. Append(func, self);
  354. if (SwigType_istemplate(name) && (strncmp(Char(name), "operator ", 9) == 0)) {
  355. /* fix for template + operators and compilers like gcc 3.3.5 */
  356. String *tprefix = SwigType_templateprefix(name);
  357. nname = tprefix;
  358. } else {
  359. nname = SwigType_namestr(name);
  360. }
  361. if (director_type) {
  362. const char *pname = "darg";
  363. String *rcaststr = SwigType_rcaststr(director_type, pname);
  364. Replaceall(func, "this", rcaststr);
  365. Delete(rcaststr);
  366. } else {
  367. pt = Getattr(p, k_type);
  368. /* If the method is invoked through a dereferenced pointer, we don't add any casts
  369. (needed for smart pointers). Otherwise, we cast to the appropriate type */
  370. if (Strstr(func, "*this")) {
  371. String *pname = Swig_cparm_name(p, 0);
  372. Replaceall(func, "this", pname);
  373. Delete(pname);
  374. } else {
  375. String *pname = Swig_cparm_name(p, 0);
  376. String *rcaststr = SwigType_rcaststr(pt, pname);
  377. Replaceall(func, "this", rcaststr);
  378. Delete(rcaststr);
  379. Delete(pname);
  380. }
  381. /*
  382. SWIGTEMPLATEDESIMBUAGATOR is compiler dependent (swiglabels.swg),
  383. - SUN Studio 9 requires 'template',
  384. - gcc-3.4 forbids the use of 'template' (correctly implementing the ISO C++ standard)
  385. the others don't seem to care,
  386. */
  387. if (SwigType_istemplate(name))
  388. Printf(func, "SWIGTEMPLATEDISAMBIGUATOR ");
  389. if (explicit_qualifier) {
  390. Printv(func, explicit_qualifier, "::", NIL);
  391. }
  392. }
  393. Printf(func, "%s(", nname);
  394. i++;
  395. p = nextSibling(p);
  396. while (p) {
  397. pt = Getattr(p, k_type);
  398. if ((SwigType_type(pt) != T_VOID)) {
  399. String *pname = Swig_cparm_name(p, i);
  400. String *rcaststr = SwigType_rcaststr(pt, pname);
  401. if (comma)
  402. Append(func, ",");
  403. Append(func, rcaststr);
  404. Delete(rcaststr);
  405. Delete(pname);
  406. comma = 1;
  407. i++;
  408. }
  409. p = nextSibling(p);
  410. }
  411. Append(func, ")");
  412. Delete(nname);
  413. return func;
  414. }
  415. /* -----------------------------------------------------------------------------
  416. * Swig_cconstructor_call()
  417. *
  418. * Creates a string that calls a C constructor function.
  419. *
  420. * (name *) calloc(1,sizeof(name));
  421. * ----------------------------------------------------------------------------- */
  422. String *Swig_cconstructor_call(String_or_char *name) {
  423. DOH *func;
  424. func = NewStringEmpty();
  425. Printf(func, "(%s *) calloc(1, sizeof(%s))", name, name);
  426. return func;
  427. }
  428. /* -----------------------------------------------------------------------------
  429. * Swig_cppconstructor_call()
  430. *
  431. * Creates a string that calls a C function using the local variable rules
  432. * defined above.
  433. *
  434. * name(arg0, arg1, arg2, ... argn)
  435. *
  436. * ----------------------------------------------------------------------------- */
  437. String *Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_self) {
  438. String *func;
  439. String *nname;
  440. int i = 0;
  441. int comma = 0;
  442. Parm *p = parms;
  443. SwigType *pt;
  444. if (skip_self) {
  445. if (p)
  446. p = nextSibling(p);
  447. i++;
  448. }
  449. nname = SwigType_namestr(name);
  450. func = NewStringEmpty();
  451. Printf(func, "new %s(", nname);
  452. while (p) {
  453. pt = Getattr(p, k_type);
  454. if ((SwigType_type(pt) != T_VOID)) {
  455. String *rcaststr = 0;
  456. String *pname = 0;
  457. if (comma)
  458. Append(func, ",");
  459. if (!Getattr(p, k_argbyname)) {
  460. pname = Swig_cparm_name(p, i);
  461. i++;
  462. } else {
  463. if ((pname = Getattr(p, k_value)))
  464. pname = Copy(pname);
  465. else
  466. pname = Copy(Getattr(p, k_name));
  467. }
  468. rcaststr = SwigType_rcaststr(pt, pname);
  469. Append(func, rcaststr);
  470. Delete(rcaststr);
  471. comma = 1;
  472. Delete(pname);
  473. }
  474. p = nextSibling(p);
  475. }
  476. Append(func, ")");
  477. Delete(nname);
  478. return func;
  479. }
  480. String *Swig_cppconstructor_call(String_or_char *name, ParmList *parms) {
  481. return Swig_cppconstructor_base_call(name, parms, 0);
  482. }
  483. String *Swig_cppconstructor_nodirector_call(String_or_char *name, ParmList *parms) {
  484. return Swig_cppconstructor_base_call(name, parms, 1);
  485. }
  486. String *Swig_cppconstructor_director_call(String_or_char *name, ParmList *parms) {
  487. return Swig_cppconstructor_base_call(name, parms, 0);
  488. }
  489. /* -----------------------------------------------------------------------------
  490. * Swig_rflag_search()
  491. *
  492. * This function searches for the class attribute 'attr' in the class
  493. * 'n' or recursively in its bases.
  494. *
  495. * If you define SWIG_FAST_REC_SEARCH, the method will set the found
  496. * 'attr' in the target class 'n'. If not, the method will set the
  497. * 'noattr' one. This prevents of having to navigate the entire
  498. * hierarchy tree everytime, so, it is an O(1) method... or something
  499. * like that. However, it populates all the parsed classes with the
  500. * 'attr' and/or 'noattr' attributes.
  501. *
  502. * If you undefine the SWIG_FAST_REC_SEARCH no attribute will be set
  503. * while searching. This could be slower for large projects with very
  504. * large hierarchy trees... or maybe not. But it will be cleaner.
  505. *
  506. * Maybe later a swig option can be added to switch at runtime.
  507. *
  508. * ----------------------------------------------------------------------------- */
  509. /* #define SWIG_FAST_REC_SEARCH 1 */
  510. String *Swig_rflag_search(Node *n, const String *attr, const String *noattr) {
  511. String *f = 0;
  512. n = Swig_methodclass(n);
  513. if (GetFlag(n, noattr)) {
  514. return 0;
  515. }
  516. f = GetFlagAttr(n, attr);
  517. if (f) {
  518. return f;
  519. } else {
  520. List *bl = Getattr(n, k_bases);
  521. if (bl) {
  522. Iterator bi;
  523. for (bi = First(bl); bi.item; bi = Next(bi)) {
  524. f = Swig_rflag_search(bi.item, attr, noattr);
  525. if (f) {
  526. #ifdef SWIG_FAST_REC_SEARCH
  527. SetFlagAttr(n, attr, f);
  528. #endif
  529. return f;
  530. }
  531. }
  532. }
  533. }
  534. #ifdef SWIG_FAST_REC_SEARCH
  535. SetFlag(n, noattr);
  536. #endif
  537. return 0;
  538. }
  539. /* -----------------------------------------------------------------------------
  540. * Swig_unref_call()
  541. *
  542. * find the unref call, if any.
  543. * ----------------------------------------------------------------------------- */
  544. String *Swig_unref_call(Node *n) {
  545. Node *cn = Swig_methodclass(n);
  546. String *unref = Swig_rflag_search(cn, "feature:unref", "feature:nounref");
  547. if (unref) {
  548. String *pname = Swig_cparm_name(0, 0);
  549. unref = NewString(unref);
  550. Replaceall(unref, "$this", pname);
  551. Replaceall(unref, "$self", pname);
  552. Delete(pname);
  553. }
  554. return unref;
  555. }
  556. /* -----------------------------------------------------------------------------
  557. * Swig_ref_call()
  558. *
  559. * find the ref call, if any.
  560. * ----------------------------------------------------------------------------- */
  561. String *Swig_ref_call(Node *n, const String *lname) {
  562. Node *cn = Swig_methodclass(n);
  563. String *ref = Swig_rflag_search(cn, "feature:ref", "feature:noref");
  564. if (ref) {
  565. ref = NewString(ref);
  566. Replaceall(ref, "$this", lname);
  567. Replaceall(ref, "$self", lname);
  568. }
  569. return ref;
  570. }
  571. /* -----------------------------------------------------------------------------
  572. * Swig_cdestructor_call()
  573. *
  574. * Creates a string that calls a C destructor function.
  575. *
  576. * free((char *) arg0);
  577. * ----------------------------------------------------------------------------- */
  578. String *Swig_cdestructor_call(Node *n) {
  579. String *unref = Swig_unref_call(n);
  580. if (unref) {
  581. return unref;
  582. } else {
  583. String *pname = Swig_cparm_name(0, 0);
  584. String *call = NewStringf("free((char *) %s);", pname);
  585. Delete(pname);
  586. return call;
  587. }
  588. }
  589. /* -----------------------------------------------------------------------------
  590. * Swig_cppdestructor_call()
  591. *
  592. * Creates a string that calls a C destructor function.
  593. *
  594. * delete arg0;
  595. * ----------------------------------------------------------------------------- */
  596. String *Swig_cppdestructor_call(Node *n) {
  597. String *unref = Swig_unref_call(n);
  598. if (unref) {
  599. return unref;
  600. } else {
  601. String *pname = Swig_cparm_name(0, 0);
  602. String *call = NewStringf("delete %s;", pname);
  603. Delete(pname);
  604. return call;
  605. }
  606. }
  607. /* -----------------------------------------------------------------------------
  608. * Swig_cmemberset_call()
  609. *
  610. * Generates a string that sets the name of a member in a C++ class or C struct.
  611. *
  612. * arg0->name = arg1
  613. *
  614. * ----------------------------------------------------------------------------- */
  615. String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref) {
  616. String *func;
  617. String *pname0 = Swig_cparm_name(0, 0);
  618. String *pname1 = Swig_cparm_name(0, 1);
  619. func = NewStringEmpty();
  620. if (!self)
  621. self = NewString("(this)->");
  622. else
  623. self = NewString(self);
  624. Replaceall(self, "this", pname0);
  625. if (SwigType_type(type) != T_ARRAY) {
  626. if (!Strstr(type, "enum $unnamed")) {
  627. String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
  628. Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
  629. Delete(dref);
  630. } else {
  631. Printf(func, "if (%s && sizeof(int) == sizeof(%s%s)) *(int*)(void*)&(%s%s) = %s", pname0, self, name, self, name, pname1);
  632. }
  633. }
  634. Delete(self);
  635. Delete(pname0);
  636. Delete(pname1);
  637. return (func);
  638. }
  639. /* -----------------------------------------------------------------------------
  640. * Swig_cmemberget_call()
  641. *
  642. * Generates a string that sets the name of a member in a C++ class or C struct.
  643. *
  644. * arg0->name
  645. *
  646. * ----------------------------------------------------------------------------- */
  647. String *Swig_cmemberget_call(const String_or_char *name, SwigType *t, String_or_char *self, int varcref) {
  648. String *func;
  649. String *call;
  650. String *pname0 = Swig_cparm_name(0, 0);
  651. if (!self)
  652. self = NewString("(this)->");
  653. else
  654. self = NewString(self);
  655. Replaceall(self, "this", pname0);
  656. func = NewStringEmpty();
  657. call = Swig_wrapped_var_assign(t, "", varcref);
  658. Printf(func, "%s (%s%s)", call, self, name);
  659. Delete(self);
  660. Delete(call);
  661. Delete(pname0);
  662. return func;
  663. }
  664. /* -----------------------------------------------------------------------------
  665. * Swig_extension_code()
  666. *
  667. * Generates an extension function (a function defined in %extend)
  668. *
  669. * return_type function_name(parms) code
  670. *
  671. * ----------------------------------------------------------------------------- */
  672. String *Swig_extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus) {
  673. String *parms_str = cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms);
  674. String *sig = NewStringf("%s(%s)", function_name, parms_str);
  675. String *rt_sig = SwigType_str(return_type, sig);
  676. String *body = NewStringf("SWIGINTERN %s", rt_sig);
  677. Printv(body, code, "\n", NIL);
  678. Delete(parms_str);
  679. Delete(sig);
  680. Delete(rt_sig);
  681. return body;
  682. }
  683. /* -----------------------------------------------------------------------------
  684. * Swig_add_extension_code()
  685. *
  686. * Generates an extension function (a function defined in %extend) and
  687. * adds it to the "wrap:code" attribute of a node
  688. *
  689. * See also Swig_extension_code()
  690. *
  691. * ----------------------------------------------------------------------------- */
  692. int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus) {
  693. String *body = Swig_extension_code(function_name, parms, return_type, code, cplusplus);
  694. Setattr(n, k_wrapcode, body);
  695. Delete(body);
  696. return SWIG_OK;
  697. }
  698. /* -----------------------------------------------------------------------------
  699. * Swig_MethodToFunction(Node *n)
  700. *
  701. * Converts a C++ method node to a function accessor function.
  702. * ----------------------------------------------------------------------------- */
  703. int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director) {
  704. String *name, *qualifier;
  705. ParmList *parms;
  706. SwigType *type;
  707. Parm *p;
  708. String *self = 0;
  709. /* If smart pointer, change self dereferencing */
  710. if (flags & CWRAP_SMART_POINTER) {
  711. self = NewString("(*this)->");
  712. }
  713. /* If node is a member template expansion, we don't allow added code */
  714. if (Getattr(n, k_templatetype))
  715. flags &= ~(CWRAP_EXTEND);
  716. name = Getattr(n, k_name);
  717. qualifier = Getattr(n, k_qualifier);
  718. parms = CopyParmList(nonvoid_parms(Getattr(n, k_parms)));
  719. type = NewString(classname);
  720. if (qualifier) {
  721. SwigType_push(type, qualifier);
  722. }
  723. SwigType_add_pointer(type);
  724. p = NewParm(type, k_self);
  725. Setattr(p, k_self, "1");
  726. Setattr(p, k_hidden, "1");
  727. /*
  728. Disable the 'this' ownership in 'self' to manage inplace
  729. operations like:
  730. A& A::operator+=(int i) { ...; return *this;}
  731. Here the 'self' parameter ownership needs to be disabled since
  732. there could be two objects sharing the same 'this' pointer: the
  733. input and the result one. And worse, the pointer could be deleted
  734. in one of the objects (input), leaving the other (output) with
  735. just a seg. fault to happen.
  736. To avoid the previous problem, use
  737. %feature("self:disown") *::operator+=;
  738. %feature("new") *::operator+=;
  739. These two lines just transfer the ownership of the 'this' pointer
  740. from the input to the output wrapping object.
  741. This happens in python, but may also happens in other target
  742. languages.
  743. */
  744. if (GetFlag(n, "feature:self:disown")) {
  745. Setattr(p, k_wrapdisown, "1");
  746. }
  747. set_nextSibling(p, parms);
  748. Delete(type);
  749. /* Generate action code for the access */
  750. if (!(flags & CWRAP_EXTEND)) {
  751. String *explicit_qualifier = 0;
  752. String *call = 0;
  753. String *cres = 0;
  754. String *explicitcall_name = 0;
  755. int pure_virtual = !(Cmp(Getattr(n, k_storage), "virtual")) && !(Cmp(Getattr(n, k_value), "0"));
  756. /* Call the explicit method rather than allow for a polymorphic call */
  757. if ((flags & CWRAP_DIRECTOR_TWO_CALLS) || (flags & CWRAP_DIRECTOR_ONE_CALL)) {
  758. String *access = Getattr(n, "access");
  759. if (access && (Cmp(access, "protected") == 0)) {
  760. /* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */
  761. String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), k_qname));
  762. explicitcall_name = NewStringf("%sSwigPublic", name);
  763. explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp);
  764. Delete(explicit_qualifier_tmp);
  765. } else {
  766. explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), k_qname));
  767. }
  768. }
  769. call = Swig_cmethod_call(explicitcall_name ? explicitcall_name : name, p, self, explicit_qualifier, director_type);
  770. cres = Swig_cresult(Getattr(n, k_type), k_result, call);
  771. if (pure_virtual && is_director && (flags & CWRAP_DIRECTOR_TWO_CALLS)) {
  772. String *qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), k_qname));
  773. Delete(cres);
  774. cres = NewStringf("Swig::DirectorPureVirtualException::raise(\"%s::%s\");", qualifier, name);
  775. Delete(qualifier);
  776. }
  777. if (flags & CWRAP_DIRECTOR_TWO_CALLS) {
  778. /* Create two method calls, one to call the explicit method, the other a normal polymorphic function call */
  779. String *cres_both_calls = NewStringf("");
  780. String *call_extra = Swig_cmethod_call(name, p, self, 0, director_type);
  781. String *cres_extra = Swig_cresult(Getattr(n, k_type), k_result, call_extra);
  782. Printv(cres_both_calls, "if (upcall) {\n", cres, "\n", "} else {", cres_extra, "\n}", NIL);
  783. Setattr(n, k_wrapaction, cres_both_calls);
  784. Delete(cres_extra);
  785. Delete(call_extra);
  786. Delete(cres_both_calls);
  787. } else {
  788. Setattr(n, k_wrapaction, cres);
  789. }
  790. Delete(explicitcall_name);
  791. Delete(call);
  792. Delete(cres);
  793. Delete(explicit_qualifier);
  794. } else {
  795. /* Methods with default arguments are wrapped with additional methods for each default argument,
  796. * however, only one extra %extend method is generated. */
  797. String *defaultargs = Getattr(n, k_defaultargs);
  798. String *code = Getattr(n, k_code);
  799. String *cname = Getattr(n, k_classname) ? Getattr(n, k_classname) : classname;
  800. String *membername = Swig_name_member(cname, name);
  801. String *mangled = Swig_name_mangle(membername);
  802. int is_smart_pointer = flags & CWRAP_SMART_POINTER;
  803. type = Getattr(n, k_type);
  804. /* Check if the method is overloaded. If so, and it has code attached, we append an extra suffix
  805. to avoid a name-clash in the generated wrappers. This allows overloaded methods to be defined
  806. in C. */
  807. if (Getattr(n, k_symoverloaded) && code) {
  808. Append(mangled, Getattr(defaultargs ? defaultargs : n, k_symovername));
  809. }
  810. /* See if there is any code that we need to emit */
  811. if (!defaultargs && code && !is_smart_pointer) {
  812. Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus);
  813. }
  814. if (is_smart_pointer) {
  815. int i = 0;
  816. Parm *pp = p;
  817. String *func = NewStringf("%s(", mangled);
  818. String *cres;
  819. if (Cmp(Getattr(n, k_storage), k_static) != 0) {
  820. String *pname = Swig_cparm_name(pp, i);
  821. String *fadd = NewStringf("(%s*)(%s)->operator ->()", cname, pname);
  822. Append(func, fadd);
  823. Delete(fadd);
  824. Delete(pname);
  825. pp = nextSibling(pp);
  826. if (pp)
  827. Append(func, ",");
  828. } else {
  829. pp = nextSibling(pp);
  830. }
  831. ++i;
  832. while (pp) {
  833. SwigType *pt = Getattr(pp, k_type);
  834. if ((SwigType_type(pt) != T_VOID)) {
  835. String *pname = Swig_cparm_name(pp, i++);
  836. String *rcaststr = SwigType_rcaststr(pt, pname);
  837. Append(func, rcaststr);
  838. Delete(rcaststr);
  839. Delete(pname);
  840. pp = nextSibling(pp);
  841. if (pp)
  842. Append(func, ",");
  843. }
  844. }
  845. Append(func, ")");
  846. cres = Swig_cresult(Getattr(n, k_type), k_result, func);
  847. Setattr(n, k_wrapaction, cres);
  848. Delete(cres);
  849. } else {
  850. String *call = Swig_cfunction_call(mangled, p);
  851. String *cres = Swig_cresult(Getattr(n, k_type), k_result, call);
  852. Setattr(n, k_wrapaction, cres);
  853. Delete(call);
  854. Delete(cres);
  855. }
  856. Delete(membername);
  857. Delete(mangled);
  858. }
  859. Setattr(n, k_parms, p);
  860. Delete(p);
  861. Delete(self);
  862. Delete(parms);
  863. return SWIG_OK;
  864. }
  865. /* -----------------------------------------------------------------------------
  866. * Swig_methodclass()
  867. *
  868. * This function returns the class node for a given method or class.
  869. * ----------------------------------------------------------------------------- */
  870. Node *Swig_methodclass(Node *n) {
  871. Node *nodetype = Getattr(n, k_nodetype);
  872. if (!Cmp(nodetype, "class"))
  873. return n;
  874. return GetFlag(n, "feature:extend") ? Getattr(Getattr(n, k_parentnode), k_parentnode) : Getattr(n, k_parentnode);
  875. }
  876. int Swig_directorclass(Node *n) {
  877. Node *classNode = Swig_methodclass(n);
  878. assert(classNode != 0);
  879. return (Getattr(classNode, k_vtable) != 0);
  880. }
  881. Node *Swig_directormap(Node *module, String *type) {
  882. int is_void = !Cmp(type, "void");
  883. if (!is_void && module) {
  884. /* ?? follow the inheritance hierarchy? */
  885. String *base = SwigType_base(type);
  886. Node *directormap = Getattr(module, k_wrapdirectormap);
  887. if (directormap)
  888. return Getattr(directormap, base);
  889. }
  890. return 0;
  891. }
  892. /* -----------------------------------------------------------------------------
  893. * Swig_ConstructorToFunction()
  894. *
  895. * This function creates a C wrapper for a C constructor function.
  896. * ----------------------------------------------------------------------------- */
  897. int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) {
  898. ParmList *parms;
  899. Parm *prefix_args;
  900. Parm *p;
  901. ParmList *directorparms;
  902. SwigType *type;
  903. Node *classNode;
  904. int use_director;
  905. classNode = Swig_methodclass(n);
  906. use_director = Swig_directorclass(n);
  907. parms = CopyParmList(nonvoid_parms(Getattr(n, k_parms)));
  908. /* Prepend the list of prefix_args (if any) */
  909. prefix_args = Getattr(n, k_directorprefixargs);
  910. if (prefix_args != NIL) {
  911. Parm *p2, *p3;
  912. directorparms = CopyParmList(prefix_args);
  913. for (p = directorparms; nextSibling(p); p = nextSibling(p));
  914. for (p2 = parms; p2; p2 = nextSibling(p2)) {
  915. p3 = CopyParm(p2);
  916. set_nextSibling(p, p3);
  917. Delete(p3);
  918. p = p3;
  919. }
  920. } else
  921. directorparms = parms;
  922. type = NewString(classname);
  923. SwigType_add_pointer(type);
  924. if (flags & CWRAP_EXTEND) {
  925. /* Constructors with default arguments are wrapped with additional constructor methods for each default argument,
  926. * however, only one extra %extend method is generated. */
  927. String *call;
  928. String *cres;
  929. String *defaultargs = Getattr(n, k_defaultargs);
  930. String *code = Getattr(n, k_code);
  931. String *membername = Swig_name_construct(classname);
  932. String *mangled = Swig_name_mangle(membername);
  933. /* Check if the constructor is overloaded. If so, and it has code attached, we append an extra suffix
  934. to avoid a name-clash in the generated wrappers. This allows overloaded constructors to be defined
  935. in C. */
  936. if (Getattr(n, k_symoverloaded) && code) {
  937. Append(mangled, Getattr(defaultargs ? defaultargs : n, k_symovername));
  938. }
  939. /* See if there is any code that we need to emit */
  940. if (!defaultargs && code) {
  941. Swig_add_extension_code(n, mangled, parms, type, code, cparse_cplusplus);
  942. }
  943. call = Swig_cfunction_call(mangled, parms);
  944. cres = Swig_cresult(type, k_result, call);
  945. Setattr(n, k_wrapaction, cres);
  946. Delete(cres);
  947. Delete(call);
  948. Delete(membername);
  949. Delete(mangled);
  950. } else {
  951. if (cplus) {
  952. /* if a C++ director class exists, create it rather than the original class */
  953. if (use_director) {
  954. Node *parent = Swig_methodclass(n);
  955. int abstract = Getattr(parent, k_abstract) != 0;
  956. String *name = Getattr(parent, k_symname);
  957. String *directorname = NewStringf("SwigDirector_%s", name);
  958. String *action = NewStringEmpty();
  959. String *tmp_none_comparison = Copy(none_comparison);
  960. String *director_call;
  961. String *nodirector_call;
  962. Replaceall(tmp_none_comparison, "$arg", "arg1");
  963. director_call = Swig_cppconstructor_director_call(directorname, directorparms);
  964. nodirector_call = Swig_cppconstructor_nodirector_call(classname, parms);
  965. if (abstract) {
  966. /* whether or not the abstract class has been subclassed in python,
  967. * create a director instance (there's no way to create a normal
  968. * instance). if any of the pure virtual methods haven't been
  969. * implemented in the target language, calls to those methods will
  970. * generate Swig::DirectorPureVirtualException exceptions.
  971. */
  972. String *cres = Swig_cresult(type, k_result, director_call);
  973. Append(action, cres);
  974. Delete(cres);
  975. } else {
  976. /* (scottm): The code for creating a new director is now a string
  977. template that gets passed in via the director_ctor argument.
  978. $comparison : an 'if' comparison from none_comparison
  979. $director_new: Call new for director class
  980. $nondirector_new: Call new for non-director class
  981. */
  982. String *cres;
  983. Append(action, director_ctor);
  984. Replaceall(action, "$comparison", tmp_none_comparison);
  985. cres = Swig_cresult(type, k_result, director_call);
  986. Replaceall(action, "$director_new", cres);
  987. Delete(cres);
  988. cres = Swig_cresult(type, k_result, nodirector_call);
  989. Replaceall(action, "$nondirector_new", cres);
  990. Delete(cres);
  991. }
  992. Setattr(n, k_wrapaction, action);
  993. Delete(tmp_none_comparison);
  994. Delete(action);
  995. Delete(directorname);
  996. } else {
  997. String *call = Swig_cppconstructor_call(classname, parms);
  998. String *cres = Swig_cresult(type, k_result, call);
  999. Setattr(n, k_wrapaction, cres);
  1000. Delete(cres);
  1001. Delete(call);
  1002. }
  1003. } else {
  1004. String *call = Swig_cconstructor_call(classname);
  1005. String *cres = Swig_cresult(type, k_result, call);
  1006. Setattr(n, k_wrapaction, cres);
  1007. Delete(cres);
  1008. Delete(call);
  1009. }
  1010. }
  1011. Setattr(n, k_type, type);
  1012. Setattr(n, k_parms, parms);
  1013. Delete(type);
  1014. if (directorparms != parms)
  1015. Delete(directorparms);
  1016. Delete(parms);
  1017. return SWIG_OK;
  1018. }
  1019. /* -----------------------------------------------------------------------------
  1020. * Swig_DestructorToFunction()
  1021. *
  1022. * This function creates a C wrapper for a destructor function.
  1023. * ----------------------------------------------------------------------------- */
  1024. int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) {
  1025. SwigType *type;
  1026. Parm *p;
  1027. type = NewString(classname);
  1028. SwigType_add_pointer(type);
  1029. p = NewParm(type, k_self);
  1030. Setattr(p, k_self, "1");
  1031. Setattr(p, k_hidden, "1");
  1032. Setattr(p, k_wrapdisown, "1");
  1033. Delete(type);
  1034. type = NewString("void");
  1035. if (flags & CWRAP_EXTEND) {
  1036. String *cres;
  1037. String *call;
  1038. String *membername, *mangled, *code;
  1039. membername = Swig_name_destroy(classname);
  1040. mangled = Swig_name_mangle(membername);
  1041. code = Getattr(n, k_code);
  1042. if (code) {
  1043. Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus);
  1044. }
  1045. call = Swig_cfunction_call(mangled, p);
  1046. cres = NewStringf("%s;\n", call);
  1047. Setattr(n, k_wrapaction, cres);
  1048. Delete(membername);
  1049. Delete(mangled);
  1050. Delete(call);
  1051. Delete(cres);
  1052. } else {
  1053. if (cplus) {
  1054. String *call = Swig_cppdestructor_call(n);
  1055. String *cres = NewStringf("%s\n", call);
  1056. Setattr(n, k_wrapaction, cres);
  1057. Delete(call);
  1058. Delete(cres);
  1059. } else {
  1060. String *call = Swig_cdestructor_call(n);
  1061. String *cres = NewStringf("%s\n", call);
  1062. Setattr(n, k_wrapaction, cres);
  1063. Delete(call);
  1064. Delete(cres);
  1065. }
  1066. }
  1067. Setattr(n, k_type, type);
  1068. Setattr(n, k_parms, p);
  1069. Delete(type);
  1070. Delete(p);
  1071. return SWIG_OK;
  1072. }
  1073. /* -----------------------------------------------------------------------------
  1074. * Swig_MembersetToFunction()
  1075. *
  1076. * This function creates a C wrapper for setting a structure member.
  1077. * ----------------------------------------------------------------------------- */
  1078. int Swig_MembersetToFunction(Node *n, String *classname, int flags) {
  1079. String *name;
  1080. ParmList *parms;
  1081. Parm *p;
  1082. SwigType *t;
  1083. SwigType *ty;
  1084. SwigType *type;
  1085. SwigType *void_type = NewString("void");
  1086. String *membername;
  1087. String *mangled;
  1088. String *self = 0;
  1089. String *sname;
  1090. int varcref = flags & CWRAP_NATURAL_VAR;
  1091. if (flags & CWRAP_SMART_POINTER) {
  1092. self = NewString("(*this)->");
  1093. }
  1094. name = Getattr(n, k_name);
  1095. type = Getattr(n, k_type);
  1096. sname = Swig_name_set(name);
  1097. membername = Swig_name_member(classname, sname);
  1098. mangled = Swig_name_mangle(membername);
  1099. t = NewString(classname);
  1100. SwigType_add_pointer(t);
  1101. parms = NewParm(t, k_self);
  1102. Setattr(parms, k_self, "1");
  1103. Setattr(parms, k_hidden, "1");
  1104. Delete(t);
  1105. ty = Swig_wrapped_member_var_type(type, varcref);
  1106. p = NewParm(ty, name);
  1107. Setattr(parms, k_hidden, "1");
  1108. set_nextSibling(parms, p);
  1109. /* If the type is a pointer or reference. We mark it with a special wrap:disown attribute */
  1110. if (SwigType_check_decl(type, "p.")) {
  1111. Setattr(p, k_wrapdisown, "1");
  1112. }
  1113. Delete(p);
  1114. if (flags & CWRAP_EXTEND) {
  1115. String *call;
  1116. String *cres;
  1117. String *code = Getattr(n, k_code);
  1118. if (code) {
  1119. Swig_add_extension_code(n, mangled, parms, void_type, code, cparse_cplusplus);
  1120. }
  1121. call = Swig_cfunction_call(mangled, parms);
  1122. cres = NewStringf("%s;\n", call);
  1123. Setattr(n, k_wrapaction, cres);
  1124. Delete(call);
  1125. Delete(cres);
  1126. } else {
  1127. String *call = Swig_cmemberset_call(name, type, self, varcref);
  1128. String *cres = NewStringf("%s;\n", call);
  1129. Setattr(n, k_wrapaction, cres);
  1130. Delete(call);
  1131. Delete(cres);
  1132. }
  1133. Setattr(n, k_type, void_type);
  1134. Setattr(n, k_parms, parms);
  1135. Delete(parms);
  1136. Delete(ty);
  1137. Delete(void_type);
  1138. Delete(membername);
  1139. Delete(sname);
  1140. Delete(mangled);
  1141. Delete(self);
  1142. return SWIG_OK;
  1143. }
  1144. /* -----------------------------------------------------------------------------
  1145. * Swig_MembergetToFunction()
  1146. *
  1147. * This function creates a C wrapper for getting a structure member.
  1148. * ----------------------------------------------------------------------------- */
  1149. int Swig_MembergetToFunction(Node *n, String *classname, int flags) {
  1150. String *name;
  1151. ParmList *parms;
  1152. SwigType *t;
  1153. SwigType *ty;
  1154. SwigType *type;
  1155. String *membername;
  1156. String *mangled;
  1157. String *self = 0;
  1158. String *gname;
  1159. int varcref = flags & CWRAP_NATURAL_VAR;
  1160. if (flags & CWRAP_SMART_POINTER) {
  1161. if (checkAttribute(n, k_storage, k_static)) {
  1162. Node *sn = Getattr(n, k_cplusstaticbase);
  1163. String *base = Getattr(sn, k_name);
  1164. self = NewStringf("%s::", base);
  1165. } else {
  1166. self = NewString("(*this)->");
  1167. }
  1168. }
  1169. name = Getattr(n, k_name);
  1170. type = Getattr(n, k_type);
  1171. gname = Swig_name_get(name);
  1172. membername = Swig_name_member(classname, gname);
  1173. mangled = Swig_name_mangle(membername);
  1174. t = NewString(classname);
  1175. SwigType_add_pointer(t);
  1176. parms = NewParm(t, k_self);
  1177. Setattr(parms, k_self, "1");
  1178. Setattr(parms, k_hidden, "1");
  1179. Delete(t);
  1180. ty = Swig_wrapped_member_var_type(type, varcref);
  1181. if (flags & CWRAP_EXTEND) {
  1182. String *call;
  1183. String *cres;
  1184. String *code = Getattr(n, k_code);
  1185. if (code) {
  1186. Swig_add_extension_code(n, mangled, parms, ty, code, cparse_cplusplus);
  1187. }
  1188. call = Swig_cfunction_call(mangled, parms);
  1189. cres = Swig_cresult(ty, k_result, call);
  1190. Setattr(n, k_wrapaction, cres);
  1191. Delete(cres);
  1192. Delete(call);
  1193. } else {
  1194. String *call = Swig_cmemberget_call(name, type, self, varcref);
  1195. String *cres = Swig_cresult(ty, k_result, call);
  1196. Setattr(n, k_wrapaction, cres);
  1197. Delete(call);
  1198. Delete(cres);
  1199. }
  1200. Setattr(n, k_type, ty);
  1201. Setattr(n, k_parms, parms);
  1202. Delete(parms);
  1203. Delete(ty);
  1204. Delete(membername);
  1205. Delete(gname);
  1206. Delete(mangled);
  1207. return SWIG_OK;
  1208. }
  1209. /* -----------------------------------------------------------------------------
  1210. * Swig_VarsetToFunction()
  1211. *
  1212. * This function creates a C wrapper for setting a global variable.
  1213. * ----------------------------------------------------------------------------- */
  1214. int Swig_VarsetToFunction(Node *n, int flags) {
  1215. String *name, *nname;
  1216. ParmList *parms;
  1217. SwigType *type, *ty;
  1218. int varcref = flags & CWRAP_NATURAL_VAR;
  1219. name = Getattr(n, k_name);
  1220. type = Getattr(n, k_type);
  1221. nname = SwigType_namestr(name);
  1222. ty = Swig_wrapped_var_type(type, varcref);
  1223. parms = NewParm(ty, name);
  1224. Delete(ty);
  1225. if (!Strstr(type, "enum $unnamed")) {
  1226. String *pname = Swig_cparm_name(0, 0);
  1227. String *dref = Swig_wrapped_var_deref(type, pname, varcref);
  1228. String *call = NewStringf("%s = %s;\n", nname, dref);
  1229. Setattr(n, k_wrapaction, call);
  1230. Delete(call);
  1231. Delete(dref);
  1232. Delete(pname);
  1233. } else {
  1234. String *pname = Swig_cparm_name(0, 0);
  1235. String *call = NewStringf("if (sizeof(int) == sizeof(%s)) *(int*)(void*)&(%s) = %s;\n", nname, nname, pname);
  1236. Setattr(n, k_wrapaction, call);
  1237. Delete(call);
  1238. }
  1239. Setattr(n, k_type, "void");
  1240. Setattr(n, k_parms, parms);
  1241. Delete(parms);
  1242. Delete(nname);
  1243. return SWIG_OK;
  1244. }
  1245. /* -----------------------------------------------------------------------------
  1246. * Swig_VargetToFunction()
  1247. *
  1248. * This function creates a C wrapper for getting a global variable.
  1249. * ----------------------------------------------------------------------------- */
  1250. int Swig_VargetToFunction(Node *n, int flags) {
  1251. String *cres, *call;
  1252. String *name, *nname;
  1253. SwigType *type, *ty;
  1254. int varcref = flags & CWRAP_NATURAL_VAR;
  1255. name = Getattr(n, k_name);
  1256. type = Getattr(n, k_type);
  1257. nname = SwigType_namestr(name);
  1258. ty = Swig_wrapped_var_type(type, varcref);
  1259. call = Swig_wrapped_var_assign(type, nname, varcref);
  1260. cres = Swig_cresult(ty, k_result, call);
  1261. Setattr(n, k_wrapaction, cres);
  1262. Delete(cres);
  1263. Delete(call);
  1264. Setattr(n, k_type, ty);
  1265. Delattr(n, k_parms);
  1266. Delete(nname);
  1267. Delete(ty);
  1268. return SWIG_OK;
  1269. }