From 2cae2d2a08e7524a7addc3ae1c343becbb433c49 Mon Sep 17 00:00:00 2001 From: ccremers Date: Wed, 26 May 2004 08:26:40 +0000 Subject: [PATCH] - Made union in TAC more ANSI compliant (and thus suitable for the sun) --- src/compiler.c | 66 ++++++++++++++++++------------------ src/parser.y | 62 +++++++++++++++++----------------- src/tac.c | 90 +++++++++++++++++++++++++------------------------- src/tac.h | 28 ++++++++-------- 4 files changed, 123 insertions(+), 123 deletions(-) diff --git a/src/compiler.c b/src/compiler.c index b890fdc..9867da4 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -226,7 +226,7 @@ defineUsertype (Tac tcdu) Term t; Term tfind; - tc = tcdu->tac1; + tc = tcdu->t1.tac; if (tc == NULL) { @@ -238,11 +238,11 @@ defineUsertype (Tac tcdu) /* check whether this term is already declared in the same way * (i.e. as a type) */ - tfind = levelFind (tc->sym1, 0); + tfind = levelFind (tc->t1.sym, 0); if (tfind == NULL) { /* 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); } else @@ -275,7 +275,7 @@ levelTacDeclaration (Tac tc, int isVar) Termlist typetl = NULL; Term t; - tscan = tc->tac2; + tscan = tc->t2.tac; if (!isVar && tscan->next != NULL) { printf ("ERROR: Multiple types not allowed for constants "); @@ -284,13 +284,13 @@ levelTacDeclaration (Tac tc, int isVar) while (tscan != NULL && tscan->op == TAC_STRING) { /* apparently there is type info, termlist? */ - t = levelFind (tscan->sym1, 0); + t = levelFind (tscan->t1.sym, 0); if (t == NULL) { /* not declared, that is unacceptable. */ printf ("ERROR: type "); - symbolPrint (tscan->sym1); + symbolPrint (tscan->t1.sym); printf (" was not declared "); errorTac (tscan->lineno); } @@ -306,10 +306,10 @@ levelTacDeclaration (Tac tc, int isVar) tscan = tscan->next; } /* parse all constants and vars */ - tscan = tc->tac1; + tscan = tc->t1.tac; while (tscan != NULL) { - t = symbolDeclare (tscan->sym1, isVar); + t = symbolDeclare (tscan->t1.sym, isVar); t->stype = typetl; tscan = tscan->next; } @@ -329,22 +329,22 @@ commEvent (int event, Tac tc) Tac trip; /* Construct label, if any */ - if (tc->sym1 == NULL) + if (tc->t1.sym == NULL) { label = NULL; } else { - label = levelFind (tc->sym1, level - 1); + label = levelFind (tc->t1.sym, level - 1); if (label == NULL) { /* effectively, labels are bound to the protocol */ level--; - label = levelConst (tc->sym1); + label = levelConst (tc->t1.sym); level++; } } - trip = tc->tac2; + trip = tc->t2.tac; switch (event) { case READ: @@ -446,22 +446,22 @@ normalDeclaration (Tac tc) { case TAC_VAR: levelDeclareVar (tc); - if (level < 2 && tc->tac3 == NULL) - knowledgeAddTermlist (sys->know, tacTermlist (tc->tac1)); + if (level < 2 && tc->t3.tac == NULL) + knowledgeAddTermlist (sys->know, tacTermlist (tc->t1.tac)); break; case TAC_CONST: levelDeclareConst (tc); - if (level < 2 && tc->tac3 == NULL) - knowledgeAddTermlist (sys->know, tacTermlist (tc->tac1)); + if (level < 2 && tc->t3.tac == NULL) + knowledgeAddTermlist (sys->know, tacTermlist (tc->t1.tac)); break; case TAC_SECRET: levelDeclareConst (tc); break; case TAC_COMPROMISED: - knowledgeAddTermlist (sys->know, tacTermlist (tc->tac1)); + knowledgeAddTermlist (sys->know, tacTermlist (tc->t1.tac)); break; case TAC_INVERSEKEYS: - knowledgeAddInverse (sys->know, tacTerm (tc->tac1), tacTerm (tc->tac2)); + knowledgeAddInverse (sys->know, tacTerm (tc->t1.tac), tacTerm (tc->t2.tac)); break; default: /* abort with false */ @@ -531,7 +531,7 @@ runInstanceCreate (Tac tc) return; /* first, locate the protocol */ - psym = tc->tac1->sym1; + psym = tc->t1.tac->t1.sym; p = sys->protocols; while (p != NULL && p->nameterm->symb != psym) p = p->next; @@ -544,7 +544,7 @@ runInstanceCreate (Tac tc) } /* locate the role */ - rsym = tc->tac1->sym2; + rsym = tc->t1.tac->t2.sym; r = p->roles; while (r != NULL && r->nameterm->symb != rsym) r = r->next; @@ -559,7 +559,7 @@ runInstanceCreate (Tac tc) } /* we now know what we are instancing, equal numbers? */ - instParams = tacTermlist (tc->tac2); + instParams = tacTermlist (tc->t2.tac); if (termlistLength (instParams) != termlistLength (p->rolenames)) { printf @@ -618,7 +618,7 @@ protocolCompile (Symbol prots, Tac tc, Tac tcroles) while (tcroles != NULL) { pr->rolenames = - termlistAppend (pr->rolenames, levelConst (tcroles->sym1)); + termlistAppend (pr->rolenames, levelConst (tcroles->t1.sym)); tcroles = tcroles->next; } @@ -629,21 +629,21 @@ protocolCompile (Symbol prots, Tac tc, Tac tcroles) { case TAC_UNTRUSTED: sys->untrusted = - termlistConcat (sys->untrusted, tacTermlist (tc->tac1)); + termlistConcat (sys->untrusted, tacTermlist (tc->t1.tac)); break; case TAC_ROLE: - t = levelFind (tc->sym1, level); + t = levelFind (tc->t1.sym, level); if (t != NULL) { - roleCompile (t, tc->tac2); + roleCompile (t, tc->t2.tac); } else { printf ("ERROR: undeclared role "); - symbolPrint (tc->sym1); + symbolPrint (tc->t1.sym); printf (" in protocol "); termPrint (pr->nameterm); - errorTac (tc->sym1->lineno); + errorTac (tc->t1.sym->lineno); } break; default: @@ -668,11 +668,11 @@ tacProcess (Tac tc) switch (tc->op) { case TAC_PROTOCOL: - protocolCompile (tc->sym1, tc->tac2, tc->tac3); + protocolCompile (tc->t1.sym, tc->t2.tac, tc->t3.tac); break; case TAC_UNTRUSTED: sys->untrusted = - termlistConcat (sys->untrusted, tacTermlist (tc->tac1)); + termlistConcat (sys->untrusted, tacTermlist (tc->t1.tac)); break; case TAC_RUN: runInstanceCreate (tc); @@ -699,16 +699,16 @@ tacTerm (Tac tc) switch (tc->op) { case TAC_ENCRYPT: - return makeTermEncrypt (tacTerm (tc->tac1), tacTerm (tc->tac2)); + return makeTermEncrypt (tacTerm (tc->t1.tac), tacTerm (tc->t2.tac)); case TAC_TUPLE: - return makeTermTuple (tacTerm (tc->tac1), tacTerm (tc->tac2)); + return makeTermTuple (tacTerm (tc->t1.tac), tacTerm (tc->t2.tac)); case TAC_STRING: { - Term t = symbolFind (tc->sym1); + Term t = symbolFind (tc->t1.sym); if (t == NULL) { printf ("Undeclared symbol "); - symbolPrint (tc->sym1); + symbolPrint (tc->t1.sym); errorTac (tc->lineno); } return t; diff --git a/src/parser.y b/src/parser.y index 52d3a91..81843ea 100644 --- a/src/parser.y +++ b/src/parser.y @@ -67,28 +67,28 @@ spdlrep : /* empty */ spdl : UNTRUSTED termlist ';' { Tac t = tacCreate(TAC_UNTRUSTED); - t->tac1 = $2; + t->t1.tac = $2; $$ = t; } | RUN roleref '(' termlist ')' ';' { Tac t = tacCreate(TAC_RUN); - t->tac1 = $2; - t->tac2 = $4; + t->t1.tac = $2; + t->t2.tac = $4; $$ = t; } | PROTOCOL ID '(' termlist ')' '{' roles '}' optclosing { Tac t = tacCreate(TAC_PROTOCOL); - t->sym1 = $2; - t->tac2 = $7; - t->tac3 = $4; + t->t1.sym = $2; + t->t2.tac = $7; + t->t3.tac = $4; $$ = t; } | USERTYPE termlist ';' { Tac t = tacCreate(TAC_USERTYPE); - t->tac1 = $2; + t->t1.tac = $2; $$ = t; } | declaration @@ -108,8 +108,8 @@ roles : /* empty */ role : ROLE ID '{' roledef '}' optclosing { Tac t = tacCreate(TAC_ROLE); - t->sym1 = $2; - t->tac2 = $4; + t->t1.sym = $2; + t->t2.tac = $4; $$ = t; } ; @@ -130,64 +130,64 @@ roledef : /* empty */ event : READT label '(' termlist ')' ';' { Tac t = tacCreate(TAC_READ); - t->sym1 = $2; + t->t1.sym = $2; /* TODO test here: tac2 should have at least 3 elements */ - t->tac2 = $4; + t->t2.tac = $4; $$ = t; } | SENDT label '(' termlist ')' ';' { Tac t = tacCreate(TAC_SEND); - t->sym1 = $2; + t->t1.sym = $2; /* TODO test here: tac2 should have at least 3 elements */ - t->tac2 = $4; + t->t2.tac = $4; $$ = t; } | CLAIMT label '(' termlist ')' ';' /* TODO maybe claims should be in the syntax */ { Tac t = tacCreate(TAC_CLAIM); - t->sym1 = $2; - t->tac2 = $4; + t->t1.sym = $2; + t->t2.tac = $4; $$ = t; } ; roleref : ID '.' ID { Tac t = tacCreate(TAC_ROLEREF); - t->sym1 = $1; - t->sym2 = $3; + t->t1.sym = $1; + t->t2.sym = $3; $$ = t; } ; declaration : secretpref CONST termlist typeinfo1 ';' { Tac t = tacCreate(TAC_CONST); - t->tac1 = $3; - t->tac2 = $4; - t->tac3 = $1; + t->t1.tac = $3; + t->t2.tac = $4; + t->t3.tac = $1; $$ = t; } | secretpref VAR termlist typeinfoN ';' { Tac t = tacCreate(TAC_VAR); - t->tac1 = $3; - t->tac2 = $4; - t->tac3 = $1; + t->t1.tac = $3; + t->t2.tac = $4; + t->t3.tac = $1; $$ = t; } | SECRET termlist typeinfo1 ';' { Tac t = tacCreate(TAC_SECRET); - t->tac1 = $2; - t->tac2 = $3; + t->t1.tac = $2; + t->t2.tac = $3; $$ = t; } | INVERSEKEYS '(' term ',' term ')' ';' { Tac t = tacCreate(TAC_INVERSEKEYS); - t->tac1 = $3; - t->tac2 = $5; + t->t1.tac = $3; + t->t2.tac = $5; $$ = t; } | COMPROMISED termlist ';' { Tac t = tacCreate(TAC_COMPROMISED); - t->tac1= $2; + t->t1.tac= $2; $$ = t; } ; @@ -210,7 +210,7 @@ typeinfo1 : /* empty */ } | ':' ID { Tac t = tacCreate(TAC_STRING); - t->sym1 = $2; + t->t1.sym = $2; $$ = t; } ; @@ -235,13 +235,13 @@ label : /* empty */ term : ID { Tac t = tacCreate(TAC_STRING); - t->sym1 = $1; + t->t1.sym = $1; $$ = t; } | ID '(' termlist ')' { Tac t = tacCreate(TAC_STRING); - t->sym1 = $1; + t->t1.sym = $1; $$ = tacJoin(TAC_ENCRYPT,tacTuple($3),t,NULL); } | '{' termlist '}' key diff --git a/src/tac.c b/src/tac.c index 55c8a2f..20b6127 100644 --- a/src/tac.c +++ b/src/tac.c @@ -38,9 +38,9 @@ tacCreate (int op) t->op = op; t->next = NULL; t->prev = NULL; - t->tac1 = NULL; - t->tac2 = NULL; - t->tac3 = NULL; + t->t1.tac = NULL; + t->t2.tac = NULL; + t->t3.tac = NULL; return t; } @@ -49,7 +49,7 @@ tacString (char *s) { Tac t; t = tacCreate (TAC_STRING); - t->str1 = s; + t->t1.str = s; return t; } @@ -58,9 +58,9 @@ tacJoin (int op, Tac t1, Tac t2, Tac t3) { Tac t; t = tacCreate (op); - t->tac1 = t1; - t->tac2 = t2; - t->tac3 = t3; + t->t1.tac = t1; + t->t2.tac = t2; + t->t3.tac = t3; return t; } @@ -110,12 +110,12 @@ tacTuple (Tac taclist) { /* otherwise, write as (x,(y,(z,..))) */ tc = tacCreate (TAC_TUPLE); - tc->tac1 = taclist; - tc->tac2 = tacTuple (taclist->next); + tc->t1.tac = taclist; + tc->t2.tac = tacTuple (taclist->next); /* unlink list */ - tc->tac1->next = NULL; - tc->tac2->prev = NULL; + tc->t1.tac->next = NULL; + tc->t2.tac->prev = NULL; } return tc; } @@ -133,64 +133,64 @@ tacPrint (Tac t) switch (t->op) { case TAC_PROTOCOL: - printf ("protocol %s (", t->sym1->text); - tacPrint (t->tac3); + printf ("protocol %s (", t->t1.sym->text); + tacPrint (t->t3.tac); printf (")\n{\n"); - tacPrint (t->tac2); + tacPrint (t->t2.tac); printf ("};\n"); break; case TAC_ROLE: - printf ("role %s\n{\n", t->sym1->text); - tacPrint (t->tac2); + printf ("role %s\n{\n", t->t1.sym->text); + tacPrint (t->t2.tac); printf ("};\n"); break; case TAC_READ: printf ("read"); - if (t->sym1 != NULL) + if (t->t1.sym != NULL) { - printf ("_%s", t->sym1->text); + printf ("_%s", t->t1.sym->text); } printf ("("); - tacPrint (t->tac2); + tacPrint (t->t2.tac); printf (");\n"); break; case TAC_SEND: printf ("send"); - if (t->sym1 != NULL) + if (t->t1.sym != NULL) { - printf ("_%s", t->sym1->text); + printf ("_%s", t->t1.sym->text); } printf ("("); - tacPrint (t->tac2); + tacPrint (t->t2.tac); printf (");\n"); break; case TAC_CLAIM: printf ("claim"); - if (t->sym1 != NULL) + if (t->t1.sym != NULL) { - printf ("_%s", t->sym1->text); + printf ("_%s", t->t1.sym->text); } printf ("("); - tacPrint (t->tac2); + tacPrint (t->t2.tac); printf (");\n"); break; case TAC_CONST: printf ("const "); - tacPrint (t->tac1); - if (t->tac2 != NULL) + tacPrint (t->t1.tac); + if (t->t2.tac != NULL) { printf (" : "); - tacPrint (t->tac2); + tacPrint (t->t2.tac); } printf (";\n"); break; case TAC_VAR: printf ("var "); - tacPrint (t->tac1); - if (t->tac2 != NULL) + tacPrint (t->t1.tac); + if (t->t2.tac != NULL) { printf (" : "); - tacPrint (t->tac2); + tacPrint (t->t2.tac); } printf (";\n"); break; @@ -200,22 +200,22 @@ tacPrint (Tac t) printf (","); break; case TAC_STRING: - printf ("%s", t->sym1->text); + printf ("%s", t->t1.sym->text); if (t->next != NULL) printf (","); break; case TAC_TUPLE: printf ("("); - tacPrint (t->tac1); + tacPrint (t->t1.tac); printf (","); - tacPrint (t->tac2); + tacPrint (t->t2.tac); printf (")"); break; case TAC_ENCRYPT: printf ("{"); - tacPrint (t->tac1); + tacPrint (t->t1.tac); printf ("}"); - tacPrint (t->tac2); + tacPrint (t->t2.tac); if (t->next != NULL) { printf (","); @@ -225,36 +225,36 @@ tacPrint (Tac t) break; case TAC_RUN: printf ("run "); - tacPrint (t->tac1); + tacPrint (t->t1.tac); printf ("("); - tacPrint (t->tac2); + tacPrint (t->t2.tac); printf (");\n"); break; case TAC_ROLEREF: - symbolPrint (t->sym1); + symbolPrint (t->t1.sym); printf ("."); - symbolPrint (t->sym2); + symbolPrint (t->t2.sym); break; case TAC_COMPROMISED: printf ("compromised "); - tacPrint (t->tac1); + tacPrint (t->t1.tac); printf (";\n"); break; case TAC_SECRET: printf ("secret "); - tacPrint (t->tac1); + tacPrint (t->t1.tac); printf (";\n"); break; case TAC_INVERSEKEYS: printf ("inversekeys ("); - tacPrint (t->tac1); + tacPrint (t->t1.tac); printf (","); - tacPrint (t->tac2); + tacPrint (t->t2.tac); printf (");\n"); break; case TAC_UNTRUSTED: printf ("untrusted "); - tacPrint (t->tac1); + tacPrint (t->t1.tac); printf (";\n"); break; default: diff --git a/src/tac.h b/src/tac.h index 7ee7f02..138e754 100644 --- a/src/tac.h +++ b/src/tac.h @@ -37,22 +37,22 @@ struct tacnode int lineno; union { - Symbol sym1; - struct tacnode *tac1; - char *str1; - }; + Symbol sym; + struct tacnode *tac; + char *str; + } t1; + union + { + Symbol sym; + struct tacnode *tac; + char *str; + } t2; union { - Symbol sym2; - struct tacnode *tac2; - char *str2; - }; - union - { - Symbol sym3; - struct tacnode *tac3; - char *str3; - }; + Symbol sym; + struct tacnode *tac; + char *str; + } t3; }; typedef struct tacnode *Tac;