/[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 1290 by johnpye, Thu Feb 22 14:08:25 2007 UTC revision 1291 by johnpye, Mon Feb 26 06:20:43 2007 UTC
# Line 23  Line 23 
23      by John Pye, 15 Feb 2007.      by John Pye, 15 Feb 2007.
24  */  */
25    
26    #include <packages/defaultall.h>
27    
28    #include <compiler/proc.h>
29    #include <compiler/name.h>
30    
31  #include <utilities/ascConfig.h>  #include <utilities/ascConfig.h>
32  #include <utilities/ascPrint.h>  #include <utilities/ascPrint.h>
33  #include <utilities/ascPanic.h>  #include <utilities/ascPanic.h>
34    
35    #include <compiler/instquery.h>
36  #include <compiler/child.h>  #include <compiler/child.h>
37  #include <compiler/type_desc.h>  #include <compiler/type_desc.h>
38  #include <compiler/symtab.h>  #include <compiler/symtab.h>
 #include <compiler/instquery.h>  
39  #include <compiler/atomvalue.h>  #include <compiler/atomvalue.h>
40  #include <compiler/visitinst.h>  #include <compiler/visitinst.h>
41  #include <compiler/parentchild.h>  #include <compiler/parentchild.h>
42  #include <compiler/library.h>  #include <compiler/library.h>
43  #include <packages/ascFreeAllVars.h>  #include <compiler/watchpt.h>
44    #include <compiler/initialize.h>
45    
46  /**  /**
47      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
# Line 72  int Asc_DefaultSelf1(struct Instance *in Line 78  int Asc_DefaultSelf1(struct Instance *in
78      return 0;      return 0;
79  }  }
80    
81  #if 0  struct DefaultAll_data{
82        symchar *default_all;
83    };
84    
85  /**  /**
86      Find child models in the present model and run their 'default_all' methods      Find child models in the present model and run their 'default_all' methods
87  */  */
88  static  static
89  void Asc_DefaultAll(struct Instance *inst){  int Asc_DefaultAll1(struct Instance *inst, struct DefaultAll_data *data){
90      int i, n;      int i, n, err = 0;
   
91      struct Instance *c;      struct Instance *c;
92      struct TypeDescription *type;      struct TypeDescription *type;
93        struct InitProcedure *method;
94        enum Proc_enum pe;
95    
96      type = InstanceTypeDesc(inst);      type = InstanceTypeDesc(inst);
97    
98      if(model_type == GetBaseType(type)){      /* loop through child atoms */
         if(0/*has a 'default' method...*/){  
             /* run the 'default' method */  
             return;  
         }  
     }  
   
     /* default any child atoms' values */  
99      n = NumberChildren(inst);      n = NumberChildren(inst);
100      for(i = 1; i <= n; ++i){      for(i = 1; i <= n; ++i){
101          c = InstanceChild(inst);          c = InstanceChild(inst,i);
102          type = InstanceTypeDesc(c);          type = InstanceTypeDesc(c);
103          if(BaseTypeIsAtomic(type)){          if(model_type == GetBaseType(type)){
104              if(!AtomDefaulted(type))continue;              /* run 'default_all' for all child models */
105              switch(GetBaseType(type)){              method = FindMethod(type,data->default_all);
106                  case real_type: SetRealAtomValue(c, GetRealDefault(type)); break;              if(method){
107                  case integer_type: SetIntAtomValue(c, GetIntDefault(type)); break;                  CONSOLE_DEBUG("Running default_all on '%s'",SCP(GetName(type)));
108                  case boolean_type: SetBooleanAtomValue(c, GetBoolDefault(type)); break;                  pe = Initialize(c , CreateIdName(ProcName(method)), "__not_named__"
109                  case symbol_type: SetSymbolAtomValue(c, GetSymDefault(type)); break;                      ,ASCERR
110                  case set_type: /* what is the mechanism for defaulting of sets? */                      ,0, NULL, NULL
111                  default: ASC_PANIC("invalid type");                  );
112                    if(pe!=Proc_all_ok)err += 1;
113                }else{
114                    CONSOLE_DEBUG("Recursing into array...");
115                    ERROR_REPORTER_HERE(ASC_PROG_ERR,"No 'default_all' found for type '%s'",SCP(GetName(type)));
116                    return 1;
117              }              }
118          }else if(BaseTypeIsCompound(type)){          }else if(array_type == GetBaseType(type)){
119              /* descend into MODELs, arrays and 'patches' (whatever they are) */              if(Asc_DefaultAll1(c,data))err += 1;
             Asc_RecursiveDefault(c);  
120          }          }
121      }      }
 }  
122    
123  int Asc_DefaultAllVars(struct Instance *root, struct gl_list_t *arglist, void *userdata){      return err;
     /* arglist is a list of gllist of instances */  
     if (arglist == NULL ||  
         gl_length(arglist) == 0L ||  
         gl_length((struct gl_list_t *)gl_fetch(arglist,1)) != 1 ||  
         gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1) == NULL  
     ){  
         /* run on the 'root' instance */  
         return Asc_RecursiveDefault(root);  
     } else {  
         /* take the first item from the first arglist */  
         return Asc_RecursiveDefault(  
             (struct Instance *)gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1)  
         );  
     }  
124  }  }
 #endif  
   
   
125    
126  int Asc_DefaultSelf(struct Instance *root, struct gl_list_t *arglist, void *userdata){  int Asc_DefaultSelf(struct Instance *root, struct gl_list_t *arglist, void *userdata){
127    /* arglist is a list of gllist of instances */    /* arglist is a list of gllist of instances */
# Line 145  int Asc_DefaultSelf(struct Instance *roo Line 134  int Asc_DefaultSelf(struct Instance *roo
134      return Asc_DefaultSelf1((struct Instance *)gl_fetch( (struct gl_list_t *)gl_fetch(arglist,1),1 ));      return Asc_DefaultSelf1((struct Instance *)gl_fetch( (struct gl_list_t *)gl_fetch(arglist,1),1 ));
135    }    }
136  }  }
137    
138    int Asc_DefaultAll(struct Instance *root, struct gl_list_t *arglist, void *userdata){
139        struct DefaultAll_data data;
140        data.default_all = AddSymbol("default_all");
141        
142        /* arglist is a list of gllist of instances */
143        if (arglist == NULL ||
144                gl_length(arglist) == 0L ||
145                gl_length((struct gl_list_t *)gl_fetch(arglist,1)) != 1 ||
146                gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1) == NULL) {
147            return Asc_DefaultAll1(root,&data);
148        }else{
149            return Asc_DefaultAll1((struct Instance *)gl_fetch( (struct gl_list_t *)gl_fetch(arglist,1),1 )
150                , &data
151            );
152        }
153    }

Legend:
Removed from v.1290  
changed lines
  Added in v.1291

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