2013-10-24 20:54:06 +04:00
//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
// author: Vassil Vassilev <vasil.georgiev.vasilev@cern.ch>
2014-01-07 14:08:37 +04:00
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
2013-10-24 20:54:06 +04:00
//------------------------------------------------------------------------------
# include "CheckEmptyTransactionTransformer.h"
2014-03-27 20:30:09 +04:00
# include "TransactionUnloader.h"
2013-10-24 20:54:06 +04:00
# include "cling/Interpreter/Transaction.h"
# include "clang/AST/Decl.h"
# include "clang/AST/DeclCXX.h"
2014-02-27 13:37:10 +04:00
# include "clang/Sema/Sema.h"
2013-10-24 20:54:06 +04:00
# include <algorithm>
using namespace clang ;
namespace cling {
void CheckEmptyTransactionTransformer : : Transform ( ) {
Transaction * T = getTransaction ( ) ;
if ( FunctionDecl * FD = T - > getWrapperFD ( ) ) {
CompoundStmt * CS = cast < CompoundStmt > ( FD - > getBody ( ) ) ;
if ( ! CS - > size ( ) | | ( CS - > size ( ) = = 1 & & isa < NullStmt > ( CS - > body_back ( ) ) ) ) {
// This is an empty wrapper function. Get rid of it.
DeclGroupRef DGR ( FD ) ;
Transaction : : DelayCallInfo DCI ( DGR ,
Transaction : : kCCIHandleTopLevelDecl ) ;
2014-02-27 13:37:10 +04:00
Transaction : : iterator found
2013-10-24 20:54:06 +04:00
= std : : find ( T - > decls_begin ( ) , T - > decls_end ( ) , DCI ) ;
if ( found ! = T - > decls_end ( ) ) {
T - > erase ( found ) ;
}
2014-02-27 13:37:53 +04:00
// We know that it didn't end up in the EE by design.
2014-03-27 20:30:09 +04:00
TransactionUnloader U ( m_Sema , /*CodeGenerator*/ 0 , /*ExecutionEngine*/ 0 ) ;
U . UnloadDecl ( FD ) ;
2013-10-24 20:54:06 +04:00
}
}
}
} // end namespace cling