New interface to export Cling run-time configuration bits.

This commit allows the user to enable/disable specific interpreter capabilities
without requiring to `#include` the heavier weight `Interpreter.h` (that also
has dependencies on llvm).

The only feature covered at the moment is definition shadowing.

Closes cling issue #360.
This commit is contained in:
Javier Lopez-Gomez 2020-12-08 12:44:02 +01:00 committed by jenkins
parent 0bc89e8172
commit 904796d2bb
7 changed files with 45 additions and 11 deletions

View File

@ -11,6 +11,7 @@
#define CLING_INTERPRETER_H
#include "cling/Interpreter/InvocationOptions.h"
#include "cling/Interpreter/RuntimeOptions.h"
#include "llvm/ADT/StringRef.h"
@ -188,9 +189,9 @@ namespace cling {
///
bool m_RawInputEnabled;
///\brief Whether to allow decl redefinition, i.e. enable the DefinitionShadower.
///
bool m_RedefinitionAllowed;
///\brief Configuration bits that can be changed at runtime. This allows the
/// user to enable/disable specific interpreter extensions.
cling::runtime::RuntimeOptions m_RuntimeOptions;
///\brief Flag toggling the optimization level to be used.
///
@ -361,6 +362,9 @@ namespace cling {
const InvocationOptions& getOptions() const { return m_Opts; }
InvocationOptions& getOptions() { return m_Opts; }
const cling::runtime::RuntimeOptions& getRuntimeOptions() const { return m_RuntimeOptions; }
cling::runtime::RuntimeOptions& getRuntimeOptions() { return m_RuntimeOptions; }
const llvm::LLVMContext* getLLVMContext() const {
return m_LLVMContext.get();
}
@ -681,9 +685,6 @@ namespace cling {
bool isRawInputEnabled() const { return m_RawInputEnabled; }
void enableRawInput(bool raw = true) { m_RawInputEnabled = raw; }
bool isRedefinitionAllowed() const { return m_RedefinitionAllowed; }
void allowRedefinition(bool b = true) { m_RedefinitionAllowed = b; }
int getDefaultOptLevel() const { return m_OptLevel; }
void setDefaultOptLevel(int optLevel) { m_OptLevel = optLevel; }

View File

@ -0,0 +1,27 @@
//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// author: Javier Lopez-Gomez <j.lopez@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.
//------------------------------------------------------------------------------
#ifndef CLING_RUNTIME_OPTIONS_H
#define CLING_RUNTIME_OPTIONS_H
namespace cling {
namespace runtime {
/// \brief Interpreter configuration bits that can be changed at run-time
/// by the user, e.g. to enable/disable extensions.
struct RuntimeOptions {
RuntimeOptions() : AllowRedefinition(0) {}
/// \brief Allow the user to redefine entities (requests enabling the
/// `DefinitionShadower` AST transformer).
bool AllowRedefinition : 1;
};
} // end namespace runtime
} // end namespace cling
#endif // CLING_RUNTIME_OPTIONS_H

View File

@ -23,6 +23,7 @@
#ifdef __cplusplus
#include <cling/Interpreter/RuntimeOptions.h>
#include <new>
namespace cling {
@ -38,6 +39,9 @@ namespace cling {
/// the dynamic scopes and the runtime bindings
extern Interpreter* gCling;
/// \brief Configuration bits for the parent interpreter.
extern RuntimeOptions* gClingOpts;
namespace internal {
/// \brief Some of clang's routines rely on valid source locations and
/// source ranges. This member can be looked up and source locations and

View File

@ -6,6 +6,7 @@ module Cling_Interpreter {
// Only included at runtime.
exclude header "Interpreter/RuntimeUniverse.h"
exclude header "Interpreter/RuntimeOptions.h"
exclude header "Interpreter/DynamicLookupRuntimeUniverse.h"
exclude header "Interpreter/RuntimePrintValue.h"

View File

@ -1,6 +1,7 @@
// Only included at runtime.
module Cling_Runtime {
module "RuntimeUniverse.h" { header "Interpreter/RuntimeUniverse.h" export * }
module "RuntimeOptions.h" { header "Interpreter/RuntimeOptions.h" export * }
module "DynamicLookupRuntimeUniverse.h" { header "Interpreter/DynamicLookupRuntimeUniverse.h" export * }
module "RuntimePrintValue.h" { header "Interpreter/RuntimePrintValue.h" export * }
export *

View File

@ -207,7 +207,7 @@ namespace cling {
m_UniqueCounter(parentInterp ? parentInterp->m_UniqueCounter + 1 : 0),
m_PrintDebug(false), m_DynamicLookupDeclared(false),
m_DynamicLookupEnabled(false), m_RawInputEnabled(false),
m_RedefinitionAllowed(false),
m_RuntimeOptions{},
m_OptLevel(parentInterp ? parentInterp->m_OptLevel : -1) {
if (handleSimpleOptions(m_Opts))
@ -442,7 +442,8 @@ namespace cling {
Strm << "#include \"cling/Interpreter/RuntimeUniverse.h\"\n";
if (EmitDefinitions)
Strm << "namespace cling { class Interpreter; namespace runtime { "
"Interpreter* gCling=(Interpreter*)" << ThisP << ";}}\n";
"Interpreter* gCling=(Interpreter*)" << ThisP << ";\n"
"RuntimeOptions* gClingOpts=(RuntimeOptions*)" << &this->m_RuntimeOptions << ";}}\n";
} else {
Strm << "#include \"cling/Interpreter/CValuePrinter.h\"\n"
<< "void* gCling";
@ -806,7 +807,7 @@ namespace cling {
wrapPoint = utils::getWrapPoint(wrapReadySource, getCI()->getLangOpts());
CompilationOptions CO = makeDefaultCompilationOpts();
CO.EnableShadowing = m_RedefinitionAllowed && !isRawInputEnabled();
CO.EnableShadowing = m_RuntimeOptions.AllowRedefinition && !isRawInputEnabled();
if (isRawInputEnabled() || wrapPoint == std::string::npos) {
CO.DeclarationExtraction = 0;

View File

@ -9,8 +9,7 @@
// RUN: cat %s | %cling 2>&1 | FileCheck %s
#include <type_traits>
#include <cstdlib>
#include "cling/Interpreter/Interpreter.h"
cling::runtime::gCling->allowRedefinition();
cling::runtime::gClingOpts->AllowRedefinition = 1;
// ==== Test UsingDirectiveDecl/UsingDecl
// These should not be nested into a `__cling_N5xxx' namespace (but placed at