/**********************************************************************/
/*                                                                    */
/*   "DP_ERROR.C"                                                     */
/*                                                                    */
/*   Last change    == Mar-07-92 ==                                   */
/*        A.Just / R.Hammer                                           */
/*                                                                    */
/* errorhandling, used when working on dotprecision-compiling         */
/*                                                                    */
/* Feb-01-92 Just : function 'd_checkerr()' will only exist with      */
/*                  macro CHECK defined.                              */
/* Feb-01-92 Just : Macro WPRINT_ON and dependend include of          */
/*                  "DP_UTIL.INC" added,                              */
/*                  'd_trace()' moved to "DP_UTIL.INC".               */
/* Feb-11-92 Just : Calls to function 'checkerror()' removed.         */
/* Mar-07-92 Just : macro 'NEW_PROTO' --> 'LINT_ARGS'                 */
/*                                                                    */
/**********************************************************************/



/* #define TRACE_ON   */
/* #define WPRINT_ON */




#include <stdio.h>
#include <stdlib.h>

#include "impor.t"
#include    "error.h"
#include    "scan.h"
#include    "symtab.h"
#include    "idtab.h"
#include    "blktab.h"
#include    "optab.h"
#include    "bintab.h"
#include    "arrx.h"
#include    "option.h"

#include    "dp_nodes.h"
#include "expor.t"
#include   "dp_error.h"
#include "implemen.t"


#if defined(TRACE_ON) || defined(WPRINT_ON)
#include "dp_util.inc"
#endif



/**************************************************************************/



#ifdef LINT_ARGS
void d_critical(char *errstr)
#else
void d_critical(errstr)
char      *errstr;
#endif

/*--------------------------------------------------------------------*/
/* handling of critical errors. Thous are errors, which make it im-   */
/* possible to go on working on the tree.                             */
/*--------------------------------------------------------------------*/
/* errstr = pointer to the error message                              */
/*--------------------------------------------------------------------*/

{

#ifdef TRACE_ON
     d_trace("'d_critical()'");
#endif


     (void)  fprintf(stderr,
             "\n\n\007Critical error occured in dotprecision handling:\n");
     (void) fprintf(stderr,"%s\n\n",errstr);
     printline();
     (void) fprintf(stderr,"\nFunction 'dotseman()' will be abandoned!\n");
     (void) fprintf(stderr,"The dotexpression won't be compiled!\n");
     (void) fprintf(stderr,"Type RETURN to go on!\n");
     (void) getchar();
     longjmp(d_critjmp,-1);

} /* d_critical() */



/**************************************************************************/



#ifdef LINT_ARGS
void d_noncritical(char flags,d_errtype err_num,tNODE *ptr)
#else
void d_noncritical(flags,err_num,ptr)
char      flags;
d_errtype err_num;
tNODE     *ptr;
#endif

/*--------------------------------------------------------------------*/
/* handling of noncritical errors. The program won't be interrupted,  */
/* but the result of the compilation will probably be false.          */
/*--------------------------------------------------------------------*/
/* flags, err_num = error flags and number                            */
/* ptr            = pointer to the work node                          */
/*--------------------------------------------------------------------*/

{
     tNODE     *pl,*pr;
     postype   err_pos;



#ifdef TRACE_ON
     d_trace("'d_noncritical()'");
#endif


     err_pos = pos;
     if( ptr == NULL )goto print_err;


     if( !( flags & dSELF ) )goto do_1st;
     if(  ( flags & dSTRUC ) && ( ptr->structure==no_structype )   )return;
     if(  ( flags & dBASE  ) && ( ptr->basetype ==no_arithtype )   )return;
     goto get_pos;

do_1st:
     if( ((pl=ptr->left)==NULL) )goto do_2nd;
     if( ( flags & dSTRUC ) && ( pl->structure==no_structype )   )return;
     if( ( flags & dBASE  ) && ( pl->basetype ==no_arithtype )   )return;

do_2nd:
     if( ((pr=ptr->right)==NULL) )goto get_pos;
     if(   ( flags & dSTRUC ) && ( pr->structure==no_structype )   )return;
     if(   ( flags & dBASE  ) && ( pr->basetype ==no_arithtype )   )return;



get_pos:
     err_pos = ptr->pos;
print_err:
     errput (err_num, err_pos, (char*)0 );

} /* d_noncritical() */



/**************************************************************************/



#ifdef LINT_ARGS
global void d_warn( d_warntype err_num, postype err_pos )
#else
global void d_warn(err_num,err_pos)
d_warntype     err_num;
postype        err_pos;
#endif

/*--------------------------------------------------------------------*/
/* The function sends a warning message to the error output.          */
/*--------------------------------------------------------------------*/
/* err_num = number of warning message                                */
/* err_pos = position in source text                                  */
/*--------------------------------------------------------------------*/

{
     if ( !on_warning ) return;


#ifdef CHECK
     if( (err_num<=dw_start) || (err_num>=wMAX_WARN) ){
          char s[64];
          sprintf(s,"Check in line %4d col %2d: ",err_pos.line,err_pos.col);
          print(s);
          print("Illegal warning number in dotexpression!");
          printline();}
#endif

     errput(err_num,err_pos,NULL);

} /* d_warn() */



/***************************************************************************/



#ifdef CHECK


#ifdef LINT_ARGS
global void d_checkerr( d_checktype err_num, postype err_pos, char *str )
#else
global void d_checkerr(err_num,err_pos,str)
d_checktype    err_num;
postype        err_pos;
char           *str;
#endif

/*--------------------------------------------------------------------*/
/* The function sends a checkerror message to the error output.       */
/*--------------------------------------------------------------------*/
/* err_num = number of checkerror                                     */
/* err_pos = position in source text                                  */
/*--------------------------------------------------------------------*/

{
     if( (err_num<=dc_start) || (err_num>=cMAX_CHECK) ){
          char s[64];
          sprintf(s,"Check in line %4d col %2d: ",err_pos.line,err_pos.col);
          print(s);
          print("Illegal checkerror number in dotexpression!");
          printline();}

     errput(err_num,err_pos,str);

} /* d_checkerr() */


#endif



/***************************************************************************/
