Removing a collection of fairly simple remaining nested function calls.

This commit is contained in:
Cas Cremers 2019-01-04 17:16:27 +01:00
parent d25445538e
commit d4ec0004d6
9 changed files with 558 additions and 528 deletions

View File

@ -300,6 +300,28 @@ goal_remove_last (int n)
}
}
//! Get index of run
int
get_index (const int run, const Term label)
{
Roledef rd;
int i;
i = 0;
rd = sys->runs[run].start;
while (rd != NULL && !isTermEqual (rd->label, label))
{
rd = rd->next;
i++;
}
#ifdef DEBUG
if (rd == NULL)
error
("Could not locate send or recv for label, after niagree holds, to test for order.");
#endif
return i;
}
//! Determine whether some label set is ordered w.r.t. send/recv order.
/**
* Assumes all these labels exist in the system, within length etc, and that the run mappings are valid.
@ -312,34 +334,16 @@ labels_ordered (Termmap runs, Termlist labels)
// Given this label, and the mapping of runs, we want to know if the order is okay. Thus, we need to know sendrole and recvrole
Labelinfo linfo;
int send_run, send_ev, recv_run, recv_ev;
Term label;
int get_index (const int run)
{
Roledef rd;
int i;
i = 0;
rd = sys->runs[run].start;
while (rd != NULL && !isTermEqual (rd->label, labels->term))
{
rd = rd->next;
i++;
}
#ifdef DEBUG
if (rd == NULL)
error
("Could not locate send or recv for label, after niagree holds, to test for order.");
#endif
return i;
}
linfo = label_find (sys->labellist, labels->term);
label = labels->term;
linfo = label_find (sys->labellist, label);
if (!linfo->ignore)
{
send_run = termmapGet (runs, linfo->sendrole);
recv_run = termmapGet (runs, linfo->recvrole);
send_ev = get_index (send_run);
recv_ev = get_index (recv_run);
send_ev = get_index (send_run, label);
recv_ev = get_index (recv_run, label);
if (!isDependEvent (send_run, send_ev, recv_run, recv_ev))
{
// Not ordered; false

View File

@ -514,35 +514,11 @@ check_claim_niagree (const System sys, const int i)
return result;
}
//! Check generic agree claim for a given set of runs, arachne style
int
arachne_runs_agree (const System sys, const Claimlist cl, const Termmap runs)
//! Get label event
Roledef
get_label_event (const System sys, const Labelinfo linfo, const Term role,
const Term label, const Termmap runs)
{
Termlist labels;
int flag;
#ifdef DEBUG
if (DEBUGL (5))
{
eprintf ("Checking runs agreement for Arachne.\n");
termmapPrint (runs);
eprintf ("\n");
}
#endif
flag = 1;
labels = cl->prec;
while (flag && labels != NULL)
{
// For each label, check whether it matches. Maybe a bit too strict (what about variables?)
// Locate roledefs for recv & send, and check whether they are before step
Roledef rd_send, rd_recv;
Labelinfo linfo;
Roledef get_label_event (const Term role, const Term label)
{
Roledef rd, rd_res;
int i;
int run;
@ -590,14 +566,41 @@ arachne_runs_agree (const System sys, const Claimlist cl, const Termmap runs)
{
return NULL;
}
}
//! Check generic agree claim for a given set of runs, arachne style
int
arachne_runs_agree (const System sys, const Claimlist cl, const Termmap runs)
{
Termlist labels;
int flag;
#ifdef DEBUG
if (DEBUGL (5))
{
eprintf ("Checking runs agreement for Arachne.\n");
termmapPrint (runs);
eprintf ("\n");
}
#endif
flag = 1;
labels = cl->prec;
while (flag && labels != NULL)
{
// For each label, check whether it matches. Maybe a bit too strict (what about variables?)
// Locate roledefs for recv & send, and check whether they are before step
Roledef rd_send, rd_recv;
Labelinfo linfo;
// Main
linfo = label_find (sys->labellist, labels->term);
if (!linfo->ignore)
{
rd_send = get_label_event (linfo->sendrole, labels->term);
rd_recv = get_label_event (linfo->recvrole, labels->term);
rd_send =
get_label_event (sys, linfo, linfo->sendrole, labels->term, runs);
rd_recv =
get_label_event (sys, linfo, linfo->recvrole, labels->term, runs);
if (rd_send == NULL || rd_recv == NULL)
{

View File

@ -1183,13 +1183,11 @@ normalDeclaration (Tac tc)
return 1;
}
//! Add all sorts of claims to this role
void
claimAddAll (const System sys, const Protocol protocol, const Role role)
{
/* first: secrecy claims for all locally declared things */
void addSecrecyList (Termlist tl)
{
void
addSecrecyList (const System sys, const Protocol protocol, const Role role,
Termlist tl)
{
while (tl != NULL)
{
Term t;
@ -1202,12 +1200,16 @@ claimAddAll (const System sys, const Protocol protocol, const Role role)
}
tl = tl->next;
}
}
}
//! Add all sorts of claims to this role
void
claimAddAll (const System sys, const Protocol protocol, const Role role)
{
if (!isHelperProtocol (protocol))
{
addSecrecyList (role->declaredconsts);
addSecrecyList (role->declaredvars);
addSecrecyList (sys, protocol, role, role->declaredconsts);
addSecrecyList (sys, protocol, role, role->declaredvars);
/* full non-injective agreement and ni-synch */
claimCreate (sys, protocol, role, CLAIM_Alive, NULL, NULL, -1);
@ -1699,6 +1701,26 @@ compute_label_roles (Termlist labels)
return roles;
}
// This function checks whether the newrole can connect to the connectedrole, and whether they fulfil their requirements.
int
roles_test (const Termlist roles_ordered, const Termlist roles_remaining,
const Term connectedrole, const Term newrole)
{
if (inTermlist (roles_ordered, connectedrole) &&
inTermlist (roles_remaining, newrole))
{
#ifdef DEBUG
if (DEBUGL (4))
{
eprintf (" ");
termPrint (newrole);
}
#endif
return true;
}
return false;
}
//! Order the label roles for a given claim
void
order_label_roles (const Claimlist cl)
@ -1749,30 +1771,28 @@ order_label_roles (const Claimlist cl)
{
// If it's not the same protocol, the labels can't match
// This function checks whether the newrole can connect to the connectedrole, and whether they fulfil their requirements.
void roles_test (const Term connectedrole,
const Term newrole)
if (roles_test
(roles_ordered, roles_remaining, linfo->sendrole,
linfo->recvrole))
{
if (inTermlist (roles_ordered, connectedrole) &&
inTermlist (roles_remaining, newrole))
{
#ifdef DEBUG
if (DEBUGL (4))
{
eprintf (" ");
termPrint (newrole);
}
#endif
roles_ordered =
termlistAppend (roles_ordered, newrole);
termlistAppend (roles_ordered, linfo->recvrole);
roles_remaining =
termlistDelTerm (termlistFind
(roles_remaining, newrole));
(roles_remaining,
linfo->recvrole));
}
if (roles_test
(roles_ordered, roles_remaining, linfo->recvrole,
linfo->sendrole))
{
roles_ordered =
termlistAppend (roles_ordered, linfo->sendrole);
roles_remaining =
termlistDelTerm (termlistFind
(roles_remaining,
linfo->sendrole));
}
roles_test (linfo->sendrole, linfo->recvrole);
roles_test (linfo->recvrole, linfo->sendrole);
}
}
}
@ -1788,35 +1808,17 @@ order_label_roles (const Claimlist cl)
#endif
}
//! Compute prec() sets for each claim.
/**
* Generates two auxiliary structures. First, a table that contains
* a mapping from all events to event/claim labels.
* A second table is used to compute the precedence order, and
* Warshall's algorithm is used to compute the transitive closure.
* Then, for each claim, the in the preceding labels occurring roles are stored,
* which is useful later.
*@returns For each claim in the claim list, a preceding label set is defined.
*/
void
compute_prec_sets (const System sys)
// Assist: compute m_index from role, lev
int
m_index (const System sys, const int r, const int lev)
{
Term *eventlabels; // array: maps events to labels
unsigned int *prec; // array: maps event*event to precedence
int size; // temp constant: rolecount * roleeventmax
int rowsize;
int r1, r2, ev1, ev2; // some counters
Claimlist cl;
// Assist: compute index from role, lev
int index (int r, int lev)
{
return r * sys->roleeventmax + lev;
}
}
// Assist: yield roledef from r, lev
Roledef roledef_re (int r, int lev)
{
Roledef
roledef_re (const System sys, int r, int lev)
{
Protocol pr;
Role ro;
Roledef rd;
@ -1854,42 +1856,55 @@ compute_prec_sets (const System sys)
{
return NULL;
}
}
}
// Assist: print matrix
void show_matrix (void)
{
//! Assist: print matrix
void
show_matrix (const System sys, const int rowsize, const unsigned int *prec)
{
int r1, r2, ev1, ev2;
r1 = 0;
while (r1 < sys->rolecount)
for (r1 = 0; r1 < sys->rolecount; r1++)
{
ev1 = 0;
while (ev1 < sys->roleeventmax)
for (ev1 = 0; ev1 < sys->roleeventmax; ev1++)
{
eprintf ("prec %i,%i: ", r1, ev1);
r2 = 0;
while (r2 < sys->rolecount)
for (r2 = 0; r2 < sys->rolecount; r2++)
{
ev2 = 0;
while (ev2 < sys->roleeventmax)
for (ev2 = 0; ev2 < sys->roleeventmax; ev2++)
{
eprintf ("%i ",
BIT (prec + rowsize * index (r2, ev2),
index (r1, ev1)));
ev2++;
BIT (prec + rowsize * m_index (sys, r2, ev2),
m_index (sys, r1, ev1)));
}
eprintf (" ");
r2++;
}
eprintf ("\n");
ev1++;
}
eprintf ("\n");
r1++;
}
eprintf ("\n");
}
eprintf ("\n");
}
eprintf ("\n");
}
//! Compute prec() sets for each claim.
/**
* Generates two auxiliary structures. First, a table that contains
* a mapping from all events to event/claim labels.
* A second table is used to compute the precedence order, and
* Warshall's algorithm is used to compute the transitive closure.
* Then, for each claim, the in the preceding labels occurring roles are stored,
* which is useful later.
*@returns For each claim in the claim list, a preceding label set is defined.
*/
void
compute_prec_sets (const System sys)
{
Term *eventlabels; // array: maps events to labels
unsigned int *prec; // array: maps event*event to precedence
int size; // temp constant: rolecount * roleeventmax
int rowsize;
int r1, r2, ev1, ev2; // some counters
Claimlist cl;
/*
* Phase 1: Allocate structures and map to labels
@ -1907,10 +1922,10 @@ compute_prec_sets (const System sys)
Roledef rd;
ev1 = 0;
rd = roledef_re (r1, ev1);
rd = roledef_re (sys, r1, ev1);
while (rd != NULL)
{
eventlabels[index (r1, ev1)] = rd->label;
eventlabels[m_index (sys, r1, ev1)] = rd->label;
//termPrint (rd->label);
//eprintf ("\t");
ev1++;
@ -1918,7 +1933,7 @@ compute_prec_sets (const System sys)
}
while (ev1 < sys->roleeventmax)
{
eventlabels[index (r1, ev1)] = NULL;
eventlabels[m_index (sys, r1, ev1)] = NULL;
ev1++;
}
//eprintf ("\n");
@ -1931,7 +1946,8 @@ compute_prec_sets (const System sys)
ev1 = 1;
while (ev1 < (sys->roleeventmax))
{
SETBIT (prec + rowsize * index (r1, ev1 - 1), index (r1, ev1));
SETBIT (prec + rowsize * m_index (sys, r1, ev1 - 1),
m_index (sys, r1, ev1));
ev1++;
}
r1++;
@ -1945,7 +1961,7 @@ compute_prec_sets (const System sys)
{
Roledef rd1;
rd1 = roledef_re (r1, ev1);
rd1 = roledef_re (sys, r1, ev1);
if (rd1 != NULL && rd1->type == SEND)
{
r2 = 0;
@ -1956,12 +1972,12 @@ compute_prec_sets (const System sys)
{
Roledef rd2;
rd2 = roledef_re (r2, ev2);
rd2 = roledef_re (sys, r2, ev2);
if (rd2 != NULL && rd2->type == RECV
&& isTermEqual (rd1->label, rd2->label))
{
SETBIT (prec + rowsize * index (r1, ev1),
index (r2, ev2));
SETBIT (prec + rowsize * m_index (sys, r1, ev1),
m_index (sys, r2, ev2));
}
ev2++;
}
@ -1976,7 +1992,7 @@ compute_prec_sets (const System sys)
#ifdef DEBUG
if (DEBUGL (5))
{
show_matrix ();
show_matrix (sys, rowsize, prec);
}
#endif
@ -1988,7 +2004,7 @@ compute_prec_sets (const System sys)
#ifdef DEBUG
if (DEBUGL (5))
{
show_matrix ();
show_matrix (sys, rowsize, prec);
}
#endif
@ -2016,14 +2032,14 @@ compute_prec_sets (const System sys)
}
}
while (r1 < sys->rolecount
&& !isTermEqual (label, eventlabels[index (r1, ev1)]));
&& !isTermEqual (label, eventlabels[m_index (sys, r1, ev1)]));
if (r1 == sys->rolecount)
{
error
("Prec() setup: Could not find the event corresponding to a claim label.");
}
rd = roledef_re (r1, ev1);
rd = roledef_re (sys, r1, ev1);
if (rd->type != CLAIM)
{
error
@ -2039,15 +2055,15 @@ compute_prec_sets (const System sys)
* Now we compute the preceding label set
*/
cl->prec = NULL; // clear first
claim_index = index (r1, ev1);
claim_index = m_index (sys, r1, ev1);
r2 = 0;
while (r2 < sys->rolecount)
{
ev2 = 0;
rd = roledef_re (r2, ev2);
rd = roledef_re (sys, r2, ev2);
while (rd != NULL)
{
if (BIT (prec + rowsize * index (r2, ev2), claim_index))
if (BIT (prec + rowsize * m_index (sys, r2, ev2), claim_index))
{
// This event precedes the claim
@ -2118,12 +2134,12 @@ compute_prec_sets (const System sys)
{
// if this event preceds the claim, replace the label term
if (BIT
(prec + rowsize * index (r_scan, ev_scan),
(prec + rowsize * m_index (sys, r_scan, ev_scan),
claim_index))
{
Roledef rd;
rd = roledef_re (r_scan, ev_scan);
rd = roledef_re (sys, r_scan, ev_scan);
if (rd->label != NULL)
{
t_buf = rd->label;

View File

@ -263,12 +263,9 @@ redirNode (const System sys, Binding b)
node (sys, b->run_to, b->ev_to);
}
//! Roledef draw
void
roledefDraw (Roledef rd)
optlabel (const Roledef rd)
{
void optlabel (void)
{
Term label;
label = rd->label;
@ -281,12 +278,16 @@ roledefDraw (Roledef rd)
eprintf ("_");
termPrintRemap (label);
}
}
}
//! Roledef draw
void
roledefDraw (Roledef rd)
{
if (rd->type == RECV)
{
eprintf ("recv");
optlabel ();
optlabel (rd);
eprintf (" from ");
termPrintRemap (rd->from);
eprintf ("\\n");
@ -295,7 +296,7 @@ roledefDraw (Roledef rd)
if (rd->type == SEND)
{
eprintf ("send");
optlabel ();
optlabel (rd);
eprintf (" to ");
termPrintRemap (rd->to);
eprintf ("\\n");
@ -304,7 +305,7 @@ roledefDraw (Roledef rd)
if (rd->type == CLAIM)
{
eprintf ("claim");
optlabel ();
optlabel (rd);
eprintf ("\\n");
termPrintRemap (rd->to);
if (rd->message != NULL)
@ -348,14 +349,9 @@ hlsValue (double n1, double n2, double hue)
return n1;
}
//! hls to rgb conversion
void
hlsrgbreal (int *r, int *g, int *b, double h, double l, double s)
int
bytedouble (double d)
{
double m1, m2;
int bytedouble (double d)
{
double x;
x = 255.0 * d;
@ -365,7 +361,13 @@ hlsrgbreal (int *r, int *g, int *b, double h, double l, double s)
return 255;
else
return (int) x;
}
}
//! hls to rgb conversion
void
hlsrgbreal (int *r, int *g, int *b, double h, double l, double s)
{
double m1, m2;
while (h >= 360.0)
h -= 360.0;
@ -385,6 +387,12 @@ hlsrgbreal (int *r, int *g, int *b, double h, double l, double s)
}
}
double
closer (double l, double factor)
{
return l + ((1.0 - l) * factor);
}
//! hls to rgb conversion
/**
* Secretly takes the monochrome switch into account
@ -392,11 +400,6 @@ hlsrgbreal (int *r, int *g, int *b, double h, double l, double s)
void
hlsrgb (int *r, int *g, int *b, double h, double l, double s)
{
double closer (double l, double factor)
{
return l + ((1.0 - l) * factor);
}
if (switches.monochrome)
{
// No colors
@ -432,6 +435,14 @@ printColor (double h, double l, double s)
eprintf ("#%02x%02x%02x", r, g, b);
}
// help function: contract roleoffset, roledelta with a factor (<= 1.0)
void
contract (double roledelta, double roleoffset, double factor)
{
roledelta = roledelta * factor;
roleoffset = (roleoffset * factor) + ((1.0 - factor) / 2.0);
}
//! Set local buffer with the correct color for this run.
/**
@ -453,13 +464,6 @@ setRunColorBuf (const System sys, int run, char *colorbuf)
double h, l, s;
int r, g, b;
// help function: contract roleoffset, roledelta with a factor (<= 1.0)
void contract (double factor)
{
roledelta = roledelta * factor;
roleoffset = (roleoffset * factor) + ((1.0 - factor) / 2.0);
}
// determine #protocol, resulting in two colors
{
Termlist protocols;
@ -547,12 +551,13 @@ setRunColorBuf (const System sys, int run, char *colorbuf)
// Now this can result in a delta that is too high (depending on protocolrange)
if (protrange * roledelta > RUNCOLORDELTA)
{
contract (RUNCOLORDELTA / (protrange * roledelta));
contract (roledelta, roleoffset,
RUNCOLORDELTA / (protrange * roledelta));
}
}
// We slightly contract the colors (taking them away from protocol edges)
contract (RUNCOLORCONTRACT);
contract (roledelta, roleoffset, RUNCOLORCONTRACT);
// Now we can convert this to a color
color = protoffset + (protrange * roleoffset);
@ -1061,14 +1066,9 @@ regularModifiedLabel (Binding b)
}
}
//! Draw a single binding
void
drawBinding (const System sys, Binding b)
myarrow (const System sys, const int m0_from, const Binding b)
{
int intr_to, intr_from, m0_from;
void myarrow (const Binding b)
{
if (m0_from)
{
eprintf ("\t");
@ -1081,7 +1081,14 @@ drawBinding (const System sys, Binding b)
arrow (sys, b);
}
}
}
//! Draw a single binding
void
drawBinding (const System sys, Binding b)
{
int intr_to, intr_from, m0_from;
intr_from = (sys->runs[b->run_from].protocol == INTRUDER);
intr_to = (sys->runs[b->run_to].protocol == INTRUDER);
@ -1121,7 +1128,7 @@ drawBinding (const System sys, Binding b)
{
// intr->intr
eprintf ("\t");
myarrow (b);
myarrow (sys, m0_from, b);
eprintf (" [label=\"");
termPrintRemap (b->term);
eprintf ("\"");
@ -1136,7 +1143,7 @@ drawBinding (const System sys, Binding b)
{
// intr->regular
eprintf ("\t");
myarrow (b);
myarrow (sys, m0_from, b);
if (m0_from)
{
eprintf ("[weight=\"0.5\"]");
@ -1151,7 +1158,7 @@ drawBinding (const System sys, Binding b)
{
// regular->intr
eprintf ("\t");
myarrow (b);
myarrow (sys, m0_from, b);
eprintf (";\n");
}
else
@ -1163,7 +1170,7 @@ drawBinding (const System sys, Binding b)
if (isCommunicationExact (sys, b))
{
eprintf ("\t");
myarrow (b);
myarrow (sys, m0_from, b);
eprintf (" [style=bold,color=\"%s\"]", GOODCOMMCOLOR);
eprintf (";\n");
}

View File

@ -56,36 +56,25 @@ addEnumTerm (const System sys, Term t, Term actor, Termlist todo,
{
if (termSubTerm (t, todo->term))
{
// Occurs, we have to iterate
void iterateThis (Term to)
{
tolist = termlistPrepend (tolist, to);
addEnumTerm (sys, t, actor, todo->next, fromlist, tolist);
tolist = termlistDelTerm (tolist);
}
Termlist tl;
fromlist = termlistPrepend (fromlist, todo->term);
if (isTermEqual (todo->term, actor))
{
// Untrusted agents only
Termlist tl;
for (tl = sys->untrusted; tl != NULL; tl = tl->next)
{
iterateThis (tl->term);
}
tl = sys->untrusted;
}
else
{
// any agents
Termlist tl;
for (tl = sys->agentnames; tl != NULL; tl = tl->next)
{
iterateThis (tl->term);
tl = sys->agentnames;
}
while (tl != NULL)
{
tolist = termlistPrepend (tolist, tl->term);
addEnumTerm (sys, t, actor, todo->next, fromlist, tolist);
tolist = termlistDelTerm (tolist);
tl = tl->next;
}
fromlist = termlistDelTerm (fromlist);
}

View File

@ -430,6 +430,14 @@ isKnowledgePublicFunction (const Knowledge know, const Term f)
return inTermlist (know->publicfunctions, f);
}
Term
funKey (Term orig, Term f)
{
/* in: f'{op}, f
* out: f{op'} */
return makeTermFcall (termDuplicate (TermOp (orig)), termDuplicate (f));
}
//! Give the inverse key term of a term.
/**
* Gives a duplicate of the inverse Key of some term (which is used to encrypt something), as is defined
@ -452,14 +460,6 @@ inverseKey (Knowledge know, Term key)
{
Termlist tl;
Term funKey (Term orig, Term f)
{
/* in: f'{op}, f
* out: f{op'} */
return makeTermFcall (termDuplicate (TermOp (orig)),
termDuplicate (f));
}
tl = know->inversekeyfunctions;
while (tl != NULL && tl->next != NULL)
{

View File

@ -146,6 +146,22 @@ unify_callback_wrapper (Termlist tl, struct state_mgu_tmp *ptr_tmpstate)
ptr_tmpstate->oldcallback, ptr_tmpstate->oldstate);
}
int
callsubst (int (*callback) (), void *state, Termlist tl, Term t, Term tsubst)
{
int proceed;
t->subst = tsubst;
#ifdef DEBUG
showSubst (t);
#endif
tl = termlistAdd (tl, t);
proceed = callback (tl, state);
tl = termlistDelTerm (tl);
t->subst = NULL;
return proceed;
}
//! Most general unifier iteration
/**
* Try to determine the most general unifier of two terms, if so calls function.
@ -161,21 +177,6 @@ unify_callback_wrapper (Termlist tl, struct state_mgu_tmp *ptr_tmpstate)
int
unify (Term t1, Term t2, Termlist tl, int (*callback) (), void *state)
{
int callsubst (Termlist tl, Term t, Term tsubst)
{
int proceed;
t->subst = tsubst;
#ifdef DEBUG
showSubst (t);
#endif
tl = termlistAdd (tl, t);
proceed = callback (tl, state);
tl = termlistDelTerm (tl);
t->subst = NULL;
return proceed;
}
/* added for speed */
t1 = deVar (t1);
t2 = deVar (t2);
@ -223,7 +224,7 @@ unify (Term t1, Term t2, Termlist tl, int (*callback) (), void *state)
t1 = t2;
t2 = t3;
}
return callsubst (tl, t1, t2);
return callsubst (callback, state, tl, t1, t2);
}
/* symmetrical tests for single variable.
@ -235,7 +236,7 @@ unify (Term t1, Term t2, Termlist tl, int (*callback) (), void *state)
return true;
else
{
return callsubst (tl, t2, t1);
return callsubst (callback, state, tl, t2, t1);
}
}
if (realTermVariable (t1))
@ -244,7 +245,7 @@ unify (Term t1, Term t2, Termlist tl, int (*callback) (), void *state)
return true;
else
{
return callsubst (tl, t1, t2);
return callsubst (callback, state, tl, t1, t2);
}
}

View File

@ -1188,15 +1188,10 @@ term_rolelocals_are_variables ()
rolelocal_variable = 1;
}
//! Count the encryption level of a term
/**
* Note that this stops at any variable that is of ticket type.
*/
//! Helper for counting encryption level of a term
int
term_encryption_level (const Term term)
iter_maxencrypt (Term baseterm, Term t)
{
int iter_maxencrypt (Term t)
{
if (isTicketTerm (t))
{
return 0;
@ -1208,7 +1203,7 @@ term_encryption_level (const Term term)
if (DEBUGL (2))
{
eprintf ("Warning: Term encryption level finds a NULL for term ");
termPrint (term);
termPrint (baseterm);
eprintf ("\n");
}
#endif
@ -1224,23 +1219,61 @@ term_encryption_level (const Term term)
if (realTermTuple (t))
{
l = iter_maxencrypt (TermOp1 (t));
r = iter_maxencrypt (TermOp2 (t));
l = iter_maxencrypt (baseterm, TermOp1 (t));
r = iter_maxencrypt (baseterm, TermOp2 (t));
}
else
{
// encrypt
l = 1 + iter_maxencrypt (TermOp (t));
r = iter_maxencrypt (TermKey (t));
l = 1 + iter_maxencrypt (baseterm, TermOp (t));
r = iter_maxencrypt (baseterm, TermKey (t));
}
if (l > r)
return l;
else
return r;
}
}
}
return iter_maxencrypt (term);
//! Count the encryption level of a term
/**
* Note that this stops at any variable that is of ticket type.
*/
int
term_encryption_level (const Term term)
{
return iter_maxencrypt (term, term);
}
struct ti_data
{
int vars;
int structure;
};
void
tcl_iterate (struct ti_data *p_data, Term t)
{
t = deVar (t);
(p_data->structure)++;
if (realTermLeaf (t))
{
if (realTermVariable (t))
(p_data->vars)++;
}
else
{
if (realTermTuple (t))
{
tcl_iterate (p_data, TermOp1 (t));
tcl_iterate (p_data, TermOp2 (t));
}
else
{
tcl_iterate (p_data, TermOp (t));
tcl_iterate (p_data, TermKey (t));
}
}
}
//! Determine 'constrained factor' of a term
@ -1252,51 +1285,20 @@ term_encryption_level (const Term term)
float
term_constrain_level (const Term term)
{
int vars;
int structure;
void tcl_iterate (Term t)
{
t = deVar (t);
structure++;
if (realTermLeaf (t))
{
if (realTermVariable (t))
vars++;
}
else
{
if (realTermTuple (t))
{
tcl_iterate (TermOp1 (t));
tcl_iterate (TermOp2 (t));
}
else
{
tcl_iterate (TermOp (t));
tcl_iterate (TermKey (t));
}
}
}
struct ti_data data;
if (term == NULL)
error ("Cannot determine constrain level of empty term.");
vars = 0;
structure = 0;
tcl_iterate (term);
return ((float) vars / (float) structure);
data.vars = 0;
data.structure = 0;
tcl_iterate (&data, term);
return ((float) data.vars / (float) data.structure);
}
//! Adjust the keylevels of the symbols in a term.
/**
* This is used to scan the roles. For each symbol, this function does the bookkeeping of the keylevels at which they occur.
*/
void
term_set_keylevels (const Term term)
scan_levels (int level, Term t)
{
void scan_levels (int level, Term t)
{
#ifdef DEBUG
if (DEBUGL (5))
{
@ -1338,11 +1340,31 @@ term_set_keylevels (const Term term)
scan_levels ((level + 1), TermKey (t));
}
}
}
}
//! Adjust the keylevels of the symbols in a term.
/**
* This is used to scan the roles. For each symbol, this function does the bookkeeping of the keylevels at which they occur.
*/
void
term_set_keylevels (const Term term)
{
scan_levels (0, term);
}
void
termFromTo (Term t1, Term t2)
{
t1 = deVar (t1);
t2 = deVar (t2);
eprintf (" [");
termPrint (t1);
eprintf ("]->[");
termPrint (t2);
eprintf ("] ");
}
//! Print the term diff of two terms
/**
* This is not correct yet. We need to add function application and correct tuple handing.
@ -1350,18 +1372,6 @@ term_set_keylevels (const Term term)
void
termPrintDiff (Term t1, Term t2)
{
void termFromTo (Term t1, Term t2)
{
t1 = deVar (t1);
t2 = deVar (t2);
eprintf (" [");
termPrint (t1);
eprintf ("]->[");
termPrint (t2);
eprintf ("] ");
}
t1 = deVar (t1);
t2 = deVar (t2);

View File

@ -843,32 +843,14 @@ xmlRunInfo (const System sys, const int run)
xmlRunVariables (sys, run);
}
//! Display runs
void
xmlOutRuns (const System sys)
{
int run;
for (run = 0; run < sys->maxruns; run++)
{
xmlPrint ("<run>");
xmlindent++;
xmlRunInfo (sys, run);
xmlPrint ("<eventlist>");
xmlindent++;
{
Roledef rd;
int index;
//! Test whether to display this event
/**
//! Test whether to display this event
/**
* Could be integrated into a single line on the while loop,
* but that makes it rather hard to understand.
*/
int showthis (void)
{
int
showthis (const System sys, const int run, const Roledef rd, const int index)
{
if (rd != NULL)
{
if (index < sys->runs[run].step)
@ -895,8 +877,7 @@ xmlOutRuns (const System sys)
* events.
*/
if (isTriviallyKnownAtArachne (sys,
rd->message,
run, index))
rd->message, run, index))
{
return true;
}
@ -925,11 +906,30 @@ xmlOutRuns (const System sys)
}
}
return false;
}
}
//! Display runs
void
xmlOutRuns (const System sys)
{
int run;
for (run = 0; run < sys->maxruns; run++)
{
xmlPrint ("<run>");
xmlindent++;
xmlRunInfo (sys, run);
xmlPrint ("<eventlist>");
xmlindent++;
{
Roledef rd;
int index;
index = 0;
rd = sys->runs[run].start;
while (showthis ())
while (showthis (sys, run, rd, index))
{
xmlOutEvent (sys, rd, run, index);
index++;