PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/tags/mkoeppe-1-3-mzscheme/SWIG/Source/Swig/cwrap.c

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