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

Diff of /trunk/base/generic/compiler/instquery.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1694 by jpye, Fri Mar 30 11:01:20 2007 UTC revision 1695 by jpye, Wed Dec 26 08:23:08 2007 UTC
# Line 81  void (*InterfaceNotify)() = NULL; Line 81  void (*InterfaceNotify)() = NULL;
81    
82  /**** END GLOBAL VARIABLE SECTION ****/  /**** END GLOBAL VARIABLE SECTION ****/
83    
84  enum inst_t InstanceKindF(CONST struct Instance *i)  enum inst_t InstanceKindF(CONST struct Instance *i){
 {  
85    if (i==NULL || (i->t & IERRINST))    if (i==NULL || (i->t & IERRINST))
86      return (ERROR_INST);      return (ERROR_INST);
87    return i->t;    return i->t;
88  }  }
89    
90    
91  unsigned long InstanceDepth(CONST struct Instance *i)  unsigned long InstanceDepth(CONST struct Instance *i){
 {  
92    register unsigned long c,result=0,d;    register unsigned long c,result=0,d;
93    register CONST struct Instance *parent;    register CONST struct Instance *parent;
94    if (i==NULL) return 0;    if (i==NULL) return 0;
# Line 103  unsigned long InstanceDepth(CONST struct Line 101  unsigned long InstanceDepth(CONST struct
101    return result+1;    return result+1;
102  }  }
103    
104  unsigned long InstanceShortDepth(CONST struct Instance *i)  unsigned long InstanceShortDepth(CONST struct Instance *i){
 {  
105    register unsigned long c,result=UINT_MAX,d;    register unsigned long c,result=UINT_MAX,d;
106    register CONST struct Instance *parent;    register CONST struct Instance *parent;
107    if (i==NULL) return 0;    if (i==NULL) return 0;
# Line 125  unsigned long InstanceShortDepth(CONST s Line 122  unsigned long InstanceShortDepth(CONST s
122   Instantiator use only!   Instantiator use only!
123  \*********************************************************************/  \*********************************************************************/
124    
125  void SetNextCliqueMember(struct Instance *i, struct Instance *next)  void SetNextCliqueMember(struct Instance *i, struct Instance *next){
 {  
126    AssertMemory(i);    AssertMemory(i);
127    switch(i->t) {    switch(i->t) {
128    case MODEL_INST:    case MODEL_INST:
# Line 167  void SetNextCliqueMember(struct Instance Line 163  void SetNextCliqueMember(struct Instance
163      SYMA_INST(i)->alike_ptr = next;      SYMA_INST(i)->alike_ptr = next;
164      break;      break;
165    case REL_INST:    case REL_INST:
166      ASC_PANIC("Relations can only be ALIKE with themselves.\n");      ASC_PANIC("Relations can only be ALIKE with themselves.");
167    case LREL_INST:    case LREL_INST:
168      Asc_Panic(2, NULL,      Asc_Panic(2, NULL,
169                "Logical Relations can only be ALIKE with themselves.\n");                "Logical Relations can only be ALIKE with themselves.");
170    case WHEN_INST:    case WHEN_INST:
171      ASC_PANIC("WHEN's can only be ALIKE with themselves.\n");      ASC_PANIC("WHEN's can only be ALIKE with themselves.");
172    case SIM_INST:    case SIM_INST:
173      ASC_PANIC("Simulations can only be ALIKE with themselves.\n");      ASC_PANIC("Simulations can only be ALIKE with themselves.");
174    case ARRAY_INT_INST:    case ARRAY_INT_INST:
175    case ARRAY_ENUM_INST:    case ARRAY_ENUM_INST:
176      ASC_PANIC("Arrays can only be ALIKE with themselves.\n");      ASC_PANIC("Arrays can only be ALIKE with themselves.");
177    /* fundamentals */    /* fundamentals */
178    case REAL_INST:    case REAL_INST:
179    case INTEGER_INST:    case INTEGER_INST:
180    case BOOLEAN_INST:    case BOOLEAN_INST:
181    case SET_INST:    case SET_INST:
182    case SYMBOL_INST:    case SYMBOL_INST:
183      ASC_PANIC("Fundamental reals cannot be made ARE_ALIKE.\n");      ASC_PANIC("Fundamental reals cannot be made ARE_ALIKE.");
184    case DUMMY_INST:    case DUMMY_INST:
185      ASC_PANIC("UNSELECTED instances cannot be made ARE_ALIKE.\n");      ASC_PANIC("UNSELECTED instances cannot be made ARE_ALIKE.");
186    default:    default:
187      ASC_PANIC("Illegal atom passed to SetNextCliqueMember.\n");      ASC_PANIC("Illegal atom passed to SetNextCliqueMember.");
188    }    }
189  }  }
190    
# Line 236  struct Instance *NextCliqueMember(CONST Line 232  struct Instance *NextCliqueMember(CONST
232    case DUMMY_INST:    case DUMMY_INST:
233      return (struct Instance *)i;      return (struct Instance *)i;
234    default:    default:
235      ASC_PANIC("Invalid arguments to NextCliqueMember.\n");      ASC_PANIC("Invalid arguments to NextCliqueMember.");
236            
237    }    }
238  }  }
239    
240  VOIDPTR GetInterfacePtr(CONST struct Instance *i)  VOIDPTR GetInterfacePtr(CONST struct Instance *i){
 {  
241    if (i == NULL) {    if (i == NULL) {
242      ASC_PANIC("NULL instance passed to GetInterfacePtr.\n");      ASC_PANIC("NULL instance passed to GetInterfacePtr.");
243    }    }
244    AssertMemory(i);    AssertMemory(i);
245    switch(i->t) {    switch(i->t) {
# Line 281  VOIDPTR GetInterfacePtr(CONST struct Ins Line 276  VOIDPTR GetInterfacePtr(CONST struct Ins
276    return NULL;    return NULL;
277  }  }
278    
279  void SetInterfacePtr(struct Instance *i, VOIDPTR c)  void SetInterfacePtr(struct Instance *i, VOIDPTR c){
 {  
280    AssertMemory(i);    AssertMemory(i);
281    switch(i->t) {    switch(i->t) {
282    case DUMMY_INST:    case DUMMY_INST:
# Line 337  void SetInterfacePtr(struct Instance *i, Line 331  void SetInterfacePtr(struct Instance *i,
331      FPRINTF(ASCERR,"Instance type does not possess an InterfacePtr.");      FPRINTF(ASCERR,"Instance type does not possess an InterfacePtr.");
332      return;      return;
333    default:    default:
334      ASC_PANIC("Undefined instance type passed to InterfacePtr.\n");      ASC_PANIC("Undefined instance type passed to InterfacePtr.");
335    }    }
336  }  }
337    
338  unsigned int GetAnonFlags(CONST struct Instance *i)  unsigned int GetAnonFlags(CONST struct Instance *i){
 {  
339    AssertMemory(i);    AssertMemory(i);
340    switch(i->t) {    switch(i->t) {
341    case SIM_INST:    case SIM_INST:
# Line 380  unsigned int GetAnonFlags(CONST struct I Line 373  unsigned int GetAnonFlags(CONST struct I
373    case SYMBOL_INST:     /* fall through */    case SYMBOL_INST:     /* fall through */
374      return 0;      return 0;
375    default:    default:
376      ASC_PANIC("Incorrect type in GetAnonFlags\n"); /*NOTREACHED*/      ASC_PANIC("Incorrect type in GetAnonFlags"); /*NOTREACHED*/
377            
378    }    }
379  }  }
380    
381  void SetAnonFlags(struct Instance *i,unsigned int flags)  void SetAnonFlags(struct Instance *i,unsigned int flags){
 {  
382    AssertMemory(i);    AssertMemory(i);
383    switch (i->t) {    switch (i->t) {
384    case SIM_INST:    case SIM_INST:
# Line 431  void SetAnonFlags(struct Instance *i,uns Line 423  void SetAnonFlags(struct Instance *i,uns
423    case SYMBOL_INST:     /* fall through */    case SYMBOL_INST:     /* fall through */
424      break;      break;
425    default:    default:
426      ASC_PANIC("Incorrect atom type in SetAnonFlags.\n");      ASC_PANIC("Incorrect atom type in SetAnonFlags.");
427    }    }
428  }  }
429    
430  symchar *GetSimulationName(struct Instance *i)  symchar *GetSimulationName(struct Instance *i){
 {  
431    assert(i&&InstanceKind(i)==SIM_INST);    assert(i&&InstanceKind(i)==SIM_INST);
432    if (!(i&&InstanceKind(i)==SIM_INST)) {    if (!(i&&InstanceKind(i)==SIM_INST)) {
433      FPRINTF(ASCERR,"GetSimulationName called on non-simulation.\n");      FPRINTF(ASCERR,"GetSimulationName called on non-simulation.");
434    }    }
435    return SIM_INST(i)->name;    return SIM_INST(i)->name;
436  }  }
437    
438  static  static
439  void CollectSimulationInstances(struct Instance *i,struct gl_list_t *sims)  void CollectSimulationInstances(struct Instance *i,struct gl_list_t *sims){
 {  
440    unsigned len;    unsigned len;
441    assert(i!=NULL && sims != NULL);    assert(i!=NULL && sims != NULL);
442    if (InstanceKind(i) == MODEL_INST) {    if (InstanceKind(i) == MODEL_INST) {
# Line 458  void CollectSimulationInstances(struct I Line 448  void CollectSimulationInstances(struct I
448    }    }
449  }  }
450    
451  struct gl_list_t *FindSimulationAncestors(struct Instance *i)  struct gl_list_t *FindSimulationAncestors(struct Instance *i){
 {  
452    struct gl_list_t *sims;    struct gl_list_t *sims;
453    if (i==NULL) {    if (i==NULL) {
454      return NULL;      return NULL;
# Line 470  struct gl_list_t *FindSimulationAncestor Line 459  struct gl_list_t *FindSimulationAncestor
459    return sims;    return sims;
460  }  }
461    
462  struct Instance *GetSimulationRoot(struct Instance *i)  struct Instance *GetSimulationRoot(struct Instance *i){
 {  
463    struct Instance **child_adr;    struct Instance **child_adr;
464    assert(i&&InstanceKind(i)==SIM_INST);    assert(i&&InstanceKind(i)==SIM_INST);
465    child_adr = SIM_CHILD(i,0);    child_adr = SIM_CHILD(i,0);
# Line 483  struct Instance *GetSimulationRoot(struc Line 471  struct Instance *GetSimulationRoot(struc
471   * Does not count relation guts, dimens, strings, or set_t *   * Does not count relation guts, dimens, strings, or set_t *
472   * as these are all potentially shared.   * as these are all potentially shared.
473   */   */
474  unsigned long InstanceSize(CONST struct Instance *i)  unsigned long InstanceSize(CONST struct Instance *i){
 {  
475    unsigned long len;    unsigned long len;
476    
477    assert(i!=NULL);    assert(i!=NULL);
# Line 596  unsigned long InstanceSize(CONST struct Line 583  unsigned long InstanceSize(CONST struct
583      }      }
584      return len;      return len;
585    default:    default:
586      ASC_PANIC("Invalid argument to InstanceSize.\n");      ASC_PANIC("Invalid argument to InstanceSize.");
587            
588    }    }
589  }  }
590    
591  int IntegerSetInstance(CONST struct Instance *i)  int IntegerSetInstance(CONST struct Instance *i){
 {  
592    AssertMemory(i);    AssertMemory(i);
593    switch(i->t) {    switch(i->t) {
594    case SET_ATOM_INST:    case SET_ATOM_INST:
# Line 610  int IntegerSetInstance(CONST struct Inst Line 596  int IntegerSetInstance(CONST struct Inst
596    case SET_INST:    case SET_INST:
597      return S_INST(i)->int_set;      return S_INST(i)->int_set;
598    default:    default:
599      ASC_PANIC("IntegerSetInstance called with non-set argument.\n");      ASC_PANIC("IntegerSetInstance called with non-set argument.");
600            
601    }    }
602  }  }
603    
604    
605  struct TypeDescription *InstanceTypeDesc(CONST struct Instance *i)  struct TypeDescription *InstanceTypeDesc(CONST struct Instance *i){
 {  
606    assert(i!=NULL);    assert(i!=NULL);
607    AssertMemory(i);    AssertMemory(i);
608    switch(i->t) {    switch(i->t) {
# Line 661  struct TypeDescription *InstanceTypeDesc Line 646  struct TypeDescription *InstanceTypeDesc
646    case SYMBOL_INST:    case SYMBOL_INST:
647      return NULL;      return NULL;
648    default:    default:
649      ASC_PANIC("Unknown instance type passed to InstanceTypeDesc.\n");      ASC_PANIC("Unknown instance type (i->t=%d)!",i->t);
650            
651    }    }
652  }  }
653    
654  unsigned long InstanceIndirected(CONST struct Instance *i)  unsigned long InstanceIndirected(CONST struct Instance *i){
 {  
655    assert(i!=NULL);    assert(i!=NULL);
656    if (InstanceKind(i) & IARR) {    if (InstanceKind(i) & IARR) {
657      return ARY_INST(i)->indirected;      return ARY_INST(i)->indirected;
# Line 675  unsigned long InstanceIndirected(CONST s Line 659  unsigned long InstanceIndirected(CONST s
659    return LONG_MAX;    return LONG_MAX;
660  }  }
661    
662  symchar *InstanceType(register CONST struct Instance *i)  symchar *InstanceType(register CONST struct Instance *i){
 {  
663    AssertMemory(i);    AssertMemory(i);
664    switch(i->t) {    switch(i->t) {
665    case SIM_INST:    /* Not sure -- return the type of root */    case SIM_INST:    /* Not sure -- return the type of root */
# Line 723  symchar *InstanceType(register CONST str Line 706  symchar *InstanceType(register CONST str
706    case SYMBOL_INST:    case SYMBOL_INST:
707      return GetBaseTypeName(symbol_type);      return GetBaseTypeName(symbol_type);
708    default:    default:
709      ASC_PANIC("InstanceType called on invalid instance.\n");      ASC_PANIC("InstanceType called on invalid instance.");
710            
711    }    }
712  }  }
713    
714    
715  struct BitList *InstanceBitList(CONST struct Instance *i)  struct BitList *InstanceBitList(CONST struct Instance *i){
 {  
716    AssertMemory(i);    AssertMemory(i);
717    switch(i->t) {    switch(i->t) {
718    case MODEL_INST:    case MODEL_INST:
# Line 757  struct BitList *InstanceBitList(CONST st Line 739  struct BitList *InstanceBitList(CONST st
739    case DUMMY_INST:    case DUMMY_INST:
740      return NULL;      return NULL;
741    default:    default:
742      ASC_PANIC("Unknown instance type passed to InstanceBitList.\n");      ASC_PANIC("Unknown instance type passed to InstanceBitList.");
743            
744    }    }
745  }  }

Legend:
Removed from v.1694  
changed lines
  Added in v.1695

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