/[ascend]/trunk/base/generic/compiler/createinst.c
ViewVC logotype

Contents of /trunk/base/generic/compiler/createinst.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 76 - (show annotations) (download) (as text)
Mon Dec 5 17:31:00 2005 UTC (14 years ago) by johnpye
File MIME type: text/x-csrc
File size: 26647 byte(s)
More error_reporter calls.
Removed some C++-unfriendly var names.
Removed some debug messages.
Turned off compiler timing and relation debugging.
1 /*
2 * Ascend Instance Allocations Functions
3 * by Tom Epperly & Ben Allan
4 * 9/3/89
5 * Version: $Revision: 1.19 $
6 * Version control file: $RCSfile: createinst.c,v $
7 * Date last modified: $Date: 1998/03/26 20:39:41 $
8 * Last modified by: $Author: ballan $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1996 Ben Allan
13 * based on instance.c
14 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
15 *
16 * The Ascend Language Interpreter is free software; you can redistribute
17 * it and/or modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of the
19 * License, or (at your option) any later version.
20 *
21 * The Ascend Language Interpreter is distributed in hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with the program; if not, write to the Free Software Foundation,
28 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
29 * COPYING.
30 *
31 */
32 #include <stdarg.h>
33 #include "utilities/ascConfig.h"
34 #include "utilities/ascPanic.h"
35 #include "utilities/ascMalloc.h"
36 #include "general/list.h"
37 #include "general/dstring.h"
38 #include "compiler/compiler.h"
39 #include "compiler/bit.h"
40 #include "compiler/symtab.h"
41 #include "compiler/fractions.h"
42 #include "compiler/dimen.h"
43 #include "compiler/functype.h"
44 #include "compiler/types.h"
45 #include "compiler/stattypes.h"
46 #include "compiler/slist.h"
47 #include "compiler/setinstval.h"
48 #include "compiler/instance_name.h"
49 #include "compiler/instance_io.h"
50 #include "compiler/check.h"
51 #include "compiler/dump.h"
52 #include "compiler/child.h"
53 #include "compiler/childinfo.h"
54 #include "compiler/type_desc.h"
55 #include "compiler/prototype.h"
56 #include "compiler/pending.h"
57 #include "compiler/find.h"
58 #include "compiler/instance_enum.h"
59 #include "compiler/relation_type.h"
60 #include "compiler/relation.h"
61 #include "compiler/logical_relation.h"
62 #include "compiler/logrelation.h"
63 #include "compiler/relation_util.h"
64 #include "compiler/logrel_util.h"
65 #include "compiler/rel_common.h"
66 #include "compiler/case.h"
67 #include "compiler/when_util.h"
68 #include "compiler/universal.h"
69 #include "general/pool.h"
70 #include "compiler/instance_types.h"
71 /* new */
72 #include "compiler/atomsize.h"
73 #include "compiler/atomvalue.h"
74 #include "compiler/cmpfunc.h"
75 #include "compiler/copyinst.h"
76 #include "compiler/createinst.h"
77 #include "compiler/destroyinst.h"
78 #include "compiler/extinst.h"
79 #include "compiler/linkinst.h"
80 #include "compiler/instmacro.h"
81 #include "compiler/instquery.h"
82
83 #ifndef lint
84 static CONST char CreateInstModuleID[] = "$Id: createinst.c,v 1.19 1998/03/26 20:39:41 ballan Exp $";
85 #endif
86
87 void ZeroNewChildrenEntries(register struct Instance **child_ary,
88 register unsigned long int num)
89 {
90 /* initialize all the children pointers to NULL */
91 while(num--) {
92 AssertMemory(child_ary);
93 *(child_ary++) = NULL;
94 }
95 }
96
97 /*
98 * Create a new model instance. The semantics at this time is
99 * as follows: We lookup for a prototype of the model in the
100 * prototype library. If found we do a deepcopy of the instance.
101 * We do this deep copy using copy-by-reference semantics on
102 * relations. THIS may change.
103 */
104 struct Instance *CreateModelInstance(struct TypeDescription *type)
105 {
106 register struct ModelInstance *result, *proto;
107 register unsigned long num_children;
108 register CONST struct StatementList *stats;
109
110 proto = MOD_INST(LookupPrototype(GetName(type)));
111 if (proto==NULL) {
112 CopyTypeDesc(type);
113 num_children = ChildListLen(GetChildList(type));
114 stats = GetStatementList(type);
115 result = MOD_INST(ascmalloc((unsigned)sizeof(struct ModelInstance)+
116 (unsigned)num_children*
117 (unsigned)sizeof(struct Instance *)));
118 result->t = MODEL_INST;
119 result->pending_entry = NULL;
120 result->interface_ptr = NULL;
121 result->parents = gl_create(AVG_PARENTS);
122 result->whens = NULL;
123 result->desc = type;
124 result->alike_ptr = INST(result);
125 result->visited = 0;
126 result->tmp_num = 0;
127 result->anon_flags = 0x0;
128 #if (LONGCHILDREN == 1)
129 result->padding = INT_MAX;
130 #endif
131
132 result->executed = CreateFBList(gl_length(GetList(stats)));
133 ZeroNewChildrenEntries(MOD_CHILD(result,0),num_children);
134 AssertMemory(result);
135 if (GetUniversalFlag(type)) {
136 AddUniversalInstance(GetUniversalTable(),type,INST(result));
137 }
138 return INST(result);
139 } else { /* instance has a prototype which may be copied */
140 result = MOD_INST(CopyInstance(INST(proto)));
141 return INST(result);
142 }
143 }
144
145 struct Instance *CreateDummyInstance(struct TypeDescription *gdt)
146 {
147 struct GlobalDummyInstance *result;
148 assert(GetBaseType(gdt)==dummy_type);
149 result = (struct GlobalDummyInstance *)
150 ascmalloc(sizeof(struct GlobalDummyInstance));
151 assert(result!=NULL);
152 CopyTypeDesc(gdt);
153 result->t = DUMMY_INST;
154 result->interface_ptr = NULL;
155 result->desc = gdt;
156 result->ref_count = 1L;
157 result->visited = 0L;
158 result->tmp_num = 0L;
159 result->anon_flags = 0;
160 AddUniversalInstance(GetUniversalTable(),gdt,INST(result));
161 return INST(result);
162 }
163
164 /*********************************************************************\
165 Simulation stuff.
166 \*********************************************************************/
167
168 struct Instance *CreateSimulationInstance(struct TypeDescription *type,
169 symchar *name)
170 {
171 register struct SimulationInstance *result;
172 int num_children;
173 unsigned int size;
174
175 num_children = 1;
176 CopyTypeDesc(type);
177 size = (unsigned)sizeof(struct SimulationInstance) +
178 (unsigned)num_children*sizeof(struct Instance *);
179 result = SIM_INST(ascmalloc((unsigned)sizeof(struct SimulationInstance) +
180 (unsigned)num_children*
181 sizeof(struct Instance *)));
182 result->t = SIM_INST;
183 result->interface_ptr = NULL;
184 result->desc = type;
185 result->name = name;
186 result->extvars = NULL;
187 return INST(result);
188 }
189
190 /*
191 * the following initialize (but do not allocate)
192 * fundamental instances. (children of atoms)
193 */
194 static void CreateReal(struct RealInstance *i, struct Instance *parent)
195 {
196 i->t = REAL_INST;
197 i->parent_offset = INST((unsigned long)i-(unsigned long)parent);
198 i->value = UNDEFAULTEDREAL;
199 i->dimen = WildDimension();
200 i->assigned = 0;
201 i->depth = UINT_MAX;
202 i->padding = INT_MAX;
203 AssertContainedMemory(i,sizeof(struct RealInstance));
204 }
205
206 static void CreateInteger(struct IntegerInstance *i, struct Instance *parent)
207 {
208 i->t = INTEGER_INST;
209 i->parent_offset = INST((unsigned long)i-(unsigned long)parent);
210 i->value = 0;
211 i->assigned = 0;
212 i->depth = 0;
213 i->padding = INT_MAX;
214 AssertContainedMemory(i,sizeof(struct IntegerInstance));
215 }
216
217 static void CreateBoolean(struct BooleanInstance *i, struct Instance *parent)
218 {
219 i->t = BOOLEAN_INST;
220 i->parent_offset = INST((unsigned long)i-(unsigned long)parent);
221 i->value = 0;
222 i->assigned = 0;
223 i->depth = UINT_MAX;
224 AssertContainedMemory(i,sizeof(struct BooleanInstance));
225 #if (LONGCHILDREN == 0)
226 i->padding = INT_MAX;
227 #endif
228
229 }
230
231 static void CreateSet(struct SetInstance *i,
232 struct Instance *parent, int intset)
233 {
234 i->t = SET_INST;
235 i->parent_offset = INST((unsigned long)i-(unsigned long)parent);
236 i->int_set = intset ? 1 : 0;
237 i->list = NULL;
238 AssertContainedMemory(i,sizeof(struct SetInstance));
239 }
240
241 static void CreateSymbol(struct SymbolInstance *i, struct Instance *parent)
242 {
243 i->t = SYMBOL_INST;
244 i->parent_offset = INST((unsigned long)i-(unsigned long)parent);
245 i->value = NULL;
246 AssertContainedMemory(i,sizeof(struct SymbolInstance));
247 }
248
249 static void MakeAtomChildren(unsigned long int nc, /* number of children */
250 struct Instance *parent, /* parent's address */
251 struct Instance *base, /* starting address of */
252 /* children instances */
253 struct Instance **iptrs, /* child pointer list */
254 CONST struct ChildDesc *childd) /* children */
255 /* descriptions */
256 {
257 register unsigned long c=1;
258 struct ChildDesc cd;
259 while(c<=nc) {
260 AssertContainedIn(parent,base);
261 AssertContainedIn(parent,iptrs);
262 *iptrs = base; /* set pointer to child's address */
263 cd = GetChildArrayElement(childd,c);
264 switch(ChildDescType(cd)) {
265 case real_child:
266 CreateReal(R_INST(base),parent);
267 if (ValueAssigned(cd)) {
268 SetRealAtomValue(base,RealDefaultValue(cd),UINT_MAX);
269 SetRealAtomDims(base,RealDimensions(cd));
270 }
271 /* prepare for next child */
272 base = INST((unsigned long)base+sizeof(struct RealInstance));
273 break;
274 case integer_child:
275 CreateInteger(I_INST(base),parent);
276 if (ValueAssigned(cd))
277 SetIntegerAtomValue(base,IntegerDefault(cd),UINT_MAX);
278 /* prepare for next child */
279 base = INST((unsigned long)base+sizeof(struct IntegerInstance));
280 break;
281 case boolean_child:
282 CreateBoolean(B_INST(base),parent);
283 if (ValueAssigned(cd))
284 SetBooleanAtomValue(base,BooleanDefault(cd),UINT_MAX);
285 /* prepare for next child */
286 base = INST((unsigned long)base+sizeof(struct BooleanInstance));
287 break;
288 case set_child:
289 CreateSet(S_INST(base),parent,(int)SetIsIntegerSet(cd));
290 if (ValueAssigned(cd))
291 AssignSetAtomList(base,CopySet(SetDefault(cd)));
292 /* prepare for next child */
293 base = INST((unsigned long)base+sizeof(struct SetInstance));
294 break;
295 case symbol_child:
296 CreateSymbol(SYM_INST(base),parent);
297 if (ValueAssigned(cd))
298 SetSymbolAtomValue(base,SymbolDefault(cd));
299 /* prepare for next child */
300 base = INST((unsigned long)base+sizeof(struct SymbolInstance));
301 break;
302 case bad_child:
303 Asc_Panic(2, NULL, "MakeAtomChildren called with bad_child\n");
304 break;
305 }
306 /* set pointer and counter for next child */
307 iptrs++;
308 c++;
309 }
310 /* FIX BUG fix me bug !
311 * ifndef NDEBUG, here we should be making sure there are no
312 * extra trailing child ptrs (due to next-highest-even) and
313 * there ARE some, initing them to NULL.
314 */
315 }
316
317
318 /*
319 * This function, redone by kirk, no longer finds universals and
320 * returns them. if that were appropriate, it should have been
321 * checked and done before hand. By ShortCutMakeUniversalInstance
322 */
323 struct Instance *CreateRealInstance(struct TypeDescription *type)
324 {
325
326 if (BaseTypeIsAtomic(type)) {
327 register struct RealAtomInstance *result;
328 register unsigned long num_children;
329 if ((result=RA_INST(LookupPrototype(GetName(type))))==NULL) {
330 CopyTypeDesc(type);
331 num_children = ChildListLen(GetChildList(type));
332 result = RA_INST(ascmalloc(GetByteSize(type)));
333 result->t = REAL_ATOM_INST;
334 result->interface_ptr = NULL;
335 result->parents = gl_create(AVG_PARENTS);
336 result->alike_ptr = INST(result);
337 result->desc = type;
338 result->visited = 0;
339 result->tmp_num = 0;
340 result->anon_flags = 0x0;
341 result->dimen = GetRealDimens(type);
342 result->relations = NULL;
343 result->depth = UINT_MAX;
344 if (AtomDefaulted(type)) {
345 result->value = GetRealDefault(type);
346 result->assigned = 1;
347 }
348 else {
349 result->value = UNDEFAULTEDREAL;
350 result->assigned = 0;
351 }
352 MakeAtomChildren(num_children,
353 INST(result),
354 BASE_ADDR(result,num_children,struct RealAtomInstance),
355 CLIST(result,struct RealAtomInstance),
356 GetChildDesc(type));
357 AssertMemory(result);
358 if (GetUniversalFlag(type)){
359 AddUniversalInstance(GetUniversalTable(),type,INST(result));
360 return INST(result);
361 }
362 AddPrototype(CopyInstance(INST(result)));
363 return INST(result);
364 }
365 else { /* instance type has a prototype which can be copied */
366 return CopyInstance(INST(result));
367 }
368 } else { /* create constant */
369 register struct RealConstantInstance *result;
370 if ((result=RC_INST(LookupPrototype(GetName(type))))==NULL) {
371 CopyTypeDesc(type);
372 result = RC_INST(ascmalloc(GetByteSize(type)));
373 result->t = REAL_CONSTANT_INST;
374 result->parents = gl_create(AVG_CONSTANT_PARENTS);
375 result->alike_ptr = INST(result);
376 result->desc = type;
377 result->visited = 0L;
378 result->tmp_num = 0L;
379 result->interface_ptr = NULL;
380 result->dimen = GetConstantDimens(type);
381 if (ConstantDefaulted(type)) {
382 result->value = GetConstantDefReal(type);
383 result->vflag = ci_ASSIGNED;
384 }
385 else {
386 result->value = UNDEFAULTEDREAL;
387 result->vflag = 0;
388 }
389 AssertMemory(result);
390 if (GetUniversalFlag(type)){
391 AddUniversalInstance(GetUniversalTable(),type,INST(result));
392 return INST(result);
393 }
394 AddPrototype(CopyInstance(INST(result)));
395 return INST(result);
396 } else { /* instance type has a prototype which can be copied */
397 return CopyInstance(INST(result));
398 }
399 }
400 }
401
402 struct Instance *CreateIntegerInstance(struct TypeDescription *type)
403 {
404 if (BaseTypeIsAtomic(type)) {
405 register struct IntegerAtomInstance *result;
406 register unsigned long num_children;
407
408 if ((result=IA_INST(LookupPrototype(GetName(type))))==NULL) {
409 CopyTypeDesc(type);
410 num_children = ChildListLen(GetChildList(type));
411 result = IA_INST(ascmalloc(GetByteSize(type)));
412 result->t = INTEGER_ATOM_INST;
413 result->interface_ptr = NULL;
414 result->parents = gl_create(AVG_PARENTS);
415 result->alike_ptr = INST(result);
416 result->desc = type;
417 result->whens = NULL;
418 result->visited = 0;
419 result->tmp_num = 0;
420 result->anon_flags = 0x0;
421 result->depth = UINT_MAX;
422 if (AtomDefaulted(type)) {
423 result->value = GetIntDefault(type);
424 result->assigned = 1;
425 } else {
426 result->value = 0L;
427 result->assigned = 0;
428 }
429 MakeAtomChildren(num_children,
430 INST(result),
431 BASE_ADDR(result,num_children,
432 struct IntegerAtomInstance),
433 CLIST(result,struct IntegerAtomInstance),
434 GetChildDesc(type));
435 AssertMemory(result);
436 if (GetUniversalFlag(type)){
437 AddUniversalInstance(GetUniversalTable(),type,INST(result));
438 return INST(result);
439 }
440 AddPrototype(CopyInstance(INST(result)));
441 return INST(result);
442 }
443 else {/* a prototype exists which can be copied */
444 return CopyInstance(INST(result));
445 }
446 } else {
447 register struct IntegerConstantInstance *result;
448
449 if ((result=IC_INST(LookupPrototype(GetName(type))))==NULL) {
450 CopyTypeDesc(type);
451 result = IC_INST(ascmalloc(GetByteSize(type)));
452 result->t = INTEGER_CONSTANT_INST;
453 result->parents = gl_create(AVG_ICONSTANT_PARENTS);
454 result->alike_ptr = INST(result);
455 result->whens = NULL;
456 result->interface_ptr = NULL;
457 result->desc = type;
458 result->visited = 0;
459 result->tmp_num = 0;
460 result->interface_ptr = NULL;
461 if (ConstantDefaulted(type)) {
462 result->value = GetConstantDefInteger(type);
463 result->vflag = ci_ASSIGNED;
464 } else {
465 result->value = 0L;
466 result->vflag = 0;
467 }
468 if (GetUniversalFlag(type)){
469 AddUniversalInstance(GetUniversalTable(),type,INST(result));
470 return INST(result);
471 }
472 AddPrototype(CopyInstance(INST(result)));
473 return INST(result);
474 }
475 else {/* a prototype exists which can be copied */
476 return CopyInstance(INST(result));
477 }
478 }
479 }
480
481 struct Instance *CreateBooleanInstance(struct TypeDescription *type)
482 {
483 if (BaseTypeIsAtomic(type)) {
484 register struct BooleanAtomInstance *result;
485 register unsigned long num_children;
486
487 if ((result=BA_INST(LookupPrototype(GetName(type))))==NULL) {
488 CopyTypeDesc(type);
489 num_children = ChildListLen(GetChildList(type));
490 result = BA_INST(ascmalloc(GetByteSize(type)));
491 result->t = BOOLEAN_ATOM_INST;
492 result->interface_ptr = NULL;
493 result->parents = gl_create(AVG_PARENTS);
494 result->alike_ptr = INST(result);
495 result->desc = type;
496 result->visited = 0;
497 result->tmp_num = 0;
498 result->anon_flags = 0x0;
499 result->depth = UINT_MAX;
500 result->padding = INT_MAX;
501 result->logrelations = NULL;
502 result->whens = NULL;
503 if (AtomDefaulted(type)) {
504 result->value = GetBoolDefault(type);
505 result->assigned = 1;
506 } else {
507 result->value = 0;
508 result->assigned = 0;
509 }
510 MakeAtomChildren(num_children,
511 INST(result),
512 BASE_ADDR(result,num_children,
513 struct BooleanAtomInstance),
514 CLIST(result,struct BooleanAtomInstance),
515 GetChildDesc(type));
516 AssertMemory(result);
517 if (GetUniversalFlag(type)){
518 AddUniversalInstance(GetUniversalTable(),type,INST(result));
519 return INST(result);
520 }
521 AddPrototype(CopyInstance(INST(result)));
522 return INST(result);
523 }
524 else {/* a prototype exists which can be copied */
525 return CopyInstance(INST(result));
526 }
527 } else {
528 register struct BooleanConstantInstance *result;
529
530 if ((result=BC_INST(LookupPrototype(GetName(type))))==NULL) {
531 CopyTypeDesc(type);
532 result = BC_INST(ascmalloc(GetByteSize(type)));
533 result->t = BOOLEAN_CONSTANT_INST;
534 result->parents = gl_create(AVG_ICONSTANT_PARENTS);
535 result->alike_ptr = INST(result);
536 result->whens = NULL;
537 result->interface_ptr = NULL;
538 result->desc = type;
539 result->visited = 0;
540 result->tmp_num = 0;
541 if (ConstantDefaulted(type)) {
542 result->vflag = 1;
543 result->vflag |= GetConstantDefBoolean(type);
544 } else {
545 result->vflag = 0;
546 }
547 AssertMemory(result);
548 if (GetUniversalFlag(type)){
549 AddUniversalInstance(GetUniversalTable(),type,INST(result));
550 return INST(result);
551 }
552 AddPrototype(CopyInstance(INST(result)));
553 return INST(result);
554 }
555 else {/* a prototype exists which can be copied */
556 return CopyInstance(INST(result));
557 }
558 }
559 }
560
561 struct Instance *CreateSetInstance(struct TypeDescription *type, int intset)
562 {
563 if (BaseTypeIsAtomic(type)) {
564 register struct SetAtomInstance *result;
565 register unsigned long num_children;
566
567 if ((result=SA_INST(LookupPrototype(GetName(type))))==NULL) {
568 CopyTypeDesc(type);
569 num_children = ChildListLen(GetChildList(type));
570 result = SA_INST(ascmalloc(GetByteSize(type)));
571 result->t = SET_ATOM_INST;
572 result->interface_ptr = NULL;
573 result->parents = gl_create(AVG_PARENTS);
574 result->alike_ptr = INST(result);
575 result->desc = type;
576 result->visited = 0;
577 result->tmp_num = 0;
578 result->anon_flags = 0x0;
579 result->list = NULL;
580 result->int_set = intset ? 1 : 0;
581 MakeAtomChildren(num_children,
582 INST(result),
583 BASE_ADDR(result,num_children,struct SetAtomInstance),
584 CLIST(result,struct SetAtomInstance),
585 GetChildDesc(type));
586 AssertMemory(result);
587 if (GetUniversalFlag(type)){
588 AddUniversalInstance(GetUniversalTable(),type,INST(result));
589 return INST(result);
590 }
591 AddPrototype(CopyInstance(INST(result)));
592 }
593 else{ /* a prototype exists which may be copied */
594 result = SA_INST(CopyInstance(INST(result)));
595 result->int_set = intset ? 1 : 0;
596 }
597 return INST(result);
598 } else {
599 FPRINTF(ASCERR,"set_constants not yet instantiable\n");
600 return NULL;
601 }
602 }
603
604 struct Instance *CreateSymbolInstance(struct TypeDescription *type)
605 {
606 if (BaseTypeIsAtomic(type)) {
607 register struct SymbolAtomInstance *result;
608 register unsigned long num_children;
609
610 if ((result=SYMA_INST(LookupPrototype(GetName(type))))==NULL){
611 CopyTypeDesc(type);
612 num_children = ChildListLen(GetChildList(type));
613 result = SYMA_INST(ascmalloc(GetByteSize(type)));
614 result->t = SYMBOL_ATOM_INST;
615 result->interface_ptr = NULL;
616 result->parents = gl_create(AVG_PARENTS);
617 result->alike_ptr = INST(result);
618 result->desc = type;
619 result->whens = NULL;
620 result->visited = 0;
621 result->tmp_num = 0;
622 result->anon_flags = 0x0;
623 /* atom value stuff */
624 if (AtomDefaulted(type)) {
625 result->value = GetSymDefault(type);
626 } else {
627 result->value = NULL;
628 }
629 MakeAtomChildren(num_children,
630 INST(result),
631 BASE_ADDR(result,num_children,struct SymbolAtomInstance),
632 CLIST(result,struct SymbolAtomInstance),
633 GetChildDesc(type));
634 AssertMemory(result);
635 if (GetUniversalFlag(type)){
636 AddUniversalInstance(GetUniversalTable(),type,INST(result));
637 return INST(result);
638 }
639 AddPrototype(CopyInstance(INST(result)));
640 return INST(result);
641 }
642 else { /* a prototype exists which may be copied */
643 return CopyInstance(INST(result));
644 }
645 } else {
646 register struct SymbolConstantInstance *result;
647
648 if ((result=SYMC_INST(LookupPrototype(GetName(type))))==NULL){
649 CopyTypeDesc(type);
650 result = SYMC_INST(ascmalloc(GetByteSize(type)));
651 result->t = SYMBOL_CONSTANT_INST;
652 result->parents = gl_create(AVG_ICONSTANT_PARENTS);
653 result->alike_ptr = INST(result);
654 result->whens = NULL;
655 result->interface_ptr = NULL;
656 result->desc = type;
657 result->visited = 0;
658 result->tmp_num = 0;
659 if (ConstantDefaulted(type)) {
660 result->value = GetConstantDefSymbol(type);
661 result->vflag = ci_ASSIGNED;
662 } else {
663 result->value = NULL;
664 result->vflag = 0;
665 }
666 AssertMemory(result);
667 if (GetUniversalFlag(type)){
668 AddUniversalInstance(GetUniversalTable(),type,INST(result));
669 return INST(result);
670 }
671 AddPrototype(CopyInstance(INST(result)));
672 return INST(result);
673 }
674 else { /* a prototype exists which may be copied */
675 return CopyInstance(INST(result));
676 }
677 }
678 }
679
680 struct Instance *CreateRelationInstance(struct TypeDescription *type,
681 enum Expr_enum reltype)
682 {
683 register struct RelationInstance *result;
684 register unsigned long num_children;
685 /*ERROR_REPORTER_DEBUG("Entered CreateRelationInstance\n");*/
686
687 if ((result=RELN_INST(LookupPrototype(GetName(type))))==NULL){
688 CopyTypeDesc(type);
689 num_children = ChildListLen(GetChildList(type));
690 result = RELN_INST(ascmalloc(GetByteSize(type)));
691 result->t = REL_INST;
692 result->interface_ptr = NULL;
693 result->parent[0] = NULL; /* relations can have only two parents */
694 result->parent[1] = NULL; /* initially it has none */
695 result->desc = type;
696 result->visited = 0;
697 result->tmp_num = 0;
698 result->anon_flags = 0;
699 /* relation stuff */
700 result->ptr = NULL;
701 result->whens = NULL;
702 result->logrels = NULL;
703 result->type = reltype;
704 /* Not required anymore :
705 * #if (LONGCHILDREN == 0)
706 * result->padding = INT_MAX;
707 * #endif
708 */
709 MakeAtomChildren(num_children,
710 INST(result),
711 BASE_ADDR(result,num_children,struct RelationInstance),
712 CLIST(result,struct RelationInstance),
713 GetChildDesc(type));
714 AddPrototype(CopyInstance(INST(result)));
715 AssertMemory(result);
716 return INST(result);
717 } else{ /* a prototype exists which may be copied */
718 result = RELN_INST(CopyInstance(INST(result)));
719 result->type = reltype; /* now set up the reltype */
720 return INST(result);
721 }
722 }
723
724
725 struct Instance *CreateLogRelInstance(struct TypeDescription *type)
726 {
727 register struct LogRelInstance *result;
728 register unsigned long num_children;
729 if ((result=LRELN_INST(LookupPrototype(GetName(type))))==NULL){
730 CopyTypeDesc(type);
731 num_children = ChildListLen(GetChildList(type));
732 result = LRELN_INST(ascmalloc(GetByteSize(type)));
733 result->t = LREL_INST;
734 result->interface_ptr = NULL;
735 result->parent[0] = NULL; /*logical relations can have only two parents*/
736 result->parent[1] = NULL; /* initially it has none */
737 result->desc = type;
738 result->visited = 0;
739 result->tmp_num = 0;
740 result->anon_flags = 0x0;
741 result->whens = NULL;
742 result->logrels = NULL;
743 result->padding = INT_MAX;
744 /* relation stuff */
745 result->ptr = NULL;
746 MakeAtomChildren(num_children,
747 INST(result),
748 BASE_ADDR(result,num_children,struct LogRelInstance),
749 CLIST(result,struct LogRelInstance),
750 GetChildDesc(type));
751 AddPrototype(CopyInstance(INST(result)));
752 AssertMemory(result);
753 return INST(result);
754 }
755 else{ /* a prototype exists which may be copied */
756 result = LRELN_INST(CopyInstance(INST(result)));
757 return INST(result);
758 }
759 }
760
761
762 struct Instance *CreateWhenInstance(struct TypeDescription *type)
763 {
764 register struct WhenInstance *result;
765 if ((result=W_INST(LookupPrototype(GetName(type))))==NULL){
766 CopyTypeDesc(type);
767 result = W_INST(ascmalloc((unsigned)sizeof(struct WhenInstance)));
768 result->t = WHEN_INST;
769 result->interface_ptr = NULL;
770 result->parent[0] = NULL; /* relations can have only two parents */
771 result->parent[1] = NULL; /* initially it has none */
772 result->whens = NULL; /* initially it has none */
773 result->cases = NULL;
774 result->bvar = NULL;
775 result->desc = type;
776 result->visited = 0;
777 result->tmp_num = 0;
778 result->anon_flags = 0x0;
779
780 AddPrototype(CopyInstance(INST(result)));
781 AssertMemory(result);
782 return INST(result);
783 }
784 else{ /* a prototype exists which may be copied */
785 result = W_INST(CopyInstance(INST(result)));
786 return INST(result);
787 }
788 }
789
790
791
792 /*
793 * Note: CopyTypeDesc(type) is not done here.; This is
794 * handled by CreateArrayTypeDesc().
795 */
796 struct Instance *CreateArrayInstance(struct TypeDescription *type,
797 unsigned long int pos)
798 {
799 struct ArrayInstance *result;
800 struct gl_list_t *list;
801 struct IndexType *ptr;
802 assert(type!=NULL);
803
804 result = ARY_INST(ascmalloc((unsigned)sizeof(struct ArrayInstance)));
805 list = GetArrayIndexList(type);
806 if ((list==NULL)||(gl_length(list)==0)) {
807 Asc_Panic(2, NULL, "An array without any indicies!\n");
808 }
809 ptr = (struct IndexType *)gl_fetch(list,pos);
810 if (GetIndexType(ptr)) {
811 result->t = ARRAY_INT_INST;
812 } else {
813 result->t = ARRAY_ENUM_INST;
814 }
815 result->pending_entry = NULL;
816 result->interface_ptr = NULL;
817 result->desc = type;
818 result->parents = gl_create(AVG_PARENTS);
819 result->children = NULL;
820 result->indirected = pos-1;
821 result->visited = 0;
822 result->tmp_num = 0;
823 result->anon_flags = 0x0;
824 AssertMemory(result);
825 return INST(result);
826 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22