2004-04-23 11:58:43 +01:00
|
|
|
#ifndef TERMS
|
|
|
|
#define TERMS
|
|
|
|
|
2004-07-24 20:07:29 +01:00
|
|
|
#include "symbol.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2005-05-12 15:52:50 +01:00
|
|
|
#define false 0
|
|
|
|
#define true 1
|
|
|
|
|
2004-07-29 12:15:07 +01:00
|
|
|
// type <= LEAF means it's a leaf, nkay?
|
2004-08-09 11:05:58 +01:00
|
|
|
enum termtypes
|
|
|
|
{ GLOBAL, VARIABLE, LEAF, ENCRYPT, TUPLE };
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! The most basic datatype in the modelchecker.
|
|
|
|
/**
|
|
|
|
* Describes a single term.
|
|
|
|
*/
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
struct term
|
|
|
|
{
|
|
|
|
/* basic : name,runid
|
|
|
|
encrypt: op,key
|
|
|
|
tuple : op,next
|
|
|
|
*/
|
2004-05-15 13:33:01 +01:00
|
|
|
|
|
|
|
//! The type of term.
|
|
|
|
/**
|
|
|
|
* \sa GLOBAL, VARIABLE, LEAF, ENCRYPT, TUPLE
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
int type;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Data Type termlist (e.g. agent or nonce)
|
|
|
|
/** Only for leaves. */
|
2005-01-14 18:18:40 +00:00
|
|
|
void *stype; // list of types
|
2004-12-29 16:05:32 +00:00
|
|
|
int roleVar; // only for leaf, arachne engine: role variable flag
|
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Substitution term.
|
|
|
|
/**
|
|
|
|
* If this is non-NULL, this leaf term is apparently substituted by
|
|
|
|
* this term.
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
struct term *subst; // only for variable/leaf, substitution term
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
union
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
Symbol symb;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Encrypted subterm.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct term *op;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Left-hand side of tuple pair.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct term *op1;
|
|
|
|
struct term *next; // for alternative memory management
|
2004-05-26 09:40:33 +01:00
|
|
|
} left;
|
2004-04-23 11:58:43 +01:00
|
|
|
union
|
|
|
|
{
|
|
|
|
int runid;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Key used to encrypt subterm.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct term *key;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Right-hand side of tuple pair.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct term *op2;
|
2004-05-26 09:40:33 +01:00
|
|
|
} right;
|
2004-04-23 11:58:43 +01:00
|
|
|
};
|
|
|
|
|
2004-11-16 12:06:36 +00:00
|
|
|
//! Component macros (left)
|
|
|
|
#define TermSymb(t) (t->left.symb)
|
|
|
|
#define TermOp1(t) (t->left.op1)
|
|
|
|
#define TermOp(t) (t->left.op)
|
|
|
|
|
|
|
|
//! Component macros (right)
|
|
|
|
#define TermRunid(t) (t->right.runid)
|
|
|
|
#define TermOp2(t) (t->right.op2)
|
|
|
|
#define TermKey(t) (t->right.key)
|
|
|
|
|
2004-08-14 15:23:21 +01:00
|
|
|
//! Flag for term status
|
|
|
|
extern int rolelocal_variable;
|
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Pointer shorthand.
|
2004-04-23 11:58:43 +01:00
|
|
|
typedef struct term *Term;
|
|
|
|
|
|
|
|
void termsInit (void);
|
|
|
|
void termsDone (void);
|
|
|
|
Term makeTermEncrypt (Term t1, Term t2);
|
|
|
|
Term makeTermTuple (Term t1, Term t2);
|
|
|
|
Term makeTermType (const int type, const Symbol symb, const int runid);
|
2004-07-20 13:41:56 +01:00
|
|
|
__inline__ Term deVarScan (Term t);
|
2004-04-23 11:58:43 +01:00
|
|
|
#define realTermLeaf(t) (t != NULL && t->type <= LEAF)
|
|
|
|
#define realTermTuple(t) (t != NULL && t->type == TUPLE)
|
|
|
|
#define realTermEncrypt(t) (t != NULL && t->type == ENCRYPT)
|
2004-11-16 12:06:36 +00:00
|
|
|
#define realTermVariable(t) (t != NULL && (t->type == VARIABLE || (t->type <= LEAF && rolelocal_variable && TermRunid(t) == -3)))
|
2004-08-14 15:23:21 +01:00
|
|
|
#define substVar(t) ((realTermVariable (t) && t->subst != NULL) ? 1 : 0)
|
|
|
|
#define deVar(t) ( substVar(t) ? deVarScan(t->subst) : t)
|
2004-04-23 11:58:43 +01:00
|
|
|
#define isTermLeaf(t) realTermLeaf(deVar(t))
|
|
|
|
#define isTermTuple(t) realTermTuple(deVar(t))
|
|
|
|
#define isTermEncrypt(t) realTermEncrypt(deVar(t))
|
|
|
|
#define isTermVariable(t) realTermVariable(deVar(t))
|
2004-07-20 13:21:01 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define isTermEqual(t1,t2) isTermEqualDebug(t1,t2)
|
|
|
|
int isTermEqualDebug (Term t1, Term t2);
|
|
|
|
#else
|
|
|
|
#define isTermEqual1(t1,t2) ((substVar(t1) || substVar(t2)) \
|
2004-04-23 11:58:43 +01:00
|
|
|
? isTermEqualFn(t1,t2) \
|
|
|
|
: ( \
|
|
|
|
(t1 == t2) \
|
|
|
|
? 1 \
|
|
|
|
: ( \
|
|
|
|
(t1 == NULL || t2 == NULL || t1->type != t2->type) \
|
|
|
|
? 0 \
|
|
|
|
: ( \
|
|
|
|
realTermLeaf(t1) \
|
2004-08-27 11:08:03 +01:00
|
|
|
? isTermEqualFn(t1,t2) \
|
2004-04-23 11:58:43 +01:00
|
|
|
: ( \
|
|
|
|
realTermEncrypt(t2) \
|
2004-11-16 12:06:36 +00:00
|
|
|
? (isTermEqualFn(TermKey(t1), TermKey(t2)) && \
|
|
|
|
isTermEqualFn(TermOp(t1), TermOp(t2))) \
|
|
|
|
: (isTermEqualFn(TermOp1(t1), TermOp1(t2)) && \
|
|
|
|
isTermEqualFn(TermOp2(t1), TermOp2(t2))) \
|
2004-04-23 11:58:43 +01:00
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
)
|
|
|
|
|
2004-07-20 13:21:01 +01:00
|
|
|
#define isTermEqual2(t1,t2) ((substVar(t1) || substVar(t2)) \
|
2004-07-21 15:26:28 +01:00
|
|
|
? isTermEqualFn(t1,t2) \
|
2004-07-20 13:21:01 +01:00
|
|
|
: ( \
|
|
|
|
(t1 == t2) \
|
|
|
|
? 1 \
|
|
|
|
: ( \
|
|
|
|
(t1 == NULL || t2 == NULL || t1->type != t2->type) \
|
|
|
|
? 0 \
|
|
|
|
: ( \
|
|
|
|
realTermLeaf(t1) \
|
2004-08-27 11:08:03 +01:00
|
|
|
? isTermEqualFn(t1,t2) \
|
2004-07-20 13:21:01 +01:00
|
|
|
: ( \
|
|
|
|
realTermEncrypt(t2) \
|
2004-11-16 12:06:36 +00:00
|
|
|
? (isTermEqual1(TermKey(t1), TermKey(t2)) && \
|
|
|
|
isTermEqual1(TermOp(t1), TermOp(t2))) \
|
|
|
|
: (isTermEqual1(TermOp1(t1), TermOp1(t2)) && \
|
|
|
|
isTermEqual1(TermOp2(t1), TermOp2(t2))) \
|
2004-07-20 13:21:01 +01:00
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define isTermEqual3(t1,t2) ((substVar(t1) || substVar(t2)) \
|
2004-07-21 15:26:28 +01:00
|
|
|
? isTermEqualFn(t1,t2) \
|
2004-07-20 13:21:01 +01:00
|
|
|
: ( \
|
|
|
|
(t1 == t2) \
|
|
|
|
? 1 \
|
|
|
|
: ( \
|
|
|
|
(t1 == NULL || t2 == NULL || t1->type != t2->type) \
|
|
|
|
? 0 \
|
|
|
|
: ( \
|
|
|
|
realTermLeaf(t1) \
|
2004-08-27 11:08:03 +01:00
|
|
|
? isTermEqualFn(t1,t2) \
|
2004-07-20 13:21:01 +01:00
|
|
|
: ( \
|
|
|
|
realTermEncrypt(t2) \
|
2004-11-16 12:06:36 +00:00
|
|
|
? (isTermEqual2(TermKey(t1), TermKey(t2)) && \
|
|
|
|
isTermEqual2(TermOp(t1), TermOp(t2))) \
|
|
|
|
: (isTermEqual2(TermOp1(t1), TermOp1(t2)) && \
|
|
|
|
isTermEqual2(TermOp2(t1), TermOp2(t2))) \
|
2004-07-20 13:21:01 +01:00
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define isTermEqual(t1,t2) isTermEqual2(t1,t2)
|
|
|
|
#endif
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
int hasTermVariable (Term term);
|
|
|
|
int isTermEqualFn (Term term1, Term term2);
|
2004-08-17 15:11:25 +01:00
|
|
|
int termSubTerm (Term t, Term tsub);
|
|
|
|
int termInTerm (Term t, Term tsub);
|
2004-04-23 11:58:43 +01:00
|
|
|
void termPrint (Term term);
|
2004-05-19 09:39:39 +01:00
|
|
|
void termTuplePrint (Term term);
|
2004-04-23 11:58:43 +01:00
|
|
|
Term termDuplicate (const Term term);
|
2004-10-12 16:12:20 +01:00
|
|
|
Term termNodeDuplicate (const Term term);
|
2004-04-23 11:58:43 +01:00
|
|
|
Term termDuplicateDeep (const Term term);
|
|
|
|
Term termDuplicateUV (Term term);
|
|
|
|
void termDelete (const Term term);
|
|
|
|
void termNormalize (Term term);
|
|
|
|
Term termRunid (Term term, int runid);
|
|
|
|
int tupleCount (Term tt);
|
|
|
|
Term tupleProject (Term tt, int n);
|
2004-08-09 11:05:58 +01:00
|
|
|
int termSize (Term t);
|
|
|
|
float termDistance (Term t1, Term t2);
|
2004-07-14 09:17:49 +01:00
|
|
|
int termOrder (Term t1, Term t2);
|
2004-08-18 13:12:29 +01:00
|
|
|
int term_iterate (const Term term, int (*leaf) (), int (*nodel) (),
|
|
|
|
int (*nodem) (), int (*noder) ());
|
2004-08-19 15:49:03 +01:00
|
|
|
int term_iterate_deVar (Term term, int (*leaf) (), int (*nodel) (),
|
2004-08-18 13:12:29 +01:00
|
|
|
int (*nodem) (), int (*noder) ());
|
2004-08-12 10:14:31 +01:00
|
|
|
int term_iterate_leaves (const Term t, int (*func) ());
|
|
|
|
int term_iterate_open_leaves (const Term term, int (*func) ());
|
2004-08-14 15:23:21 +01:00
|
|
|
void term_rolelocals_are_variables ();
|
2004-08-18 15:06:14 +01:00
|
|
|
int term_encryption_level (const Term term);
|
|
|
|
float term_constrain_level (const Term term);
|
2004-08-20 20:16:56 +01:00
|
|
|
void term_set_keylevels (const Term term);
|
2004-11-01 14:06:26 +00:00
|
|
|
void termPrintDiff (Term t1, Term t2);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
#endif
|