view anagram/agcore/error.cpp @ 4:bebb2ba69e1d

maybe help with getting tex to fail properly on error
author David A. Holland
date Sat, 18 Apr 2020 17:12:17 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * error.cpp - Error reporting module
 */

#include "config.h"
#include "error.h"
#include "pgg24-defs.h"
#include "stacks.h"

//#define INCLUDE_LOGGING
#include "log.h"


AgString errorReportFile("");

int charRangeDiagnostic;
int negativeCharDiagnostic;
int eventDrivenDiagnostic;
int errorResynchDiagnostic;

AgStack<Error> errorList;

const char *Error::keyString[] = {"Warning", "Error"};

void reset_errors(void) {
  charRangeDiagnostic = 0;
  eventDrivenDiagnostic = 0;
  negativeCharDiagnostic = 0;
  errorResynchDiagnostic = 0;
}

void checkParams() {
  LOGSECTION("checkParams");
  if (!eventDrivenDiagnostic && event_driven && pointer_input) {
    eventDrivenDiagnostic = 1;
    log_error("Event driven parser cannot use pointer input");
  }
  if (!errorResynchDiagnostic && error_token && auto_resynch) {
    log_error("Both error token resynch and auto resynch specified");
    errorResynchDiagnostic = 1;
  }
}

/*
 * XXX. Sometime we need to go through and check up on all calls to
 * the next two versions of log_error(), distinguishing those where
 * a meaningful location can be fetched from the pgg24 PCB and 
 * those that should have no location.
 *
 * (Note: the direct Error constructor calls have been checked.)
 */

void log_error(const char *msg) {
  LOGSECTION("log_error(const char *)");
  errorList.push(Error(pgcb.line, pgcb.column, msg));
}

void log_error() {
  LOGSECTION("log_error()");
  LOGS(string_base);
  errorList.push(Error(pgcb.line, pgcb.column, string_base));
  rcs();
}

void log_error(int l, int c) {
  LOGSECTION("log_error(int,int)");
  LOGV(l) LCV(c) LV(string_base);
  errorList.push(Error(l, c, string_base));
  rcs();
}

/* 
 * XXX the equivalent of this function used to always report the last
 * line and column, not the first. But this function is for cases
 * where that's not appropriate, so how about arranging things so it
 * doesn't report any at all?
 */

Error::Error(AgString msg)
  : file(errorReportFile),
    line(1),
    column(1),
    key(warn),
    message(msg)
{
  LOGSECTION("Error::Error(AgString)");
  // Nothing here
}

Error::Error(int l, int c, AgString msg)
  : file(errorReportFile),
    line(l),
    column(c),
    key(warn),
    message(msg)
{
  LOGSECTION("Error::Error(int, int, AgString)");
  LOGV(line) LCV(column) LCV(msg.pointer());
  // Nothing here
}

Error::Error(int l, int c, AgString f, AgString msg)
  : file(f),
    line(l),
    column(c),
    key(warn),
    message(msg)
{
  // Nothing here
}