Add super efficient execute function. It doesn't do any fancy things with the
declarations - it just compiles and runs given expression or statement. git-svn-id: http://root.cern.ch/svn/root/trunk@46636 27541ba8-7e3a-0410-8455-c3a389f83636
This commit is contained in:
parent
ff1861cfc2
commit
f48a4881cd
@ -364,6 +364,18 @@ namespace cling {
|
|||||||
///
|
///
|
||||||
CompilationResult echo(const std::string& input, StoredValueRef* V = 0);
|
CompilationResult echo(const std::string& input, StoredValueRef* V = 0);
|
||||||
|
|
||||||
|
///\brief Compiles input line and runs.
|
||||||
|
///
|
||||||
|
/// The interface is the fastest way to compile and run a statement or
|
||||||
|
/// expression. It just wraps the input and runs the wrapper, without any
|
||||||
|
/// other "magic"
|
||||||
|
///
|
||||||
|
/// @param[in] input - The input containing only expressions.
|
||||||
|
///
|
||||||
|
///\returns Whether the operation was fully successful.
|
||||||
|
///
|
||||||
|
CompilationResult execute(const std::string& input);
|
||||||
|
|
||||||
///\brief Loads header file or shared library.
|
///\brief Loads header file or shared library.
|
||||||
///
|
///
|
||||||
///\param [in] filename - The file to loaded.
|
///\param [in] filename - The file to loaded.
|
||||||
|
@ -213,7 +213,7 @@ namespace cling {
|
|||||||
// Set up the gCling variable
|
// Set up the gCling variable
|
||||||
std::stringstream initializer;
|
std::stringstream initializer;
|
||||||
initializer << "gCling=(cling::Interpreter*)" << (uintptr_t)this << ";";
|
initializer << "gCling=(cling::Interpreter*)" << (uintptr_t)this << ";";
|
||||||
evaluate(initializer.str());
|
execute(initializer.str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
declare("#include \"cling/Interpreter/CValuePrinter.h\"");
|
declare("#include \"cling/Interpreter/CValuePrinter.h\"");
|
||||||
@ -444,6 +444,36 @@ namespace cling {
|
|||||||
return EvaluateInternal(input, CO, V);
|
return EvaluateInternal(input, CO, V);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Interpreter::CompilationResult
|
||||||
|
Interpreter::execute(const std::string& input) {
|
||||||
|
CompilationOptions CO;
|
||||||
|
CO.DeclarationExtraction = 0;
|
||||||
|
CO.ValuePrinting = 0;
|
||||||
|
CO.ResultEvaluation = 0;
|
||||||
|
CO.DynamicScoping = 0;
|
||||||
|
CO.Debug = isPrintingAST();
|
||||||
|
|
||||||
|
DiagnosticsEngine& Diag = getCI()->getDiagnostics();
|
||||||
|
// Disable warnings which doesn't make sense when using the prompt
|
||||||
|
// This gets reset with the clang::Diagnostics().Reset()
|
||||||
|
Diag.setDiagnosticMapping(clang::diag::warn_unused_expr,
|
||||||
|
clang::diag::MAP_IGNORE, SourceLocation());
|
||||||
|
Diag.setDiagnosticMapping(clang::diag::warn_unused_call,
|
||||||
|
clang::diag::MAP_IGNORE, SourceLocation());
|
||||||
|
Diag.setDiagnosticMapping(clang::diag::warn_unused_comparison,
|
||||||
|
clang::diag::MAP_IGNORE, SourceLocation());
|
||||||
|
|
||||||
|
// Wrap the expression
|
||||||
|
std::string WrapperName;
|
||||||
|
std::string Wrapper = input;
|
||||||
|
WrapInput(Wrapper, WrapperName);
|
||||||
|
if (m_IncrParser->Compile(Wrapper, CO) == IncrementalParser::kSuccess)
|
||||||
|
if (RunFunction(WrapperName, QualType()))
|
||||||
|
return Interpreter::kSuccess;
|
||||||
|
|
||||||
|
return Interpreter::kFailure;
|
||||||
|
}
|
||||||
|
|
||||||
void Interpreter::WrapInput(std::string& input, std::string& fname) {
|
void Interpreter::WrapInput(std::string& input, std::string& fname) {
|
||||||
fname = createUniqueWrapper();
|
fname = createUniqueWrapper();
|
||||||
input.insert(0, "void " + fname + "() {\n ");
|
input.insert(0, "void " + fname + "() {\n ");
|
||||||
|
8
test/Interfaces/execute.C
Normal file
8
test/Interfaces/execute.C
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// RUN: cat %s | %cling 2>&1 | FileCheck %s
|
||||||
|
|
||||||
|
#include "cling/Interpreter/Interpreter.h"
|
||||||
|
|
||||||
|
gCling->execute("1;");
|
||||||
|
extern "C" int printf(const char* fmt, ...);
|
||||||
|
gCling->execute("printf(\"%d\", printf(\"%d\",1));");
|
||||||
|
// CHECK: 11
|
Loading…
Reference in New Issue
Block a user