foreign_t pl_getPresumedLoc(term_t DeclT, term_t FilenameT,
                             term_t LineT, term_t ColT) {
   const Decl *D;
   if ( !PL_get_pointer(DeclT, (void **) &D))
     return PL_warning("getPresumedLoc/4: instantiation fault on first arg");
   const SourceManager &SM = getCompilationInfo()->getSourceManager();
   const PresumedLoc PL = SM.getPresumedLoc(D->getLocation());
   if ( !PL_unify_atom_chars(FilenameT, PL.getFilename())) return FALSE;
   if ( !PL_unify_int64(LineT, (int64_t) PL.getLine())) return FALSE;
   return PL_unify_int64(ColT, (int64_t) PL.getColumn());
 }
Beispiel #2
0
static foreign_t python_export(term_t t, term_t pl) {
  foreign_t rc = false;
  if (PL_is_functor(t, FUNCTOR_pointer1)) {
    void *ptr;
    term_t targ = PL_new_term_ref();

    if (!PL_get_arg(1, t, targ)) {
      return false;
    }
    if (!PL_get_pointer(targ, &ptr)) {
      return false;
    }
    Py_INCREF((PyObject *)ptr);
    /* return __main__,s */
    rc = python_to_term((PyObject *)ptr, pl);
  }
  return rc;
}
Beispiel #3
0
static foreign_t
pl_gdImagePng(term_t im_term, term_t filename_term)
{ 
  gdImagePtr im;
  void *im_ptr;
  char *filename;
  FILE *out;

  if ( PL_get_atom_chars(filename_term, &filename) && PL_get_pointer(im_term, &im_ptr) )
    { 
      im = (gdImagePtr)im_ptr;
      out = fopen(filename,"wb");
      if (out) {
        gdImagePng(im,out);
        PL_succeed;
      }
    }

  PL_fail;
}
Beispiel #4
0
static int
get_timer(term_t t, Event *ev)
{ if ( PL_is_functor(t, FUNCTOR_alarm1) )
  { term_t a = PL_new_term_ref();
    void *p;

    _PL_get_arg(1, t, a);
    if ( PL_get_pointer(a, &p) )
    { Event e = p;

      if ( e->magic == EV_MAGIC )
      { *ev = e;
        return TRUE;
      } else
      { return pl_error("get_timer", 1, NULL,
			ERR_DOMAIN, t, "alarm");
      }
    }
  }

  return pl_error("get_timer", 1, NULL,
		  ERR_ARGTYPE, 1, t, "alarm");
}
    foreign_t pl_reportViolation(term_t RuleT, term_t MsgT, term_t CulpritsT) {
      // FIXME: all 'return FALSE' should be PL_warning'
      const char *Rule;
      if ( !PL_get_atom_chars(RuleT, (char **) &Rule)) return FALSE;
      const char *Msg;
      if ( !PL_get_atom_chars(MsgT, (char **) &Msg)) return FALSE;
      // atom_t StmtA = PL_new_atom("stmt");
      // functor_t StmtF = PL_new_functor(StmtA, 1);
      atom_t NamedDeclA = PL_new_atom("NamedDecl");
      functor_t NamedDeclF = PL_new_functor(NamedDeclA, 2);

      // functor_t SortF;
      // if ( !PL_get_functor(LocT, &SortF)) return FALSE;
      // term_t ElemT = PL_new_term_ref();
      // if ( !PL_get_arg(1, LocT, ElemT)) return FALSE;
      // SourceLocation SL;
      // if ( PL_unify_functor(LocT, StmtF)) {
      //   Stmt *S;
      //   if ( !PL_get_pointer(ElemT, (void **) &S)) return FALSE;
      //   SL = S->getLocStart();
      // }
      // // FIXME: same for Decl and other elems.

      const CompilerInstance &CI = getCompilationInfo()->getCompilerInstance();
      DiagnosticsEngine &DE = CI.getDiagnostics();
      Twine MsgWithRule = Twine(Rule) + Twine(": ") + Twine(Msg);
      unsigned DiagId = DE.getCustomDiagID(DiagnosticsEngine::Warning,
                                           MsgWithRule.str());
      DiagnosticBuilder DB = DE.Report(DiagId);

      term_t HeadT = PL_new_term_ref();
      term_t ListT = PL_copy_term_ref(CulpritsT); // copy as we need to write
      while(PL_get_list(ListT, HeadT, ListT)) {
        term_t ElemT = PL_new_term_ref();
        if ( !PL_get_arg(1, HeadT, ElemT)) return FALSE;
        if ( PL_unify_functor(HeadT, NamedDeclF)) {
          const NamedDecl *ND;
          if ( !PL_get_pointer(ElemT, (void **) &ND)) return FALSE;
          DB << ND->getDeclName();
          continue;
        }
        // FIXME: same for Type and other elems
      }
      DB.~DiagnosticBuilder();  // Emits the diagnostic

      ListT = PL_copy_term_ref(CulpritsT);
      while(PL_get_list(ListT, HeadT, ListT)) {
        functor_t SortF;
        if ( !PL_get_functor(HeadT, &SortF)) return FALSE;
        term_t ElemT = PL_new_term_ref();
        if ( !PL_get_arg(1, HeadT, ElemT)) return FALSE;
        term_t MsgT = PL_new_term_ref();
        if ( !PL_get_arg(2, HeadT, MsgT)) return FALSE;
        const char *Msg;
        if ( !PL_get_atom_chars(MsgT, (char **) &Msg)) return FALSE;
        if ( PL_unify_functor(HeadT, NamedDeclF)) {
          const NamedDecl *ND;
          if ( !PL_get_pointer(ElemT, (void **) &ND)) return FALSE;
          DiagId = DE.getCustomDiagID(DiagnosticsEngine::Note, Msg);
          DiagnosticBuilder DB = DE.Report(ND->getLocStart(), DiagId);
          DB << ND->getDeclName();
          DB.~DiagnosticBuilder(); // Emits the diagnostic
          continue;
        }
        // FIXME: same for Type and other elems
      }

      return TRUE;
    }