1 /* -*- tab-width: 4 -*-
2  *
3  * Electric(tm) VLSI Design System
4  *
5  * File: vhdlsemantic.c
6  * Semantic Analyzer 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 
39 extern PTREE	*vhdl_ptree;
40 extern INTBIG	vhdl_warnflag, vhdl_target;
41 extern BOOLEAN	vhdl_err;
42 extern TOKENLIST *vhdl_nexttoken;
43 SYMBOLLIST		*vhdl_symbols = 0, *vhdl_gsymbols = 0;
44 SYMBOLLIST      *vhdl_symbollists = 0;
45 DBUNITS			*vhdl_units = 0;
46 static CHAR		vhdl_default_name[80];
47 #ifdef VHDL50
48   static INTBIG	vhdl_default_num;
49 #else
50   static INTBIG	vhdl_for_level = 0;
51   static INTBIG	vhdl_for_tags[10];
52 #endif
53 
54 /* prototypes for local routines */
55 static void             vhdl_createdefaulttype(SYMBOLLIST*);
56 static void             vhdl_sempackage(PACKAGE*);
57 static DBINTERFACE     *vhdl_seminterface(VINTERFACE*);
58 static DBBODY          *vhdl_sembody(BODY*);
59 static DBPORTLIST      *vhdl_semformal_port_list(FPORTLIST*);
60 static DBBODYDECLARE   *vhdl_sembody_declare(BODYDECLARE*);
61 static DBCOMPONENTS    *vhdl_semcomponent(VCOMPONENT*);
62 static DBSIGNALS       *vhdl_sembasic_declare(BASICDECLARE*);
63 static DBSIGNALS       *vhdl_semobject_declare(OBJECTDECLARE*);
64 static DBSIGNALS       *vhdl_semsignal_declare(SIGNALDECLARE*);
65 static void             vhdl_semconstant_declare(CONSTANTDECLARE*);
66 static DBSTATEMENTS    *vhdl_semset_of_statements(STATEMENTS*);
67 static DBINSTANCE      *vhdl_seminstance(VINSTANCE*);
68 static DBSTATEMENTS    *vhdl_semgenerate(GENERATE*);
69 #ifdef VHDL50
70   static void           vhdl_semwith(WITH*);
71 #endif
72 static void             vhdl_semuse(USE*);
73 static SYMBOLTREE      *vhdl_searchfsymbol(IDENTTABLE*, SYMBOLLIST*);
74 static SYMBOLTREE      *vhdl_searchsymboltree(IDENTTABLE*, SYMBOLTREE*);
75 static SYMBOLTREE      *vhdl_addsymbol(IDENTTABLE*, INTBIG, CHAR*, SYMBOLLIST*);
76 static SYMBOLTREE      *vhdl_addsymboltree(IDENTTABLE*, INTBIG, CHAR*, SYMBOLTREE*);
77 static SYMBOLLIST      *vhdl_pushsymbols(SYMBOLLIST*);
78 static SYMBOLLIST      *vhdl_popsymbols(SYMBOLLIST*);
79 static void             vhdl_semaport_check(VNAME*);
80 static void             vhdl_semaport_check_single_name(SINGLENAME*);
81 static CHAR            *vhdl_parsescalar_type(void);
82 static COMPOSITE       *vhdl_parsecomposite_type(void);
83 static CHAR            *vhdl_parserecord_type(void);
84 static ARRAY           *vhdl_parsearray_type(void);
85 static void             vhdl_semtype_declare(TYPE*);
86 static DBLTYPE         *vhdl_semcomposite_type(COMPOSITE*);
87 static DBLTYPE         *vhdl_semarray_type(ARRAY*);
88 static DBLTYPE         *vhdl_semconstrained_array(CONSTRAINED*);
89 static DBDISCRETERANGE *vhdl_semdiscrete_range(DISCRETERANGE*);
90 static DBDISCRETERANGE *vhdl_semrange(RANGE*);
91 static DBLTYPE         *vhdl_semsubtype_indication(SUBTYPEIND*);
92 static DBLTYPE         *vhdl_semtype_mark(VNAME*);
93 static DBLTYPE         *vhdl_getsymboltype(SYMBOLTREE*);
94 static void             vhdl_freesymboltree(SYMBOLTREE *tree);
95 
96 static int vhdl_freeinggsymbols;
97 
vhdl_freesemantic(void)98 void vhdl_freesemantic(void)
99 {
100 	DBINTERFACE	*intf;
101 	SYMBOLLIST *sym, *lastsym, *nextsym;
102 	DBBODY *body;
103 	DBBODYDECLARE *bodydecl;
104 	DBSTATEMENTS *state;
105 	DBCOMPONENTS *comp;
106 	DBPORTLIST *port;
107 	DBSIGNALS *signals;
108 	DBINSTANCE *inst;
109 	DBAPORTLIST *aport;
110 	DBEXPRLIST *expr;
111 
112 	if (vhdl_units == 0) return;
113 	while (vhdl_units->interfaces != 0)
114 	{
115 		intf = vhdl_units->interfaces;
116 		vhdl_units->interfaces = vhdl_units->interfaces->next;
117 		while (intf->ports != 0)
118 		{
119 			port = intf->ports;
120 			intf->ports = intf->ports->next;
121 			efree((CHAR *)port);
122 		}
123 		efree((CHAR *)intf);
124 	}
125 	while (vhdl_units->bodies != 0)
126 	{
127 		body = vhdl_units->bodies;
128 		vhdl_units->bodies = vhdl_units->bodies->next;
129 		if (body->declare != 0)
130 		{
131 			bodydecl = body->declare;
132 			while (bodydecl->components != 0)
133 			{
134 				comp = bodydecl->components;
135 				bodydecl->components = bodydecl->components->next;
136 				while (comp->ports != 0)
137 				{
138 					port = comp->ports;
139 					comp->ports = comp->ports->next;
140 					efree((CHAR *)port);
141 				}
142 				efree((CHAR *)comp);
143 			}
144 			while (bodydecl->bodysignals != 0)
145 			{
146 				signals = bodydecl->bodysignals;
147 				bodydecl->bodysignals = bodydecl->bodysignals->next;
148 				efree((CHAR *)signals);
149 			}
150 			efree((CHAR *)bodydecl);
151 
152 			if (body->statements != 0)
153 			{
154 				state = body->statements;
155 				while (state->instances != 0)
156 				{
157 					inst = state->instances;
158 					state->instances = state->instances->next;
159 					while (inst->ports != 0)
160 					{
161 						aport = inst->ports;
162 						inst->ports = inst->ports->next;
163 						if (aport->name != 0)
164 						{
165 							while (aport->name->pointer != 0)
166 							{
167 								expr = (DBEXPRLIST *)aport->name->pointer;
168 								aport->name->pointer = (CHAR *)expr->next;
169 								efree((CHAR *)expr);
170 							}
171 							efree((CHAR *)aport->name);
172 						}
173 						efree((CHAR *)aport);
174 					}
175 					efree((CHAR *)inst);
176 				}
177 				efree((CHAR *)state);
178 			}
179 		}
180 		efree((CHAR *)body);
181 	}
182 	efree((CHAR *)vhdl_units);
183 	vhdl_units = 0;
184 
185 	for(sym = vhdl_symbollists; sym != 0; sym = sym->next)
186 		if (sym->root != 0) sym->root->seen = 0;
187 	lastsym = 0;
188 	for(sym = vhdl_symbollists; sym != 0; sym = nextsym)
189 	{
190 		nextsym = sym->next;
191 		if (sym->root != 0 && sym->root->seen != 0)
192 		{
193 			if (lastsym == 0) vhdl_symbollists = sym->next; else
194 				lastsym->next = sym->next;
195 			efree((CHAR *)sym);
196 			continue;
197 		}
198 		lastsym = sym;
199 		if (sym->root != 0) sym->root->seen = 1;
200 	}
201 	while (vhdl_symbollists != 0)
202 	{
203 		sym = vhdl_symbollists;
204 		vhdl_symbollists = vhdl_symbollists->next;
205 		if (sym->root != 0)
206 		{
207 			if (sym == vhdl_gsymbols) vhdl_freeinggsymbols = 1; else
208 				vhdl_freeinggsymbols = 0;
209 			vhdl_freesymboltree(sym->root);
210 			sym->root = 0;
211 		}
212 		efree((CHAR *)sym);
213 	}
214 	vhdl_gsymbols = vhdl_symbols = 0;
215 }
216 
vhdl_freesymboltree(SYMBOLTREE * tree)217 void vhdl_freesymboltree(SYMBOLTREE *tree)
218 {
219 	DBLTYPE *dbtype;
220 	DBINDEXRANGE *range;
221 
222 	if (tree->pointer != 0)
223 	{
224 		switch (tree->type)
225 		{
226 			case SYMBOL_PACKAGE:
227 				if (vhdl_freeinggsymbols != 0)
228 					efree((CHAR *)tree->pointer);
229 				break;
230 			case SYMBOL_TYPE:
231 				dbtype = (DBLTYPE *)tree->pointer;
232 				while (dbtype->pointer != 0)
233 				{
234 					range = (DBINDEXRANGE *)dbtype->pointer;
235 					dbtype->pointer = (CHAR *)range->next;
236 					if (range->drange != 0) efree((CHAR *)range->drange);
237 					efree((CHAR *)range);
238 				}
239 				efree((CHAR *)dbtype);
240 				break;
241 		}
242 	}
243 	if (tree->lptr != 0) vhdl_freesymboltree(tree->lptr);
244 	if (tree->rptr != 0) vhdl_freesymboltree(tree->rptr);
245 	efree((CHAR *)tree);
246 }
247 
248 /*
249 Module:  vhdl_semantic
250 ------------------------------------------------------------------------
251 Description:
252 	Start semantic analysis of the generated parse tree.  Return the
253 	status of the analysis (errors).
254 ------------------------------------------------------------------------
255 Calling Sequence:  err = vhdl_semantic();
256 ------------------------------------------------------------------------
257 */
vhdl_semantic(void)258 BOOLEAN vhdl_semantic(void)
259 {
260 	PTREE *unit;
261 	DBINTERFACE *interfacef, *endinterface;
262 	DBBODY *body, *endbody;
263 	SYMBOLLIST *ssymbols;
264 
265 	vhdl_err = FALSE;
266 	estrcpy(vhdl_default_name, x_("default"));
267 #ifdef VHDL50
268 	vhdl_default_num = 0;
269 #endif
270 
271 	/* first free previous semantic memory */
272 	vhdl_freesemantic();
273 
274 	vhdl_units = (DBUNITS *)emalloc((INTBIG)sizeof(DBUNITS), vhdl_tool->cluster);
275 	vhdl_units->interfaces = endinterface = 0;
276 	vhdl_units->bodies = endbody = 0;
277 
278 	vhdl_symbols = vhdl_pushsymbols((SYMBOLLIST *)0);
279 	vhdl_gsymbols = vhdl_pushsymbols((SYMBOLLIST *)0);
280 
281 	/* add defaults to symbol tree */
282 	vhdl_createdefaulttype(vhdl_symbols);
283 	ssymbols = vhdl_symbols;
284 
285 	vhdl_symbols = vhdl_pushsymbols(vhdl_symbols);
286 
287 	for (unit = vhdl_ptree; unit != 0; unit = unit->next)
288 	{
289 		switch (unit->type)
290 		{
291 			case UNIT_INTERFACE:
292 				interfacef = vhdl_seminterface((VINTERFACE *)unit->pointer);
293 				if (interfacef == 0) break;
294 				if (endinterface == 0)
295 				{
296 					vhdl_units->interfaces = endinterface = interfacef;
297 				} else
298 				{
299 					endinterface->next = interfacef;
300 					endinterface = interfacef;
301 				}
302 				vhdl_symbols = vhdl_pushsymbols(ssymbols);
303 				break;
304 			case UNIT_BODY:
305 				body = vhdl_sembody((BODY *)unit->pointer);
306 				if (endbody == 0)
307 				{
308 					vhdl_units->bodies = endbody = body;
309 				} else
310 				{
311 					endbody->next = body;
312 					endbody = body;
313 				}
314 				vhdl_symbols = vhdl_pushsymbols(ssymbols);
315 				break;
316 			case UNIT_PACKAGE:
317 				vhdl_sempackage((PACKAGE *)unit->pointer);
318 				break;
319 #ifdef VHDL50
320 			case UNIT_WITH:
321 				vhdl_semwith((WITH *)unit->pointer);
322 				break;
323 #endif
324 			case UNIT_USE:
325 				vhdl_semuse((USE *)unit->pointer);
326 				break;
327 			case UNIT_FUNCTION:
328 			default:
329 				break;
330 		}
331 	}
332 
333 	return(vhdl_err);
334 }
335 
336 /*
337 Module:  vhdl_createdefaulttype
338 ------------------------------------------------------------------------
339 Description:
340 	Create the default type symbol tree.
341 ------------------------------------------------------------------------
342 Calling Sequence:  vhdl_createdefaulttype(symbols);
343 
344 Name		Type		Description
345 ----		----		-----------
346 symbols		*SYMBOLLIST	Pointer to current symbol list.
347 ------------------------------------------------------------------------
348 */
vhdl_createdefaulttype(SYMBOLLIST * symbols)349 void vhdl_createdefaulttype(SYMBOLLIST *symbols)
350 {
351 	IDENTTABLE *ikey;
352 	CHAR *bitname;
353 
354 	/* type BIT */
355 	allocstring(&bitname, x_("BIT"), vhdl_tool->cluster);
356 	if ((ikey = vhdl_findidentkey(bitname)) == 0)
357 	{
358 		ikey = vhdl_makeidentkey(bitname);
359 		if (ikey == 0) return;
360 	} else efree(bitname);
361 	vhdl_addsymbol(ikey, (INTBIG)SYMBOL_TYPE, (CHAR *)0, symbols);
362 
363 	/* type "std_logic" */
364 	allocstring(&bitname, x_("std_logic"), vhdl_tool->cluster);
365 	if ((ikey = vhdl_findidentkey(bitname)) == 0)
366 	{
367 		ikey = vhdl_makeidentkey(bitname);
368 		if (ikey == 0) return;
369 	} else efree(bitname);
370 	vhdl_addsymbol(ikey, (INTBIG)SYMBOL_TYPE, (CHAR *)0, symbols);
371 }
372 
373 /*
374 Module:  vhdl_sempackage
375 ------------------------------------------------------------------------
376 Description:
377 	Semantic analysis of a package declaration.
378 ------------------------------------------------------------------------
379 Calling Sequence:  vhdl_sempackage(package);
380 
381 Name		Type		Description
382 ----		----		-----------
383 package		*PACKAGE	Pointer to a package.
384 ------------------------------------------------------------------------
385 */
vhdl_sempackage(PACKAGE * package)386 void vhdl_sempackage(PACKAGE *package)
387 {
388 	DBPACKAGE *dbpackage;
389 	PACKAGEDPART *part;
390 
391 	if (package == 0) return;
392 	dbpackage = 0;
393 
394 	/* search to see if package name is unique */
395 	if (vhdl_searchsymbol((IDENTTABLE *)package->name->pointer, vhdl_gsymbols))
396 	{
397 		vhdl_reporterrormsg(package->name, _("Symbol previously defined"));
398 	} else
399 	{
400 		dbpackage = (DBPACKAGE *)emalloc((INTBIG)sizeof(DBPACKAGE), vhdl_tool->cluster);
401 		dbpackage->name = (IDENTTABLE *)package->name->pointer;
402 		dbpackage->root = 0;
403 		vhdl_addsymbol(dbpackage->name, (INTBIG)SYMBOL_PACKAGE, (CHAR *)dbpackage, vhdl_gsymbols);
404 	}
405 
406 	/* check package parts */
407 	vhdl_symbols = vhdl_pushsymbols(vhdl_symbols);
408 	for (part = package->declare; part != 0; part = part->next)
409 	{
410 		vhdl_sembasic_declare(part->item);
411 	}
412 	if (dbpackage)
413 	{
414 		dbpackage->root = vhdl_symbols->root;
415 	}
416 	vhdl_symbols = vhdl_popsymbols(vhdl_symbols);
417 }
418 
419 /*
420 Module:  vhdl_seminterface
421 ------------------------------------------------------------------------
422 Description:
423 	Semantic analysis of an interface declaration.
424 ------------------------------------------------------------------------
425 Calling Sequence:  dbinterface = vhdl_seminterface(interfacef);
426 
427 Name		Type			Description
428 ----		----			-----------
429 interfacef	*VINTERFACE		Pointer to interface parse structure.
430 dbinterface	*DBINTERFACE	Resultant database interface.
431 ------------------------------------------------------------------------
432 */
vhdl_seminterface(VINTERFACE * interfacef)433 DBINTERFACE  *vhdl_seminterface(VINTERFACE *interfacef)
434 {
435 	DBINTERFACE *dbinter;
436 	SYMBOLLIST *endsymbol;
437 
438 	dbinter = 0;
439 	if (interfacef == 0) return(dbinter);
440 	if (vhdl_searchsymbol((IDENTTABLE *)interfacef->name->pointer, vhdl_gsymbols))
441 	{
442 		vhdl_reporterrormsg(interfacef->name, _("Entity previously defined"));
443 	} else
444 	{
445 		dbinter = (DBINTERFACE *)emalloc((INTBIG)sizeof(DBINTERFACE), vhdl_tool->cluster);
446 		dbinter->name = (IDENTTABLE *)interfacef->name->pointer;
447 		dbinter->ports = 0;
448 		dbinter->flags = 0;
449 		dbinter->bodies = 0;
450 		dbinter->symbols = 0;
451 		dbinter->next = 0;
452 		vhdl_addsymbol(dbinter->name, (INTBIG)SYMBOL_ENTITY, (CHAR *)dbinter, vhdl_gsymbols);
453 		vhdl_symbols = vhdl_pushsymbols(vhdl_symbols);
454 		dbinter->ports = vhdl_semformal_port_list(interfacef->ports);
455 
456 		/* remove last symbol tree */
457 		endsymbol = vhdl_symbols;
458 		while (endsymbol->last->last)
459 		{
460 			endsymbol = endsymbol->last;
461 		}
462 		endsymbol->last = 0;
463 		dbinter->symbols = vhdl_symbols;
464 	}
465 	return(dbinter);
466 }
467 
468 /*
469 Module:  vhdl_sembody
470 ------------------------------------------------------------------------
471 Description:
472 	Semantic analysis of an body declaration.
473 ------------------------------------------------------------------------
474 Calling Sequence:  dbbody = vhdl_sembody(body);
475 
476 Name		Type		Description
477 ----		----		-----------
478 body		*BODY		Pointer to body parse structure.
479 dbbody		*DBBODY		Resultant database body.
480 ------------------------------------------------------------------------
481 */
vhdl_sembody(BODY * body)482 DBBODY *vhdl_sembody(BODY *body)
483 {
484 	DBBODY *dbbody;
485 	SYMBOLTREE *symbol;
486 	SYMBOLLIST *temp_symbols, *endsymbol;
487 
488 	dbbody = 0;
489 	if (body == 0) return(dbbody);
490 	if (vhdl_searchsymbol((IDENTTABLE *)body->name->pointer, vhdl_gsymbols))
491 	{
492 		vhdl_reporterrormsg(body->name, _("Body previously defined"));
493 		return(dbbody);
494 	}
495 
496 	/* create dbbody */
497 	dbbody = (DBBODY *)emalloc((INTBIG)sizeof(DBBODY), vhdl_tool->cluster);
498 	dbbody->classnew = body->classnew;
499 	dbbody->name = (IDENTTABLE *)body->name->pointer;
500 	dbbody->entity = 0;
501 	dbbody->declare = 0;
502 	dbbody->statements = 0;
503 	dbbody->parent = 0;
504 	dbbody->same_parent = 0;
505 	dbbody->next = 0;
506 	vhdl_addsymbol(dbbody->name, (INTBIG)SYMBOL_BODY, (CHAR *)dbbody, vhdl_gsymbols);
507 
508 	/* check if interface declared */
509 	if ((symbol = vhdl_searchsymbol((IDENTTABLE *)body->entity->identifier->pointer,
510 		vhdl_gsymbols)) == 0)
511 	{
512 		vhdl_reporterrormsg((TOKENLIST *)body->entity, _("Reference to undefined entity"));
513 		return(dbbody);
514 	} else if (symbol->type != SYMBOL_ENTITY)
515 	{
516 		vhdl_reporterrormsg((TOKENLIST *)body->entity, _("Symbol is not an entity"));
517 		return(dbbody);
518 	} else
519 	{
520 		dbbody->entity = symbol->value;
521 		dbbody->parent = (DBINTERFACE *)symbol->pointer;
522 		if (symbol->pointer)
523 		{
524 			/* add interfacef-body reference to list */
525 			dbbody->same_parent = ((DBINTERFACE *)(symbol->pointer))->bodies;
526 			((DBINTERFACE *)(symbol->pointer))->bodies = dbbody;
527 		}
528 	}
529 
530 	/* create new symbol tree */
531 	temp_symbols = vhdl_symbols;
532 	if (symbol->pointer)
533 	{
534 		endsymbol = vhdl_symbols;
535 		while (endsymbol->last)
536 		{
537 			endsymbol = endsymbol->last;
538 		}
539 		endsymbol->last = ((DBINTERFACE *)(symbol->pointer))->symbols;
540 	}
541 	vhdl_symbols = vhdl_pushsymbols(vhdl_symbols);
542 
543 	/* check body declaration */
544 	dbbody->declare = vhdl_sembody_declare(body->body_declare);
545 
546 	/* check statements */
547 	dbbody->statements = vhdl_semset_of_statements(body->statements);
548 
549 	/* delete current symbol table */
550 	vhdl_symbols = temp_symbols;
551 	endsymbol->last = 0;
552 
553 	return(dbbody);
554 }
555 
556 /*
557 Module:  vhdl_semformal_port_list
558 ------------------------------------------------------------------------
559 Description:
560 	Check the semantic of the passed formal port list.
561 ------------------------------------------------------------------------
562 Calling Sequence::  dbports = vhdl_semformal_port_list(ports);
563 
564 Name		Type		Description
565 ----		----		-----------
566 ports		*FPORTLIST	Pointer to start of formal port list.
567 dbports		*DBPORTLIST	Pointer to database port list.
568 ------------------------------------------------------------------------
569 */
vhdl_semformal_port_list(FPORTLIST * port)570 DBPORTLIST *vhdl_semformal_port_list(FPORTLIST *port)
571 {
572 	IDENTLIST *names;
573 	SYMBOLTREE *symbol;
574 	DBPORTLIST *dbports, *newport, *endport;
575 
576 	dbports = endport = 0;
577 
578 	for (; port != 0; port = port->next)
579 	{
580 		/* check the mode of the port */
581 		switch (port->mode)
582 		{
583 			case MODE_IN:
584 			case MODE_DOTOUT:
585 			case MODE_OUT:
586 			case MODE_INOUT:
587 			case MODE_LINKAGE:
588 				break;
589 			default:
590 				vhdl_reporterrormsg(port->names->identifier, _("Unknown port mode"));
591 				break;
592 		}
593 
594 		/* check the type */
595 		if ((symbol = vhdl_searchsymbol(vhdl_getnameident(port->type), vhdl_symbols)) == 0 ||
596 			symbol->type != SYMBOL_TYPE)
597 		{
598 			vhdl_reporterrormsg(vhdl_getnametoken(port->type), _("Unknown port mode"));
599 		}
600 
601 		/* check for uniqueness of port names */
602 		for (names = port->names; names != 0; names = names->next)
603 		{
604 			if (vhdl_searchfsymbol((IDENTTABLE *)names->identifier->pointer, vhdl_symbols))
605 			{
606 				vhdl_reporterrormsg(names->identifier, _("Duplicate port name in port list"));
607 			} else
608 			{
609 				/* add to port list */
610 				newport = (DBPORTLIST *)emalloc((INTBIG)sizeof(DBPORTLIST), vhdl_tool->cluster);
611 				newport->name = (IDENTTABLE *)names->identifier->pointer;
612 				newport->mode = port->mode;
613 				if (symbol)
614 				{
615 					newport->type = (DBLTYPE *)symbol->pointer;
616 				} else
617 				{
618 					newport->type = 0;
619 				}
620 				newport->flags = 0;
621 				newport->next = 0;
622 				if (endport == 0)
623 				{
624 					dbports = endport = newport;
625 				} else
626 				{
627 					endport->next = newport;
628 					endport = newport;
629 				}
630 				vhdl_addsymbol(newport->name, (INTBIG)SYMBOL_FPORT, (CHAR *)newport, vhdl_symbols);
631 			}
632 		}
633 	}
634 
635 	return(dbports);
636 }
637 
638 /*
639 Module:  vhdl_sembody_declare
640 ------------------------------------------------------------------------
641 Description:
642 	Semantic analysis of the body declaration portion of a body.
643 ------------------------------------------------------------------------
644 Calling Sequence:  dbdeclare = vhdl_sembody_declare(declare);
645 
646 Name		Type			Description
647 ----		----			-----------
648 declare		*BODYDECLARE	Pointer to body declare.
649 dbdeclare	*DBBODYDECLARE	Pointer to generated body declare.
650 ------------------------------------------------------------------------
651 */
vhdl_sembody_declare(BODYDECLARE * declare)652 DBBODYDECLARE *vhdl_sembody_declare(BODYDECLARE *declare)
653 {
654 	DBBODYDECLARE *dbdeclare;
655 	DBCOMPONENTS *endcomponent, *newcomponent;
656 	DBSIGNALS *endsignal, *newsignals;
657 
658 	dbdeclare = 0;
659 	if (declare == 0) return(dbdeclare);
660 	dbdeclare = (DBBODYDECLARE *)emalloc((INTBIG)sizeof(DBBODYDECLARE), vhdl_tool->cluster);
661 	dbdeclare->components = endcomponent = 0;
662 	dbdeclare->bodysignals = endsignal = 0;
663 
664 	for (; declare != 0; declare = declare->next)
665 	{
666 		switch (declare->type)
667 		{
668 			case BODYDECLARE_BASIC:
669 				newsignals = vhdl_sembasic_declare((BASICDECLARE *)declare->pointer);
670 				if (newsignals)
671 				{
672 					if (endsignal == 0)
673 					{
674 						dbdeclare->bodysignals = endsignal = newsignals;
675 					} else
676 					{
677 						endsignal->next = newsignals;
678 						endsignal = newsignals;
679 					}
680 					while (endsignal->next)
681 					{
682 						endsignal = endsignal->next;
683 					}
684 				}
685 				break;
686 			case BODYDECLARE_COMPONENT:
687 				newcomponent = vhdl_semcomponent((VCOMPONENT *)declare->pointer /*, dbdeclare */);
688 				if (newcomponent)
689 				{
690 					if (endcomponent == 0)
691 					{
692 						dbdeclare->components = endcomponent = newcomponent;
693 					} else
694 					{
695 						endcomponent->next = newcomponent;
696 						endcomponent = newcomponent;
697 					}
698 				}
699 				break;
700 			case BODYDECLARE_RESOLUTION:
701 			case BODYDECLARE_LOCAL:
702 			default:
703 				break;
704 		}
705 	}
706 
707 	return(dbdeclare);
708 }
709 
710 /*
711 Module:  vhdl_semcomponent
712 ------------------------------------------------------------------------
713 Description:
714 	Semantic analysis of body's component.
715 ------------------------------------------------------------------------
716 Calling Sequence:  dbcomp = vhdl_semcomponent(compo);
717 
718 Name		Type			Description
719 ----		----			-----------
720 compo		*VCOMPONENT		Pointer to component parse.
721 dbcomp		*DBCOMPONENTS	Pointer to created component.
722 ------------------------------------------------------------------------
723 */
vhdl_semcomponent(VCOMPONENT * compo)724 DBCOMPONENTS *vhdl_semcomponent(VCOMPONENT *compo)
725 {
726 	DBCOMPONENTS *dbcomp;
727 
728 	dbcomp = 0;
729 	if (compo == 0) return(dbcomp);
730 	if (vhdl_searchfsymbol((IDENTTABLE *)compo->name->pointer, vhdl_symbols))
731 	{
732 		vhdl_reporterrormsg(compo->name, _("Identifier previously defined"));
733 		return(dbcomp);
734 	}
735 	dbcomp = (DBCOMPONENTS *)emalloc((INTBIG)sizeof(DBCOMPONENTS), vhdl_tool->cluster);
736 	dbcomp->name = (IDENTTABLE *)compo->name->pointer;
737 	dbcomp->ports = 0;
738 	dbcomp->next = 0;
739 	vhdl_addsymbol(dbcomp->name, (INTBIG)SYMBOL_COMPONENT, (CHAR *)dbcomp, vhdl_symbols);
740 	vhdl_symbols = vhdl_pushsymbols(vhdl_symbols);
741 	dbcomp->ports = vhdl_semformal_port_list(compo->ports);
742 	vhdl_symbols = vhdl_popsymbols(vhdl_symbols);
743 	return(dbcomp);
744 }
745 
746 /*
747 Module:  vhdl_sembasic_declare
748 ------------------------------------------------------------------------
749 Description:
750 	Semantic analysis of basic declaration.
751 ------------------------------------------------------------------------
752 Calling Sequence:  dbsignal = vhdl_sembasic_declare(declare);
753 
754 Name		Type			Description
755 ----		----			-----------
756 declare		*BASICDECLARE	Pointer to basic declaration structure.
757 dbsignal	*DBSIGNALS		Pointer to new signal, 0 if not.
758 ------------------------------------------------------------------------
759 */
vhdl_sembasic_declare(BASICDECLARE * declare)760 DBSIGNALS *vhdl_sembasic_declare(BASICDECLARE *declare)
761 {
762 	DBSIGNALS *dbsignal;
763 
764 	dbsignal = 0;
765 	if (declare == 0) return(dbsignal);
766 	switch (declare->type)
767 	{
768 		case BASICDECLARE_OBJECT:
769 			dbsignal = vhdl_semobject_declare((OBJECTDECLARE *)declare->pointer);
770 			break;
771 		case BASICDECLARE_TYPE:
772 			vhdl_semtype_declare((TYPE *)declare->pointer);
773 			break;
774 		case BASICDECLARE_SUBTYPE:
775 		case BASICDECLARE_CONVERSION:
776 		case BASICDECLARE_ATTRIBUTE:
777 		case BASICDECLARE_ATT_SPEC:
778 		default:
779 			break;
780 	}
781 	return(dbsignal);
782 }
783 
784 /*
785 Module:  vhdl_semobject_declare
786 ------------------------------------------------------------------------
787 Description:
788 	Semantic analysis of object declaration.
789 ------------------------------------------------------------------------
790 Calling Sequence:  dbsignal = vhdl_semobject_declare(declare);
791 
792 Name		Type			Description
793 ----		----			-----------
794 declare		*OBJECTDECLARE	Pointer to object declaration structure.
795 dbsignal	*DBSIGNALS		Pointer to new signals, 0 if not.
796 ------------------------------------------------------------------------
797 */
vhdl_semobject_declare(OBJECTDECLARE * declare)798 DBSIGNALS *vhdl_semobject_declare(OBJECTDECLARE *declare)
799 {
800 	DBSIGNALS *signals;
801 
802 	signals = 0;
803 	if (declare == 0) return(signals);
804 	switch (declare->type)
805 	{
806 		case OBJECTDECLARE_SIGNAL:
807 			signals = vhdl_semsignal_declare((SIGNALDECLARE *)declare->pointer);
808 			break;
809 		case OBJECTDECLARE_CONSTANT:
810 			vhdl_semconstant_declare((CONSTANTDECLARE *)declare->pointer);
811 			break;
812 		case OBJECTDECLARE_VARIABLE:
813 		case OBJECTDECLARE_ALIAS:
814 		default:
815 			break;
816 	}
817 	return(signals);
818 }
819 
820 /*
821 Module:  vhdl_semsignal_declare
822 ------------------------------------------------------------------------
823 Description:
824 	Semantic analysis of signal declaration.
825 ------------------------------------------------------------------------
826 Calling Sequence:  signals = vhdl_semsignal_declare(signal);
827 
828 Name		Type			Description
829 ----		----			-----------
830 signal		*SIGNALDECLARE	Pointer to signal declaration.
831 signals		*DBSIGNALS		Pointer to new signals.
832 ------------------------------------------------------------------------
833 */
vhdl_semsignal_declare(SIGNALDECLARE * signal)834 DBSIGNALS *vhdl_semsignal_declare(SIGNALDECLARE *signal)
835 {
836 	DBSIGNALS *signals, *newsignal;
837 	IDENTLIST *sig, *type;
838 	SYMBOLTREE *symbol;
839 
840 	signals = 0;
841 	if (signal == 0) return(signals);
842 
843 	/* check for valid type */
844 	type = (IDENTLIST *)vhdl_getnameident(signal->subtype->type);
845 	if ((symbol = vhdl_searchsymbol((IDENTTABLE *)type, vhdl_symbols)) == 0 ||
846 		symbol->type != SYMBOL_TYPE)
847 	{
848 		vhdl_reporterrormsg(vhdl_getnametoken(signal->subtype->type), _("Bad type"));
849 	}
850 
851 	/* check each signal in signal list for uniqueness */
852 	for (sig = signal->names; sig != 0; sig = sig->next)
853 	{
854 		if (vhdl_searchsymbol((IDENTTABLE *)sig->identifier->pointer, vhdl_symbols))
855 		{
856 			vhdl_reporterrormsg(sig->identifier, _("Signal previously defined"));
857 		} else
858 		{
859 			newsignal = (DBSIGNALS *)emalloc((INTBIG)sizeof(DBSIGNALS), vhdl_tool->cluster);
860 			newsignal->name = (IDENTTABLE *)sig->identifier->pointer;
861 			if (symbol)
862 			{
863 				newsignal->type = (DBLTYPE *)symbol->pointer;
864 			} else
865 			{
866 				newsignal->type = 0;
867 			}
868 			newsignal->next = signals;
869 			signals = newsignal;
870 			vhdl_addsymbol(newsignal->name, (INTBIG)SYMBOL_SIGNAL, (CHAR *)newsignal, vhdl_symbols);
871 		}
872 	}
873 
874 	return(signals);
875 }
876 
877 /*
878 Module:  vhdl_semconstant_declare
879 ------------------------------------------------------------------------
880 Description:
881 	Semantic analysis of constant declaration.
882 ------------------------------------------------------------------------
883 Calling Sequence:  vhdl_semconstant_declare(constant);
884 
885 Name		Type				Description
886 ----		----				-----------
887 constant	*CONSTANTDECLARE	Pointer to constant declare structure.
888 ------------------------------------------------------------------------
889 */
vhdl_semconstant_declare(CONSTANTDECLARE * constant)890 void vhdl_semconstant_declare(CONSTANTDECLARE *constant)
891 {
892 	INTBIG value;
893 
894 	if (constant == 0) return;
895 
896 	/* check if name exists in top level of symbol tree */
897 	if (vhdl_searchfsymbol((IDENTTABLE *)constant->identifier->pointer, vhdl_symbols))
898 	{
899 		vhdl_reporterrormsg(constant->identifier, _("Symbol previously defined"));
900 	} else
901 	{
902 		value = vhdl_evalexpression(constant->expression);
903 		vhdl_addsymbol((IDENTTABLE *)constant->identifier->pointer, (INTBIG)SYMBOL_CONSTANT,
904 			(CHAR *)value, vhdl_symbols);
905 	}
906 }
907 
908 /*
909 Module:  vhdl_semset_of_statements
910 ------------------------------------------------------------------------
911 Description:
912 	Semantic analysis of architectural set of statements in a body.
913 ------------------------------------------------------------------------
914 Calling Sequence:  dbstates = vhdl_semset_of_statements(state);
915 
916 Name		Type			Description
917 ----		----			-----------
918 state		*STATEMENTS		Pointer to architectural statements.
919 dbstates	*DBSTATEMENTS	Pointer to created statements.
920 ------------------------------------------------------------------------
921 */
vhdl_semset_of_statements(STATEMENTS * state)922 DBSTATEMENTS *vhdl_semset_of_statements(STATEMENTS *state)
923 {
924 	DBSTATEMENTS *dbstates, *newstate;
925 	DBINSTANCE *newinstance, *endinstance;
926 
927 	dbstates = 0;
928 	if (state == 0) return(dbstates);
929 	dbstates = (DBSTATEMENTS *)emalloc((INTBIG)sizeof(DBSTATEMENTS), vhdl_tool->cluster);
930 	dbstates->instances = endinstance = 0;
931 	for (; state != 0; state = state->next)
932 	{
933 		switch (state->type)
934 		{
935 			case ARCHSTATE_INSTANCE:
936 				newinstance = vhdl_seminstance((VINSTANCE *)state->pointer);
937 				if (endinstance == 0)
938 				{
939 					dbstates->instances = endinstance = newinstance;
940 				} else
941 				{
942 					endinstance->next = newinstance;
943 					endinstance = newinstance;
944 				}
945 				break;
946 			case ARCHSTATE_GENERATE:
947 				newstate = vhdl_semgenerate((GENERATE *)state->pointer);
948 				if (newstate != 0)
949 				{
950 					for (newinstance = newstate->instances; newinstance != 0;
951 						newinstance = newinstance->next)
952 					{
953 						if (endinstance == 0)
954 						{
955 							dbstates->instances = endinstance = newinstance;
956 						} else
957 						{
958 							endinstance->next = newinstance;
959 							endinstance = newinstance;
960 						}
961 					}
962 					efree((CHAR *)newstate);
963 				}
964 				break;
965 			case ARCHSTATE_SIG_ASSIGN:
966 			case ARCHSTATE_IF:
967 			case ARCHSTATE_CASE:
968 			default:
969 				break;
970 		}
971 	}
972 	return(dbstates);
973 }
974 
975 /*
976 Module:  vhdl_seminstance
977 ------------------------------------------------------------------------
978 Description:
979 	Semantic analysis of instance for an architectural body.
980 ------------------------------------------------------------------------
981 Calling Sequence:  dbinst = vhdl_seminstance(inst);
982 
983 Name		Type		Description
984 ----		----		-----------
985 inst		*VINSTANCE	Pointer to instance structure.
986 dbinst		*DBINSTANCE	Pointer to created instance.
987 ------------------------------------------------------------------------
988 */
vhdl_seminstance(VINSTANCE * inst)989 DBINSTANCE *vhdl_seminstance(VINSTANCE *inst)
990 {
991 	DBINSTANCE *dbinst;
992 	SYMBOLTREE *symbol;
993 	DBCOMPONENTS *compo;
994 	INTBIG iport_num, cport_num;
995 	APORTLIST *aplist;
996 	DBPORTLIST *plist;
997 	CHAR sbuffer[80], *sptr;
998 	IDENTTABLE *ikey;
999 	DBAPORTLIST *dbaport, *enddbaport;
1000 #ifndef VHDL50
1001 	INTBIG i;
1002 	CHAR temp[20];
1003 #endif
1004 
1005 	dbinst = 0;
1006 	if (inst == 0) return(dbinst);
1007 #ifdef VHDL50
1008 	/* check that instance name unique */
1009 	if (!inst->name)
1010 	{
1011 		if (vhdl_warnflag)
1012 			ttyputmsg(_("WARNING - no name for node instance, adding default"));
1013 
1014 		/* create instance name */
1015 		esnprintf(sbuffer, 80, x_("%s_%ld"), vhdl_default_name, vhdl_default_num++);
1016 #else
1017 	/* If inside a "for generate" make unique instance name
1018 	 * from instance label and vhdl_for_tags[]
1019 	 */
1020 	if (vhdl_for_level > 0)
1021 	{
1022 		if (!inst->name) estrcpy(sbuffer, x_("no_name")); else
1023 			estrcpy(sbuffer,((IDENTTABLE *)(inst->name->pointer))->string);
1024 		for (i=1; i<=vhdl_for_level; ++i)
1025 		{
1026 			esnprintf(temp, 20, x_("_%ld"), (INTBIG)vhdl_for_tags[i]);
1027 			estrcat(sbuffer,temp);
1028 		}
1029 #endif
1030 		/* add to global name space */
1031 		if ((ikey = vhdl_findidentkey(sbuffer)) == 0)
1032 		{
1033 			(void)allocstring(&sptr, sbuffer, vhdl_tool->cluster);
1034 			ikey = vhdl_makeidentkey(sptr);
1035 			if (ikey == 0) return((DBINSTANCE *)0);
1036 		}
1037 	} else
1038 	{
1039 		ikey = (IDENTTABLE *)inst->name->pointer;
1040 	}
1041 	dbinst = (DBINSTANCE *)emalloc((INTBIG)sizeof(DBINSTANCE), vhdl_tool->cluster);
1042 	dbinst->name = ikey;
1043 	dbinst->compo = 0;
1044 	dbinst->ports = enddbaport = 0;
1045 	dbinst->next = 0;
1046 	if (vhdl_searchsymbol(dbinst->name, vhdl_symbols))
1047 	{
1048 		vhdl_reporterrormsg(inst->name, _("Instance name previously defined"));
1049 	} else
1050 	{
1051 		vhdl_addsymbol(dbinst->name, (INTBIG)SYMBOL_INSTANCE, (CHAR *)dbinst, vhdl_symbols);
1052 	}
1053 
1054 	/* check that instance entity is among component list */
1055 	compo = 0;
1056 	symbol = vhdl_searchsymbol((IDENTTABLE *)inst->entity->identifier->pointer, vhdl_symbols);
1057 	if (symbol == 0)
1058 	{
1059 		vhdl_reporterrormsg(inst->entity->identifier, _("Instance references undefined component"));
1060 	} else if (symbol->type != SYMBOL_COMPONENT)
1061 	{
1062 		vhdl_reporterrormsg(inst->entity->identifier, _("Symbol is not a component reference"));
1063 	} else
1064 	{
1065 		compo = (DBCOMPONENTS *)symbol->pointer;
1066 		dbinst->compo = compo;
1067 
1068 		/* check that number of ports match */
1069 		iport_num = 0;
1070 		for (aplist = inst->ports; aplist != 0; aplist = aplist->next)
1071 		{
1072 			iport_num++;
1073 		}
1074 		cport_num = 0;
1075 		for (plist = compo->ports; plist != 0; plist = plist->next)
1076 		{
1077 			cport_num++;
1078 		}
1079 		if (iport_num != cport_num)
1080 		{
1081 			vhdl_reporterrormsg(vhdl_getnametoken((VNAME *)inst->ports->pointer),
1082 				_("Instance has different number of ports that component"));
1083 			return((DBINSTANCE *)0);
1084 		}
1085 	}
1086 
1087 	/* check that ports of instance are either signals or entity port */
1088 	/* note 0 ports are allowed for position placement */
1089 	if (compo)
1090 	{
1091 		plist = compo->ports;
1092 	} else
1093 	{
1094 		plist = 0;
1095 	}
1096 	for (aplist = inst->ports; aplist != 0; aplist = aplist->next)
1097 	{
1098 		dbaport = (DBAPORTLIST *)emalloc((INTBIG)sizeof(DBAPORTLIST), vhdl_tool->cluster);
1099 		dbaport->name = 0;
1100 		dbaport->port = plist;
1101 		if (plist)
1102 		{
1103 			plist = plist->next;
1104 		}
1105 		dbaport->flags = 0;
1106 		dbaport->next = 0;
1107 		if (enddbaport == 0)
1108 		{
1109 			dbinst->ports = enddbaport = dbaport;
1110 		} else
1111 		{
1112 			enddbaport->next = dbaport;
1113 			enddbaport = dbaport;
1114 		}
1115 		if (aplist->pointer == 0) continue;
1116 		dbaport->name = vhdl_semname((VNAME *)aplist->pointer);
1117 
1118 		/* check that name is reference to a signal or formal port */
1119 		vhdl_semaport_check((VNAME *)aplist->pointer);
1120 	}
1121 
1122 	return(dbinst);
1123 }
1124 
1125 /*
1126 Module:  vhdl_semgenerate
1127 ------------------------------------------------------------------------
1128 Description:
1129 	Semantic analysis of generate statement.
1130 ------------------------------------------------------------------------
1131 Calling Sequence:  dbstates = vhdl_semgenerate(gen);
1132 
1133 Name		Type			Description
1134 ----		----			-----------
1135 gen			*GENERATE		Pointer to generate statement.
1136 dbstates	*DBSTATEMENTS	Pointer to generated statements.
1137 ------------------------------------------------------------------------
1138 */
1139 DBSTATEMENTS *vhdl_semgenerate(GENERATE *gen)
1140 {
1141 	DBSTATEMENTS *dbstates, *oldstates;
1142 	DBINSTANCE *inst, *endinst;
1143 	GENSCHEME *scheme;
1144 	SYMBOLTREE *symbol;
1145 	INTBIG temp;
1146 	DBDISCRETERANGE *drange;
1147 
1148 	dbstates = 0;
1149 	if (gen == 0) return(dbstates);
1150 
1151 	/* check label */
1152 #ifdef VHDL50
1153 	if (gen->label != 0)
1154 	{
1155 #else
1156 	/* For IEEE standard, check label only if not inside a for generate */
1157 	/* Not a perfect implementation, but label is not used for anything */
1158 	/* in this situation.  This is easier to check in the parser...     */
1159 	if (gen->label != 0 && vhdl_for_level == 0)
1160 	{
1161 #endif
1162 		/* check label for uniqueness */
1163 		if (vhdl_searchsymbol((IDENTTABLE *)gen->label->pointer, vhdl_symbols))
1164 		{
1165 			vhdl_reporterrormsg(gen->label, _("Symbol previously defined"));
1166 		} else
1167 		{
1168 			vhdl_addsymbol((IDENTTABLE *)gen->label->pointer, (INTBIG)SYMBOL_LABEL, (CHAR *)0,
1169 				vhdl_symbols);
1170 			estrcpy(vhdl_default_name, ((IDENTTABLE *)(gen->label->pointer))->string);
1171 #ifdef VHDL50
1172 			vhdl_default_num = 0;
1173 #endif
1174 		}
1175 	}
1176 
1177 	/* check generation scheme */
1178 	scheme = gen->gen_scheme;
1179 	if (scheme == 0)
1180 		return(dbstates);
1181 	switch (scheme->scheme)
1182 	{
1183 		case GENSCHEME_FOR:
1184 
1185 #ifndef VHDL50
1186 			/* Increment vhdl_for_level and clear tag */
1187 			vhdl_for_tags[++vhdl_for_level] = 0;
1188 #endif
1189 			/* create new local symbol table */
1190 			vhdl_symbols = vhdl_pushsymbols(vhdl_symbols);
1191 
1192 			/* add identifier as a variable symbol */
1193 			symbol = vhdl_addsymbol((IDENTTABLE *)scheme->identifier->pointer, (INTBIG)SYMBOL_VARIABLE,
1194 				(CHAR *)0, vhdl_symbols);
1195 
1196 			/* determine direction of discrete range (ascending or descending) */
1197 			drange = vhdl_semdiscrete_range(scheme->range);
1198 			if (drange->start > drange->end)
1199 			{
1200 				temp = drange->end;
1201 				drange->end = drange->start;
1202 				drange->start = temp;
1203 			}
1204 			oldstates = 0;
1205 			for (temp = drange->start; temp <= drange->end; temp++)
1206 			{
1207 				symbol->pointer = (CHAR *)temp;
1208 				dbstates = vhdl_semset_of_statements(gen->statements);
1209 #ifndef VHDL50
1210 				++vhdl_for_tags[vhdl_for_level];
1211 #endif
1212 				if (dbstates)
1213 				{
1214 					if (oldstates == 0)
1215 					{
1216 						oldstates = dbstates;
1217 						endinst = dbstates->instances;
1218 						if (endinst)
1219 						{
1220 							while (endinst->next)
1221 							{
1222 								endinst = endinst->next;
1223 							}
1224 						}
1225 					} else
1226 					{
1227 						for (inst = dbstates->instances; inst != 0; inst = inst->next)
1228 						{
1229 							if (endinst == 0)
1230 							{
1231 								oldstates->instances = endinst = inst;
1232 							} else
1233 							{
1234 								endinst->next = inst;
1235 								endinst = inst;
1236 							}
1237 						}
1238 						efree((CHAR *)dbstates);
1239 					}
1240 				}
1241 			}
1242 			efree((CHAR *)drange);
1243 			dbstates = oldstates;
1244 
1245 			/* restore old symbol table */
1246 			vhdl_symbols = vhdl_popsymbols(vhdl_symbols);
1247 #ifndef VHDL50
1248 			--vhdl_for_level;
1249 #endif
1250 			break;
1251 
1252 		case GENSCHEME_IF:
1253 			if (vhdl_evalexpression(scheme->condition))
1254 			{
1255 				dbstates = vhdl_semset_of_statements(gen->statements);
1256 			}
1257 		default:
1258 			break;
1259 	}
1260 	return(dbstates);
1261 }
1262 
1263 #ifdef VHDL50
1264 /*
1265 Module:  vhdl_semwith
1266 ------------------------------------------------------------------------
1267 Description:
1268 	Semantic analysis of a with statement. Attempt to add package name
1269 	to symbol list.
1270 ------------------------------------------------------------------------
1271 Calling Sequence:  vhdl_semwith(with);
1272 
1273 Name		Type		Description
1274 ----		----		-----------
1275 with		*WITH		Pointer to with parse structure.
1276 ------------------------------------------------------------------------
1277 */
1278 void vhdl_semwith(WITH *with)
1279 {
1280 	SYMBOLTREE *symbol;
1281 
1282 	for ( ; with != 0; with = with->next)
1283 	{
1284 		symbol = vhdl_searchsymbol((IDENTTABLE *)with->unit->pointer, vhdl_gsymbols);
1285 		if (symbol == 0)
1286 		{
1287 			vhdl_reporterrormsg(with->unit, _("Symbol is undefined"));
1288 			continue;
1289 		}
1290 		if (symbol->type != SYMBOL_PACKAGE)
1291 		{
1292 			vhdl_reporterrormsg(with->unit, _("Symbol is not a PACKAGE"));
1293 		} else
1294 		{
1295 			vhdl_addsymbol(symbol->value, (INTBIG)SYMBOL_PACKAGE, symbol->pointer, vhdl_symbols);
1296 		}
1297 	}
1298 	return;
1299 }
1300 #endif
1301 
1302 /*
1303 Module:  vhdl_semuse
1304 ------------------------------------------------------------------------
1305 Description:
1306 	Semantic analysis of a use statement. Add package symbols to symbol
1307 	list.
1308 ------------------------------------------------------------------------
1309 Calling Sequence:  vhdl_semuse(use);
1310 
1311 Name		Type		Description
1312 ----		----		-----------
1313 use			*USE		Pointer to use parse structure.
1314 ------------------------------------------------------------------------
1315 */
1316 void vhdl_semuse(USE *use)
1317 {
1318 	SYMBOLTREE *symbol;
1319 
1320 	for ( ; use != 0; use = use->next)
1321 	{
1322 #ifndef VHDL50
1323 		/* Note this code was lifted with minor mods from vhdl_semwith()
1324 		 * which is not a distinct function in IEEE version.
1325 		 * It seems a little redundant as written, but I don't
1326 		 * really understand what Andy was doing here.....
1327 		 */
1328 		symbol = vhdl_searchsymbol((IDENTTABLE *)use->unit->pointer, vhdl_gsymbols);
1329 		if (symbol == 0)
1330 		{
1331 			continue;
1332 		}
1333 		if (symbol->type != SYMBOL_PACKAGE)
1334 		{
1335 			vhdl_reporterrormsg(use->unit, _("Symbol is not a PACKAGE"));
1336 		} else
1337 		{
1338 			vhdl_addsymbol(symbol->value, (INTBIG)SYMBOL_PACKAGE, symbol->pointer, vhdl_symbols);
1339 		}
1340 #endif
1341 		symbol = vhdl_searchsymbol((IDENTTABLE *)use->unit->pointer, vhdl_gsymbols);
1342 		if (symbol == 0)
1343 		{
1344 			vhdl_reporterrormsg(use->unit, _("Symbol is undefined"));
1345 			continue;
1346 		}
1347 		if (symbol->type != SYMBOL_PACKAGE)
1348 		{
1349 			vhdl_reporterrormsg(use->unit, _("Symbol is not a PACKAGE"));
1350 		} else
1351 		{
1352 			vhdl_symbols = vhdl_pushsymbols(vhdl_symbols);
1353 			vhdl_symbols->root = ((DBPACKAGE *)(symbol->pointer))->root;
1354 			vhdl_symbols = vhdl_pushsymbols(vhdl_symbols);
1355 		}
1356 	}
1357 }
1358 
1359 /*
1360 Module:  vhdl_searchsymbol
1361 ------------------------------------------------------------------------
1362 Description:
1363 	Search the symbol list for a symbol of the passed value.  If found,
1364 	return a pointer to the node, if not found, return 0.  Note that
1365 	all symbol trees of the list are checked, from last to first.
1366 ------------------------------------------------------------------------
1367 Calling Sequence:  ptr = vhdl_searchsymbol(ident, sym_list);
1368 
1369 Name		Type		Description
1370 ----		----		-----------
1371 ident		*IDENTTABLE	Pointer to global name space (unique).
1372 sym_list	*SYMBOLLIST	Pointer to last (current) symbol list.
1373 ptr			*SYMBOLTREE	Pointer to tree node if found, else 0.
1374 ------------------------------------------------------------------------
1375 */
1376 SYMBOLTREE *vhdl_searchsymbol(IDENTTABLE *ident, SYMBOLLIST *sym_list)
1377 {
1378 	SYMBOLTREE *node;
1379 
1380 	for ( ; sym_list != 0; sym_list = sym_list->last)
1381 	{
1382 		if ((node = vhdl_searchsymboltree(ident, sym_list->root)))
1383 		{
1384 			return(node);
1385 		}
1386 	}
1387 	return((SYMBOLTREE *)0);
1388 }
1389 
1390 /*
1391 Module:  vhdl_searchfsymbol
1392 ------------------------------------------------------------------------
1393 Description:
1394 	Search the symbol list for the first symbol of the passed value.  If
1395 	found, return a pointer to the node, if not found, return 0.
1396 	Note that only the first symbol tree of the list is checked.
1397 ------------------------------------------------------------------------
1398 Calling Sequence:  ptr = vhdl_searchfsymbol(ident, sym_list);
1399 
1400 Name		Type		Description
1401 ----		----		-----------
1402 ident		*IDENTTABLE	Pointer to global name space (unique).
1403 sym_list	*SYMBOLLIST	Pointer to last (current) symbol list.
1404 ptr			*SYMBOLTREE	Pointer to tree node if found, else 0.
1405 ------------------------------------------------------------------------
1406 */
1407 SYMBOLTREE *vhdl_searchfsymbol(IDENTTABLE *ident, SYMBOLLIST *sym_list)
1408 {
1409 	SYMBOLTREE *node;
1410 
1411 	if (sym_list)
1412 	{
1413 		if ((node = vhdl_searchsymboltree(ident, sym_list->root)))
1414 		{
1415 			return(node);
1416 		}
1417 	}
1418 	return((SYMBOLTREE *)0);
1419 }
1420 
1421 /*
1422 Module:  vhdl_searchsymboltree
1423 ------------------------------------------------------------------------
1424 Description:
1425 	Recursive search of a symbol tree for a particular value.  Return
1426 	0 if not found or address of tree node if found.
1427 ------------------------------------------------------------------------
1428 Calling Sequence:  node = vhdl_searchsymboltree(value, nptr);
1429 
1430 Name		Type		Description
1431 ----		----		-----------
1432 value		*IDENTTABLE	Pointer to identifier in namespace.
1433 nptr		*SYMBOLTREE	Pointer to current node in tree.
1434 node		*SYMBOLTREE	Returned pointer to node, 0 if not
1435 								found.
1436 ------------------------------------------------------------------------
1437 */
1438 SYMBOLTREE *vhdl_searchsymboltree(IDENTTABLE *value, SYMBOLTREE *nptr)
1439 {
1440 	if (nptr == 0) return((SYMBOLTREE *)0);
1441 	if (value < nptr->value) return(vhdl_searchsymboltree(value, nptr->lptr));
1442 	if (value > nptr->value) return(vhdl_searchsymboltree(value, nptr->rptr));
1443 	return(nptr);
1444 }
1445 
1446 /*
1447 Module:  vhdl_addsymbol
1448 ------------------------------------------------------------------------
1449 Description:
1450 	Add a symbol to the symbol tree at the current symbol list.
1451 	Return pointer to created symbol.
1452 ------------------------------------------------------------------------
1453 Calling Sequence:  symbol = vhdl_addsymbol(value, type, pointer, sym_list);
1454 
1455 Name		Type		Description
1456 ----		----		-----------
1457 value		*IDENTTABLE	Pointer to identifier in namespace.
1458 type		INTBIG		Type of symbol.
1459 pointer		*char		Generic pointer to symbol.
1460 sym_list	*SYMBOLLIST	Pointer to symbol list.
1461 symbol		*SYMBOLTREE	Pointer to created symbol.
1462 ------------------------------------------------------------------------
1463 */
1464 SYMBOLTREE *vhdl_addsymbol(IDENTTABLE *value, INTBIG type, CHAR *pointer, SYMBOLLIST *sym_list)
1465 {
1466 	SYMBOLTREE *symbol;
1467 
1468 	if (sym_list->root)
1469 	{
1470 		symbol = vhdl_addsymboltree(value, (INTBIG)type, pointer, sym_list->root);
1471 	} else
1472 	{
1473 		sym_list->root = (SYMBOLTREE *)emalloc((INTBIG)sizeof(SYMBOLTREE), vhdl_tool->cluster);
1474 		sym_list->root->value = value;
1475 		sym_list->root->type = type;
1476 		sym_list->root->pointer = pointer;
1477 		sym_list->root->lptr = 0;
1478 		sym_list->root->rptr = 0;
1479 		symbol = sym_list->root;
1480 	}
1481 	return(symbol);
1482 }
1483 
1484 /*
1485 Module:  vhdl_addsymboltree
1486 ------------------------------------------------------------------------
1487 Description:
1488 	Add passed item to the indicated symbol tree.  Assume the item does
1489 	have a root.  Return the pointer to the created symbol.
1490 ------------------------------------------------------------------------
1491 Calling Sequence:  symbol = vhdl_addsymboltree(ident, value, pointer, nptr);
1492 
1493 Name		Type		Description
1494 ----		----		-----------
1495 ident		*IDENTTABLE	Pointer to identifier table (unique).
1496 type		INTBIG		Type of symbol.
1497 pointer		*char		Generic pointer to entity.
1498 nptr		*SYMBOLTREE	Pointer to current tree node.
1499 symbol		*SYMBOLTREE	Pointer to created symbol.
1500 ------------------------------------------------------------------------
1501 */
1502 SYMBOLTREE *vhdl_addsymboltree(IDENTTABLE *value, INTBIG type, CHAR *pointer, SYMBOLTREE *nptr)
1503 {
1504 	SYMBOLTREE **tptr, *newnode;
1505 
1506 	if (value < nptr->value)
1507 	{
1508 		if (nptr->lptr)
1509 		{
1510 			newnode = vhdl_addsymboltree(value, (INTBIG)type, pointer, nptr->lptr);
1511 			return(newnode);
1512 		}
1513 		tptr = &nptr->lptr;
1514 	} else if (value > nptr->value)
1515 	{
1516 		if (nptr->rptr)
1517 		{
1518 			newnode = vhdl_addsymboltree(value, (INTBIG)type, pointer, nptr->rptr);
1519 			return(newnode);
1520 		}
1521 		tptr = &nptr->rptr;
1522 	} else
1523 	{
1524 		ttyputmsg(_("ERROR - symbol %s already exists"), value->string);
1525 		return((SYMBOLTREE *)0);
1526 	}
1527 
1528 	/* create new node */
1529 	newnode = (SYMBOLTREE *)emalloc((INTBIG)sizeof(SYMBOLTREE), vhdl_tool->cluster);
1530 	newnode->value = value;
1531 	newnode->type = type;
1532 	newnode->pointer = pointer;
1533 	newnode->lptr = newnode->rptr = 0;
1534 	*tptr = newnode;
1535 	return(newnode);
1536 }
1537 
1538 /*
1539 Module:  vhdl_pushsymbols
1540 ------------------------------------------------------------------------
1541 Description:
1542 	Add a new symbol tree to the symbol list.
1543 ------------------------------------------------------------------------
1544 Calling Sequence:  new_sym_list = vhdl_pushsymbols(old_sym_list);
1545 
1546 Name			Type		Description
1547 ----			----		-----------
1548 old_sym_list	*SYMBOLLIST	Pointer to old symbol list.
1549 new_sym_list	*SYMBOLLIST	Returned pointer to new symbol list.
1550 ------------------------------------------------------------------------
1551 */
1552 SYMBOLLIST *vhdl_pushsymbols(SYMBOLLIST *old_sym_list)
1553 {
1554 	SYMBOLLIST *new_sym_list;
1555 
1556 	new_sym_list = (SYMBOLLIST *)emalloc((INTBIG)sizeof(SYMBOLLIST), vhdl_tool->cluster);
1557 	new_sym_list->root = 0;
1558 	new_sym_list->last = old_sym_list;
1559 
1560 	/* save in global list */
1561 	new_sym_list->next = vhdl_symbollists;
1562 	vhdl_symbollists = new_sym_list;
1563 	return(new_sym_list);
1564 }
1565 
1566 /*
1567 Module:  vhdl_popsymbols
1568 ------------------------------------------------------------------------
1569 Description:
1570 	Pop off the top most symbol list and return next symbol list.
1571 ------------------------------------------------------------------------
1572 Calling Sequence:  new_sym_list = vhdl_popsymbols(old_sym_list);
1573 
1574 Name			Type		Description
1575 ----			----		-----------
1576 old_sym_list	*SYMBOLLIST	Pointer to old symbol list.
1577 new_sym_list	*SYMBOLLIST	Returned pointer to new symbol list.
1578 ------------------------------------------------------------------------
1579 */
1580 SYMBOLLIST *vhdl_popsymbols(SYMBOLLIST *old_sym_list)
1581 {
1582 	SYMBOLLIST *new_sym_list;
1583 
1584 	if (!old_sym_list)
1585 	{
1586 		ttyputmsg(_("ERROR - trying to pop nonexistant symbol list."));
1587 		return((SYMBOLLIST *)0);
1588 	}
1589 	new_sym_list = old_sym_list->last;
1590 	return(new_sym_list);
1591 }
1592 
1593 /*
1594 Module:  vhdl_semaport_check
1595 ------------------------------------------------------------------------
1596 Description:
1597 	Check that the passed name which is a reference on an actual port
1598 	list is a signal of formal port.
1599 ------------------------------------------------------------------------
1600 Calling Sequence:  vhdl_semaport_check(name);
1601 
1602 Name		Type		Description
1603 ----		----		-----------
1604 name		*VNAME		Pointer to name parse structure.
1605 ------------------------------------------------------------------------
1606 */
1607 void vhdl_semaport_check(VNAME *name)
1608 {
1609 	CONCATENATEDNAME *cat;
1610 
1611 	switch (name->type)
1612 	{
1613 		case NAME_SINGLE:
1614 			vhdl_semaport_check_single_name((SINGLENAME *)name->pointer);
1615 			break;
1616 		case NAME_CONCATENATE:
1617 			for (cat = (CONCATENATEDNAME *)name->pointer; cat; cat = cat->next)
1618 			{
1619 				vhdl_semaport_check_single_name(cat->name);
1620 			}
1621 			break;
1622 		default:
1623 			break;
1624 	}
1625 	return;
1626 }
1627 
1628 /*
1629 Module:  vhdl_semaport_check_single_name
1630 ------------------------------------------------------------------------
1631 Description:
1632 	Check that the passed single name references a signal or formal port.
1633 ------------------------------------------------------------------------
1634 Calling Sequence:  vhdl_semaport_check_single_name(sname);
1635 
1636 Name		Type		Description
1637 ----		----		-----------
1638 sname		*SINGLENAME	Pointer to single name structure.
1639 ------------------------------------------------------------------------
1640 */
1641 void vhdl_semaport_check_single_name(SINGLENAME *sname)
1642 {
1643 	SIMPLENAME *simname;
1644 	IDENTTABLE *ident;
1645 	SYMBOLTREE *symbol;
1646 	INDEXEDNAME *iname;
1647 
1648 	switch (sname->type)
1649 	{
1650 		case SINGLENAME_SIMPLE:
1651 			simname = (SIMPLENAME *)sname->pointer;
1652 			ident = (IDENTTABLE *)simname->identifier->pointer;
1653 			if ((symbol = vhdl_searchsymbol(ident, vhdl_symbols)) == 0 ||
1654 				(symbol->type != SYMBOL_FPORT && symbol->type != SYMBOL_SIGNAL))
1655 			{
1656 				vhdl_reporterrormsg(simname->identifier,
1657 					_("Instance port has reference to unknown port"));
1658 			}
1659 			break;
1660 		case SINGLENAME_INDEXED:
1661 			iname = (INDEXEDNAME *)sname->pointer;
1662 			ident = (IDENTTABLE *)vhdl_getprefixident(iname->prefix);
1663 			if ((symbol = vhdl_searchsymbol(ident, vhdl_symbols)) == 0 ||
1664 				(symbol->type != SYMBOL_FPORT && symbol->type != SYMBOL_SIGNAL))
1665 			{
1666 				vhdl_reporterrormsg(vhdl_getprefixtoken(iname->prefix),
1667 					_("Instance port has reference to unknown port"));
1668 			}
1669 			break;
1670 		default:
1671 			break;
1672 	}
1673 	return;
1674 }
1675 
1676 /********************* This was the module "types.c" *********************/
1677 
1678 /*
1679 Module:  vhdl_parsetype
1680 ------------------------------------------------------------------------
1681 Description:
1682 	Parse a type declaration of the form:
1683 
1684 		type_declaration ::=
1685 			TYPE identifier IS type_definition ;
1686 ------------------------------------------------------------------------
1687 Calling Sequence:  type = vhdl_parsetype();
1688 
1689 Name		Type		Description
1690 ----		----		-----------
1691 type		*TYPE		Pointer to type declaration structure.
1692 ------------------------------------------------------------------------
1693 */
1694 TYPE *vhdl_parsetype(void)
1695 {
1696 	TYPE *type;
1697 	TOKENLIST *ident;
1698 	INTBIG type_define;
1699 	CHAR *pointer;
1700 
1701 	type = NULL;
1702 
1703 	/* should be at keyword TYPE */
1704 	if (!vhdl_keysame(vhdl_nexttoken, KEY_TYPE))
1705 	{
1706 		vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting keyword TYPE"));
1707 		vhdl_getnexttoken();
1708 		return(type);
1709 	}
1710 	vhdl_getnexttoken();
1711 
1712 	/* should be at type identifier */
1713 	if (vhdl_nexttoken->token != TOKEN_IDENTIFIER)
1714 	{
1715 		vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting an identifier"));
1716 		vhdl_getnexttoken();
1717 		return(type);
1718 	}
1719 	ident = vhdl_nexttoken;
1720 	vhdl_getnexttoken();
1721 
1722 	/* should be keyword IS */
1723 	if (!vhdl_keysame(vhdl_nexttoken, KEY_IS))
1724 	{
1725 		vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting keyword IS"));
1726 		vhdl_getnexttoken();
1727 		return(type);
1728 	}
1729 	vhdl_getnexttoken();
1730 
1731 	/* parse type definition */
1732 	if (vhdl_keysame(vhdl_nexttoken, KEY_ARRAY))
1733 	{
1734 		type_define = TYPE_COMPOSITE;
1735 		pointer = (CHAR *)vhdl_parsecomposite_type();
1736 	} else if (vhdl_keysame(vhdl_nexttoken, KEY_RECORD))
1737 	{
1738 		type_define = TYPE_COMPOSITE;
1739 		pointer = (CHAR *)vhdl_parsecomposite_type();
1740 	} else if (vhdl_keysame(vhdl_nexttoken, KEY_RANGE))
1741 	{
1742 		type_define = TYPE_SCALAR;
1743 		pointer = vhdl_parsescalar_type();
1744 	} else if (vhdl_nexttoken->token == TOKEN_LEFTBRACKET)
1745 	{
1746 		type_define = TYPE_SCALAR;
1747 		pointer = vhdl_parsescalar_type();
1748 	} else
1749 	{
1750 		vhdl_reporterrormsg(vhdl_nexttoken, _("Invalid type definition"));
1751 		vhdl_getnexttoken();
1752 		return(type);
1753 	}
1754 
1755 	/* should be at semicolon */
1756 	if (vhdl_nexttoken->token != TOKEN_SEMICOLON)
1757 	{
1758 		vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting a semicolon"));
1759 		vhdl_getnexttoken();
1760 		return(type);
1761 	}
1762 	vhdl_getnexttoken();
1763 
1764 	type = (TYPE *)emalloc((INTBIG)sizeof(TYPE), vhdl_tool->cluster);
1765 	type->identifier = ident;
1766 	type->type = type_define;
1767 	type->pointer = pointer;
1768 
1769 	return(type);
1770 }
1771 
1772 CHAR *vhdl_parsescalar_type(void) { return((CHAR *)NULL); }
1773 
1774 /*
1775 Module:  vhdl_parsecomposite_type
1776 ------------------------------------------------------------------------
1777 Description:
1778 	Parse a composite type definition of the form:
1779 
1780 		composite_type_definition ::=
1781 			  array_type_definition
1782 			| record_type_definition
1783 ------------------------------------------------------------------------
1784 */
1785 COMPOSITE *vhdl_parsecomposite_type(void)
1786 {
1787 	COMPOSITE *compo;
1788 	INTBIG type;
1789 	CHAR *pointer;
1790 
1791 	compo = NULL;
1792 
1793 	/* should be ARRAY or RECORD keyword */
1794 	if (vhdl_keysame(vhdl_nexttoken, KEY_ARRAY))
1795 	{
1796 		type = COMPOSITE_ARRAY;
1797 		pointer = (CHAR *)vhdl_parsearray_type();
1798 	} else if (vhdl_keysame(vhdl_nexttoken, KEY_RECORD))
1799 	{
1800 		type = COMPOSITE_RECORD;
1801 		pointer = vhdl_parserecord_type();
1802 	} else
1803 	{
1804 		vhdl_reporterrormsg(vhdl_nexttoken, _("Invalid composite type"));
1805 		vhdl_getnexttoken();
1806 		return(compo);
1807 	}
1808 
1809 	compo = (COMPOSITE *)emalloc((INTBIG)sizeof(COMPOSITE), vhdl_tool->cluster);
1810 	compo->type = type;
1811 	compo->pointer = pointer;
1812 
1813 	return(compo);
1814 }
1815 
1816 CHAR *vhdl_parserecord_type() { return((CHAR *)NULL); }
1817 
1818 /*
1819 Module:  vhdl_parsearray_type
1820 ------------------------------------------------------------------------
1821 Description:
1822 	Parse an array type definition of the form:
1823 
1824 		array_type_definition ::=
1825 			  unconstrained_array_definition
1826 			| constrained_array_definition
1827 
1828 		unconstrained_array_definition ::=
1829 			ARRAY (index_subtype_definition {, index_subtype_definition})
1830 				OF subtype_indication
1831 
1832 		constrained_array_definition ::=
1833 			ARRAY index_constraint OF subtype_indication
1834 
1835 		index_constraint ::= (discrete_range {, discrete_range})
1836 
1837 NOTE:  Only currently supporting constrained array definitions.
1838 ------------------------------------------------------------------------
1839 Calling Sequence:  array = vhdl_parsearray_type();
1840 
1841 Name		Type		Description
1842 ----		----		-----------
1843 array		*ARRAY		Pointer to array type definition.
1844 ------------------------------------------------------------------------
1845 */
1846 ARRAY *vhdl_parsearray_type(void)
1847 {
1848 	ARRAY *array;
1849 	INDEXCONSTRAINT *iconstraint, *endconstraint, *newconstraint;
1850 	SUBTYPEIND *subtype;
1851 	CONSTRAINED *constr;
1852 
1853 	array = NULL;
1854 
1855 	/* should be keyword ARRAY */
1856 	if (!vhdl_keysame(vhdl_nexttoken, KEY_ARRAY))
1857 	{
1858 		vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting keyword ARRAY"));
1859 		vhdl_getnexttoken();
1860 		return(array);
1861 	}
1862 	vhdl_getnexttoken();
1863 
1864 	/* index_constraint */
1865 	/* should be left bracket */
1866 	if (vhdl_nexttoken->token != TOKEN_LEFTBRACKET)
1867 	{
1868 		vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting a left bracket"));
1869 		vhdl_getnexttoken();
1870 		return(array);
1871 	}
1872 	vhdl_getnexttoken();
1873 
1874 	/* should at least one discrete range */
1875 	iconstraint = (INDEXCONSTRAINT *)emalloc((INTBIG)sizeof(INDEXCONSTRAINT), vhdl_tool->cluster);
1876 	iconstraint->discrete = vhdl_parsediscrete_range();
1877 	iconstraint->next = NULL;
1878 	endconstraint = iconstraint;
1879 
1880 	/* continue while comma */
1881 	while (vhdl_nexttoken->token == TOKEN_COMMA)
1882 	{
1883 		vhdl_getnexttoken();
1884 		newconstraint = (INDEXCONSTRAINT *)emalloc((INTBIG)sizeof(INDEXCONSTRAINT), vhdl_tool->cluster);
1885 		newconstraint->discrete = vhdl_parsediscrete_range();
1886 		newconstraint->next = NULL;
1887 		endconstraint->next = newconstraint;
1888 		endconstraint = newconstraint;
1889 	}
1890 
1891 	/* should be at right bracket */
1892 	if (vhdl_nexttoken->token != TOKEN_RIGHTBRACKET)
1893 	{
1894 		vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting a right bracket"));
1895 		vhdl_getnexttoken();
1896 		return(array);
1897 	}
1898 	vhdl_getnexttoken();
1899 
1900 	/* should be at keyword OF */
1901 	if (!vhdl_keysame(vhdl_nexttoken, KEY_OF))
1902 	{
1903 		vhdl_reporterrormsg(vhdl_nexttoken, _("Expecting keyword OF"));
1904 		vhdl_getnexttoken();
1905 		return(array);
1906 	}
1907 	vhdl_getnexttoken();
1908 
1909 	/* subtype_indication */
1910 	subtype = vhdl_parsesubtype_indication();
1911 
1912 	/* create array type definition */
1913 	array = (ARRAY *)emalloc((INTBIG)sizeof(ARRAY), vhdl_tool->cluster);
1914 	array->type = ARRAY_CONSTRAINED;
1915 	constr = (CONSTRAINED *)emalloc((INTBIG)sizeof(CONSTRAINED), vhdl_tool->cluster);
1916 	array->pointer = (CHAR *)constr;
1917 	constr->constraint = iconstraint;
1918 	constr->subtype = subtype;
1919 
1920 	return(array);
1921 }
1922 
1923 /*
1924 Module:  vhdl_semtype_declare
1925 ------------------------------------------------------------------------
1926 Description:
1927 	Semantic analysis of a type declaration.
1928 ------------------------------------------------------------------------
1929 Calling Sequence:  vhdl_semtype_declare(type);
1930 
1931 Name		Type		Description
1932 ----		----		-----------
1933 type		*TYPE		Pointer to type parse tree.
1934 ------------------------------------------------------------------------
1935 */
1936 void vhdl_semtype_declare(TYPE *type)
1937 {
1938 	DBLTYPE *dbtype;
1939 
1940 	dbtype = NULL;
1941 	if (type == NULL) return;
1942 
1943 	/* check that type name is distict */
1944 	if (vhdl_searchsymbol((IDENTTABLE *)type->identifier->pointer, vhdl_symbols))
1945 	{
1946 		vhdl_reporterrormsg(type->identifier, _("Identifier previously defined"));
1947 		return;
1948 	}
1949 
1950 	/* check type definition */
1951 	switch (type->type)
1952 	{
1953 		case TYPE_SCALAR:
1954 			break;
1955 		case TYPE_COMPOSITE:
1956 			dbtype = vhdl_semcomposite_type((COMPOSITE *)type->pointer);
1957 			break;
1958 		default:
1959 			break;
1960 	}
1961 
1962 	/* add symbol to list */
1963 	if (dbtype)
1964 	{
1965 		dbtype->name = (IDENTTABLE *)type->identifier->pointer;
1966 		vhdl_addsymbol(dbtype->name, (INTBIG)SYMBOL_TYPE, (CHAR *)dbtype, vhdl_symbols);
1967 	}
1968 }
1969 
1970 /*
1971 Module:  vhdl_semcomposite_type
1972 ------------------------------------------------------------------------
1973 Description:
1974 	Semantic analysis of a composite type definition.
1975 ------------------------------------------------------------------------
1976 Calling Sequence:  dbtype = vhdl_semcomposite_type(composite);
1977 
1978 Name		Type		Description
1979 ----		----		-----------
1980 composite	*COMPOSITE	Pointer to composite type structure.
1981 dbtype		*DBLTYPE	Generated db type.
1982 ------------------------------------------------------------------------
1983 */
1984 DBLTYPE *vhdl_semcomposite_type(COMPOSITE *composite)
1985 {
1986 	DBLTYPE *dbtype;
1987 
1988 	dbtype = NULL;
1989 	if (composite == NULL) return(dbtype);
1990 	switch (composite->type)
1991 	{
1992 		case COMPOSITE_ARRAY:
1993 			dbtype = vhdl_semarray_type((ARRAY *)composite->pointer);
1994 			break;
1995 		case COMPOSITE_RECORD:
1996 			break;
1997 		default:
1998 			break;
1999 	}
2000 	return(dbtype);
2001 }
2002 
2003 /*
2004 Module:  vhdl_semarray_type
2005 ------------------------------------------------------------------------
2006 Description:
2007 	Semantic analysis of an array composite type definition.
2008 ------------------------------------------------------------------------
2009 Calling Sequence:  dbtype = vhdl_semarray_type(array);
2010 
2011 Name		Type		Description
2012 ----		----		-----------
2013 array		*ARRAY		Pointer to composite array type structure.
2014 dbtype		*DBLTYPE	Pointer to generated type.
2015 ------------------------------------------------------------------------
2016 */
2017 DBLTYPE *vhdl_semarray_type(ARRAY *array)
2018 {
2019 	DBLTYPE *dbtype;
2020 
2021 	dbtype = NULL;
2022 	if (array == NULL) return(dbtype);
2023 	switch (array->type)
2024 	{
2025 		case ARRAY_UNCONSTRAINED:
2026 			break;
2027 		case ARRAY_CONSTRAINED:
2028 			dbtype = vhdl_semconstrained_array((CONSTRAINED *)array->pointer);
2029 			break;
2030 		default:
2031 			break;
2032 	}
2033 	return(dbtype);
2034 }
2035 
2036 /*
2037 Module:  vhdl_semconstrained_array
2038 ------------------------------------------------------------------------
2039 Description:
2040 	Semantic analysis of a composite constrained array type definition.
2041 ------------------------------------------------------------------------
2042 Calling Sequence:  dbtype = vhdl_semconstrained_array(constr);
2043 
2044 Name		Type			Description
2045 ----		----			-----------
2046 constr		*CONSTRAINED	Pointer to constrained array structure.
2047 dbtype		*DBLTYPE		Pointer to generated type.
2048 ------------------------------------------------------------------------
2049 */
2050 DBLTYPE *vhdl_semconstrained_array(CONSTRAINED *constr)
2051 {
2052 	DBLTYPE *dbtype;
2053 	INDEXCONSTRAINT *indexc;
2054 	DBINDEXRANGE *newrange, *endrange;
2055 
2056 	dbtype = NULL;
2057 	if (constr == NULL) return(dbtype);
2058 	dbtype = (DBLTYPE *)emalloc((INTBIG)sizeof(DBLTYPE), vhdl_tool->cluster);
2059 	dbtype->name = NULL;
2060 	dbtype->type = DBTYPE_ARRAY;
2061 	endrange = NULL;
2062 	dbtype->pointer = NULL;
2063 	dbtype->subtype = NULL;
2064 
2065 	/* check index constraint */
2066 	for (indexc = constr->constraint; indexc != NULL; indexc = indexc->next)
2067 	{
2068 		newrange = (DBINDEXRANGE *)emalloc((INTBIG)sizeof(DBINDEXRANGE), vhdl_tool->cluster);
2069 		newrange->drange = vhdl_semdiscrete_range(indexc->discrete);
2070 		newrange->next = NULL;
2071 		if (endrange == NULL)
2072 		{
2073 			endrange = newrange;
2074 			dbtype->pointer = (CHAR *)newrange;
2075 		} else
2076 		{
2077 			endrange->next = newrange;
2078 			endrange = newrange;
2079 		}
2080 	}
2081 	/* check subtype indication */
2082 	dbtype->subtype = vhdl_semsubtype_indication(constr->subtype);
2083 
2084 	return(dbtype);
2085 }
2086 
2087 /*
2088 Module:  vhdl_semdiscrete_range
2089 ------------------------------------------------------------------------
2090 Description:
2091 	Semantic analysis of a discrete range.
2092 ------------------------------------------------------------------------
2093 Calling Sequence:  dbrange = vhdl_semdiscrete_range(discrete);
2094 
2095 Name		Type				Description
2096 ----		----				-----------
2097 discrete	*DISCRETERANGE		Pointer to a discrete range structure.
2098 dbrange		*DBDISCRETERANGE	Pointer to generated range.
2099 ------------------------------------------------------------------------
2100 */
2101 DBDISCRETERANGE *vhdl_semdiscrete_range(DISCRETERANGE *discrete)
2102 {
2103 	DBDISCRETERANGE *dbrange;
2104 
2105 	dbrange = NULL;
2106 	if (discrete == NULL) return(dbrange);
2107 	switch (discrete->type)
2108 	{
2109 		case DISCRETERANGE_SUBTYPE:
2110 			break;
2111 		case DISCRETERANGE_RANGE:
2112 			dbrange = vhdl_semrange((RANGE *)discrete->pointer);
2113 			break;
2114 		default:
2115 			break;
2116 	}
2117 	return(dbrange);
2118 }
2119 
2120 /*
2121 Module:  vhdl_semrange
2122 ------------------------------------------------------------------------
2123 Description:
2124 	Semantic analysis of a range.
2125 ------------------------------------------------------------------------
2126 Calling Sequence:  dbrange = vhdl_semrange(range);
2127 
2128 Name		Type				Description
2129 ----		----				-----------
2130 range		*RANGE				Pointer to a range structure.
2131 dbrange		*DBDISCRETERANGE	Pointer to generated range.
2132 ------------------------------------------------------------------------
2133 */
2134 DBDISCRETERANGE *vhdl_semrange(RANGE *range)
2135 {
2136 	DBDISCRETERANGE *dbrange;
2137 	RANGESIMPLE *rsimp;
2138 
2139 	dbrange = NULL;
2140 	if (range == NULL) return(dbrange);
2141 	switch (range->type)
2142 	{
2143 		case RANGE_ATTRIBUTE:
2144 			break;
2145 		case RANGE_SIMPLE_EXPR:
2146 			rsimp = (RANGESIMPLE *)range->pointer;
2147 			if (rsimp)
2148 			{
2149 				dbrange = (DBDISCRETERANGE *)emalloc((INTBIG)sizeof(DBDISCRETERANGE), vhdl_tool->cluster);
2150 				dbrange->start = vhdl_evalsimpleexpr(rsimp->start);
2151 				dbrange->end = vhdl_evalsimpleexpr(rsimp->end);
2152 			}
2153 			break;
2154 		default:
2155 			break;
2156 	}
2157 	return(dbrange);
2158 }
2159 
2160 /*
2161 Module:  vhdl_semsubtype_indication
2162 ------------------------------------------------------------------------
2163 Description:
2164 	Semantic analysis of a sybtype indication.
2165 ------------------------------------------------------------------------
2166 Calling Sequence:  dbtype = vhdl_semsubtype_indication(subtype);
2167 
2168 Name		Type		Description
2169 ----		----		-----------
2170 subtype		*SUBTYPEIND	Pointer to subtype indication.
2171 dbtype		*DBLTYPE	Pointer to db type;
2172 ------------------------------------------------------------------------
2173 */
2174 DBLTYPE *vhdl_semsubtype_indication(SUBTYPEIND *subtype)
2175 {
2176 	DBLTYPE *dbtype;
2177 
2178 	dbtype = NULL;
2179 	if (subtype == NULL) return(dbtype);
2180 	dbtype = vhdl_semtype_mark(subtype->type);
2181 	return(dbtype);
2182 }
2183 
2184 /*
2185 Module:  vhdl_semtype_mark
2186 ------------------------------------------------------------------------
2187 Description:
2188 	Semantic type mark.
2189 ------------------------------------------------------------------------
2190 Calling Sequence:  dbtype = vhdl_semtype_mark(name);
2191 
2192 Name		Type		Description
2193 ----		----		-----------
2194 name		*VNAME		Pointer to type name.
2195 dbtype		*DBLTYPE	Pointer to db type.
2196 ------------------------------------------------------------------------
2197 */
2198 DBLTYPE *vhdl_semtype_mark(VNAME *name)
2199 {
2200 	DBLTYPE *dbtype;
2201 	SYMBOLTREE *symbol;
2202 
2203 	dbtype = NULL;
2204 	if (name == NULL) return(dbtype);
2205 	if ((symbol = vhdl_searchsymbol(vhdl_getnameident(name), vhdl_symbols)) == NULL ||
2206 		symbol->type != SYMBOL_TYPE)
2207 	{
2208 		vhdl_reporterrormsg(vhdl_getnametoken(name), _("Bad type"));
2209 	} else
2210 	{
2211 		dbtype = (DBLTYPE *)symbol->pointer;
2212 	}
2213 	return(dbtype);
2214 }
2215 
2216 /*
2217 Module:  vhdl_getsymboltype
2218 ------------------------------------------------------------------------
2219 Description:
2220 	Return a pointer to the type of a symbol.  If no type exists,
2221 	return a NULL.
2222 ------------------------------------------------------------------------
2223 Calling Sequence:  type = vhdl_getsymboltype(symbol);
2224 
2225 Name		Type		Description
2226 ----		----		-----------
2227 symbol		*SYMBOLTREE	Pointer to symbol.
2228 type		*DBLTYPE	Pointer to returned type, NULL if no type exists.
2229 ------------------------------------------------------------------------
2230 */
2231 DBLTYPE *vhdl_getsymboltype(SYMBOLTREE *symbol)
2232 {
2233 	DBLTYPE *type;
2234 	DBPORTLIST *fport;
2235 	DBSIGNALS *signal;
2236 
2237 	type = NULL;
2238 	if (symbol == NULL) return(type);
2239 	switch (symbol->type)
2240 	{
2241 		case SYMBOL_FPORT:
2242 			if ((fport = (DBPORTLIST *)symbol->pointer) == NULL) break;
2243 			type = fport->type;
2244 			break;
2245 		case SYMBOL_SIGNAL:
2246 			if ((signal = (DBSIGNALS *)symbol->pointer) == NULL) break;
2247 			type = signal->type;
2248 			break;
2249 		case SYMBOL_TYPE:
2250 			type = (DBLTYPE *)symbol->pointer;
2251 			break;
2252 		default:
2253 			break;
2254 	}
2255 	return(type);
2256 }
2257 
2258 /*
2259 Module:  vhdl_gettype
2260 ------------------------------------------------------------------------
2261 Description:
2262 	Return the type of an identifier.  Return NULL if no type.
2263 ------------------------------------------------------------------------
2264 Calling Sequence:  type = vhdl_gettype(ident);
2265 
2266 Name		Type		Description
2267 ----		----		-----------
2268 ident		*IDENTTABLE	Pointer to identifier.
2269 type		*DBLTYPE	Returned type, NULL if no type.
2270 ------------------------------------------------------------------------
2271 */
2272 DBLTYPE *vhdl_gettype(IDENTTABLE *ident)
2273 {
2274 	DBLTYPE *type;
2275 	SYMBOLTREE *symbol;
2276 
2277 	type = NULL;
2278 	if (ident)
2279 	{
2280 		if ((symbol = vhdl_searchsymbol(ident, vhdl_symbols)))
2281 		{
2282 			type = vhdl_getsymboltype(symbol);
2283 		}
2284 	}
2285 
2286 	return(type);
2287 }
2288 
2289 #endif  /* VHDLTOOL - at top */
2290