PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/main-premerge/SWIG/Source/Swig/cwrap.c

#
C | 976 lines | 615 code | 148 blank | 213 comment | 60 complexity | b582a6ed0b3da332ccfb647682f415a5 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * cwrap.c
  3. *
  4. * This file defines a variety of wrapping rules for C/C++ handling including
  5. * the naming of local variables, calling conventions, and so forth.
  6. *
  7. * Author(s) : David Beazley (beazley@cs.uchicago.edu)
  8. *
  9. * Copyright (C) 1998-2000. The University of Chicago
  10. * Copyright (C) 1995-1998. The University of Utah and The Regents of the
  11. * University of California.
  12. *
  13. * See the file LICENSE for information on usage and redistribution.
  14. * ----------------------------------------------------------------------------- */
  15. static char cvsroot[] = "$Header$";
  16. #include "swig.h"
  17. /* -----------------------------------------------------------------------------
  18. * Swig_parm_name()
  19. *
  20. * Generates a name for the ith argument in an argument list
  21. * ----------------------------------------------------------------------------- */
  22. String *
  23. Swig_cparm_name(Parm *p, int i) {
  24. String *name = NewStringf("arg%d",i);
  25. if (p) {
  26. Setlname(p,name);
  27. }
  28. return Swig_temp_result(name);
  29. }
  30. /* -----------------------------------------------------------------------------
  31. * Swig_clocal()
  32. *
  33. * Creates a string that declares a C local variable type. Converts references
  34. * and user defined types to pointers.
  35. * ----------------------------------------------------------------------------- */
  36. String *
  37. Swig_clocal(SwigType *t, String_or_char *name, String_or_char *value) {
  38. String *decl = 0;
  39. /* *((char *) decl) = 'x';*/
  40. decl = NewString("");
  41. switch(SwigType_type(t)) {
  42. case T_USER:
  43. SwigType_add_pointer(t);
  44. if (value)
  45. Printf(decl,"%s = (%s) &%s", SwigType_lstr(t,name), SwigType_lstr(t,0), value);
  46. else
  47. Printf(decl,"%s", SwigType_lstr(t,name));
  48. SwigType_del_pointer(t);
  49. break;
  50. case T_REFERENCE:
  51. if (value)
  52. Printf(decl,"%s = (%s) &%s", SwigType_lstr(t,name), SwigType_lstr(t,0), value);
  53. else
  54. Printf(decl,"%s", SwigType_lstr(t,name));
  55. break;
  56. case T_VOID:
  57. break;
  58. default:
  59. if (value)
  60. Printf(decl,"%s = %s", SwigType_lstr(t,name), value);
  61. else
  62. Printf(decl,"%s", SwigType_lstr(t,name));
  63. }
  64. return Swig_temp_result(decl);
  65. }
  66. /* -----------------------------------------------------------------------------
  67. * Swig_clocal_type()
  68. *
  69. * Creates a string that declares a C local variable type. Converts references
  70. * and user defined types to pointers.
  71. * ----------------------------------------------------------------------------- */
  72. SwigType *
  73. Swig_clocal_type(SwigType *t) {
  74. SwigType *ty;
  75. switch(SwigType_type(t)) {
  76. case T_USER:
  77. SwigType_add_pointer(t);
  78. ty = SwigType_ltype(t);
  79. SwigType_del_pointer(t);
  80. break;
  81. default:
  82. ty = SwigType_ltype(t);
  83. break;
  84. }
  85. return ty;
  86. }
  87. /* -----------------------------------------------------------------------------
  88. * Swig_clocal_deref()
  89. *
  90. * Creates a string that can be used to deref a local variable wrapped with
  91. * the Swig_clocal() function.
  92. * ----------------------------------------------------------------------------- */
  93. String *
  94. Swig_clocal_deref(SwigType *t, String_or_char *name) {
  95. switch(SwigType_type(t)) {
  96. case T_USER:
  97. return Swig_temp_result(NewStringf("*%s",name));
  98. break;
  99. case T_VOID:
  100. return Swig_temp_result(NewString(""));
  101. break;
  102. default:
  103. return SwigType_rcaststr(t,name);
  104. break;
  105. }
  106. }
  107. /* -----------------------------------------------------------------------------
  108. * Swig_clocal_assign()
  109. *
  110. * Assigns a value to a local
  111. * ----------------------------------------------------------------------------- */
  112. String *
  113. Swig_clocal_assign(SwigType *t, String_or_char *name) {
  114. switch(SwigType_type(t)) {
  115. case T_VOID:
  116. return Swig_temp_result(NewString(""));
  117. break;
  118. case T_USER:
  119. return Swig_temp_result(NewStringf("&%s", name));
  120. break;
  121. default:
  122. return SwigType_lcaststr(t,name);
  123. break;
  124. }
  125. }
  126. /* -----------------------------------------------------------------------------
  127. * Swig_cargs()
  128. *
  129. * Emit all of the local variables for a list of parameters. Returns the
  130. * number of parameters.
  131. * ----------------------------------------------------------------------------- */
  132. int Swig_cargs(Wrapper *w, ParmList *p) {
  133. int i;
  134. SwigType *pt;
  135. String *pvalue;
  136. String *pname;
  137. String *local;
  138. String *lname;
  139. i = 0;
  140. while (p != 0) {
  141. lname = Swig_cparm_name(p,i);
  142. pt = Gettype(p);
  143. pname = Getname(p);
  144. pvalue = Getvalue(p);
  145. local = Swig_clocal(pt,lname,pvalue);
  146. Wrapper_add_localv(w,lname,local,0);
  147. i++;
  148. p = Getnext(p);
  149. }
  150. return(i);
  151. }
  152. /* -----------------------------------------------------------------------------
  153. * Swig_cresult()
  154. *
  155. * This function generates the C code needed to set the result of a C
  156. * function call.
  157. * ----------------------------------------------------------------------------- */
  158. void Swig_cresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_char *decl) {
  159. String *fcall;
  160. fcall = NewString("");
  161. if (SwigType_type(t) != T_VOID)
  162. Wrapper_add_localv(w,name, Swig_clocal(t,name,0), 0);
  163. switch(SwigType_type(t)) {
  164. case T_VOID:
  165. break;
  166. case T_USER:
  167. SwigType_add_pointer(t);
  168. Printf(fcall,"%s = (%s) malloc(sizeof(", name, SwigType_lstr(t,0));
  169. SwigType_del_pointer(t);
  170. Printf(fcall, "%s));\n", SwigType_str(t,0));
  171. Printf(fcall, "*(%s) = ", name);
  172. break;
  173. case T_REFERENCE:
  174. Printf(fcall,"%s = ", SwigType_str(t,"_result_ref"));
  175. break;
  176. default:
  177. /* Normal return value */
  178. Printf(fcall,"%s = (%s)", name, SwigType_lstr(t,0));
  179. break;
  180. }
  181. /* Now print out function call */
  182. Printv(fcall,decl,0);
  183. /* A sick hack */
  184. {
  185. char *c = Char(decl) + Len(decl) - 1;
  186. if (!((*c == ';') || (*c == '}')))
  187. Printf(fcall, ";");
  188. }
  189. Printf(fcall,"\n");
  190. if (SwigType_type(t) == T_REFERENCE) {
  191. Printf(fcall,"%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0));
  192. }
  193. if (Replace(w,"$function",fcall, DOH_REPLACE_ANY) == 0) {
  194. Printv(w, fcall, 0);
  195. }
  196. Delete(fcall);
  197. }
  198. /* -----------------------------------------------------------------------------
  199. * Swig_cppresult()
  200. *
  201. * This function generates the C++ code needed to set the result. This uses
  202. * the C++ default copy constructor for user defined objects.
  203. * ----------------------------------------------------------------------------- */
  204. void Swig_cppresult(Wrapper *w, SwigType *t, String_or_char *name, String_or_char *decl) {
  205. String *fcall;
  206. fcall = NewString("");
  207. if (SwigType_type(t) != T_VOID)
  208. Wrapper_add_localv(w,name, Swig_clocal(t,name,0), 0);
  209. switch(SwigType_type(t)) {
  210. case T_VOID:
  211. break;
  212. case T_USER:
  213. {
  214. SwigType *temp = Copy(t);
  215. while (SwigType_isconst(temp)) {
  216. SwigType_pop(temp);
  217. }
  218. Printf(fcall, "%s = new %s(", name, SwigType_str(temp,0));
  219. Delete(temp);
  220. }
  221. break;
  222. case T_REFERENCE:
  223. Printf(fcall, "%s = ", SwigType_str(t,"_result_ref"));
  224. break;
  225. default:
  226. Printf(fcall,"%s = (%s)", name, SwigType_lstr(t,0));
  227. break;
  228. }
  229. /* Now print out function call */
  230. Printv(fcall, decl, 0);
  231. switch(SwigType_type(t)) {
  232. case T_USER:
  233. Printf(fcall,");\n");
  234. break;
  235. case T_REFERENCE:
  236. Printf(fcall,";\n");
  237. Printf(fcall, "%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0));
  238. break;
  239. default:
  240. /* A sick hack */
  241. {
  242. char *c = Char(decl) + Len(decl) - 1;
  243. if (!((*c == ';') || (*c == '}')))
  244. Printf(fcall, ";");
  245. }
  246. Printf(fcall,"\n");
  247. break;
  248. }
  249. if (Replace(w,"$function",fcall, DOH_REPLACE_ANY) == 0) {
  250. Printv(w, fcall, 0);
  251. }
  252. Delete(fcall);
  253. }
  254. /* -----------------------------------------------------------------------------
  255. * Swig_cfunction_call()
  256. *
  257. * Creates a string that calls a C function using the local variable rules
  258. * defined above.
  259. *
  260. * name(arg0, arg1, arg2, ... argn)
  261. *
  262. * ----------------------------------------------------------------------------- */
  263. String *
  264. Swig_cfunction_call(String_or_char *name, ParmList *parms) {
  265. DOH *func;
  266. int i = 0;
  267. Parm *p = parms;
  268. SwigType *pt;
  269. func = NewString("");
  270. Printf(func,"%s(", name);
  271. while (p) {
  272. String *pname;
  273. pt = Gettype(p);
  274. pname = Swig_cparm_name(p,i);
  275. Printf(func,"%s", Swig_clocal_deref(pt, pname));
  276. i++;
  277. p = Getnext(p);
  278. if (p)
  279. Printf(func,",");
  280. }
  281. Printf(func,")");
  282. return Swig_temp_result(func);
  283. }
  284. /* -----------------------------------------------------------------------------
  285. * Swig_cmethod_call()
  286. *
  287. * Generates a string that calls a C++ method from a list of parameters.
  288. *
  289. * arg0->name(arg1, arg2, arg3, ..., argn)
  290. *
  291. * ----------------------------------------------------------------------------- */
  292. String *
  293. Swig_cmethod_call(String_or_char *name, ParmList *parms) {
  294. DOH *func;
  295. int i = 0;
  296. Parm *p = parms;
  297. SwigType *pt;
  298. func = NewString("");
  299. if (!p) return Swig_temp_result(func);
  300. Printf(func,"%s->%s(", Swig_cparm_name(p,0), name);
  301. i++;
  302. p = Getnext(p);
  303. while (p) {
  304. String *pname;
  305. pt = Gettype(p);
  306. pname = Swig_cparm_name(p,i);
  307. Printf(func,"%s", Swig_clocal_deref(pt, pname));
  308. i++;
  309. p = Getnext(p);
  310. if (p)
  311. Printf(func,",");
  312. }
  313. Printf(func,")");
  314. return Swig_temp_result(func);
  315. }
  316. /* -----------------------------------------------------------------------------
  317. * Swig_cconstructor_call()
  318. *
  319. * Creates a string that calls a C constructor function.
  320. *
  321. * (name *) calloc(1,sizeof(name));
  322. * ----------------------------------------------------------------------------- */
  323. String *
  324. Swig_cconstructor_call(String_or_char *name) {
  325. DOH *func;
  326. func = NewString("");
  327. Printf(func,"(%s *) calloc(1, sizeof(%s))", name, name);
  328. return Swig_temp_result(func);
  329. }
  330. /* -----------------------------------------------------------------------------
  331. * Swig_cppconstructor_call()
  332. *
  333. * Creates a string that calls a C function using the local variable rules
  334. * defined above.
  335. *
  336. * name(arg0, arg1, arg2, ... argn)
  337. *
  338. * ----------------------------------------------------------------------------- */
  339. String *
  340. Swig_cppconstructor_call(String_or_char *name, ParmList *parms) {
  341. DOH *func;
  342. int i = 0;
  343. Parm *p = parms;
  344. SwigType *pt;
  345. func = NewString("");
  346. Printf(func,"new %s(", name);
  347. while (p) {
  348. String *pname;
  349. pt = Gettype(p);
  350. pname = Swig_cparm_name(p,i);
  351. Printf(func,"%s", Swig_clocal_deref(pt, pname));
  352. i++;
  353. p = Getnext(p);
  354. if (p)
  355. Printf(func,",");
  356. }
  357. Printf(func,")");
  358. return Swig_temp_result(func);
  359. }
  360. /* -----------------------------------------------------------------------------
  361. * Swig_cdestructor_call()
  362. *
  363. * Creates a string that calls a C constructor function.
  364. *
  365. * free((char *) arg0);
  366. * ----------------------------------------------------------------------------- */
  367. String *
  368. Swig_cdestructor_call() {
  369. DOH *func;
  370. func = NewString("");
  371. Printf(func,"free((char *) %s)", Swig_cparm_name(0,0));
  372. return Swig_temp_result(func);
  373. }
  374. /* -----------------------------------------------------------------------------
  375. * Swig_cppdestructor_call()
  376. *
  377. * Creates a string that calls a C constructor function.
  378. *
  379. * delete arg0;
  380. * ----------------------------------------------------------------------------- */
  381. String *
  382. Swig_cppdestructor_call() {
  383. DOH *func;
  384. func = NewString("");
  385. Printf(func,"delete %s", Swig_cparm_name(0,0));
  386. return Swig_temp_result(func);
  387. }
  388. /* -----------------------------------------------------------------------------
  389. * Swig_cmemberset_call()
  390. *
  391. * Generates a string that sets the name of a member in a C++ class or C struct.
  392. *
  393. * arg0->name = arg1
  394. *
  395. * ----------------------------------------------------------------------------- */
  396. String *
  397. Swig_cmemberset_call(String_or_char *name, SwigType *type) {
  398. DOH *func;
  399. func = NewString("");
  400. /*
  401. if (SwigType_type(type) == T_USER) {
  402. Printf(func,"%s %s->%s; ", Swig_clocal_assign(type,""), Swig_cparm_name(0,0), name);
  403. } else {
  404. Printf(func,"%s ", Swig_clocal_assign(type,""));
  405. }
  406. */
  407. /* Printf(func,"(%s->%s = ", Swig_cparm_name(0,0), name);
  408. Printf(func,"%s)", Swig_clocal_deref(type, (pname = Swig_cparm_name(0,1))));
  409. */
  410. Printf(func,"%s->%s = %s",Swig_cparm_name(0,0),name, Swig_clocal_deref(type, Swig_cparm_name(0,1)));
  411. return Swig_temp_result(func);
  412. }
  413. /* -----------------------------------------------------------------------------
  414. * Swig_cmemberget_call()
  415. *
  416. * Generates a string that sets the name of a member in a C++ class or C struct.
  417. *
  418. * arg0->name
  419. *
  420. * ----------------------------------------------------------------------------- */
  421. String *
  422. Swig_cmemberget_call(String_or_char *name, SwigType *t) {
  423. DOH *func;
  424. func = NewString("");
  425. Printf(func,"%s (%s->%s)", Swig_clocal_assign(t,""),Swig_cparm_name(0,0), name);
  426. return Swig_temp_result(func);
  427. }
  428. static void fix_parm_names(ParmList *p) {
  429. int i = 0;
  430. while (p) {
  431. if (!Getname(p)) {
  432. char temp[64];
  433. sprintf(temp,"arg%d",i);
  434. Setname(p,temp);
  435. }
  436. i++;
  437. p = Getnext(p);
  438. }
  439. }
  440. /* -----------------------------------------------------------------------------
  441. * Swig_cfunction_wrapper()
  442. *
  443. * This function creates a C wrapper around a C++ method. Returns a Wrapper
  444. * object containing the code, parameters, and so forth.
  445. * ----------------------------------------------------------------------------- */
  446. Wrapper *
  447. Swig_cfunction_wrapper(String_or_char *funcname,
  448. SwigType *rtype,
  449. ParmList *parms,
  450. String_or_char *code)
  451. {
  452. Wrapper *w;
  453. ParmList *l;
  454. w = NewWrapper();
  455. /* Set the name of the function */
  456. Setname(w,funcname);
  457. l = CopyParmList(parms);
  458. fix_parm_names(l);
  459. Printf(w,"%s %s(%s) {\n", SwigType_str(rtype,0), funcname, ParmList_str(l));
  460. if (code) {
  461. Printv(w, code, "\n", 0);
  462. }
  463. Printf(w,"}\n");
  464. Setattr(w,"type",rtype);
  465. Setattr(w,"parms",l);
  466. Delete(l);
  467. return w;
  468. }
  469. /* -----------------------------------------------------------------------------
  470. * Swig_cmethod_wrapper()
  471. *
  472. * This function creates a C wrapper around a C++ method. Returns a Wrapper
  473. * object containing the code, parameters, and so forth.
  474. * ----------------------------------------------------------------------------- */
  475. Wrapper *
  476. Swig_cmethod_wrapper(String_or_char *classname,
  477. String_or_char *methodname,
  478. SwigType *rtype,
  479. ParmList *parms,
  480. String_or_char *code)
  481. {
  482. Wrapper *w;
  483. ParmList *l;
  484. Parm *p;
  485. SwigType *t;
  486. w = NewWrapper();
  487. /* Set the name of the function */
  488. Setname(w,Swig_name_member(classname, methodname));
  489. l = CopyParmList(parms);
  490. t = NewString(classname);
  491. SwigType_add_pointer(t);
  492. p = NewParm(t,"self");
  493. Setnext(p,l);
  494. Delete(t);
  495. l = p;
  496. fix_parm_names(l);
  497. Printf(w,"%s %s(%s) {\n", SwigType_str(rtype,0), Swig_name_member(classname, methodname), ParmList_str(l));
  498. if (!code) {
  499. /* No code supplied. Write a function manually */
  500. if (SwigType_type(rtype) != T_VOID) {
  501. Printf(w,"return ");
  502. }
  503. Printf(w,"self->%s(", methodname);
  504. p = Getnext(l);
  505. while (p) {
  506. Printf(w,"%s", Getname(p));
  507. p = Getnext(p);
  508. if (p)
  509. Printf(w,",");
  510. }
  511. Printf(w,");\n");
  512. Printf(w,"}\n");
  513. } else {
  514. Printv(w, code, "\n", 0);
  515. Printf(w,"}\n");
  516. }
  517. Setattr(w,"type",rtype);
  518. Setattr(w,"parms",l);
  519. Delete(l);
  520. return w;
  521. }
  522. /* -----------------------------------------------------------------------------
  523. * Swig_cconstructor_wrapper()
  524. *
  525. * This function creates a C wrapper for a C constructor function.
  526. * ----------------------------------------------------------------------------- */
  527. Wrapper *
  528. Swig_cconstructor_wrapper(String_or_char *classname,
  529. ParmList *parms,
  530. String_or_char *code)
  531. {
  532. Wrapper *w;
  533. ParmList *l;
  534. SwigType *t;
  535. w = NewWrapper();
  536. /* Set the name of the function */
  537. Setname(w,Swig_name_construct(classname));
  538. l = CopyParmList(parms);
  539. t = NewString(classname);
  540. SwigType_add_pointer(t);
  541. /* Patch up the argument names */
  542. fix_parm_names(l);
  543. Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l));
  544. if (!code) {
  545. /* No code supplied. Write a function manually */
  546. Printf(w,"return (%s) calloc(1,sizeof(%s));\n", SwigType_str(t,0), classname);
  547. } else {
  548. Printv(w, code, "\n", 0);
  549. }
  550. Printf(w,"}\n");
  551. Setattr(w,"type",t);
  552. Setattr(w,"parms",l);
  553. Delete(l);
  554. Delete(t);
  555. return w;
  556. }
  557. /* -----------------------------------------------------------------------------
  558. * Swig_cppconstructor_wrapper()
  559. *
  560. * This function creates a C wrapper for a C++ constructor function.
  561. * ----------------------------------------------------------------------------- */
  562. Wrapper *
  563. Swig_cppconstructor_wrapper(String_or_char *classname,
  564. ParmList *parms,
  565. String_or_char *code)
  566. {
  567. Wrapper *w;
  568. ParmList *l;
  569. SwigType *t;
  570. Parm *p;
  571. w = NewWrapper();
  572. /* Set the name of the function */
  573. Setname(w,Swig_name_construct(classname));
  574. l = CopyParmList(parms);
  575. t = NewString(classname);
  576. SwigType_add_pointer(t);
  577. /* Patch up the argument names */
  578. fix_parm_names(l);
  579. Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_construct(classname), ParmList_str(l));
  580. if (!code) {
  581. /* No code supplied. Write a function manually */
  582. Printf(w,"return new %s", SwigType_str(t,0));
  583. p = l;
  584. if (p) {
  585. Printf(w,"(");
  586. while (p) {
  587. Printf(w,"%s", Getname(p));
  588. p = Getnext(p);
  589. if (p)
  590. Printf(w,",");
  591. }
  592. Printf(w,")");
  593. }
  594. Printf(w,";\n");
  595. } else {
  596. Printv(w, code, "\n", 0);
  597. }
  598. Printf(w,"}\n");
  599. Setattr(w,"type",t);
  600. Setattr(w,"parms",l);
  601. Delete(l);
  602. Delete(t);
  603. return w;
  604. }
  605. /* -----------------------------------------------------------------------------
  606. * Swig_cdestructor_wrapper()
  607. *
  608. * This function creates a C wrapper for a C destructor.
  609. * ----------------------------------------------------------------------------- */
  610. Wrapper *
  611. Swig_cdestructor_wrapper(String_or_char *classname,
  612. String_or_char *code)
  613. {
  614. Wrapper *w;
  615. ParmList *l;
  616. SwigType *t;
  617. Parm *p;
  618. w = NewWrapper();
  619. /* Set the name of the function */
  620. Setname(w, Swig_name_destroy(classname));
  621. t = NewString(classname);
  622. SwigType_add_pointer(t);
  623. p = NewParm(t,"self");
  624. l = p;
  625. Delete(t);
  626. t = NewString("void");
  627. Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l));
  628. if (!code) {
  629. /* No code supplied. Write a function manually */
  630. Printf(w,"free((char *) self);\n");
  631. } else {
  632. Printv(w, code, "\n", 0);
  633. }
  634. Printf(w,"}\n");
  635. Setattr(w,"type",t);
  636. Setattr(w,"parms",l);
  637. Delete(l);
  638. Delete(t);
  639. return w;
  640. }
  641. /* -----------------------------------------------------------------------------
  642. * Swig_cppdestructor_wrapper()
  643. *
  644. * This function creates a C wrapper for a C++ destructor.
  645. * ----------------------------------------------------------------------------- */
  646. Wrapper *
  647. Swig_cppdestructor_wrapper(String_or_char *classname,
  648. String_or_char *code)
  649. {
  650. Wrapper *w;
  651. ParmList *l;
  652. SwigType *t;
  653. Parm *p;
  654. w = NewWrapper();
  655. /* Set the name of the function */
  656. Setname(w, Swig_name_destroy(classname));
  657. t = NewString(classname);
  658. SwigType_add_pointer(t);
  659. p = NewParm(t,"self");
  660. l = p;
  661. Delete(t);
  662. t = NewString("void");
  663. Printf(w,"%s %s(%s) {\n", SwigType_str(t,0), Swig_name_destroy(classname), ParmList_str(l));
  664. if (!code) {
  665. /* No code supplied. Write a function manually */
  666. Printf(w,"delete self;\n");
  667. } else {
  668. Printv(w, code, "\n", 0);
  669. }
  670. Printf(w,"}\n");
  671. Setattr(w,"type",t);
  672. Setattr(w,"parms",l);
  673. Delete(l);
  674. Delete(t);
  675. return w;
  676. }
  677. /* -----------------------------------------------------------------------------
  678. * Swig_cmemberset_wrapper()
  679. *
  680. * This function creates a C wrapper for setting a C++ structure member.
  681. * ----------------------------------------------------------------------------- */
  682. Wrapper *
  683. Swig_cmemberset_wrapper(String_or_char *classname,
  684. String_or_char *membername,
  685. SwigType *type,
  686. String_or_char *code)
  687. {
  688. Wrapper *w;
  689. ParmList *l;
  690. Parm *p;
  691. SwigType *t;
  692. SwigType *lt;
  693. w = NewWrapper();
  694. /* Set the name of the function */
  695. Setname(w, Swig_name_member(classname, Swig_name_set(membername)));
  696. t = NewString(classname);
  697. SwigType_add_pointer(t);
  698. p = NewParm(t,"self");
  699. l = p;
  700. Delete(t);
  701. lt = Swig_clocal_type(type);
  702. p = NewParm(lt,"value");
  703. Setnext(l,p);
  704. Printf(w,"void %s(%s) {\n", Getname(w), ParmList_str(l));
  705. if (!code) {
  706. /* No code supplied. Write a function manually */
  707. Printf(w,"self->%s = %s;\n", membername, Swig_clocal_deref(lt,"value"));
  708. Printf(w,"return %s self->%s;\n", Swig_clocal_assign(lt,""), membername);
  709. } else {
  710. Printv(w, code, "\n", 0);
  711. }
  712. Printf(w,"}\n");
  713. /* Wrapper_Settype(w,lt); */
  714. Setattr(w,"type","void");
  715. Setattr(w,"parms", l);
  716. Delete(l);
  717. Delete(lt);
  718. return w;
  719. }
  720. /* -----------------------------------------------------------------------------
  721. * Swig_cmemberget_wrapper()
  722. *
  723. * This function creates a C wrapper for getting a structure member
  724. * ----------------------------------------------------------------------------- */
  725. Wrapper *
  726. Swig_cmemberget_wrapper(String_or_char *classname,
  727. String_or_char *membername,
  728. SwigType *type,
  729. String_or_char *code)
  730. {
  731. Wrapper *w;
  732. ParmList *l;
  733. Parm *p;
  734. SwigType *t;
  735. SwigType *lt;
  736. w = NewWrapper();
  737. /* Set the name of the function */
  738. Setname(w,Swig_name_member(classname, Swig_name_get(membername)));
  739. t = NewString(classname);
  740. SwigType_add_pointer(t);
  741. p = NewParm(t,"self");
  742. l = p;
  743. Delete(t);
  744. lt = Swig_clocal_type(type);
  745. Printf(w,"%s %s(%s) {\n", SwigType_str(lt,0), Getname(w), ParmList_str(l));
  746. if (!code) {
  747. /* No code supplied. Write a function manually */
  748. Printf(w,"return %s self->%s;", Swig_clocal_assign(lt,""), membername);
  749. } else {
  750. Printv(w, code, "\n", 0);
  751. }
  752. Printf(w,"}\n");
  753. Setattr(w,"type",lt);
  754. Setattr(w,"parms",l);
  755. Delete(l);
  756. Delete(lt);
  757. return w;
  758. }
  759. /* -----------------------------------------------------------------------------
  760. * Swig_cvarset_wrapper()
  761. *
  762. * This function creates a C wrapper for setting a global variable.
  763. * ----------------------------------------------------------------------------- */
  764. Wrapper *
  765. Swig_cvarset_wrapper(String_or_char *varname,
  766. SwigType *type,
  767. String_or_char *code)
  768. {
  769. Wrapper *w;
  770. ParmList *l;
  771. Parm *p;
  772. SwigType *lt;
  773. w = NewWrapper();
  774. /* Set the name of the function */
  775. Setname(w,Swig_name_set(varname));
  776. lt = Swig_clocal_type(type);
  777. p = NewParm(lt,"value");
  778. l = p;
  779. Printf(w,"%s %s(%s) {\n", SwigType_str(lt,0), Getname(w), ParmList_str(l));
  780. if (!code) {
  781. /* No code supplied. Write a function manually */
  782. Printf(w,"%s = %s;\n", varname, Swig_clocal_deref(lt,"value"));
  783. Printf(w,"return %s;\n", Swig_clocal_assign(lt,varname));
  784. } else {
  785. Printv(w, code, "\n", 0);
  786. Replace(w,"$target",varname, DOH_REPLACE_ANY);
  787. Replace(w,"$source","value", DOH_REPLACE_ANY);
  788. Replace(w,"$ltype", SwigType_str(lt,""), DOH_REPLACE_ANY);
  789. Replace(w,"$rtype", SwigType_str(type,""), DOH_REPLACE_ANY);
  790. }
  791. Printf(w,"}\n");
  792. Setattr(w,"type",lt);
  793. Setattr(w,"parms",l);
  794. Delete(l);
  795. Delete(lt);
  796. return w;
  797. }
  798. /* -----------------------------------------------------------------------------
  799. * Swig_cvarget_wrapper()
  800. *
  801. * This function creates a C wrapper for getting a structure member
  802. * ----------------------------------------------------------------------------- */
  803. Wrapper *
  804. Swig_cvarget_wrapper(String_or_char *varname,
  805. SwigType *type,
  806. String_or_char *code)
  807. {
  808. Wrapper *w;
  809. ParmList *l = 0;
  810. SwigType *lt;
  811. w = NewWrapper();
  812. /* Set the name of the function */
  813. Setname(w,Swig_name_get(varname));
  814. lt = Swig_clocal_type(type);
  815. Printf(w,"%s %s(%s) {\n", SwigType_str(lt,0), Getname(w), ParmList_str(l));
  816. if (!code) {
  817. /* No code supplied. Write a function manually */
  818. Printf(w,"return %s;", Swig_clocal_assign(type,varname));
  819. } else {
  820. Printv(w, code, "\n", 0);
  821. }
  822. Printf(w,"}\n");
  823. Setattr(w,"type",lt);
  824. Setattr(w,"parms",l);
  825. Delete(l);
  826. Delete(lt);
  827. return w;
  828. }