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

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