1212#include " cling/Interpreter/Interpreter.h"
1313#include " cling/Interpreter/Transaction.h"
1414#include " cling/Interpreter/Value.h"
15-
1615#include " cling/Utils/AST.h"
16+ #include " cling/Utils/Output.h"
1717
1818#include " clang/AST/ASTContext.h"
1919#include " clang/AST/DeclGroup.h"
@@ -204,8 +204,8 @@ namespace {
204204}
205205
206206 Expr* ValueExtractionSynthesizer::SynthesizeSVRInit (Expr* E) {
207- if (!m_gClingVD)
208- FindAndCacheRuntimeDecls () ;
207+ if (!m_gClingVD && ! FindAndCacheRuntimeDecls () )
208+ return nullptr ;
209209
210210 // Build a reference to gCling
211211 ExprResult gClingDRE
@@ -407,34 +407,54 @@ namespace {
407407 return Call.get ();
408408 }
409409
410- void ValueExtractionSynthesizer::FindAndCacheRuntimeDecls () {
410+ static bool VSError (const char * err) {
411+ cling::errs () << " ValueExtractionSynthesizer error: " << err << " .\n " ;
412+ return false ;
413+ }
414+
415+ bool ValueExtractionSynthesizer::FindAndCacheRuntimeDecls () {
411416 assert (!m_gClingVD && " Called multiple times!?" );
412417 DeclContext* NSD = m_Context->getTranslationUnitDecl ();
418+ clang::VarDecl* clingVD = nullptr ;
413419 if (m_Sema->getLangOpts ().CPlusPlus ) {
414- NSD = utils::Lookup::Namespace (m_Sema, " cling" );
415- NSD = utils::Lookup::Namespace (m_Sema, " runtime" , NSD);
416- m_gClingVD = cast<VarDecl>(utils::Lookup::Named (m_Sema, " gCling" , NSD));
417- NSD = utils::Lookup::Namespace (m_Sema, " internal" ,NSD);
420+ if (!(NSD = utils::Lookup::Namespace (m_Sema, " cling" )))
421+ return VSError (" cling namespace not defined" );
422+ 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+
430+ if (!(NSD = utils::Lookup::Namespace (m_Sema, " internal" , NSD)))
431+ return VSError (" cling::runtime::internal namespace not defined" );
418432 }
419433 LookupResult R (*m_Sema, &m_Context->Idents .get (" setValueNoAlloc" ),
420434 SourceLocation (), Sema::LookupOrdinaryName,
421435 Sema::ForRedeclaration);
422436
423437 m_Sema->LookupQualifiedName (R, NSD);
424- assert (! R.empty ()
425- && " Cannot find cling::runtime::internal::setValueNoAlloc" );
438+ if ( R.empty () )
439+ return VSError ( " Cannot find cling::runtime::internal::setValueNoAlloc" );
426440
441+ const bool ADL = false ;
427442 CXXScopeSpec CSS;
428- m_UnresolvedNoAlloc
429- = m_Sema->BuildDeclarationNameExpr (CSS, R, /* ADL*/ false ).get ();
443+ m_UnresolvedNoAlloc = m_Sema->BuildDeclarationNameExpr (CSS, R, ADL).get ();
444+ if (!m_UnresolvedNoAlloc)
445+ return VSError (" Could not build cling::runtime::internal"
446+ " ::setValueNoAlloc" );
430447
431448 R.clear ();
432449 R.setLookupName (&m_Context->Idents .get (" setValueWithAlloc" ));
433450 m_Sema->LookupQualifiedName (R, NSD);
434- assert (!R.empty ()
435- && " Cannot find cling::runtime::internal::setValueWithAlloc" );
436- m_UnresolvedWithAlloc
437- = m_Sema->BuildDeclarationNameExpr (CSS, R, /* ADL*/ false ).get ();
451+ if (R.empty ())
452+ return VSError (" Cannot find cling::runtime::internal::setValueWithAlloc" );
453+
454+ m_UnresolvedWithAlloc = m_Sema->BuildDeclarationNameExpr (CSS, R, ADL).get ();
455+ if (!m_UnresolvedWithAlloc)
456+ return VSError (" Could not build cling::runtime::internal"
457+ " ::setValueWithAlloc" );
438458
439459 R.clear ();
440460 R.setLookupName (&m_Context->Idents .get (" copyArray" ));
@@ -445,10 +465,15 @@ namespace {
445465 // parent interpreter, but it will fail, because this is a template function.
446466 // Once the import of template functions becomes supported by clang,
447467 // this check can be de-activated.
448- if (!m_isChildInterpreter)
449- assert (!R.empty () && " Cannot find cling::runtime::internal::copyArray" );
450- m_UnresolvedCopyArray
451- = m_Sema->BuildDeclarationNameExpr (CSS, R, /* ADL*/ false ).get ();
468+ if (!m_isChildInterpreter && R.empty ())
469+ return VSError (" Cannot find cling::runtime::internal::copyArray" );
470+
471+ m_UnresolvedCopyArray = m_Sema->BuildDeclarationNameExpr (CSS, R, ADL).get ();
472+ if (!m_UnresolvedCopyArray)
473+ return VSError (" Could not build cling::runtime::internal::copyArray" );
474+
475+ m_gClingVD = clingVD;
476+ return true ;
452477 }
453478} // end namespace cling
454479
0 commit comments