Example #1
0
bool Yap_PrintWarning(Term twarning) {
  CACHE_REGS
  PredEntry *pred = RepPredProp(PredPropByFunc(
      FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2;
  if (twarning)
    __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " warning(%s)",
                        Yap_TermToBuffer(twarning, Quote_illegal_f | Ignore_ops_f | Handle_cyclics_f));
  Term cmod = (CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule);
  bool rc;
  Term ts[2], err;

  
  if (twarning && LOCAL_PrologMode & InErrorMode &&
      LOCAL_ActiveError->errorClass != WARNING &&
      (err = LOCAL_ActiveError->errorNo)  ) {
    fprintf(stderr, "%% Warning %s while processing error: %s %s\n",
            Yap_TermToBuffer(twarning,
                             Quote_illegal_f | Ignore_ops_f),
            Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err));
    return false;
  }
  LOCAL_PrologMode |= InErrorMode;
  if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) {
    fprintf(stderr, "%s:%ld/* d:%d warning */:\n",
	    LOCAL_ActiveError->errorFile,
	    LOCAL_ActiveError->errorLine, 0 );
    if (!twarning)
      twarning =  Yap_MkFullError();
    Yap_DebugPlWriteln(twarning);
    LOCAL_DoingUndefp = false;
    LOCAL_PrologMode &= ~InErrorMode;
    CurrentModule = cmod;
    return false;
  }
    if (!twarning)
      twarning =  Yap_MkFullError();
  ts[1] = twarning;
  ts[0] = MkAtomTerm(AtomWarning);
  rc = Yap_execute_pred(pred, ts, true PASS_REGS);
  LOCAL_within_print_message = false;
  LOCAL_PrologMode &= ~InErrorMode;
  return rc;
   
}
Example #2
0
/**
* Syntax Error Handler
*
* @par tokptr: the sequence of tokens
* @par sno: the stream numbet
*
* Implicit arguments:
*    +
*/
Term Yap_syntax_error(TokEntry *errtok, int sno) {
  CACHE_REGS
  Term info;
  Term startline, errline, endline;
  Term tf[4];
  Term *tailp = tf + 3;
  CELL *Hi = HR;
  TokEntry *tok = LOCAL_tokptr;
  Int cline = tok->TokPos;

  startline = MkIntegerTerm(cline);
  if (errtok != LOCAL_toktide) {
    errtok = LOCAL_toktide;
  }
  LOCAL_Error_TYPE = YAP_NO_ERROR;
  errline = MkIntegerTerm(errtok->TokPos);
  if (LOCAL_ErrorMessage)
    tf[0] = MkStringTerm(LOCAL_ErrorMessage);
  else
    tf[0] = MkStringTerm("");
  while (tok) {
    Term ts[2];

    if (HR > ASP - 1024) {
      errline = MkIntegerTerm(0);
      endline = MkIntegerTerm(0);
      /* for some reason moving this earlier confuses gcc on solaris */
      HR = Hi;
      break;
    }
    if (tok->TokPos != cline) {
      *tailp = MkPairTerm(TermNewLine, TermNil);
      tailp = RepPair(*tailp) + 1;
      cline = tok->TokPos;
    }
    if (tok == errtok && tok->Tok != Error_tok) {
      *tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
      tailp = RepPair(*tailp) + 1;
    }
    info = tok->TokInfo;
    switch (tok->Tok) {
    case Name_tok: {
      Term t0[1];
      if (info) {
        t0[0] = MkAtomTerm((Atom)info);
      } else {
        t0[0] = TermNil;
      }
      ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
    } break;
    case QuasiQuotes_tok: {
      Term t0[2];
      t0[0] = MkAtomTerm(Yap_LookupAtom("<QQ>"));
      ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
    } break;
    case WQuasiQuotes_tok: {
      Term t0[2];
      t0[0] = MkAtomTerm(Yap_LookupAtom("<WideQQ>"));
      ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
    } break;
    case Number_tok:
      ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomNumber, 1), 1, &(tok->TokInfo));
      break;
    case Var_tok: {
      Term t[2];
      VarEntry *varinfo = (VarEntry *)info;

      t[0] = MkIntTerm(0);
      t[1] = Yap_CharsToString(varinfo->VarRep, ENC_ISO_LATIN1 PASS_REGS);
      ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t);
    } break;
    case String_tok: {
      Term t0 =
          Yap_CharsToTDQ((char *)info, CurrentModule, ENC_ISO_LATIN1 PASS_REGS);
      if (!t0) {
        return 0;
      }
      ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
    } break;
    case WString_tok: {
      Term t0 = Yap_WCharsToTDQ((wchar_t *)info, CurrentModule PASS_REGS);
      if (!t0)
        return 0;
      ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
    } break;
    case BQString_tok: {
      Term t0 =
          Yap_CharsToTBQ((char *)info, CurrentModule, ENC_ISO_LATIN1 PASS_REGS);
      ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
    } break;
    case WBQString_tok: {
      Term t0 = Yap_WCharsToTBQ((wchar_t *)info, CurrentModule PASS_REGS);
      ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
    } break;
    case Error_tok: {
      ts[0] = MkAtomTerm(AtomError);
    } break;
    case eot_tok:
      endline = MkIntegerTerm(tok->TokPos);
      ts[0] = MkAtomTerm(Yap_LookupAtom("EOT"));

      break;
    case Ponctuation_tok: {
      char s[2];
      s[1] = '\0';
      if ((info) == 'l') {
        s[0] = '(';
      } else {
        s[0] = (char)info;
      }
      ts[0] = MkAtomTerm(Yap_LookupAtom(s));
    }
    }
    tok = tok->TokNext;
    if (!tok)
      break;
    *tailp = MkPairTerm(ts[0], TermNil);
    tailp = RepPair(*tailp) + 1;
  }
  {
    Term t[3];
    t[0] = startline;
    t[1] = errline;
    t[2] = endline;
    tf[1] = Yap_MkApplTerm(Yap_MkFunctor(AtomBetween, 3), 3, t);
  }
  /* 0: id */
  /* 1: strat, error, end line */
  /*2 msg */
  /* file */
  tf[2] = Yap_StreamUserName(sno);
  clean_vars(LOCAL_VarTable);
  clean_vars(LOCAL_AnonVarTable);
  Term terr = Yap_MkApplTerm(FunctorSyntaxError, 4, tf);
  Term tn[2];
  tn[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, &terr);
  tn[1] = TermNil;
  terr = Yap_MkApplTerm(FunctorError, 2, tn);
#if DEBUG
  if (Yap_ExecutionMode == YAP_BOOT_MODE) {
    fprintf(stderr, "SYNTAX ERROR while booting: ");
    Yap_DebugPlWriteln(terr);
  }
#endif
  return terr;
}
Example #3
0
/**
 * Syntax Error Handler
 *
 * @par tokptr: the sequence of tokens
 * @par sno: the stream numbet
 *
 * Implicit arguments:
 *    +
 */
static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
  CACHE_REGS
  Term startline, errline, endline;
  Term tf[3];
  Term tm;
  Term *tailp = tf + 2;
  CELL *Hi = HR;
  TokEntry *tok = LOCAL_tokptr;
  Int cline = tok->TokPos;

  startline = MkIntegerTerm(cline);
  endline = MkIntegerTerm(cline);
  if (errtok != LOCAL_toktide) {
    errtok = LOCAL_toktide;
  }
  LOCAL_Error_TYPE = YAP_NO_ERROR;
  errline = MkIntegerTerm(errtok->TokPos);
  if (LOCAL_ErrorMessage)
    tm = MkStringTerm(LOCAL_ErrorMessage);
  else
    tm = MkStringTerm("syntax error");
  while (tok) {

    if (HR > ASP - 1024) {
      errline = MkIntegerTerm(0);
      endline = MkIntegerTerm(0);
      /* for some reason moving this earlier confuses gcc on solaris */
      HR = Hi;
      break;
    }
    if (tok->TokPos != cline) {
      *tailp = MkPairTerm(TermNewLine, TermNil);
      tailp = RepPair(*tailp) + 1;
      cline = tok->TokPos;
    }
    if (tok == errtok && tok->Tok != Error_tok) {
      *tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
      tailp = RepPair(*tailp) + 1;
    }
    Term rep = Yap_tokRep(tok);
    if (tok->TokNext) {
      tok = tok->TokNext;
    } else {
      endline = MkIntegerTerm(tok->TokPos);
      tok = NULL;
      break;
    }
    *tailp = MkPairTerm(rep, TermNil);
    tailp = RepPair(*tailp) + 1;
  }
  {
    Term t[3];
    t[0] = startline;
    t[1] = errline;
    t[2] = endline;
    tf[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomBetween, 3), 3, t);
  }
  /* 0:  strat, error, end line */
  /*2 msg */
  /* 1: file */
  tf[1] = Yap_StreamUserName(sno);
  clean_vars(LOCAL_VarTable);
  clean_vars(LOCAL_AnonVarTable);
  Term terr = Yap_MkApplTerm(FunctorInfo3, 3, tf);
  Term tn[2];
  tn[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, &tm);
  tn[1] = terr;
  terr = Yap_MkApplTerm(FunctorError, 2, tn);
#if DEBUG
  if (Yap_ExecutionMode == YAP_BOOT_MODE) {
    fprintf(stderr, "SYNTAX ERROR while booting: ");
    Yap_DebugPlWriteln(terr);
  }
#endif
  return terr;
}