- Reindent script was improved (and consequences added)
This commit is contained in:
parent
5d2d836d07
commit
d3f2971181
235
src/hidelevel.c
235
src/hidelevel.c
@ -13,168 +13,175 @@
|
|||||||
unsigned int
|
unsigned int
|
||||||
protocolHidelevel (const System sys, const Term t)
|
protocolHidelevel (const System sys, const Term t)
|
||||||
{
|
{
|
||||||
unsigned int minlevel;
|
unsigned int minlevel;
|
||||||
|
|
||||||
minlevel = INT_MAX;
|
minlevel = INT_MAX;
|
||||||
|
|
||||||
int itsends (const System sys, const Protocol p, const Role r)
|
int itsends (const System sys, const Protocol p, const Role r)
|
||||||
|
{
|
||||||
|
int sends (Roledef rd)
|
||||||
|
{
|
||||||
|
if (rd->type == SEND)
|
||||||
{
|
{
|
||||||
int sends(Roledef rd)
|
unsigned int l;
|
||||||
{
|
|
||||||
if (rd->type == SEND)
|
|
||||||
{
|
|
||||||
unsigned int l;
|
|
||||||
|
|
||||||
l = termHidelevel (t, rd->from);
|
l = termHidelevel (t, rd->from);
|
||||||
if (l < minlevel) minlevel = l;
|
if (l < minlevel)
|
||||||
l = termHidelevel (t, rd->to);
|
minlevel = l;
|
||||||
if (l < minlevel) minlevel = l;
|
l = termHidelevel (t, rd->to);
|
||||||
l = termHidelevel (t, rd->message);
|
if (l < minlevel)
|
||||||
if (l < minlevel) minlevel = l;
|
minlevel = l;
|
||||||
}
|
l = termHidelevel (t, rd->message);
|
||||||
return true;
|
if (l < minlevel)
|
||||||
}
|
minlevel = l;
|
||||||
|
|
||||||
roledef_iterate_events (r->roledef, sends);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
system_iterate_roles (sys, itsends);
|
roledef_iterate_events (r->roledef, sends);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return minlevel;
|
system_iterate_roles (sys, itsends);
|
||||||
|
|
||||||
|
return minlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! hide level within initial knowledge
|
//! hide level within initial knowledge
|
||||||
unsigned int
|
unsigned int
|
||||||
knowledgeHidelevel (const System sys, const Term t)
|
knowledgeHidelevel (const System sys, const Term t)
|
||||||
{
|
{
|
||||||
unsigned int minlevel;
|
unsigned int minlevel;
|
||||||
Termlist tl;
|
Termlist tl;
|
||||||
|
|
||||||
minlevel = INT_MAX;
|
minlevel = INT_MAX;
|
||||||
tl = knowledgeSet (sys->know);
|
tl = knowledgeSet (sys->know);
|
||||||
while (tl != NULL)
|
while (tl != NULL)
|
||||||
|
{
|
||||||
|
unsigned int l;
|
||||||
|
|
||||||
|
l = termHidelevel (t, tl->term);
|
||||||
|
if (l < minlevel)
|
||||||
{
|
{
|
||||||
unsigned int l;
|
minlevel = l;
|
||||||
|
|
||||||
l = termHidelevel (t, tl->term);
|
|
||||||
if (l < minlevel)
|
|
||||||
{
|
|
||||||
minlevel = l;
|
|
||||||
}
|
|
||||||
tl = tl->next;
|
|
||||||
}
|
}
|
||||||
termlistDelete (tl);
|
tl = tl->next;
|
||||||
|
}
|
||||||
|
termlistDelete (tl);
|
||||||
|
|
||||||
return minlevel;
|
return minlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Check hide levels
|
//! Check hide levels
|
||||||
void
|
void
|
||||||
hidelevelCompute (const System sys)
|
hidelevelCompute (const System sys)
|
||||||
{
|
{
|
||||||
Termlist tl;
|
Termlist tl;
|
||||||
|
|
||||||
sys->hidden = NULL;
|
sys->hidden = NULL;
|
||||||
tl = sys->globalconstants;
|
tl = sys->globalconstants;
|
||||||
eprintf ("Global constants: ");
|
eprintf ("Global constants: ");
|
||||||
termlistPrint (tl);
|
termlistPrint (tl);
|
||||||
eprintf ("\n");
|
eprintf ("\n");
|
||||||
|
|
||||||
while (tl != NULL)
|
while (tl != NULL)
|
||||||
|
{
|
||||||
|
unsigned int l1, l2, l;
|
||||||
|
|
||||||
|
l1 = knowledgeHidelevel (sys, tl->term);
|
||||||
|
l2 = protocolHidelevel (sys, tl->term);
|
||||||
|
if (l1 < l2)
|
||||||
{
|
{
|
||||||
unsigned int l1,l2,l;
|
l = l1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l = l2;
|
||||||
|
}
|
||||||
|
|
||||||
l1 = knowledgeHidelevel (sys, tl->term);
|
// Interesting only if higher than zero
|
||||||
l2 = protocolHidelevel (sys, tl->term);
|
if (l > 0)
|
||||||
if (l1 < l2)
|
{
|
||||||
{
|
Hiddenterm ht;
|
||||||
l = l1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
l = l2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interesting only if higher than zero
|
ht = (Hiddenterm) memAlloc (sizeof (struct hiddenterm));
|
||||||
if (l > 0)
|
ht->term = tl->term;
|
||||||
{
|
ht->hideminimum = l;
|
||||||
Hiddenterm ht;
|
ht->hideprotocol = l2;
|
||||||
|
ht->hideknowledge = l1;
|
||||||
ht = (Hiddenterm) memAlloc (sizeof (struct hiddenterm));
|
ht->next = sys->hidden;
|
||||||
ht->term = tl->term;
|
sys->hidden = ht;
|
||||||
ht->hideminimum = l;
|
|
||||||
ht->hideprotocol = l2;
|
|
||||||
ht->hideknowledge = l1;
|
|
||||||
ht->next = sys->hidden;
|
|
||||||
sys->hidden = ht;
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
eprintf ("Added possibly interesting term: ");
|
eprintf ("Added possibly interesting term: ");
|
||||||
termPrint (tl->term);
|
termPrint (tl->term);
|
||||||
eprintf ("; know %i, prot %i\n", l1,l2);
|
eprintf ("; know %i, prot %i\n", l1, l2);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
tl = tl->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tl = tl->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Given a term, iterate over all factors
|
//! Given a term, iterate over all factors
|
||||||
int iterate_interesting (const System sys, const Term goalterm, int (*func) ())
|
int
|
||||||
|
iterate_interesting (const System sys, const Term goalterm, int (*func) ())
|
||||||
{
|
{
|
||||||
Hiddenterm ht;
|
Hiddenterm ht;
|
||||||
|
|
||||||
ht = sys->hidden;
|
ht = sys->hidden;
|
||||||
while (ht != NULL)
|
while (ht != NULL)
|
||||||
|
{
|
||||||
|
unsigned int l;
|
||||||
|
// Test the goalterm for occurrences of this
|
||||||
|
|
||||||
|
l = termHidelevel (ht->term, goalterm);
|
||||||
|
if (l < INT_MAX)
|
||||||
{
|
{
|
||||||
unsigned int l;
|
if (!func (l, ht->hideminimum, ht->hideprotocol, ht->hideknowledge))
|
||||||
// Test the goalterm for occurrences of this
|
{
|
||||||
|
return false;
|
||||||
l = termHidelevel (ht->term, goalterm);
|
}
|
||||||
if (l < INT_MAX)
|
|
||||||
{
|
|
||||||
if (!func (l, ht->hideminimum, ht->hideprotocol, ht->hideknowledge))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ht = ht->next;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
ht = ht->next;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Determine whether a goal might be interesting from the viewpoint of hide levels (the highest minimum is best)
|
//! Determine whether a goal might be interesting from the viewpoint of hide levels (the highest minimum is best)
|
||||||
int hidelevelInteresting (const System sys, const Term goalterm)
|
int
|
||||||
|
hidelevelInteresting (const System sys, const Term goalterm)
|
||||||
{
|
{
|
||||||
int uninteresting (unsigned int l, unsigned int lmin, unsigned int lprot, unsigned int lknow)
|
int uninteresting (unsigned int l, unsigned int lmin, unsigned int lprot,
|
||||||
{
|
unsigned int lknow)
|
||||||
if (lmin > 0)
|
{
|
||||||
{
|
if (lmin > 0)
|
||||||
// anything higher than usual is interesting :)
|
{
|
||||||
return false;
|
// anything higher than usual is interesting :)
|
||||||
}
|
return false;
|
||||||
return true;
|
}
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return !iterate_interesting (sys, goalterm, uninteresting);
|
return !iterate_interesting (sys, goalterm, uninteresting);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Determine whether a goal is impossible to satisfy because of the hidelevel lemma.
|
//! Determine whether a goal is impossible to satisfy because of the hidelevel lemma.
|
||||||
int hidelevelImpossible (const System sys, const Term goalterm)
|
int
|
||||||
|
hidelevelImpossible (const System sys, const Term goalterm)
|
||||||
{
|
{
|
||||||
int possible (unsigned int l, unsigned int lmin, unsigned int lprot, unsigned int lknow)
|
int possible (unsigned int l, unsigned int lmin, unsigned int lprot,
|
||||||
{
|
unsigned int lknow)
|
||||||
if (l < lmin)
|
{
|
||||||
{
|
if (l < lmin)
|
||||||
// impossible, abort!
|
{
|
||||||
return false;
|
// impossible, abort!
|
||||||
}
|
return false;
|
||||||
return true;
|
}
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return !iterate_interesting (sys, goalterm, possible);
|
return !iterate_interesting (sys, goalterm, possible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,4 +13,3 @@ int hidelevelInteresting (const System sys, const Term goalterm);
|
|||||||
int hidelevelImpossible (const System sys, const Term goalterm);
|
int hidelevelImpossible (const System sys, const Term goalterm);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
#
|
#
|
||||||
# Indent any changed files, ending in .c or .h
|
# Indent any changed files, ending in .c or .h
|
||||||
#
|
#
|
||||||
svn st | grep "^M.*\.[ch]$"| awk '{print $2}' | xargs indent
|
svn st | grep "^[MA].*\.[ch]$"| awk '{print $2}' | xargs indent
|
||||||
|
Loading…
Reference in New Issue
Block a user