2015-12-18 18:12:00 +03:00
//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// author: Elisavet Sakellari <elisavet.sakellari@cern.ch>
//
// 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.
//------------------------------------------------------------------------------
2016-07-07 11:47:58 +03:00
# ifndef CLING_EXTERNAL_INTERPRETER_SOURCE
# define CLING_EXTERNAL_INTERPRETER_SOURCE
2015-12-18 18:12:00 +03:00
2016-07-14 19:06:47 +03:00
# include "clang/AST/ExternalASTSource.h"
2015-12-18 18:12:00 +03:00
# include <string>
# include <map>
namespace clang {
class ASTContext ;
2016-07-14 19:06:47 +03:00
class ASTImporter ;
2015-12-18 18:12:00 +03:00
class Decl ;
class DeclContext ;
class DeclarationName ;
2016-07-14 19:06:47 +03:00
class ExternalASTSource ;
2015-12-18 18:12:00 +03:00
class NamedDecl ;
class Sema ;
}
2016-01-11 17:17:58 +03:00
namespace cling {
class Interpreter ;
}
2015-12-18 18:12:00 +03:00
namespace cling {
2016-07-07 11:47:58 +03:00
class ExternalInterpreterSource : public clang : : ExternalASTSource {
2015-12-18 18:12:00 +03:00
private :
2016-07-07 11:47:58 +03:00
const cling : : Interpreter * m_ParentInterpreter ;
cling : : Interpreter * m_ChildInterpreter ;
2015-12-18 18:12:00 +03:00
///\brief We keep a mapping between the imported DeclContexts
/// and the original ones from of the first Interpreter.
/// Key: imported DeclContext
/// Value: original DeclContext
///
2016-07-07 11:47:58 +03:00
std : : map < const clang : : DeclContext * , clang : : DeclContext * > m_ImportedDeclContexts ;
2015-12-18 18:12:00 +03:00
///\brief A map for all the imported Decls (Contexts)
/// according to their names.
/// Key: Name of the Decl(Context) as a string.
/// Value: The DeclarationName of this Decl(Context) is the one
/// that comes from the first Interpreter.
///
2016-07-07 11:47:58 +03:00
std : : map < clang : : DeclarationName , clang : : DeclarationName > m_ImportedDecls ;
2015-12-18 18:12:00 +03:00
2016-07-15 13:50:02 +03:00
///\brief The ASTImporter which does the actual imports from the parent
/// interpreter to the child interpreter.
std : : unique_ptr < clang : : ASTImporter > m_Importer ;
2015-12-18 18:12:00 +03:00
public :
2016-07-07 11:47:58 +03:00
ExternalInterpreterSource ( const cling : : Interpreter * parent ,
cling : : Interpreter * child ) ;
2016-07-14 19:06:47 +03:00
virtual ~ ExternalInterpreterSource ( ) ;
2015-12-18 18:12:00 +03:00
2016-06-23 19:09:06 +03:00
void completeVisibleDeclsMap ( const clang : : DeclContext * DC ) override ;
2016-07-07 11:47:58 +03:00
bool FindExternalVisibleDeclsByName (
const clang : : DeclContext * childCurrentDeclContext ,
clang : : DeclarationName childDeclName ) override ;
2015-12-18 18:12:00 +03:00
2016-07-07 11:47:58 +03:00
bool Import ( clang : : DeclContext : : lookup_result lookupResult ,
2015-12-18 18:12:00 +03:00
const clang : : DeclContext * childCurrentDeclContext ,
clang : : DeclarationName & childDeclName ,
clang : : DeclarationName & parentDeclName ) ;
void ImportDeclContext ( clang : : DeclContext * declContextToImport ,
clang : : DeclarationName & childDeclName ,
clang : : DeclarationName & parentDeclName ,
const clang : : DeclContext * childCurrentDeclContext ) ;
void ImportDecl ( clang : : Decl * declToImport ,
clang : : DeclarationName & childDeclName ,
clang : : DeclarationName & parentDeclName ,
const clang : : DeclContext * childCurrentDeclContext ) ;
2016-06-23 19:09:06 +03:00
2016-07-07 11:47:58 +03:00
void addToImportedDecls ( clang : : DeclarationName child ,
clang : : DeclarationName parent ) {
m_ImportedDecls [ child ] = parent ;
}
void addToImportedDeclContexts ( clang : : DeclContext * child ,
2016-06-23 19:09:06 +03:00
clang : : DeclContext * parent ) {
2016-07-07 11:47:58 +03:00
m_ImportedDeclContexts [ child ] = parent ;
2016-06-23 19:09:06 +03:00
}
2015-12-18 18:12:00 +03:00
} ;
} // end namespace cling
2016-07-07 11:47:58 +03:00
2015-12-18 18:12:00 +03:00
# endif //CLING_ASTIMPORTSOURCE_H