/[ascend]/trunk/base/generic/packages/defaultall.c
ViewVC logotype

Diff of /trunk/base/generic/packages/defaultall.c

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

revision 1371 by johnpye, Thu Mar 1 06:04:21 2007 UTC revision 1372 by jpye, Fri Mar 30 11:01:20 2007 UTC
# Line 43  Line 43 
43  #include <compiler/watchpt.h>  #include <compiler/watchpt.h>
44  #include <compiler/initialize.h>  #include <compiler/initialize.h>
45    
46  /* #define DEFAULT_DEBUG */  #define DEFAULT_DEBUG
47    
48    /*------------------------------------------------------------------------------
49      visit child atoms of the current model (don't visit sub models) and set
50      to ATOM default values
51    */
52    
53    static int defaultself_visit_childatoms1(struct Instance *inst);
54    
55    int defaultself_visit_childatoms(struct Instance *root, struct gl_list_t *arglist, void *userdata){
56        /* arglist is a list of gllist of instances */
57        if (arglist == NULL ||
58            gl_length(arglist) == 0L ||
59            gl_length((struct gl_list_t *)gl_fetch(arglist,1)) != 1 ||
60            gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1) == NULL) {
61        return defaultself_visit_childatoms1(root);
62        }else{
63            return defaultself_visit_childatoms1(
64                (struct Instance *)gl_fetch( (struct gl_list_t *)gl_fetch(arglist,1),1 )
65            );
66        }
67    }
68    
69    
70  /**  /**
71      Find atom children in the present model and set them to their ATOM DEFAULT      Find atom children in the present model and set them to their ATOM DEFAULT
72      values.      values.
73  */  */
74  static  static
75  int Asc_DefaultSelf1(struct Instance *inst){  int defaultself_visit_childatoms1(struct Instance *inst){
76      int i,n;      int i,n;
77      struct Instance *c;      struct Instance *c;
78      struct TypeDescription *type;        struct TypeDescription *type;  
# Line 68  int Asc_DefaultSelf1(struct Instance *in Line 90  int Asc_DefaultSelf1(struct Instance *in
90          if(BaseTypeIsAtomic(type)){          if(BaseTypeIsAtomic(type)){
91              if(!AtomDefaulted(type))continue;              if(!AtomDefaulted(type))continue;
92              switch(GetBaseType(type)){              switch(GetBaseType(type)){
93                  case real_type: SetRealAtomValue(c, GetRealDefault(type), 0); break;                  case real_type:
94                        CONSOLE_DEBUG("Setting to atom default = %f",GetRealDefault(type));
95                        SetRealAtomValue(c, GetRealDefault(type), 0);
96                        break;
97                  case integer_type: SetIntegerAtomValue(c, GetIntDefault(type), 0); break;                  case integer_type: SetIntegerAtomValue(c, GetIntDefault(type), 0); break;
98                  case boolean_type: SetBooleanAtomValue(c, GetBoolDefault(type), 0); break;                  case boolean_type: SetBooleanAtomValue(c, GetBoolDefault(type), 0); break;
99                  case symbol_type: SetSymbolAtomValue(c, GetSymDefault(type)); break;                  case symbol_type: SetSymbolAtomValue(c, GetSymDefault(type)); break;
# Line 80  int Asc_DefaultSelf1(struct Instance *in Line 105  int Asc_DefaultSelf1(struct Instance *in
105  #endif  #endif
106          }else if(GetBaseType(type)==array_type){          }else if(GetBaseType(type)==array_type){
107              /* descend into arrays */              /* descend into arrays */
108              Asc_DefaultSelf1(c);              defaultself_visit_childatoms1(c);
109          }          }
110      }      }
111        CONSOLE_DEBUG("defaultself_visit_childatoms1 returning %d",0);
112      return 0;      return 0;
113  }  }
114    
115    /*------------------------------------------------------------------------------
116      visit submodels, running 'default_self' on each
117    */
118    
119  struct DefaultAll_data{  struct DefaultAll_data{
120      symchar *default_all;      symchar *method_name;
121  };  };
122    
123    static int defaultself_visit_submodels1(struct Instance *inst
124            , struct DefaultAll_data *data
125    );
126    
127    int defaultself_visit_submodels(struct Instance *root
128            , struct gl_list_t *arglist, void *userdata
129    ){
130        struct DefaultAll_data data;
131        data.method_name = AddSymbol("default_self");
132        
133        /* arglist is a list of gllist of instances */
134        if (arglist == NULL ||
135                gl_length(arglist) == 0L ||
136                gl_length((struct gl_list_t *)gl_fetch(arglist,1)) != 1 ||
137                gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1) == NULL) {
138            return defaultself_visit_submodels1(root,&data);
139        }else{
140            return defaultself_visit_submodels1(
141                (struct Instance *)gl_fetch( (struct gl_list_t *)gl_fetch(arglist,1),1 )
142                , &data
143            );
144        }
145    }
146    
147  /**  /**
148      Find child models in the present model and run their 'default_all' methods      Find child models in the present model and run their 'default_self' methods
149  */  */
150  static  static
151  int Asc_DefaultAll1(struct Instance *inst, struct DefaultAll_data *data){  int defaultself_visit_submodels1(struct Instance *inst
152            , struct DefaultAll_data *data
153    ){
154      int i, n, err = 0;      int i, n, err = 0;
155      struct Instance *c;      struct Instance *c;
156      struct TypeDescription *type;      struct TypeDescription *type;
# Line 112  int Asc_DefaultAll1(struct Instance *ins Line 168  int Asc_DefaultAll1(struct Instance *ins
168          type = InstanceTypeDesc(c);          type = InstanceTypeDesc(c);
169          if(model_type == GetBaseType(type)){          if(model_type == GetBaseType(type)){
170              /* run 'default_all' for all child models */              /* run 'default_all' for all child models */
171              method = FindMethod(type,data->default_all);              method = FindMethod(type,data->method_name);
172              if(method){              if(method){
173  #ifdef DEFAULT_DEBUG  #ifdef DEFAULT_DEBUG
174                  CONSOLE_DEBUG("Running default_all on '%s'",SCP(GetName(type)));                  CONSOLE_DEBUG("Running METHOD %s on '%s'",SCP(data->method_name),SCP(GetName(type)));
175  #endif  #endif
176                  pe = Initialize(c , CreateIdName(ProcName(method)), "__not_named__"                  CONSOLE_DEBUG("ENTERING INITIALISE CALL...");
177                    pe = Initialize(c , CreateIdName(ProcName(method))
178                        , SCP(data->method_name)
179                      ,ASCERR                      ,ASCERR
180                      ,0, NULL, NULL                      ,0, NULL, NULL
181                  );                  );
182                    CONSOLE_DEBUG("...BACK FROM INITIALISE CALL");
183                  if(pe!=Proc_all_ok)err += 1;                  if(pe!=Proc_all_ok)err += 1;
184              }else{              }else{
185  #ifdef DEFAULT_DEBUG  #ifdef DEFAULT_DEBUG
186                  CONSOLE_DEBUG("Recursing into array...");                  CONSOLE_DEBUG("Recursing into array...");
187  #endif  #endif
188                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"No 'default_all' found for type '%s'",SCP(GetName(type)));                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"No '%s' found for type '%s'",SCP(data->method_name),SCP(GetName(type)));
189                  return 1;                  return 1;
190              }              }
191          }else if(array_type == GetBaseType(type)){          }else if(array_type == GetBaseType(type)){
192              if(Asc_DefaultAll1(c,data))err += 1;              if(defaultself_visit_submodels1(c,data))err += 1;
193          }          }
194      }      }
195    
196        CONSOLE_DEBUG("defaultself_visit_submodels1 return ing %d",err);
197      return err;      return err;
198  }  }
199    
200  int Asc_DefaultSelf(struct Instance *root, struct gl_list_t *arglist, void *userdata){  #if 0
201    /* arglist is a list of gllist of instances */  /**
202    if (arglist == NULL ||      NOTE YET IMPLEMENTED: we need to be able to pass string constants to
203        gl_length(arglist) == 0L ||      methods, which I don't think is possible yet.
204        gl_length((struct gl_list_t *)gl_fetch(arglist,1)) != 1 ||  */
205        gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1) == NULL) {  int Asc_VisitSubmodels(struct Instance *root
206      return Asc_DefaultSelf1(root);          , struct gl_list_t *arglist, void *userdata
207    }else{  ){
     return Asc_DefaultSelf1((struct Instance *)gl_fetch( (struct gl_list_t *)gl_fetch(arglist,1),1 ));  
   }  
 }  
   
 int Asc_DefaultAll(struct Instance *root, struct gl_list_t *arglist, void *userdata){  
208      struct DefaultAll_data data;      struct DefaultAll_data data;
209      data.default_all = AddSymbol("default_all");      (void)userdata;
210        
211      /* arglist is a list of gllist of instances */      ERROR_REPORTER_HERE(ASC_USER_ERROR,"not implemented");      
212      if (arglist == NULL ||      return 1;
213              gl_length(arglist) == 0L ||      if (arglist == NULL
214              gl_length((struct gl_list_t *)gl_fetch(arglist,1)) != 1 ||              || gl_length(arglist) == 0L
215              gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1) == NULL) {              || gl_length((struct gl_list_t *)gl_fetch(arglist,1)) != 2
216          return Asc_DefaultAll1(root,&data);              || gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1) == NULL
217      }else{              || gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),2) == NULL
218          return Asc_DefaultAll1((struct Instance *)gl_fetch( (struct gl_list_t *)gl_fetch(arglist,1),1 )      ){
219              , &data          ERROR_REPORTER_HERE(ASC_USER_ERROR,"EXTERNAL visit_submodels(SELF,'methodname') called with bad argument list");
220          );          return 1;
221      }      }
222    
223        data.method_name = AddSymbol("default_all");
224        
225        return Asc_DefaultAll1(
226            (struct Instance *)gl_fetch( (struct gl_list_t *)gl_fetch(arglist,1),1 )
227            , &data
228        );
229  }  }
230    #endif

Legend:
Removed from v.1371  
changed lines
  Added in v.1372

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