2012-09-05 09:37:39 +00:00
//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// author: Vassil Vassilev <vasil.georgiev.vasilev@cern.ch>
2014-01-07 11:08:37 +01: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 09:37:39 +00:00
//------------------------------------------------------------------------------
# ifndef CLING_DECL_COLLECTOR_H
# define CLING_DECL_COLLECTOR_H
# include "clang/AST/ASTConsumer.h"
2014-09-29 15:32:10 +02:00
# include "clang/AST/ASTMutationListener.h"
2013-10-21 17:31:21 +02:00
# include "clang/Lex/PPCallbacks.h"
2012-09-05 09:37:39 +00:00
namespace clang {
class ASTContext ;
2013-04-04 15:40:05 +00:00
class CodeGenerator ;
2013-04-09 15:38:50 +00:00
class Decl ;
2012-09-05 09:37:39 +00:00
class DeclGroupRef ;
2013-10-21 17:31:21 +02:00
class Token ;
2012-09-05 09:37:39 +00:00
}
namespace cling {
2013-04-10 15:15:49 +00:00
class Interpreter ;
2012-09-05 09:37:39 +00:00
class Transaction ;
///\brief Collects declarations and fills them in cling::Transaction.
///
2014-08-03 21:05:42 -05:00
/// cling::Transaction becomes is a main building block in the interpreter.
/// cling::DeclCollector is responsible for appending all the declarations
2013-04-04 15:40:05 +00:00
/// seen by clang.
2012-09-05 09:37:39 +00:00
///
2014-09-29 15:32:10 +02:00
class DeclCollector : public clang : : PPCallbacks ,
public clang : : ASTMutationListener ,
public clang : : ASTConsumer {
2012-09-05 09:37:39 +00:00
private :
Transaction * m_CurTransaction ;
2013-04-10 06:57:36 +00:00
///\brief Test whether the first decl of the DeclGroupRef comes from an AST
/// file.
2013-08-26 17:59:33 +02:00
///
2013-04-09 15:38:50 +00:00
bool comesFromASTReader ( clang : : DeclGroupRef DGR ) const ;
2014-09-29 15:32:10 +02:00
bool comesFromASTReader ( const clang : : Decl * D ) const ;
2013-04-09 15:38:50 +00:00
2012-09-05 09:37:39 +00:00
public :
2013-08-26 17:59:33 +02:00
DeclCollector ( ) : m_CurTransaction ( 0 ) { }
2012-09-05 09:37:39 +00:00
virtual ~ DeclCollector ( ) ;
2014-09-29 15:32:10 +02:00
/// \name PPCallbacks overrides
/// Macro support
virtual void MacroDefined ( const clang : : Token & MacroNameTok ,
const clang : : MacroDirective * MD ) ;
/// \}
/// \name ASTMutationListeners overrides
virtual void AddedCXXImplicitMember ( const clang : : CXXRecordDecl * RD ,
const clang : : Decl * D ) ;
/// \}
2012-09-05 09:37:39 +00:00
/// \{
/// \name ASTConsumer overrides
virtual bool HandleTopLevelDecl ( clang : : DeclGroupRef DGR ) ;
virtual void HandleInterestingDecl ( clang : : DeclGroupRef DGR ) ;
virtual void HandleTagDeclDefinition ( clang : : TagDecl * TD ) ;
virtual void HandleVTable ( clang : : CXXRecordDecl * RD ,
bool DefinitionRequired ) ;
virtual void CompleteTentativeDefinition ( clang : : VarDecl * VD ) ;
virtual void HandleTranslationUnit ( clang : : ASTContext & Ctx ) ;
2012-12-12 08:08:56 +00:00
virtual void HandleCXXImplicitFunctionInstantiation ( clang : : FunctionDecl * D ) ;
virtual void HandleCXXStaticMemberVarInstantiation ( clang : : VarDecl * D ) ;
2012-09-05 09:37:39 +00:00
/// \}
/// \{
/// \name Transaction Support
Transaction * getTransaction ( ) { return m_CurTransaction ; }
const Transaction * getTransaction ( ) const { return m_CurTransaction ; }
void setTransaction ( Transaction * curT ) { m_CurTransaction = curT ; }
2014-08-03 21:05:42 -05:00
void setTransaction ( const Transaction * curT ) {
m_CurTransaction = const_cast < Transaction * > ( curT ) ;
2012-09-05 09:37:39 +00:00
}
/// \}
2012-10-13 15:04:49 +00:00
// dyn_cast/isa support
static bool classof ( const clang : : ASTConsumer * ) { return true ; }
2012-09-05 09:37:39 +00:00
} ;
} // namespace cling
# endif // CLING_DECL_COLLECTOR_H