- Modified error reporting setup.
- Updated some of the error reporting code, but not all.
This commit is contained in:
parent
19724dd086
commit
1c345c4955
@ -121,8 +121,7 @@ levelInit (void)
|
|||||||
level++;
|
level++;
|
||||||
if (level >= MAXLEVELS)
|
if (level >= MAXLEVELS)
|
||||||
{
|
{
|
||||||
printf ("ERROR: level is increased too much\n");
|
error ("level is increased too much.");
|
||||||
exit (1);
|
|
||||||
}
|
}
|
||||||
leveltl[level] = NULL;
|
leveltl[level] = NULL;
|
||||||
}
|
}
|
||||||
@ -132,8 +131,7 @@ levelDone (void)
|
|||||||
{
|
{
|
||||||
if (level < 0)
|
if (level < 0)
|
||||||
{
|
{
|
||||||
printf ("ERROR: level is increased too much\n");
|
error ("level is decreased too much.");
|
||||||
exit (1);
|
|
||||||
}
|
}
|
||||||
leveltl[level] = NULL;
|
leveltl[level] = NULL;
|
||||||
level--;
|
level--;
|
||||||
@ -230,8 +228,7 @@ defineUsertype (Tac tcdu)
|
|||||||
|
|
||||||
if (tc == NULL)
|
if (tc == NULL)
|
||||||
{
|
{
|
||||||
printf ("ERROR: empty usertype declaration.\n");
|
error ("Empty usertype declaration on line %i.", tcdu->lineno);
|
||||||
errorTac (tcdu->lineno);
|
|
||||||
}
|
}
|
||||||
while (tc != NULL && tc->op == TAC_STRING)
|
while (tc != NULL && tc->op == TAC_STRING)
|
||||||
{
|
{
|
||||||
@ -258,10 +255,7 @@ defineUsertype (Tac tcdu)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* that's not right! */
|
/* that's not right! */
|
||||||
printf ("ERROR: conflicting definitions for ");
|
error ("Conflicting definitions in usertype definition on line %i.", tc->lineno);
|
||||||
termPrint (tfind);
|
|
||||||
printf (" in usertype definition ");
|
|
||||||
errorTac (tc->lineno);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tc = tc->next;
|
tc = tc->next;
|
||||||
@ -278,8 +272,7 @@ levelTacDeclaration (Tac tc, int isVar)
|
|||||||
tscan = tc->t2.tac;
|
tscan = tc->t2.tac;
|
||||||
if (!isVar && tscan->next != NULL)
|
if (!isVar && tscan->next != NULL)
|
||||||
{
|
{
|
||||||
printf ("ERROR: Multiple types not allowed for constants ");
|
error ("Multiple type definition for constant on line %i.", tscan->lineno);
|
||||||
errorTac (tscan->lineno);
|
|
||||||
}
|
}
|
||||||
while (tscan != NULL && tscan->op == TAC_STRING)
|
while (tscan != NULL && tscan->op == TAC_STRING)
|
||||||
{
|
{
|
||||||
@ -289,17 +282,13 @@ levelTacDeclaration (Tac tc, int isVar)
|
|||||||
if (t == NULL)
|
if (t == NULL)
|
||||||
{
|
{
|
||||||
/* not declared, that is unacceptable. */
|
/* not declared, that is unacceptable. */
|
||||||
printf ("ERROR: type ");
|
error ("Undeclared type on line %i.", tscan->lineno);
|
||||||
symbolPrint (tscan->t1.sym);
|
|
||||||
printf (" was not declared ");
|
|
||||||
errorTac (tscan->lineno);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!inTermlist (t->stype, TERM_Type))
|
if (!inTermlist (t->stype, TERM_Type))
|
||||||
{
|
{
|
||||||
printf ("ERROR: non-type constant in type declaration ");
|
error ("Non-type constant in type declaration on line %i.", tscan->lineno);
|
||||||
errorTac (tscan->lineno);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
typetl = termlistAdd (typetl, t);
|
typetl = termlistAdd (typetl, t);
|
||||||
@ -352,8 +341,7 @@ commEvent (int event, Tac tc)
|
|||||||
/* now parse triplet info */
|
/* now parse triplet info */
|
||||||
if (trip == NULL || trip->next == NULL || trip->next->next == NULL)
|
if (trip == NULL || trip->next == NULL || trip->next->next == NULL)
|
||||||
{
|
{
|
||||||
printf ("ERROR in %i event ", event);
|
error ("Problem with %i event on line %i.", event, tc->lineno);
|
||||||
errorTac (tc->lineno);
|
|
||||||
}
|
}
|
||||||
fromrole = tacTerm (trip);
|
fromrole = tacTerm (trip);
|
||||||
torole = tacTerm (trip->next);
|
torole = tacTerm (trip->next);
|
||||||
@ -364,8 +352,7 @@ commEvent (int event, Tac tc)
|
|||||||
/* now parse tuple info */
|
/* now parse tuple info */
|
||||||
if (trip == NULL || trip->next == NULL)
|
if (trip == NULL || trip->next == NULL)
|
||||||
{
|
{
|
||||||
printf ("ERROR in %i event ", event);
|
error ("Problem with %i event on line %i.", event, tc->lineno);
|
||||||
errorTac (tc->lineno);
|
|
||||||
}
|
}
|
||||||
fromrole = tacTerm (trip);
|
fromrole = tacTerm (trip);
|
||||||
claimbig = tacTerm (tacTuple ((trip->next)));
|
claimbig = tacTerm (tacTuple ((trip->next)));
|
||||||
@ -375,8 +362,7 @@ commEvent (int event, Tac tc)
|
|||||||
/* check for obvious flaws */
|
/* check for obvious flaws */
|
||||||
if (claim == NULL)
|
if (claim == NULL)
|
||||||
{
|
{
|
||||||
printf ("ERROR: invalid claim specification ");
|
error ("Invalid claim specification on line %i.", tc->lineno);
|
||||||
errorTac (trip->next->lineno);
|
|
||||||
}
|
}
|
||||||
if (!inTermlist (claim->stype, TERM_Claim))
|
if (!inTermlist (claim->stype, TERM_Claim))
|
||||||
{
|
{
|
||||||
@ -398,9 +384,7 @@ commEvent (int event, Tac tc)
|
|||||||
msg = deVar (claimbig)->right.op2;
|
msg = deVar (claimbig)->right.op2;
|
||||||
if (tupleCount (msg) != n)
|
if (tupleCount (msg) != n)
|
||||||
{
|
{
|
||||||
printf
|
error ("Problem with claim tuple unfolding at line %i.", trip->next->lineno);
|
||||||
("ERROR: something went wrong in the claim tuple parameter unfolding ");
|
|
||||||
errorTac (trip->next->lineno);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,9 +394,7 @@ commEvent (int event, Tac tc)
|
|||||||
{
|
{
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
{
|
{
|
||||||
printf
|
error ("Secrecy claim requires a list of terms to be secret on line %i.",trip->next->lineno);
|
||||||
("ERROR: secrecy claim requires a list of terms to be secret ");
|
|
||||||
errorTac (trip->next->lineno);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -420,8 +402,7 @@ commEvent (int event, Tac tc)
|
|||||||
{
|
{
|
||||||
if (n != 0)
|
if (n != 0)
|
||||||
{
|
{
|
||||||
printf ("ERROR: nisynch claim has no parameters ");
|
error ("NISYNCH claim requires no parameters at line %i.", trip->next->lineno);
|
||||||
errorTac (trip->next->lineno);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
44
src/error.c
44
src/error.c
@ -2,19 +2,55 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
|
//! Die from error with exit code
|
||||||
|
void
|
||||||
|
error_die (void)
|
||||||
|
{
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Print error message header
|
||||||
|
/**
|
||||||
|
* Adapted from [K&R2], p. 174
|
||||||
|
*@todo It would be nice to redirect all output to stderr, which would enable use of termprint etc.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
error_pre (void)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "error: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Print post-error message and die.
|
||||||
|
/**
|
||||||
|
* Adapted from [K&R2], p. 174
|
||||||
|
* Input is comparable to printf, only end of line is not required.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
error_post (char *fmt, ... )
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start (args, fmt);
|
||||||
|
vfprintf (stderr, fmt, args);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
va_end (args);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
//! Print error message and die.
|
//! Print error message and die.
|
||||||
/**
|
/**
|
||||||
* Adapted from [K&R2], p. 174
|
* Adapted from [K&R2], p. 174
|
||||||
* Input is comparable to printf, only end of line is not required.
|
* Input is comparable to printf, only end of line is not required.
|
||||||
*/
|
*/
|
||||||
void error (char *fmt, ...)
|
void
|
||||||
|
error (char *fmt, ... )
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
|
error_pre ();
|
||||||
va_start (args, fmt);
|
va_start (args, fmt);
|
||||||
fprintf (stderr, "error: ");
|
vfprintf (stderr, fmt, args);
|
||||||
vprintf (stderr, fmt, args);
|
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
va_end (args);
|
va_end (args);
|
||||||
exit(1);
|
error_die ();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#ifndef ERROR
|
#ifndef ERROR
|
||||||
#define ERROR
|
#define ERROR
|
||||||
|
|
||||||
void error (char *fmt, ...)
|
void error_die (void);
|
||||||
|
void error_pre (void);
|
||||||
|
void error_post (char *fmt, ... );
|
||||||
|
void error (char *fmt, ... );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -274,8 +274,7 @@ int yyerror(char *s)
|
|||||||
extern int yylineno; // defined and maintained in lex.c
|
extern int yylineno; // defined and maintained in lex.c
|
||||||
extern char *yytext; // defined and maintained in lex.c
|
extern char *yytext; // defined and maintained in lex.c
|
||||||
|
|
||||||
printf("\nERROR %s at symbol %s on line %i.\n", s, yytext, yylineno);
|
error ("%s at symbol '%s' on line %i.\n", s, yytext, yylineno);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user