コード例 #1
0
  void EvaluateTSynthesizer::Transform() {
    if (!getTransaction()->getCompilationOpts().DynamicScoping)
      return;

    // Find DynamicLookup specific builtins
    if (!m_EvalDecl) {
      Initialize();
    }

    const Transaction* T = getTransaction();
    for (Transaction::const_iterator I = T->decls_begin(), E = T->decls_end();
         I != E; ++I) {
      // Copy DCI; it might get relocated below.
      Transaction::DelayCallInfo DCI = *I;
      for (DeclGroupRef::const_iterator J = DCI.m_DGR.begin(), 
             JE = DCI.m_DGR.end(); J != JE; ++J)
        if (ShouldVisit(*J) && (*J)->hasBody()) {
          if (FunctionDecl* FD = dyn_cast<FunctionDecl>(*J)) {
            // Set the decl context, which is needed by Evaluate.
            m_CurDeclContext = FD;
            ASTNodeInfo NewBody = Visit((*J)->getBody());
            FD->setBody(NewBody.getAsSingleNode());
          }
          assert ((!isa<BlockDecl>(*J) || !isa<ObjCMethodDecl>(*J))
                  && "Not implemented yet!");
        }
    }

    //TODO: Check for error before returning.
  }
コード例 #2
0
  void EvaluateTSynthesizer::Transform() {
    if (!getTransaction()->getCompilationOpts().DynamicScoping)
      return;

    // include the DynamicLookup specific builtins
    if (!m_EvalDecl) {
      TemplateDecl* D
        = cast_or_null<TemplateDecl>(m_Interpreter->LookupDecl("cling").
                                     LookupDecl("runtime").
                                     LookupDecl("internal").
                                     LookupDecl("EvaluateT").
                                     getSingleDecl());
      assert(D && "Cannot find EvaluateT TemplateDecl!\n");

      m_EvalDecl = dyn_cast<FunctionDecl>(D->getTemplatedDecl());
      assert (m_EvalDecl && "The Eval function not found!");
    }

    if (m_NoRange.isInvalid()) {

      NamespaceDecl* NSD = utils::Lookup::Namespace(m_Sema, "cling");
      NSD = utils::Lookup::Namespace(m_Sema, "runtime", NSD);
      NSD = utils::Lookup::Namespace(m_Sema, "internal", NSD);

      DeclarationName Name
        = &m_Context->Idents.get(
                           "InterpreterGeneratedCodeDiagnosticsMaybeIncorrect");
      LookupResult R(*m_Sema, Name, SourceLocation(), Sema::LookupOrdinaryName,
                     Sema::ForRedeclaration);

      m_Sema->LookupQualifiedName(R, NSD);
      assert(!R.empty() && "Cannot find PrintValue(...)");

      NamedDecl* ND = R.getFoundDecl();
      m_NoRange = ND->getSourceRange();
      m_NoSLoc = m_NoRange.getBegin();
      m_NoELoc =  m_NoRange.getEnd();
    }
    for (Transaction::const_iterator I = getTransaction()->decls_begin(), 
           E = getTransaction()->decls_end(); I != E; ++I)
      for (DeclGroupRef::const_iterator J = (*I).begin(), 
             JE = (*I).end(); J != JE; ++J)
        if (ShouldVisit(*J) && (*J)->hasBody()) {
          if (FunctionDecl* FD = dyn_cast<FunctionDecl>(*J)) {
            // Set the decl context, which is needed by Evaluate.
            m_CurDeclContext = FD->getDeclContext();
            ASTNodeInfo NewBody = Visit((*J)->getBody());
            FD->setBody(NewBody.getAsSingleNode());
          }
          assert ((!isa<BlockDecl>(*J) || !isa<ObjCMethodDecl>(*J))
                  && "Not implemented yet!");
        }

    //TODO: Check for error before returning.
  }