1313#include " cling/Interpreter/Transaction.h"
1414#include " cling/Interpreter/Value.h"
1515#include " cling/Utils/AST.h"
16- #include " cling/Utils/Output.h"
1716
1817#include " clang/AST/ASTContext.h"
1918#include " clang/AST/DeclGroup.h"
@@ -204,7 +203,7 @@ namespace {
204203}
205204
206205 Expr* ValueExtractionSynthesizer::SynthesizeSVRInit (Expr* E) {
207- if (!m_gClingVD && !FindAndCacheRuntimeDecls ())
206+ if (!m_gClingVD && !FindAndCacheRuntimeDecls (E ))
208207 return nullptr ;
209208
210209 // Build a reference to gCling
@@ -407,54 +406,54 @@ namespace {
407406 return Call.get ();
408407 }
409408
410- static bool VSError (const char * err) {
411- cling::errs () << " ValueExtractionSynthesizer error: " << err << " .\n " ;
409+ static bool VSError (clang::Sema* Sema, clang::Expr* E, llvm::StringRef Err) {
410+ DiagnosticsEngine& Diags = Sema->getDiagnostics ();
411+ Diags.Report (E->getLocStart (),
412+ Diags.getCustomDiagID (
413+ clang::DiagnosticsEngine::Level::Error,
414+ " ValueExtractionSynthesizer could not find: '%0'." ))
415+ << Err;
412416 return false ;
413417 }
414418
415- bool ValueExtractionSynthesizer::FindAndCacheRuntimeDecls () {
419+ bool ValueExtractionSynthesizer::FindAndCacheRuntimeDecls (clang::Expr* E ) {
416420 assert (!m_gClingVD && " Called multiple times!?" );
417421 DeclContext* NSD = m_Context->getTranslationUnitDecl ();
418422 clang::VarDecl* clingVD = nullptr ;
419423 if (m_Sema->getLangOpts ().CPlusPlus ) {
420424 if (!(NSD = utils::Lookup::Namespace (m_Sema, " cling" )))
421- return VSError (" cling namespace not defined " );
425+ return VSError (m_Sema, E, " cling namespace" );
422426 if (!(NSD = utils::Lookup::Namespace (m_Sema, " runtime" , NSD)))
423- return VSError (" cling::runtime namespace not defined" );
424- if (!(clingVD = cast<VarDecl>(utils::Lookup::Named (m_Sema, " gCling" ,
425- NSD))))
426- return VSError (" cling::runtime::gCling not defined" );
427- if (!NSD)
428- return VSError (" cling::runtime namespace not defined" );
429-
427+ return VSError (m_Sema, E, " cling::runtime namespace" );
428+ if (!(clingVD = dyn_cast_or_null<VarDecl>(
429+ utils::Lookup::Named (m_Sema, " gCling" , NSD))))
430+ return VSError (m_Sema, E, " cling::runtime::gCling" );
430431 if (!(NSD = utils::Lookup::Namespace (m_Sema, " internal" , NSD)))
431- return VSError (" cling::runtime::internal namespace not defined " );
432+ return VSError (m_Sema, E, " cling::runtime::internal namespace" );
432433 }
433434 LookupResult R (*m_Sema, &m_Context->Idents .get (" setValueNoAlloc" ),
434435 SourceLocation (), Sema::LookupOrdinaryName,
435436 Sema::ForRedeclaration);
436437
437438 m_Sema->LookupQualifiedName (R, NSD);
438439 if (R.empty ())
439- return VSError (" Cannot find cling::runtime::internal::setValueNoAlloc" );
440+ return VSError (m_Sema, E, " cling::runtime::internal::setValueNoAlloc" );
440441
441442 const bool ADL = false ;
442443 CXXScopeSpec CSS;
443444 m_UnresolvedNoAlloc = m_Sema->BuildDeclarationNameExpr (CSS, R, ADL).get ();
444445 if (!m_UnresolvedNoAlloc)
445- return VSError (" Could not build cling::runtime::internal"
446- " ::setValueNoAlloc" );
446+ return VSError (m_Sema, E, " cling::runtime::internal::setValueNoAlloc" );
447447
448448 R.clear ();
449449 R.setLookupName (&m_Context->Idents .get (" setValueWithAlloc" ));
450450 m_Sema->LookupQualifiedName (R, NSD);
451451 if (R.empty ())
452- return VSError (" Cannot find cling::runtime::internal::setValueWithAlloc" );
452+ return VSError (m_Sema, E, " cling::runtime::internal::setValueWithAlloc" );
453453
454454 m_UnresolvedWithAlloc = m_Sema->BuildDeclarationNameExpr (CSS, R, ADL).get ();
455455 if (!m_UnresolvedWithAlloc)
456- return VSError (" Could not build cling::runtime::internal"
457- " ::setValueWithAlloc" );
456+ return VSError (m_Sema, E, " cling::runtime::internal::setValueWithAlloc" );
458457
459458 R.clear ();
460459 R.setLookupName (&m_Context->Idents .get (" copyArray" ));
@@ -466,11 +465,11 @@ namespace {
466465 // Once the import of template functions becomes supported by clang,
467466 // this check can be de-activated.
468467 if (!m_isChildInterpreter && R.empty ())
469- return VSError (" Cannot find cling::runtime::internal::copyArray" );
468+ return VSError (m_Sema, E, " cling::runtime::internal::copyArray" );
470469
471470 m_UnresolvedCopyArray = m_Sema->BuildDeclarationNameExpr (CSS, R, ADL).get ();
472471 if (!m_UnresolvedCopyArray)
473- return VSError (" Could not build cling::runtime::internal::copyArray" );
472+ return VSError (m_Sema, E, " cling::runtime::internal::copyArray" );
474473
475474 m_gClingVD = clingVD;
476475 return true ;
0 commit comments