1 /* -*- tab-width: 4 -*-
2 *
3 * Electric(tm) VLSI Design System
4 *
5 * File: vhdlexpr.c
6 * Expressions handling for the VHDL front-end compiler
7 * Written by: Andrew R. Kostiuk, Queen's University
8 * Modified by: Steven M. Rubin, Static Free Software
9 *
10 * Copyright (c) 2000 Static Free Software.
11 *
12 * Electric(tm) is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * Electric(tm) is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with Electric(tm); see the file COPYING. If not, write to
24 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
25 * Boston, Mass 02111-1307, USA.
26 *
27 * Static Free Software
28 * 4119 Alpine Road
29 * Portola Valley, California 94028
30 * info@staticfreesoft.com
31 */
32
33 #include "config.h"
34 #if VHDLTOOL
35
36 #include "global.h"
37 #include "vhdl.h"
38 #include <math.h>
39
40 extern TOKENLIST *vhdl_nexttoken;
41 extern SYMBOLLIST *vhdl_symbols;
42
43 /* prototypes for local routines */
44 static MRELATIONS *vhdl_parsemorerelations(INTBIG, INTBIG);
45 static RELATION *vhdl_parserelation(void);
46 static TERM *vhdl_parseterm(void);
47 static MTERMS *vhdl_parsemoreterms(void);
48 static FACTOR *vhdl_parsefactor(void);
49 static MFACTORS *vhdl_parsemorefactors(void);
50 static PRIMARY *vhdl_parseprimary(void);
51 static LITERAL *vhdl_parseliteral(void);
52 static INTBIG vhdl_parsedecimal(void);
53 static INTBIG vhdl_evalrelation(RELATION*);
54 static INTBIG vhdl_evalterm(TERM*);
55 static INTBIG vhdl_evalfactor(FACTOR*);
56 static INTBIG vhdl_evalprimary(PRIMARY*);
57 static INTBIG vhdl_evalname(VNAME*);
58 static BOOLEAN vhdl_indiscreterange(INTBIG, DBDISCRETERANGE*);
59 static SINGLENAME *vhdl_parsesinglename(void);
60 static INDEXEDNAME *vhdl_parseindexedname(INTBIG, CHAR*);
61 static DBNAME *vhdl_semsinglename(SINGLENAME*);
62 static DBNAME *vhdl_semconcatenatedname(CONCATENATEDNAME*);
63 static DBNAME *vhdl_semindexedname(INDEXEDNAME*);
64
65 /*
66 Module: vhdl_parseexpression
67 ------------------------------------------------------------------------
68 Description:
69 Parse an expression of the form:
70
71 expression ::=
72 relation {AND relation}
73 | relation {OR relation}
74 | relation {NAND relation}
75 | relation {NOR relation}
76 | relation {XOR relation}
77 ------------------------------------------------------------------------
78 Calling Sequence: exp = vhdl_parseexpression();
79
80 Name Type Description
81 ---- ---- -----------
82 exp *EXPRESSION Returned expression structure.
83 ------------------------------------------------------------------------
84 */
vhdl_parseexpression(void)85 EXPRESSION *vhdl_parseexpression(void)
86 {
87 EXPRESSION *exp;
88 INTBIG key, logop;
89
90 exp = (EXPRESSION *)emalloc((INTBIG)sizeof(EXPRESSION), vhdl_tool->cluster);
91 exp->relation = vhdl_parserelation();
92 exp->next = 0;
93
94 /* check for more terms */
95 logop = NOLOGOP;
96 if (vhdl_nexttoken->token == TOKEN_KEYWORD)
97 {
98 key = ((VKEYWORD *)(vhdl_nexttoken->pointer))->num;
99 switch (key = ((VKEYWORD *)(vhdl_nexttoken->pointer))->num)
100 {
101 case KEY_AND:
102 logop = LOGOP_AND;
103 break;
104 case KEY_OR:
105 logop = LOGOP_OR;
106 break;
107 case KEY_NAND:
108 logop = LOGOP_NAND;
109 break;
110 case KEY_NOR:
111 logop = LOGOP_NOR;
112 break;
113 case KEY_XOR:
114 logop = LOGOP_XOR;
115 break;
116 default:
117 break;
118 }
119 }
120
121 if (logop != NOLOGOP)
122 {
123 exp->next = vhdl_parsemorerelations((INTBIG)key, (INTBIG)logop);
124 }
125
126 return(exp);
127 }
128
129 /*
130 Module: vhdl_parsemorerelations
131 ------------------------------------------------------------------------
132 Description:
133 Parse more relations of an expression of the form:
134
135 AND | OR | NAND | NOR | XOR relation
136 ------------------------------------------------------------------------
137 Calling Sequence: more = vhdl_parsemorerelations(keyop, logop);
138
139 Name Type Description
140 ---- ---- -----------
141 keyop INTBIG Key of logical operator.
142 logop INTBIG Logical operator.
143 more *MRELATIONS Returned pointer to more relations,
144 0 if no more.
145
146 Note: The logical operator must be the same throughout.
147 ------------------------------------------------------------------------
148 */
vhdl_parsemorerelations(INTBIG key,INTBIG logop)149 MRELATIONS *vhdl_parsemorerelations(INTBIG key, INTBIG logop)
150 {
151 MRELATIONS *more;
152
153 more = 0;
154
155 if (vhdl_keysame(vhdl_nexttoken, key))
156 {
157 vhdl_getnexttoken();
158 more = (MRELATIONS *)emalloc((INTBIG)sizeof(MRELATIONS), vhdl_tool->cluster);
159 more->log_operator = logop;
160 more->relation = vhdl_parserelation();
161 more->next = vhdl_parsemorerelations(key, logop);
162 }
163 return(more);
164 }
165
166 /*
167 Module: vhdl_parserelation
168 ------------------------------------------------------------------------
169 Description:
170 Parse a relation of the form:
171
172 relation ::=
173 simple_expression [relational_operator simple_expression]
174
175 relational_operator ::=
176 = | /= | < | <= | > | >=
177 ------------------------------------------------------------------------
178 Calling Sequence: relation = vhdl_parserelation();
179
180 Name Type Description
181 ---- ---- -----------
182 relation *RELATION Pointer to returned relation structure.
183 ------------------------------------------------------------------------
184 */
vhdl_parserelation(void)185 RELATION *vhdl_parserelation(void)
186 {
187 RELATION *relation;
188 INTBIG relop;
189
190 relop = NORELOP;
191 relation = (RELATION *)emalloc((INTBIG)sizeof(RELATION), vhdl_tool->cluster);
192 relation->simple_expr = vhdl_parsesimpleexpression();
193 relation->rel_operator = NORELOP;
194 relation->simple_expr2 = 0;
195
196 switch (vhdl_nexttoken->token)
197 {
198 case TOKEN_EQ:
199 relop = RELOP_EQ;
200 break;
201 case TOKEN_NE:
202 relop = RELOP_NE;
203 break;
204 case TOKEN_LT:
205 relop = RELOP_LT;
206 break;
207 case TOKEN_LE:
208 relop = RELOP_LE;
209 break;
210 case TOKEN_GT:
211 relop = RELOP_GT;
212 break;
213 case TOKEN_GE:
214 relop = RELOP_GE;
215 break;
216 default:
217 break;
218 }
219
220 if (relop != NORELOP)
221 {
222 relation->rel_operator = relop;
223 vhdl_getnexttoken();
224 relation->simple_expr2 = vhdl_parsesimpleexpression();
225 }
226
227 return(relation);
228 }
229
230 /*
231 Module: vhdl_parsesimpleexpression
232 ------------------------------------------------------------------------
233 Description:
234 Parse a simple expression of the form:
235
236 simple_expression ::=
237 [sign] term {adding_operator term}
238 ------------------------------------------------------------------------
239 Calling Sequence: exp = vhdl_parsesimpleexpression();
240
241 Name Type Description
242 ---- ---- -----------
243 exp *SIMPLEEXPR Returned simple expression structure.
244 ------------------------------------------------------------------------
245 */
vhdl_parsesimpleexpression(void)246 SIMPLEEXPR *vhdl_parsesimpleexpression(void)
247 {
248 SIMPLEEXPR *exp;
249
250 exp = (SIMPLEEXPR *)emalloc((INTBIG)sizeof(SIMPLEEXPR), vhdl_tool->cluster);
251
252 /* check for optional sign */
253 if (vhdl_nexttoken->token == TOKEN_PLUS)
254 {
255 exp->sign = 1;
256 vhdl_getnexttoken();
257 } else if (vhdl_nexttoken->token == TOKEN_MINUS)
258 {
259 exp->sign = -1;
260 vhdl_getnexttoken();
261 } else
262 {
263 exp->sign = 1; /* default sign */
264 }
265
266 /* next is a term */
267 exp->term = vhdl_parseterm();
268
269 /* check for more terms */
270 exp->next = vhdl_parsemoreterms();
271
272 return(exp);
273 }
274
275 /*
276 Module: vhdl_parseterm
277 ------------------------------------------------------------------------
278 Description:
279 Parse a term of the form:
280
281 term ::=
282 factor {multiplying_operator factor}
283 ------------------------------------------------------------------------
284 Calling Sequence: term = vhdl_parseterm();
285
286 Name Type Description
287 ---- ---- -----------
288 term *TERM Returned term structure.
289 ------------------------------------------------------------------------
290 */
vhdl_parseterm(void)291 TERM *vhdl_parseterm(void)
292 {
293 TERM *term;
294
295 term = (TERM *)emalloc((INTBIG)sizeof(TERM), vhdl_tool->cluster);
296 term->factor = vhdl_parsefactor();
297 term->next = vhdl_parsemorefactors();
298 return(term);
299 }
300
301 /*
302 Module: vhdl_parsemoreterms
303 ------------------------------------------------------------------------
304 Description:
305 Parse more terms of a simple expression of the form:
306
307 adding_operator term
308 ------------------------------------------------------------------------
309 Calling Sequence: more = vhdl_parsemoreterms();
310
311 Name Type Description
312 ---- ---- -----------
313 more *MTERMS Returned pointer to more terms,
314 0 if no more.
315 ------------------------------------------------------------------------
316 */
vhdl_parsemoreterms(void)317 MTERMS *vhdl_parsemoreterms(void)
318 {
319 MTERMS *more;
320 INTBIG addop;
321
322 more = 0;
323 addop = NOADDOP;
324 if (vhdl_nexttoken->token == TOKEN_PLUS)
325 {
326 addop = ADDOP_ADD;
327 } else if (vhdl_nexttoken->token == TOKEN_MINUS)
328 {
329 addop = ADDOP_SUBTRACT;
330 }
331 if (addop != NOADDOP)
332 {
333 vhdl_getnexttoken();
334 more = (MTERMS *)emalloc((INTBIG)sizeof(MTERMS), vhdl_tool->cluster);
335 more->add_operator = addop;
336 more->term = vhdl_parseterm();
337 more->next = vhdl_parsemoreterms();
338 }
339 return(more);
340 }
341
342 /*
343 Module: vhdl_parsefactor
344 ------------------------------------------------------------------------
345 Description:
346 Parse a factor of the form:
347
348 factor :==
349 primary [** primary]
350 | ABS primary
351 | NOT primary
352 ------------------------------------------------------------------------
353 Calling Sequence: factor = vhdl_parsefactor();
354
355 Name Type Description
356 ---- ---- -----------
357 factor *FACTOR Returned factor structure.
358 ------------------------------------------------------------------------
359 */
vhdl_parsefactor(void)360 FACTOR *vhdl_parsefactor(void)
361 {
362 FACTOR *factor;
363 INTBIG miscop;
364 PRIMARY *primary, *primary2;
365
366 factor = 0;
367 primary = primary2 = 0;
368 miscop = NOMISCOP;
369 if (vhdl_keysame(vhdl_nexttoken, KEY_ABS))
370 {
371 miscop = MISCOP_ABS;
372 vhdl_getnexttoken();
373 primary = vhdl_parseprimary();
374 } else if (vhdl_keysame(vhdl_nexttoken, KEY_NOT))
375 {
376 miscop = MISCOP_NOT;
377 vhdl_getnexttoken();
378 primary = vhdl_parseprimary();
379 } else
380 {
381 primary = vhdl_parseprimary();
382 if (vhdl_nexttoken->token == TOKEN_DOUBLESTAR)
383 {
384 miscop = MISCOP_POWER;
385 vhdl_getnexttoken();
386 primary2 = vhdl_parseprimary();
387 }
388 }
389 factor = (FACTOR *)emalloc((INTBIG)sizeof(FACTOR), vhdl_tool->cluster);
390 factor->primary = primary;
391 factor->misc_operator = miscop;
392 factor->primary2 = primary2;
393 return(factor);
394 }
395
396 /*
397 Module: vhdl_parsemorefactors
398 ------------------------------------------------------------------------
399 Description:
400 Parse more factors of a term of the form:
401
402 multiplying_operator factor
403 ------------------------------------------------------------------------
404 Calling Sequence: more = vhdl_parsemorefactors();
405
406 Name Type Description
407 ---- ---- -----------
408 more *MFACTORS Returned pointer to more factors,
409 0 if no more.
410 ------------------------------------------------------------------------
411 */
vhdl_parsemorefactors(void)412 MFACTORS *vhdl_parsemorefactors(void)
413 {
414 MFACTORS *more;
415 INTBIG mulop;
416
417 more = 0;
418 mulop = NOMULOP;
419 if (vhdl_nexttoken->token == TOKEN_STAR)
420 {
421 mulop = MULOP_MULTIPLY;
422 } else if (vhdl_nexttoken->token == TOKEN_SLASH)
423 {
424 mulop = MULOP_DIVIDE;
425 } else if (vhdl_keysame(vhdl_nexttoken, KEY_MOD))
426 {
427 mulop = MULOP_MOD;
428 } else if (vhdl_keysame(vhdl_nexttoken, KEY_REM))
429 {
430 mulop = MULOP_REM;
431 }
432 if (mulop != NOMULOP)
433 {
434 vhdl_getnexttoken();
435 more = (MFACTORS *)emalloc((INTBIG)sizeof(MFACTORS), vhdl_tool->cluster);
436 more->mul_operator = mulop;
437 more->factor = vhdl_parsefactor();
438 more->next = vhdl_parsemorefactors();
439 }
440 return(more);
441 }
442
443 /*
444 Module: vhdl_parseprimary
445 ------------------------------------------------------------------------
446 Description:
447 Parse a primary of the form:
448
449 primary ::=
450 name
451 | literal
452 | aggregate
453 | concatenation
454 | function_call
455 | type_conversion
456 | qualified_expression
457 | (expression)
458 ------------------------------------------------------------------------
459 Calling Sequence: primary = vhdl_parseprimary();
460
461 Name Type Description
462 ---- ---- -----------
463 primary *PRIMARY Returned primary structure.
464 ------------------------------------------------------------------------
465 */
vhdl_parseprimary(void)466 PRIMARY *vhdl_parseprimary(void)
467 {
468 PRIMARY *primary;
469 INTBIG type;
470 CHAR *pointer;
471
472 type = NOPRIMARY;
473 primary = 0;
474 switch (vhdl_nexttoken->token)
475 {
476 case TOKEN_DECIMAL:
477 case TOKEN_BASED:
478 case TOKEN_STRING:
479 case TOKEN_BIT_STRING:
480 type = PRIMARY_LITERAL;
481 pointer = (CHAR *)vhdl_parseliteral();
482 break;
483 case TOKEN_IDENTIFIER:
484 type = PRIMARY_NAME;
485 pointer = (CHAR *)vhdl_parsename();
486 break;
487 case TOKEN_LEFTBRACKET:
488 /* should be an expression in brackets */
489 vhdl_getnexttoken();
490 type = PRIMARY_EXPRESSION;
491 pointer = (CHAR *)vhdl_parseexpression();
492
493 /* should be at right bracket */
494 if (vhdl_nexttoken->token != TOKEN_RIGHTBRACKET)
495 {
496 vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting a right bracket"));
497 }
498 vhdl_getnexttoken();
499 break;
500 default:
501 break;
502 }
503 if (type != NOPRIMARY)
504 {
505 primary = (PRIMARY *)emalloc((INTBIG)sizeof(PRIMARY), vhdl_tool->cluster);
506 primary->type = type;
507 primary->pointer = pointer;
508 }
509 return(primary);
510 }
511
512 /*
513 Module: vhdl_parseliteral
514 ------------------------------------------------------------------------
515 Description:
516 Parse a literal of the form:
517
518 literal ::=
519 numeric_literal
520 | enumeration_literal
521 | string_literal
522 | bit_string_literal
523 ------------------------------------------------------------------------
524 Calling Sequence: literal = vhdl_parseliteral();
525
526 Name Type Description
527 ---- ---- -----------
528 literal *LITERAL Pointer to returned literal structure.
529 ------------------------------------------------------------------------
530 */
vhdl_parseliteral(void)531 LITERAL *vhdl_parseliteral(void)
532 {
533 LITERAL *literal;
534 INTBIG type;
535 CHAR *pointer;
536
537 literal = 0;
538 type = NOLITERAL;
539 switch(vhdl_nexttoken->token)
540 {
541 case TOKEN_DECIMAL:
542 type = LITERAL_NUMERIC;
543 pointer = (CHAR *)vhdl_parsedecimal();
544 break;
545 case TOKEN_BASED:
546 /* type = LITERAL_NUMERIC;
547 pointer = vhdl_parsebased(); */
548 break;
549 case TOKEN_STRING:
550 break;
551 case TOKEN_BIT_STRING:
552 break;
553 default:
554 break;
555 }
556 if (type != NOLITERAL)
557 {
558 literal = (LITERAL *)emalloc((INTBIG)sizeof(LITERAL), vhdl_tool->cluster);
559 literal->type = type;
560 literal->pointer = pointer;
561 }
562 return(literal);
563 }
564
565 /*
566 Module: vhdl_parsedecimal
567 ------------------------------------------------------------------------
568 Description:
569 Parse a decimal literal of the form:
570
571 decimal_literal ::= integer [.integer] [exponent]
572
573 integer ::= digit {[underline] digit}
574 exponent ::= E [+] integer | E - integer
575
576 Note: Currently only integer supported.
577 ------------------------------------------------------------------------
578 Calling Sequence: value = vhdl_parsedecimal();
579
580 Name Type Description
581 ---- ---- -----------
582 value INTBIG Value of decimal literal.
583 ------------------------------------------------------------------------
584 */
vhdl_parsedecimal(void)585 INTBIG vhdl_parsedecimal(void)
586 {
587 INTBIG value;
588
589 value = 0;
590 /* only supports integers */
591 value = (INTBIG)eatoi(vhdl_nexttoken->pointer);
592 vhdl_getnexttoken();
593 return(value);
594 }
595
596 /*
597 Module: vhdl_evalexpression
598 ------------------------------------------------------------------------
599 Description:
600 Return the value of an expression.
601 ------------------------------------------------------------------------
602 Calling Sequence: value = vhdl_evalexpression(expr);
603
604 Name Type Description
605 ---- ---- -----------
606 expr *EPRESSION Pointer to expression structure.
607 value INTBIG Returned value.
608 ------------------------------------------------------------------------
609 */
vhdl_evalexpression(EXPRESSION * expr)610 INTBIG vhdl_evalexpression(EXPRESSION *expr)
611 {
612 INTBIG value, value2;
613 MRELATIONS *more;
614
615 if (expr == 0) return(0);
616 value = vhdl_evalrelation(expr->relation);
617 if (expr->next)
618 {
619 if (value) value = 1;
620 }
621 for (more = expr->next; more != 0; more = more->next)
622 {
623 value2 = vhdl_evalrelation(more->relation);
624 if (value2) value2 = 1;
625 switch (more->log_operator)
626 {
627 case LOGOP_AND:
628 value &= value2;
629 break;
630 case LOGOP_OR:
631 value |= value2;
632 break;
633 case LOGOP_NAND:
634 value = !(value & value2);
635 break;
636 case LOGOP_NOR:
637 value = !(value | value2);
638 break;
639 case LOGOP_XOR:
640 value ^= value2;
641 break;
642 default:
643 break;
644 }
645 }
646 return(value);
647 }
648
649 /*
650 Module: vhdl_evalrelation
651 ------------------------------------------------------------------------
652 Description:
653 Evaluate a relation.
654 ------------------------------------------------------------------------
655 Calling Sequence: value = vhdl_evalrelation(relation);
656
657 Name Type Description
658 ---- ---- -----------
659 relation *RELATION Pointer to relation structure.
660 value INTBIG Returned evaluated value.
661 ------------------------------------------------------------------------
662 */
vhdl_evalrelation(RELATION * relation)663 INTBIG vhdl_evalrelation(RELATION *relation)
664 {
665 INTBIG value, value2;
666
667 if (relation == 0) return(0);
668 value = vhdl_evalsimpleexpr(relation->simple_expr);
669 if (relation->rel_operator != NORELOP)
670 {
671 value2 = vhdl_evalsimpleexpr(relation->simple_expr2);
672 switch (relation->rel_operator)
673 {
674 case RELOP_EQ:
675 if (value == value2) value = TRUE; else
676 value = FALSE;
677 break;
678 case RELOP_NE:
679 if (value != value2) value = TRUE; else
680 value = FALSE;
681 break;
682 case RELOP_LT:
683 if (value < value2) value = TRUE; else
684 value = FALSE;
685 break;
686 case RELOP_LE:
687 if (value <= value2) value = TRUE; else
688 value = FALSE;
689 break;
690 case RELOP_GT:
691 if (value > value2) value = TRUE; else
692 value = FALSE;
693 break;
694 case RELOP_GE:
695 if (value >= value2) value = TRUE; else
696 value = FALSE;
697 break;
698 default:
699 break;
700 }
701 }
702 return(value);
703 }
704
705 /*
706 Module: vhdl_evalsimpleexpr
707 ------------------------------------------------------------------------
708 Description:
709 Return the value of a simple expression.
710 ------------------------------------------------------------------------
711 Calling Sequence: value = vhdl_evalsimpleexpr(expr);
712
713 Name Type Description
714 ---- ---- -----------
715 expr *SIMPLEEXPR Pointer to a simple expression.
716 value INTBIG Returned value.
717 ------------------------------------------------------------------------
718 */
vhdl_evalsimpleexpr(SIMPLEEXPR * expr)719 INTBIG vhdl_evalsimpleexpr(SIMPLEEXPR *expr)
720 {
721 INTBIG value, value2;
722 MTERMS *more;
723
724 if (expr == 0) return(0);
725 value = vhdl_evalterm(expr->term) * expr->sign;
726 for (more = expr->next; more != 0; more = more->next)
727 {
728 value2 = vhdl_evalterm(more->term);
729 switch (more->add_operator)
730 {
731 case ADDOP_ADD:
732 value += value2;
733 break;
734 case ADDOP_SUBTRACT:
735 value -= value2;
736 break;
737 default:
738 break;
739 }
740 }
741 return(value);
742 }
743
744 /*
745 Module: vhdl_evalterm
746 ------------------------------------------------------------------------
747 Description:
748 Return the value of a term.
749 ------------------------------------------------------------------------
750 Calling Sequence: value = vhdl_evalterm(term);
751
752 Name Type Description
753 ---- ---- -----------
754 term *TERM Pointer to a term.
755 value INTBIG Returned value.
756 ------------------------------------------------------------------------
757 */
vhdl_evalterm(TERM * term)758 INTBIG vhdl_evalterm(TERM *term)
759 {
760 INTBIG value, value2;
761 MFACTORS *more;
762
763 if (term == 0) return(0);
764 value = vhdl_evalfactor(term->factor);
765 for (more = term->next; more != 0; more = more->next)
766 {
767 value2 = vhdl_evalfactor(more->factor);
768 switch (more->mul_operator)
769 {
770 case MULOP_MULTIPLY:
771 value *= value2;
772 break;
773 case MULOP_DIVIDE:
774 value /= value2;
775 break;
776 case MULOP_MOD:
777 value %= value2;
778 break;
779 case MULOP_REM:
780 value -= (INTBIG)(value / value2) * value2;
781 break;
782 default:
783 break;
784 }
785 }
786 return(value);
787 }
788
789 /*
790 Module: vhdl_evalfactor
791 ------------------------------------------------------------------------
792 Description:
793 Return the value of a factor.
794 ------------------------------------------------------------------------
795 Calling Sequence: value = vhdl_evalfactor(factor);
796
797 Name Type Description
798 ---- ---- -----------
799 factor *FACTOR Pointer to a factor.
800 value INTBIG Returned value.
801 ------------------------------------------------------------------------
802 */
vhdl_evalfactor(FACTOR * factor)803 INTBIG vhdl_evalfactor(FACTOR *factor)
804 {
805 INTBIG value, value2;
806
807 if (factor == 0) return(0);
808 value = vhdl_evalprimary(factor->primary);
809 switch (factor->misc_operator)
810 {
811 case MISCOP_POWER:
812 value2 = vhdl_evalprimary(factor->primary2);
813 while (value2--)
814 {
815 value += value;
816 }
817 break;
818 case MISCOP_ABS:
819 value = abs(value);
820 break;
821 case MISCOP_NOT:
822 if (value) value = 0; else
823 value = 1;
824 break;
825 default:
826 break;
827 }
828 return(value);
829 }
830
831 /*
832 Module: vhdl_evalprimary
833 ------------------------------------------------------------------------
834 Description:
835 Evaluate the value of a primary and return.
836 ------------------------------------------------------------------------
837 Calling Sequence: value = vhdl_evalprimary(primary);
838
839 Name Type Description
840 ---- ---- -----------
841 primary *PRIMARY Pointer to primary structure.
842 value INTBIG Returned evaluated value.
843 ------------------------------------------------------------------------
844 */
vhdl_evalprimary(PRIMARY * primary)845 INTBIG vhdl_evalprimary(PRIMARY *primary)
846 {
847 INTBIG value;
848 LITERAL *literal;
849
850 if (primary == 0) return(0);
851 value = 0;
852 switch (primary->type)
853 {
854 case PRIMARY_LITERAL:
855 if ((literal = (LITERAL *)primary->pointer) == 0) break;
856 switch (literal->type)
857 {
858 case LITERAL_NUMERIC:
859 value = (INTBIG)literal->pointer;
860 break;
861 case LITERAL_ENUMERATION:
862 case LITERAL_STRING:
863 case LITERAL_BIT_STRING:
864 default:
865 break;
866 }
867 break;
868 case PRIMARY_NAME:
869 value = vhdl_evalname((VNAME *)primary->pointer);
870 break;
871 case PRIMARY_EXPRESSION:
872 value = vhdl_evalexpression((EXPRESSION *)primary->pointer);
873 break;
874 case PRIMARY_AGGREGATE:
875 case PRIMARY_CONCATENATION:
876 case PRIMARY_FUNCTION_CALL:
877 case PRIMARY_TYPE_CONVERSION:
878 case PRIMARY_QUALIFIED_EXPR:
879 default:
880 break;
881 }
882 return(value);
883 }
884
885 /*
886 Module: vhdl_evalname
887 ------------------------------------------------------------------------
888 Description:
889 Evaluate and return the value of a name.
890 ------------------------------------------------------------------------
891 Calling Sequence: value = vhdl_evalname(name);
892
893 Name Type Description
894 ---- ---- -----------
895 name *VNAME Pointer to name.
896 value INTBIG Returned value, 0 if no value.
897 ------------------------------------------------------------------------
898 */
vhdl_evalname(VNAME * name)899 INTBIG vhdl_evalname(VNAME *name)
900 {
901 INTBIG value;
902 SYMBOLTREE *symbol;
903
904 if (name == 0) return(0);
905 value = 0;
906 if ((symbol = vhdl_searchsymbol(vhdl_getnameident(name), vhdl_symbols)) == 0)
907 {
908 vhdl_reporterrormsg(vhdl_getnametoken(name), _("Symbol is undefined"));
909 return(value);
910 }
911 if (symbol->type == SYMBOL_VARIABLE)
912 {
913 value = (INTBIG)symbol->pointer;
914 } else if (symbol->type == SYMBOL_CONSTANT)
915 {
916 value = (INTBIG)symbol->pointer;
917 } else
918 {
919 vhdl_reporterrormsg(vhdl_getnametoken(name), _("Cannot evaluate value of symbol"));
920 return(value);
921 }
922 return(value);
923 }
924
925 /*
926 Module: vhdl_indiscreterange
927 ------------------------------------------------------------------------
928 Description:
929 Return TRUE if value is in discrete range, else return FALSE.
930 ------------------------------------------------------------------------
931 Calling Sequence: in_range = vhdl_indiscreterange(value, discrete);
932
933 Name Type Description
934 ---- ---- -----------
935 value INTBIG Value to be checked.
936 discrete *DBDISCRETERANGE Pointer to db discrete range structure.
937 in_range INTBIG Returned value, TRUE if value in
938 discrete range, else FALSE.
939 ------------------------------------------------------------------------
940 */
vhdl_indiscreterange(INTBIG value,DBDISCRETERANGE * discrete)941 BOOLEAN vhdl_indiscreterange(INTBIG value, DBDISCRETERANGE *discrete)
942 {
943 BOOLEAN in_range;
944 INTBIG start, end, temp;
945
946 in_range = FALSE;
947 if (discrete == 0)
948 return(in_range);
949 start = discrete->start;
950 end = discrete->end;
951 if (start > end)
952 {
953 temp = end;
954 end = start;
955 start = temp;
956 }
957 if (value >= start && value <= end)
958 in_range = TRUE;
959 return(in_range);
960 }
961
962 /******************** this used to be the file "names.c" ********************/
963
964 /*
965 Module: vhdl_parsename
966 ------------------------------------------------------------------------
967 Description:
968 Parse a name. The form of a name is:
969
970 name :==
971 single_name
972 | concatenated_name
973 | attribute_name
974 ------------------------------------------------------------------------
975 Calling Sequence: name = vhdl_parsename();
976
977 Name Type Description
978 ---- ---- -----------
979 name *VNAME Pointer to name parse tree.
980 ------------------------------------------------------------------------
981 */
vhdl_parsename(void)982 VNAME *vhdl_parsename(void)
983 {
984 VNAME *name;
985 INTBIG type;
986 CHAR *pointer, *pointer2;
987 CONCATENATEDNAME *concat, *concat2;
988
989 name = NULL;
990 type = NONAME;
991 pointer = (CHAR *)vhdl_parsesinglename();
992
993 switch (vhdl_nexttoken->token)
994 {
995 case TOKEN_AMPERSAND:
996 type = NAME_CONCATENATE;
997 concat = (CONCATENATEDNAME *)emalloc((INTBIG)sizeof(CONCATENATEDNAME), vhdl_tool->cluster);
998 concat->name = (SINGLENAME *)pointer;
999 concat->next = NULL;
1000 pointer = (CHAR *)concat;
1001 while (vhdl_nexttoken->token == TOKEN_AMPERSAND)
1002 {
1003 vhdl_getnexttoken();
1004 pointer2 = (CHAR *)vhdl_parsesinglename();
1005 concat2 = (CONCATENATEDNAME *)emalloc((INTBIG)sizeof(CONCATENATEDNAME), vhdl_tool->cluster);
1006 concat->next = concat2;
1007 concat2->name = (SINGLENAME *)pointer2;
1008 concat2->next = NULL;
1009 concat = concat2;
1010 }
1011 break;
1012 case TOKEN_APOSTROPHE:
1013 break;
1014 default:
1015 type = NAME_SINGLE;
1016 break;
1017 }
1018
1019 if (type != NONAME)
1020 {
1021 name = (VNAME *)emalloc((INTBIG)sizeof(VNAME), vhdl_tool->cluster);
1022 name->type = type;
1023 name->pointer = pointer;
1024 } else
1025 {
1026 vhdl_getnexttoken();
1027 }
1028 return(name);
1029 }
1030
1031 /*
1032 Module: vhdl_parsesinglename
1033 ------------------------------------------------------------------------
1034 Description:
1035 Parse a single name. Single names are of the form:
1036
1037 single_name :==
1038 simple_name
1039 | selected_name
1040 | indexed_name
1041 | slice_name
1042 ------------------------------------------------------------------------
1043 Calling Sequence: sname = vhdl_parsesinglename();
1044
1045 Name Type Description
1046 ---- ---- -----------
1047 sname *SINGLENAME Pointer to single name structure.
1048 ------------------------------------------------------------------------
1049 */
vhdl_parsesinglename(void)1050 SINGLENAME *vhdl_parsesinglename(void)
1051 {
1052 SINGLENAME *sname, *sname2;
1053 INTBIG type;
1054 CHAR *pointer;
1055 VNAME *nptr;
1056
1057 type = NOSINGLENAME;
1058 sname = NULL;
1059 pointer = (CHAR *)vhdl_parsesimplename();
1060
1061 if (vhdl_nexttoken->last->space)
1062 {
1063 type = SINGLENAME_SIMPLE;
1064 } else
1065 {
1066 switch (vhdl_nexttoken->token)
1067 {
1068 case TOKEN_PERIOD:
1069 break;
1070 case TOKEN_LEFTBRACKET:
1071 /* could be a indexed_name or a slice_name */
1072 /* but support only indexed names */
1073 vhdl_getnexttoken();
1074 type = SINGLENAME_INDEXED;
1075 nptr = (VNAME *)emalloc((INTBIG)sizeof(VNAME), vhdl_tool->cluster);
1076 nptr->type = NAME_SINGLE;
1077 sname2 = (SINGLENAME *)emalloc((INTBIG)sizeof(SINGLENAME), vhdl_tool->cluster);
1078 nptr->pointer = (CHAR *)sname2;
1079 sname2->type = SINGLENAME_SIMPLE;
1080 sname2->pointer = pointer;
1081 pointer = (CHAR *)vhdl_parseindexedname((INTBIG)PREFIX_NAME, (CHAR *)nptr);
1082 /* should be at right bracket */
1083 if (vhdl_nexttoken->token != TOKEN_RIGHTBRACKET)
1084 {
1085 vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting a right bracket"));
1086 }
1087 vhdl_getnexttoken();
1088 break;
1089 default:
1090 type = SINGLENAME_SIMPLE;
1091 break;
1092 }
1093 }
1094
1095 if (type != NOSINGLENAME)
1096 {
1097 sname = (SINGLENAME *)emalloc((INTBIG)sizeof(SINGLENAME), vhdl_tool->cluster);
1098 sname->type = type;
1099 sname->pointer = pointer;
1100 } else
1101 {
1102 vhdl_getnexttoken();
1103 }
1104 return(sname);
1105 }
1106
1107 /*
1108 Module: vhdl_parsesimplename
1109 ------------------------------------------------------------------------
1110 Description:
1111 Parse a simple name of the form:
1112
1113 simple_name ::= identifier
1114 ------------------------------------------------------------------------
1115 Calling Sequence: sname = vhdl_parsesimplename();
1116
1117 Name Type Description
1118 ---- ---- -----------
1119 sname *SIMPLENAME Pointer to simple name structure.
1120 ------------------------------------------------------------------------
1121 */
vhdl_parsesimplename(void)1122 SIMPLENAME *vhdl_parsesimplename(void)
1123 {
1124 SIMPLENAME *sname;
1125
1126 sname = NULL;
1127 if (vhdl_nexttoken->token != TOKEN_IDENTIFIER)
1128 {
1129 vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting an identifier"));
1130 vhdl_getnexttoken();
1131 return(sname);
1132 }
1133 sname = (SIMPLENAME *)emalloc((INTBIG)sizeof(SIMPLENAME), vhdl_tool->cluster);
1134 sname->identifier = vhdl_nexttoken;
1135 vhdl_getnexttoken();
1136 return(sname);
1137 }
1138
1139 /*
1140 Module: vhdl_parseindexedname
1141 ------------------------------------------------------------------------
1142 Description:
1143 Parse an indexed name given its prefix and now at the index. The
1144 form of an indexed name is:
1145
1146 indexed_name ::= prefix(expression{, expression})
1147 ------------------------------------------------------------------------
1148 Calling Sequence: pointer = vhdl_parseindexedname(pre_type, pre_ptr);
1149
1150 Name Type Description
1151 ---- ---- -----------
1152 pre_type INTBIG Type of prefix (VNAME or FUNCTION CALL).
1153 pre_ptr *char Pointer to prefix structure.
1154 pointer *INDEXEDNAME Returned pointer to indexed name.
1155 ------------------------------------------------------------------------
1156 */
vhdl_parseindexedname(INTBIG pre_type,CHAR * pre_ptr)1157 INDEXEDNAME *vhdl_parseindexedname(INTBIG pre_type, CHAR *pre_ptr)
1158 {
1159 PREFIX *prefix;
1160 INDEXEDNAME *ind;
1161 EXPRLIST *elist, *newelist;
1162
1163 prefix = (PREFIX *)emalloc((INTBIG)sizeof(PREFIX), vhdl_tool->cluster);
1164 prefix->type = pre_type;
1165 prefix->pointer = pre_ptr;
1166 ind = (INDEXEDNAME *)emalloc((INTBIG)sizeof(INDEXEDNAME), vhdl_tool->cluster);
1167 ind->prefix = prefix;
1168 ind->expr_list = (EXPRLIST *)emalloc((INTBIG)sizeof(EXPRLIST), vhdl_tool->cluster);
1169 ind->expr_list->expression = vhdl_parseexpression();
1170 ind->expr_list->next = NULL;
1171 elist = ind->expr_list;
1172
1173 /* continue while at a comma */
1174 while (vhdl_nexttoken->token == TOKEN_COMMA)
1175 {
1176 vhdl_getnexttoken();
1177 newelist = (EXPRLIST *)emalloc((INTBIG)sizeof(EXPRLIST), vhdl_tool->cluster);
1178 newelist->expression = vhdl_parseexpression();
1179 newelist->next = NULL;
1180 elist->next = newelist;
1181 elist = newelist;
1182 }
1183
1184 return(ind);
1185 }
1186
1187 /*
1188 Module: vhdl_getnameident
1189 ------------------------------------------------------------------------
1190 Description:
1191 Given a pointer to a name, return its reference to an global
1192 namespace entry.
1193 ------------------------------------------------------------------------
1194 Calling Sequence: itable = vhdl_getnameident(name);
1195
1196 Name Type Description
1197 ---- ---- -----------
1198 name *VNAME Pointer to name structure.
1199 itable *IDENTTABLE Returned pointer to global name space,
1200 NULL if not found.
1201 ------------------------------------------------------------------------
1202 */
vhdl_getnameident(VNAME * name)1203 IDENTTABLE *vhdl_getnameident(VNAME *name)
1204 {
1205 IDENTTABLE *itable;
1206 SINGLENAME *singl;
1207
1208 itable = NULL;
1209 if (name == NULL) return(itable);
1210 switch (name->type)
1211 {
1212 case NAME_SINGLE:
1213 singl = (SINGLENAME *)(name->pointer);
1214 switch (singl->type)
1215 {
1216 case SINGLENAME_SIMPLE:
1217 itable = (IDENTTABLE *)((SIMPLENAME *)(singl->pointer))->identifier->pointer;
1218 break;
1219 case SINGLENAME_INDEXED:
1220 itable = vhdl_getprefixident(((INDEXEDNAME *)(singl->pointer))->prefix);
1221 break;
1222 case SINGLENAME_SELECTED:
1223 case SINGLENAME_SLICE:
1224 default:
1225 break;
1226 }
1227 break;
1228 case NAME_CONCATENATE:
1229 case NAME_ATTRIBUTE:
1230 default:
1231 break;
1232 }
1233 return(itable);
1234 }
1235
1236 /*
1237 Module: vhdl_getprefixident
1238 ------------------------------------------------------------------------
1239 Description:
1240 Given a pointer to a prefix, return its reference to an global
1241 namespace entry.
1242 ------------------------------------------------------------------------
1243 Calling Sequence: itable = vhdl_getprefixident(prefix);
1244
1245 Name Type Description
1246 ---- ---- -----------
1247 prefix *PREFIX Pointer to prefix structure.
1248 itable *IDENTTABLE Returned pointer to global name space,
1249 NULL if not found.
1250 ------------------------------------------------------------------------
1251 */
vhdl_getprefixident(PREFIX * prefix)1252 IDENTTABLE *vhdl_getprefixident(PREFIX *prefix)
1253 {
1254 IDENTTABLE *itable;
1255
1256 itable = NULL;
1257 if (prefix == NULL) return(itable);
1258 switch (prefix->type)
1259 {
1260 case PREFIX_NAME:
1261 itable = vhdl_getnameident((VNAME *)prefix->pointer);
1262 break;
1263 case PREFIX_FUNCTION_CALL:
1264 default:
1265 break;
1266 }
1267 return(itable);
1268 }
1269
1270 /*
1271 Module: vhdl_getnametoken
1272 ------------------------------------------------------------------------
1273 Description:
1274 Given a pointer to a name, return its reference to a token.
1275 ------------------------------------------------------------------------
1276 Calling Sequence: token = vhdl_getnametoken(name);
1277
1278 Name Type Description
1279 ---- ---- -----------
1280 name *VNAME Pointer to name structure.
1281 token *TOKENLIST Returned pointer to token,
1282 NULL if not found.
1283 ------------------------------------------------------------------------
1284 */
vhdl_getnametoken(VNAME * name)1285 TOKENLIST *vhdl_getnametoken(VNAME *name)
1286 {
1287 TOKENLIST *token;
1288 SINGLENAME *singl;
1289
1290 token = NULL;
1291 if (name == NULL) return(token);
1292 switch (name->type)
1293 {
1294 case NAME_SINGLE:
1295 singl = (SINGLENAME *)(name->pointer);
1296 switch (singl->type)
1297 {
1298 case SINGLENAME_SIMPLE:
1299 token = ((SIMPLENAME *)(singl->pointer))->identifier;
1300 break;
1301 case SINGLENAME_SELECTED:
1302 break;
1303 case SINGLENAME_INDEXED:
1304 token = vhdl_getprefixtoken(((INDEXEDNAME *)(singl->pointer))->prefix);
1305 break;
1306 case SINGLENAME_SLICE:
1307 default:
1308 break;
1309 }
1310 break;
1311 case NAME_CONCATENATE:
1312 case NAME_ATTRIBUTE:
1313 default:
1314 break;
1315 }
1316 return(token);
1317 }
1318
1319 /*
1320 Module: vhdl_getprefixtoken
1321 ------------------------------------------------------------------------
1322 Description:
1323 Given a pointer to a prefix, return its reference to a token.
1324 ------------------------------------------------------------------------
1325 Calling Sequence: token = vhdl_getprefixtoken(prefix);
1326
1327 Name Type Description
1328 ---- ---- -----------
1329 prefix *PREFIX Pointer to prefix structure.
1330 token *TOKENLIST Returned pointer to token,
1331 NULL if not found.
1332 ------------------------------------------------------------------------
1333 */
vhdl_getprefixtoken(PREFIX * prefix)1334 TOKENLIST *vhdl_getprefixtoken(PREFIX *prefix)
1335 {
1336 TOKENLIST *token;
1337
1338 token = NULL;
1339 if (prefix == NULL) return(token);
1340 switch (prefix->type)
1341 {
1342 case PREFIX_NAME:
1343 token = vhdl_getnametoken((VNAME *)prefix->pointer);
1344 break;
1345 case PREFIX_FUNCTION_CALL:
1346 default:
1347 break;
1348 }
1349 return(token);
1350 }
1351
1352 /*
1353 Module: vhdl_semname
1354 ------------------------------------------------------------------------
1355 Description:
1356 Semantic analysis of a name.
1357 ------------------------------------------------------------------------
1358 Calling Sequence: dbname = vhdl_semname(name);
1359
1360 Name Type Description
1361 ---- ---- -----------
1362 name *VNAME Pointer to name structure.
1363 dbname *DBNAME pointer to created db name.
1364 ------------------------------------------------------------------------
1365 */
vhdl_semname(VNAME * name)1366 DBNAME *vhdl_semname(VNAME *name)
1367 {
1368 DBNAME *dbname;
1369
1370 dbname = NULL;
1371 if (name == NULL) return(dbname);
1372 switch (name->type)
1373 {
1374 case NAME_SINGLE:
1375 dbname = vhdl_semsinglename((SINGLENAME *)name->pointer);
1376 break;
1377 case NAME_CONCATENATE:
1378 dbname = vhdl_semconcatenatedname((CONCATENATEDNAME *)name->pointer);
1379 break;
1380 case NAME_ATTRIBUTE:
1381 default:
1382 break;
1383 }
1384 return(dbname);
1385 }
1386
1387 /*
1388 Module: vhdl_semsinglename
1389 ------------------------------------------------------------------------
1390 Description:
1391 Semantic analysis of a single name.
1392 ------------------------------------------------------------------------
1393 Calling Sequence: dbname = vhdl_semsinglename(name);
1394
1395 Name Type Description
1396 ---- ---- -----------
1397 name *SINGLENAME Pointer to single name structure.
1398 dbname *DBNAME Pointer to generated db name.
1399 ------------------------------------------------------------------------
1400 */
vhdl_semsinglename(SINGLENAME * name)1401 DBNAME *vhdl_semsinglename(SINGLENAME *name)
1402 {
1403 DBNAME *dbname;
1404
1405 dbname = NULL;
1406 if (name == NULL) return(dbname);
1407 switch (name->type)
1408 {
1409 case SINGLENAME_SIMPLE:
1410 dbname = (DBNAME *)emalloc((INTBIG)sizeof(DBNAME), vhdl_tool->cluster);
1411 dbname->name = (IDENTTABLE *)((SIMPLENAME *)(name->pointer))->identifier->pointer;
1412 dbname->type = DBNAME_IDENTIFIER;
1413 dbname->pointer = NULL;
1414 dbname->dbtype = vhdl_gettype(dbname->name);
1415 break;
1416 case SINGLENAME_INDEXED:
1417 dbname = vhdl_semindexedname((INDEXEDNAME *)name->pointer);
1418 break;
1419 case SINGLENAME_SLICE:
1420 case SINGLENAME_SELECTED:
1421 default:
1422 break;
1423 }
1424 return(dbname);
1425 }
1426
1427 /*
1428 Module: vhdl_semconcatenatedname
1429 ------------------------------------------------------------------------
1430 Description:
1431 Semantic analysis of a concatenated name.
1432 ------------------------------------------------------------------------
1433 Calling Sequence: dbname = vhdl_semconcatenatedname(name);
1434
1435 Name Type Description
1436 ---- ---- -----------
1437 name *CONCATENATEDNAME Pointer to concatenated name structure.
1438 dbname *DBNAME Pointer to generated db name.
1439 ------------------------------------------------------------------------
1440 */
vhdl_semconcatenatedname(CONCATENATEDNAME * name)1441 DBNAME *vhdl_semconcatenatedname(CONCATENATEDNAME *name)
1442 {
1443 CONCATENATEDNAME *cat;
1444 DBNAME *dbname;
1445 DBNAMELIST *end, *newnl;
1446
1447 dbname = NULL;
1448 if (name == NULL) return(dbname);
1449 dbname = (DBNAME *)emalloc((INTBIG)sizeof(DBNAME), vhdl_tool->cluster);
1450 dbname->name = NULL;
1451 dbname->type = DBNAME_CONCATENATED;
1452 dbname->pointer = NULL;
1453 dbname->dbtype = NULL;
1454 end = NULL;
1455 for (cat = name; cat != NULL; cat = cat->next)
1456 {
1457 newnl = (DBNAMELIST *)emalloc((INTBIG)sizeof(DBNAMELIST), vhdl_tool->cluster);
1458 newnl->name = vhdl_semsinglename(cat->name);
1459 newnl->next = NULL;
1460 if (end)
1461 {
1462 end->next = newnl;
1463 end = newnl;
1464 } else
1465 {
1466 end = newnl;
1467 dbname->pointer = (CHAR *)newnl;
1468 }
1469 }
1470 return(dbname);
1471 }
1472
1473 /*
1474 Module: vhdl_semindexedname
1475 ------------------------------------------------------------------------
1476 Description:
1477 Semantic analysis of an indexed name.
1478 ------------------------------------------------------------------------
1479 Calling Sequence: dbname = vhdl_semindexedname(name);
1480
1481 Name Type Description
1482 ---- ---- -----------
1483 name *INDEXEDNAME Pointer to indexed name structure.
1484 dbname *DBNAME Pointer to generated name.
1485 ------------------------------------------------------------------------
1486 */
vhdl_semindexedname(INDEXEDNAME * name)1487 DBNAME *vhdl_semindexedname(INDEXEDNAME *name)
1488 {
1489 DBNAME *dbname;
1490 EXPRLIST *expr;
1491 DBINDEXRANGE *indexr;
1492 DBEXPRLIST *dbexpr, *nexpr, *endexpr;
1493 INTBIG value;
1494 DBLTYPE *type;
1495
1496 dbname = NULL;
1497 if (name == NULL) return(dbname);
1498
1499 /* must be an array type */
1500 type = vhdl_gettype(vhdl_getprefixident(name->prefix));
1501 if (type == NULL)
1502 {
1503 vhdl_reporterrormsg(vhdl_getprefixtoken(name->prefix), _("No type specified"));
1504 return(dbname);
1505 }
1506 if (type->type != DBTYPE_ARRAY)
1507 {
1508 vhdl_reporterrormsg(vhdl_getprefixtoken(name->prefix), _("Must be of constrained array type"));
1509 return(dbname);
1510 }
1511 dbname = (DBNAME *)emalloc((INTBIG)sizeof(DBNAME), vhdl_tool->cluster);
1512 dbname->name = vhdl_getprefixident(name->prefix);
1513 dbname->type = DBNAME_INDEXED;
1514 dbname->pointer = NULL;
1515 dbname->dbtype = type;
1516
1517 /* evaluate any expressions */
1518 indexr = (DBINDEXRANGE *)type->pointer;
1519 dbexpr = endexpr = NULL;
1520 for (expr = name->expr_list; expr && indexr; expr = expr->next)
1521 {
1522 value = vhdl_evalexpression(expr->expression);
1523 if (!vhdl_indiscreterange((INTBIG)value, indexr->drange))
1524 {
1525 vhdl_reporterrormsg(vhdl_getprefixtoken(name->prefix), _("Index is out of range"));
1526 return(dbname);
1527 }
1528 nexpr = (DBEXPRLIST *)emalloc((INTBIG)sizeof(DBEXPRLIST), vhdl_tool->cluster);
1529 nexpr->value = value;
1530 nexpr->next = NULL;
1531 if (endexpr == NULL)
1532 {
1533 dbexpr = endexpr = nexpr;
1534 } else
1535 {
1536 endexpr->next = nexpr;
1537 endexpr = nexpr;
1538 }
1539 indexr = indexr->next;
1540 }
1541 dbname->pointer = (CHAR *)dbexpr;
1542 return(dbname);
1543 }
1544
1545 #endif /* VHDLTOOL - at top */
1546