NAPA Compiler V4.50
Author: Yves Leduc, yves.leduc.be@gmail.com
Loading...
Searching...
No Matches
C:/Simulate/Napados/Source/dc.c
Go to the documentation of this file.
1/* *** PROCESS DECLARATIONS ***************************************************************************************************** */
2
3#undef EXTERN
4#define EXTERN extern
5
6#include "./napa.h"
7#include "./proto.h"
8
9
10/* *** In this file: ************************************************************************************************************ */
11
12/* void declaration_type_A(void) */
13/* void declaration_type_B(void) */
14
15
16/* ****************************************************************************************************************************** */
17
18/* Processing of list based on instructions 'declare (sometype) ...' */
19/* If <sometype> is not empty, the declaration is processed by 'declaration_type_A()', otherwise by 'declaration_type_B()'. */
20
21/* These functions are prepared to process a constant, as a formal parameter of a cell can be attributed to a number or a string. */
22
23/* Multiple declaration is possible, although consistency is required. Declarations are often essentially inside cells. */
24
26 long in;
27 long k, l, m, n;
28 long t;
29 char *nm1 = (char*) NULL;
30 char *nm2 = (char*) NULL;
31
32 for (in = 0L; in < Num_Declares; in++) { /* used to check consistency, or as hint */
33 t = Declare_List[in].type;
34 k = node_id(Declare_List[in].name);
35 l = var_id(Declare_List[in].name);
36 m = constant_type(Declare_List[in].name);
37 n = update_id(Declare_List[in].name, 1);
38 if ((UNDEFINED == k) && (UNDEFINED == l) && (UNKNOWN_TYPE == m) && (STRING_DATA_TYPE != t)) {
39 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
40 (void) fprintf(STDERR, " node or variable <%s> does not exist\n", Declare_List[in].name);
43 /* process may continue */
44 continue;
45 }
46 if (CONSTANT_TYPE == t) {
47 if (UNDEFINED != n) { /* only one message when aliased */
48 if ((0 == strcmp(Declare_List[in].name, Var_List[l].name1)) || (0 == strcmp(Declare_List[in].name, Var_List[l].name2))) {
49 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
50 (void) fprintf(STDERR, " according to declaration, variable <%s> cannot be updated,\n\n", Var_List[l].name2);
51 if (0 != strcmp(Var_List[l].name1, Var_List[l].name2)) {
52 (void) fprintf(STDERR, " this variable, aliased as <%s>, is updated\n", Var_List[l].name1);
53 } else {
54 (void) fprintf(STDERR, " this variable is updated\n");
55 }
56 print_location(Update_List[n].mline, Update_List[n].mfile);
57 }
58 /* process may continue */
59 continue;
60 }
61 if (UNDEFINED != k) {
62 if ((DC_KIND != Node_List[k].kind) && (CONST_KIND != Node_List[k].kind)) {
63 if ((0 != strcmp(Declare_List[in].name, Node_List[k].name1)) ||
64 (0 != strcmp(Declare_List[in].name, Node_List[k].name2))) { /* only one message when aliased */
65 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
66 (void) fprintf(STDERR, " according to declaration, node <%s> should be a 'dc' or a 'const' node,\n", Node_List[k].name2);
67 if (0 != strcmp(Node_List[k].name1, Node_List[l].name2)) {
68 (void) fprintf(STDERR, " this node, aliased as <%s>, is defined\n\n", Node_List[k].name1);
69 } else {
70 (void) fprintf(STDERR, " this node is defined\n\n");
71 }
72 print_location(Node_List[k].mline, Node_List[k].mfile);
73 }
74 /* process may continue */
75 continue;
76 }
77 }
78 continue;
79 }
80 if (UNDEFINED != k) { /* declaration concerning a node */
81 nm1 = Node_List[k].name1;
82 nm2 = Node_List[k].name2;
83 if (STRING_DATA_TYPE == t) {
84 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
85 if (0 != strcmp(nm1, nm2)) {
86 (void) fprintf(STDERR, " node <%s>, aliased as <%s>, cannot be declared as a string\n", nm2, nm1);
87 } else {
88 (void) fprintf(STDERR, " node <%s> cannot be declared as a string\n", nm2);
89 }
90 /* process may continue */
91 continue;
92 }
93 if ((DIGITAL_DATA_TYPE == t) && (ANALOG_DATA_TYPE == Node_List[k].declare)) {
94 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
95 if (0 != strcmp(nm1, nm2)) {
96 (void) fprintf(STDERR, " node <%s>, aliased as <%s>, was already declared as analog\n", nm2, nm1);
97 } else {
98 (void) fprintf(STDERR, " node <%s> was already declared as analog\n", nm2);
99 }
100 Node_List[k].declare = t;
101 /* process may continue */
102 continue;
103 }
104 if ((ANALOG_DATA_TYPE == t) && (DIGITAL_DATA_TYPE == Node_List[k].declare)) {
105 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
106 if (0 != strcmp(nm1, nm2)) {
107 (void) fprintf(STDERR, " node <%s>, aliased as <%s>, was already declared as digital\n", nm2, nm1);
108 } else {
109 (void) fprintf(STDERR, " node <%s> was already declared as digital\n", nm2);
110 }
111 Node_List[k].declare = t;
112 /* process may continue */
113 continue;
114 }
115 if (CONSTANT_TYPE != t) {
116 Node_List[k].declare = t; /* as a hint or verification for node determination */
117 }
118 continue;
119 }
120 if (UNDEFINED != l) { /* declaration concerning variable, immediate check */
121 nm1 = Var_List[l].name1;
122 nm2 = Var_List[l].name2;
123 if ((DIGITAL_DATA_TYPE == Var_List[l].declare) && (DIGITAL_DATA_TYPE != t)) {
124 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
125 if (0 != strcmp(nm1, nm2)) {
126 (void) fprintf(STDERR, " variable <%s>, aliased as <%s>, was already declared as digital\n", nm2, nm1);
127 } else {
128 (void) fprintf(STDERR, " variable <%s> was already declared as digital\n", nm2);
129 }
130 /* process may continue */
131 continue;
132 }
133 if ((ANALOG_DATA_TYPE == Var_List[l].declare) && (ANALOG_DATA_TYPE != t)) {
134 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
135 if (0 != strcmp(nm1, nm2)) {
136 (void) fprintf(STDERR, " variable <%s>, aliased as <%s>, was already declared as analog\n", nm2, nm1);
137 } else {
138 (void) fprintf(STDERR, " variable <%s> was already declared as analog\n", nm2);
139 }
140 /* process may continue */
141 continue;
142 }
143 if ((STRING_DATA_TYPE == Var_List[l].declare) && (STRING_DATA_TYPE != t)) {
144 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
145 if (0 != strcmp(nm1, nm2)) {
146 (void) fprintf(STDERR, " variable <%s>, aliased as <%s>, was already declared as a string\n", nm2, nm1);
147 } else {
148 (void) fprintf(STDERR, " variable <%s> was already declared as a string\n", nm2);
149 }
150 /* process may continue */
151 continue;
152 }
153 if ((t != Var_List[l].type) && (ANALOG_DATA_TYPE == t)) {
154 print_error_location("declare", Var_List[l].mline, Var_List[l].mfile);
155 if (0 != strcmp(nm1, nm2)) {
156 (void) fprintf(STDERR, " according to a declaration, variable <%s>, aliased as <%s>, must be analog\n", nm2, nm1);
157 } else {
158 (void) fprintf(STDERR, " according to a declaration, variable <%s> must be analog\n", nm2);
159 }
160 Var_List[l].declare = t;
161 /* process may continue */
162 continue;
163 }
164 if ((t != Var_List[l].type) && (DIGITAL_DATA_TYPE == t)) {
165 print_error_location("declare", Var_List[l].mline, Var_List[l].mfile);
166 if (0 != strcmp(nm1, nm2)) {
167 (void) fprintf(STDERR, " according to a declaration, variable <%s>, aliased as <%s>, must be digital\n", nm2, nm1);
168 } else {
169 (void) fprintf(STDERR, " according to a declaration, variable <%s> must be digital\n", nm2);
170 }
171 Var_List[l].declare = t;
172 /* process may continue */
173 continue;
174 }
175 if ((t != Var_List[l].type) && (STRING_DATA_TYPE == t)) {
176 print_error_location("declare", Var_List[l].mline, Var_List[l].mfile);
177 if (0 != strcmp(nm1, nm2)) {
178 (void) fprintf(STDERR, " according to a declaration, variable <%s>, aliased as <%s>, must be a string\n", nm2, nm1);
179 } else {
180 (void) fprintf(STDERR, " according to a declaration, variable <%s> must be a string\n", nm2);
181 }
182 Var_List[l].declare = t;
183 /* process may continue */
184 continue;
185 }
186 if (CONSTANT_TYPE != t) {
187 Var_List[l].declare = t;
188 }
189 continue;
190 }
191 if ((UNKNOWN_TYPE != m) && (CONSTANT_TYPE != t)) { /* declaration concerning constant */
192 nm1 = Declare_List[in].name;
193 if ((t != m) && (ANALOG_DATA_TYPE == t)) {
194 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
195 (void) fprintf(STDERR, " parameter corresponding to declaration #%ld", Declare_List[in].number);
196 (void) fprintf(STDERR, " is not an analog number, (value: <%s>)\n", nm1);
197 /* process may continue */
198 continue;
199 }
200 if ((t != m) && (DIGITAL_DATA_TYPE == t)) {
201 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
202 (void) fprintf(STDERR, " parameter corresponding to declaration #%ld", Declare_List[in].number);
203 (void) fprintf(STDERR, " is not a strict digital number (value: <%s>)\n", nm1);
204 /* process may continue */
205 continue;
206 }
207 if ((t != m) && (STRING_DATA_TYPE == t)) {
208 print_error_location("declare", Declare_List[in].mline, Declare_List[in].mfile);
209 (void) fprintf(STDERR, " parameter corresponding to declaration #%ld", Declare_List[in].number);
210 (void) fprintf(STDERR, " is not a string constant (value: <%s>)\n", nm1);
211 /* process may continue */
212 continue;
213 }
214 }
215 }
216 return;
217}
218
219
220/* Processing of list based on instruction 'declare () ... ' where parameter list is empty. */
221/* This function must be prepared to process a constant as a formal parameter of a cell can */
222/* be attributed to a constant (number or string) */
223
224/* Multiple declaration is possible, although consistency is required. This is very common */
225/* as declarations are located essentially in cells. */
226
228 long in;
229 long k;
230 long t, typ;
231 char sgn[2] = {'\0'};
232 char tok[STRLENGTH] = {'\0'};
233 char *str = (char*) NULL;
234 for (in = 0L; in < Num_Declare_Commons; in++) { /* declaration is used to check consistency */
235 str = Declare_Common_List[in].value;
236 str = get_sign_and_token(str, sgn, tok);
237 typ = get_type(tok);
238 if (UNKNOWN_TYPE == typ) { /* this error is not processed here */
239 continue;
240 }
241 k = node_id(tok);
242 if (UNDEFINED != k) {
243 Node_List[k].declare = typ;
244 }
245 k = var_id(tok);
246 if (UNDEFINED != k) {
247 Var_List[k].declare = typ;
248 }
249 for (;;) {
250 if (ISEMPTY(str)) {
251 break;
252 }
253 str = get_sign_and_token(str, sgn, tok);
254 t = get_type(tok);
255 if (UNKNOWN_TYPE == typ) {
256 continue; /* this error is not processed here */
257 }
258 if (t != typ) {
259 str = Declare_Common_List[in].value;
260 print_error_location("declare", Declare_Common_List[in].mline, Declare_Common_List[in].mfile);
261 str = get_sign_and_token(str, sgn, tok);
262 (void) fprintf(STDERR, " according to a declaration, the types of <%s>", tok);
263 for (;;) {
264 if (ISEMPTY(str)) {
265 break;
266 }
267 str = get_sign_and_token(str, sgn, tok);
268 if (ISEMPTY(str)) {
269 (void) fprintf(STDERR, " and <%s>", tok);
270 } else {
271 (void) fprintf(STDERR, ", <%s>", tok);
272 }
273 }
274 (void) fprintf(STDERR, " must be the same\n");
275 /* process may continue */
276 continue;
277 }
278 k = node_id(tok);
279 if (UNDEFINED != k) {
280 Node_List[k].declare = t;
281 }
282 k = var_id(tok);
283 if (UNDEFINED != k) {
284 Var_List[k].declare = t;
285 }
286 }
287 }
288 return;
289}
290
291
292/* ****************************************************************************************************************************** */
293/* end of file */
void declaration_type_B(void)
Definition dc.c:227
void declaration_type_A(void)
Definition dc.c:25
void print_location(const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:1510
void print_error_location(const char *type, const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:1476
long constant_type(char *identifier)
Definition id.c:1130
long get_type(char *identifier)
Definition id.c:1190
long update_id(const char *identifier, long num)
Definition id.c:807
long node_id(const char *identifier)
Definition id.c:718
long var_id(const char *identifier)
Definition id.c:855
void process_node_error(const char *tok1)
Definition mp.c:259
void process_variable_error(const char *tok1)
Definition mp.c:331
EXTERN VAR_TYPE Var_List[2047L]
Definition napa.h:970
EXTERN DECLARE_COMMON_TYPE Declare_Common_List[255L]
Definition napa.h:954
EXTERN DECLARE_TYPE Declare_List[1023L]
Definition napa.h:953
#define UNKNOWN_TYPE
Definition napa.h:332
#define UNDEFINED
Definition napa.h:331
#define STDERR
Definition napa.h:105
EXTERN NODE_TYPE Node_List[4095L]
Definition napa.h:962
#define CONST_KIND
Definition napa.h:246
#define CONSTANT_TYPE
Definition napa.h:344
#define ANALOG_DATA_TYPE
Definition napa.h:338
EXTERN long Num_Declares
Definition napa.h:810
#define DC_KIND
Definition napa.h:252
#define STRLENGTH
Definition napa.h:217
#define ISEMPTY(s)
Definition napa.h:394
#define STRING_DATA_TYPE
Definition napa.h:339
EXTERN long Num_Declare_Commons
Definition napa.h:806
#define DIGITAL_DATA_TYPE
Definition napa.h:337
EXTERN UPDATE_TYPE Update_List[2047L]
Definition napa.h:968
char * get_sign_and_token(char *str, char *sgn, char *tok)
Definition tk.c:1188