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

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

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

revision 706 by johnpye, Mon Jun 26 14:04:49 2006 UTC revision 707 by johnpye, Tue Jun 27 05:49:11 2006 UTC
# Line 1  Line 1 
1  /*  /*  ASCEND modelling environment
2   *  Ascend Instantiator Implementation      Copyright (C) 2006 Carnegie Mellon University
3   *  by Tom Epperly      Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
4   *  Created: 1/24/90      Copyright (C) 1997 Benjamin Allan, Vicente Rico-Ramirez
5   *  Version: $Revision: 1.84 $  
6   *  Version control file: $RCSfile: instantiate.c,v $      This program is free software; you can redistribute it and/or modify
7   *  Date last modified: $Date: 2003/02/06 04:08:30 $      it under the terms of the GNU General Public License as published by
8   *  Last modified by: $Author: ballan $      the Free Software Foundation; either version 2, or (at your option)
9   *      any later version.
10   *  This file is part of the Ascend Language Interpreter.  
11   *      This program is distributed in the hope that it will be useful,
12   *  Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly      but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  Copyright (C) 1997 Benjamin Allan, Vicente Rico-Ramirez      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *      GNU General Public License for more details.
15   *  The Ascend Language Interpreter is free software; you can redistribute  
16   *  it and/or modify it under the terms of the GNU General Public License as      You should have received a copy of the GNU General Public License
17   *  published by the Free Software Foundation; either version 2 of the      along with this program; if not, write to the Free Software
18   *  License, or (at your option) any later version.      Foundation, Inc., 59 Temple Place - Suite 330,
19   *      Boston, MA 02111-1307, USA.
20   *  The Ascend Language Interpreter is distributed in hope that it will be  *//*
21   *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of      @file
22   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      Ascend Instantiator Implementation
23   *  General Public License for more details.  
24   *      @TODO this file is enormous and should be broken into pieces! -- JP
25   *  You should have received a copy of the GNU General Public License  *//*
26   *  along with the program; if not, write to the Free Software Foundation,      by Tom Epperly
27   *  Inc., 675 Mass Ave, Cambridge, MA 02139 USA.  Check the file named      Created: 1/24/90
28   *  COPYING.      Last in CVS: $Revision: 1.84 $ $Date: 2003/02/06 04:08:30 $ $Author: ballan $
29   *  */
30   */  
31  #include <stdarg.h>  #include <stdarg.h>
32  #include <utilities/ascConfig.h>  #include <utilities/ascConfig.h>
33  #include <utilities/ascMalloc.h>  #include <utilities/ascMalloc.h>
# Line 107  Line 107 
107  #include "watchpt.h"  #include "watchpt.h"
108  #include "initialize.h"  #include "initialize.h"
109  #include "instantiate.h"  #include "instantiate.h"
110  /* don't even THINK ABOUT adding instmacro.h to this list */  
111    /* don't even THINK ABOUT adding instmacro.h to this list -- ...what the? */
112    
113  #define MAXNUMBER 4     /* maximum number of iterations allowed  #define MAXNUMBER 4     /* maximum number of iterations allowed
114                                   * without change */                                   * without change */
# Line 138  struct Instance *g_cursim; Line 139  struct Instance *g_cursim;
139    
140  #define NEW_ext 1  #define NEW_ext 1
141  #define OLD_ext 0  #define OLD_ext 0
142  /*************************************************************************\  /**<
143  variable to check agreement in the number of boolean, integer or symbol      variable to check agreement in the number of boolean, integer or symbol
144  variables in the WHEN/SELECT statement with the number of boolean, integer      variables in the WHEN/SELECT statement with the number of boolean, integer
145  or symbol values in each of the CASEs      or symbol values in each of the CASEs
146  \*************************************************************************/  */
147    
148  #define MAX_VAR_IN_LIST  20  #define MAX_VAR_IN_LIST  20
149    /**<
150  /*      Variables to switch old and new pass 2 instantiation.
151   * Variables to switch old and new pass 2 instantiation.      The condition for using new pass 2 (anonymous type-based
152   * The condition for using new pass 2 (anonymous type-based      relation copying) is g_use_copyanon != 0 || FORCE applied.
153   * relation copying) is g_use_copyanon != 0  */
  * || FORCE applied.  
  */  
154    
155  int g_use_copyanon = 1;  int g_use_copyanon = 1;
156  /* g_use_copyanon is the user switch for anonymous type based relation  /**
157   * copying. if 0, no copying by that method is done.      the user switch for anonymous type based relation
158   */      copying. if 0, no copying by that method is done.
159    */
160    
161  #if TIMECOMPILER  #if TIMECOMPILER
162  static  static int g_ExecuteREL_CreateTokenRelation_calls = 0;
163  int g_ExecuteREL_CreateTokenRelation_calls = 0;  /**<
164  /* count the number of calls to CreateTokenRelation from ExecuteREL */      count the number of calls to CreateTokenRelation from ExecuteREL
165    */
166    
167  int g_CopyAnonRelation = 0;  int g_CopyAnonRelation = 0;
168  #endif  #endif
169    
170  long int g_compiler_counter = 1;  long int g_compiler_counter = 1;
171  /*  /**<
172   * What: counter incremented every time a compiler action capable of      What: counter incremented every time a compiler action capable of
173   *       changing the instance tree is executed.           changing the instance tree is executed.
174   *       At present the compiler cares nothing about this counter,           At present the compiler cares nothing about this counter,
175   *       but it is provided as a service to clients.           but it is provided as a service to clients.
176   *      
177   * Real applications:      Real applications:
178   * 1) This variable is used for keeping track of calls to      1) This variable is used for keeping track of calls to
179   * the compiler which will create the need for a total solver system      the compiler which will create the need for a total solver system
180   * rebuild.  This variable should be incremented anytime a function      rebuild.  This variable should be incremented anytime a function
181   * which changes the instance tree is called.      which changes the instance tree is called.
182   */  */
183    
184  /* #define DEBUG_RELS */  /* #define DEBUG_RELS */
185  /* undef DEBUG_RELS if you want less spew in pass 2 */  /* undef DEBUG_RELS if you want less spew in pass 2 */
# Line 208  static char *g_trychildexpansion_errmess Line 210  static char *g_trychildexpansion_errmess
210  static CONST char InstantiatorRCSid[] = "$Id: instantiate.c,v 1.84 2003/02/06 04:08:30 ballan Exp $";  static CONST char InstantiatorRCSid[] = "$Id: instantiate.c,v 1.84 2003/02/06 04:08:30 ballan Exp $";
211  #endif  #endif
212    
213    /*------------------------------------------------------------------------------
214        forward declarations
215    */
216    
217  /*************************   forward declarations   ************************/  static void WriteForValueError(struct Statement *, struct value_t);
218    static void MakeInstance(CONST struct Name *, struct TypeDescription *, int,
 static  
 void WriteForValueError(struct Statement *, struct value_t);  
 static  
 void MakeInstance(CONST struct Name *, struct TypeDescription *, int,  
219                    struct Instance *, struct Statement *, struct Instance *);                    struct Instance *, struct Statement *, struct Instance *);
220  static  static int CheckVarList(struct Instance *, struct Statement *);
221  int CheckVarList(struct Instance *, struct Statement *);  static int CheckWhereStatements(struct Instance *,struct StatementList *);
222  static  static int ExecuteISA(struct Instance *, struct Statement *);
223  int CheckWhereStatements(struct Instance *,struct StatementList *);  static int ExecuteCASGN(struct Instance *, struct Statement *);
224  static  static int DigestArguments(struct Instance *,
 int ExecuteISA(struct Instance *, struct Statement *);  
 static  
 int ExecuteCASGN(struct Instance *, struct Statement *);  
 static  
 int DigestArguments(struct Instance *,  
225                      struct gl_list_t *, struct StatementList *,                      struct gl_list_t *, struct StatementList *,
226                      struct StatementList *, struct Statement *);                      struct StatementList *, struct Statement *);
227  static  static int DeriveSetType(CONST struct Set *, struct Instance *,CONST unsigned int);
 int DeriveSetType(CONST struct Set *, struct Instance *,CONST unsigned int);  
228    
229  static  static struct gl_list_t *FindInsts(struct Instance *, CONST struct VariableList *,
 struct gl_list_t *FindInsts(struct Instance *, CONST struct VariableList *,  
230                              enum find_errors *);                              enum find_errors *);
231    
232  static  static void MissingInsts(struct Instance *, CONST struct VariableList *,int);
233  void MissingInsts(struct Instance *, CONST struct VariableList *,int);  static struct gl_list_t *FindArgInsts(struct Instance *, struct Set *,
 static  
 struct gl_list_t *FindArgInsts(struct Instance *, struct Set *,  
234                                 enum find_errors *);                                 enum find_errors *);
235  static void AddIncompleteInst(struct Instance *);  static void AddIncompleteInst(struct Instance *);
236  static int CheckALIASES(struct Instance *, struct Statement *);  static int CheckALIASES(struct Instance *, struct Statement *);
237  static int CheckARR(struct Instance *, struct Statement *);  static int CheckARR(struct Instance *, struct Statement *);
238  static int CheckISA(struct Instance *, struct Statement *);  static int CheckISA(struct Instance *, struct Statement *);
239  static  static int AssignStructuralValue(struct Instance *,struct value_t,struct Statement *);
 int AssignStructuralValue(struct Instance *,struct value_t,struct Statement *);  
240  static int  CheckSELECT(struct Instance *, struct Statement *);  static int  CheckSELECT(struct Instance *, struct Statement *);
241  static int  CheckWHEN(struct Instance *, struct Statement *);  static int  CheckWHEN(struct Instance *, struct Statement *);
242  static void MakeRealWhenCaseReferencesFOR(struct Instance *,  static void MakeRealWhenCaseReferencesFOR(struct Instance *,
# Line 302  static int ExecuteUnSelectedWHEN(struct Line 293  static int ExecuteUnSelectedWHEN(struct
293  static void ReEvaluateSELECT(struct Instance *, unsigned long *,  static void ReEvaluateSELECT(struct Instance *, unsigned long *,
294                               struct Statement *, int, int *);                               struct Statement *, int, int *);
295    
296  /***************************************************************************/  /*-----------------------------------------------------------------------------
297        ...
298    */
299    
300    
301  static  static
# Line 331  void WriteSetError(struct Statement *sta Line 324  void WriteSetError(struct Statement *sta
324                               : "Set type specified for a non-set type");                               : "Set type specified for a non-set type");
325  }  }
326    
327  /*  /**
328   * This code will emit error messages only on the last      This code will emit error messages only on the last
329   * iteration when trying to clear pending statements.      iteration when trying to clear pending statements.
330   * g_iteration is the global iteration counter, and MAXNUMBER      g_iteration is the global iteration counter, and MAXNUMBER
331   * is the number of times that the instantiator will try      is the number of times that the instantiator will try
332   * to clear the list, without change.      to clear the list, without change.
333   */  */
334  static  static
335  void WriteUnexecutedMessage(FILE *f, struct Statement *stat, CONST char *msg)  void WriteUnexecutedMessage(FILE *f, struct Statement *stat, CONST char *msg)
336  {  {
# Line 345  void WriteUnexecutedMessage(FILE *f, str Line 338  void WriteUnexecutedMessage(FILE *f, str
338  }  }
339    
340    
341  /*  /**
342   * Write Unexecuted Error Message in Pass 3 WUEMPASS3      Write Unexecuted Error Message in Pass 3 WUEMPASS3
343   *      
344   * This code will emit error messages only on the last      This code will emit error messages only on the last
345   * iteration of pass3 when trying to clear pending statements.      iteration of pass3 when trying to clear pending statements.
346   * g_iteration is the global iteration counter, and PASS3MAXNUMBER      g_iteration is the global iteration counter, and PASS3MAXNUMBER
347   * is the number of times that the instantiator will try      is the number of times that the instantiator will try
348   * to clear the list, without change.      to clear the list, without change.
349   */  */
   
350  static  static
351  void WUEMPASS3(FILE *f, struct Statement *stat, CONST char *msg)  void WUEMPASS3(FILE *f, struct Statement *stat, CONST char *msg)
352  {  {
353    if (g_iteration>=(PASS3MAXNUMBER)) WSSM(f,stat,msg,0);    if (g_iteration>=(PASS3MAXNUMBER)) WSSM(f,stat,msg,0);
354  }  }
355    
356    /*------------------------------------------------------------------------------
357      DENSE ARRAY PROCESSING
358    
359  /***************************************************************\      ...mostly
360    dense array processing, mostly.  */
 \***************************************************************/  
361    
362  /*  /**
363   * returns 0 if c is NULL, probably should be -1.      returns 0 if c is NULL, probably should be -1.
364   * -2 if c is illegal set type      -2 if c is illegal set type
365   * 1 if c IS_A integer_constant set type      1 if c IS_A integer_constant set type
366   * 0 if c IS_A symbol_constant set type      0 if c IS_A symbol_constant set type
367   * statement is used only to issue error messages.      @param statement is used only to issue error messages.
368   */  */
369  static  static
370  int CalcSetType(symchar *c, struct Statement *statement)  int CalcSetType(symchar *c, struct Statement *statement)
371  {  {
# Line 393  int CalcSetType(symchar *c, struct State Line 386  int CalcSetType(symchar *c, struct State
386    }    }
387  }  }
388    
389  /* last minute check for set values that subscript arrays.  /**
390   * probably should check constantness too but does not.      last minute check for set values that subscript arrays.
391   * return 0 if ok, 1 if not.      probably should check constantness too but does not.
392   */      return 0 if ok, 1 if not.
393    */
394  static  static
395  int CheckSetVal(struct value_t setval)  int CheckSetVal(struct value_t setval)
396  {  {
# Line 437  int CheckSetVal(struct value_t setval) Line 431  int CheckSetVal(struct value_t setval)
431    }    }
432    return 0;    return 0;
433  }  }
434  /* This attempts to evaluate a the next undone subscript of the  
435   * array and call ExpandArray with that set value.  /**
436   * In the case of ALIAS arrays this must always succeed, because      This attempts to evaluate a the next undone subscript of the
437   * we have checked first that it will. If it did not we would      array and call ExpandArray with that set value.
438   * be stuck because later calls to ExpandArray will not know      In the case of ALIAS arrays this must always succeed, because
439   * the difference between the unexpanded alias array and the      we have checked first that it will. If it did not we would
440   * unexpanded IS_A array.      be stuck because later calls to ExpandArray will not know
441   * Similarly, in the case of parameterized arrays this must      the difference between the unexpanded alias array and the
442   * always succeed, OTHERWISE ExpandArray will not know the      unexpanded IS_A array.
443   * arguments of the IS_A type, arginst next time around.  
444   *      Similarly, in the case of parameterized arrays this must
445   * In the event that the set given or set value expanded is bogus,      always succeed, OTHERWISE ExpandArray will not know the
446   * returns 1 and statement from which this call was derived is      arguments of the IS_A type, arginst next time around.
447   * semantically garbage.  
448   */      In the event that the set given or set value expanded is bogus,
449        returns 1 and statement from which this call was derived is
450        semantically garbage.
451    */
452  static  static
453  int ValueExpand(struct Instance *i, unsigned long int pos,  int ValueExpand(struct Instance *i, unsigned long int pos,
454                   struct value_t value, int *changed,                   struct value_t value, int *changed,
# Line 489  int ValueExpand(struct Instance *i, unsi Line 486  int ValueExpand(struct Instance *i, unsi
486    return 0;    return 0;
487  }  }
488    
489  /* When an incorrect combination of sparse and dense indices is found,  /**
490   * marks the statement wrong and whines. If the statement has already      When an incorrect combination of sparse and dense indices is found,
491   * been marked wrong, does not whine.      marks the statement wrong and whines. If the statement has already
492   * In FOR loops,      been marked wrong, does not whine.
493   * this function warns  about a problem that the implementation really  
494   * should allow. Alas, the fix is pending a complete rework of arrays.      In FOR loops,
495   * In user is idiot case,      this function warns  about a problem that the implementation really
496   * this really should have been ruled out by checkisa, which lets a little      should allow. Alas, the fix is pending a complete rework of arrays.
497   * too much trash through. Our whole array implementation sucks.  
498   */      In user is idiot case,
499        this really should have been ruled out by checkisa, which lets a little
500        too much trash through. Our whole array implementation sucks.
501    */
502  static  static
503  void SignalChildExpansionFailure(struct Instance *work,unsigned long cnum)  void SignalChildExpansionFailure(struct Instance *work,unsigned long cnum)
504  {  {
# Line 533  void SignalChildExpansionFailure(struct Line 533  void SignalChildExpansionFailure(struct
533    return;    return;
534  }  }
535    
536  /*  /**
537   * Should never be called with BOTH rhs(inst/list) and arginst != NULL,      Should never be called with BOTH rhs(inst/list) and arginst != NULL,
538   * but one or both may be NULL depending on other circumstances.      but one or both may be NULL depending on other circumstances.
539   * Should never be called on ALIASES/IS_A inside a for loop.      Should never be called on ALIASES/IS_A inside a for loop.
540   * Returns an error number other than 0 if called inside a for loop.      Returns an error number other than 0 if called inside a for loop.
541   * If error, outer scope should mark statement incorrect.      If error, outer scope should mark statement incorrect.
542   */  */
543  static  static
544  int TryChildExpansion(struct Instance *child,  int TryChildExpansion(struct Instance *child,
545                         struct Instance *parent,                         struct Instance *parent,
# Line 573  int TryChildExpansion(struct Instance *c Line 573  int TryChildExpansion(struct Instance *c
573    return error;    return error;
574  }  }
575    
576  /* expands, if possible, children of nonrelation,  /**
577   * nonalias, nonparameterized arrays.      expands, if possible, children of nonrelation,
578   */      nonalias, nonparameterized arrays.
579    */
580  static  static
581  void TryArrayExpansion(struct Instance *work, int *changed)  void TryArrayExpansion(struct Instance *work, int *changed)
582  {  {
# Line 623  void DestroyIndexList(struct gl_list_t * Line 624  void DestroyIndexList(struct gl_list_t *
624    }    }
625  }  }
626    
627    /**
628        returns 1 if ex believed to be integer, 0 if symbol, and -1 if
629        confused. if searchfor TRUE, includes fortable in search
630    */
631  static  static
632  int FindExprType(CONST struct Expr *ex, struct Instance *parent,  int FindExprType(CONST struct Expr *ex, struct Instance *parent,
633                   CONST unsigned int searchfor)                   CONST unsigned int searchfor
634  /*********************************************************************\  ){
  returns 1 if ex believed to be integer, 0 if symbol, and -1 if  
  confused. if searchfor TRUE, includes fortable in search  
 \*********************************************************************/  
 {  
635    struct Instance *i;    struct Instance *i;
636    struct gl_list_t *ilist;    struct gl_list_t *ilist;
637    enum find_errors err;    enum find_errors err;
# Line 698  int FindExprType(CONST struct Expr *ex, Line 699  int FindExprType(CONST struct Expr *ex,
699    }    }
700  }  }
701    
702    /**
703        returns -1 if has no clue,
704        returns 1 if set appears to be int set
705        returns 0 if apparently symbol_constant set.
706    */
707  static  static
708  int DeriveSetType(CONST struct Set *sptr, struct Instance *parent,  int DeriveSetType(CONST struct Set *sptr, struct Instance *parent,
709                    CONST unsigned int searchfor)                    CONST unsigned int searchfor
710  /*********************************************************************\  ){
 returns -1 if has no clue,  
 returns 1 if set appears to be int set  
 returns 0 if apparently symbol_constant set.  
 \*********************************************************************/  
 {  
711    register CONST struct Set *ptr;    register CONST struct Set *ptr;
712    int result=-1;        /* -1 indicates a failure */    int result=-1;        /* -1 indicates a failure */
713    ptr = sptr;    ptr = sptr;
# Line 726  returns 0 if apparently symbol_constant Line 727  returns 0 if apparently symbol_constant
727    return -1;            /* undefined type */    return -1;            /* undefined type */
728  }  }
729    
730  /*  /**
731   * Returns a gllist contain the string form (or forms) of array      Returns a gllist contain the string form (or forms) of array
732   * subscripts(s)      subscripts(s)
733   * e.g. Name a[1..2]['foo']      e.g. Name a[1..2]['foo']
734   * will return a gllist containing something like:      will return a gllist containing something like:
735   * "1..2"      "1..2"
736   * "foo"      "foo"
737   */  */
738  static  static
739  struct gl_list_t *ArrayIndices(CONST struct Name *name,  struct gl_list_t *ArrayIndices(CONST struct Name *name,
740                                 struct Instance *parent)                                 struct Instance *parent)
# Line 764  struct gl_list_t *ArrayIndices(CONST str Line 765  struct gl_list_t *ArrayIndices(CONST str
765    return result;    return result;
766  }  }
767    
768  /**************************************************************************\  /*-----------------------------------------------------------------------------
769    Sparse and Dense Array Processing.    SPARSE AND DENSE ARRAY PROCESSING
770  \**************************************************************************/  */
771    
772  /* this function has been modified to handle list results when called  /**
773   * from check aliases and dense executearr.      this function has been modified to handle list results when called
774   * The indices made here in the aliases case where the alias is NOT      from check aliases and dense executearr.
775   * inside a FOR loop are NOT for consumption by anyone because they      The indices made here in the aliases case where the alias is NOT
776   * contain a dummy index type. They merely indicate that      inside a FOR loop are NOT for consumption by anyone because they
777   * indices can be made. They should be immediately destroyed.      contain a dummy index type. They merely indicate that
778   * DestroyIndexType is the only thing that groks the Dummy.      indices can be made. They should be immediately destroyed.
779   * This should not be called on the final subscript of an ALIASES/IS_A      DestroyIndexType is the only thing that groks the Dummy.
780   * inside a FOR loop unless you can grok a dummy in last place.      This should not be called on the final subscript of an ALIASES/IS_A
781   */      inside a FOR loop unless you can grok a dummy in last place.
782    */
783  static  static
784  struct IndexType *MakeIndex(struct Instance *inst,  struct IndexType *MakeIndex(struct Instance *inst,
785                              CONST struct Set *sptr,                              CONST struct Set *sptr,
# Line 877  struct IndexType *MakeIndex(struct Insta Line 879  struct IndexType *MakeIndex(struct Insta
879    }    }
880  }  }
881    
882  /*  /**
883   * This function is used for making the indices of individual      This function is used for making the indices of individual
884   * elements of sparse arrays (and for checking that it is possible)      elements of sparse arrays (and for checking that it is possible)
885   * and for checking that the indices of dense alias arrays (a      and for checking that the indices of dense alias arrays (a
886   * very wierd thing to have) and dense parameterized IS_A      very wierd thing to have) and dense parameterized IS_A
887   * are fully defined so that aliases      are fully defined so that aliases
888   * and parameterized/sparse IS_A can be fully constructed in 1 pass.      and parameterized/sparse IS_A can be fully constructed in 1 pass.
889   * paves over the last subscript on sparse ALIASES-IS_A.      paves over the last subscript on sparse ALIASES-IS_A.
890   */  */
891  static  static
892  struct gl_list_t *MakeIndices(struct Instance *inst,  struct gl_list_t *MakeIndices(struct Instance *inst,
893                                CONST struct Name *name,                                CONST struct Name *name,
# Line 917  struct gl_list_t *MakeIndices(struct Ins Line 919  struct gl_list_t *MakeIndices(struct Ins
919    return result;    return result;
920  }  }
921    
 /*************************************************************************\  
   Sparse and Dense Array Processing.  
 \**************************************************************************/  
922  static  static
923  void LinkToParentByName(struct Instance *inst,  void LinkToParentByName(struct Instance *inst,
924                          struct Instance *child,                          struct Instance *child,
# Line 963  struct Instance *GetArrayHead(struct Ins Line 962  struct Instance *GetArrayHead(struct Ins
962    return NULL;    return NULL;
963  }  }
964    
965  /*  /**
966   * We are inside a FOR loop.      We are inside a FOR loop.
967   * If rhsinst is not null, we are in an alias statement and      If rhsinst is not null, we are in an alias statement and
968   * will use rhsinst as the child added instead of      will use rhsinst as the child added instead of
969   * creating a new child.      creating a new child.
970   * If arginst is not null, we will use it to aid in      If arginst is not null, we will use it to aid in
971   * creating IS_A elements.      creating IS_A elements.
972   * at least one of arginst, rhsinst must be NULL.      at least one of arginst, rhsinst must be NULL.
973   * If last !=0, returns NULL naturally and ok.      If last !=0, returns NULL naturally and ok.
974   */  */
975  static  static
976  struct Instance *DoNextArray(struct Instance *parentofary, /* MODEL */  struct Instance *DoNextArray(struct Instance *parentofary, /* MODEL */
977                               struct Instance *ptr, /* array layer */                               struct Instance *ptr, /* array layer */
# Line 1046  struct Instance *DoNextArray(struct Inst Line 1045  struct Instance *DoNextArray(struct Inst
1045    }    }
1046  }  }
1047    
1048  /*  /**
1049   * We are inside a FOR loop.      We are inside a FOR loop.
1050   * If rhsinst is not null, we are in an alias statement and      If rhsinst is not null, we are in an alias statement and
1051   * will eventually use rhsinst as the child added instead of      will eventually use rhsinst as the child added instead of
1052   * creating a new child.      creating a new child.
1053   * we expand each subscript individually here rahter than recursively.      we expand each subscript individually here rahter than recursively.
1054   * If we are on last subscript of an ALIASES/IS_A, we copy the      If we are on last subscript of an ALIASES/IS_A, we copy the
1055   * layer in rhslist rather than expanding individually.      layer in rhslist rather than expanding individually.
1056   * rhslist and intset only make sense simultaneously.      rhslist and intset only make sense simultaneously.
1057   */  */
1058  static  static
1059  struct Instance *AddArrayChild(struct Instance *parentofary,  struct Instance *AddArrayChild(struct Instance *parentofary,
1060                                 CONST struct Name *name,                                 CONST struct Name *name,
# Line 1085  struct Instance *AddArrayChild(struct In Line 1084  struct Instance *AddArrayChild(struct In
1084    }    }
1085  }  }
1086    
1087  /*  /**
1088   * Create the sparse array typedesc based on the statement kind      Create the sparse array typedesc based on the statement kind
1089   * and also add first child named. intset and def used for nonrelation types      and also add first child named. intset and def used for nonrelation types
1090   * only.      only.
1091   * This function returns the child pointer because relation functions  
1092   * need it, not because the child is unconnected.      This function returns the child pointer because relation functions
1093   * If rhsinst is not NULL, uses rhsinst instead of creating new one.      need it, not because the child is unconnected.
1094   * If rhslist is not NULL, uses rhslist instead of rhsinst or creating.      
1095   * It is expected that all subscripts will be evaluatable and that      If rhsinst is not NULL, uses rhsinst instead of creating new one.
1096   * in the case of the ALIASES-IS_A statement, the IS_A part is done      If rhslist is not NULL, uses rhslist instead of rhsinst or creating.
1097   * just before the ALIASES part.  
1098   */      It is expected that all subscripts will be evaluatable and that
1099        in the case of the ALIASES-IS_A statement, the IS_A part is done
1100        just before the ALIASES part.
1101    */
1102  static  static
1103  struct Instance *MakeSparseArray(struct Instance *parent,  struct Instance *MakeSparseArray(struct Instance *parent,
1104                                   CONST struct Name *name,                                   CONST struct Name *name,
# Line 1147  struct Instance *MakeSparseArray(struct Line 1149  struct Instance *MakeSparseArray(struct
1149    }    }
1150  }  }
1151    
1152    /*------------------------------------------------------------------------------
1153  /* handles construction of alias statements, allegedly, per lhs.      ...
1154   * parent function should find rhs and send it in as rhsinst.  */
1155   * rhsinst == null should never be used with this function.  
1156   * currently, arrays ignored, fatally.  /**
1157   */      handles construction of alias statements, allegedly, per lhs.
1158        parent function should find rhs and send it in as rhsinst.
1159        rhsinst == null should never be used with this function.
1160        currently, arrays ignored, fatally.
1161    */
1162  static  static
1163  void MakeAliasInstance(CONST struct Name *name,  void MakeAliasInstance(CONST struct Name *name,
1164                         CONST struct TypeDescription *basedef,                         CONST struct TypeDescription *basedef,
# Line 1277  void MakeAliasInstance(CONST struct Name Line 1283  void MakeAliasInstance(CONST struct Name
1283    }    }
1284  }  }
1285    
1286  /* returns 1 if concluded with statement, 0 if might try later.  /**
1287   */      @return 1 if concluded with statement, 0 if might try later.
1288    */
1289  static  static
1290  int ExecuteALIASES(struct Instance *inst, struct Statement *statement)  int ExecuteALIASES(struct Instance *inst, struct Statement *statement)
1291  {  {
# Line 1333  int ExecuteALIASES(struct Instance *inst Line 1340  int ExecuteALIASES(struct Instance *inst
1340  }  }
1341    
1342    
1343  /****************** support for ALIASES-IS_A statements ******************/  /*------------------------------------------------------------------------------
1344      SUPPORT FOR ALIASES-IS_A STATEMENTS
1345    */
1346    
1347  /* enforce max len and no ' rules for subscripts. string returned  /**
1348   * may not be string sent.      enforce max len and no-apostrope (') rules for subscripts. string returned
1349   */      may not be string sent.
1350    */
1351  static  static
1352  char *DeSingleQuote(char *s)  char *DeSingleQuote(char *s)
1353  {  {
# Line 1369  char *DeSingleQuote(char *s) Line 1379  char *DeSingleQuote(char *s)
1379    return old;    return old;
1380  }  }
1381    
1382  /* returns a symchar based on but not in strset,  /**
1383   * and adds original and results to sym table.      returns a symchar based on but not in strset,
1384   * destroys the s given.      and adds original and results to sym table.
1385   */      destroys the s given.
1386    */
1387  static  static
1388  symchar *UniquifyString(char *s, struct set_t *strset)  symchar *UniquifyString(char *s, struct set_t *strset)
1389  {  {
# Line 1449  void DestroyArrayElements(struct gl_list Line 1460  void DestroyArrayElements(struct gl_list
1460    gl_destroy(rhslist);    gl_destroy(rhslist);
1461  }  }
1462    
1463  /*  /**
1464   * this function computes the subscript set (or generates it if      this function computes the subscript set (or generates it if
1465   * needed) and checks it for matching against the instance list      needed) and checks it for matching against the instance list
1466   * and whines when things aren't kosher.      and whines when things aren't kosher.
1467   * When things are kosher, creates a gl_list of array children.      When things are kosher, creates a gl_list of array children.
1468   * This list is returned through rhslist.      This list is returned through rhslist.
1469   */  */
1470  static  static
1471  struct value_t ComputeArrayElements(struct Instance *inst,  struct value_t ComputeArrayElements(struct Instance *inst,
1472                                      struct Statement *statement,                                      struct Statement *statement,
# Line 1583  struct value_t ComputeArrayElements(stru Line 1594  struct value_t ComputeArrayElements(stru
1594    }    }
1595  }  }
1596    
1597  /* returns 1 if concluded with statement, 0 if might try later.  /**
1598   */      @return 1 if concluded with statement, 0 if might try later.
1599    */
1600  static  static
1601  int ExecuteARR(struct Instance *inst, struct Statement *statement)  int ExecuteARR(struct Instance *inst, struct Statement *statement)
1602  {  {
# Line 1700  int ExecuteARR(struct Instance *inst, st Line 1712  int ExecuteARR(struct Instance *inst, st
1712    return 1;    return 1;
1713  }  }
1714    
1715    /*------------------------------------------------------------------------------
1716  /*      ...
1717   * Makes a single instance of the type given,which must not be array  */
1718   * or relation of any kind or when.  /**
1719   * If type is a MODEL, adds the MODEL to pending list.      Makes a single instance of the type given,which must not be array
1720   * The argument intset is only used if type is set, then      or relation of any kind or when.
1721   * if intset==1, set ATOM made will be integer set.  
1722   * Attempts to find a UNIVERSAL before making the instance.      If type is a MODEL, adds the MODEL to pending list.
1723   * statement is used only for error messages.  
1724   */      The argument intset is only used if type is set, then
1725        if intset==1, set ATOM made will be integer set.
1726    
1727        Attempts to find a UNIVERSAL before making the instance.
1728    
1729        @param statement only used for error messages.
1730    */
1731  static  static
1732  struct Instance *MakeSimpleInstance(struct TypeDescription *def,  struct Instance *MakeSimpleInstance(struct TypeDescription *def,
1733                                      int intset,                                      int intset,
# Line 1791  void CountUnassignedConst(struct Instanc Line 1809  void CountUnassignedConst(struct Instanc
1809      }      }
1810    }    }
1811  }  }
1812  /* Returns 0 if all constant scalars in ipass are assigned,  /**
1813   * for ipass that are of set/scalar array/scalar type.      Returns 0 if all constant scalars in ipass are assigned,
1814   * Handles null input gracefully, as if there is something      for ipass that are of set/scalar array/scalar type.
1815   * unassigned in it.      Handles null input gracefully, as if there is something
1816   * Variable types are considered permanently assigned, since      unassigned in it.
1817   * we are checking for constants being unassigned.      Variable types are considered permanently assigned, since
1818   * Assumes arrays, if passed in, are fully expanded.      we are checking for constants being unassigned.
1819   */      Assumes arrays, if passed in, are fully expanded.
1820    */
1821  static  static
1822  int ArgValuesUnassigned(struct Instance *ipass)  int ArgValuesUnassigned(struct Instance *ipass)
1823  {  {
# Line 1846  int ArgValuesUnassigned(struct Instance Line 1865  int ArgValuesUnassigned(struct Instance
1865      return 1; /* NOTREACHED */      return 1; /* NOTREACHED */
1866    }    }
1867  }  }
1868  /*  /**
1869   * This function appends the pointers in the set chain s      Appends the pointers in the set chain s
1870   * into the list given args. args must not be NULL unless s is.      into the list given args. args must not be NULL unless s is.
1871   * If needed, args will be expanded, but if you know the length  
1872   * to expect, make args of that size before calling and this      If needed, args will be expanded, but if you know the length
1873   * will be faster.      to expect, make args of that size before calling and this
1874   * This does not go into the expressions (which may contain other      will be faster.
1875   * sets themselves) of the set nodes and disassemble them.      
1876   * The list may be safely destroyed, but its contents should not      This does not go into the expressions (which may contain other
1877   * be destroyed with it as they belong to something else in all      sets themselves) of the set nodes and disassemble them.
1878   * likelihood.      The list may be safely destroyed, but its contents should not
1879   * This function should be moved into a set header someplace.      be destroyed with it as they belong to something else in all
1880   */      likelihood.
1881        
1882        @TODO This function should be moved into a set header someplace.
1883    */
1884  static  static
1885  void SplitArgumentSet(CONST struct Set *s, struct gl_list_t *args)  void SplitArgumentSet(CONST struct Set *s, struct gl_list_t *args)
1886  {  {
# Line 1874  void SplitArgumentSet(CONST struct Set * Line 1896  void SplitArgumentSet(CONST struct Set *
1896    
1897  #define GETARG(l,n) ((struct Set *)gl_fetch((l),(n)))  #define GETARG(l,n) ((struct Set *)gl_fetch((l),(n)))
1898    
1899  /*  /**
1900   * returns 1 if all ok,      Check compatibility of array elements? -- JP
1901   * returns 0 if any array child is < type required,  
1902   * returns -1 if some array child is type incompatible with ptype/stype.      @return 1 if all ok, 0 if any array child is < type required,
1903   * Does some optimization around arrays of sets and array basetypes.          -1 if some array child is type incompatible with ptype/stype.
1904   * Doesn't check names.  
1905   */      Does some optimization around arrays of sets and array basetypes.
1906        Doesn't check names.
1907    */
1908  static  static
1909  int ArrayElementsTypeCompatible(CONST struct Instance *ipass,  int ArrayElementsTypeCompatible(CONST struct Instance *ipass,
1910                                  CONST struct TypeDescription *ptype,                                  CONST struct TypeDescription *ptype,
# Line 1939  int ArrayElementsTypeCompatible(CONST st Line 1963  int ArrayElementsTypeCompatible(CONST st
1963    return (lessrefined==0L); /* if any elements are inadequately refined, 0 */    return (lessrefined==0L); /* if any elements are inadequately refined, 0 */
1964  }  }
1965    
1966  /* returns a value_t, but the real result is learned by consulting err.  /**
1967   * err == 0 means some interesting value found.      returns a value_t, but the real result is learned by consulting err.
1968   * err == 1 means try again later      err == 0 means some interesting value found.
1969   * err == -1 means things are hopeless.      err == 1 means try again later
1970   */      err == -1 means things are hopeless.
1971    */
1972  static  static
1973  struct value_t FindArgValue(struct Instance *parent,  struct value_t FindArgValue(struct Instance *parent,
1974                              struct Set *argset,                              struct Set *argset,
# Line 2042  char *g_mpi_message[] = { Line 2067  char *g_mpi_message[] = {
2067  /* -25 */ "WHERE condition incorrect (nonboolean value)"  /* -25 */ "WHERE condition incorrect (nonboolean value)"
2068  };  };
2069    
2070  /* Returns MPIOK if value in ipass matches WITH_VALUE field of  /**
2071   * statement, or if the test is silly beacause ipass isn't      Returns MPIOK if value in ipass matches WITH_VALUE field of
2072   * a set/constant or if statement does not constrain value.      statement, or if the test is silly beacause ipass isn't
2073   * Returns MPIWAIT if statement truth cannot be tested because      a set/constant or if statement does not constrain value.
2074   * WITH_VALUE clause is not yet evaluatable.      Returns MPIWAIT if statement truth cannot be tested because
2075   * Returns MPIARGVAL if WITH_VALUE is provably unsatisfied.      WITH_VALUE clause is not yet evaluatable.
2076   * On truly garbage input, unlikely to return.      Returns MPIARGVAL if WITH_VALUE is provably unsatisfied.
2077   */      On truly garbage input, unlikely to return.
2078    */
2079  static  static
2080  int ArgValueCorrect(struct Instance *inst,  int ArgValueCorrect(struct Instance *inst,
2081                      struct Instance *tmpinst,                      struct Instance *tmpinst,
# Line 2172  int ArgValueCorrect(struct Instance *ins Line 2198  int ArgValueCorrect(struct Instance *ins
2198    return MPIOK;    return MPIOK;
2199  }  }
2200    
2201  /* evaluate a logical or real relation and see that it  /**
2202   * is satisfied.      evaluate a logical or real relation and see that it is satisfied.
2203   * BUG baa. needs to be exception safe and is not.      
2204   * returns MPIOK (satisfied)      @BUG baa. needs to be exception safe and is not.
2205   * returns MPIBADREL (dissatisified)  
2206   * returns MPIVARREL (dissatisified - variable result)      returns MPIOK (satisfied)
2207   * returns MPIWAIT (not yet determinable)      returns MPIBADREL (dissatisified)
2208   * returns MPIEXCEP (evaluation is impossible due to float/other error)      returns MPIVARREL (dissatisified - variable result)
2209   * returns MPINOTBOOL (dissatisfied- nonboolean result)      returns MPIWAIT (not yet determinable)
2210   * statement given should be a rel or logrel.      returns MPIEXCEP (evaluation is impossible due to float/other error)
2211   */      returns MPINOTBOOL (dissatisfied- nonboolean result)
2212        
2213        @param statement should be a rel or logrel.
2214    */
2215  static  static
2216  int MPICheckConstraint(struct Instance *tmpinst, struct Statement *statement)  int MPICheckConstraint(struct Instance *tmpinst, struct Statement *statement)
2217  {  {
# Line 2248  int MPICheckConstraint(struct Instance * Line 2277  int MPICheckConstraint(struct Instance *
2277    }    }
2278  }  }
2279    
2280  /*  /**
2281   * returns MPIOK if subscripts match declarations,      returns MPIOK if subscripts match declarations,
2282   * MPIWAIT if declarations cannot yet be interpretted,      MPIWAIT if declarations cannot yet be interpretted,
2283   * or some other error if there is a mismatch.      or some other error if there is a mismatch.
2284   * So far only the square version. Should have a forvar  
2285   * capable recursive version sometime when we allow      So far only the square version. Should have a forvar
2286   * passage of sparse arrays.      capable recursive version sometime when we allow
2287   * Assumes the array given has proper number of      passage of sparse arrays.
2288   * subscripts to match name and is fully expanded.  
2289   */      Assumes the array given has proper number of
2290        subscripts to match name and is fully expanded.
2291    */
2292  static  static
2293  int MPICheckSubscripts(struct Instance *tmpinst,  int MPICheckSubscripts(struct Instance *tmpinst,
2294                         struct Instance *aryinst,                         struct Instance *aryinst,
# Line 2277  int MPICheckSubscripts(struct Instance * Line 2308  int MPICheckSubscripts(struct Instance *
2308    }    }
2309  }  }
2310    
 /* links parent and child. if checkdup != 0,  
  * it will check child to see if it already has this parent.  
  */  
2311  #define NOIPICHECK 0  #define NOIPICHECK 0
2312  #define IPICHECK 1  #define IPICHECK 1
2313    /**
2314        links parent and child. if checkdup != 0,
2315        it will check child to see if it already has this parent.
2316    */
2317  static  static
2318  int InsertParameterInst(struct Instance *parent,  int InsertParameterInst(struct Instance *parent,
2319                          struct Instance *child,                          struct Instance *child,
# Line 2321  int InsertParameterInst(struct Instance Line 2353  int InsertParameterInst(struct Instance
2353    }    }
2354  }  }
2355    
2356  /*  /**
2357   * The instance this is called with should not have      The instance this is called with should not have
2358   * any parents whatsoever. The instance this is called      any parents whatsoever. The instance this is called
2359   * with will be completely destroyed including any parts      with will be completely destroyed including any parts
2360   * of the instance that do not have other parents.      of the instance that do not have other parents.
2361   */  */
2362  static  static
2363  void DestroyParameterInst(struct Instance *i)  void DestroyParameterInst(struct Instance *i)
2364  {  {
2365    DestroyInstance(i,NULL);    DestroyInstance(i,NULL);
2366  }  }
2367  /* destroys everything you send it. If you send some arguments in  
2368   * as null, we don't mind.  /**
2369   */      destroys everything you send it. If you send some arguments in
2370        as null, we don't mind.
2371    */
2372  static  static
2373  void ClearMPImem(  void ClearMPImem(
2374    struct gl_list_t *args,    struct gl_list_t *args,
# Line 2362  void ClearMPImem( Line 2396  void ClearMPImem(
2396    }    }
2397  }  }
2398    
2399    /**
2400         What is MPI? parallel computing stuff?? -- JP
2401    */
2402  static  static
2403  void mpierror(struct Set *argset,  void mpierror(struct Set *argset,
2404                unsigned long argn,                unsigned long argn,
# Line 2412  void MPIwum(struct Set *argset, Line 2448  void MPIwum(struct Set *argset,
2448    WriteUnexecutedMessage(ASCERR,statement,g_mpi_message[arrloc]);    WriteUnexecutedMessage(ASCERR,statement,g_mpi_message[arrloc]);
2449  }  }
2450    
2451  /* process pass by value scalar: evaluate and make it, or return  /**
2452   * appropriate whine if not possible.      process pass by value scalar: evaluate and make it, or return
2453   * If this returns anything other than mpiok, the user may      appropriate whine if not possible.
2454   * wish to dispose of tmpinst, args as we do not here.      If this returns anything other than mpiok, the user may
2455   * We do issue whines here, however.      wish to dispose of tmpinst, args as we do not here.
2456   */      We do issue whines here, however.
2457    */
2458  static  static
2459  int MPIMakeSimple(struct Instance *parent,  int MPIMakeSimple(struct Instance *parent,
2460                    struct Instance *tmpinst,                    struct Instance *tmpinst,
# Line 2470  int MPIMakeSimple(struct Instance *paren Line 2507  int MPIMakeSimple(struct Instance *paren
2507  }  }
2508  #define NOKEEPARGINST 0  #define NOKEEPARGINST 0
2509  #define KEEPARGINST 1  #define KEEPARGINST 1
2510  /*  /**
2511   * This function is responsible for checking and assembling the      Check and assemble the arguments of the parameterized type referenced in
2512   * arguments of the parameterized type referenced in statement,      statement, using information derived from the parent instance.
2513   * using information derived from the parent instance.  
2514   * If the type found in the statement given is not a MODEL type,      If the type found in the statement given is not a MODEL type,
2515   * we will immediately return 1 and *arginstptr will be set NULL.      we will immediately return 1 and *arginstptr will be set NULL.
2516   *  
2517   * In general, we are trying to check and assemble enough information      In general, we are trying to check and assemble enough information
2518   * to prove that a parameterized IS_A can be executed or proved wrong      to prove that a parameterized IS_A can be executed or proved wrong
2519   * once ExecuteISA sees it.      once ExecuteISA sees it.
2520   *  
2521   * If keepargs ==KEEPARGINST, then on a successful return,      If keepargs ==KEEPARGINST, then on a successful return,
2522   * *arginstptr will be to a MODEL instance (with no parents)      *arginstptr will be to a MODEL instance (with no parents)
2523   * with its children derived via parameter list filled in and      with its children derived via parameter list filled in and
2524   * all other children NULL.      all other children NULL.
2525   * If there are NO children derived via parameter list or      If there are NO children derived via parameter list or
2526   * the reductions list, then *arginstptr will be NULL.      the reductions list, then *arginstptr will be NULL.
2527   * If keepargs != KEEPARGINST, then arginstptr will not be      If keepargs != KEEPARGINST, then arginstptr will not be
2528   * used/set in any way, OTHERWISE it should be NULL on entry.      used/set in any way, OTHERWISE it should be NULL on entry.
2529   * If keepargs != KEEPARGINST, then we will do only the minimal      If keepargs != KEEPARGINST, then we will do only the minimal
2530   * necessary work to check that the arginst could be created.      necessary work to check that the arginst could be created.
2531   * At present, we can't tell what this last ambition amounts to -      At present, we can't tell what this last ambition amounts to -
2532   * we do the same amount of work regardless, though we try to put      we do the same amount of work regardless, though we try to put
2533   * the more likely to fail steps first.      the more likely to fail steps first.
2534   *  
2535   * A successful return value is 1.      A successful return value is 1.
2536   *      
2537   * A failure possibly to succeed later is 0.      A failure possibly to succeed later is 0.
2538   * Possible causes will be detailed via the WriteUnexecutedMessage      Possible causes will be detailed via the WriteUnexecutedMessage
2539   * facility.      facility.
2540   *  
2541   * A permanent failure is any value < 0.      A permanent failure is any value < 0.
2542   * Causes will be detailed via the WSEM facility, in addition return      Causes will be detailed via the WSEM facility, in addition return
2543   * values < 0 have the interpretations given in g_mpi_message[-value]      values < 0 have the interpretations given in g_mpi_message[-value]
2544   * above.      above.
2545   */      
2546  /*      @NOTE assumes statement is well formed, in terms of
2547   * assumes statement is well formed, in terms of      arglist of IS_A/IS_REFINED_TO (if there is one) being of correct length.
2548   * arglist of IS_A/IS_REFINED_TO (if there is one) being of correct length.      returns fairly quickly for nonmodel and nonparametric
2549   * returns fairly quickly for nonmodel and nonparametric      MODEL types.
2550   * MODEL types.  */
  */  
2551  static  static
2552  int MakeParameterInst(struct Instance *parent,  int MakeParameterInst(struct Instance *parent,
2553                        struct Statement *statement,                        struct Statement *statement,
# Line 2959  int MPICheckWBTS(struct Instance *tmpins Line 2995  int MPICheckWBTS(struct Instance *tmpins
2995  #define MPICheckWB(a,b) MPIWEIRD  #define MPICheckWB(a,b) MPIWEIRD
2996  /* WILL_BE not yet legal in where section. implement later if req'd */  /* WILL_BE not yet legal in where section. implement later if req'd */
2997    
2998  /*  /**
2999   * verifies that all the instances found, if any, are different.      verifies that all the instances found, if any, are different.
3000   * uses an nlogn (n = # of instance) algorithm, which      uses an nlogn (n = # of instance) algorithm, which
3001   * could be made order n using the interface pointer protocol,      could be made order n using the interface pointer protocol,
3002   * but the additional overhead makes the multiplier for      but the additional overhead makes the multiplier for
3003   * o(n) probably not worth the trouble.      o(n) probably not worth the trouble.
3004   */  */
3005  static  static
3006  int MPICheckWNBTS(struct Instance *tmpinst, struct Statement *statement)  int MPICheckWNBTS(struct Instance *tmpinst, struct Statement *statement)
3007  {  {
# Line 2997  int MPICheckWNBTS(struct Instance *tmpin Line 3033  int MPICheckWNBTS(struct Instance *tmpin
3033    gl_destroy(instances);    gl_destroy(instances);
3034    return MPIOK;    return MPIOK;
3035  }  }
3036  /*  
3037   * Checks the for statements, along with all the horrid machinery needed  /**
3038   * to make a for loop go.      Checks the for statements, along with all the horrid machinery needed
3039   */      to make a for loop go.
3040    */
3041  static  static
3042  int CheckWhereFOR(struct Instance *inst, struct Statement *statement)  int CheckWhereFOR(struct Instance *inst, struct Statement *statement)
3043  {  {
# Line 3083  int CheckWhereFOR(struct Instance *inst, Line 3120  int CheckWhereFOR(struct Instance *inst,
3120    }    }
3121    return code;    return code;
3122  }  }
3123  /*  
3124   * checks that all conditions are satisfied, else returns a whine.  /**
3125   * does not call mpierror, so caller ought to if needed.      checks that all conditions are satisfied, else returns a whine.
3126   * returns one of the defined MPI codes.      does not call mpierror, so caller ought to if needed.
3127   */      returns one of the defined MPI codes.
3128    */
3129  static  static
3130  int CheckWhereStatements(struct Instance *tmpinst, struct StatementList *sl)  int CheckWhereStatements(struct Instance *tmpinst, struct StatementList *sl)
3131  {  {
# Line 3158  struct parpendingentry { Line 3196  struct parpendingentry {
3196    
3197  #endif /* 0 migraining */  #endif /* 0 migraining */
3198    
3199  /*  /**
3200   * returns a single instance, if such can be properly derived      returns a single instance, if such can be properly derived
3201   * from the name given.      from the name given.
3202   * Returns NULL if too many or no instances are found.      
3203   * Probably ought to have a return code, but doesn't.      Returns NULL if too many or no instances are found.
3204   */      Probably ought to have a return code, but doesn't.
3205    */
3206  static  static
3207  struct Instance *GetNamedInstance(CONST struct Name *nptr,  struct Instance *GetNamedInstance(CONST struct Name *nptr,
3208                                    CONST struct Instance *tmpinst)                                    CONST struct Instance *tmpinst)
# Line 3186  struct Instance *GetNamedInstance(CONST Line 3225  struct Instance *GetNamedInstance(CONST
3225  }  }
3226    
3227  /*  /*
3228   * put the parameters open (if any) and absorbed statements into the      put the parameters open (if any) and absorbed statements into the
3229   * pending list we're creating.      pending list we're creating.
3230   */  */
3231  static  static
3232  struct parpendingentry *  struct parpendingentry *
3233  CreateParameterPendings(struct Instance *tmpinst,  CreateParameterPendings(struct Instance *tmpinst,
# Line 3308  void DestroyParameterPendings( struct pa Line 3347  void DestroyParameterPendings( struct pa
3347  }  }
3348    
3349  /*  /*
3350   * this function should not be entered until all WB arguments have      this function should not be entered until all WB arguments have
3351   * been installed in tmpinst.      been installed in tmpinst.
3352   */  */
3353  static  static
3354  int DigestArguments(  int DigestArguments(
3355                      struct Instance *tmpinst,                      struct Instance *tmpinst,
# Line 3587  void ConfigureReference(struct Instance Line 3626  void ConfigureReference(struct Instance
3626    }    }
3627  }  }
3628    
3629  /* Connect WILL_BE'd children from arginst to inst.  /**
3630   * Copy IS_A'd children from arginst to inst.      Connect WILL_BE'd children from arginst to inst.
3631   * At this point there can be no alias children -- all      Copy IS_A'd children from arginst to inst.
3632   * are either WILL_BE or IS_A of constants/arrays.      At this point there can be no alias children -- all
3633   * This must only be called with models when arginst !=NULL.      are either WILL_BE or IS_A of constants/arrays.
3634   * arginst == NULL --> immediate, no action return.      This must only be called with models when arginst !=NULL.
3635   * inst and arginst are assumed to be the same type.      arginst == NULL --> immediate, no action return.
3636   */      inst and arginst are assumed to be the same type.
3637    */
3638  void ConfigureInstFromArgs(struct Instance *inst,  void ConfigureInstFromArgs(struct Instance *inst,
3639                             CONST struct Instance *arginst)                             CONST struct Instance *arginst)
3640  {  {
# Line 3633  void ConfigureInstFromArgs(struct Instan Line 3673  void ConfigureInstFromArgs(struct Instan
3673    }    }
3674  }  }
3675    
3676  /*  /**
3677   * For Those children not already present in inst,      For Those children not already present in inst,
3678   * which must be of the same type as arginst.      which must be of the same type as arginst.
3679   * Connect WILL_BE'd children from arginst to inst.      Connect WILL_BE'd children from arginst to inst.
3680   * Copy IS_A'd children from arginst to inst.      Copy IS_A'd children from arginst to inst.
3681   * At this point there can be no alias children -- all      At this point there can be no alias children -- all
3682   * are either WILL_BE or IS_A of constants/arrays, so far as      are either WILL_BE or IS_A of constants/arrays, so far as
3683   * arginst is concerned.      arginst is concerned.
3684   * This must only be called with models when arginst !=NULL.      
3685   * arginst == NULL --> immediate, no action return.      This must only be called with models when arginst !=NULL.
3686   * inst is expected to be of same type as arginst.      arginst == NULL --> immediate, no action return.
3687   */      inst is expected to be of same type as arginst.
3688    */
3689  void ReConfigureInstFromArgs(struct Instance *inst,  void ReConfigureInstFromArgs(struct Instance *inst,
3690                               CONST struct Instance *arginst)                               CONST struct Instance *arginst)
3691  {  {
# Line 3700  int EqualChildInsts(struct Instance *i1, Line 3741  int EqualChildInsts(struct Instance *i1,
3741    return 0;    return 0;
3742  }  }
3743    
3744  /* Bugs:  /**
3745   * do not call this with instances other than variables/constants      On proper types returns 0 if the inst values are ==
3746   * or arrays of same. relations, models, etc make it barf or lie.      for the c1th child of i1 and c2th child of i2. OTHERWISE nonzero.
3747   * On proper types returns 0 if the inst values are ==  
3748   * for the c1th child of i1 and c2th child of i2. OTHERWISE nonzero.      @BUG
3749   */      do not call this with instances other than variables/constants
3750        or arrays of same. relations, models, etc make it barf or lie.
3751    */
3752  static  static
3753  int CompareChildInsts(struct Instance *i1, struct Instance *i2,  int CompareChildInsts(struct Instance *i1, struct Instance *i2,
3754                        unsigned long c1, unsigned long c2)                        unsigned long c1, unsigned long c2)
# Line 3727  int CompareChildInsts(struct Instance *i Line 3770  int CompareChildInsts(struct Instance *i
3770    }    }
3771  }  }
3772    
3773  /* Needs to see that all nonnull children in inst are compatible  /**
3774   * with corresponding children in mpi if such exist.      Needs to see that all nonnull children in inst are compatible
3775   * arginst must be as or morerefined than inst.      with corresponding children in mpi if such exist.
3776   * In particular, needs to be damned picky about where's being met      arginst must be as or morerefined than inst.
3777   * and types matching exactly because we won't refine up stuff  
3778   * by passing it through a parameter list.      In particular, needs to be damned picky about where's being met
3779   * WILL_BE child pointers of the arginst must = those in inst      and types matching exactly because we won't refine up stuff
3780   * when the inst has a child of that name.      by passing it through a parameter list.
3781   * IS_A child pointers of the arginst must have same value as      WILL_BE child pointers of the arginst must = those in inst
3782   * those in inst when the inst has a child of that name.      when the inst has a child of that name.
3783   * When inst has no child of that name, must eventually copy it      IS_A child pointers of the arginst must have same value as
3784   * to the expanded instance.      those in inst when the inst has a child of that name.
3785   * This has to check that absolutely everything is correct      When inst has no child of that name, must eventually copy it
3786   * because RefineClique/RefineInstance asks no questions.      to the expanded instance.
3787   * This itself assume arginst has been correctly constructed.  
3788   */      This has to check that absolutely everything is correct
3789        because RefineClique/RefineInstance asks no questions.
3790        This itself assume arginst has been correctly constructed.
3791    */
3792  static  static
3793  int CheckParamRefinement(struct Instance *parent,  int CheckParamRefinement(struct Instance *parent,
3794                           struct Instance *inst,                           struct Instance *inst,
# Line 3846  int CheckParamRefinement(struct Instance Line 3892  int CheckParamRefinement(struct Instance
3892    return MPIOK;    return MPIOK;
3893  }  }
3894    
3895    /*------------------------------------------------------------------------------
3896  /* handles construction of IS_A statements.      ...
3897   * MakeInstance and its subsidiaries must not cannibalize  */
3898   * parts from arginst, because it may be used again on  
3899   * subsequent calls when the IS_A has several lhs.  /**
3900   */      handles construction of IS_A statements.
3901        MakeInstance and its subsidiaries must not cannibalize
3902        parts from arginst, because it may be used again on
3903        subsequent calls when the IS_A has several lhs.
3904    */
3905  static  static
3906  void MakeInstance(CONST struct Name *name,  void MakeInstance(CONST struct Name *name,
3907                    struct TypeDescription *def,                    struct TypeDescription *def,
# Line 4026  int ExecuteISA(struct Instance *inst, st Line 4076  int ExecuteISA(struct Instance *inst, st
4076    }    }
4077  }  }
4078    
4079  /* handles construction of Dummy Instance  /**
4080   * A dummy instance is universal.      handles construction of Dummy Instance
4081   */      A dummy instance is universal.
4082    */
4083  static  static
4084  void MakeDummyInstance(CONST struct Name *name,  void MakeDummyInstance(CONST struct Name *name,
4085                         struct TypeDescription *def,                         struct TypeDescription *def,
# Line 4069  void MakeDummyInstance(CONST struct Name Line 4120  void MakeDummyInstance(CONST struct Name
4120  }  }
4121    
4122    
4123  /* Used for IS_A statement inside a non-matching CASE of a  /**
4124   * SELECT statement.      Used for IS_A statement inside a non-matching CASE of a
4125   * Make a dummy instance for each name in vlisti,      SELECT statement.
4126   * but arrays are not expanded over subscripts.  
4127   * The dummy instance is UNIVERSAL.      Make a dummy instance for each name in vlisti, but arrays are not expanded
4128   */      over subscripts. The dummy instance is UNIVERSAL.
4129    */
4130  static  static
4131  int ExecuteUnSelectedISA( struct Instance *inst, struct Statement *statement)  int ExecuteUnSelectedISA( struct Instance *inst, struct Statement *statement)
4132  {  {
# Line 4102  int ExecuteUnSelectedISA( struct Instanc Line 4154  int ExecuteUnSelectedISA( struct Instanc
4154  }  }
4155    
4156    
4157  /*  /**
4158   * For ALIASES inside a non matching CASEs of a SELECT statement, we      For ALIASES inside a non matching CASEs of a SELECT statement, we
4159   * do not even have to care about the rhs. Similar to ISAs, we only      do not even have to care about the rhs. Similar to ISAs, we only
4160   * take the list of variables and create the dummy instance      take the list of variables and create the dummy instance
4161   */  */
4162  static  static
4163  int ExecuteUnSelectedALIASES(struct Instance *inst,  int ExecuteUnSelectedALIASES(struct Instance *inst,
4164                               struct Statement *statement)                               struct Statement *statement)
# Line 4122  int ExecuteUnSelectedALIASES(struct Inst Line 4174  int ExecuteUnSelectedALIASES(struct Inst
4174    return 1;    return 1;
4175  }  }
4176    
4177    /*------------------------------------------------------------------------------
4178        REFERENCE STATEMENT PROCESSING
4179    
4180  /*      "Highly incomplete      KAA_DEBUG"
4181   **************************************************************************  */
  * Reference Statement Processing  
  *  
  * Highly incomplete        KAA_DEBUG  
  **************************************************************************  
  */  
4182    
4183  #ifdef THIS_IS_AN_UNUSED_FUNCTION  #ifdef THIS_IS_AN_UNUSED_FUNCTION
4184  static  static
# Line 4153  int ExecuteREF(struct Instance *inst, st Line 4202  int ExecuteREF(struct Instance *inst, st
4202    return 1;    return 1;
4203  }  }
4204    
4205  /*  /**
4206   * Finds all the instances required to evaluate set element given.      Finds all the instances required to evaluate set element given.
4207   * If problem, returns NULL and err should be consulted.      If problem, returns NULL and err should be consulted.
4208   * Note this may have some angst around FOR vars, as it      Note this may have some angst around FOR vars, as it
4209   * should since forvars are not instances.      should since forvars are not instances.
4210   * Lint is precluding passing a forvar where an instance is required.      
4211   * err should only be consulted if result comes back NULL.      Lint is precluding passing a forvar where an instance is required.
4212   * Note also that we will ignore any sets chained on to the end      err should only be consulted if result comes back NULL.
4213   * of s.  
4214   */      @NOTE that we will ignore any sets chained on to the end of s.
4215    */
4216  static  static
4217  struct gl_list_t *FindArgInsts(struct Instance *parent,  struct gl_list_t *FindArgInsts(struct Instance *parent,
4218                                 struct Set *s,                                 struct Set *s,
# Line 4189  struct gl_list_t *FindArgInsts(struct In Line 4239  struct gl_list_t *FindArgInsts(struct In
4239    return result;    return result;
4240  }  }
4241    
4242  /**************************************************************************\  /**
4243     FindInsts: makes sure at least one thing is found for      Find instances: Make sure at least one thing is found for each name item
4244     each name item on list (else returned list will be NULL)      on list (else returned list will be NULL) and return the collected instances.
4245     and returns the collected instances.  */
 \**************************************************************************/  
4246  static  static
4247  struct gl_list_t *FindInsts(struct Instance *inst,  struct gl_list_t *FindInsts(struct Instance *inst,
4248                              CONST struct VariableList *list,                              CONST struct VariableList *list,
# Line 4218  struct gl_list_t *FindInsts(struct Insta Line 4267  struct gl_list_t *FindInsts(struct Insta
4267    return result;    return result;
4268  }  }
4269    
4270  /**************************************************************************\  /**
4271     MissingInsts: makes sure at least one thing is found for     Missing instances: makes sure at least one thing is found for
4272     each name item on list (else prints the name with a little message)     each name item on list (else prints the name with a little message)
4273     if noisy != 0 || on last iteration, does the printing, OTHERWISE     if noisy != 0 || on last iteration, does the printing, OTHERWISE
4274     returns immediately.     returns immediately.
4275  \**************************************************************************/  */
4276  static  static
4277  void MissingInsts(struct Instance *inst,  void MissingInsts(struct Instance *inst,
4278                    CONST struct VariableList *list,                    CONST struct VariableList *list,
# Line 4249  void MissingInsts(struct Instance *inst, Line 4298  void MissingInsts(struct Instance *inst,
4298    }    }
4299  }  }
4300    
4301  /**************************************************************************\  /**
4302     VerifyInsts: makes sure at least one thing is found for     Verify instances: Makes sure at least one thing is found for
4303     each name item on list. Returns 1 if so, or 0 if not.     each name item on list. Returns 1 if so, or 0 if not.
4304     Does not return the collected instances.     Does not return the collected instances.
4305  \**************************************************************************/  */
4306  static  static
4307  int VerifyInsts(struct Instance *inst,  int VerifyInsts(struct Instance *inst,
4308                  CONST struct VariableList *list,                  CONST struct VariableList *list,
# Line 4297  int InPrecedingClique(struct gl_list_t * Line 4346  int InPrecedingClique(struct gl_list_t *
4346    return 0;    return 0;
4347  }  }
4348    
4349    /**
4350        This procedure takes time proportion to n^2.
4351    */
4352  static  static
4353  void RemoveExtras(struct gl_list_t *list)  void RemoveExtras(struct gl_list_t *list){
 /*********************************************************************\  
 This procedure takes time proportional to n^2.  
 \*********************************************************************/  
 {  
4354    unsigned long c=1;    unsigned long c=1;
4355    struct Instance *inst;    struct Instance *inst;
4356    while(c<=gl_length(list)){    while(c<=gl_length(list)){
# Line 4483  int ExecuteIRT(struct Instance *work, st Line 4531  int ExecuteIRT(struct Instance *work, st
4531    }    }
4532  }  }
4533    
4534    /**
4535        This assumes that NULL is not in the list.
4536    */
4537  static  static
4538  void RemoveDuplicates(struct gl_list_t *list)  void RemoveDuplicates(struct gl_list_t *list)
 /*********************************************************************\  
 This assumes that Null is not in the list.  
 \*********************************************************************/  
4539  {  {
4540    VOIDPTR ptr=NULL;    VOIDPTR ptr=NULL;
4541    unsigned c=1;    unsigned c=1;
# Line 4502  This assumes that Null is not in the lis Line 4550  This assumes that Null is not in the lis
4550    }    }
4551  }  }
4552    
4553    /**
4554        Return NULL if the list is not conformable or empty.  Otherwise,
4555        return the type description of the most refined instance.
4556    */
4557  static  static
4558  struct TypeDescription *MostRefined(struct gl_list_t *list)  struct TypeDescription *MostRefined(struct gl_list_t *list)
 /*********************************************************************\  
 Return NULL if the list is not conformable or empty.  Otherwise,  
 return the type description of the most refined instance.  
 \*********************************************************************/  
4559  {  {
4560    struct TypeDescription *mostrefined;    struct TypeDescription *mostrefined;
4561    struct Instance *inst;    struct Instance *inst;
# Line 4579  int ExecuteATS(struct Instance *inst, st Line 4627  int ExecuteATS(struct Instance *inst, st
4627    }    }
4628  }  }
4629    
4630  /* disallows parameterized objects from being added to cliques.  /**
4631   */      disallows parameterized objects from being added to cliques.
4632    */
4633  static  static
4634  int ExecuteAA(struct Instance *inst, struct Statement *statement)  int ExecuteAA(struct Instance *inst, struct Statement *statement)
4635  {  {
# Line 4643  int ExecuteAA(struct Instance *inst, str Line 4692  int ExecuteAA(struct Instance *inst, str
4692    }    }
4693  }  }
4694    
4695    /*------------------------------------------------------------------------------
4696        RELATION PROCESSING
4697    */
4698    
 /**************************************************************************\  
   Relation Processing.  
 \**************************************************************************/  
4699  static  static
4700  struct Instance *MakeRelationInstance(struct Name *name,  struct Instance *MakeRelationInstance(struct Name *name,
4701                                        struct TypeDescription *def,                                        struct TypeDescription *def,
# Line 4694  struct Instance *MakeRelationInstance(st Line 4743  struct Instance *MakeRelationInstance(st
4743  }  }
4744    
4745    
4746  /*  /**
4747   * ok, now we can whine real loud about what's missing.      ok, now we can whine real loud about what's missing.
4748   * even in relations referencing relations, because they      even in relations referencing relations, because they
4749   * should have been added to pendings in dependency order. (hah!)      should have been added to pendings in dependency order. (hah!)
4750   */  */
4751  static  static
4752  int ExecuteREL(struct Instance *inst, struct Statement *statement)  int ExecuteREL(struct Instance *inst, struct Statement *statement)
4753  {  {
# Line 4838  int ExecuteREL(struct Instance *inst, st Line 4887  int ExecuteREL(struct Instance *inst, st
4887  #endif  #endif
4888  }  }
4889    
4890  /*  /**
4891   * set a relation instance as Conditional. This is done by activating      set a relation instance as Conditional. This is done by activating
4892   * a bit ( relinst_set_conditional(rel,TRUE) ) and by using a flag      a bit ( relinst_set_conditional(rel,TRUE) ) and by using a flag
4893   * SetRelationIsCond(reln). Only one of these two would be strictly      SetRelationIsCond(reln). Only one of these two would be strictly
4894   * required      required
4895   */  */
4896  static  static
4897  void MarkREL(struct Instance *inst, struct Statement *statement)  void MarkREL(struct Instance *inst, struct Statement *statement)
4898  {  {
# Line 4878  void MarkREL(struct Instance *inst, stru Line 4927  void MarkREL(struct Instance *inst, stru
4927    }    }
4928  }  }
4929    
4930  /*  /**
4931   * set a logical relation instance as Conditional. This is done by activating      set a logical relation instance as Conditional. This is done by activating
4932   * a bit ( logrelinst_set_conditional(lrel,TRUE) ) and by using a flag      a bit ( logrelinst_set_conditional(lrel,TRUE) ) and by using a flag
4933   * SetLogRelIsCond(reln). Only one of these two would be strictly      SetLogRelIsCond(reln). Only one of these two would be strictly
4934   * required      required
4935   */  */
4936  static  static
4937  void MarkLOGREL(struct Instance *inst, struct Statement *statement)  void MarkLOGREL(struct Instance *inst, struct Statement *statement)
4938  {  {
# Line 4918  void MarkLOGREL(struct Instance *inst, s Line 4967  void MarkLOGREL(struct Instance *inst, s
4967  }  }
4968    
4969    
4970  /*  /**
4971   * For its use in ExecuteUnSelectedStatements.      For its use in ExecuteUnSelectedStatements.
4972   * Execute the REL or LOGREL statements inside those cases of a SELECT      Execute the REL or LOGREL statements inside those cases of a SELECT
4973   * which do not match the selection variables      which do not match the selection variables
4974   */  */
4975  static  static
4976  int ExecuteUnSelectedEQN(struct Instance *inst, struct Statement *statement)  int ExecuteUnSelectedEQN(struct Instance *inst, struct Statement *statement)
4977  {  {
# Line 4960  int ExecuteUnSelectedEQN(struct Instance Line 5009  int ExecuteUnSelectedEQN(struct Instance
5009    return 1;    return 1;
5010  }  }
5011    
5012    /*------------------------------------------------------------------------------
5013      LOGICAL RELATIONS PROCESSING
5014    
 /******************************************************************\  
   LOGICAL RELATIONS Processing  
5015    Making instances of logical relations or arrays of instances of    Making instances of logical relations or arrays of instances of
5016    logical relations.    logical relations.
5017  \******************************************************************/  */
5018    
5019  static  static
5020  struct Instance *MakeLogRelInstance(struct Name *name,  struct Instance *MakeLogRelInstance(struct Name *name,
5021                                      struct TypeDescription *def,                                      struct TypeDescription *def,
# Line 5122  int ExecuteLOGREL(struct Instance *inst, Line 5172  int ExecuteLOGREL(struct Instance *inst,
5172    }    }
5173  }  }
5174    
5175    /*==============================================================================
5176      EXTERNAL CALL PROCESSING
5177    */
5178    
5179    /*------------------------------------------------------------------------------
5180      BLACK BOX RELATIONS PROCESSING
5181    */
5182    
5183  /**************************************************************************\  static struct gl_list_t *MakeExtIndices(unsigned long nindices){
   External Procedures Processing.  
 \**************************************************************************/  
   
 /*  
  **************************************************************************  
  * BlackBox Relations processing.  
  *  
  **************************************************************************  
  */  
 static  
 struct gl_list_t *MakeExtIndices(unsigned long nindices)  
 {  
5184    struct gl_list_t *result;    struct gl_list_t *result;
5185    struct Set *s;    struct Set *s;
5186    struct IndexType *index;    struct IndexType *index;
# Line 5155  struct gl_list_t *MakeExtIndices(unsigne Line 5199  struct gl_list_t *MakeExtIndices(unsigne
5199    }    }
5200  }  }
5201    
5202  /*  /**
5203   * This function accepts an array instance for a relation array      This function accepts an array instance for a relation array
5204   * and will construct the appropriate number of children for this      and will construct the appropriate number of children for this
5205   * array and append them to the instance.      array and append them to the instance.
5206   */  */
5207  static  static int AddExtArrayChildren(struct Instance *inst, /* this is the aryinst */
5208  int AddExtArrayChildren(struct Instance *inst, /* this is the aryinst */          struct Statement *stat,
5209                          struct Statement *stat,          struct gl_list_t *arglist,
5210                          struct gl_list_t *arglist,          struct Instance *data,
5211                          struct Instance *data,          unsigned long n_input_args,
5212                          unsigned long n_input_args,          unsigned long n_output_args
5213                          unsigned long n_output_args)  ){
 {  
5214    struct Instance *subject;    struct Instance *subject;
5215    struct Instance *relinst;    struct Instance *relinst;
5216    struct relation *reln;    struct relation *reln;
# Line 5206  int AddExtArrayChildren(struct Instance Line 5249  int AddExtArrayChildren(struct Instance
5249    }    }
5250  }  }
5251    
5252  /*  /**
5253   * This function creates the array instance for which the      This function creates the array instance for which the
5254   * children of the array of relations will be apppended.      children of the array of relations will be apppended.
5255   */  */
5256  static  static struct Instance *MakeExtRelationArray(struct Instance * inst,
5257  struct Instance *MakeExtRelationArray(struct Instance * inst,          struct Name *name,
5258                                        struct Name *name,          struct Statement *stat
5259                                        struct Statement *stat)  ){
 {  
   
5260    symchar *relation_name;    symchar *relation_name;
5261    struct TypeDescription *desc;    struct TypeDescription *desc;
5262    struct InstanceName rec;    struct InstanceName rec;
# Line 5266  int CheckExtCallArgTypes(struct gl_list_ Line 5307  int CheckExtCallArgTypes(struct gl_list_
5307    return 0;    return 0;
5308  }  }
5309    
5310  /*  /**
5311   * This function if fully successful will return a list of      This function if fully successful will return a list of
5312   * lists. This will be wasteful if many singlets are used      lists. This will be wasteful if many singlets are used
5313   * as args, other wise it should be more useful than other      as args, other wise it should be more useful than other
5314   * representations.      representations.
5315   */  */
5316    static struct gl_list_t *ProcessArgs(struct Instance *inst,
5317  static          CONST struct VariableList *vl,
5318  struct gl_list_t *ProcessArgs(struct Instance *inst,          enum find_errors *ferr
5319                                CONST struct VariableList *vl,  ){
                               enum find_errors *ferr)  
 {  
5320    struct gl_list_t *arglist;    struct gl_list_t *arglist;
5321    struct gl_list_t *branch;    struct gl_list_t *branch;
5322    
# Line 5297  struct gl_list_t *ProcessArgs(struct Ins Line 5336  struct gl_list_t *ProcessArgs(struct Ins
5336    return arglist;    return arglist;
5337  }  }
5338    
5339  static /* blackbox only */  /**
5340  struct gl_list_t *CheckExtCallArgs(struct Instance *inst,      blackbox only
5341                                     struct Statement *stat,  */
5342                                     enum find_errors *ferr)  static struct gl_list_t *CheckExtCallArgs(struct Instance *inst,
5343  {          struct Statement *stat,
5344            enum find_errors *ferr
5345    ){
5346    struct VariableList *vl;    struct VariableList *vl;
5347    struct gl_list_t *result;    struct gl_list_t *result;
5348    
# Line 5313  struct gl_list_t *CheckExtCallArgs(struc Line 5354  struct gl_list_t *CheckExtCallArgs(struc
5354    return result;    return result;
5355  }  }
5356    
5357  static /* blackbox only */  /** black box only */
5358  struct Instance *CheckExtCallData(struct Instance *inst,  static struct Instance *CheckExtCallData(struct Instance *inst,
5359                                    struct Statement *stat,          struct Statement *stat,
5360                                    enum find_errors *ferr)          enum find_errors *ferr
5361  {  ){
5362    struct Name *n;    struct Name *n;
5363    struct Instance *result;    struct Instance *result;
5364    struct gl_list_t *instances;    struct gl_list_t *instances;
# Line 5358  struct Instance *CheckExtCallData(struct Line 5399  struct Instance *CheckExtCallData(struct
5399      This function does the job of creating an instance of a 'black box'      This function does the job of creating an instance of a 'black box'
5400      external relation or set of relations.      external relation or set of relations.
5401  */  */
5402  static  static int ExecuteBlackBoxEXT(struct Instance *inst
5403  int ExecuteBlackBoxEXT(struct Instance *inst, struct Statement *statement)          , struct Statement *statement
5404  {  ){
5405    struct Name *name;    struct Name *name;
5406    enum find_errors ferr;    enum find_errors ferr;
5407    struct gl_list_t *arglist=NULL;    struct gl_list_t *arglist=NULL;
# Line 5459  int ExecuteBlackBoxEXT(struct Instance * Line 5500  int ExecuteBlackBoxEXT(struct Instance *
5500    }    }
5501  }  }
5502    
5503    /*------------------------------------------------------------------------------
5504  /*    GLASS BOX RELATIONS PROCESSING
5505   **************************************************************************  
5506   * GlassBox Relations processing.      GlassBox relations processing. As is to be expected, this code
5507   *      is a hybrid between TRUE ascend relations and blackbox relations.
5508   * GlassBox relations processing. As is to be expected this code  */
  * is a hybrid between TRUE ascend relations and blackbox relations.  
  **************************************************************************  
  */  
5509    
5510  static  static
5511  struct gl_list_t *CheckGlassBoxArgs(struct Instance *inst,  struct gl_list_t *CheckGlassBoxArgs(struct Instance *inst,
# Line 5687  int ExecuteEXT(struct Instance *inst, st Line 5725  int ExecuteEXT(struct Instance *inst, st
5725    }    }
5726  }  }
5727    
5728  /**************************************************************************\  /*------------------------------------------------------------------------------
5729    Assignment Processing.    ASSIGNMENT PROCESSING
5730  \**************************************************************************/  */
5731  static  static
5732  void StructuralAsgnErrorReport(struct Statement *statement,  void StructuralAsgnErrorReport(struct Statement *statement,
5733                                 struct value_t *value)                                 struct value_t *value)
# Line 5761  void ReAssignmentError(CONST char *str, Line 5799  void ReAssignmentError(CONST char *str,
5799    ascfree(msg);    ascfree(msg);
5800  }  }
5801    
5802  /*  /**
5803   * returns 1 if ok, 0 if unhappy.      returns 1 if ok, 0 if unhappy.
5804   * for any given statement, once unhappy = always unhappy.      for any given statement, once unhappy = always unhappy.
5805   */  */
5806  static  static
5807  int AssignStructuralValue(struct Instance *inst,  int AssignStructuralValue(struct Instance *inst,
5808                   struct value_t value,                   struct value_t value,
# Line 5943  int AssignStructuralValue(struct Instanc Line 5981  int AssignStructuralValue(struct Instanc
5981    }    }
5982  }  }
5983    
5984  /*  /**
5985   * Execute structural and dimensional assignments.      Execute structural and dimensional assignments.
5986   * This is called by execute statements and exec for statements.      This is called by execute statements and exec for statements.
5987   * Assignments to variable types are ignored.      Assignments to variable types are ignored.
5988   * Variable defaults expressions are done in executedefaults.      Variable defaults expressions are done in executedefaults.
5989   * rhs expressions must yield constant value_t.      rhs expressions must yield constant value_t.
5990   * Incorrect statements will be marked context_WRONG where possible.      Incorrect statements will be marked context_WRONG where possible.
5991   */  */
5992  static  static
5993  int ExecuteCASGN(struct Instance *work, struct Statement *statement)  int ExecuteCASGN(struct Instance *work, struct Statement *statement)
5994  {  {
# Line 6022  int ExecuteCASGN(struct Instance *work, Line 6060  int ExecuteCASGN(struct Instance *work,
6060    }    }
6061  }  }
6062    
6063  /**************************************************************************\  /*------------------------------------------------------------------------------
6064    Check routines.    CHECK ROUTINES
6065  \**************************************************************************/  */
6066  /*  
6067   * Returns 1 if name can be found in name, or 0 OTHERWISE.  /**
6068   * only deals well with n and sub being Id names.      Returns 1 if name can be found in name, or 0 OTHERWISE.
6069   */      only deals well with n and sub being Id names.
6070    */
6071  static  static
6072  int NameContainsName(CONST struct Name *n,CONST struct Name *sub)  int NameContainsName(CONST struct Name *n,CONST struct Name *sub)
6073  {  {
# Line 6055  int NameContainsName(CONST struct Name * Line 6094  int NameContainsName(CONST struct Name *
6094    ascfree(en);    ascfree(en);
6095    return 0;    return 0;
6096  }  }
6097  /*  
6098   * Checks that the namelist, less any components that contain arrsetname,  /**
6099   * can be evaluated to constant values.      Checks that the namelist, less any components that contain arrsetname,
6100   * Returns 1 if it can be evaluated.      can be evaluated to constant values.
6101   *      Returns 1 if it can be evaluated.
6102   * This is heuristic. It can fail in very very twisty circumstances.  
6103   * What saves the heuristic is that usually all the other conditions      This is heuristic. It can fail in very very twisty circumstances.
6104   * on the compound ALIASES (that rhs's must exist and so forth) will      What saves the heuristic is that usually all the other conditions
6105   * be satisfied before this check is performed and that that will mean      on the compound ALIASES (that rhs's must exist and so forth) will
6106   * enough structure to do the job at Execute time will be in place even      be satisfied before this check is performed and that that will mean
6107   * if this returns a FALSE positive.      enough structure to do the job at Execute time will be in place even
6108   * Basically to trick this thing you have to do indirect addressing with      if this returns a FALSE positive.
6109   * the set elements of the IS_A set in declaring the lhs of the ALIASES  
6110   * part. Of course if you really do that sort of thing, you should be      Basically to trick this thing you have to do indirect addressing with
6111   * coding in C++ or F90 anyway.      the set elements of the IS_A set in declaring the lhs of the ALIASES
6112   *      part. Of course if you really do that sort of thing, you should be
6113   * What it comes down to is that this array constructor from diverse      coding in C++ or F90 anyway.
6114   * elements really sucks -- but so does varargs and that's what we're  
6115   * using the compound alias array constructor to implement.      What it comes down to is that this array constructor from diverse
6116   *      elements really sucks -- but so does varargs and that's what we're
6117   * There is an extremely expensive alternative that is not heuristic --      using the compound alias array constructor to implement.
6118   * create the IS_A set (which might be a sparse array) during the  
6119   * check process and blow it away when the check fails. This is an      There is an extremely expensive alternative that is not heuristic --
6120   * utter nuisance and a cost absurdity.      create the IS_A set (which might be a sparse array) during the
6121   * --baa 1/97.      check process and blow it away when the check fails. This is an
6122   */      utter nuisance and a cost absurdity.
6123        --baa 1/97.
6124    */
6125  static  static
6126  int ArrayCheckNameList(struct Instance *inst,  int ArrayCheckNameList(struct Instance *inst,
6127                         struct Statement *statement,                         struct Statement *statement,
# Line 6141  int ArrayCheckNameList(struct Instance * Line 6182  int ArrayCheckNameList(struct Instance *
6182    return 1;    return 1;
6183  }  }
6184  /*  /*
6185   * check the subscripts for definedness, including FOR table checks and      check the subscripts for definedness, including FOR table checks and
6186   * checks for the special name in the compound ALIASES-IS_A statement.      checks for the special name in the compound ALIASES-IS_A statement.
6187   * Assumes it is going to be handed a name consisting entirely of      Assumes it is going to be handed a name consisting entirely of
6188   * subscripts.      subscripts.
6189   */  */
6190  static  static
6191  int FailsCompoundArrayCheck(struct Instance *inst,  int FailsCompoundArrayCheck(struct Instance *inst,
6192                              CONST struct Name *name,                              CONST struct Name *name,
# Line 6177  int FailsCompoundArrayCheck(struct Insta Line 6218  int FailsCompoundArrayCheck(struct Insta
6218    return 0;    return 0;
6219  }  }
6220    
6221    /**
6222        The name pointer is known to be an array, so now it is checked to make
6223        sure that each index type can be determined.
6224        It is not a . qualified name.
6225    
6226        With searchfor == 0:
6227        This routine deliberately lets some errors through because the will
6228        be trapped elsewhere.  Its *only* job is to detect undefined index
6229        types. (defined indices simply missing values will merely be done
6230        in a later array expansion.
6231        Returns 1 if set type indeterminate.
6232    
6233        With searchfor != 0:
6234        Tries to expand the indices completely and returns 1 if fails.
6235        arrset name is a special name that may be used in indices when
6236        creating compound ALIASES-IS_A -- it is the name the IS_A will create.
6237        It is only considered if searchfor != 0.
6238    */
6239  static  static
6240  int FailsIndexCheck(CONST struct Name *name, struct Statement *statement,  int FailsIndexCheck(CONST struct Name *name, struct Statement *statement,
6241                      struct Instance *inst, CONST unsigned int searchfor,                      struct Instance *inst, CONST unsigned int searchfor,
6242                      CONST struct Name *arrsetname)                      CONST struct Name *arrsetname)
 /*********************************************************************\  
 The name pointer is known to be an array, so now it is checked to make  
 sure that each index type can be determined.  
 It is not a . qualified name.  
   
 With searchfor == 0:  
 This routine deliberately lets some errors through because the will  
 be trapped elsewhere.  Its *only* job is to detect undefined index  
 types. (defined indices simply missing values will merely be done  
 in a later array expansion.  
 Returns 1 if set type indeterminate.  
   
 With searchfor != 0:  
 Tries to expand the indices completely and returns 1 if fails.  
 arrset name is a special name that may be used in indices when  
 creating compound ALIASES-IS_A -- it is the name the IS_A will create.  
 It is only considered if searchfor != 0.  
 \*********************************************************************/  
6243  {  {
6244    CONST struct Set *sptr;    CONST struct Set *sptr;
6245    struct gl_list_t *indices;    struct gl_list_t *indices;
# Line 6245  It is only considered if searchfor != 0. Line 6286  It is only considered if searchfor != 0.
6286    return 0;    return 0;
6287  }  }
6288    
6289    /**
6290        This has to check this member of the variable list for unknown
6291        array indices.  It returns TRUE iff it contains an unknown index;
6292        otherwise, it returns FALSE.
6293        If searchfor !=0, include for indices in list of valid things,
6294        and insist that values actually have been assigned as well.
6295    */
6296  static  static
6297  int ContainsUnknownArrayIndex(struct Instance *inst,  int ContainsUnknownArrayIndex(struct Instance *inst,
6298                                struct Statement *stat,                                struct Statement *stat,
6299                                CONST struct Name *name,                                CONST struct Name *name,
6300                                CONST unsigned int searchfor,                                CONST unsigned int searchfor,
6301                                CONST struct Name *arrsetname)                                CONST struct Name *arrsetname)
 /*********************************************************************\  
 This has to check this member of the variable list for unknown  
 array indices.  It returns TRUE iff it contains an unknown index;  
 otherwise, it returns FALSE.  
 If searchfor !=0, include for indices in list of valid things,  
 and insist that values actually have been assigned as well.  
 \*********************************************************************/  
6302  {  {
6303    if (!SimpleNameIdPtr(name)){ /* simple names never miss indices */    if (!SimpleNameIdPtr(name)){ /* simple names never miss indices */
6304      if (FailsIndexCheck(name,stat,inst,searchfor,arrsetname)) return 1;      if (FailsIndexCheck(name,stat,inst,searchfor,arrsetname)) return 1;
# Line 6265  and insist that values actually have bee Line 6306  and insist that values actually have bee
6306    return 0;    return 0;
6307  }  }
6308    
6309    /**
6310        If there are no array instances, this should always return TRUE.  When
6311        there are array instances to be created, it has to check to make sure
6312        that all of the index types can be determined and their values are
6313        defined!
6314    
6315        aliases always appears to be in for loop because we must always have
6316        a definition of all the sets because an alias array can't be finished
6317        up later.
6318    */
6319  static  static
6320  int CheckALIASES(struct Instance *inst, struct Statement *stat)  int CheckALIASES(struct Instance *inst, struct Statement *stat)
 /*********************************************************************\  
 If there are no array instances, this should always return TRUE.  When  
 there are array instances to be created, it has to check to make sure  
 that all of the index types can be determined and their values are  
 defined!  
   
 aliases always appears to be in for loop because we must always have  
 a definition of all the sets because an alias array can't be finished  
 up later.  
 \*********************************************************************/  
6321  {  {
6322    CONST struct VariableList *vlist;    CONST struct VariableList *vlist;
6323    int cu;    int cu;
# Line 6311  up later. Line 6352  up later.
6352    return 1;    return 1;
6353  }  }
6354    
6355    /**
6356        This has to make sure the RHS list of the ALIASES and the WITH_VALUE
6357        of the IS_A are both satisfied.
6358    
6359        When the statement is in a FOR loop, this has to check to make sure
6360        that all of the LHS index types can be determined and their values are
6361        defined!
6362        ALIASES always appears to be in for loop because we must always have
6363        a definition of all the sets because an alias array can't be finished
6364        up later.
6365    */
6366  static  static
6367  int CheckARR(struct Instance *inst, struct Statement *stat)  int CheckARR(struct Instance *inst, struct Statement *stat)
 /*********************************************************************\  
 This has to make sure the RHS list of the ALIASES and the WITH_VALUE  
 of the IS_A are both satisfied.  
   
 When the statement is in a FOR loop, this has to check to make sure  
 that all of the LHS index types can be determined and their values are  
 defined!  
 ALIASES always appears to be in for loop because we must always have  
 a definition of all the sets because an alias array can't be finished  
 up later.  
 \*********************************************************************/  
6368  {  {
6369    CONST struct VariableList *vlist;    CONST struct VariableList *vlist;
6370    struct value_t value;    struct value_t value;
# Line 6388  up later. Line 6429  up later.
6429    return 1;    return 1;
6430  }  }
6431    
6432  static  /**
6433  int CheckISA(struct Instance *inst, struct Statement *stat)      If there are no array instances, this should always return TRUE.  When
6434  /*********************************************************************\      there are array instances to be created, it has to check to make sure
6435  If there are no array instances, this should always return TRUE.  When      that all of the index types can be determined.
6436  there are array instances to be created, it has to check to make sure      If statement requires type args, also checks that all array indices
6437  that all of the index types can be determined.      can be evaluated.
 If statement requires type args, also checks that all array indices  
 can be evaluated.  
6438    
6439  Currently, this can handle checking for completable sets in any      Currently, this can handle checking for completable sets in any
6440  statement's var list, not just ISAs.      statement's var list, not just ISAs.
6441    
6442  It does not at present check arguments of IS_A's.      It does not at present check arguments of IS_A's.
6443  \*********************************************************************/  */
6444    static
6445    int CheckISA(struct Instance *inst, struct Statement *stat)
6446  {  {
6447    CONST struct VariableList *vlist;    CONST struct VariableList *vlist;
6448    int cu;    int cu;
# Line 6422  It does not at present check arguments o Line 6463  It does not at present check arguments o
6463    return 1;    return 1;
6464  }  }
6465    
6466  /***********************************************************************/  /**
6467  /*      checks that all the names in a varlist exist as instances.
6468   * checks that all the names in a varlist exist as instances.      returns 1 if TRUE, 0 if not.
6469   * returns 1 if TRUE, 0 if not.  */
  */  
6470  static  static
6471  int CheckVarList(struct Instance *inst, struct Statement *statement)  int CheckVarList(struct Instance *inst, struct Statement *statement)
6472  {  {
# Line 6462  int CheckAA(struct Instance *inst, struc Line 6502  int CheckAA(struct Instance *inst, struc
6502    return CheckVarList(inst,statement);    return CheckVarList(inst,statement);
6503  }  }
6504    
6505  /***********************************************************************/  /**
6506  /*      Checks that the lhs of an assignment statement expands into
6507   * Checks that the lhs of an assignment statement expands into      a complete set of instances.
6508   * a complete set of instances.      Not check that the first of those instances is type compatible with
6509   * Not check that the first of those instances is type compatible with      the value being assigned.
6510   * the value being assigned.  */
  */  
6511  static  static
6512  int CheckCASGN(struct Instance *inst, struct Statement *statement)  int CheckCASGN(struct Instance *inst, struct Statement *statement)
6513  {  {
# Line 6504  int CheckCASGN(struct Instance *inst, st Line 6543  int CheckCASGN(struct Instance *inst, st
6543    }    }
6544  }  }
6545    
 /***********************************************************************/  
6546  #ifdef THIS_IS_AN_UNUSED_FUNCTION  #ifdef THIS_IS_AN_UNUSED_FUNCTION
6547  static  static
6548  int CheckASGN(struct Instance *inst, struct Statement *statement)  int CheckASGN(struct Instance *inst, struct Statement *statement)
# Line 6544  int CheckASGN(struct Instance *inst, str Line 6582  int CheckASGN(struct Instance *inst, str
6582  #endif   /* THIS_IS_AN_UNUSED_FUNCTION */  #endif   /* THIS_IS_AN_UNUSED_FUNCTION */
6583    
6584    
6585  /***********************************************************************/  /**
6586  /*      Check if the relation exists, also, if it exists as relation or as a
6587   * Check if the relation exists, also, if it exists as relation or as a      dummy instance. return -1 for DUMMY. 1 for relation. 0 if the checking
6588   * dummy instance. return -1 for DUMMY. 1 for relation. 0 if the checking      fails.
6589   * fails.  */
  */  
6590  static  static
6591  int CheckRelName(struct Instance *work, struct Name *name)  int CheckRelName(struct Instance *work, struct Name *name)
6592  {  {
# Line 6578  int CheckRelName(struct Instance *work, Line 6615  int CheckRelName(struct Instance *work,
6615    }    }
6616  }  }
6617    
6618  /*  /**
6619   * If the relation is already there, it may be a dummy instance. In      If the relation is already there, it may be a dummy instance. In
6620   * such a case, do not check the expression. Currently not in      such a case, do not check the expression. Currently not in
6621   * use.      use.
6622   */  */
6623  static  static
6624  int CheckREL(struct Instance *inst, struct Statement *statement)  int CheckREL(struct Instance *inst, struct Statement *statement)
6625  {  {
# Line 6596  int CheckREL(struct Instance *inst, stru Line 6633  int CheckREL(struct Instance *inst, stru
6633    return CheckRelation(inst,RelationStatExpr(statement));    return CheckRelation(inst,RelationStatExpr(statement));
6634  }  }
6635    
6636  /***********************************************************************/  /**
6637        Check that the logical relation instance of some name has not been
6638  /* Check that the logical relation instance of some name has not been      previously created, or if it has, the instance is unique and
6639   * previously created, or if it has, the instance is unique and      corresponds to a logical relation or to a dummy.
6640   * corresponds to a logical relation or to a dummy.      return -1 for DUMMY. 1 for log relation. 0 if the checking fails.
6641   * return -1 for DUMMY. 1 for log relation. 0 if the checking fails.  */
  */  
6642  static  static
6643  int CheckLogRelName(struct Instance *work, struct Name *name)  int CheckLogRelName(struct Instance *work, struct Name *name)
6644  {  {
# Line 6631  int CheckLogRelName(struct Instance *wor Line 6667  int CheckLogRelName(struct Instance *wor
6667    }    }
6668  }  }
6669    
6670  /* Checking of Logical relation. First the name, then the expression.  /**
6671   * If the logrel exists as a dummy, then do not check the expression.      Checking of Logical relation. First the name, then the expression.
6672   * Currently not in use.      If the logrel exists as a dummy, then do not check the expression.
6673   */      Currently not in use.
6674    */
6675  static  static
6676  int CheckLOGREL(struct Instance *inst, struct Statement *statement)  int CheckLOGREL(struct Instance *inst, struct Statement *statement)
6677  {  {
# Line 6646  int CheckLOGREL(struct Instance *inst, s Line 6683  int CheckLOGREL(struct Instance *inst, s
6683  }  }
6684    
6685    
6686  /***********************************************************************/  /**
6687                      /* Checking FNAME statement */      Checking FNAME statement (1)
6688    
6689  /* The following two functions check that the FNAME inside a WHEN      ["The following two functions..." -- ed] Check that the FNAME inside a WHEN
6690   * make reference to instance of models, relations, or arrays of      make reference to instance of models, relations, or arrays of
6691   * models or relations previously created.      models or relations previously created.
6692   */  */
6693  static  static
6694  int CheckArrayRelMod(struct Instance *child)  int CheckArrayRelMod(struct Instance *child)
6695  {  {
# Line 6680  int CheckArrayRelMod(struct Instance *ch Line 6717  int CheckArrayRelMod(struct Instance *ch
6717    }    }
6718  }  }
6719    
6720    /**
6721        Checking FNAME statement (2)
6722    
6723        Check that the FNAME inside a WHEN
6724        make reference to instance of models, relations, or arrays of
6725        models or relations previously created.
6726    */
6727  static  static
6728  int CheckRelModName(struct Instance *work, struct Name *name)  int CheckRelModName(struct Instance *work, struct Name *name)
6729  {  {
# Line 6740  int CheckRelModName(struct Instance *wor Line 6784  int CheckRelModName(struct Instance *wor
6784    }    }
6785  }  }
6786    
6787  /*  /**
6788   * A FNAME statement stands for a relation, model, or an array of models      A FNAME statement stands for a relation, model, or an array of models
6789   * or relations. This checking is to make sure that those instance      or relations. This checking is to make sure that those instance
6790   * were already created      were already created
6791   */  */
6792  static  static
6793  int CheckFNAME(struct Instance *inst, struct Statement *statement)  int CheckFNAME(struct Instance *inst, struct Statement *statement)
6794  {  {
# Line 6754  int CheckFNAME(struct Instance *inst, st Line 6798  int CheckFNAME(struct Instance *inst, st
6798      return 1;      return 1;
6799  }  }
6800    
6801  /***********************************************************************/  /**
6802        Only logrelations and FOR loops of logrelations are allowed inside a
6803  /* Only logrelations and FOR loops of logrelations are allowed inside a      conditional statement in Pass3. This function ask for recursively
6804   * conditional statement in Pass3. This function ask for recursively      checking these statements
6805   * checking these statements */  */
6806  static  static
6807  int Pass3CheckCondStatements(struct Instance *inst,  int Pass3CheckCondStatements(struct Instance *inst,
6808                               struct Statement *statement)                               struct Statement *statement)
# Line 6793  int Pass3CheckCondStatements(struct Inst Line 6837  int Pass3CheckCondStatements(struct Inst
6837      }      }
6838  }  }
6839    
6840  /* Checking the statement list inside a CONDITIONAL statement in Pass3 */  /**
6841        Checking the statement list inside a CONDITIONAL statement in Pass3
6842    */
6843  static  static
6844  int Pass3CheckCOND(struct Instance *inst, struct Statement *statement)  int Pass3CheckCOND(struct Instance *inst, struct Statement *statement)
6845  {  {
# Line 6813  int Pass3CheckCOND(struct Instance *inst Line 6859  int Pass3CheckCOND(struct Instance *inst
6859  }  }
6860    
6861    
6862  /* Only relations and FOR loops of relations are allowed inside a  /**
6863   * conditional statement in Pass2. This function ask for recursively      Only relations and FOR loops of relations are allowed inside a
6864   * checking these statements */      conditional statement in Pass2. This function ask for recursively
6865        checking these statements
6866    */
6867  static  static
6868  int Pass2CheckCondStatements(struct Instance *inst,  int Pass2CheckCondStatements(struct Instance *inst,
6869                               struct Statement *statement)                               struct Statement *statement)
# Line 6850  int Pass2CheckCondStatements(struct Inst Line 6898  int Pass2CheckCondStatements(struct Inst
6898      }      }
6899  }  }
6900    
6901  /* Checking the statement list inside a CONDITIONAL statement in Pass2 */  /**
6902        Checking the statement list inside a CONDITIONAL statement in Pass2
6903    */
6904  static  static
6905  int Pass2CheckCOND(struct Instance *inst, struct Statement *statement)  int Pass2CheckCOND(struct Instance *inst, struct Statement *statement)
6906  {  {
# Line 6869  int Pass2CheckCOND(struct Instance *inst Line 6919  int Pass2CheckCOND(struct Instance *inst
6919    return 1;    return 1;
6920  }  }
6921    
6922    /**
6923  /***********************************************************************/      Checking that not other instance has been created with the same
6924        name of the current WHEN. If it has, it has to be a WHEN or a
6925  /*      DUMMY. return -1 for DUMMY. 1 for WHEN. 0 if the checking fails.
6926   * Checking that not other instance has been created with the same  */
  * name of the current WHEN. If it has, it has to be a WHEN or a  
  * DUMMY. return -1 for DUMMY. 1 for WHEN. 0 if the checking fails.  
  */  
6927  static  static
6928  int CheckWhenName(struct Instance *work, struct Name *name)  int CheckWhenName(struct Instance *work, struct Name *name)
6929  {  {
# Line 6905  int CheckWhenName(struct Instance *work, Line 6952  int CheckWhenName(struct Instance *work,
6952    }    }
6953  }  }
6954    
6955  /*  /**
6956   * p1 and p2 are pointers to arrays of integers. Here we are checking      p1 and p2 are pointers to arrays of integers. Here we are checking
6957   * that the type (integer, boolean, symbol) of each variable in the      that the type (integer, boolean, symbol) of each variable in the
6958   * variable list of a WHEN (or a SELECT) is the same as the type of      variable list of a WHEN (or a SELECT) is the same as the type of
6959   * each value in the list of values a CASE      each value in the list of values a CASE
6960   */  */
6961  static  static
6962  int CompListInArray(unsigned long numvar, int *p1, int *p2)  int CompListInArray(unsigned long numvar, int *p1, int *p2)
6963  {  {
# Line 6928  int CompListInArray(unsigned long numvar Line 6975  int CompListInArray(unsigned long numvar
6975  }  }
6976    
6977    
6978  /*  /**
6979   * Checking that the values of the set of values of each CASE of a      Checking that the values of the set of values of each CASE of a
6980   * WHEN statement are appropriate. This is, they      WHEN statement are appropriate. This is, they
6981   * are symbol, integer or boolean. The first part of the      are symbol, integer or boolean. The first part of the
6982   * function was written for the case of WHEN statement      function was written for the case of WHEN statement
6983   * inside a FOR loop. This function also sorts      inside a FOR loop. This function also sorts
6984   * the kinds of values in the set by assigning a value      the kinds of values in the set by assigning a value
6985   * to the integer *p2      to the integer *p2
6986   */  */
6987  static  static
6988  int CheckWhenSetNode(struct Instance *ref, CONST struct Expr *expr,  int CheckWhenSetNode(struct Instance *ref, CONST struct Expr *expr,
6989                       int *p2)                       int *p2)
# Line 7010  int CheckWhenSetNode(struct Instance *re Line 7057  int CheckWhenSetNode(struct Instance *re
7057  }  }
7058    
7059    
7060  /*  /**
7061   * Checking that the variables of the list of variables of a      Checking that the variables of the list of variables of a
7062   * WHEN statement are appropriate. This is, they      WHEN statement are appropriate. This is, they
7063   * are boolean, integer or symbol instances. The first part of the      are boolean, integer or symbol instances. The first part of the
7064   * function was written for the case of WHEN statement      function was written for the case of WHEN statement
7065   * inside a FOR loop. This function also sorts      inside a FOR loop. This function also sorts
7066   * the kinds of variables in the list by assigning a value      the kinds of variables in the list by assigning a value
7067   * to the integer *p1      to the integer *p1
7068   */  */
7069  static  static
7070  int CheckWhenVariableNode(struct Instance *ref,  int CheckWhenVariableNode(struct Instance *ref,
7071                            CONST struct Name *name,                            CONST struct Name *name,
# Line 7143  int CheckWhenVariableNode(struct Instanc Line 7190  int CheckWhenVariableNode(struct Instanc
7190  }  }
7191    
7192    
7193  /*  /**
7194   * Inside a WHEN, only FNAMEs (name of models, relations or array of)      Inside a WHEN, only FNAMEs (name of models, relations or array of)
7195   * and nested WHENs ( and FOR loops of them) are allowed. This function      and nested WHENs ( and FOR loops of them) are allowed. This function
7196   * asks for the checking of these statements.      asks for the checking of these statements.
7197   */  */
7198  static  static
7199  int CheckWhenStatements(struct Instance *inst, struct Statement *statement)  int CheckWhenStatements(struct Instance *inst, struct Statement *statement)
7200  {  {
# Line 7181  int CheckWhenStatements(struct Instance Line 7228  int CheckWhenStatements(struct Instance
7228      }      }
7229  }  }
7230    
7231  /*  /**
7232   * Call CheckWhenSetNode for each value in the set of values included      Call CheckWhenSetNode for each value in the set of values included
7233   * in the CASE of a WHEN statement      in the CASE of a WHEN statement
7234   */  */
7235  static  static
7236  int CheckWhenSetList(struct Instance *inst, struct Set *s, int *p2)  int CheckWhenSetList(struct Instance *inst, struct Set *s, int *p2)
7237  {  {
# Line 7199  int CheckWhenSetList(struct Instance *in Line 7246  int CheckWhenSetList(struct Instance *in
7246    }    }
7247    return 1;    return 1;
7248  }  }
7249    
7250  /*  /**
7251   * Call CheckWhenVariableNode for each variable vl in the variable      Call CheckWhenVariableNode for each variable vl in the variable
7252   * list of a WHEN statement      list of a WHEN statement
7253   */  */
7254  static  static
7255  int CheckWhenVariableList(struct Instance *inst, struct VariableList *vlist,  int CheckWhenVariableList(struct Instance *inst, struct VariableList *vlist,
7256                            int *p1)                            int *p1)
# Line 7220  int CheckWhenVariableList(struct Instanc Line 7267  int CheckWhenVariableList(struct Instanc
7267    return 1;    return 1;
7268  }  }
7269    
7270  /*  /**
7271   * Checking the list statements of statements inside each CASE of the      Checking the list statements of statements inside each CASE of the
7272   * WHEN statement by calling CheckWhenStatements      WHEN statement by calling CheckWhenStatements
7273   */  */
7274  static  static
7275  int CheckWhenStatementList(struct Instance *inst, struct StatementList *sl)  int CheckWhenStatementList(struct Instance *inst, struct StatementList *sl)
7276  {  {
# Line 7241  int CheckWhenStatementList(struct Instan Line 7288  int CheckWhenStatementList(struct Instan
7288  }  }
7289    
7290    
7291  /* Checking of the Select statements. It checks that:  /**
7292   * 1) The name of the WHEN. If it was already created. It has to be      Checking of the Select statements. It checks that:
7293   *    a WHEN or a DUMMY. If a Dummy (case -1 of CheckWhenName),      1) The name of the WHEN. If it was already created. It has to be
7294   *    do not check the structure of the WHEN statement, return 1.         a WHEN or a DUMMY. If a Dummy (case -1 of CheckWhenName),
7295   * 2) The number of conditional variables is equal to the number         do not check the structure of the WHEN statement, return 1.
7296   *    of values in each of the CASEs.      2) The number of conditional variables is equal to the number
7297   * 3) That the conditional variables exist, and are boolean         of values in each of the CASEs.
7298   *    integer or symbol.      3) That the conditional variables exist, and are boolean
7299   * 4) The number and the type  of conditional variables is the same         integer or symbol.
7300   *    as the number of values in each of the CASEs.      4) The number and the type  of conditional variables is the same
7301   * 5) Only one OTHERWISE case is present.         as the number of values in each of the CASEs.
7302   * 6) The statements inside a WHEN are only a FNAME or a nested WHEN,      5) Only one OTHERWISE case is present.
7303   *    and ask for the chcking of these interior statements.      6) The statements inside a WHEN are only a FNAME or a nested WHEN,
7304   */         and ask for the chcking of these interior statements.
7305    */
7306  static  static
7307  int CheckWHEN(struct Instance *inst, struct Statement *statement)  int CheckWHEN(struct Instance *inst, struct Statement *statement)
7308  {  {
# Line 7361  int CheckWHEN(struct Instance *inst, str Line 7409  int CheckWHEN(struct Instance *inst, str
7409  }  }
7410    
7411    
7412  /***********************************************************************/  /* - - - - - - - - - - - - -
7413                         /*   Check SELECT Functions */      Check SELECT Functions
7414    */
7415    
 /*****************************  
  * Code curently not in use. It would be used in case that we want to do  
  * the checking of all of the statement list in all of the cases of a  
  * SELECT simultaneously, previous to execution.  
  * Actually, the code is in disrepair, particularly around what is  
  * allowed in SELECT. We surely need to create a CheckSelectStatement  
  * function specific for each pass of instantiation.  
  */  
7416  #ifdef THIS_IS_AN_UNUSED_FUNCTION  #ifdef THIS_IS_AN_UNUSED_FUNCTION
7417    /**
7418        Code curently not in use. It would be used in case that we want to do
7419        the checking of all of the statement list in all of the cases of a
7420        SELECT simultaneously, previous to execution.
7421        Actually, the code is in disrepair, particularly around what is
7422        allowed in SELECT. We surely need to create a CheckSelectStatement
7423        function specific for each pass of instantiation.
7424    */
7425  static  static
7426  int CheckSelectStatements(struct Instance *inst, struct Statement *statement)  int CheckSelectStatements(struct Instance *inst, struct Statement *statement)
7427  {  {
# Line 7413  int CheckSelectStatements(struct Instanc Line 7462  int CheckSelectStatements(struct Instanc
7462    
7463    
7464  #ifdef THIS_IS_AN_UNUSED_FUNCTION  #ifdef THIS_IS_AN_UNUSED_FUNCTION
7465  /* Currently not in use */  /**
7466        Currently not in use
7467    */
7468  static  static
7469  int CheckSelectStatementList(struct Instance *inst, struct StatementList *sl)  int CheckSelectStatementList(struct Instance *inst, struct StatementList *sl)
7470  {  {
# Line 7432  int CheckSelectStatementList(struct Inst Line 7483  int CheckSelectStatementList(struct Inst
7483  #endif  /* THIS_IS_AN_UNUSED_FUNCTION */  #endif  /* THIS_IS_AN_UNUSED_FUNCTION */
7484    
7485    
7486  /*  /**
7487   * Current checking of the Select statement starts here.      Current checking of the Select statement starts here.
7488   *      
7489   * Checking that the values of the set of values of each CASE of a      Checking that the values of the set of values of each CASE of a
7490   * SELECT statement are appropriate. This is, they      SELECT statement are appropriate. This is, they
7491   * are symbol, integer or boolean. The first part of the      are symbol, integer or boolean. The first part of the
7492   * function was written for the case of SELECT statement      function was written for the case of SELECT statement
7493   * inside a FOR loop. Therefore, it is going to be there,      inside a FOR loop. Therefore, it is going to be there,
7494   * but not used at the moment.This function also sorts      but not used at the moment.This function also sorts
7495   * the kinds of values in the set by assigning a value      the kinds of values in the set by assigning a value
7496   * to the integer *p2      to the integer *p2
7497   */  */
7498  static  static
7499  int CheckSelectSetNode(struct Instance *ref, CONST struct Expr *expr,  int CheckSelectSetNode(struct Instance *ref, CONST struct Expr *expr,
7500                         int *p2 )                         int *p2 )
# Line 7495  int CheckSelectSetNode(struct Instance * Line 7546  int CheckSelectSetNode(struct Instance *
7546    }    }
7547  }  }
7548    
7549  /*  /**
7550   * Checking that the variables of the list of variables of a      Checking that the variables of the list of variables of a
7551   * SELECT statement are appropriate. This is, they      SELECT statement are appropriate. This is, they
7552   * are constant and are assigned. The first part of the      are constant and are assigned. The first part of the
7553   * function was written for the case of SELECT statement      function was written for the case of SELECT statement
7554   * inside a FOR loop. Therefore, it is going to be there,      inside a FOR loop. Therefore, it is going to be there,
7555   * but not used at the moment.This function also sorts      but not used at the moment.This function also sorts
7556   * the kinds of variables in the list by assigning a value      the kinds of variables in the list by assigning a value
7557   * to the integer *p1      to the integer *p1
7558   */  */
7559  static  static
7560  int CheckSelectVariableNode(struct Instance *ref,  int CheckSelectVariableNode(struct Instance *ref,
7561                              CONST struct Name *name,                              CONST struct Name *name,
# Line 7582  int CheckSelectVariableNode(struct Insta Line 7633  int CheckSelectVariableNode(struct Insta
7633    }    }
7634  }  }
7635    
7636  /*  /**
7637   * Call CheckSelectSetNode for each set member of the set of      Call CheckSelectSetNode for each set member of the set of
7638   * values of each CASE of a SELECT statement      values of each CASE of a SELECT statement
7639   */  */
7640  static  static
7641  int CheckSelectSetList(struct Instance *inst, struct Set *s, int *p2 )  int CheckSelectSetList(struct Instance *inst, struct Set *s, int *p2 )
7642  {  {
# Line 7601  int CheckSelectSetList(struct Instance * Line 7652  int CheckSelectSetList(struct Instance *
7652    return 1;    return 1;
7653  }  }
7654    
7655  /*  /**
7656   * Call CheckSelectVariableNode for each variable vl in the variable      Call CheckSelectVariableNode for each variable vl in the variable
7657   *list of a SELECT statement      list of a SELECT statement
7658   */  */
7659  static  static
7660  int CheckSelectVariableList(struct Instance *inst, struct VariableList *vlist,  int CheckSelectVariableList(struct Instance *inst, struct VariableList *vlist,
7661                              int *p1)                              int *p1)
# Line 7622  int CheckSelectVariableList(struct Insta Line 7673  int CheckSelectVariableList(struct Insta
7673  }  }
7674    
7675    
7676  /*  /**
7677   * The conditions for checkselect is that      The conditions for checkselect is that
7678   * 1) The number of selection variables is equal to the number      1) The number of selection variables is equal to the number
7679   *    of values in each of the CASEs.         of values in each of the CASEs.
7680   * 2) That the selection variables exist, are constant and      2) That the selection variables exist, are constant and
7681   *    are assigned.         are assigned.
7682   * 3) Only one OTHERWISE case is present.      3) Only one OTHERWISE case is present.
7683   */  */
7684  static  static
7685  int CheckSELECT(struct Instance *inst, struct Statement *statement)  int CheckSELECT(struct Instance *inst, struct Statement *statement)
7686  {  {
# Line 7671  int CheckSELECT(struct Instance *inst, s Line 7722  int CheckSELECT(struct Instance *inst, s
7722  }  }
7723    
7724    
7725  /***********************************************************************/  /*==============================================================================
7726        PASS-BY-PASS CHECKING
7727  /* BUG!: CheckStatement and New flavors of same ignore the  */
    type EXT. We never use external relations inside a loop?!  
    well, ok, maybe they are always hidden as models */  
7728    
7729    /**
7730        @BUG: CheckStatement and New flavors of same ignore the
7731        type EXT. We never use external relations inside a loop?!
7732        well, ok, maybe they are always hidden as models
7733    */
7734  static  static
7735  int Pass4CheckStatement(struct Instance *inst, struct Statement *stat)  int Pass4CheckStatement(struct Instance *inst, struct Statement *stat)
7736  {  {
# Line 7764  int Pass2CheckStatement(struct Instance Line 7818  int Pass2CheckStatement(struct Instance
7818  }  }
7819    
7820  /**  /**
7821   * checking statementlist, as in a FOR loop check.      checking statementlist, as in a FOR loop check.
7822   * relations are not handled in pass 1      relations are not handled in pass 1
7823   */  */
7824  static  static
7825  int Pass1CheckStatement(struct Instance *inst, struct Statement *stat)  int Pass1CheckStatement(struct Instance *inst, struct Statement *stat)
7826  {  {
# Line 7880  int Pass1CheckStatementList(struct Insta Line 7934  int Pass1CheckStatementList(struct Insta
7934  }  }
7935    
7936    
7937  /*************************************************************************\  /*------------------------------------------------------------------------------
7938    FNAME  Statement Processing    'FNAME' STATEMENT PROCESSING
7939  \*************************************************************************/  */
7940    
7941  /*  /**
7942   * The FNAME statement is just used to stand for the model relations or      The FNAME statement is just used to stand for the model relations or
7943   * arrays inside the CASES of a WHEN statement. Actually, this      arrays inside the CASES of a WHEN statement. Actually, this
7944   * statement does not need to be executed. It is required only      statement does not need to be executed. It is required only
7945   * for checking and for avoiding conflicts in the semantics.      for checking and for avoiding conflicts in the semantics.
7946   */  */
7947  static  static
7948  int ExecuteFNAME(struct Instance *inst, struct Statement *statement)  int ExecuteFNAME(struct Instance *inst, struct Statement *statement)
7949  {  {
# Line 7898  int ExecuteFNAME(struct Instance *inst, Line 7952  int ExecuteFNAME(struct Instance *inst,
7952    return 1;    return 1;
7953  }  }
7954    
7955    /*------------------------------------------------------------------------------
   
 /******************************************************************\  
7956    CONDITIONAL Statement Processing    CONDITIONAL Statement Processing
7957  \******************************************************************/  */
7958    
7959  /* The logical relations inside a conditional statement do not have  /**
7960   * to be satisified. They are going to be used to check conditions in      The logical relations inside a conditional statement do not have
7961   * the solution of other logical relations. So, we need something to      to be satisified. They are going to be used to check conditions in
7962   * distinguish a conditional logrelation from a non-conditional      the solution of other logical relations. So, we need something to
7963   * logrelation. The next three functions "Mark" those log relations      distinguish a conditional logrelation from a non-conditional
7964   * inside a CONDITIONAL statement as Conditional logrelations.      logrelation. The next three functions "Mark" those log relations
7965   * Right now we not only set a bit indicating      inside a CONDITIONAL statement as Conditional logrelations.
7966   * that the logrelation is conditional, but also set a flag equal to 1.      Right now we not only set a bit indicating
7967   * This is done in MarkLOGREL above. The flag could be eliminated, but      that the logrelation is conditional, but also set a flag equal to 1.
7968   * we need to fix some places in which it is used, and to use the      This is done in MarkLOGREL above. The flag could be eliminated, but
7969   * bit instead.      we need to fix some places in which it is used, and to use the
7970   */      bit instead.
7971    */
7972  static  static
7973  void Pass3MarkCondLogRels(struct Instance *inst, struct Statement *statement)  void Pass3MarkCondLogRels(struct Instance *inst, struct Statement *statement)
7974  {  {
# Line 7983  void Pass3MarkCondLogRelStat(struct Inst Line 8036  void Pass3MarkCondLogRelStat(struct Inst
8036  }  }
8037    
8038    
8039  /*  /**
8040   * Execution of the statements allowed inside a CONDITIONAL      Execution of the statements allowed inside a CONDITIONAL
8041   * statement. Only log/relations and FOR loops containing only      statement. Only log/relations and FOR loops containing only
8042   * log/relations are allowed.      log/relations are allowed.
8043   */  */
8044  static  static
8045  int Pass3ExecuteCondStatements(struct Instance *inst,  int Pass3ExecuteCondStatements(struct Instance *inst,
8046                                 struct Statement *statement)                                 struct Statement *statement)
# Line 8028  int Pass3RealExecuteCOND(struct Instance Line 8081  int Pass3RealExecuteCOND(struct Instance
8081    return 1;    return 1;
8082  }  }
8083    
8084  /*  /**
8085   * Execution of the Conditional statements. In pass3 we consider only      Execution of the Conditional statements. In pass3 we consider only
8086   * logrelations (or FOR loops of logrelations),so  the checking is not      logrelations (or FOR loops of logrelations),so  the checking is not
8087   * done at all. After execution, the logrelations are set as conditional      done at all. After execution, the logrelations are set as conditional
8088   * by means of a bit and a flag      by means of a bit and a flag
8089   */  */
8090  static  static
8091  int Pass3ExecuteCOND(struct Instance *inst, struct Statement *statement)  int Pass3ExecuteCOND(struct Instance *inst, struct Statement *statement)
8092  {  {
# Line 8049  int Pass3ExecuteCOND(struct Instance *in Line 8102  int Pass3ExecuteCOND(struct Instance *in
8102    return return_value;    return return_value;
8103  }  }
8104    
8105  /* The relations inside a conditional statement do not have to be  /**
8106   * solved. They are going to be used as boundaries in conditional      The relations inside a conditional statement do not have to be
8107   * programming. So, we need something to distinguish a conditional      solved. They are going to be used as boundaries in conditional
8108   * relation from a non-conditional relation. The next three functions      programming. So, we need something to distinguish a conditional
8109   * "Mark" those relations inside a CONDITIONAL statement as      relation from a non-conditional relation. The next three functions
8110   * Conditional relations. Right now we not only set a bit indicating      "Mark" those relations inside a CONDITIONAL statement as
8111   * that the relation is conditional, but also set a flag equal to 1.      Conditional relations. Right now we not only set a bit indicating
8112   * This is done in MarkREL above. The flag could be eliminated, but      that the relation is conditional, but also set a flag equal to 1.
8113   * we need to fix some places in which it is used, and to use the      This is done in MarkREL above. The flag could be eliminated, but
8114   * bit instead.      we need to fix some places in which it is used, and to use the
8115   */      bit instead.
8116    */
8117  static  static
8118  void Pass2MarkCondRelations(struct Instance *inst, struct Statement *statement)  void Pass2MarkCondRelations(struct Instance *inst, struct Statement *statement)
8119  {  {
# Line 8124  void Pass2MarkCondRelStat(struct Instanc Line 8178  void Pass2MarkCondRelStat(struct Instanc
8178    }    }
8179  }  }
8180    
8181  /*  /**
8182   * Execution of the statements allowed inside a CONDITIONAL      Execution of the statements allowed inside a CONDITIONAL
8183   * statement. Only relations and FOR loops containing only      statement. Only relations and FOR loops containing only
8184   * relations are considered in Pass2.      relations are considered in Pass2.
8185   */  */
8186  static  static
8187  int Pass2ExecuteCondStatements(struct Instance *inst,  int Pass2ExecuteCondStatements(struct Instance *inst,
8188                                 struct Statement *statement)                                 struct Statement *statement)
# Line 8179  int Pass2RealExecuteCOND(struct Instance Line 8233  int Pass2RealExecuteCOND(struct Instance
8233    return 1;    return 1;
8234  }  }
8235    
8236  /*  /**
8237   * Execution of the Conditional statements. In pass2 we consider only      Execution of the Conditional statements. In pass2 we consider only
8238   * relations (or FOR loops of relations),so  the checking is not      relations (or FOR loops of relations),so  the checking is not
8239   * done at all. After execution, the relations are set as conditional      done at all. After execution, the relations are set as conditional
8240   * by means of a bit and a flag      by means of a bit and a flag
8241   */  */
8242  static  static
8243  int Pass2ExecuteCOND(struct Instance *inst, struct Statement *statement)  int Pass2ExecuteCOND(struct Instance *inst, struct Statement *statement)
8244  {  {
# Line 8201  int Pass2ExecuteCOND(struct Instance *in Line 8255  int Pass2ExecuteCOND(struct Instance *in
8255  }  }
8256    
8257    
8258  /*  /**
8259   * For its use in ExecuteUnSelectedStatements.      For its use in ExecuteUnSelectedStatements.
8260   * Execute the  statements of a CONDITIONAL statement which is inside      Execute the  statements of a CONDITIONAL statement which is inside
8261   * a CASE not matching the selection variables.      a CASE not matching the selection variables.
8262   * Only FOR loops containing log/relations or log/relations are allowed  
8263   * inside CONDITIONAL statements. This function ultimately call      Only FOR loops containing log/relations or log/relations are allowed
8264   * the function ExecuteUnSelectedEQN, to create Dummy instances      inside CONDITIONAL statements. This function ultimately call
8265   * for the relations inside CONDITIONAL      the function ExecuteUnSelectedEQN, to create Dummy instances
8266   */      for the relations inside CONDITIONAL
8267    */
8268  static  static
8269  int ExecuteUnSelectedCOND(struct Instance *inst, struct Statement *statement)  int ExecuteUnSelectedCOND(struct Instance *inst, struct Statement *statement)
8270  {  {
# Line 8243  int ExecuteUnSelectedCOND(struct Instanc Line 8298  int ExecuteUnSelectedCOND(struct Instanc
8298    return 1;    return 1;
8299  }  }
8300    
8301    /*------------------------------------------------------------------------------
8302      'WHEN' STATEMENT PROCESSING
8303    */
8304    
8305  /*************************************************************************\  /**
8306    WHEN Statement Processing      Find the instances corresponding to the list of conditional
8307  \*************************************************************************/      variables of a WHEN, and append ther pointers in a gl_list.
8308        This gl_list becomes part of the WHEN instance.
8309  /* Find the instances corresponding to the list of conditional      Also, this function notify those instances that the WHEN is
8310   * variables of a WHEN, and append ther pointers in a gl_list.      pointing to them, so that their list of whens is updated.
8311   * This gl_list becomes part of the WHEN instance.  */
  * Also, this function notify those instances that the WHEN is  
  * pointing to them, so that their list of whens is updated.  
  */  
8312  static  static
8313  struct gl_list_t *MakeWhenVarList(struct Instance *inst,  struct gl_list_t *MakeWhenVarList(struct Instance *inst,
8314                                    struct Instance *child,                                    struct Instance *child,
# Line 8305  struct gl_list_t *MakeWhenVarList(struct Line 8360  struct gl_list_t *MakeWhenVarList(struct
8360    return whenvars;    return whenvars;
8361  }  }
8362    
8363  /* The following four functions create the gl_list of references of  /*- - - - - - - - - -  -  - - - - - - - - -
8364   * each CASE of a WHEN instance. By list of references I mean the      The following four functions create the gl_list of references of
8365   * list of pointers to relations, models or arrays which will become      each CASE of a WHEN instance. By list of references I mean the
8366   * active if such a CASE applies.      list of pointers to relations, models or arrays which will become
8367   */      active if such a CASE applies.
8368    */
8369    
8370  /* dealing with arrays */  /**
8371        creating list of reference for each CASE in a WHEN: (1) dealing with arrays
8372    */
8373  static  static
8374  void MakeWhenArrayReference(struct Instance *when,  void MakeWhenArrayReference(struct Instance *when,
8375                              struct Instance *child,                              struct Instance *child,
# Line 8353  void MakeWhenArrayReference(struct Insta Line 8411  void MakeWhenArrayReference(struct Insta
8411    }    }
8412  }  }
8413    
8414    /**
8415        creating list of reference for each CASE in a WHEN: (2)
8416    */
8417  static  static
8418  void MakeWhenReference(struct Instance *ref,  void MakeWhenReference(struct Instance *ref,
8419                         struct Instance *child,                         struct Instance *child,
# Line 8423  void MakeWhenReference(struct Instance * Line 8484  void MakeWhenReference(struct Instance *
8484    }    }
8485  }  }
8486    
8487  /* dealing with nested WHENs, nested FOR loops etc. */  /**
8488        creating list of reference for each CASE in a WHEN: (3) nested WHENs,
8489        nested FOR loops etc.
8490    */
8491  static  static
8492  void MakeWhenCaseReferences(struct Instance *inst,  void MakeWhenCaseReferences(struct Instance *inst,
8493                              struct Instance *child,                              struct Instance *child,
# Line 8458  void MakeWhenCaseReferences(struct Insta Line 8522  void MakeWhenCaseReferences(struct Insta
8522    }    }
8523  }  }
8524    
8525  /* The following function is almos identical from the previous one.  /**
8526   * They differ only in the case of a FOR loop. This function is      creating list of reference for each CASE in a WHEN: (4) almost identical
8527   * required to appropriately deal with nested FOR loops which      to the previous one.
8528   * contain FNAMEs or WHENs      They differ only in the case of a FOR loop. This function is
8529   */      required to appropriately deal with nested FOR loops which
8530        contain FNAMEs or WHENs
8531    */
8532  static  static
8533  void MakeRealWhenCaseReferencesList(struct Instance *inst,  void MakeRealWhenCaseReferencesList(struct Instance *inst,
8534                                      struct Instance *child,                                      struct Instance *child,
# Line 8499  void MakeRealWhenCaseReferencesList(stru Line 8565  void MakeRealWhenCaseReferencesList(stru
8565    return ;    return ;
8566  }  }
8567    
8568    /*-  - - - - - - - - - -- - - - - -  - - */
8569    
8570  /* Make a WHEN instance or an array of WHEN instances by calling  /**
8571   * CreateWhenInstance. It does not create the lists of pointers      Make a WHEN instance or an array of WHEN instances by calling
8572   * to the conditional variables or the models or relations.      CreateWhenInstance. It does not create the lists of pointers
8573   */      to the conditional variables or the models or relations.
8574    */
8575    
8576  static  static
8577  struct Instance *MakeWhenInstance(struct Instance *parent,  struct Instance *MakeWhenInstance(struct Instance *parent,
# Line 8544  struct Instance *MakeWhenInstance(struct Line 8612  struct Instance *MakeWhenInstance(struct
8612    }    }
8613  }  }
8614    
8615  /*  /**
8616   * Executing the possible kind of statements inside a WHEN. It      Executing the possible kind of statements inside a WHEN. It
8617   * consider the existence of FOR loops and nested WHENs      consider the existence of FOR loops and nested WHENs
8618   */  */
8619  static  static
8620  void ExecuteWhenStatements(struct Instance *inst,  void ExecuteWhenStatements(struct Instance *inst,
8621                             struct StatementList *sl)                             struct StatementList *sl)
# Line 8582  void ExecuteWhenStatements(struct Instan Line 8650  void ExecuteWhenStatements(struct Instan
8650  }  }
8651    
8652    
8653  /*  /**
8654   * Creates a CASE included in a WHEN statement. It involves the      Creates a CASE included in a WHEN statement. It involves the
8655   * allocation of memory of the CASE and the creation of the      allocation of memory of the CASE and the creation of the
8656   * gl_list of references (pointer to models, arrays, relations)      gl_list of references (pointer to models, arrays, relations)
8657   * which will be contained in such a case.      which will be contained in such a case.
8658   */  */
8659  static  static
8660  struct Case *RealExecuteWhenStatements(struct Instance *inst,  struct Case *RealExecuteWhenStatements(struct Instance *inst,
8661                                         struct Instance *child,                                         struct Instance *child,
# Line 8609  struct Case *RealExecuteWhenStatements(s Line 8677  struct Case *RealExecuteWhenStatements(s
8677    return cur_case;    return cur_case;
8678  }  }
8679    
8680  /* Call the Creation of a WHEN instance. This function is also in charge  /**
8681   * of filling the gl_list of conditional variables and the gl_list of      Call the Creation of a WHEN instance. This function is also in charge
8682   * CASEs contained in the WHEN instance      of filling the gl_list of conditional variables and the gl_list of
8683   */      CASEs contained in the WHEN instance
8684    */
8685  static  static
8686  void RealExecuteWHEN(struct Instance *inst, struct Statement *statement)  void RealExecuteWHEN(struct Instance *inst, struct Statement *statement)
8687  {  {
# Line 8670  void RealExecuteWHEN(struct Instance *in Line 8739  void RealExecuteWHEN(struct Instance *in
8739  }  }
8740    
8741    
8742  /* After Checking the WHEN statement, it calls for its  execution */  /**
8743        After Checking the WHEN statement, it calls for its  execution
8744    */
8745  static  static
8746  int ExecuteWHEN(struct Instance *inst, struct Statement *statement)  int ExecuteWHEN(struct Instance *inst, struct Statement *statement)
8747  {  {
# Line 8684  int ExecuteWHEN(struct Instance *inst, s Line 8755  int ExecuteWHEN(struct Instance *inst, s
8755  }  }
8756    
8757    
8758  /*  /**
8759   * Written because of the possiblity of nested WHEN and      Written because of the possiblity of nested WHEN and
8760   * Nested WHEN inside a FOR loop in an unselected case of      Nested WHEN inside a FOR loop in an unselected case of
8761   * SELECT statement      SELECT statement
8762   */  */
8763  static  static
8764  void ExecuteUnSelectedWhenStatements(struct Instance *inst,  void ExecuteUnSelectedWhenStatements(struct Instance *inst,
8765                                       struct StatementList *sl)                                       struct StatementList *sl)
# Line 8722  void ExecuteUnSelectedWhenStatements(str Line 8793  void ExecuteUnSelectedWhenStatements(str
8793  }  }
8794    
8795  /*  /*
8796   * For its use in ExecuteUnSelectedStatements.      For its use in ExecuteUnSelectedStatements.
8797   * Execute the WHEN statements inside those cases of a SELECT      Execute the WHEN statements inside those cases of a SELECT
8798   * which do not match the selection variables      which do not match the selection variables
8799   */  */
8800  static  static
8801  int ExecuteUnSelectedWHEN(struct Instance *inst, struct Statement *statement)  int ExecuteUnSelectedWHEN(struct Instance *inst, struct Statement *statement)
8802  {  {
# Line 8764  int ExecuteUnSelectedWHEN(struct Instanc Line 8835  int ExecuteUnSelectedWHEN(struct Instanc
8835    return 1;    return 1;
8836  }  }
8837    
8838    /*------------------------------------------------------------------------------
8839      'SELECT' STATEMENT PROCESSING
8840    */
8841    
8842  /*************************************************************************\  /**
8843    SELECT  Statement Processing      Execution of the Statements inside the case that
8844  \*************************************************************************/      matches the selection variables
8845    */
 /*  
  * Execution of the Statements inside the case that  
  * matches the selection variables  
  */  
8846  static  static
8847  void ExecuteSelectStatements(struct Instance *inst, unsigned long *count,  void ExecuteSelectStatements(struct Instance *inst, unsigned long *count,
8848                               struct StatementList *sl)                               struct StatementList *sl)
# Line 8861  void ExecuteSelectStatements(struct Inst Line 8931  void ExecuteSelectStatements(struct Inst
8931  }  }
8932    
8933    
8934  /*  /**
8935   * Execution of the UnSelected Statements inside those cases of the      Execution of the UnSelected Statements inside those cases of the
8936   * SELECT that do not match match the selection variables      SELECT that do not match match the selection variables
8937   */  */
   
8938  static  static
8939  void ExecuteUnSelectedStatements(struct Instance *inst,unsigned long *count,  void ExecuteUnSelectedStatements(struct Instance *inst,unsigned long *count,
8940                                   struct StatementList *sl)                                   struct StatementList *sl)
# Line 8938  void ExecuteUnSelectedStatements(struct Line 9007  void ExecuteUnSelectedStatements(struct
9007    }    }
9008  }  }
9009    
9010  /*  /**
9011   * Execution of the SELECT statement inside a case that does not      Execution of the SELECT statement inside a case that does not
9012   * match the selection variables      match the selection variables
9013   */  */
9014  static  static
9015  int ExecuteUnSelectedSELECT(struct Instance *inst, unsigned long *c,  int ExecuteUnSelectedSELECT(struct Instance *inst, unsigned long *c,
9016                              struct Statement *statement)                              struct Statement *statement)
# Line 8962  int ExecuteUnSelectedSELECT(struct Insta Line 9031  int ExecuteUnSelectedSELECT(struct Insta
9031  }  }
9032    
9033    
9034  /*  /**
9035   * Compare current values of the selection variables with      Compare current values of the selection variables with
9036   * the set of values in a CASE of a SELECT statement, and try to find      the set of values in a CASE of a SELECT statement, and try to find
9037   * is such values are the same. If they are, the function will return 1,      is such values are the same. If they are, the function will return 1,
9038   * else, it will return 0.      else, it will return 0.
9039   */  */
9040  static  static
9041  int AnalyzeSelectCase(struct Instance *ref, struct VariableList *vlist,  int AnalyzeSelectCase(struct Instance *ref, struct VariableList *vlist,
9042                        struct Set *s)                        struct Set *s)
# Line 9032  int AnalyzeSelectCase(struct Instance *r Line 9101  int AnalyzeSelectCase(struct Instance *r
9101  }  }
9102    
9103    
9104  /* This function will determine which case of a SELECT statement  /**
9105   * applies for the current values of the selection variables.      This function will determine which case of a SELECT statement
9106   * this function  will call for the execution of the case which      applies for the current values of the selection variables.
9107   * matches. It handles OTHERWISE properly (case when set == NULL).      this function  will call for the execution of the case which
9108   * At most one case is going to be executed.      matches. It handles OTHERWISE properly (case when set == NULL).
9109   */      At most one case is going to be executed.
9110    */
9111  static  static
9112  void RealExecuteSELECT(struct Instance *inst, unsigned long *c,  void RealExecuteSELECT(struct Instance *inst, unsigned long *c,
9113                         struct Statement *statement)                         struct Statement *statement)
# Line 9083  void RealExecuteSELECT(struct Instance * Line 9152  void RealExecuteSELECT(struct Instance *
9152  }  }
9153    
9154    
9155  /* If A SELECT statement passess its checking, this function  /**
9156   * will ask for its execution, otherwise the SELECT and all      If A SELECT statement passess its checking, this function
9157   * the other statements inside of it, will not be touched.      will ask for its execution, otherwise the SELECT and all
9158   * The counter in the bitlist is increased properly.      the other statements inside of it, will not be touched.
9159   * NOTE for efficiency: Maybe we should integrate the      The counter in the bitlist is increased properly.
9160   * Check function of the SELECT together with the analysis      NOTE for efficiency: Maybe we should integrate the
9161   * of the CASEs to see which of them matches.We are doing      Check function of the SELECT together with the analysis
9162   * twice the execution of some C functions.      of the CASEs to see which of them matches.We are doing
9163   */      twice the execution of some C functions.
9164    */
9165  static  static
9166  int ExecuteSELECT(struct Instance *inst, unsigned long *c,  int ExecuteSELECT(struct Instance *inst, unsigned long *c,
9167                    struct Statement *statement)                    struct Statement *statement)
# Line 9113  int ExecuteSELECT(struct Instance *inst, Line 9183  int ExecuteSELECT(struct Instance *inst,
9183  }  }
9184    
9185    
9186  /*  /**
9187   * This function jumps the statements inside non-matching      This function jumps the statements inside non-matching
9188   * cases of a SELECT statement, so that they are not analyzed      cases of a SELECT statement, so that they are not analyzed
9189   * in compilation passes > 1.      in compilation passes > 1.
9190   * If there is a SELECT inside a SELECT,      If there is a SELECT inside a SELECT,
9191   * the function uses the number of statements in the nested      the function uses the number of statements in the nested
9192   * SELECTs      SELECTs
9193   */  */
9194  static  static
9195  void JumpSELECTStats(unsigned long *count,struct StatementList *sl)  void JumpSELECTStats(unsigned long *count,struct StatementList *sl)
9196  {  {
# Line 9146  void JumpSELECTStats(unsigned long *coun Line 9216  void JumpSELECTStats(unsigned long *coun
9216    return;    return;
9217  }  }
9218    
9219  /* This function is used only for setting  the  /**
9220   * bits ON for some statements in the matching case of a      This function is used only for setting  the
9221   * SELECT statement. Only these statements will be      bits ON for some statements in the matching case of a
9222   * analyzed in Pass > 1. The conditions to set a bit ON      SELECT statement. Only these statements will be
9223   * depend on the number of pass.      analyzed in Pass > 1. The conditions to set a bit ON
9224   */      depend on the number of pass.
9225    */
9226  static  static
9227  void SetBitsOnOfSELECTStats(struct Instance *inst, unsigned long *count,  void SetBitsOnOfSELECTStats(struct Instance *inst, unsigned long *count,
9228                              struct StatementList *sl, int pass, int *changed)                              struct StatementList *sl, int pass, int *changed)
# Line 9260  void SetBitsOnOfSELECTStats(struct Insta Line 9331  void SetBitsOnOfSELECTStats(struct Insta
9331  }  }
9332    
9333    
9334  /* This function will determine which case of a SELECT statement  /**
9335   * applies for the current values of the selection variables.      This function will determine which case of a SELECT statement
9336   * Similar performance from RealExecuteSELECT, but this function      applies for the current values of the selection variables.
9337   * does not call for execution, it is used only for "jumping"      Similar performance from RealExecuteSELECT, but this function
9338   * the statements inside a non-matching case, or seting the      does not call for execution, it is used only for "jumping"
9339   * bits on for some statements in the matching case.      the statements inside a non-matching case, or seting the
9340   * It handles OTHERWISE properly (case when set == NULL).      bits on for some statements in the matching case.
9341   */      It handles OTHERWISE properly (case when set == NULL).
9342    */
9343  static  static
9344  void SetBitOfSELECTStat(struct Instance *inst, unsigned long *c,  void SetBitOfSELECTStat(struct Instance *inst, unsigned long *c,
9345                          struct Statement *statement, int pass, int *changed)                          struct Statement *statement, int pass, int *changed)
# Line 9307  void SetBitOfSELECTStat(struct Instance Line 9379  void SetBitOfSELECTStat(struct Instance
9379    }    }
9380  }  }
9381    
9382  /*  /**
9383   * For compilation passes > 1, this function will tell me if I      For compilation passes > 1, this function will tell me if I
9384   * should Set the Bits on for statements inside the CASEs of      should Set the Bits on for statements inside the CASEs of
9385   * a SELECT statement. This evaluation is needed because there may be      a SELECT statement. This evaluation is needed because there may be
9386   * relations, whens or log rels that should not be executed      relations, whens or log rels that should not be executed
9387   * at all (when the selection variables do not exist, for example)      at all (when the selection variables do not exist, for example)
9388   * or should  not be reanlyzed in pass2 3 and 4 (when they are      or should  not be reanlyzed in pass2 3 and 4 (when they are
9389   * already dummys, for example). This re-evaluation will not be done      already dummys, for example). This re-evaluation will not be done
9390   * if the SELECT does not contain rels, logrels or when.      if the SELECT does not contain rels, logrels or when.
9391   * NOTE for efficiency: Maybe we should integrate the      NOTE for efficiency: Maybe we should integrate the
9392   * Check function of the SELECT together with the analysis      Check function of the SELECT together with the analysis
9393   * of the CASEs to see which of them matches.We are doing      of the CASEs to see which of them matches.We are doing
9394   * twice the execution of some C functions.      twice the execution of some C functions.
9395   */  */
   
9396  static  static
9397  void ReEvaluateSELECT(struct Instance *inst, unsigned long *c,  void ReEvaluateSELECT(struct Instance *inst, unsigned long *c,
9398                        struct Statement *statement, int pass, int *changed)                        struct Statement *statement, int pass, int *changed)
# Line 9341  void ReEvaluateSELECT(struct Instance *i Line 9412  void ReEvaluateSELECT(struct Instance *i
9412  }  }
9413    
9414    
9415  /* This function is used only for setting  the  /**
9416   * bits ON for some statements in the matching case of a      This function is used only for setting  the
9417   * SELECT statement. Only these statements will be      bits ON for some statements in the matching case of a
9418   * analyzed in Pass > 1. The conditions to set a bit ON      SELECT statement. Only these statements will be
9419   * depend on the number of pass.      analyzed in Pass > 1. The conditions to set a bit ON
9420   */      depend on the number of pass.
9421    */
9422  static  static
9423  void ExecuteDefaultsInSELECTCase(struct Instance *inst, unsigned long *count,  void ExecuteDefaultsInSELECTCase(struct Instance *inst, unsigned long *count,
9424                                   struct StatementList *sl,                                   struct StatementList *sl,
# Line 9385  void ExecuteDefaultsInSELECTCase(struct Line 9457  void ExecuteDefaultsInSELECTCase(struct
9457  }  }
9458    
9459    
9460  /* This function will determine which case of a SELECT statement  /**
9461   * applies for the current values of the selection variables.      This function will determine which case of a SELECT statement
9462   * Similar performance from RealExecuteSELECT. This function      applies for the current values of the selection variables.
9463   * is used only for "jumping"  the statements inside a non-matching      Similar performance from RealExecuteSELECT. This function
9464   * case, or Executing Defaults in the matching case.      is used only for "jumping"  the statements inside a non-matching
9465   * It handles OTHERWISE properly (case when set == NULL).      case, or Executing Defaults in the matching case.
9466   */      It handles OTHERWISE properly (case when set == NULL).
9467    */
9468  static  static
9469  void ExecuteDefaultsInSELECTStat(struct Instance *inst, unsigned long *c,  void ExecuteDefaultsInSELECTStat(struct Instance *inst, unsigned long *c,
9470                                   struct Statement *statement,                                   struct Statement *statement,
# Line 9432  void ExecuteDefaultsInSELECTStat(struct Line 9505  void ExecuteDefaultsInSELECTStat(struct
9505    }    }
9506  }  }
9507    
9508  /*  /**
9509   * For Execution of Defaults, which uses a Visit Instance Tree instead of      For Execution of Defaults, which uses a Visit Instance Tree instead of
9510   * a BitList. this function will tell me if I      a BitList. this function will tell me if I
9511   * should Set the Bits on for statements inside the CASEs of      should Set the Bits on for statements inside the CASEs of
9512   * a SELECT statement. This evaluation is needed because there is      a SELECT statement. This evaluation is needed because there is
9513   * the possibility of different assignments to the same variable in      the possibility of different assignments to the same variable in
9514   * different cases of the select. I need to execute only those in      different cases of the select. I need to execute only those in
9515   * cases mathing the selection variables.      cases mathing the selection variables.
9516   * It is becoming annoying to have so similar functions, I need      
9517   * to create a robust and general function which considers all the      @TODO It is becoming annoying to have so similar functions, I need
9518   * possible applications.      to create a robust and general function which considers all the
9519   */      possible applications.
9520    */
9521  static  static
9522  void ExecuteDefaultsInSELECT(struct Instance *inst, unsigned long *c,  void ExecuteDefaultsInSELECT(struct Instance *inst, unsigned long *c,
9523                               struct Statement *statement,                               struct Statement *statement,
# Line 9461  void ExecuteDefaultsInSELECT(struct Inst Line 9535  void ExecuteDefaultsInSELECT(struct Inst
9535    return;    return;
9536  }  }
9537    
9538    /*------------------------------------------------------------------------------
9539  /**************************************************************************\    'FOR' STATEMENT PROCESSING
9540    FOR Statement processing.  */
 \**************************************************************************/  
9541  static  static
9542  void WriteForValueError(struct Statement *statement, struct value_t value)  void WriteForValueError(struct Statement *statement, struct value_t value)
9543  {  {
# Line 9549  int Pass4ExecuteForStatements(struct Ins Line 9622  int Pass4ExecuteForStatements(struct Ins
9622  }  }
9623    
9624    
9625  /* Note: this function must not be called until all the rel,ext  /**
9626   * statements in sl pass their checks.      @NOTE this function must not be called until all the rel,ext
9627   */      statements in sl pass their checks.
9628    */
9629  static  static
9630  int Pass3ExecuteForStatements(struct Instance *inst,  int Pass3ExecuteForStatements(struct Instance *inst,
9631                                struct StatementList *sl)                                struct StatementList *sl)
# Line 9624  int Pass3ExecuteForStatements(struct Ins Line 9698  int Pass3ExecuteForStatements(struct Ins
9698  }  }
9699    
9700    
9701  /* Note: this function must not be called until all the rel,ext  /**
9702   * statements in sl pass their checks.      @NOTE this function must not be called until all the rel,ext
9703   * This is because if any of the Executes fail      statements in sl pass their checks.
9704   * (returning 0) we abort (at least when assert is active).      
9705   * This should be changed.      This is because if any of the Executes fail
9706   */      (returning 0) we abort (at least when assert is active).
9707        
9708        @TODO This should be changed.
9709    */
9710  static  static
9711  void Pass2ExecuteForStatements(struct Instance *inst,  void Pass2ExecuteForStatements(struct Instance *inst,
9712                                 struct StatementList *sl)                                 struct StatementList *sl)
# Line 9716  void Pass2ExecuteForStatements(struct In Line 9793  void Pass2ExecuteForStatements(struct In
9793  }  }
9794    
9795    
9796  /* Note: this function must not be called until all the statements in sl  /**
9797   * (except rel, ext)pass their checks.      @NOTE this function must not be called until all the statements in sl
9798   * This is because if any of the Executes fail      (except rel, ext)pass their checks.
9799   * (returning 0) we abort (at least when assert is active)  */      This is because if any of the Executes fail
9800        (returning 0) we abort (at least when assert is active)
9801    */
9802  static  static
9803  void Pass1ExecuteForStatements(struct Instance *inst,  void Pass1ExecuteForStatements(struct Instance *inst,
9804                                 struct StatementList *sl)                                 struct StatementList *sl)
# Line 9791  void Pass1ExecuteForStatements(struct In Line 9870  void Pass1ExecuteForStatements(struct In
9870  }  }
9871    
9872    
9873  /*  /**
9874   * Execute UnSelected statements inside a FOR loop      Execute UnSelected statements inside a FOR loop
9875   * Note that we are not expanding arrays. This actually      Note that we are not expanding arrays. This actually
9876   * may be impossible even if we want to do it.      may be impossible even if we want to do it.
9877   */  */
   
9878  static  static
9879  int ExecuteUnSelectedForStatements(struct Instance *inst,  int ExecuteUnSelectedForStatements(struct Instance *inst,
9880                                     struct StatementList *sl)                                     struct StatementList *sl)
# Line 10031  void MakeRealWhenCaseReferencesFOR(struc Line 10109  void MakeRealWhenCaseReferencesFOR(struc
10109    }    }
10110  }  }
10111    
10112  /* this function needs to be made much less aggressive about exiting  /**
10113   * and more verbose about error messages  so we can skip the np3checkfor      @TODO this function needs to be made much less aggressive about exiting
10114   * probably also means it needs the 0/1 fail/succeed return code.      and more verbose about error messages  so we can skip the np3checkfor
10115   */      probably also means it needs the 0/1 fail/succeed return code.
10116    */
10117  static  static
10118  int Pass3RealExecuteFOR(struct Instance *inst, struct Statement *statement)  int Pass3RealExecuteFOR(struct Instance *inst, struct Statement *statement)
10119  {  {
# Line 10199  void Pass3FORMarkCond(struct Instance *i Line 10278  void Pass3FORMarkCond(struct Instance *i
10278  }  }
10279    
10280    
10281  /* this function needs to be made much less aggressive about exiting  /**
10282   * and more verbose about error messages  so we can skip the np2checkfor      @TODO this function needs to be made much less aggressive about exiting
10283   * probably also means it needs the 0/1 fail/succeed return code.      and more verbose about error messages  so we can skip the np2checkfor
10284   */      probably also means it needs the 0/1 fail/succeed return code.
10285    */
10286  static  static
10287  int Pass2RealExecuteFOR(struct Instance *inst, struct Statement *statement)  int Pass2RealExecuteFOR(struct Instance *inst, struct Statement *statement)
10288  {  {
# Line 10651  int Pass3RealCheckFOR (struct Instance * Line 10731  int Pass3RealCheckFOR (struct Instance *
10731  }  }
10732    
10733    
10734  /* a currently unused function, with therefore unused subsidiary functions */  /**
10735        a currently unused function, with therefore unused subsidiary functions
10736    */
10737  static  static
10738  int Pass2CheckFOR(struct Instance *inst, struct Statement *statement)  int Pass2CheckFOR(struct Instance *inst, struct Statement *statement)
10739  {  {
# Line 10935  int Pass1ExecuteFOR(struct Instance *ins Line 11017  int Pass1ExecuteFOR(struct Instance *ins
11017    }    }
11018  }  }
11019    
11020    /*------------------------------------------------------------------------------
11021      GENERAL STATEMENT PROCESSING
11022    */
11023    
   
 /**************************************************************************\  
   General Statement processing.  
 \**************************************************************************/  
11024  static  static
11025  int Pass4ExecuteStatement(struct Instance *inst,struct Statement *statement)  int Pass4ExecuteStatement(struct Instance *inst,struct Statement *statement)
11026  {  {
# Line 11084  int ArraysExpanded(struct Instance *work Line 11165  int ArraysExpanded(struct Instance *work
11165    return 1;    return 1;
11166  }  }
11167    
11168    /**
11169        Try to execute all the when statements in instance work.
11170        It assumes that work is the top of the pending instance list.
11171        Will skip all non-when statements.
11172    */
11173  static  static
11174  void Pass4ExecuteWhenStatements(struct BitList *blist,  void Pass4ExecuteWhenStatements(struct BitList *blist,
11175                                  struct Instance *work,                                  struct Instance *work,
11176                                  int *changed)                                  int *changed
11177  /*********************************************************************\  ){
 Try to execute all the when statements in instance work.  
 It assumes that work is the top of the pending instance list.  
 Will skip all non-when statements.  
 \*********************************************************************/  
 {  
11178    unsigned long c;    unsigned long c;
11179    struct TypeDescription *def;    struct TypeDescription *def;
11180    struct gl_list_t *statements;    struct gl_list_t *statements;
# Line 11112  Will skip all non-when statements. Line 11193  Will skip all non-when statements.
11193    }    }
11194  }  }
11195    
11196    /**
11197        Try to execute all the unexecuted logical relations in instance work.
11198        It assumes that work is the top of the pending instance list.
11199        Will skip all non-logical relations.
11200    */
11201  static  static
11202  void Pass3ExecuteLogRelStatements(struct BitList *blist,  void Pass3ExecuteLogRelStatements(struct BitList *blist,
11203                                       struct Instance *work,                                       struct Instance *work,
11204                                       int *changed)                                       int *changed
11205  /*********************************************************************\  ){
 Try to execute all the unexecuted logical relations in instance work.  
 It assumes that work is the top of the pending instance list.  
 Will skip all non-logical relations.  
 \*********************************************************************/  
 {  
11206    unsigned long c;    unsigned long c;
11207    struct TypeDescription *def;    struct TypeDescription *def;
11208    struct gl_list_t *statements;    struct gl_list_t *statements;
# Line 11140  Will skip all non-logical relations. Line 11221  Will skip all non-logical relations.
11221    }    }
11222  }  }
11223    
11224    /**
11225        Try to execute all the unexecuted relations in instance work.
11226        Does not assume that work is the top of the pending instance list.
11227        Will skip all non-relations in instance work.
11228    */
11229  static  static
11230  void Pass2ExecuteRelationStatements(struct BitList *blist,  void Pass2ExecuteRelationStatements(struct BitList *blist,
11231                                      struct Instance *work,                                      struct Instance *work,
11232                                      int *changed)                                      int *changed
11233  /*********************************************************************\  ){
 Try to execute all the unexecuted relations in instance work.  
 Does not assume that work is the top of the pending instance list.  
 Will skip all non-relations in instance work.  
 \*********************************************************************/  
 {  
11234    unsigned long c;    unsigned long c;
11235    struct TypeDescription *def;    struct TypeDescription *def;
11236    struct gl_list_t *statements;    struct gl_list_t *statements;
# Line 11168  Will skip all non-relations in instance Line 11249  Will skip all non-relations in instance
11249    }    }
11250  }  }
11251    
11252    /**
11253        Try to execute all the unexecuted statements in instance work.
11254        It assumes that work is the top of the pending instance list.
11255        Will skip relations in a new way. Relations instances and arrays of
11256        relations will be left as NULL instances (not merely hollow relations)
11257    */
11258  static  static
11259  void Pass1ExecuteInstanceStatements(struct BitList *blist,  void Pass1ExecuteInstanceStatements(struct BitList *blist,
11260                                      struct Instance *work,                                      struct Instance *work,
11261                                      int *changed)                                      int *changed
11262  /*********************************************************************\  ){
 Try to execute all the unexecuted statements in instance work.  
 It assumes that work is the top of the pending instance list.  
 Will skip relations in a new way. Relations instances and arrays of  
 relations will be left as NULL instances (not merely hollow relations)  
 \*********************************************************************/  
 {  
11263    unsigned long c;    unsigned long c;
11264    struct TypeDescription *def;    struct TypeDescription *def;
11265    struct gl_list_t *statements;    struct gl_list_t *statements;
# Line 11330  void Pass3ProcessPendingInstances(void) Line 11411  void Pass3ProcessPendingInstances(void)
11411    /* done, or there were no pendings at all and while failed */    /* done, or there were no pendings at all and while failed */
11412  }  }
11413    
11414  /*  /**
11415   * This is the singlepass phase2 with anontype sharing of      This is the singlepass phase2 with anontype sharing of
11416   * relations implemented. If relations can depend on other      relations implemented. If relations can depend on other
11417   * relations (as in future differential work) then this function      relations (as in future differential work) then this function
11418   * needs to be slightly more sophisticated.      needs to be slightly more sophisticated.
11419   */  */
11420  static  static
11421  void Pass2ProcessPendingInstancesAnon(struct Instance *result)  void Pass2ProcessPendingInstancesAnon(struct Instance *result)
11422  {  {
# Line 11423  void Pass2ProcessPendingInstancesAnon(st Line 11504  void Pass2ProcessPendingInstancesAnon(st
11504    /* done, or there were no pendings at all and while failed */    /* done, or there were no pendings at all and while failed */
11505  }  }
11506    
11507  /*  /**
11508   * This is the old pass1-like flavor of pass2process.      This is the old pass1-like flavor of pass2process.
11509   * Do not delete it yet, as it is the way we'll have to      Do not delete it yet, as it is the way we'll have to
11510   * start thinking if relations reference relations, i.e.      start thinking if relations reference relations, i.e.
11511   * in the use of derivatives in the ASCEND language.      in the use of derivatives in the ASCEND language.
11512   */  */
11513  static  static
11514  void Pass2ProcessPendingInstances(void)  void Pass2ProcessPendingInstances(void)
11515  {  {
# Line 11492  void Pass2ProcessPendingInstances(void) Line 11573  void Pass2ProcessPendingInstances(void)
11573  }  }
11574    
11575    
11576  /*  /**
11577   * in a bizarre way, this will generally lead to a bottom up      in a bizarre way, this will generally lead to a bottom up
11578   * instantiation finishing process, though it is started in a      instantiation finishing process, though it is started in a
11579   * top down fashion.      top down fashion.
11580   */  */
11581  static  static
11582  void Pass1ProcessPendingInstances(void)  void Pass1ProcessPendingInstances(void)
11583  {  {
# Line 11688  static void ExecuteDefault(struct Instan Line 11769  static void ExecuteDefault(struct Instan
11769    }    }
11770  }  }
11771    
11772  /* run the default statements of i, including nested fors, but  /**
11773   * not recursive to i children.      run the default statements of i, including nested fors, but
11774   */      not recursive to i children.
11775    */
11776  static  static
11777  void ExecuteDefaultStatements(struct Instance *i,  void ExecuteDefaultStatements(struct Instance *i,
11778                                struct gl_list_t *slist,                                struct gl_list_t *slist,
# Line 11853  void DefaultInstanceTree(struct Instance Line 11935  void DefaultInstanceTree(struct Instance
11935    VisitInstanceTree(i,DefaultInstance,0,0);    VisitInstanceTree(i,DefaultInstance,0,0);
11936  }  }
11937    
11938  /* This just handles instantiating whens,  /**
11939   * ignoring anything else.      This just handles instantiating whens,
11940   * This works with Pass4ProcessPendingInstances.      ignoring anything else.
11941   */      This works with Pass4ProcessPendingInstances.
11942    */
11943  static  static
11944  struct Instance *Pass4InstantiateModel(struct Instance *result,  struct Instance *Pass4InstantiateModel(struct Instance *result,
11945                                         unsigned long *pcount)                                         unsigned long *pcount)
# Line 11925  void Pass4SetWhenBits(struct Instance *i Line 12008  void Pass4SetWhenBits(struct Instance *i
12008    
12009    
12010    
12011  /* This just handles instantiating logical relations,  /**
12012   * ignoring anything else.      This just handles instantiating logical relations,
12013   * This works with Pass3ProcessPendingInstances.      ignoring anything else.
12014   * No recursion. No reallocation of result.      This works with Pass3ProcessPendingInstances.
12015   */      No recursion. No reallocation of result.
12016    */
12017  static  static
12018  struct Instance *Pass3InstantiateModel(struct Instance *result,  struct Instance *Pass3InstantiateModel(struct Instance *result,
12019                                         unsigned long *pcount)                                         unsigned long *pcount)
# Line 11996  void Pass3SetLogRelBits(struct Instance Line 12080  void Pass3SetLogRelBits(struct Instance
12080    }    }
12081  }  }
12082    
12083  /* This just handles instantiating relations, ignoring anything else.  /**
12084   * This works with Pass2ProcessPendingInstances AND      This just handles instantiating relations, ignoring anything else.
12085   * Pass2ProcessPendingInstancesAnon, both of which are required to      This works with Pass2ProcessPendingInstances AND
12086   * maintain a correct compilation.      Pass2ProcessPendingInstancesAnon, both of which are required to
12087   * No recursion. No reallocation of result.      maintain a correct compilation.
12088   */      No recursion. No reallocation of result.
12089    */
12090  #define ANONFORCE 0 /* require anonymous type use, even if whining OTHERWISE */  #define ANONFORCE 0 /* require anonymous type use, even if whining OTHERWISE */
12091  static  static
12092  struct Instance *Pass2InstantiateModel(struct Instance *result,  struct Instance *Pass2InstantiateModel(struct Instance *result,
# Line 12104  void Pass2SetRelationBits(struct Instanc Line 12189  void Pass2SetRelationBits(struct Instanc
12189  }  }
12190    
12191    
12192  /* This just handles instantiating models and reinstantiating models/arrays,  /**
12193   * ignoring defaults and relations.      This just handles instantiating models and reinstantiating models/arrays,
12194   * This works with Pass1ProcessPendingInstances.      ignoring defaults and relations.
12195   * This is not a recursive function.      This works with Pass1ProcessPendingInstances.
12196   * Either def should be null or oldresult should null.      This is not a recursive function.
12197   * If def is null, it is a reinstantiation, else result will be created.      Either def should be null or oldresult should null.
12198   */      If def is null, it is a reinstantiation, else result will be created.
12199    */
12200  static  static
12201  struct Instance *Pass1InstantiateModel(struct TypeDescription *def,  struct Instance *Pass1InstantiateModel(struct TypeDescription *def,
12202                                         unsigned long *pcount,                                         unsigned long *pcount,
# Line 12171  struct Instance *Pass1InstantiateModel(s Line 12257  struct Instance *Pass1InstantiateModel(s
12257    return result;    return result;
12258  }  }
12259    
12260  /*  /**
12261   * we have to introduce a new head to instantiatemodel to manage      we have to introduce a new head to instantiatemodel to manage
12262   * the phases.      the phases.
12263   * 5 phases: model creation, relation creation,      5 phases: model creation, relation creation,
12264   * logical relation creation, when creation,      logical relation creation, when creation,
12265   * defaulting.      defaulting.
12266   * BAA      BAA
12267   * each pass is responsible for clearing the pending list it leaves.      each pass is responsible for clearing the pending list it leaves.
12268   */  */
12269  static  static
12270  struct Instance *NewInstantiateModel(struct TypeDescription *def)  struct Instance *NewInstantiateModel(struct TypeDescription *def)
12271  {  {
# Line 12308  struct Instance *NewInstantiateModel(str Line 12394  struct Instance *NewInstantiateModel(str
12394    
12395    
12396    
12397  /* returns 1 if the type is uninstantiable as a sim or 0 other wise */  /**
12398        @return 1 if the type is uninstantiable as a sim or 0 otherwise
12399    */
12400  static  static
12401  int ValidRealInstantiateType(struct TypeDescription *def)  int ValidRealInstantiateType(struct TypeDescription *def)
12402  {  {
# Line 12347  int ValidRealInstantiateType(struct Type Line 12435  int ValidRealInstantiateType(struct Type
12435    }    }
12436  }  }
12437    
12438  /* this function not recursive */  /**
12439        this function not recursive
12440    */
12441  static  static
12442  struct Instance *NewRealInstantiate(struct TypeDescription *def,  struct Instance *NewRealInstantiate(struct TypeDescription *def,
12443                                   int intset)                                   int intset)
# Line 12405  void ExecDefMethod(struct Instance *root Line 12495  void ExecDefMethod(struct Instance *root
12495    }    }
12496  }  }
12497    
 /*  
  */  
12498  struct Instance *NewInstantiate(symchar *type, symchar *name, int intset,  struct Instance *NewInstantiate(symchar *type, symchar *name, int intset,
12499                                  symchar *defmethod)                                  symchar *defmethod)
12500  {  {
# Line 12498  void AddIncompleteInst(struct Instance * Line 12586  void AddIncompleteInst(struct Instance *
12586    }    }
12587  }  }
12588    
12589  /*  /**
12590   * On entry it is assumed that the instance i has already been      On entry it is assumed that the instance i has already been
12591   * refined and so will not MOVE during subsequent work.      refined and so will not MOVE during subsequent work.
12592   * The process here must be kept in sync with NewRealInstantiateModel,      The process here must be kept in sync with NewRealInstantiateModel,
12593   * but must, additionally, deal ok with array instances as input.      but must, additionally, deal ok with array instances as input.
12594   */  */
12595  void NewReInstantiate(struct Instance *i)  void NewReInstantiate(struct Instance *i)
12596  {  {
12597    struct Instance *result;    struct Instance *result;
# Line 12581  void NewReInstantiate(struct Instance *i Line 12669  void NewReInstantiate(struct Instance *i
12669    return;    return;
12670  }  }
12671    
12672  /*  /*------------------------------------------------------------------------------
12673   * Some supporting code for the new partial instantiation,      Some supporting code for the new (how new?) partial instantiation,
12674   * and encapsulation schemes.      and encapsulation schemes.
12675   */  */
12676    
12677  void SetInstantiationRelnFlags(unsigned int flag)  void SetInstantiationRelnFlags(unsigned int flag)
12678  {  {
# Line 12596  unsigned int GetInstantiationRelnFlags(v Line 12684  unsigned int GetInstantiationRelnFlags(v
12684    return g_instantiate_relns;    return g_instantiate_relns;
12685  }  }
12686    
12687  /*  /**
12688   * This is the version of instantiate to deal with with 'patched'      This is the version of instantiate to deal with with 'patched'
12689   * types. Here name is the name of the patch that is to be      types. Here name is the name of the patch that is to be
12690   * instantiated. We first find the 'original' type, instantiate it      instantiated. We first find the 'original' type, instantiate it
12691   * and then apply the patch. The things that are properly and fully      and then apply the patch. The things that are properly and fully
12692   * supported is external relations, which is the real reason that      supported is external relations, which is the real reason that
12693   * the patch was designed.      the patch was designed.
12694   */  */
   
   
12695  void UpdateInstance(struct Instance *root, /* the simulation root */  void UpdateInstance(struct Instance *root, /* the simulation root */
12696                      struct Instance *target,                      struct Instance *target,
12697                      CONST struct StatementList *slist)                      CONST struct StatementList *slist)
# Line 12656  void UpdateInstance(struct Instance *roo Line 12742  void UpdateInstance(struct Instance *roo
12742  }  }
12743    
12744    
12745  /*  /**
12746   * this function instantiates a thing of type name      this function instantiates a thing of type name
12747   * without doing relations.      without doing relations.
12748   * Relations are then hacked in from external places  
12749   * but OTHERWISE the object appears as a regular      Relations are then hacked in from external places
12750   * ascend object. (note HACKED is the right word.)      but OTHERWISE the object appears as a regular
12751   * This function is obsolete; bintoken.c and multiphase      ASCEND object. (note HACKED is the right word.)
12752   * instantiation make it irrelevant.  
12753   */      @DEPRECATED This function is obsolete; bintoken.c and multiphase
12754        instantiation make it irrelevant.
12755    */
12756  struct Instance *InstantiatePatch(symchar *patch,  struct Instance *InstantiatePatch(symchar *patch,
12757                                    symchar *name, int intset)                                    symchar *name, int intset)
12758  {  {

Legend:
Removed from v.706  
changed lines
  Added in v.707

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