Wild Life  2.30
 All Data Structures Files Functions Variables Typedefs Macros
arity.c
Go to the documentation of this file.
1 
7 #ifdef ARITY
8 
9 #include "defs.h"
10 
11 static int Aunif=0;
12 static int Amerge=0;
13 static int Aadd=0;
14 static int Atop=0;
15 static int Atoptop=0;
16 static int Auid=0;
17 static int Audiff=0;
18 static int Anil=0;
19 static int Anilnil=0;
20 static int Aident=0;
21 static int Adiff=0;
22 static int Aglb=0;
23 
29 void arity_init()
30 {
31  /*
32  features=fopen("features.log","w");
33  if(!features) {
34  Errorline("Couldn't open feature log file\n");
35  abort_life(TRUE); // djd added TRUE
36  }
37  */ // RECOMMENTED 2.16 DJD
38 }
39 
45 void arity_end()
46 {
47 
48  fclose(features);
49 
50  features=fopen("profile.log","w");
51  if(features) {
52  fprintf(features,"---- Unifications and Features ----\n\n");
53 
54  fprintf(features,"add feature: %d\n\n",Aadd);
55 
56  fprintf(features,"unify: %d\n",Aunif);
57  fprintf(features,"types:\n");
58  fprintf(features,"\ttop-top: %d = %3.1lf\n",PERUNIF(Atoptop));
59  fprintf(features,"\ttop-X: %d = %3.1lf\n",PERUNIF(Atop));
60  fprintf(features,"\tX-X: %d = %3.1lf\n",PERUNIF(Auid));
61  fprintf(features,"\tX-Y: %d = %3.1lf\n",PERUNIF(Audiff));
62  fprintf(features,"\tGLB: %d = %3.1lf\n",PERUNIF(Aglb));
63 
64  fprintf(features,"merges: %d = %3.1lf\n",PERUNIF(Amerge));
65 
66  fprintf(features,"\tnil-nil: %d = %3.1lf\n",PERMERGE(Anilnil));
67  fprintf(features,"\tnil-X: %d = %3.1lf\n",PERMERGE(Anil));
68  fprintf(features,"\tX-X: %d = %3.1lf\n",PERMERGE(Aident));
69  fprintf(features,"\tX-Y: %d = %3.1lf\n",PERMERGE(Adiff));
70 
71  fclose(features);
72  }
73 }
74 
81 void rec_print_feat(ptr_node n)
82 {
83  if(n) {
84  if(n->left) {
85  rec_print_feat(n->left);
86  fprintf(features,",");
87  }
88 
89  fprintf(features,n->key);
90 
91  if(n->right) {
92  fprintf(features,",");
93  rec_print_feat(n->right);
94  }
95  }
96 }
97 
104 void print_features(ptr_node u)
105 {
106  fprintf(features,"(");
107  rec_print_feat(u);
108  fprintf(features,")");
109 }
110 
118 int check_equal(ptr_node u,ptr_node v)
119 {
120  int same=TRUE;
121 
122  if(u) {
123  same=check_equal(u->left,v) &&
124  find(FEATCMP,u->key,v) &&
125  check_equal(u->right,v);
126  }
127 
128  return same;
129 }
130 
138 void arity_unify(ptr_psi_term u,ptr_psi_term v)
139 {
140  Aunif++;
141 
142  if(u->type==top)
143  if(v->type==top)
144  Atoptop++;
145  else
146  Atop++;
147  else
148  if(v->type==top)
149  Atop++;
150  else
151  if(u->type==v->type)
152  Auid++;
153  else
154  if(u->type->children || v->type->children)
155  Aglb++;
156  else
157  Audiff++;
158 
159  /*
160  fprintf(features,
161  "unify: %s %s\n",
162  u->type->keyword->symbol,
163  v->type->keyword->symbol);
164  */
165 }
166 
174 void arity_merge(ptr_node u,ptr_node v)
175 {
176  Amerge++;
177 
178  if(u)
179  if(v)
180  if(check_equal(u,v))
181  Aident++;
182  else
183  Adiff++;
184  else
185  Anil++;
186  else
187  if(v)
188  Anil++;
189  else
190  Anilnil++;
191 
192  /*
193  fprintf(features,"merge: ");
194  print_features(u);
195  fprintf(features," ");
196  print_features(v);
197  fprintf(features,"\n");
198  */
199 }
200 
208 void arity_add(ptr_psi_term u,char *s)
209 {
210  Aadd++;
211 
212  /*
213  fprintf(features,"add %s to %s",s,u->type->keyword->symbol);
214  print_features(u->attr_list);
215  fprintf(features,"\n");
216  */
217 }
218 
219 #endif
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
includes
ptr_node left
Definition: def_struct.h:199
char * key
Definition: def_struct.h:198
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
ptr_definition top
symbol in syntax module
Definition: def_glob.h:403
FILE * features
Definition: def_glob.h:883
#define PERUNIF(X)
Definition: def_macro.h:273
#define PERMERGE(X)
Definition: def_macro.h:274
ptr_definition type
Definition: def_struct.h:181
ptr_int_list children
Definition: def_struct.h:152
ptr_node right
Definition: def_struct.h:200