- Made union in TAC more ANSI compliant (and thus suitable for the sun)

This commit is contained in:
ccremers 2004-05-26 08:26:40 +00:00
parent 2106aadb23
commit 2cae2d2a08
4 changed files with 123 additions and 123 deletions

View File

@ -226,7 +226,7 @@ defineUsertype (Tac tcdu)
Term t; Term t;
Term tfind; Term tfind;
tc = tcdu->tac1; tc = tcdu->t1.tac;
if (tc == NULL) if (tc == NULL)
{ {
@ -238,11 +238,11 @@ defineUsertype (Tac tcdu)
/* check whether this term is already declared in the same way /* check whether this term is already declared in the same way
* (i.e. as a type) */ * (i.e. as a type) */
tfind = levelFind (tc->sym1, 0); tfind = levelFind (tc->t1.sym, 0);
if (tfind == NULL) if (tfind == NULL)
{ {
/* this is what we expected: this type is not declared yet */ /* this is what we expected: this type is not declared yet */
t = levelDeclare (tc->sym1, 0, 0); t = levelDeclare (tc->t1.sym, 0, 0);
t->stype = termlistAdd (NULL, TERM_Type); t->stype = termlistAdd (NULL, TERM_Type);
} }
else else
@ -275,7 +275,7 @@ levelTacDeclaration (Tac tc, int isVar)
Termlist typetl = NULL; Termlist typetl = NULL;
Term t; Term t;
tscan = tc->tac2; tscan = tc->t2.tac;
if (!isVar && tscan->next != NULL) if (!isVar && tscan->next != NULL)
{ {
printf ("ERROR: Multiple types not allowed for constants "); printf ("ERROR: Multiple types not allowed for constants ");
@ -284,13 +284,13 @@ levelTacDeclaration (Tac tc, int isVar)
while (tscan != NULL && tscan->op == TAC_STRING) while (tscan != NULL && tscan->op == TAC_STRING)
{ {
/* apparently there is type info, termlist? */ /* apparently there is type info, termlist? */
t = levelFind (tscan->sym1, 0); t = levelFind (tscan->t1.sym, 0);
if (t == NULL) if (t == NULL)
{ {
/* not declared, that is unacceptable. */ /* not declared, that is unacceptable. */
printf ("ERROR: type "); printf ("ERROR: type ");
symbolPrint (tscan->sym1); symbolPrint (tscan->t1.sym);
printf (" was not declared "); printf (" was not declared ");
errorTac (tscan->lineno); errorTac (tscan->lineno);
} }
@ -306,10 +306,10 @@ levelTacDeclaration (Tac tc, int isVar)
tscan = tscan->next; tscan = tscan->next;
} }
/* parse all constants and vars */ /* parse all constants and vars */
tscan = tc->tac1; tscan = tc->t1.tac;
while (tscan != NULL) while (tscan != NULL)
{ {
t = symbolDeclare (tscan->sym1, isVar); t = symbolDeclare (tscan->t1.sym, isVar);
t->stype = typetl; t->stype = typetl;
tscan = tscan->next; tscan = tscan->next;
} }
@ -329,22 +329,22 @@ commEvent (int event, Tac tc)
Tac trip; Tac trip;
/* Construct label, if any */ /* Construct label, if any */
if (tc->sym1 == NULL) if (tc->t1.sym == NULL)
{ {
label = NULL; label = NULL;
} }
else else
{ {
label = levelFind (tc->sym1, level - 1); label = levelFind (tc->t1.sym, level - 1);
if (label == NULL) if (label == NULL)
{ {
/* effectively, labels are bound to the protocol */ /* effectively, labels are bound to the protocol */
level--; level--;
label = levelConst (tc->sym1); label = levelConst (tc->t1.sym);
level++; level++;
} }
} }
trip = tc->tac2; trip = tc->t2.tac;
switch (event) switch (event)
{ {
case READ: case READ:
@ -446,22 +446,22 @@ normalDeclaration (Tac tc)
{ {
case TAC_VAR: case TAC_VAR:
levelDeclareVar (tc); levelDeclareVar (tc);
if (level < 2 && tc->tac3 == NULL) if (level < 2 && tc->t3.tac == NULL)
knowledgeAddTermlist (sys->know, tacTermlist (tc->tac1)); knowledgeAddTermlist (sys->know, tacTermlist (tc->t1.tac));
break; break;
case TAC_CONST: case TAC_CONST:
levelDeclareConst (tc); levelDeclareConst (tc);
if (level < 2 && tc->tac3 == NULL) if (level < 2 && tc->t3.tac == NULL)
knowledgeAddTermlist (sys->know, tacTermlist (tc->tac1)); knowledgeAddTermlist (sys->know, tacTermlist (tc->t1.tac));
break; break;
case TAC_SECRET: case TAC_SECRET:
levelDeclareConst (tc); levelDeclareConst (tc);
break; break;
case TAC_COMPROMISED: case TAC_COMPROMISED:
knowledgeAddTermlist (sys->know, tacTermlist (tc->tac1)); knowledgeAddTermlist (sys->know, tacTermlist (tc->t1.tac));
break; break;
case TAC_INVERSEKEYS: case TAC_INVERSEKEYS:
knowledgeAddInverse (sys->know, tacTerm (tc->tac1), tacTerm (tc->tac2)); knowledgeAddInverse (sys->know, tacTerm (tc->t1.tac), tacTerm (tc->t2.tac));
break; break;
default: default:
/* abort with false */ /* abort with false */
@ -531,7 +531,7 @@ runInstanceCreate (Tac tc)
return; return;
/* first, locate the protocol */ /* first, locate the protocol */
psym = tc->tac1->sym1; psym = tc->t1.tac->t1.sym;
p = sys->protocols; p = sys->protocols;
while (p != NULL && p->nameterm->symb != psym) while (p != NULL && p->nameterm->symb != psym)
p = p->next; p = p->next;
@ -544,7 +544,7 @@ runInstanceCreate (Tac tc)
} }
/* locate the role */ /* locate the role */
rsym = tc->tac1->sym2; rsym = tc->t1.tac->t2.sym;
r = p->roles; r = p->roles;
while (r != NULL && r->nameterm->symb != rsym) while (r != NULL && r->nameterm->symb != rsym)
r = r->next; r = r->next;
@ -559,7 +559,7 @@ runInstanceCreate (Tac tc)
} }
/* we now know what we are instancing, equal numbers? */ /* we now know what we are instancing, equal numbers? */
instParams = tacTermlist (tc->tac2); instParams = tacTermlist (tc->t2.tac);
if (termlistLength (instParams) != termlistLength (p->rolenames)) if (termlistLength (instParams) != termlistLength (p->rolenames))
{ {
printf printf
@ -618,7 +618,7 @@ protocolCompile (Symbol prots, Tac tc, Tac tcroles)
while (tcroles != NULL) while (tcroles != NULL)
{ {
pr->rolenames = pr->rolenames =
termlistAppend (pr->rolenames, levelConst (tcroles->sym1)); termlistAppend (pr->rolenames, levelConst (tcroles->t1.sym));
tcroles = tcroles->next; tcroles = tcroles->next;
} }
@ -629,21 +629,21 @@ protocolCompile (Symbol prots, Tac tc, Tac tcroles)
{ {
case TAC_UNTRUSTED: case TAC_UNTRUSTED:
sys->untrusted = sys->untrusted =
termlistConcat (sys->untrusted, tacTermlist (tc->tac1)); termlistConcat (sys->untrusted, tacTermlist (tc->t1.tac));
break; break;
case TAC_ROLE: case TAC_ROLE:
t = levelFind (tc->sym1, level); t = levelFind (tc->t1.sym, level);
if (t != NULL) if (t != NULL)
{ {
roleCompile (t, tc->tac2); roleCompile (t, tc->t2.tac);
} }
else else
{ {
printf ("ERROR: undeclared role "); printf ("ERROR: undeclared role ");
symbolPrint (tc->sym1); symbolPrint (tc->t1.sym);
printf (" in protocol "); printf (" in protocol ");
termPrint (pr->nameterm); termPrint (pr->nameterm);
errorTac (tc->sym1->lineno); errorTac (tc->t1.sym->lineno);
} }
break; break;
default: default:
@ -668,11 +668,11 @@ tacProcess (Tac tc)
switch (tc->op) switch (tc->op)
{ {
case TAC_PROTOCOL: case TAC_PROTOCOL:
protocolCompile (tc->sym1, tc->tac2, tc->tac3); protocolCompile (tc->t1.sym, tc->t2.tac, tc->t3.tac);
break; break;
case TAC_UNTRUSTED: case TAC_UNTRUSTED:
sys->untrusted = sys->untrusted =
termlistConcat (sys->untrusted, tacTermlist (tc->tac1)); termlistConcat (sys->untrusted, tacTermlist (tc->t1.tac));
break; break;
case TAC_RUN: case TAC_RUN:
runInstanceCreate (tc); runInstanceCreate (tc);
@ -699,16 +699,16 @@ tacTerm (Tac tc)
switch (tc->op) switch (tc->op)
{ {
case TAC_ENCRYPT: case TAC_ENCRYPT:
return makeTermEncrypt (tacTerm (tc->tac1), tacTerm (tc->tac2)); return makeTermEncrypt (tacTerm (tc->t1.tac), tacTerm (tc->t2.tac));
case TAC_TUPLE: case TAC_TUPLE:
return makeTermTuple (tacTerm (tc->tac1), tacTerm (tc->tac2)); return makeTermTuple (tacTerm (tc->t1.tac), tacTerm (tc->t2.tac));
case TAC_STRING: case TAC_STRING:
{ {
Term t = symbolFind (tc->sym1); Term t = symbolFind (tc->t1.sym);
if (t == NULL) if (t == NULL)
{ {
printf ("Undeclared symbol "); printf ("Undeclared symbol ");
symbolPrint (tc->sym1); symbolPrint (tc->t1.sym);
errorTac (tc->lineno); errorTac (tc->lineno);
} }
return t; return t;

View File

@ -67,28 +67,28 @@ spdlrep : /* empty */
spdl : UNTRUSTED termlist ';' spdl : UNTRUSTED termlist ';'
{ {
Tac t = tacCreate(TAC_UNTRUSTED); Tac t = tacCreate(TAC_UNTRUSTED);
t->tac1 = $2; t->t1.tac = $2;
$$ = t; $$ = t;
} }
| RUN roleref '(' termlist ')' ';' | RUN roleref '(' termlist ')' ';'
{ {
Tac t = tacCreate(TAC_RUN); Tac t = tacCreate(TAC_RUN);
t->tac1 = $2; t->t1.tac = $2;
t->tac2 = $4; t->t2.tac = $4;
$$ = t; $$ = t;
} }
| PROTOCOL ID '(' termlist ')' '{' roles '}' optclosing | PROTOCOL ID '(' termlist ')' '{' roles '}' optclosing
{ {
Tac t = tacCreate(TAC_PROTOCOL); Tac t = tacCreate(TAC_PROTOCOL);
t->sym1 = $2; t->t1.sym = $2;
t->tac2 = $7; t->t2.tac = $7;
t->tac3 = $4; t->t3.tac = $4;
$$ = t; $$ = t;
} }
| USERTYPE termlist ';' | USERTYPE termlist ';'
{ {
Tac t = tacCreate(TAC_USERTYPE); Tac t = tacCreate(TAC_USERTYPE);
t->tac1 = $2; t->t1.tac = $2;
$$ = t; $$ = t;
} }
| declaration | declaration
@ -108,8 +108,8 @@ roles : /* empty */
role : ROLE ID '{' roledef '}' optclosing role : ROLE ID '{' roledef '}' optclosing
{ {
Tac t = tacCreate(TAC_ROLE); Tac t = tacCreate(TAC_ROLE);
t->sym1 = $2; t->t1.sym = $2;
t->tac2 = $4; t->t2.tac = $4;
$$ = t; $$ = t;
} }
; ;
@ -130,64 +130,64 @@ roledef : /* empty */
event : READT label '(' termlist ')' ';' event : READT label '(' termlist ')' ';'
{ Tac t = tacCreate(TAC_READ); { Tac t = tacCreate(TAC_READ);
t->sym1 = $2; t->t1.sym = $2;
/* TODO test here: tac2 should have at least 3 elements */ /* TODO test here: tac2 should have at least 3 elements */
t->tac2 = $4; t->t2.tac = $4;
$$ = t; $$ = t;
} }
| SENDT label '(' termlist ')' ';' | SENDT label '(' termlist ')' ';'
{ Tac t = tacCreate(TAC_SEND); { Tac t = tacCreate(TAC_SEND);
t->sym1 = $2; t->t1.sym = $2;
/* TODO test here: tac2 should have at least 3 elements */ /* TODO test here: tac2 should have at least 3 elements */
t->tac2 = $4; t->t2.tac = $4;
$$ = t; $$ = t;
} }
| CLAIMT label '(' termlist ')' ';' | CLAIMT label '(' termlist ')' ';'
/* TODO maybe claims should be in the syntax */ /* TODO maybe claims should be in the syntax */
{ Tac t = tacCreate(TAC_CLAIM); { Tac t = tacCreate(TAC_CLAIM);
t->sym1 = $2; t->t1.sym = $2;
t->tac2 = $4; t->t2.tac = $4;
$$ = t; $$ = t;
} }
; ;
roleref : ID '.' ID roleref : ID '.' ID
{ Tac t = tacCreate(TAC_ROLEREF); { Tac t = tacCreate(TAC_ROLEREF);
t->sym1 = $1; t->t1.sym = $1;
t->sym2 = $3; t->t2.sym = $3;
$$ = t; $$ = t;
} }
; ;
declaration : secretpref CONST termlist typeinfo1 ';' declaration : secretpref CONST termlist typeinfo1 ';'
{ Tac t = tacCreate(TAC_CONST); { Tac t = tacCreate(TAC_CONST);
t->tac1 = $3; t->t1.tac = $3;
t->tac2 = $4; t->t2.tac = $4;
t->tac3 = $1; t->t3.tac = $1;
$$ = t; $$ = t;
} }
| secretpref VAR termlist typeinfoN ';' | secretpref VAR termlist typeinfoN ';'
{ Tac t = tacCreate(TAC_VAR); { Tac t = tacCreate(TAC_VAR);
t->tac1 = $3; t->t1.tac = $3;
t->tac2 = $4; t->t2.tac = $4;
t->tac3 = $1; t->t3.tac = $1;
$$ = t; $$ = t;
} }
| SECRET termlist typeinfo1 ';' | SECRET termlist typeinfo1 ';'
{ Tac t = tacCreate(TAC_SECRET); { Tac t = tacCreate(TAC_SECRET);
t->tac1 = $2; t->t1.tac = $2;
t->tac2 = $3; t->t2.tac = $3;
$$ = t; $$ = t;
} }
| INVERSEKEYS '(' term ',' term ')' ';' | INVERSEKEYS '(' term ',' term ')' ';'
{ Tac t = tacCreate(TAC_INVERSEKEYS); { Tac t = tacCreate(TAC_INVERSEKEYS);
t->tac1 = $3; t->t1.tac = $3;
t->tac2 = $5; t->t2.tac = $5;
$$ = t; $$ = t;
} }
| COMPROMISED termlist ';' | COMPROMISED termlist ';'
{ Tac t = tacCreate(TAC_COMPROMISED); { Tac t = tacCreate(TAC_COMPROMISED);
t->tac1= $2; t->t1.tac= $2;
$$ = t; $$ = t;
} }
; ;
@ -210,7 +210,7 @@ typeinfo1 : /* empty */
} }
| ':' ID | ':' ID
{ Tac t = tacCreate(TAC_STRING); { Tac t = tacCreate(TAC_STRING);
t->sym1 = $2; t->t1.sym = $2;
$$ = t; $$ = t;
} }
; ;
@ -235,13 +235,13 @@ label : /* empty */
term : ID term : ID
{ {
Tac t = tacCreate(TAC_STRING); Tac t = tacCreate(TAC_STRING);
t->sym1 = $1; t->t1.sym = $1;
$$ = t; $$ = t;
} }
| ID '(' termlist ')' | ID '(' termlist ')'
{ {
Tac t = tacCreate(TAC_STRING); Tac t = tacCreate(TAC_STRING);
t->sym1 = $1; t->t1.sym = $1;
$$ = tacJoin(TAC_ENCRYPT,tacTuple($3),t,NULL); $$ = tacJoin(TAC_ENCRYPT,tacTuple($3),t,NULL);
} }
| '{' termlist '}' key | '{' termlist '}' key

View File

@ -38,9 +38,9 @@ tacCreate (int op)
t->op = op; t->op = op;
t->next = NULL; t->next = NULL;
t->prev = NULL; t->prev = NULL;
t->tac1 = NULL; t->t1.tac = NULL;
t->tac2 = NULL; t->t2.tac = NULL;
t->tac3 = NULL; t->t3.tac = NULL;
return t; return t;
} }
@ -49,7 +49,7 @@ tacString (char *s)
{ {
Tac t; Tac t;
t = tacCreate (TAC_STRING); t = tacCreate (TAC_STRING);
t->str1 = s; t->t1.str = s;
return t; return t;
} }
@ -58,9 +58,9 @@ tacJoin (int op, Tac t1, Tac t2, Tac t3)
{ {
Tac t; Tac t;
t = tacCreate (op); t = tacCreate (op);
t->tac1 = t1; t->t1.tac = t1;
t->tac2 = t2; t->t2.tac = t2;
t->tac3 = t3; t->t3.tac = t3;
return t; return t;
} }
@ -110,12 +110,12 @@ tacTuple (Tac taclist)
{ {
/* otherwise, write as (x,(y,(z,..))) */ /* otherwise, write as (x,(y,(z,..))) */
tc = tacCreate (TAC_TUPLE); tc = tacCreate (TAC_TUPLE);
tc->tac1 = taclist; tc->t1.tac = taclist;
tc->tac2 = tacTuple (taclist->next); tc->t2.tac = tacTuple (taclist->next);
/* unlink list */ /* unlink list */
tc->tac1->next = NULL; tc->t1.tac->next = NULL;
tc->tac2->prev = NULL; tc->t2.tac->prev = NULL;
} }
return tc; return tc;
} }
@ -133,64 +133,64 @@ tacPrint (Tac t)
switch (t->op) switch (t->op)
{ {
case TAC_PROTOCOL: case TAC_PROTOCOL:
printf ("protocol %s (", t->sym1->text); printf ("protocol %s (", t->t1.sym->text);
tacPrint (t->tac3); tacPrint (t->t3.tac);
printf (")\n{\n"); printf (")\n{\n");
tacPrint (t->tac2); tacPrint (t->t2.tac);
printf ("};\n"); printf ("};\n");
break; break;
case TAC_ROLE: case TAC_ROLE:
printf ("role %s\n{\n", t->sym1->text); printf ("role %s\n{\n", t->t1.sym->text);
tacPrint (t->tac2); tacPrint (t->t2.tac);
printf ("};\n"); printf ("};\n");
break; break;
case TAC_READ: case TAC_READ:
printf ("read"); printf ("read");
if (t->sym1 != NULL) if (t->t1.sym != NULL)
{ {
printf ("_%s", t->sym1->text); printf ("_%s", t->t1.sym->text);
} }
printf ("("); printf ("(");
tacPrint (t->tac2); tacPrint (t->t2.tac);
printf (");\n"); printf (");\n");
break; break;
case TAC_SEND: case TAC_SEND:
printf ("send"); printf ("send");
if (t->sym1 != NULL) if (t->t1.sym != NULL)
{ {
printf ("_%s", t->sym1->text); printf ("_%s", t->t1.sym->text);
} }
printf ("("); printf ("(");
tacPrint (t->tac2); tacPrint (t->t2.tac);
printf (");\n"); printf (");\n");
break; break;
case TAC_CLAIM: case TAC_CLAIM:
printf ("claim"); printf ("claim");
if (t->sym1 != NULL) if (t->t1.sym != NULL)
{ {
printf ("_%s", t->sym1->text); printf ("_%s", t->t1.sym->text);
} }
printf ("("); printf ("(");
tacPrint (t->tac2); tacPrint (t->t2.tac);
printf (");\n"); printf (");\n");
break; break;
case TAC_CONST: case TAC_CONST:
printf ("const "); printf ("const ");
tacPrint (t->tac1); tacPrint (t->t1.tac);
if (t->tac2 != NULL) if (t->t2.tac != NULL)
{ {
printf (" : "); printf (" : ");
tacPrint (t->tac2); tacPrint (t->t2.tac);
} }
printf (";\n"); printf (";\n");
break; break;
case TAC_VAR: case TAC_VAR:
printf ("var "); printf ("var ");
tacPrint (t->tac1); tacPrint (t->t1.tac);
if (t->tac2 != NULL) if (t->t2.tac != NULL)
{ {
printf (" : "); printf (" : ");
tacPrint (t->tac2); tacPrint (t->t2.tac);
} }
printf (";\n"); printf (";\n");
break; break;
@ -200,22 +200,22 @@ tacPrint (Tac t)
printf (","); printf (",");
break; break;
case TAC_STRING: case TAC_STRING:
printf ("%s", t->sym1->text); printf ("%s", t->t1.sym->text);
if (t->next != NULL) if (t->next != NULL)
printf (","); printf (",");
break; break;
case TAC_TUPLE: case TAC_TUPLE:
printf ("("); printf ("(");
tacPrint (t->tac1); tacPrint (t->t1.tac);
printf (","); printf (",");
tacPrint (t->tac2); tacPrint (t->t2.tac);
printf (")"); printf (")");
break; break;
case TAC_ENCRYPT: case TAC_ENCRYPT:
printf ("{"); printf ("{");
tacPrint (t->tac1); tacPrint (t->t1.tac);
printf ("}"); printf ("}");
tacPrint (t->tac2); tacPrint (t->t2.tac);
if (t->next != NULL) if (t->next != NULL)
{ {
printf (","); printf (",");
@ -225,36 +225,36 @@ tacPrint (Tac t)
break; break;
case TAC_RUN: case TAC_RUN:
printf ("run "); printf ("run ");
tacPrint (t->tac1); tacPrint (t->t1.tac);
printf ("("); printf ("(");
tacPrint (t->tac2); tacPrint (t->t2.tac);
printf (");\n"); printf (");\n");
break; break;
case TAC_ROLEREF: case TAC_ROLEREF:
symbolPrint (t->sym1); symbolPrint (t->t1.sym);
printf ("."); printf (".");
symbolPrint (t->sym2); symbolPrint (t->t2.sym);
break; break;
case TAC_COMPROMISED: case TAC_COMPROMISED:
printf ("compromised "); printf ("compromised ");
tacPrint (t->tac1); tacPrint (t->t1.tac);
printf (";\n"); printf (";\n");
break; break;
case TAC_SECRET: case TAC_SECRET:
printf ("secret "); printf ("secret ");
tacPrint (t->tac1); tacPrint (t->t1.tac);
printf (";\n"); printf (";\n");
break; break;
case TAC_INVERSEKEYS: case TAC_INVERSEKEYS:
printf ("inversekeys ("); printf ("inversekeys (");
tacPrint (t->tac1); tacPrint (t->t1.tac);
printf (","); printf (",");
tacPrint (t->tac2); tacPrint (t->t2.tac);
printf (");\n"); printf (");\n");
break; break;
case TAC_UNTRUSTED: case TAC_UNTRUSTED:
printf ("untrusted "); printf ("untrusted ");
tacPrint (t->tac1); tacPrint (t->t1.tac);
printf (";\n"); printf (";\n");
break; break;
default: default:

View File

@ -37,22 +37,22 @@ struct tacnode
int lineno; int lineno;
union union
{ {
Symbol sym1; Symbol sym;
struct tacnode *tac1; struct tacnode *tac;
char *str1; char *str;
}; } t1;
union
{
Symbol sym;
struct tacnode *tac;
char *str;
} t2;
union union
{ {
Symbol sym2; Symbol sym;
struct tacnode *tac2; struct tacnode *tac;
char *str2; char *str;
}; } t3;
union
{
Symbol sym3;
struct tacnode *tac3;
char *str3;
};
}; };
typedef struct tacnode *Tac; typedef struct tacnode *Tac;