No need to synthesize anything anymore.

This commit is contained in:
Vassil Vassilev 2014-05-16 23:24:47 +02:00 committed by sftnight
parent 3dfc56637b
commit 3e5af816aa
3 changed files with 1 additions and 141 deletions

View File

@ -53,33 +53,6 @@ namespace cling {
void flushToStream(llvm::raw_ostream& o, const std::string& s);
template<typename T>
void Select(llvm::raw_ostream* o, const Value* value) {
// Only because we don't want to include llvm::raw_ostream in the header
//flushToStream(*o, printType(0, (void*)0, value)
// + printValue(0, (void*)0, value) + '\n');
}
/* template <typename T>
const T& Select(llvm::raw_ostream* o, Interpreter* I,
clang::ASTContext* C, const T& value) {
ValuePrinterInfo VPI(I, C);
// Only because we don't want to include llvm::raw_ostream in the header
flushToStream(*o, printType(&value, &value, VPI)
+ printValue(&value, &value, VPI) + '\n');
return value;
}
template <typename T>
T* Select(llvm::raw_ostream* o, Interpreter* I,
clang::ASTContext* C, T* value) {
ValuePrinterInfo VPI(I, C);
// Only because we don't want to include llvm::raw_ostream in the header
flushToStream(*o, printType((const void*) value, value, VPI)
+ printValue((const void*) value, value, VPI) + '\n');
return value;
}
*/
} // namespace valuePrinterInternal
///\brief Catch-all implementation for value printing.

View File

@ -98,9 +98,7 @@ namespace cling {
To = PE->getSubExpr();
Expr* Result = 0;
if (m_Sema->getLangOpts().CPlusPlus)
;//Result = SynthesizeCppVP(To);
else
if (!m_Sema->getLangOpts().CPlusPlus)
Result = SynthesizeVP(To);
if (Result)
@ -121,116 +119,6 @@ namespace cling {
return true;
}
// We need to artificially create:
// cling::valuePrinterInternal::Select((void*) raw_ostream,
// (ASTContext)Ctx, (Expr*)E, &i);
Expr* ValuePrinterSynthesizer::SynthesizeCppVP(Expr* E) {
QualType QT = E->getType();
// For now we skip void and function pointer types.
if (QT.isNull() || QT->isVoidType())
return 0;
// 1. Call gCling->getValuePrinterStream()
// 1.1. Find gCling
NamespaceDecl* NSD = utils::Lookup::Namespace(m_Sema, "cling");
NSD = utils::Lookup::Namespace(m_Sema, "valuePrinterInternal", NSD);
DeclarationName PVName = &m_Context->Idents.get("Select");
LookupResult R(*m_Sema, PVName, E->getLocStart(), Sema::LookupOrdinaryName,
Sema::ForRedeclaration);
assert(NSD && "There must be a valid namespace.");
m_Sema->LookupQualifiedName(R, NSD);
assert(!R.empty() && "Cannot find valuePrinterInternal::Select(...)");
CXXScopeSpec CSS;
Expr* UnresolvedLookup
= m_Sema->BuildDeclarationNameExpr(CSS, R, /*ADL*/ false).take();
// 2.4. Prepare the params
// 2.4.1 Lookup the llvm::raw_ostream
CXXRecordDecl* RawOStreamRD
= dyn_cast<CXXRecordDecl>(utils::Lookup::Named(m_Sema, "raw_ostream",
utils::Lookup::Namespace(m_Sema,
"llvm")));
assert(RawOStreamRD && "Declaration of the expr not found!");
QualType RawOStreamRDTy = m_Context->getTypeDeclType(RawOStreamRD);
// 2.4.2 Lookup the interpreter type
NamespaceDecl* ClingRuntimeNSD =
utils::Lookup::Namespace(m_Sema,"runtime",
utils::Lookup::Namespace(m_Sema, "cling"));
VarDecl* gCling = dyn_cast<VarDecl>(utils::Lookup::Named(m_Sema, "gCling",
ClingRuntimeNSD));
// Build a reference to gCling
ExprResult gClingDRE
= m_Sema->BuildDeclRefExpr(gCling, gCling->getType(),
VK_RValue, SourceLocation());
assert(gCling && "Declaration of the expr not found!");
// 2.4.3 Lookup ASTContext type
CXXRecordDecl* ASTContextRD
= dyn_cast<CXXRecordDecl>(utils::Lookup::Named(m_Sema, "ASTContext",
utils::Lookup::Namespace(m_Sema,
"clang")));
assert(ASTContextRD && "Declaration of the expr not found!");
QualType ASTContextRDTy = m_Context->getTypeDeclType(ASTContextRD);
Expr* RawOStreamTy
= utils::Synthesize::CStyleCastPtrExpr(m_Sema, RawOStreamRDTy,
(uint64_t)m_ValuePrinterStream.get()
);
Expr* ASTContextTy
= utils::Synthesize::CStyleCastPtrExpr(m_Sema, ASTContextRDTy,
(uint64_t)m_Context);
// E might contain temporaries. This means that the topmost expr is
// ExprWithCleanups. This contains the information about the temporaries and
// signals when they should be destroyed.
// Here we replace E with call to value printer and we must extend the life
// time of those temporaries to the end of the new CallExpr.
bool NeedsCleanup = false;
if (ExprWithCleanups* EWC = dyn_cast<ExprWithCleanups>(E)) {
E = EWC->getSubExpr();
NeedsCleanup = true;
}
if (QT->isFunctionPointerType()) {
// convert func ptr to void*:
E = utils::Synthesize::CStyleCastPtrExpr(m_Sema, m_Context->VoidPtrTy, E);
}
llvm::SmallVector<Expr*, 4> CallArgs;
CallArgs.push_back(RawOStreamTy);
CallArgs.push_back(gClingDRE.take());
CallArgs.push_back(ASTContextTy);
CallArgs.push_back(E);
Scope* S = m_Sema->getScopeForContext(m_Sema->CurContext);
// Here we expect a template instantiation. We need to open the transaction
// that we are currently work with.
Transaction::State oldState = getTransaction()->getState();
getTransaction()->setState(Transaction::kCollecting);
Expr* Result = m_Sema->ActOnCallExpr(S, UnresolvedLookup, E->getLocStart(),
CallArgs, E->getLocEnd()).take();
getTransaction()->setState(oldState);
Result = m_Sema->ActOnFinishFullExpr(Result).take();
if (NeedsCleanup && !isa<ExprWithCleanups>(Result)) {
llvm::ArrayRef<ExprWithCleanups::CleanupObject> Cleanups;
ExprWithCleanups* EWC
= ExprWithCleanups::Create(*m_Context, Result, Cleanups);
Result = EWC;
}
assert(Result && "Cannot create value printer!");
return Result;
}
// We need to artificially create:
// cling_PrintValue(void* (ASTContext)C, void* (Expr)E, const void* (&i)
Expr* ValuePrinterSynthesizer::SynthesizeVP(Expr* E) {

View File

@ -62,7 +62,6 @@ public:
/// options disallowint it - it will return still true. Returns false on
/// critical error.
bool tryAttachVP(clang::FunctionDecl* FD);
clang::Expr* SynthesizeCppVP(clang::Expr* E);
clang::Expr* SynthesizeVP(clang::Expr* E);
unsigned ClearNullStmts(clang::CompoundStmt* CS);
};