/[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 731 - (show annotations) (download) (as text)
Tue Jul 4 07:42:06 2006 UTC (14 years, 4 months ago) by johnpye
File MIME type: text/x-csrc
File size: 26653 byte(s)
Removed some debug messages.
Fixed up return values for Integrators functions to comply with integrator.c API.
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 <utilities/error.h>
37 #include <general/list.h>
38 #include <general/dstring.h>
39 #include "compiler.h"
40 #include "bit.h"
41 #include "symtab.h"
42 #include "fractions.h"
43 #include "dimen.h"
44 #include "functype.h"
45 #include "expr_types.h"
46 #include "stattypes.h"
47 #include "slist.h"
48 #include "setinstval.h"
49 #include "instance_name.h"
50 #include "instance_io.h"
51 #include "check.h"
52 #include "dump.h"
53 #include "child.h"
54 #include "childinfo.h"
55 #include "type_desc.h"
56 #include "prototype.h"
57 #include "pending.h"
58 #include "find.h"
59 #include "instance_enum.h"
60 #include "relation_type.h"
61 #include "relation.h"
62 #include "logical_relation.h"
63 #include "logrelation.h"
64 #include "relation_util.h"
65 #include "logrel_util.h"
66 #include "rel_common.h"
67 #include "case.h"
68 #include "when_util.h"
69 #include "universal.h"
70 #include <general/pool.h>
71 #include "instance_types.h"
72 /* new */
73 #include "atomsize.h"
74 #include "atomvalue.h"
75 #include "cmpfunc.h"
76 #include "copyinst.h"
77 #include "createinst.h"
78 #include "destroyinst.h"
79 #include "extinst.h"
80 #include "linkinst.h"
81 #include "instmacro.h"
82 #include "instquery.h"
83
84 #ifndef lint
85 static CONST char CreateInstModuleID[] = "$Id: createinst.c,v 1.19 1998/03/26 20:39:41 ballan Exp $";
86 #endif
87
88 void ZeroNewChildrenEntries(register struct Instance **child_ary,
89 register unsigned long int num)
90 {
91 /* initialize all the children pointers to NULL */
92 while(num--) {
93 AssertMemory(child_ary);
94 *(child_ary++) = NULL;
95 }
96 }
97
98 /*
99 * Create a new model instance. The semantics at this time is
100 * as follows: We lookup for a prototype of the model in the
101 * prototype library. If found we do a deepcopy of the instance.
102 * We do this deep copy using copy-by-reference semantics on
103 * relations. THIS may change.
104 */
105 struct Instance *CreateModelInstance(struct TypeDescription *type)
106 {
107 register struct ModelInstance *result, *proto;
108 register unsigned long num_children;
109 register CONST struct StatementList *stats;
110
111 proto = MOD_INST(LookupPrototype(GetName(type)));
112 if (proto==NULL) {
113 CopyTypeDesc(type);
114 num_children = ChildListLen(GetChildList(type));
115 stats = GetStatementList(type);
116 result = MOD_INST(ascmalloc((unsigned)sizeof(struct ModelInstance)+
117 (unsigned)num_children*
118 (unsigned)sizeof(struct Instance *)));
119 result->t = MODEL_INST;
120 result->pending_entry = NULL;
121 result->interface_ptr = NULL;
122 result->parents = gl_create(AVG_PARENTS);
123 result->whens = NULL;
124 result->desc = type;
125 result->alike_ptr = INST(result);
126 result->visited = 0;
127 result->tmp_num = 0;
128 result->anon_flags = 0x0;
129 #if (LONGCHILDREN == 1)
130 result->padding = INT_MAX;
131 #endif
132
133 result->executed = CreateFBList(gl_length(GetList(stats)));
134 ZeroNewChildrenEntries(MOD_CHILD(result,0),num_children);
135 AssertMemory(result);
136 if (GetUniversalFlag(type)) {
137 AddUniversalInstance(GetUniversalTable(),type,INST(result));
138 }
139 return INST(result);
140 } else { /* instance has a prototype which may be copied */
141 result = MOD_INST(CopyInstance(INST(proto)));
142 return INST(result);
143 }
144 }
145
146 struct Instance *CreateDummyInstance(struct TypeDescription *gdt)
147 {
148 struct GlobalDummyInstance *result;
149 assert(GetBaseType(gdt)==dummy_type);
150 result = ASC_NEW(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 if (BaseTypeIsAtomic(type)) {
326 register struct RealAtomInstance *result;
327 register unsigned long num_children;
328
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
345 if(AtomDefaulted(type)){
346 result->value = GetRealDefault(type);
347 result->assigned = 1;
348 }
349 else {
350 result->value = UNDEFAULTEDREAL;
351 result->assigned = 0;
352 }
353
354 MakeAtomChildren(num_children,
355 INST(result),
356 BASE_ADDR(result,num_children,struct RealAtomInstance),
357 CLIST(result,struct RealAtomInstance),
358 GetChildDesc(type)
359 );
360 AssertMemory(result);
361
362 /*
363 CONSOLE_DEBUG("CREATED REAL ATOM INSTANCE of type '%s' at %p"
364 ,SCP(GetName(type)),result
365 );
366 */
367
368 if (GetUniversalFlag(type)){
369 AddUniversalInstance(GetUniversalTable(),type,INST(result));
370 return INST(result);
371 }
372 AddPrototype(CopyInstance(INST(result)));
373 return INST(result);
374 }else{ /* instance type has a prototype which can be copied */
375 result = CopyInstance(INST(result));
376 /*
377 CONSOLE_DEBUG("CREATED (COPIED PROTOTYPE) REAL ATOM INSTANCE "
378 "of type '%s' at %p" ,SCP(GetName(type)),result
379 );
380 */
381 return result;
382 }
383 } else {
384 /* create constant */
385 register struct RealConstantInstance *result;
386 if((result=RC_INST(LookupPrototype(GetName(type))))==NULL){
387 CopyTypeDesc(type);
388 result = RC_INST(ascmalloc(GetByteSize(type)));
389 result->t = REAL_CONSTANT_INST;
390 result->parents = gl_create(AVG_CONSTANT_PARENTS);
391 result->alike_ptr = INST(result);
392 result->desc = type;
393 result->visited = 0L;
394 result->tmp_num = 0L;
395 result->interface_ptr = NULL;
396 result->dimen = GetConstantDimens(type);
397 if (ConstantDefaulted(type)) {
398 result->value = GetConstantDefReal(type);
399 result->vflag = ci_ASSIGNED;
400 }
401 else {
402 result->value = UNDEFAULTEDREAL;
403 result->vflag = 0;
404 }
405 AssertMemory(result);
406 if (GetUniversalFlag(type)){
407 AddUniversalInstance(GetUniversalTable(),type,INST(result));
408 return INST(result);
409 }
410 AddPrototype(CopyInstance(INST(result)));
411 return INST(result);
412 } else { /* instance type has a prototype which can be copied */
413 return CopyInstance(INST(result));
414 }
415 }
416 }
417
418 struct Instance *CreateIntegerInstance(struct TypeDescription *type)
419 {
420 if (BaseTypeIsAtomic(type)) {
421 register struct IntegerAtomInstance *result;
422 register unsigned long num_children;
423
424 if ((result=IA_INST(LookupPrototype(GetName(type))))==NULL) {
425 CopyTypeDesc(type);
426 num_children = ChildListLen(GetChildList(type));
427 result = IA_INST(ascmalloc(GetByteSize(type)));
428 result->t = INTEGER_ATOM_INST;
429 result->interface_ptr = NULL;
430 result->parents = gl_create(AVG_PARENTS);
431 result->alike_ptr = INST(result);
432 result->desc = type;
433 result->whens = NULL;
434 result->visited = 0;
435 result->tmp_num = 0;
436 result->anon_flags = 0x0;
437 result->depth = UINT_MAX;
438 if (AtomDefaulted(type)) {
439 result->value = GetIntDefault(type);
440 result->assigned = 1;
441 } else {
442 result->value = 0L;
443 result->assigned = 0;
444 }
445 MakeAtomChildren(num_children,
446 INST(result),
447 BASE_ADDR(result,num_children,
448 struct IntegerAtomInstance),
449 CLIST(result,struct IntegerAtomInstance),
450 GetChildDesc(type));
451 AssertMemory(result);
452 if (GetUniversalFlag(type)){
453 AddUniversalInstance(GetUniversalTable(),type,INST(result));
454 return INST(result);
455 }
456 AddPrototype(CopyInstance(INST(result)));
457 return INST(result);
458 }
459 else {/* a prototype exists which can be copied */
460 return CopyInstance(INST(result));
461 }
462 } else {
463 register struct IntegerConstantInstance *result;
464
465 if ((result=IC_INST(LookupPrototype(GetName(type))))==NULL) {
466 CopyTypeDesc(type);
467 result = IC_INST(ascmalloc(GetByteSize(type)));
468 result->t = INTEGER_CONSTANT_INST;
469 result->parents = gl_create(AVG_ICONSTANT_PARENTS);
470 result->alike_ptr = INST(result);
471 result->whens = NULL;
472 result->interface_ptr = NULL;
473 result->desc = type;
474 result->visited = 0;
475 result->tmp_num = 0;
476 result->interface_ptr = NULL;
477 if (ConstantDefaulted(type)) {
478 result->value = GetConstantDefInteger(type);
479 result->vflag = ci_ASSIGNED;
480 } else {
481 result->value = 0L;
482 result->vflag = 0;
483 }
484 if (GetUniversalFlag(type)){
485 AddUniversalInstance(GetUniversalTable(),type,INST(result));
486 return INST(result);
487 }
488 AddPrototype(CopyInstance(INST(result)));
489 return INST(result);
490 }
491 else {/* a prototype exists which can be copied */
492 return CopyInstance(INST(result));
493 }
494 }
495 }
496
497 struct Instance *CreateBooleanInstance(struct TypeDescription *type)
498 {
499 if (BaseTypeIsAtomic(type)) {
500 register struct BooleanAtomInstance *result;
501 register unsigned long num_children;
502
503 if ((result=BA_INST(LookupPrototype(GetName(type))))==NULL) {
504 CopyTypeDesc(type);
505 num_children = ChildListLen(GetChildList(type));
506 result = BA_INST(ascmalloc(GetByteSize(type)));
507 result->t = BOOLEAN_ATOM_INST;
508 result->interface_ptr = NULL;
509 result->parents = gl_create(AVG_PARENTS);
510 result->alike_ptr = INST(result);
511 result->desc = type;
512 result->visited = 0;
513 result->tmp_num = 0;
514 result->anon_flags = 0x0;
515 result->depth = UINT_MAX;
516 result->padding = INT_MAX;
517 result->logrelations = NULL;
518 result->whens = NULL;
519 if (AtomDefaulted(type)) {
520 result->value = GetBoolDefault(type);
521 result->assigned = 1;
522 } else {
523 result->value = 0;
524 result->assigned = 0;
525 }
526 MakeAtomChildren(num_children,
527 INST(result),
528 BASE_ADDR(result,num_children,
529 struct BooleanAtomInstance),
530 CLIST(result,struct BooleanAtomInstance),
531 GetChildDesc(type));
532 AssertMemory(result);
533 if (GetUniversalFlag(type)){
534 AddUniversalInstance(GetUniversalTable(),type,INST(result));
535 return INST(result);
536 }
537 AddPrototype(CopyInstance(INST(result)));
538 return INST(result);
539 }
540 else {/* a prototype exists which can be copied */
541 return CopyInstance(INST(result));
542 }
543 } else {
544 register struct BooleanConstantInstance *result;
545
546 if ((result=BC_INST(LookupPrototype(GetName(type))))==NULL) {
547 CopyTypeDesc(type);
548 result = BC_INST(ascmalloc(GetByteSize(type)));
549 result->t = BOOLEAN_CONSTANT_INST;
550 result->parents = gl_create(AVG_ICONSTANT_PARENTS);
551 result->alike_ptr = INST(result);
552 result->whens = NULL;
553 result->interface_ptr = NULL;
554 result->desc = type;
555 result->visited = 0;
556 result->tmp_num = 0;
557 if (ConstantDefaulted(type)) {
558 result->vflag = 1;
559 result->vflag |= GetConstantDefBoolean(type);
560 } else {
561 result->vflag = 0;
562 }
563 AssertMemory(result);
564 if (GetUniversalFlag(type)){
565 AddUniversalInstance(GetUniversalTable(),type,INST(result));
566 return INST(result);
567 }
568 AddPrototype(CopyInstance(INST(result)));
569 return INST(result);
570 }
571 else {/* a prototype exists which can be copied */
572 return CopyInstance(INST(result));
573 }
574 }
575 }
576
577 struct Instance *CreateSetInstance(struct TypeDescription *type, int intset)
578 {
579 if (BaseTypeIsAtomic(type)) {
580 register struct SetAtomInstance *result;
581 register unsigned long num_children;
582
583 if ((result=SA_INST(LookupPrototype(GetName(type))))==NULL) {
584 CopyTypeDesc(type);
585 num_children = ChildListLen(GetChildList(type));
586 result = SA_INST(ascmalloc(GetByteSize(type)));
587 result->t = SET_ATOM_INST;
588 result->interface_ptr = NULL;
589 result->parents = gl_create(AVG_PARENTS);
590 result->alike_ptr = INST(result);
591 result->desc = type;
592 result->visited = 0;
593 result->tmp_num = 0;
594 result->anon_flags = 0x0;
595 result->list = NULL;
596 result->int_set = intset ? 1 : 0;
597 MakeAtomChildren(num_children,
598 INST(result),
599 BASE_ADDR(result,num_children,struct SetAtomInstance),
600 CLIST(result,struct SetAtomInstance),
601 GetChildDesc(type));
602 AssertMemory(result);
603 if (GetUniversalFlag(type)){
604 AddUniversalInstance(GetUniversalTable(),type,INST(result));
605 return INST(result);
606 }
607 AddPrototype(CopyInstance(INST(result)));
608 }
609 else{ /* a prototype exists which may be copied */
610 result = SA_INST(CopyInstance(INST(result)));
611 result->int_set = intset ? 1 : 0;
612 }
613 return INST(result);
614 } else {
615 FPRINTF(ASCERR,"set_constants not yet instantiable\n");
616 return NULL;
617 }
618 }
619
620 struct Instance *CreateSymbolInstance(struct TypeDescription *type)
621 {
622 if (BaseTypeIsAtomic(type)) {
623 register struct SymbolAtomInstance *result;
624 register unsigned long num_children;
625
626 if ((result=SYMA_INST(LookupPrototype(GetName(type))))==NULL){
627 CopyTypeDesc(type);
628 num_children = ChildListLen(GetChildList(type));
629 result = SYMA_INST(ascmalloc(GetByteSize(type)));
630 result->t = SYMBOL_ATOM_INST;
631 result->interface_ptr = NULL;
632 result->parents = gl_create(AVG_PARENTS);
633 result->alike_ptr = INST(result);
634 result->desc = type;
635 result->whens = NULL;
636 result->visited = 0;
637 result->tmp_num = 0;
638 result->anon_flags = 0x0;
639 /* atom value stuff */
640 if (AtomDefaulted(type)) {
641 result->value = GetSymDefault(type);
642 } else {
643 result->value = NULL;
644 }
645 MakeAtomChildren(num_children,
646 INST(result),
647 BASE_ADDR(result,num_children,struct SymbolAtomInstance),
648 CLIST(result,struct SymbolAtomInstance),
649 GetChildDesc(type));
650 AssertMemory(result);
651 if (GetUniversalFlag(type)){
652 AddUniversalInstance(GetUniversalTable(),type,INST(result));
653 return INST(result);
654 }
655 AddPrototype(CopyInstance(INST(result)));
656 return INST(result);
657 }
658 else { /* a prototype exists which may be copied */
659 return CopyInstance(INST(result));
660 }
661 } else {
662 register struct SymbolConstantInstance *result;
663
664 if ((result=SYMC_INST(LookupPrototype(GetName(type))))==NULL){
665 CopyTypeDesc(type);
666 result = SYMC_INST(ascmalloc(GetByteSize(type)));
667 result->t = SYMBOL_CONSTANT_INST;
668 result->parents = gl_create(AVG_ICONSTANT_PARENTS);
669 result->alike_ptr = INST(result);
670 result->whens = NULL;
671 result->interface_ptr = NULL;
672 result->desc = type;
673 result->visited = 0;
674 result->tmp_num = 0;
675 if (ConstantDefaulted(type)) {
676 result->value = GetConstantDefSymbol(type);
677 result->vflag = ci_ASSIGNED;
678 } else {
679 result->value = NULL;
680 result->vflag = 0;
681 }
682 AssertMemory(result);
683 if (GetUniversalFlag(type)){
684 AddUniversalInstance(GetUniversalTable(),type,INST(result));
685 return INST(result);
686 }
687 AddPrototype(CopyInstance(INST(result)));
688 return INST(result);
689 }
690 else { /* a prototype exists which may be copied */
691 return CopyInstance(INST(result));
692 }
693 }
694 }
695
696 struct Instance *CreateRelationInstance(struct TypeDescription *type,
697 enum Expr_enum reltype)
698 {
699 register struct RelationInstance *result;
700 register unsigned long num_children;
701 /* ERROR_REPORTER_DEBUG("Entered CreateRelationInstance\n"); */
702
703 if ((result=RELN_INST(LookupPrototype(GetName(type))))==NULL){
704 CopyTypeDesc(type);
705 num_children = ChildListLen(GetChildList(type));
706 result = RELN_INST(ascmalloc(GetByteSize(type)));
707 result->t = REL_INST;
708 result->interface_ptr = NULL;
709 result->parent[0] = NULL; /* relations can have only two parents */
710 result->parent[1] = NULL; /* initially it has none */
711 result->desc = type;
712 result->visited = 0;
713 result->tmp_num = 0;
714 result->anon_flags = 0;
715 /* relation stuff */
716 CONSOLE_DEBUG("Creating instance with NULL rel ptr");
717 result->ptr = NULL;
718 result->whens = NULL;
719 result->logrels = NULL;
720 result->type = reltype;
721 /* Not required anymore :
722 * #if (LONGCHILDREN == 0)
723 * result->padding = INT_MAX;
724 * #endif
725 */
726 MakeAtomChildren(num_children,
727 INST(result),
728 BASE_ADDR(result,num_children,struct RelationInstance),
729 CLIST(result,struct RelationInstance),
730 GetChildDesc(type));
731 AddPrototype(CopyInstance(INST(result)));
732 AssertMemory(result);
733 return INST(result);
734 } else{ /* a prototype exists which may be copied */
735 result = RELN_INST(CopyInstance(INST(result)));
736 result->type = reltype; /* now set up the reltype */
737 return INST(result);
738 }
739 }
740
741
742 struct Instance *CreateLogRelInstance(struct TypeDescription *type)
743 {
744 register struct LogRelInstance *result;
745 register unsigned long num_children;
746 if ((result=LRELN_INST(LookupPrototype(GetName(type))))==NULL){
747 CopyTypeDesc(type);
748 num_children = ChildListLen(GetChildList(type));
749 result = LRELN_INST(ascmalloc(GetByteSize(type)));
750 result->t = LREL_INST;
751 result->interface_ptr = NULL;
752 result->parent[0] = NULL; /*logical relations can have only two parents*/
753 result->parent[1] = NULL; /* initially it has none */
754 result->desc = type;
755 result->visited = 0;
756 result->tmp_num = 0;
757 result->anon_flags = 0x0;
758 result->whens = NULL;
759 result->logrels = NULL;
760 result->padding = INT_MAX;
761 /* relation stuff */
762 if(result->ptr!=NULL){
763 CONSOLE_DEBUG("Clearing rel ptr %p",result->ptr);
764 }
765 result->ptr = NULL;
766 MakeAtomChildren(num_children,
767 INST(result),
768 BASE_ADDR(result,num_children,struct LogRelInstance),
769 CLIST(result,struct LogRelInstance),
770 GetChildDesc(type));
771 AddPrototype(CopyInstance(INST(result)));
772 AssertMemory(result);
773 return INST(result);
774 }
775 else{ /* a prototype exists which may be copied */
776 result = LRELN_INST(CopyInstance(INST(result)));
777 return INST(result);
778 }
779 }
780
781
782 struct Instance *CreateWhenInstance(struct TypeDescription *type)
783 {
784 register struct WhenInstance *result;
785 if ((result=W_INST(LookupPrototype(GetName(type))))==NULL){
786 CopyTypeDesc(type);
787 result = W_INST(ascmalloc((unsigned)sizeof(struct WhenInstance)));
788 result->t = WHEN_INST;
789 result->interface_ptr = NULL;
790 result->parent[0] = NULL; /* relations can have only two parents */
791 result->parent[1] = NULL; /* initially it has none */
792 result->whens = NULL; /* initially it has none */
793 result->cases = NULL;
794 result->bvar = NULL;
795 result->desc = type;
796 result->visited = 0;
797 result->tmp_num = 0;
798 result->anon_flags = 0x0;
799
800 AddPrototype(CopyInstance(INST(result)));
801 AssertMemory(result);
802 return INST(result);
803 }
804 else{ /* a prototype exists which may be copied */
805 result = W_INST(CopyInstance(INST(result)));
806 return INST(result);
807 }
808 }
809
810
811
812 /*
813 * Note: CopyTypeDesc(type) is not done here.; This is
814 * handled by CreateArrayTypeDesc().
815 */
816 struct Instance *CreateArrayInstance(struct TypeDescription *type,
817 unsigned long int pos)
818 {
819 struct ArrayInstance *result;
820 struct gl_list_t *list;
821 struct IndexType *ptr;
822 assert(type!=NULL);
823
824 result = ARY_INST(ascmalloc((unsigned)sizeof(struct ArrayInstance)));
825 list = GetArrayIndexList(type);
826 if ((list==NULL)||(gl_length(list)==0)) {
827 Asc_Panic(2, NULL, "An array without any indicies!\n");
828 }
829 ptr = (struct IndexType *)gl_fetch(list,pos);
830 if (GetIndexType(ptr)) {
831 result->t = ARRAY_INT_INST;
832 } else {
833 result->t = ARRAY_ENUM_INST;
834 }
835 result->pending_entry = NULL;
836 result->interface_ptr = NULL;
837 result->desc = type;
838 result->parents = gl_create(AVG_PARENTS);
839 result->children = NULL;
840 result->indirected = pos-1;
841 result->visited = 0;
842 result->tmp_num = 0;
843 result->anon_flags = 0x0;
844 AssertMemory(result);
845 return INST(result);
846 }

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