60 |
on list (else returned list will be NULL) and return the collected instances. |
on list (else returned list will be NULL) and return the collected instances. |
61 |
DS: it returns a non-flattened list of the instances |
DS: it returns a non-flattened list of the instances |
62 |
*/ |
*/ |
63 |
|
static struct gl_list_t *FindInstsNonFlat( |
64 |
|
struct Instance *inst,CONST struct VariableList *list,enum find_errors *err |
65 |
static |
){ |
|
struct gl_list_t *FindInstsNonFlat(struct Instance *inst, |
|
|
CONST struct VariableList *list, |
|
|
enum find_errors *err) |
|
|
{ |
|
66 |
struct gl_list_t *result,*temp; |
struct gl_list_t *result,*temp; |
67 |
|
|
68 |
result = gl_create(AVG_LINKS_INST); |
result = gl_create(AVG_LINKS_INST); |
83 |
on list (else returned list will be NULL) and return the collected instances. |
on list (else returned list will be NULL) and return the collected instances. |
84 |
DS: it returns a flattened list of the instances |
DS: it returns a flattened list of the instances |
85 |
*/ |
*/ |
86 |
|
static struct gl_list_t *FindInsts( |
87 |
static |
struct Instance *inst, CONST struct VariableList *list, enum find_errors *err |
88 |
struct gl_list_t *FindInsts(struct Instance *inst, |
){ |
|
CONST struct VariableList *list, |
|
|
enum find_errors *err) |
|
|
{ |
|
89 |
struct gl_list_t *result,*temp; |
struct gl_list_t *result,*temp; |
90 |
unsigned c,len; |
unsigned c,len; |
91 |
result = gl_create(AVG_LINKS_INST); |
result = gl_create(AVG_LINKS_INST); |
107 |
|
|
108 |
|
|
109 |
/** |
/** |
110 |
* DS: Helper function that compares a key and a list of instances with a link_entry |
DS: Helper function that compares a key and a list of instances with a link_entry |
111 |
If the tuple (key, instances) is the same as the link entry returns 0, |
@return 0 if the tuple (key, instances) is the same as the link entry, |
112 |
otherwise return 1. |
otherwise return 1. |
113 |
*/ |
*/ |
114 |
static int CmpLinkEntry(symchar *key, struct VariableList *vlist,struct link_entry_t *linkEntry) |
static int CmpLinkEntry(symchar *key, struct VariableList *vlist,struct link_entry_t *linkEntry){ |
115 |
{ |
/* DS: Note: the key_cache and the u.vl were used instead of |
116 |
/* DS: Note: the key_cache and the u.vl were used instead of LINKStatKey(linkEntry->u.statptr) and LINKStatVlist(linkEntry->u.statptr), because for some reason the pointer to the statement becomes NULL after the statement is executed */ |
LINKStatKey(linkEntry->u.statptr) and LINKStatVlist(linkEntry->u.statptr), |
117 |
|
because for some reason the pointer to the statement becomes NULL after the |
118 |
|
statement is executed */ |
119 |
|
|
120 |
struct VariableList *linkEntry_vlist; |
struct VariableList *linkEntry_vlist; |
121 |
|
|
122 |
if(CmpSymchar(key,linkEntry->key_cache) != 0) { /* if the keys are different, the LINKs are different */ |
if(CmpSymchar(key,linkEntry->key_cache) != 0) { |
123 |
|
/* if the keys are different, the LINKs are different */ |
124 |
return 1; |
return 1; |
125 |
} |
} |
126 |
|
|
127 |
linkEntry_vlist = linkEntry->u.vl; |
linkEntry_vlist = linkEntry->u.vl; |
128 |
if(VariableListLength(vlist) != VariableListLength(linkEntry_vlist)) { /* if the number of variables linked are different, the LINKs are different */ |
if(VariableListLength(vlist) != VariableListLength(linkEntry_vlist)) { |
129 |
|
/* if the number of variables linked are different, the LINKs are different */ |
130 |
return 1; |
return 1; |
131 |
} |
} |
132 |
|
|
133 |
if(CompareVariableLists(vlist,linkEntry_vlist) != 0) { /* if the variables linked are different, the LINKs are different */ |
if(CompareVariableLists(vlist,linkEntry_vlist) != 0) { /* if the variables linked are different, the LINKs are different */ |
134 |
return 1; /* DS Note: it is ordered biased */ |
return 1; /* DS Note: it is ordered biased */ |
135 |
} |
} |
136 |
|
|
137 |
return 0; /* (key, instances) is the same as linkEntry */ |
return 0; /* (key, instances) is the same as linkEntry */ |
138 |
} |
} |
139 |
|
|
140 |
|
|
142 |
{ |
{ |
143 |
struct TypeDescription *modelType; |
struct TypeDescription *modelType; |
144 |
struct link_entry_t *link_entry; |
struct link_entry_t *link_entry; |
145 |
symchar *key, *key_result; |
symchar *key, *key_result; |
146 |
int c1, c2, len_table, len_result, existent; |
int c1, c2, len_table, len_result, existent; |
147 |
|
|
148 |
modelType = InstanceTypeDesc(model); |
modelType = InstanceTypeDesc(model); |
149 |
if(modelType->t == model_type) { |
if(modelType->t == model_type) { |
150 |
// probe instance given (if appropriate kind) to get link info needed from the TypeDescription link_table |
|
151 |
|
/* probe instance given (if appropriate kind) to get link info needed |
152 |
|
from the TypeDescription link_table */ |
153 |
len_table = gl_length(modelType->u.modarg.link_table); |
len_table = gl_length(modelType->u.modarg.link_table); |
154 |
|
|
155 |
for(c1=1;c1<=len_table;c1++){ |
for(c1=1;c1<=len_table;c1++){ |
156 |
link_entry = (struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,c1); |
link_entry = (struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,c1); |
157 |
if(link_entry->key_cache == NULL){ /**< in case the cache is empty we need to find keys from the statements */ |
if(link_entry->key_cache == NULL){ /**< in case the cache is empty we need to find keys from the statements */ |
158 |
key = LINKStatKey(link_entry->u.statptr); |
key = LINKStatKey(link_entry->u.statptr); |
159 |
}else { |
}else{ |
160 |
key = link_entry->key_cache; |
key = link_entry->key_cache; |
161 |
} |
} |
162 |
// verify that any new info obtained is kept uniquely in the result list.(not efficient at all DS TODO) |
// verify that any new info obtained is kept uniquely in the result list.(not efficient at all DS TODO) |
173 |
} |
} |
174 |
} |
} |
175 |
|
|
176 |
// probe instance given (if appropriate kind) to get link info needed from the ModelInstances link_table |
/* probe instance given (if appropriate kind) to get link info needed |
177 |
|
from the ModelInstances link_table */ |
178 |
len_table = gl_length(MOD_INST(model)->link_table); |
len_table = gl_length(MOD_INST(model)->link_table); |
179 |
for(c1=1;c1<=len_table;c1++){ |
for(c1=1;c1<=len_table;c1++){ |
180 |
link_entry = (struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,c1); |
link_entry = (struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,c1); |
181 |
if(link_entry->key_cache == NULL){ /**< in case the cache is empty we need to find keys from the statements */ |
if(link_entry->key_cache == NULL){ /**< in case the cache is empty we need to find keys from the statements */ |
182 |
key = LINKStatKey(link_entry->u.statptr); |
key = LINKStatKey(link_entry->u.statptr); |
183 |
}else { |
}else{ |
184 |
key = link_entry->key_cache; |
key = link_entry->key_cache; |
185 |
} |
} |
186 |
// verify that any new info obtained is kept uniquely in the result list.(not efficient at all DS TODO) |
/* verify that any new info obtained is kept uniquely in the result |
187 |
|
list.(not efficient at all DS TODO) */ |
188 |
len_result = gl_length(result); |
len_result = gl_length(result); |
189 |
existent = 0; |
existent = 0; |
190 |
for(c2=1;c2<=len_result;c2++){ |
for(c2=1;c2<=len_result;c2++){ |
198 |
} |
} |
199 |
} |
} |
200 |
} |
} |
201 |
/*DS:If the instance or the child instance is not a model we do nothing since a "link_table" is only present in the typedescription of a model (modarg) */ |
/*DS:If the instance or the child instance is not a model we do nothing |
202 |
|
since a "link_table" is only present in the typedescription of a model (modarg) */ |
203 |
} |
} |
204 |
|
|
205 |
|
|
206 |
/** find all the keys in link table(s), optionally recursive. */ |
/** find all the keys in link table(s), optionally recursive. */ |
207 |
extern struct gl_list_t *getLinkTypes (struct Instance *model, int recursive) |
extern struct gl_list_t *getLinkTypes (struct Instance *model, int recursive){ |
|
{ |
|
208 |
struct gl_list_t *result = gl_create(AVG_LINKS); |
struct gl_list_t *result = gl_create(AVG_LINKS); |
209 |
|
|
210 |
if (recursive) { |
if (recursive) { |
211 |
VisitInstanceTreeTwo(model, (VisitTwoProc)CollectLinkTypes, 0,0, result); |
VisitInstanceTreeTwo(model, (VisitTwoProc)CollectLinkTypes, 0,0, result); |
212 |
} else { |
}else{ |
213 |
CollectLinkTypes(model, result); |
CollectLinkTypes(model, result); |
214 |
} |
} |
215 |
|
return result; |
|
return result; |
|
216 |
} |
} |
217 |
|
|
218 |
|
|
219 |
void CollectLinks(struct Instance *model, struct gl_list_t *result) |
void CollectLinks(struct Instance *model, struct gl_list_t *result){ |
|
{ |
|
220 |
struct TypeDescription *modelType; |
struct TypeDescription *modelType; |
221 |
struct link_entry_t *link_entry, *link_entry_result; |
struct link_entry_t *link_entry, *link_entry_result; |
222 |
int c1, c2, len_table, len_result, existent; |
int c1, c2, len_table, len_result, existent; |
223 |
|
|
224 |
modelType = InstanceTypeDesc(model); |
modelType = InstanceTypeDesc(model); |
225 |
if(modelType->t == model_type) { |
if(modelType->t == model_type) { |
226 |
// probe instance given (if appropriate kind) to get link info needed from the TypeDescription link_table |
|
227 |
|
/* probe instance given (if appropriate kind) to get link info needed |
228 |
|
from the TypeDescription link_table */ |
229 |
len_table = gl_length(modelType->u.modarg.link_table); |
len_table = gl_length(modelType->u.modarg.link_table); |
230 |
for(c1=1;c1<=len_table;c1++){ |
for(c1=1;c1<=len_table;c1++){ |
231 |
link_entry = (struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,c1); |
link_entry = (struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,c1); |
240 |
} |
} |
241 |
} |
} |
242 |
if(!existent){ |
if(!existent){ |
243 |
gl_append_ptr(result,(VOIDPTR)link_entry); |
gl_append_ptr(result,(VOIDPTR)link_entry); |
244 |
} |
} |
245 |
} |
} |
246 |
|
|
247 |
// probe instance given (if appropriate kind) to get link info needed from the ModelInstance link_table |
/* probe instance given (if appropriate kind) to get link info needed |
248 |
|
from the ModelInstance link_table */ |
249 |
len_table = gl_length(MOD_INST(model)->link_table); |
len_table = gl_length(MOD_INST(model)->link_table); |
250 |
for(c1=1;c1<=len_table;c1++){ |
for(c1=1;c1<=len_table;c1++){ |
251 |
link_entry = (struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,c1); |
link_entry = (struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,c1); |
260 |
} |
} |
261 |
} |
} |
262 |
if(!existent){ |
if(!existent){ |
263 |
gl_append_ptr(result,(VOIDPTR)link_entry); |
gl_append_ptr(result,(VOIDPTR)link_entry); |
264 |
} |
} |
265 |
} |
} |
266 |
} |
} |
267 |
/*DS:If the instance or the child instance is not a model we do nothing since a "link_table" is only present in the typedescription of a model (modarg) */ |
/*DS:If the instance or the child instance is not a model we do nothing since |
268 |
|
a "link_table" is only present in the typedescription of a model (modarg) */ |
269 |
} |
} |
270 |
|
|
271 |
|
|
272 |
extern struct gl_list_t *getLinks(struct Instance *model, symchar *target_key, int recursive) |
extern struct gl_list_t *getLinks(struct Instance *model |
273 |
{ |
, symchar *target_key, int recursive |
274 |
|
){ |
275 |
struct gl_list_t *result = gl_create(AVG_LINKS); /**< DS: hardcoded for now but will eventually be a constant */ |
struct gl_list_t *result = gl_create(AVG_LINKS); /**< DS: hardcoded for now but will eventually be a constant */ |
276 |
int c1, len_result; |
int c1, len_result; |
277 |
struct link_entry_t *link_entry; |
struct link_entry_t *link_entry; |
278 |
if (recursive) { |
|
279 |
VisitInstanceTreeTwo(model, (VisitTwoProc)CollectLinks, 0,0, result); |
if(recursive){ |
280 |
} else { |
VisitInstanceTreeTwo(model, (VisitTwoProc)CollectLinks, 0,0, result); |
281 |
CollectLinks(model, result); |
}else{ |
282 |
} |
CollectLinks(model, result); |
283 |
|
} |
284 |
|
|
285 |
len_result = gl_length(result); |
len_result = gl_length(result); |
286 |
|
|
291 |
len_result--; |
len_result--; |
292 |
} |
} |
293 |
} |
} |
294 |
|
return result; |
|
return result; |
|
295 |
} |
} |
296 |
|
|
297 |
|
|
298 |
/**<DS: get all links matching key, optionally recursive. */ |
/**<DS: get all links matching key, optionally recursive. */ |
299 |
extern struct gl_list_t *getLinksReferencing (struct Instance *model, symchar* key, struct Instance *targetInstance, int recursive) |
extern struct gl_list_t *getLinksReferencing (struct Instance *model |
300 |
{ |
, symchar* key, struct Instance *targetInstance, int recursive |
301 |
|
){ |
302 |
struct gl_list_t *link_instances,*result = gl_create(AVG_LINKS); |
struct gl_list_t *link_instances,*result = gl_create(AVG_LINKS); |
303 |
struct link_entry_t *link_entry; |
struct link_entry_t *link_entry; |
304 |
struct Instance *inst; |
struct Instance *inst; |
305 |
enum find_errors err; |
enum find_errors err; |
306 |
int c1, c2, len_result, len_inst, containsInst; |
int c1, c2, len_result, len_inst, containsInst; |
307 |
|
|
308 |
|
if(recursive){ |
309 |
if (recursive) { |
VisitInstanceTreeTwo(model, (VisitTwoProc)CollectLinks, 0,0, result); |
310 |
VisitInstanceTreeTwo(model, (VisitTwoProc)CollectLinks, 0,0, result); |
}else{ |
311 |
} else { |
CollectLinks(model, result); |
312 |
CollectLinks(model, result); |
} |
|
} |
|
313 |
|
|
314 |
/* DS: get all the links that contain the target instance */ |
/* DS: get all the links that contain the target instance */ |
315 |
len_result = gl_length(result); |
len_result = gl_length(result); |
316 |
for(c1=1;c1<=len_result;c1++){ |
for(c1=1;c1<=len_result;c1++){ |
317 |
link_entry = (struct link_entry_t *)gl_fetch(result,c1); |
link_entry = (struct link_entry_t *)gl_fetch(result,c1); |
318 |
if(link_entry->instances_cache == NULL ) { |
if(link_entry->instances_cache == NULL ) { |
319 |
link_instances = FindInsts(model,link_entry->u.vl,&err); |
link_instances = FindInsts(model,link_entry->u.vl,&err); |
320 |
} else { |
}else{ |
321 |
link_instances = link_entry->instances_cache; |
link_instances = link_entry->instances_cache; |
322 |
} |
} |
323 |
|
|
324 |
len_inst = gl_length(link_instances); |
len_inst = gl_length(link_instances); |
325 |
containsInst = 0; |
containsInst = 0; |
326 |
if(CmpSymchar(link_entry->key_cache,key) == 0){ |
if(CmpSymchar(link_entry->key_cache,key) == 0){ |
329 |
if(inst == targetInstance){ |
if(inst == targetInstance){ |
330 |
containsInst = 1; |
containsInst = 1; |
331 |
} |
} |
332 |
} |
} |
333 |
} |
} |
334 |
if(!containsInst){ |
if(!containsInst){ |
335 |
gl_delete(result,c1,0); /* if the link entry does not have sought key we delete it from the result list */ |
gl_delete(result,c1,0); /* if the link entry does not have sought key we delete it from the result list */ |
336 |
len_result--; |
len_result--; |
337 |
} |
} |
338 |
} |
} |
|
|
|
|
|
|
|
|
|
339 |
return result; |
return result; |
340 |
} |
} |
341 |
|
|
342 |
/*DS: called by the ASCEND LINK command, both in the declarative and the non-declarative section */ |
/** DS: called by the ASCEND LINK command, both in the declarative and the non-declarative section */ |
343 |
extern void addLinkEntry(struct Instance *model, symchar *key, struct gl_list_t *instances, struct Statement *stat, unsigned int declarative) |
extern void addLinkEntry(struct Instance *model, symchar *key |
344 |
{ |
, struct gl_list_t *instances, struct Statement *stat, unsigned int declarative |
345 |
|
){ |
346 |
struct TypeDescription *modelType; |
struct TypeDescription *modelType; |
347 |
struct link_entry_t *link_entry, *old_link_entry; |
struct link_entry_t *link_entry, *old_link_entry; |
348 |
struct for_var_t *ptr; |
struct for_var_t *ptr; |
349 |
int c,len,exist = 0; |
int c,len,exist = 0; |
350 |
|
|
351 |
if(strcmp("TestingRoutine",SCP(key)) == 0) { |
if(strcmp("TestingRoutine",SCP(key)) == 0) { |
353 |
return; |
return; |
354 |
} |
} |
355 |
|
|
356 |
/* in case the LINK key is in fact the index of a for loop, the value of the index at the current iteration is turned into a symchar and stored as a key*/ |
/* in case the LINK key is in fact the index of a for loop, the value of the |
357 |
|
index at the current iteration is turned into a symchar and stored as a key*/ |
358 |
if(GetEvaluationForTable() && (ptr = FindForVar((struct gl_list_t *)GetEvaluationForTable(),key)) != NULL) { |
if(GetEvaluationForTable() && (ptr = FindForVar((struct gl_list_t *)GetEvaluationForTable(),key)) != NULL) { |
359 |
char index_key[10]; |
char index_key[10]; |
360 |
sprintf(index_key,"%ld",GetForInteger(ptr)); |
sprintf(index_key,"%ld",GetForInteger(ptr)); |
386 |
gl_append_ptr(MOD_INST(model)->link_table,(VOIDPTR)link_entry); |
gl_append_ptr(MOD_INST(model)->link_table,(VOIDPTR)link_entry); |
387 |
printf("\n non-declarative LINK no of instances in cache: %ld \n", gl_length(link_entry->instances_cache)); |
printf("\n non-declarative LINK no of instances in cache: %ld \n", gl_length(link_entry->instances_cache)); |
388 |
printf("\n non-declarative LINK key %s \n", SCP(key)); |
printf("\n non-declarative LINK key %s \n", SCP(key)); |
389 |
} |
}else{ |
|
else{ |
|
390 |
ERROR_REPORTER_HERE(ASC_USER_WARNING,"The LINK entry to-be added is already present in the non-declarative LINK table."); |
ERROR_REPORTER_HERE(ASC_USER_WARNING,"The LINK entry to-be added is already present in the non-declarative LINK table."); |
391 |
} |
} |
392 |
} |
}else{ |
|
else { |
|
393 |
if(link_entry->link_type == link_ignore) { |
if(link_entry->link_type == link_ignore) { |
394 |
ignoreDeclLinkEntry(model,key,LINKStatVlist(stat)); |
ignoreDeclLinkEntry(model,key,LINKStatVlist(stat)); |
395 |
} |
}else { |
|
else { |
|
396 |
modelType = InstanceTypeDesc(model); |
modelType = InstanceTypeDesc(model); |
397 |
len = gl_length(modelType->u.modarg.link_table); |
len = gl_length(modelType->u.modarg.link_table); |
398 |
|
|
399 |
for(c=1;c<=len;c++){ |
for(c=1;c<=len;c++){ |
400 |
old_link_entry = (struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,c); |
old_link_entry = (struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,c); |
401 |
if(CmpLinkEntry(key,LINKStatVlist(stat),old_link_entry) == 0){ |
if(CmpLinkEntry(key,LINKStatVlist(stat),old_link_entry) == 0){ |
402 |
exist = 1; |
exist = 1; |
403 |
} |
} |
419 |
/* DS: testing purposes: */ |
/* DS: testing purposes: */ |
420 |
printf("\n declarative LINK no of instances in cache: %ld \n", gl_length(link_entry->instances_cache)); |
printf("\n declarative LINK no of instances in cache: %ld \n", gl_length(link_entry->instances_cache)); |
421 |
printf("\n declarative LINK key %s \n", SCP(key)); |
printf("\n declarative LINK key %s \n", SCP(key)); |
422 |
} |
}else{ |
423 |
else{ |
ERROR_REPORTER_HERE(ASC_USER_WARNING,"The LINK entry to-be added is already present in the declarative LINK table."); |
|
ERROR_REPORTER_HERE(ASC_USER_WARNING,"The LINK entry to-be added is already present in the declarative LINK table."); |
|
424 |
} |
} |
425 |
} |
} |
426 |
} |
} |
427 |
} |
} |
428 |
|
|
429 |
extern void ignoreDeclLinkEntry(struct Instance *model, symchar *key, struct VariableList *vlist) |
extern void ignoreDeclLinkEntry(struct Instance *model |
430 |
{ |
, symchar *key, struct VariableList *vlist |
431 |
|
){ |
432 |
/*DS: used in case the 'ignore' key is used for a declarative link */ |
/*DS: used in case the 'ignore' key is used for a declarative link */ |
433 |
struct TypeDescription *modelType; |
struct TypeDescription *modelType; |
434 |
struct link_entry_t *link_entry; |
struct link_entry_t *link_entry; |
453 |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"The LINK entry to-be ignored does not exist."); |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"The LINK entry to-be ignored does not exist."); |
454 |
} |
} |
455 |
} |
} |
456 |
/* DS: (current Implementation) check if the the non-declarative or declarative link table contains any of the instances in the list under the given key, if so remove them from the entries */ |
|
457 |
extern void removeLinkEntry(struct Instance *model, symchar *key, struct VariableList *vlist) |
/** |
458 |
{ |
DS: (current Implementation) check if the the non-declarative or declarative |
459 |
|
link table contains any of the instances in the list under the given key, if |
460 |
|
so remove them from the entries |
461 |
|
*/ |
462 |
|
extern void removeLinkEntry(struct Instance *model |
463 |
|
, symchar *key, struct VariableList *vlist |
464 |
|
){ |
465 |
/* used when called by the UNLINK command in the METHODS section by ASCEND */ |
/* used when called by the UNLINK command in the METHODS section by ASCEND */ |
466 |
struct link_entry_t *link_entry; |
struct link_entry_t *link_entry; |
467 |
struct for_var_t *ptr; |
struct for_var_t *ptr; |
468 |
int c, len, exist = 0; |
int c, len, exist = 0; |
469 |
|
|
470 |
|
|
471 |
printf("\n execute removeLinkEntry \n"); |
printf("\n execute removeLinkEntry \n"); |
472 |
|
|
473 |
/* in case the LINK key is in fact the index of a for loop, the value of the index at the current iteration is turned into a symchar and stored as a key*/ |
/* in case the LINK key is in fact the index of a for loop, the value of |
474 |
|
the index at the current iteration is turned into a symchar and stored as a key*/ |
475 |
if(GetEvaluationForTable() && (ptr = FindForVar((struct gl_list_t *)GetEvaluationForTable(),key)) != NULL) { |
if(GetEvaluationForTable() && (ptr = FindForVar((struct gl_list_t *)GetEvaluationForTable(),key)) != NULL) { |
476 |
char index_key[10]; |
char index_key[10]; |
477 |
sprintf(index_key,"%ld",GetForInteger(ptr)); |
sprintf(index_key,"%ld",GetForInteger(ptr)); |
480 |
|
|
481 |
len = gl_length(MOD_INST(model)->link_table); |
len = gl_length(MOD_INST(model)->link_table); |
482 |
printf("\n non-declarative link_table size %d\n",len); |
printf("\n non-declarative link_table size %d\n",len); |
483 |
for(c=1;c<=len;c++){ |
for(c=1;c<=len;c++){ |
484 |
link_entry = (struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,c); |
link_entry = (struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,c); |
485 |
if (CmpLinkEntry(key,vlist,link_entry) == 0) { |
if(CmpLinkEntry(key,vlist,link_entry) == 0) { |
486 |
exist = 1; |
exist = 1; |
487 |
printf("\n removed LinkEntry from non-declarative link_table\n"); |
printf("\n removed LinkEntry from non-declarative link_table\n"); |
488 |
gl_delete(MOD_INST(model)->link_table,c,1); /* we also deallocate the memory allocated for the link_entry */ |
gl_delete(MOD_INST(model)->link_table,c,1); /* we also deallocate the memory allocated for the link_entry */ |
500 |
} |
} |
501 |
|
|
502 |
|
|
503 |
/* DS: (current Implementation) check if the the non-declarative link table contains any of the instances in the list under the given key, if so remove them from the entries */ |
/** DS: (current Implementation) check if the the non-declarative link table contains any of the instances in the list under the given key, if so remove them from the entries */ |
504 |
extern void removeNonDeclarativeLinkEntry(struct Instance *model, symchar *key, int recursive) |
extern void removeNonDeclarativeLinkEntry(struct Instance *model |
505 |
{ |
, symchar *key, int recursive |
506 |
|
){ |
507 |
struct gl_list_t *result=gl_create(AVG_LINKS); |
struct gl_list_t *result=gl_create(AVG_LINKS); |
508 |
struct link_entry_t *link_entry; |
struct link_entry_t *link_entry; |
509 |
int c=1, len; |
int c=1, len; |
510 |
|
|
511 |
|
|
512 |
if (recursive) { |
if (recursive) { |
513 |
VisitInstanceTreeTwo(model, (VisitTwoProc)CollectLinks, 0,0, result); |
VisitInstanceTreeTwo(model, (VisitTwoProc)CollectLinks, 0,0, result); |
514 |
} else { |
}else{ |
515 |
CollectLinks(model, result); |
CollectLinks(model, result); |
516 |
} |
} |
517 |
|
|
518 |
printf("\n execute removeNonDeclarativeLinkEntry \n"); |
printf("\n execute removeNonDeclarativeLinkEntry \n"); |
519 |
len = gl_length(MOD_INST(model)->link_table); |
len = gl_length(MOD_INST(model)->link_table); |
525 |
printf("\n execute removed LinkEntry \n"); |
printf("\n execute removed LinkEntry \n"); |
526 |
gl_delete(MOD_INST(model)->link_table,c,1); |
gl_delete(MOD_INST(model)->link_table,c,1); |
527 |
len--; |
len--; |
528 |
} |
}else{ |
|
else{ |
|
529 |
c++; |
c++; |
530 |
} |
} |
531 |
} |
} |
535 |
} |
} |
536 |
|
|
537 |
|
|
538 |
CONST struct gl_list_t *getLinkInstances(struct Instance *inst, struct link_entry_t *link_entry,int status) |
const struct gl_list_t *getLinkInstances(struct Instance *inst |
539 |
{ |
, struct link_entry_t *link_entry,int status |
540 |
|
){ |
541 |
struct gl_list_t *result = gl_create(AVG_LINKS_INST); |
struct gl_list_t *result = gl_create(AVG_LINKS_INST); |
542 |
enum find_errors err; |
enum find_errors err; |
543 |
|
|
544 |
result = FindInstsNonFlat(inst,link_entry->u.vl,&err); |
result = FindInstsNonFlat(inst,link_entry->u.vl,&err); |
545 |
|
|
546 |
if (result==NULL) { |
if (result==NULL) { |
547 |
switch(err){ |
switch(err){ |
548 |
case impossible_instance: |
case impossible_instance: |
549 |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"LINK entry contains imposible instance name"); |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"LINK entry contains imposible instance name"); |
550 |
default: |
default: |
551 |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"incomplete instances in LINK entry"); |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"incomplete instances in LINK entry"); |
552 |
} |
} |
553 |
} |
} |
554 |
return result; |
return result; |
555 |
} |
} |
556 |
|
|
557 |
|
|
558 |
CONST struct gl_list_t *getLinkInstancesFlat(struct Instance *inst, struct link_entry_t *link_entry,int status) |
const struct gl_list_t *getLinkInstancesFlat(struct Instance *inst |
559 |
{ |
, struct link_entry_t *link_entry,int status |
560 |
|
){ |
561 |
struct gl_list_t *result = gl_create(AVG_LINKS_INST); |
struct gl_list_t *result = gl_create(AVG_LINKS_INST); |
562 |
enum find_errors err; |
enum find_errors err; |
563 |
if(link_entry->instances_cache == NULL) { |
if(link_entry->instances_cache == NULL) { |
564 |
result = FindInsts(inst,link_entry->u.vl,&err); |
result = FindInsts(inst,link_entry->u.vl,&err); |
565 |
if (result==NULL) { |
if (result==NULL) { |
566 |
switch(err){ |
switch(err){ |
567 |
case impossible_instance: |
case impossible_instance: |
568 |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"LINK entry contains impossible instance name"); |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"LINK entry contains impossible instance name"); |
569 |
default: |
default: |
570 |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"incomplete instances in LINK entry"); |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"incomplete instances in LINK entry"); |
571 |
/* statement is not ready to be executed */ |
/* statement is not ready to be executed */ |
572 |
} |
} |
573 |
} |
} |
574 |
return result; |
return result; |
575 |
} else { |
}else{ |
576 |
result = link_entry->instances_cache; |
result = link_entry->instances_cache; |
577 |
} |
} |
578 |
return result; |
return result; |
579 |
} |
} |
580 |
|
|
581 |
|
|
582 |
/**<DS: get the list (link_table) with all the declarative link entries located in the TypeDescription */ |
/** DS: get the list (link_table) with all the declarative link entries located in the TypeDescription */ |
583 |
extern struct gl_list_t *getLinkTableDeclarative(struct Instance *model) |
extern struct gl_list_t *getLinkTableDeclarative(struct Instance *model){ |
|
{ |
|
584 |
struct TypeDescription *modelType; |
struct TypeDescription *modelType; |
585 |
modelType = InstanceTypeDesc(model); |
modelType = InstanceTypeDesc(model); |
586 |
|
|
587 |
if(modelType->t == model_type) { |
if(modelType->t == model_type) { |
588 |
return modelType->u.modarg.link_table; |
return modelType->u.modarg.link_table; |
589 |
} |
}else{ |
|
else { |
|
590 |
return NULL; |
return NULL; |
591 |
ERROR_REPORTER_HERE(ASC_USER_WARNING,"the getLinkTableDeclarative procedure is called by a non-model instance"); |
ERROR_REPORTER_HERE(ASC_USER_WARNING,"the getLinkTableDeclarative procedure is called by a non-model instance"); |
592 |
} |
} |
593 |
} |
} |
594 |
|
|
595 |
|
|
596 |
/**<DS: get the list (link_table) with all the non-declarative link entries located in the ModelInstance */ |
/** DS: get the list (link_table) with all the non-declarative link entries located in the ModelInstance */ |
597 |
extern struct gl_list_t *getLinkTableProcedural(struct Instance *model) |
extern struct gl_list_t *getLinkTableProcedural(struct Instance *model){ |
|
{ |
|
598 |
struct TypeDescription *modelType; |
struct TypeDescription *modelType; |
599 |
modelType = InstanceTypeDesc(model); |
modelType = InstanceTypeDesc(model); |
600 |
if(modelType->t == model_type) { |
if(modelType->t == model_type) { |
601 |
return MOD_INST(model)->link_table; |
return MOD_INST(model)->link_table; |
602 |
} |
}else{ |
|
else { |
|
603 |
return NULL; |
return NULL; |
604 |
ERROR_REPORTER_HERE(ASC_USER_WARNING,"the getLinkTableProcedural procedure is called by a non-model instance"); |
ERROR_REPORTER_HERE(ASC_USER_WARNING,"the getLinkTableProcedural procedure is called by a non-model instance"); |
605 |
} |
} |
606 |
} |
} |
607 |
|
|
608 |
|
|
609 |
extern int isDeclarative(struct Instance* model, struct link_entry_t *target_link_entry) |
extern int isDeclarative(struct Instance* model, struct link_entry_t *target_link_entry){ |
|
{ |
|
610 |
struct TypeDescription *modelType; |
struct TypeDescription *modelType; |
611 |
struct link_entry_t *link_entry; |
struct link_entry_t *link_entry; |
612 |
int c, len; |
int c, len; |
615 |
modelType = InstanceTypeDesc(model); |
modelType = InstanceTypeDesc(model); |
616 |
len = gl_length(modelType->u.modarg.link_table); |
len = gl_length(modelType->u.modarg.link_table); |
617 |
|
|
618 |
for(c=1;c<=len;c++){ |
for(c=1;c<=len;c++){ |
619 |
link_entry = (struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,c); |
link_entry = (struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,c); |
620 |
if (CmpLinkEntry(target_link_entry->key_cache,target_link_entry->u.vl,link_entry) == 0) { |
if(CmpLinkEntry(target_link_entry->key_cache,target_link_entry->u.vl,link_entry) == 0) { |
621 |
return 1; |
return 1; |
622 |
} |
} |
623 |
} |
} |
624 |
return 0; |
return 0; |
625 |
} |
} |
626 |
|
|
627 |
|
|
628 |
extern void clearLinkCache(struct Instance* model) |
extern void clearLinkCache(struct Instance* model){ |
|
{ |
|
629 |
struct gl_list_t* link_table; |
struct gl_list_t* link_table; |
630 |
struct link_entry_t *link_entry; |
struct link_entry_t *link_entry; |
631 |
int c,len; |
int c,len; |
645 |
} |
} |
646 |
} |
} |
647 |
|
|
648 |
extern void populateLinkCache(struct Instance* model) |
extern void populateLinkCache(struct Instance* model){ |
|
{ |
|
|
|
|
649 |
struct gl_list_t *link_table; |
struct gl_list_t *link_table; |
650 |
struct link_entry_t *link_entry; |
struct link_entry_t *link_entry; |
651 |
enum find_errors err; |
enum find_errors err; |
652 |
int c,len; |
int c,len; |
653 |
|
|
654 |
link_table = getLinkTableDeclarative(model); |
link_table = getLinkTableDeclarative(model); |
656 |
for(c=1;c<=len;c++) { |
for(c=1;c<=len;c++) { |
657 |
link_entry = gl_fetch(link_table,c); |
link_entry = gl_fetch(link_table,c); |
658 |
link_entry->instances_cache = FindInsts(model,link_entry->u.vl,&err); |
link_entry->instances_cache = FindInsts(model,link_entry->u.vl,&err); |
659 |
if (link_entry->instances_cache==NULL) { |
if (link_entry->instances_cache==NULL) { |
660 |
switch(err){ |
switch(err){ |
661 |
case impossible_instance: |
case impossible_instance: |
662 |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"LINK statement contains an impossible instance name (populateLinkCache)"); |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"LINK statement contains an impossible instance name (populateLinkCache)"); |
663 |
default: |
default: |
664 |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"Incomplete instances in LINK (populateLinkCache)"); |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"Incomplete instances in LINK (populateLinkCache)"); |
665 |
} |
} |
666 |
} |
} |
667 |
} |
} |
668 |
|
|
669 |
link_table = getLinkTableProcedural(model); |
link_table = getLinkTableProcedural(model); |
671 |
for(c=1;c<=len;c++) { |
for(c=1;c<=len;c++) { |
672 |
link_entry = gl_fetch(link_table,c); |
link_entry = gl_fetch(link_table,c); |
673 |
link_entry->instances_cache = FindInsts(model,link_entry->u.vl,&err); |
link_entry->instances_cache = FindInsts(model,link_entry->u.vl,&err); |
674 |
if (link_entry->instances_cache==NULL) { |
if (link_entry->instances_cache==NULL) { |
675 |
switch(err){ |
switch(err){ |
676 |
case impossible_instance: |
case impossible_instance: |
677 |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"LINK statement contains an impossible instance name (populateLinkCache)"); |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"LINK statement contains an impossible instance name (populateLinkCache)"); |
678 |
default: |
default: |
679 |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"Incomplete instances in LINK (populateLinkCache)"); |
ERROR_REPORTER_HERE(ASC_USER_ERROR,"Incomplete instances in LINK (populateLinkCache)"); |
680 |
} |
} |
681 |
} |
} |
682 |
} |
} |
683 |
} |
} |
684 |
|
|
786 |
len1 = gl_length(linkTypes); |
len1 = gl_length(linkTypes); |
787 |
CONSOLE_DEBUG("\n number of unique link types: %d \n",len1); |
CONSOLE_DEBUG("\n number of unique link types: %d \n",len1); |
788 |
CONSOLE_DEBUG("\n The unique link keys are: "); |
CONSOLE_DEBUG("\n The unique link keys are: "); |
789 |
for(c1=1;c1<=len1;c1++){ |
for(c1=1;c1<=len1;c1++){ |
790 |
keyc1= (symchar *)gl_fetch(linkTypes,c1); |
keyc1= (symchar *)gl_fetch(linkTypes,c1); |
791 |
CONSOLE_DEBUG("%s ",SCP(keyc1)); |
CONSOLE_DEBUG("%s ",SCP(keyc1)); |
792 |
} |
} |
793 |
CONSOLE_DEBUG("\n"); |
CONSOLE_DEBUG("\n"); |
794 |
|
|
795 |
/* test getLinks */ |
/* test getLinks */ |
800 |
len2 = gl_length(links); |
len2 = gl_length(links); |
801 |
CONSOLE_DEBUG("\n number of links with key %s is: %d \n",SCP(keyc1),len2); |
CONSOLE_DEBUG("\n number of links with key %s is: %d \n",SCP(keyc1),len2); |
802 |
|
|
|
|
|
|
|
|
803 |
/* just a test for comparing two instances pointer-wise */ |
/* just a test for comparing two instances pointer-wise */ |
804 |
/* |
/* |
805 |
struct Instance *i11,*i22; |
struct Instance *i11,*i22; |
814 |
} */ |
} */ |
815 |
|
|
816 |
/* test getLinksReferencing */ |
/* test getLinksReferencing */ |
817 |
lnk = (struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,1); /* take the first link from all the non-declarative and declarative LINK Tables, just for testing */ |
lnk = (struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,1); |
818 |
|
/* take the first link from all the non-declarative and declarative LINK Tables, just for testing */ |
819 |
populateLinkCache(model); |
populateLinkCache(model); |
820 |
i1= (struct Instance *)gl_fetch(lnk->instances_cache,1); |
i1= (struct Instance *)gl_fetch(lnk->instances_cache,1); |
821 |
CONSOLE_DEBUG("\n number links referencing the first instance and key %s is %ld \n",SCP(keyc1),gl_length(getLinksReferencing(model,keyc1,i1,0))); |
CONSOLE_DEBUG("\n number links referencing the first instance and key %s is %ld \n" |
822 |
|
,SCP(keyc1),gl_length(getLinksReferencing(model,keyc1,i1,0)) |
823 |
|
); |
824 |
|
|
825 |
/* test getLinkInstances */ |
/* test getLinkInstances */ |
826 |
|
|
828 |
|
|
829 |
/* test isDeclarative */ |
/* test isDeclarative */ |
830 |
modelType = InstanceTypeDesc(model); |
modelType = InstanceTypeDesc(model); |
831 |
CONSOLE_DEBUG("\n the link should be declarative %d\n",isDeclarative(model,(struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,1))); |
CONSOLE_DEBUG("\n the link should be declarative %d\n" |
832 |
CONSOLE_DEBUG("\n the link should be non-declarative %d\n",isDeclarative(model,(struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,1))); |
,isDeclarative(model,(struct link_entry_t *)gl_fetch(modelType->u.modarg.link_table,1)) |
833 |
|
); |
834 |
|
CONSOLE_DEBUG("\n the link should be non-declarative %d\n" |
835 |
|
,isDeclarative(model,(struct link_entry_t *)gl_fetch(MOD_INST(model)->link_table,1)) |
836 |
|
); |
837 |
|
|
838 |
/* test removeNonDeclarative LINKs */ |
/* test removeNonDeclarative LINKs */ |
839 |
removeNonDeclarativeLinkEntry(model,NULL,0); /*since the key is NULL, all non declarative LINKS are removed */ |
removeNonDeclarativeLinkEntry(model,NULL,0); /*since the key is NULL, all non declarative LINKS are removed */ |