@@ -205,7 +205,7 @@ namespace {
205205}
206206
207207 Expr* ValueExtractionSynthesizer::SynthesizeSVRInit (Expr* E) {
208- if (!m_gClingVD && !FindAndCacheRuntimeDecls ())
208+ if (!m_gClingVD && !FindAndCacheRuntimeDecls (E ))
209209 return nullptr ;
210210
211211 // Build a reference to gCling
@@ -408,54 +408,54 @@ namespace {
408408 return Call.get ();
409409 }
410410
411- static bool VSError (const char * err) {
412- cling::errs () << " ValueExtractionSynthesizer error: " << err << " .\n " ;
411+ static bool VSError (clang::Sema* Sema, clang::Expr* E, llvm::StringRef Err) {
412+ DiagnosticsEngine& Diags = Sema->getDiagnostics ();
413+ Diags.Report (E->getLocStart (),
414+ Diags.getCustomDiagID (
415+ clang::DiagnosticsEngine::Level::Error,
416+ " ValueExtractionSynthesizer could not find: '%0'." ))
417+ << Err;
413418 return false ;
414419 }
415420
416- bool ValueExtractionSynthesizer::FindAndCacheRuntimeDecls () {
421+ bool ValueExtractionSynthesizer::FindAndCacheRuntimeDecls (clang::Expr* E ) {
417422 assert (!m_gClingVD && " Called multiple times!?" );
418423 DeclContext* NSD = m_Context->getTranslationUnitDecl ();
419424 clang::VarDecl* clingVD = nullptr ;
420425 if (m_Sema->getLangOpts ().CPlusPlus ) {
421426 if (!(NSD = utils::Lookup::Namespace (m_Sema, " cling" )))
422- return VSError (" cling namespace not defined " );
427+ return VSError (m_Sema, E, " cling namespace" );
423428 if (!(NSD = utils::Lookup::Namespace (m_Sema, " runtime" , NSD)))
424- return VSError (" cling::runtime namespace not defined" );
425- if (!(clingVD = cast<VarDecl>(utils::Lookup::Named (m_Sema, " gCling" ,
426- NSD))))
427- return VSError (" cling::runtime::gCling not defined" );
428- if (!NSD)
429- return VSError (" cling::runtime namespace not defined" );
430-
429+ return VSError (m_Sema, E, " cling::runtime namespace" );
430+ if (!(clingVD = dyn_cast_or_null<VarDecl>(
431+ utils::Lookup::Named (m_Sema, " gCling" , NSD))))
432+ return VSError (m_Sema, E, " cling::runtime::gCling" );
431433 if (!(NSD = utils::Lookup::Namespace (m_Sema, " internal" , NSD)))
432- return VSError (" cling::runtime::internal namespace not defined " );
434+ return VSError (m_Sema, E, " cling::runtime::internal namespace" );
433435 }
434436 LookupResult R (*m_Sema, &m_Context->Idents .get (" setValueNoAlloc" ),
435437 SourceLocation (), Sema::LookupOrdinaryName,
436438 Sema::ForRedeclaration);
437439
438440 m_Sema->LookupQualifiedName (R, NSD);
439441 if (R.empty ())
440- return VSError (" Cannot find cling::runtime::internal::setValueNoAlloc" );
442+ return VSError (m_Sema, E, " cling::runtime::internal::setValueNoAlloc" );
441443
442444 const bool ADL = false ;
443445 CXXScopeSpec CSS;
444446 m_UnresolvedNoAlloc = m_Sema->BuildDeclarationNameExpr (CSS, R, ADL).get ();
445447 if (!m_UnresolvedNoAlloc)
446- return VSError (" Could not build cling::runtime::internal"
447- " ::setValueNoAlloc" );
448+ return VSError (m_Sema, E, " cling::runtime::internal::setValueNoAlloc" );
448449
449450 R.clear ();
450451 R.setLookupName (&m_Context->Idents .get (" setValueWithAlloc" ));
451452 m_Sema->LookupQualifiedName (R, NSD);
452453 if (R.empty ())
453- return VSError (" Cannot find cling::runtime::internal::setValueWithAlloc" );
454+ return VSError (m_Sema, E, " cling::runtime::internal::setValueWithAlloc" );
454455
455456 m_UnresolvedWithAlloc = m_Sema->BuildDeclarationNameExpr (CSS, R, ADL).get ();
456457 if (!m_UnresolvedWithAlloc)
457- return VSError (" Could not build cling::runtime::internal"
458- " ::setValueWithAlloc" );
458+ return VSError (m_Sema, E, " cling::runtime::internal::setValueWithAlloc" );
459459
460460 R.clear ();
461461 R.setLookupName (&m_Context->Idents .get (" copyArray" ));
@@ -467,11 +467,11 @@ namespace {
467467 // Once the import of template functions becomes supported by clang,
468468 // this check can be de-activated.
469469 if (!m_isChildInterpreter && R.empty ())
470- return VSError (" Cannot find cling::runtime::internal::copyArray" );
470+ return VSError (m_Sema, E, " cling::runtime::internal::copyArray" );
471471
472472 m_UnresolvedCopyArray = m_Sema->BuildDeclarationNameExpr (CSS, R, ADL).get ();
473473 if (!m_UnresolvedCopyArray)
474- return VSError (" Could not build cling::runtime::internal::copyArray" );
474+ return VSError (m_Sema, E, " cling::runtime::internal::copyArray" );
475475
476476 m_gClingVD = clingVD;
477477 return true ;
0 commit comments