WorkWithlistofmodulebysubroutine.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /******************************************************************************/
  2. /* */
  3. /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */
  4. /* */
  5. /* Copyright or or Copr. Laurent Debreu (Laurent.Debreu@imag.fr) */
  6. /* Cyril Mazauric (Cyril_Mazauric@yahoo.fr) */
  7. /* This software is governed by the CeCILL-C license under French law and */
  8. /* abiding by the rules of distribution of free software. You can use, */
  9. /* modify and/ or redistribute the software under the terms of the CeCILL-C */
  10. /* license as circulated by CEA, CNRS and INRIA at the following URL */
  11. /* "http://www.cecill.info". */
  12. /* */
  13. /* As a counterpart to the access to the source code and rights to copy, */
  14. /* modify and redistribute granted by the license, users are provided only */
  15. /* with a limited warranty and the software's author, the holder of the */
  16. /* economic rights, and the successive licensors have only limited */
  17. /* liability. */
  18. /* */
  19. /* In this respect, the user's attention is drawn to the risks associated */
  20. /* with loading, using, modifying and/or developing or reproducing the */
  21. /* software by the user in light of its specific status of free software, */
  22. /* that may mean that it is complicated to manipulate, and that also */
  23. /* therefore means that it is reserved for developers and experienced */
  24. /* professionals having in-depth computer knowledge. Users are therefore */
  25. /* encouraged to load and test the software's suitability as regards their */
  26. /* requirements in conditions enabling the security of their systems and/or */
  27. /* data to be ensured and, more generally, to use and operate it in the */
  28. /* same conditions as regards security. */
  29. /* */
  30. /* The fact that you are presently reading this means that you have had */
  31. /* knowledge of the CeCILL-C license and that you accept its terms. */
  32. /******************************************************************************/
  33. /* version 1.7 */
  34. /******************************************************************************/
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include "decl.h"
  39. /******************************************************************************/
  40. /* RecordUseModulesVariables */
  41. /******************************************************************************/
  42. /* */
  43. /******************************************************************************/
  44. void RecordUseModulesVariables()
  45. {
  46. listusemodule *tmplistmodule;
  47. /* we should record all variables defined in modules used in this file */
  48. if ( List_NameOfModuleUsed )
  49. {
  50. tmplistmodule = List_NameOfModuleUsed;
  51. while ( tmplistmodule )
  52. {
  53. if ( tmplistmodule->u_firstuse == 1 )
  54. {
  55. /* check if the file .depend<u_usemodule> exist */
  56. List_ModuleUsed_Var = Readthedependfile
  57. (tmplistmodule->u_usemodule,List_ModuleUsed_Var);
  58. List_GlobParamModuleUsed_Var = ReaddependParameterList
  59. (tmplistmodule->u_usemodule,List_GlobParamModuleUsed_Var);
  60. }
  61. tmplistmodule = tmplistmodule->suiv;
  62. }
  63. }
  64. }
  65. /******************************************************************************/
  66. /* RecordUseModulesUseModulesVariables */
  67. /******************************************************************************/
  68. /******************************************************************************/
  69. void RecordUseModulesUseModulesVariables()
  70. {
  71. listusemodule *tmplistmodule;
  72. listusemodule *save_list;
  73. if ( ! List_NameOfModuleUsed ) return;
  74. /* we should record all variables defined in modules used in this file */
  75. /* and we should read the .depend of the module used by the module used */
  76. tmplistmodule = List_NameOfModuleUsed;
  77. while ( tmplistmodule )
  78. {
  79. Readthedependlistofmoduleused(tmplistmodule->u_usemodule);
  80. while( tmpuselocallist )
  81. {
  82. Addmoduletothelisttmp(tmpuselocallist->u_usemodule);
  83. save_list = tmpuselocallist->suiv;
  84. free(tmpuselocallist);
  85. tmpuselocallist = save_list;
  86. }
  87. tmplistmodule = tmplistmodule->suiv;
  88. }
  89. tmplistmodule = listofmoduletmp;
  90. while ( tmplistmodule )
  91. {
  92. Readthedependlistofmoduleused(tmplistmodule->u_usemodule);
  93. while( tmpuselocallist )
  94. {
  95. Addmoduletothelisttmp(tmpuselocallist->u_usemodule);
  96. save_list = tmpuselocallist->suiv;
  97. free(tmpuselocallist);
  98. tmpuselocallist = save_list;
  99. }
  100. tmplistmodule = tmplistmodule->suiv;
  101. }
  102. tmplistmodule = listofmoduletmp;
  103. while ( tmplistmodule )
  104. {
  105. // check if the file .depend<u_usemodule> exists
  106. List_ModuleUsedInModuleUsed_Var =
  107. Readthedependfile(tmplistmodule->u_usemodule,List_ModuleUsedInModuleUsed_Var);
  108. List_GlobParamModuleUsedInModuleUsed_Var =
  109. ReaddependParameterList(tmplistmodule->u_usemodule,List_GlobParamModuleUsedInModuleUsed_Var);
  110. tmplistmodule = tmplistmodule->suiv;
  111. }
  112. }
  113. /******************************************************************************/
  114. /* Add_NameOfModuleUsed_1 */
  115. /******************************************************************************/
  116. /* This subroutine is used to add a record to a list of struct */
  117. /* listusemodule */
  118. /******************************************************************************/
  119. /* */
  120. /* subroutine sub ... USE mod1 ===> insert in list */
  121. /* _______ _______ _______ _______ _______ */
  122. /* + + + + + + + + + + */
  123. /* + NEW +--->+ list +--->+ list +--->+ list +--->+ list + */
  124. /* +______+ +______+ +______+ +______+ +______+ */
  125. /* */
  126. /* list = List_NameOfModuleUsed */
  127. /* */
  128. /******************************************************************************/
  129. void Add_NameOfModuleUsed_1(char *name)
  130. {
  131. listusemodule *newmodule;
  132. listusemodule *parcours;
  133. int out;
  134. newmodule = (listusemodule*) calloc(1, sizeof(listusemodule));
  135. strcpy(newmodule->u_usemodule, name);
  136. strcpy(newmodule->u_charusemodule, charusemodule);
  137. strcpy(newmodule->u_modulename, curmodulename);
  138. strcpy(newmodule->u_cursubroutine, subroutinename);
  139. newmodule->u_firstuse = 1 ;
  140. newmodule->suiv = NULL;
  141. if ( List_NameOfModuleUsed == NULL )
  142. {
  143. List_NameOfModuleUsed = newmodule ;
  144. }
  145. else
  146. {
  147. parcours = List_NameOfModuleUsed;
  148. while ( parcours && newmodule->u_firstuse )
  149. {
  150. if ( !strcasecmp(name,parcours->u_usemodule) )
  151. {
  152. newmodule->u_firstuse = 0 ;
  153. }
  154. parcours = parcours->suiv;
  155. }
  156. /* we can not add the same module twice for the same subroutine */
  157. parcours = List_NameOfModuleUsed;
  158. out = 0 ;
  159. while ( parcours && out == 0 )
  160. {
  161. if ( !strcasecmp(name,parcours->u_usemodule) &&
  162. !strcasecmp(subroutinename,parcours->u_cursubroutine) )
  163. {
  164. out = 1 ;
  165. free(newmodule);
  166. }
  167. else
  168. parcours = parcours->suiv;
  169. }
  170. if ( out == 0 )
  171. {
  172. newmodule->suiv = List_NameOfModuleUsed;
  173. List_NameOfModuleUsed = newmodule;
  174. }
  175. }
  176. }
  177. /******************************************************************************/
  178. /* Addmoduletothelist */
  179. /******************************************************************************/
  180. /* This subroutine is used to add a record to a list of struct */
  181. /* listusemodule */
  182. /******************************************************************************/
  183. /* */
  184. /* subroutine sub ... USE mod1 ===> insert in list */
  185. /* _______ _______ _______ _______ _______ */
  186. /* + + + + + + + + + + */
  187. /* + NEW +--->+ list +--->+ list +--->+ list +--->+ list + */
  188. /* +______+ +______+ +______+ +______+ +______+ */
  189. /* */
  190. /* list = List_NameOfModuleUsed */
  191. /* */
  192. /******************************************************************************/
  193. void Addmoduletothelist(const char *name)
  194. {
  195. listusemodule *newmodule;
  196. listusemodule *parcours;
  197. int out;
  198. newmodule = (listusemodule*) calloc(1,sizeof(listusemodule));
  199. strcpy(newmodule->u_usemodule, name);
  200. strcpy(newmodule->u_charusemodule, charusemodule);
  201. strcpy(newmodule->u_cursubroutine, subroutinename);
  202. newmodule->u_firstuse = 1 ;
  203. newmodule->suiv = NULL;
  204. if ( !List_NameOfModuleUsed )
  205. {
  206. List_NameOfModuleUsed = newmodule ;
  207. }
  208. else
  209. {
  210. parcours = List_NameOfModuleUsed;
  211. while ( parcours && newmodule->u_firstuse == 1 )
  212. {
  213. if ( !strcasecmp(name,parcours->u_usemodule) )
  214. {
  215. newmodule->u_firstuse = 0 ;
  216. }
  217. parcours=parcours->suiv;
  218. }
  219. /* we can not add the same module twice for the same subroutine */
  220. parcours = List_NameOfModuleUsed;
  221. out = 0 ;
  222. while ( parcours && out == 0 )
  223. {
  224. if ( !strcasecmp(name,parcours->u_usemodule) &&
  225. !strcasecmp(subroutinename,parcours->u_cursubroutine) )
  226. {
  227. out = 1 ;
  228. free(newmodule);
  229. }
  230. else
  231. parcours=parcours->suiv;
  232. }
  233. if ( out == 0 )
  234. {
  235. newmodule->suiv = List_NameOfModuleUsed;
  236. List_NameOfModuleUsed = newmodule;
  237. }
  238. }
  239. }
  240. /******************************************************************************/
  241. /* WriteUsemoduleDeclaration */
  242. /******************************************************************************/
  243. /* Firstpass 0 */
  244. /******************************************************************************/
  245. /* */
  246. /******************************************************************************/
  247. void WriteUsemoduleDeclaration(const char *cursubroutinename)
  248. {
  249. listusemodule *newmodule;
  250. listvarpointtovar *pointtmp;
  251. long int fictifpos;
  252. int findcoupled;
  253. fprintf(fortran_out,"\n");
  254. newmodule = List_NameOfModuleUsed;
  255. while ( newmodule )
  256. {
  257. if ( !strcasecmp(newmodule->u_cursubroutine, cursubroutinename) )
  258. {
  259. if (strcmp(newmodule->u_charusemodule,""))
  260. {
  261. /*
  262. findcoupled = 0;
  263. pointtmp = List_CouplePointed_Var;
  264. while(pointtmp)
  265. {
  266. if ((!strcasecmp(pointtmp->t_usemodule, newmodule->u_charusemodule)) && \
  267. (!strcasecmp(pointtmp->t_cursubroutine, cursubroutinename)))
  268. {
  269. fictifpos = setposcur();
  270. variableisglobalinmodule(pointtmp->t_couple,newmodule->u_charusemodule,fortran_out,fictifpos);
  271. findcoupled = 1;
  272. }
  273. pointtmp=pointtmp->suiv;
  274. }
  275. if (findcoupled == 0) fprintf(fortran_out," use %s\n",newmodule->u_charusemodule);
  276. */
  277. fprintf(fortran_out," use %s\n", newmodule->u_charusemodule);
  278. }
  279. }
  280. newmodule = newmodule ->suiv;
  281. }
  282. }