In AutoSynthesizer handle the case of try-catch function [ROOT-8034].

Example of try-catch function:

void function_with_try_block()
try
{
    // try block body
}
catch (...)
{
    // catch block body
}
This commit is contained in:
Philippe Canal 2016-03-03 12:07:28 -06:00 committed by sftnight
parent 9bf850678c
commit f8a9fdcfc7

View File

@ -46,6 +46,17 @@ namespace cling {
CS->setStmts(m_Sema->getASTContext(), Stmts.data(), Stmts.size());
}
void Fix(CXXTryStmt* TS) {
Fix(TS->getTryBlock());
for(unsigned int h = 0; h < TS->getNumHandlers(); ++h) {
Stmt *s = TS->getHandler(h)->getHandlerBlock();
if (CompoundStmt* CS = dyn_cast_or_null<CompoundStmt>(s))
Fix(CS);
else if (CXXTryStmt *TS = dyn_cast_or_null<CXXTryStmt>(s))
Fix(TS);
}
}
bool VisitDeclRefExpr(DeclRefExpr* DRE) {
const Decl* D = DRE->getDecl();
if (const AnnotateAttr* A = D->getAttr<AnnotateAttr>())
@ -78,8 +89,11 @@ namespace cling {
// getBody() might return nullptr even though hasBody() is true for
// late template parsed functions. We simply don't do auto auto on
// those.
if (CompoundStmt* CS = cast_or_null<CompoundStmt>(FD->getBody()))
Stmt *Body = FD->getBody();
if (CompoundStmt* CS = dyn_cast_or_null<CompoundStmt>(Body))
m_AutoFixer->Fix(CS);
else if (CXXTryStmt *TS = dyn_cast_or_null<CXXTryStmt>(Body))
m_AutoFixer->Fix(TS);
}
return Result(D, true);
}