Involved, but ultimately straightforward refactoring for nested function.
This commit is contained in:
parent
8aed349139
commit
01e366e6dd
113
src/system.c
113
src/system.c
@ -466,27 +466,18 @@ run_localize (const System sys, const int rid, Termlist fromlist,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct cl_struct
|
||||||
//! Instantiate a role by making a new run for Arachne
|
{
|
||||||
/**
|
Termlist fromlist;
|
||||||
* This involves creation of a new run(id).
|
Termlist tolist;
|
||||||
* Copy & subst of Roledef, Agent knowledge.
|
Term extterm;
|
||||||
* Tolist might contain type constants.
|
Role role;
|
||||||
*/
|
Roledef rd;
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
roleInstanceArachne (const System sys, const Protocol protocol,
|
createLocal (const System sys, struct cl_struct *p_data, Term oldt,
|
||||||
const Role role, const Termlist paramlist,
|
int isvariable, int isrole, const int rid)
|
||||||
Termlist substlist)
|
|
||||||
{
|
|
||||||
int rid;
|
|
||||||
Run runs;
|
|
||||||
Roledef rd;
|
|
||||||
Termlist fromlist = NULL; // deleted at the end
|
|
||||||
Termlist tolist = NULL; // -> .locals
|
|
||||||
Term extterm = NULL; // construction thing (will go to artefacts)
|
|
||||||
|
|
||||||
void createLocal (Term oldt, int isvariable, int isrole)
|
|
||||||
{
|
{
|
||||||
Term newt;
|
Term newt;
|
||||||
|
|
||||||
@ -505,12 +496,12 @@ roleInstanceArachne (const System sys, const Protocol protocol,
|
|||||||
newt->helper.roleVar = isrole; // set role status
|
newt->helper.roleVar = isrole; // set role status
|
||||||
|
|
||||||
// Add to copy list
|
// Add to copy list
|
||||||
TERMLISTADD (fromlist, oldt);
|
TERMLISTADD ((p_data->fromlist), oldt);
|
||||||
TERMLISTADD (tolist, newt);
|
TERMLISTADD ((p_data->tolist), newt);
|
||||||
|
|
||||||
// Add to registration lists
|
// Add to registration lists
|
||||||
// Everything to destructor list
|
// Everything to destructor list
|
||||||
TERMLISTADD (runs[rid].artefacts, newt);
|
TERMLISTADD ((sys->runs[rid].artefacts), newt);
|
||||||
// Variable / Constant?
|
// Variable / Constant?
|
||||||
if (isvariable)
|
if (isvariable)
|
||||||
{
|
{
|
||||||
@ -522,24 +513,25 @@ roleInstanceArachne (const System sys, const Protocol protocol,
|
|||||||
* We use append to make sure the order is
|
* We use append to make sure the order is
|
||||||
* consistent with the role names list.
|
* consistent with the role names list.
|
||||||
*/
|
*/
|
||||||
TERMLISTAPPEND (runs[rid].rho, newt);
|
TERMLISTAPPEND ((sys->runs[rid]).rho, newt);
|
||||||
if (!role->initiator)
|
if (!((p_data->role)->initiator))
|
||||||
{
|
{
|
||||||
// For non-initiators, we prepend the recving of the role names
|
// For non-initiators, we prepend the recving of the role names
|
||||||
|
|
||||||
// XXX disabled for now TODO [x] [cc]
|
// XXX disabled for now TODO [x] [cc]
|
||||||
if (0 == 1 && not_recv_first (rd, oldt))
|
if (0 == 1 && not_recv_first (p_data->rd, oldt))
|
||||||
{
|
{
|
||||||
/* this term is forced as a choose, or it does not occur in the (first) recv event */
|
/* this term is forced as a choose, or it does not occur in the (first) recv event */
|
||||||
if (extterm == NULL)
|
if (p_data->extterm == NULL)
|
||||||
{
|
{
|
||||||
extterm = newt;
|
p_data->extterm = newt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
extterm = makeTermTuple (newt, extterm);
|
p_data->extterm = makeTermTuple (newt, p_data->extterm);
|
||||||
// NOTE: don't these get double deleted? By roledefdestroy?
|
// NOTE: don't these get double deleted? By roledefdestroy?
|
||||||
TERMLISTAPPEND (runs[rid].artefacts, extterm);
|
TERMLISTAPPEND ((sys->runs[rid].artefacts),
|
||||||
|
p_data->extterm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -547,43 +539,64 @@ roleInstanceArachne (const System sys, const Protocol protocol,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// normal variable
|
// normal variable
|
||||||
TERMLISTAPPEND (runs[rid].sigma, newt);
|
TERMLISTAPPEND ((sys->runs[rid].sigma), newt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// local constant
|
// local constant
|
||||||
TERMLISTADD (runs[rid].constants, newt);
|
TERMLISTADD ((sys->runs[rid].constants), newt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//! The next function makes locals for all in the list. Flags denote whether it is a variable or role.
|
//! The next function makes locals for all in the list. Flags denote whether it is a variable or role.
|
||||||
void createLocals (Termlist list, int isvariable, int isrole)
|
void
|
||||||
|
createLocals (const System sys, struct cl_struct *p_data, Termlist list,
|
||||||
|
int isvariable, int isrole, const int rid)
|
||||||
{
|
{
|
||||||
while (list != NULL)
|
while (list != NULL)
|
||||||
{
|
{
|
||||||
createLocal (list->term, isvariable, isrole);
|
createLocal (sys, p_data, list->term, isvariable, isrole, rid);
|
||||||
list = list->next;
|
list = list->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Instantiate a role by making a new run for Arachne
|
||||||
|
/**
|
||||||
|
* This involves creation of a new run(id).
|
||||||
|
* Copy & subst of Roledef, Agent knowledge.
|
||||||
|
* Tolist might contain type constants.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
roleInstanceArachne (const System sys, const Protocol protocol,
|
||||||
|
const Role role, const Termlist paramlist,
|
||||||
|
Termlist substlist)
|
||||||
|
{
|
||||||
|
int rid;
|
||||||
|
struct cl_struct data;
|
||||||
|
|
||||||
|
data.fromlist = NULL; // deleted at the end
|
||||||
|
data.tolist = NULL; // -> .locals
|
||||||
|
data.extterm = NULL; // construction thing (will go to artefacts)
|
||||||
|
data.role = role;
|
||||||
|
|
||||||
/* claim runid, allocate space */
|
/* claim runid, allocate space */
|
||||||
rid = sys->maxruns;
|
rid = sys->maxruns;
|
||||||
ensureValidRun (sys, rid); // creates a new block
|
ensureValidRun (sys, rid); // creates a new block
|
||||||
runs = sys->runs; // simple structure pointer transfer (shortcut)
|
|
||||||
|
|
||||||
/* duplicate roledef in buffer rd */
|
/* duplicate roledef in buffer rd */
|
||||||
/* Notice that it is not stored (yet) in the run structure,
|
/* Notice that it is not stored (yet) in the run structure,
|
||||||
* and that termDuplicate is used internally
|
* and that termDuplicate is used internally
|
||||||
*/
|
*/
|
||||||
rd = roledefDuplicate (role->roledef);
|
data.rd = roledefDuplicate (role->roledef);
|
||||||
|
|
||||||
/* set parameters */
|
/* set parameters */
|
||||||
/* generic setup of inherited stuff */
|
/* generic setup of inherited stuff */
|
||||||
runs[rid].protocol = protocol;
|
sys->runs[rid].protocol = protocol;
|
||||||
runs[rid].role = role;
|
sys->runs[rid].role = role;
|
||||||
runs[rid].step = 0;
|
sys->runs[rid].step = 0;
|
||||||
runs[rid].firstReal = 0;
|
sys->runs[rid].firstReal = 0;
|
||||||
|
|
||||||
/* Now we need to create local terms corresponding to rho, sigma, and any local constants.
|
/* Now we need to create local terms corresponding to rho, sigma, and any local constants.
|
||||||
*
|
*
|
||||||
@ -591,35 +604,35 @@ roleInstanceArachne (const System sys, const Protocol protocol,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Create rho, sigma, constants
|
// Create rho, sigma, constants
|
||||||
createLocals (protocol->rolenames, true, true);
|
createLocals (sys, &data, protocol->rolenames, true, true, rid);
|
||||||
createLocals (role->declaredvars, true, false);
|
createLocals (sys, &data, role->declaredvars, true, false, rid);
|
||||||
createLocals (role->declaredconsts, false, false);
|
createLocals (sys, &data, role->declaredconsts, false, false, rid);
|
||||||
|
|
||||||
/* Now we prefix the recv before rd, if extterm is not NULL. Even if
|
/* Now we prefix the recv before rd, if extterm is not NULL. Even if
|
||||||
* extterm is NULL, rd is still set as the start and the index pointer of
|
* extterm is NULL, rd is still set as the start and the index pointer of
|
||||||
* the run.
|
* the run.
|
||||||
*/
|
*/
|
||||||
run_prefix_recv (sys, rid, rd, extterm);
|
run_prefix_recv (sys, rid, data.rd, data.extterm);
|
||||||
|
|
||||||
/* TODO this is not what we want yet, also local knowledge. The local
|
/* TODO this is not what we want yet, also local knowledge. The local
|
||||||
* knowledge (list?) also needs to be substituted on invocation. */
|
* knowledge (list?) also needs to be substituted on invocation. */
|
||||||
runs[rid].know = NULL;
|
sys->runs[rid].know = NULL;
|
||||||
|
|
||||||
/* now adjust the local run copy */
|
/* now adjust the local run copy */
|
||||||
run_localize (sys, rid, fromlist, tolist, substlist);
|
run_localize (sys, rid, data.fromlist, data.tolist, substlist);
|
||||||
|
|
||||||
termlistDelete (fromlist);
|
termlistDelete (data.fromlist);
|
||||||
runs[rid].locals = tolist;
|
sys->runs[rid].locals = data.tolist;
|
||||||
|
|
||||||
/* erase any substitutions in the role definition, as they are now copied */
|
/* erase any substitutions in the role definition, as they are now copied */
|
||||||
termlistSubstReset (role->variables);
|
termlistSubstReset (role->variables);
|
||||||
|
|
||||||
/* length */
|
/* length */
|
||||||
runs[rid].rolelength = roledef_length (runs[rid].start);
|
sys->runs[rid].rolelength = roledef_length (sys->runs[rid].start);
|
||||||
/* [[[ Hack ]]] this length is minimally 3 (to help the construction of the encryptors/decryptors from bare roledefs */
|
/* [[[ Hack ]]] this length is minimally 3 (to help the construction of the encryptors/decryptors from bare roledefs */
|
||||||
if (runs[rid].rolelength < 3)
|
if (sys->runs[rid].rolelength < 3)
|
||||||
{
|
{
|
||||||
runs[rid].rolelength = 3;
|
sys->runs[rid].rolelength = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* new graph to create */
|
/* new graph to create */
|
||||||
|
Loading…
Reference in New Issue
Block a user