2012-09-05 13:37:39 +04:00
//--------------------------------------------------------------------*- C++ -*-
// 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.
2012-09-05 13:37:39 +04:00
//------------------------------------------------------------------------------
# ifndef CLING_DECL_COLLECTOR_H
# define CLING_DECL_COLLECTOR_H
# include "clang/AST/ASTConsumer.h"
2018-05-11 15:26:46 +03:00
# include "clang/Serialization/ASTDeserializationListener.h"
2012-09-05 13:37:39 +04:00
2015-03-16 16:58:26 +03:00
# include "ASTTransformer.h"
2015-03-16 16:49:28 +03:00
# include <vector>
# include <memory>
2012-09-05 13:37:39 +04:00
namespace clang {
class ASTContext ;
2013-04-04 19:40:05 +04:00
class CodeGenerator ;
2013-04-09 19:38:50 +04:00
class Decl ;
2012-09-05 13:37:39 +04:00
class DeclGroupRef ;
2017-06-15 23:32:02 +03:00
class Preprocessor ;
2013-10-21 19:31:21 +04:00
class Token ;
2018-05-11 15:26:46 +03:00
class Module ;
2012-09-05 13:37:39 +04:00
}
namespace cling {
2015-03-16 16:49:28 +03:00
class ASTTransformer ;
class WrapperTransformer ;
2015-01-15 17:09:24 +03:00
class DeclCollector ;
2015-03-16 16:49:28 +03:00
class IncrementalParser ;
2012-09-05 13:37:39 +04:00
class Transaction ;
///\brief Collects declarations and fills them in cling::Transaction.
///
2014-08-04 06:05:42 +04:00
/// cling::Transaction becomes is a main building block in the interpreter.
/// cling::DeclCollector is responsible for appending all the declarations
2013-04-04 19:40:05 +04:00
/// seen by clang.
2012-09-05 13:37:39 +04:00
///
2018-05-11 15:26:46 +03:00
class DeclCollector : public clang : : ASTConsumer , public clang : : ASTDeserializationListener {
2017-06-15 23:32:02 +03:00
/// \brief PPCallbacks overrides/ Macro support
class PPAdapter ;
2015-03-16 16:49:28 +03:00
///\brief Contains the transaction AST transformers.
///
std : : vector < std : : unique_ptr < ASTTransformer > > m_TransactionTransformers ;
///\brief Contains the AST transformers operating on the wrapper.
///
std : : vector < std : : unique_ptr < WrapperTransformer > > m_WrapperTransformers ;
IncrementalParser * m_IncrParser ;
clang : : ASTConsumer * m_Consumer ;
2012-09-05 13:37:39 +04:00
Transaction * m_CurTransaction ;
2016-08-30 11:27:17 +03:00
/// Whether Transform() is active; prevents recursion.
bool m_Transforming = false ;
2013-04-10 10:57:36 +04:00
///\brief Test whether the first decl of the DeclGroupRef comes from an AST
/// file.
2013-08-26 19:59:33 +04:00
///
2013-04-09 19:38:50 +04:00
bool comesFromASTReader ( clang : : DeclGroupRef DGR ) const ;
2014-09-29 17:32:10 +04:00
bool comesFromASTReader ( const clang : : Decl * D ) const ;
2013-04-09 19:38:50 +04:00
2016-08-30 11:27:17 +03:00
bool Transform ( clang : : DeclGroupRef & DGR ) ;
2015-03-16 16:49:28 +03:00
///\brief Runs AST transformers on a transaction.
///
///\param[in] D - the decl to be transformed.
///
ASTTransformer : : Result TransformDecl ( clang : : Decl * D ) const ;
2012-09-05 13:37:39 +04:00
public :
2015-03-16 16:49:28 +03:00
DeclCollector ( ) :
m_IncrParser ( 0 ) , m_Consumer ( 0 ) , m_CurTransaction ( 0 ) { }
2012-09-05 13:37:39 +04:00
virtual ~ DeclCollector ( ) ;
2016-09-12 22:48:19 +03:00
void SetTransformers ( std : : vector < std : : unique_ptr < ASTTransformer > > & & allTT ,
std : : vector < std : : unique_ptr < WrapperTransformer > > & & allWT ) {
m_TransactionTransformers . swap ( allTT ) ;
m_WrapperTransformers . swap ( allWT ) ;
2015-03-16 16:49:28 +03:00
for ( auto & & TT : m_TransactionTransformers )
TT - > SetConsumer ( this ) ;
for ( auto & & WT : m_WrapperTransformers )
WT - > SetConsumer ( this ) ;
}
2017-06-15 23:32:02 +03:00
void Setup ( IncrementalParser * IncrParser , ASTConsumer * Consumer ,
clang : : Preprocessor & PP ) ;
2014-09-29 17:32:10 +04:00
2012-09-05 13:37:39 +04:00
/// \{
/// \name ASTConsumer overrides
2017-06-15 23:45:10 +03:00
bool HandleTopLevelDecl ( clang : : DeclGroupRef DGR ) final ;
void HandleInterestingDecl ( clang : : DeclGroupRef DGR ) final ;
void HandleTagDeclDefinition ( clang : : TagDecl * TD ) final ;
void HandleInvalidTagDeclDefinition ( clang : : TagDecl * TD ) final ;
void HandleVTable ( clang : : CXXRecordDecl * RD ) final ;
void CompleteTentativeDefinition ( clang : : VarDecl * VD ) final ;
void HandleTranslationUnit ( clang : : ASTContext & Ctx ) final ;
void HandleCXXImplicitFunctionInstantiation ( clang : : FunctionDecl * D ) final ;
void HandleCXXStaticMemberVarInstantiation ( clang : : VarDecl * D ) final ;
2012-09-05 13:37:39 +04:00
/// \}
/// \{
/// \name Transaction Support
Transaction * getTransaction ( ) { return m_CurTransaction ; }
const Transaction * getTransaction ( ) const { return m_CurTransaction ; }
void setTransaction ( Transaction * curT ) { m_CurTransaction = curT ; }
/// \}
2012-10-13 19:04:49 +04:00
// dyn_cast/isa support
static bool classof ( const clang : : ASTConsumer * ) { return true ; }
2018-05-11 15:26:46 +03:00
static bool classof ( const clang : : ASTDeserializationListener * ) { return true ; }
///\brief ASTDeserializationListener function which gets callback when a decl is deserialized
void DeclRead ( clang : : serialization : : DeclID , const clang : : Decl * D ) final ;
2012-09-05 13:37:39 +04:00
} ;
} // namespace cling
# endif // CLING_DECL_COLLECTOR_H