1 | /******************************************************************************/ |
---|
2 | /* */ |
---|
3 | /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */ |
---|
4 | /* */ |
---|
5 | /* Copyright (C) 2005 Laurent Debreu (Laurent.Debreu@imag.fr) */ |
---|
6 | /* Cyril Mazauric (Cyril.Mazauric@imag.fr) */ |
---|
7 | /* */ |
---|
8 | /* This program is free software; you can redistribute it and/or modify */ |
---|
9 | /* it */ |
---|
10 | /* */ |
---|
11 | /* This program is distributed in the hope that it will be useful, */ |
---|
12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
---|
13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
---|
14 | /* GNU General Public License for more details. */ |
---|
15 | /* */ |
---|
16 | /******************************************************************************/ |
---|
17 | #include <stdio.h> |
---|
18 | #include <stdlib.h> |
---|
19 | #include <string.h> |
---|
20 | |
---|
21 | #include "decl.h" |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | /******************************************************************************/ |
---|
26 | /* RecordUseModulesVariables */ |
---|
27 | /******************************************************************************/ |
---|
28 | /******************************************************************************/ |
---|
29 | void RecordUseModulesVariables() |
---|
30 | { |
---|
31 | listusemodule *tmplistmodule; |
---|
32 | |
---|
33 | /* we should record all variables defined in modules used in this file */ |
---|
34 | if ( listofmodulebysubroutine ) |
---|
35 | { |
---|
36 | globalvarofusefile = (listvar *)NULL; |
---|
37 | tmpparameterlocallist = (listparameter *)NULL; |
---|
38 | listofvarofusemodulecreated = 1; |
---|
39 | tmplistmodule = listofmodulebysubroutine; |
---|
40 | while ( tmplistmodule ) |
---|
41 | { |
---|
42 | if ( tmplistmodule->firstuse == 1 ) |
---|
43 | { |
---|
44 | /* check if the file .depend<usemodule> exist */ |
---|
45 | globalvarofusefile = Recordglobalvarofusefile |
---|
46 | (tmplistmodule->usemodule,globalvarofusefile); |
---|
47 | |
---|
48 | tmpparameterlocallist = ReaddependParameterList |
---|
49 | (tmplistmodule->usemodule,tmpparameterlocallist); |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | tmplistmodule = tmplistmodule->suiv; |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | /******************************************************************************/ |
---|
59 | /* RecordUseModulesUseModulesVariables */ |
---|
60 | /******************************************************************************/ |
---|
61 | /******************************************************************************/ |
---|
62 | void RecordUseModulesUseModulesVariables() |
---|
63 | { |
---|
64 | listusemodule *tmplistmodule; |
---|
65 | |
---|
66 | /* we should record all variables defined in modules used in this file */ |
---|
67 | if ( listofmodulebysubroutine ) |
---|
68 | { |
---|
69 | /* and we should read the .depend of the module used by the module used */ |
---|
70 | tmplistmodule = listofmodulebysubroutine; |
---|
71 | while ( tmplistmodule ) |
---|
72 | { |
---|
73 | Readthedependlistofmoduleused(tmplistmodule->usemodule); |
---|
74 | while( tmpuselocallist ) |
---|
75 | { |
---|
76 | Addmoduletothelisttmp(tmpuselocallist->usemodule); |
---|
77 | tmpuselocallist = tmpuselocallist->suiv; |
---|
78 | } |
---|
79 | tmplistmodule = tmplistmodule->suiv; |
---|
80 | } |
---|
81 | |
---|
82 | globalvarofusefile2 = (listvar *)NULL; |
---|
83 | tmpparameterlocallist2 = (listparameter *)NULL; |
---|
84 | tmplistmodule = listofmoduletmp; |
---|
85 | while ( tmplistmodule ) |
---|
86 | { |
---|
87 | /* check if the file .depend<usemodule> exist */ |
---|
88 | globalvarofusefile2 = Recordglobalvarofusefile |
---|
89 | (tmplistmodule->usemodule,globalvarofusefile2); |
---|
90 | |
---|
91 | tmpparameterlocallist2 = ReaddependParameterList |
---|
92 | (tmplistmodule->usemodule,tmpparameterlocallist2); |
---|
93 | |
---|
94 | tmplistmodule = tmplistmodule->suiv; |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | /******************************************************************************/ |
---|
101 | /* Addmoduletothelist */ |
---|
102 | /******************************************************************************/ |
---|
103 | /* This subroutine is used to add a record to a list of struct */ |
---|
104 | /* listusemodule */ |
---|
105 | /******************************************************************************/ |
---|
106 | /* */ |
---|
107 | /* subroutine sub ... USE mod1 ===> insert in list */ |
---|
108 | /* _______ _______ _______ _______ _______ */ |
---|
109 | /* + + + + + + + + + + */ |
---|
110 | /* + NEW +--->+ list +--->+ list +--->+ list +--->+ list + */ |
---|
111 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
112 | /* */ |
---|
113 | /* list = listofmodulebysubroutine */ |
---|
114 | /* */ |
---|
115 | /******************************************************************************/ |
---|
116 | void Addmoduletothelist(char *name) |
---|
117 | { |
---|
118 | listusemodule *newmodule; |
---|
119 | listusemodule *parcours; |
---|
120 | int out; |
---|
121 | |
---|
122 | newmodule =(listusemodule *)malloc(sizeof(listusemodule)); |
---|
123 | strcpy(newmodule->usemodule,name); |
---|
124 | strcpy(newmodule->charusemodule,charusemodule); |
---|
125 | strcpy(newmodule->cursubroutine,subroutinename); |
---|
126 | newmodule->firstuse = 1 ; |
---|
127 | newmodule->suiv = NULL; |
---|
128 | |
---|
129 | if ( !listofmodulebysubroutine) |
---|
130 | { |
---|
131 | listofmodulebysubroutine = newmodule ; |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | parcours = listofmodulebysubroutine; |
---|
136 | while ( parcours && newmodule->firstuse == 1 ) |
---|
137 | { |
---|
138 | if ( !strcasecmp(name,parcours->usemodule) ) |
---|
139 | { |
---|
140 | newmodule->firstuse = 0 ; |
---|
141 | } |
---|
142 | parcours=parcours->suiv; |
---|
143 | } |
---|
144 | /* we can not add the same module twice for the same subroutine */ |
---|
145 | parcours = listofmodulebysubroutine; |
---|
146 | out = 0 ; |
---|
147 | while ( parcours && out == 0 ) |
---|
148 | { |
---|
149 | if ( !strcasecmp(name,parcours->usemodule) && |
---|
150 | !strcasecmp(subroutinename,parcours->cursubroutine) |
---|
151 | ) |
---|
152 | { |
---|
153 | out = 1 ; |
---|
154 | free(newmodule); |
---|
155 | } |
---|
156 | else parcours=parcours->suiv; |
---|
157 | } |
---|
158 | if ( out == 0 ) |
---|
159 | { |
---|
160 | newmodule->suiv = listofmodulebysubroutine; |
---|
161 | listofmodulebysubroutine = newmodule; |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | /******************************************************************************/ |
---|
168 | /* WriteUsemoduleDeclaration */ |
---|
169 | /******************************************************************************/ |
---|
170 | /* Firstpass 0 */ |
---|
171 | /******************************************************************************/ |
---|
172 | /* */ |
---|
173 | /******************************************************************************/ |
---|
174 | void WriteUsemoduleDeclaration() |
---|
175 | { |
---|
176 | listusemodule *newmodule; |
---|
177 | |
---|
178 | newmodule = listofmodulebysubroutine; |
---|
179 | fprintf(fortranout,"\n"); |
---|
180 | while ( newmodule ) |
---|
181 | { |
---|
182 | if ( !strcasecmp(newmodule->cursubroutine,subroutinename) ) |
---|
183 | { |
---|
184 | if ( strcasecmp(newmodule->charusemodule,"Agrif_Util") || |
---|
185 | adduseagrifutil != 1 ) fprintf(fortranout," USE %s \n" |
---|
186 | ,newmodule->charusemodule); |
---|
187 | } |
---|
188 | newmodule = newmodule ->suiv; |
---|
189 | } |
---|
190 | } |
---|