PageRenderTime 333ms CodeModel.GetById 16ms RepoModel.GetById 8ms app.codeStats 0ms

/tags/v-1-3-a5-release/SWIG/Source/Swig/cwrap.c

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