/[ascend]/trunk/ascend/compiler/initialize.c
ViewVC logotype

Diff of /trunk/ascend/compiler/initialize.c

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

revision 2218 by jpye, Tue May 4 13:38:42 2010 UTC revision 2219 by jpye, Tue Jul 20 13:03:40 2010 UTC
# Line 243  void ExecuteInitRun(struct procFrame *fm Line 243  void ExecuteInitRun(struct procFrame *fm
243  */  */
244  static void  static void
245  execute_init_fix_or_free(int val, struct procFrame *fm, struct Statement *stat){  execute_init_fix_or_free(int val, struct procFrame *fm, struct Statement *stat){
246    CONST struct VariableList *vars;      CONST struct VariableList *vars;
247    enum find_errors e;      enum find_errors e;
248    struct gl_list_t *temp;      struct gl_list_t *temp;
249    unsigned i, len;      unsigned i, len;
250    struct Instance *i1, *i2;      struct Instance *i1, *i2;
251    char *instname;      //char *instname;
252    struct TypeDescription *t, *st;      struct TypeDescription *t, *st;
253    CONST struct Name *name;      CONST struct Name *name;
254    symchar *fixed;      symchar *fixed;
255    /* setup */      /* setup */
256    fixed = AddSymbol("fixed");      fixed = AddSymbol("fixed");
257    st = FindType(AddSymbol("solver_var"));      st = FindType(AddSymbol("solver_var"));
258    if(st==NULL){      if(st==NULL){
259      ERROR_REPORTER_HERE(ASC_PROG_ERR,"'solver_var' type is not yet in library");          ERROR_REPORTER_HERE(ASC_PROG_ERR,"'solver_var' type is not yet in library");
260      fm->ErrNo = Proc_type_not_found;          fm->ErrNo = Proc_type_not_found;
261      return;          return;
262    }      }
263    
264    /* iterate through the variable list */  #ifdef FIXFREE_DEBUG
265    /*CONSOLE_DEBUG("STARTING 'FIX'/'FREE' STATEMENT EXECUTION");*/      CONSOLE_DEBUG("STARTING 'FIX'/'FREE' EXECUTION...");
266    vars = stat->v.fx.vars;      WriteStatement(ASCERR,stat,4);
267    while(vars!=NULL){  #endif
     name = NamePointer(vars);  
     temp = FindInstances(fm->i, name, &e);  
     if(temp==NULL){  
       fm->ErrNo = Proc_bad_name;  
       return;  
     }  
     len = gl_length(temp);  
     for(i=1; i<=len; i++){  
         i1 = (struct Instance *)gl_fetch(temp,i);  
     instname = WriteInstanceNameString(i1,NULL);  
     /*if(val){  
         CONSOLE_DEBUG("ABOUT TO FIX %s",instname);  
     }else{  
         CONSOLE_DEBUG("ABOUT TO FREE %s",instname);  
     }*/  
     ascfree(instname);  
     gl_destroy(temp);  
268    
269      if(InstanceKind(i1)!=REAL_ATOM_INST){      /* iterate through the variable list */
270        fm->ErrNo = Proc_illegal_type_use;      vars = stat->v.fx.vars;
271        ProcWriteFixError(fm,name);      while(vars!=NULL){
272        return;          name = NamePointer(vars);
273      }          temp = FindInstances(fm->i, name, &e);
274      t = InstanceTypeDesc(i1);          if(temp==NULL){
275      if(!MoreRefined(t,st)){              fm->ErrNo = Proc_bad_name;
276        CONSOLE_DEBUG("Attempted to FIX or FREE variable that is not a refined solver_var.");              return;
277        fm->ErrNo = Proc_illegal_type_use;          }
278        ProcWriteFixError(fm,name);          len = gl_length(temp);
279        return;          for(i=1; i<=len; i++){
280      }              i1 = (struct Instance *)gl_fetch(temp,i);
281      i2 = ChildByChar(i1,fixed);  #ifdef FIXFREE_DEBUG
282      if(i2==NULL){              instname = WriteInstanceNameString(i1,NULL);
283        CONSOLE_DEBUG("Attempted to FIX or FREE a solver_var that doesn't have a 'fixed' child!");              if(val){
284        fm->ErrNo = Proc_illegal_type_use;                  CONSOLE_DEBUG("ABOUT TO FIX %s",instname);
285        ProcWriteFixError(fm,name);              }else{
286        return;                  CONSOLE_DEBUG("ABOUT TO FREE %s",instname);
287      }              }
288      if(InstanceKind(i2)!=BOOLEAN_INST){              ascfree(instname);
289        CONSOLE_DEBUG("Attempted to FIX or FREE a solver_var whose 'fixed' child is not boolean!");  #endif
290        fm->ErrNo = Proc_illegal_type_use;              if(InstanceKind(i1)!=REAL_ATOM_INST){
291        ProcWriteFixError(fm,name);                  fm->ErrNo = Proc_illegal_type_use;
292        return;                  ProcWriteFixError(fm,name);
293                    return;
294                }
295                t = InstanceTypeDesc(i1);
296                if(!MoreRefined(t,st)){
297                    CONSOLE_DEBUG("Attempted to FIX or FREE variable that is not a refined solver_var.");
298                    fm->ErrNo = Proc_illegal_type_use;
299                    ProcWriteFixError(fm,name);
300                    return;
301                }
302                i2 = ChildByChar(i1,fixed);
303                if(i2==NULL){
304                    CONSOLE_DEBUG("Attempted to FIX or FREE a solver_var that doesn't have a 'fixed' child!");
305                    fm->ErrNo = Proc_illegal_type_use;
306                    ProcWriteFixError(fm,name);
307                    return;
308                }
309                if(InstanceKind(i2)!=BOOLEAN_INST){
310                    CONSOLE_DEBUG("Attempted to FIX or FREE a solver_var whose 'fixed' child is not boolean!");
311                    fm->ErrNo = Proc_illegal_type_use;
312                    ProcWriteFixError(fm,name);
313                    return;
314                }
315                SetBooleanAtomValue(i2,val,0);
316            }
317            gl_destroy(temp);
318            vars = NextVariableNode(vars);
319      }      }
320      SetBooleanAtomValue(i2,val,0);      /* CONSOLE_DEBUG("DONE WITH VARLIST"); */
     }  
     vars = NextVariableNode(vars);  
   }  
   /* CONSOLE_DEBUG("DONE WITH VARLIST"); */  
321    
322    /* return 'ok' */      /* return 'ok' */
323    fm->ErrNo = Proc_all_ok;      fm->ErrNo = Proc_all_ok;
324  }  }
325    
326  static void  static void

Legend:
Removed from v.2218  
changed lines
  Added in v.2219

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