Add support for TClingCallFunc function wrappers to transactions.

This commit is contained in:
Paul Russo 2013-08-27 17:25:37 -05:00 committed by sftnight
parent 7fa8507477
commit 63cb406f2f
4 changed files with 40 additions and 3 deletions

View File

@ -107,6 +107,11 @@ namespace cling {
///
clang::FunctionDecl* m_WrapperFD;
///\brief The wrapper function produced by the intepreter if any
/// for CallFunc.
///
clang::FunctionDecl* m_CFWrapperFD;
///\brief Next transaction in if any.
///
const Transaction* m_Next;
@ -354,6 +359,7 @@ namespace cling {
void setModule(llvm::Module* M) { m_Module = M ; }
clang::FunctionDecl* getWrapperFD() const { return m_WrapperFD; }
clang::FunctionDecl* getCFWrapperFD() const { return m_CFWrapperFD; }
const Transaction* getNext() const { return m_Next; }
void setNext(Transaction* T) { m_Next = T; }

View File

@ -40,6 +40,16 @@ namespace utils {
///
static bool IsWrapper(const clang::NamedDecl* ND);
///\brief Checks whether the declaration is a interpreter-generated
/// CallFunc wrapper function.
///
///\param[in] ND - The decl being checked. If null returns false.
///
///\returns true if the decl is a interpreter-generated CallFunc wrapper
/// function.
///
static bool IsCFWrapper(const clang::NamedDecl* ND);
///\brief Retrieves the last expression of a function body. If it was a
/// DeclStmt with a variable declaration, creates DeclRefExpr and adds it to
/// the function body.
@ -68,6 +78,7 @@ namespace utils {
class Synthesize {
public:
static const char* const UniquePrefix;
static const char* const CFUniquePrefix;
///\brief Synthesizes c-style cast in the AST from given pointer and type to
/// cast to.

View File

@ -35,6 +35,7 @@ namespace cling {
m_Opts = CompilationOptions();
m_Module = 0;
m_WrapperFD = 0;
m_CFWrapperFD = 0;
m_Next = 0;
//m_ASTContext = C;
}
@ -97,6 +98,7 @@ namespace cling {
m_NestedTransactions.reset(0); // FIXME: leaks the nested transactions.
m_Module = 0;
m_WrapperFD = 0;
m_CFWrapperFD = 0;
m_Next = 0;
}
@ -140,14 +142,22 @@ namespace cling {
#endif
bool checkForWrapper = !m_WrapperFD;
bool checkForCFWrapper = !m_CFWrapperFD;
// FIXME: Assignment in assert!!!!
assert(checkForWrapper = true && "Check for wrappers with asserts");
// register the wrapper if any.
if (checkForWrapper && !DCI.m_DGR.isNull() && DCI.m_DGR.isSingleDecl()) {
if (FunctionDecl* FD = dyn_cast<FunctionDecl>(DCI.m_DGR.getSingleDecl()))
if (utils::Analyze::IsWrapper(FD)) {
if ((checkForWrapper || checkForCFWrapper) && !DCI.m_DGR.isNull() &&
DCI.m_DGR.isSingleDecl()) {
if (FunctionDecl* FD =
dyn_cast<FunctionDecl>(DCI.m_DGR.getSingleDecl())) {
if (checkForWrapper && utils::Analyze::IsWrapper(FD)) {
assert(!m_WrapperFD && "Two wrappers in one transaction?");
m_WrapperFD = FD;
}
if (checkForCFWrapper && utils::Analyze::IsCFWrapper(FD)) {
m_CFWrapperFD = FD;
}
}
}
if (comesFromASTReader(DCI.m_DGR))

View File

@ -28,6 +28,15 @@ namespace utils {
.startswith(Synthesize::UniquePrefix);
}
bool Analyze::IsCFWrapper(const NamedDecl* ND) {
if (!ND) {
return false;
}
bool ret = StringRef(ND->getNameAsString()).startswith(
Synthesize::CFUniquePrefix);
return ret;
}
Expr* Analyze::GetOrCreateLastExpr(FunctionDecl* FD,
int* FoundAt /*=0*/,
bool omitDeclStmts /*=true*/,
@ -91,6 +100,7 @@ namespace utils {
}
const char* const Synthesize::UniquePrefix = "__cling_Un1Qu3";
const char* const Synthesize::CFUniquePrefix = "__cf_Un1Qu3";
Expr* Synthesize::CStyleCastPtrExpr(Sema* S, QualType Ty, uint64_t Ptr) {
ASTContext& Ctx = S->getASTContext();