Make result evaluation optional again.

This commit is contained in:
Axel Naumann 2013-06-10 15:14:36 +02:00 committed by sftnight
parent 50c463b803
commit 11e71f5c76
8 changed files with 59 additions and 53 deletions

View File

@ -68,8 +68,9 @@ namespace cling {
/// have in case of multi input mode.
///\returns -1 if quit was requiested.
///
int process(const char* input_line, cling::StoredValueRef& result,
Interpreter::CompilationResult& compRes);
int process(const char* input_line,
Interpreter::CompilationResult& compRes,
cling::StoredValueRef* result);
///\brief When continuation is requested, this cancels and ignores previous
/// input, resetting the continuation to a new line.
@ -91,8 +92,8 @@ namespace cling {
///\returns true on success
///
bool executeFile(llvm::StringRef file, llvm::StringRef args,
cling::StoredValueRef& result,
Interpreter::CompilationResult& compRes);
Interpreter::CompilationResult& compRes,
cling::StoredValueRef* result);
///\brief Get the file name that is currently executing as passed to
/// the currently active executeFile(). The returned StringRef::data() is
@ -121,7 +122,7 @@ namespace cling {
///
Interpreter::CompilationResult
readInputFromFile(llvm::StringRef filename,
StoredValueRef& result,
StoredValueRef* result,
bool ignoreOutmostBlock = false);
};

View File

@ -11,6 +11,7 @@
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/InvocationOptions.h"
#include "cling/Interpreter/StoredValueRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Path.h"
@ -81,9 +82,9 @@ namespace cling {
consumeToken();
}
bool MetaParser::isMetaCommand(StoredValueRef& resultValue,
MetaSema::ActionResult& actionResult) {
return isCommandSymbol() && isCommand(resultValue, actionResult);
bool MetaParser::isMetaCommand(MetaSema::ActionResult& actionResult,
StoredValueRef* resultValue) {
return isCommandSymbol() && isCommand(actionResult, resultValue);
}
bool MetaParser::isQuitRequested() const {
@ -99,17 +100,18 @@ namespace cling {
return true;
}
bool MetaParser::isCommand(StoredValueRef& resultValue,
MetaSema::ActionResult& actionResult) {
resultValue = StoredValueRef();
bool MetaParser::isCommand(MetaSema::ActionResult& actionResult,
StoredValueRef* resultValue) {
if (resultValue)
*resultValue = StoredValueRef::invalidValue();
return isLCommand(actionResult)
|| isXCommand(resultValue, actionResult)
|| isXCommand(actionResult, resultValue)
|| isqCommand()
|| isUCommand(actionResult) || isICommand() || israwInputCommand()
|| isprintASTCommand() || isdynamicExtensionsCommand() || ishelpCommand()
|| isfileExCommand() || isfilesCommand() || isClassCommand()
|| isgCommand() || isTypedefCommand()
|| isShellCommand(resultValue, actionResult);
|| isShellCommand(actionResult, resultValue);
}
// L := 'L' FilePath
@ -137,9 +139,10 @@ namespace cling {
// FilePath := AnyString
// ArgList := (ExtraArgList) ' ' [ArgList]
// ExtraArgList := AnyString [, ExtraArgList]
bool MetaParser::isXCommand(StoredValueRef& resultValue,
MetaSema::ActionResult& actionResult) {
resultValue = StoredValueRef();
bool MetaParser::isXCommand(MetaSema::ActionResult& actionResult,
StoredValueRef* resultValue) {
if (resultValue)
*resultValue = StoredValueRef::invalidValue();
const Token& Tok = getCurTok();
if (Tok.is(tok::ident) && (Tok.getIdent().equals("x")
|| Tok.getIdent().equals("X"))) {
@ -319,9 +322,10 @@ namespace cling {
return false;
}
bool MetaParser::isShellCommand(StoredValueRef& resultValue,
MetaSema::ActionResult& actionResult) {
resultValue = StoredValueRef();
bool MetaParser::isShellCommand(MetaSema::ActionResult& actionResult,
StoredValueRef* resultValue) {
if (resultValue)
*resultValue = StoredValueRef::invalidValue();
actionResult = MetaSema::AR_Failure;
const Token& Tok = getCurTok();
if (Tok.is(tok::excl_mark)) {

View File

@ -9,8 +9,6 @@
#include "MetaLexer.h" // for cling::Token
#include "MetaSema.h" // for ActionResult
#include "cling/Interpreter/StoredValueRef.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallVector.h"
@ -24,6 +22,7 @@ namespace llvm {
namespace cling {
class MetaLexer;
class MetaSema;
class StoredValueRef;
// Command syntax: MetaCommand := <CommandSymbol><Command>
// CommandSymbol := '.' | '//.'
@ -65,12 +64,12 @@ namespace cling {
void skipWhitespace();
bool isCommandSymbol();
bool isCommand(StoredValueRef& resultValue,
MetaSema::ActionResult& actionResult);
bool isCommand(MetaSema::ActionResult& actionResult,
StoredValueRef* resultValue);
bool isLCommand(MetaSema::ActionResult& actionResult);
bool isExtraArgList();
bool isXCommand(StoredValueRef& resultValue,
MetaSema::ActionResult& actionResult);
bool isXCommand(MetaSema::ActionResult& actionResult,
StoredValueRef* resultValue);
bool isqCommand();
bool isUCommand(MetaSema::ActionResult& actionResult);
bool isICommand();
@ -83,8 +82,8 @@ namespace cling {
bool isClassCommand();
bool isgCommand();
bool isTypedefCommand();
bool isShellCommand(StoredValueRef& resultValue,
MetaSema::ActionResult& actionResult);
bool isShellCommand(MetaSema::ActionResult& actionResult,
StoredValueRef* resultValue);
public:
MetaParser(MetaSema* Actions);
void enterNewInputLine(llvm::StringRef Line);
@ -93,8 +92,8 @@ namespace cling {
///
///\returns true if it was meta command.
///
bool isMetaCommand(StoredValueRef& resultValue,
MetaSema::ActionResult& actionResult);
bool isMetaCommand(MetaSema::ActionResult& actionResult,
StoredValueRef* resultValue);
///\brief Returns whether quit was requested via .q command
///

View File

@ -11,6 +11,7 @@
#include "MetaParser.h"
#include "MetaSema.h"
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/StoredValueRef.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/TargetInfo.h"
@ -37,9 +38,10 @@ namespace cling {
MetaProcessor::~MetaProcessor() {}
int MetaProcessor::process(const char* input_text,
StoredValueRef& result,
Interpreter::CompilationResult& compRes) {
result = StoredValueRef();
Interpreter::CompilationResult& compRes,
StoredValueRef* result) {
if (result)
*result = StoredValueRef::invalidValue();
compRes = Interpreter::kSuccess;
int expectedIndent = m_InputValidator->getExpectedIndent();
@ -56,7 +58,7 @@ namespace cling {
// Check for and handle meta commands.
m_MetaParser->enterNewInputLine(input_line);
MetaSema::ActionResult actionResult = MetaSema::AR_Success;
if (m_MetaParser->isMetaCommand(result, actionResult)) {
if (m_MetaParser->isMetaCommand(actionResult, result)) {
if (m_MetaParser->isQuitRequested())
return -1;
@ -79,7 +81,7 @@ namespace cling {
// if (m_Options.RawInput)
// compResLocal = m_Interp.declare(input);
// else
compRes = m_Interp.process(input, &result);
compRes = m_Interp.process(input, result);
return 0;
}
@ -94,8 +96,8 @@ namespace cling {
// Run a file: .x file[(args)]
bool MetaProcessor::executeFile(llvm::StringRef file, llvm::StringRef args,
StoredValueRef& result,
Interpreter::CompilationResult& compRes) {
Interpreter::CompilationResult& compRes,
StoredValueRef* result) {
// Look for start of parameters:
typedef std::pair<llvm::StringRef,llvm::StringRef> StringRefPair;
@ -113,7 +115,7 @@ namespace cling {
if (topmost)
m_TopExecutingFile = m_CurrentlyExecutingFile;
interpRes = m_Interp.process(expression, &result);
interpRes = m_Interp.process(expression, result);
m_CurrentlyExecutingFile = llvm::StringRef();
if (topmost)
@ -125,7 +127,7 @@ namespace cling {
Interpreter::CompilationResult
MetaProcessor::readInputFromFile(llvm::StringRef filename,
StoredValueRef& result,
StoredValueRef* result,
bool ignoreOutmostBlock /*=false*/) {
{
@ -203,8 +205,8 @@ namespace cling {
bool topmost = !m_TopExecutingFile.data();
if (topmost)
m_TopExecutingFile = m_CurrentlyExecutingFile;
Interpreter::CompilationResult ret = Interpreter::kSuccess;
if (process(content.c_str(), result, ret)) {
Interpreter::CompilationResult ret;
if (process(content.c_str(), ret, result)) {
// Input file has to be complete.
llvm::errs()
<< "Error in cling::MetaProcessor: file "

View File

@ -9,6 +9,7 @@
#include "Display.h"
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/StoredValueRef.h"
#include "cling/MetaProcessor/MetaProcessor.h"
#include "clang/AST/ASTContext.h"
@ -43,10 +44,10 @@ namespace cling {
MetaSema::ActionResult MetaSema::actOnxCommand(llvm::sys::Path file,
llvm::StringRef args,
StoredValueRef& result) {
StoredValueRef* result) {
// Fall back to the meta processor for now.
Interpreter::CompilationResult compRes = Interpreter::kFailure;
m_MetaProcessor.executeFile(file.str(), args.str(), result, compRes);
m_MetaProcessor.executeFile(file.str(), args.str(), compRes, result);
ActionResult actionResult = AR_Failure;
if (compRes == Interpreter::kSuccess)
actionResult = AR_Success;
@ -196,7 +197,7 @@ namespace cling {
MetaSema::ActionResult
MetaSema::actOnShellCommand(llvm::StringRef commandLine,
StoredValueRef& result) const {
StoredValueRef* result) const {
llvm::StringRef trimmed(commandLine.trim(" \t\n\v\f\r "));
if (!trimmed.empty()) {
int ret = std::system(trimmed.str().c_str());
@ -206,11 +207,13 @@ namespace cling {
llvm::GenericValue retGV;
retGV.IntVal = llvm::APInt(sizeof(int) * 8, ret, true /*isSigned*/);
Value V(retGV, Ctx.IntTy);
result = StoredValueRef::bitwiseCopy(Ctx, V);
if (result)
*result = StoredValueRef::bitwiseCopy(Ctx, V);
return (ret == 0) ? AR_Success : AR_Failure;
}
result = StoredValueRef();
if (result)
*result = StoredValueRef();
// nothing to run - should this be success or failure?
return AR_Failure;
}

View File

@ -7,8 +7,6 @@
#ifndef CLING_META_SEMA_H
#define CLING_META_SEMA_H
#include "cling/Interpreter/StoredValueRef.h"
namespace llvm {
class StringRef;
class raw_ostream;
@ -20,6 +18,7 @@ namespace llvm {
namespace cling {
class Interpreter;
class MetaProcessor;
class StoredValueRef;
///\brief Semantic analysis for our home-grown language. All implementation
/// details of the commands should go here.
@ -71,7 +70,7 @@ namespace cling {
///\param[in] args - The optional list of arguments.
///
ActionResult actOnxCommand(llvm::sys::Path file, llvm::StringRef args,
StoredValueRef& result);
StoredValueRef* result);
///\brief Actions to be performed on quit.
///
@ -152,7 +151,7 @@ namespace cling {
// list of parameters.
///
ActionResult actOnShellCommand(llvm::StringRef commandLine,
StoredValueRef& result) const;
StoredValueRef* result) const;
};
} // end namespace cling

View File

@ -70,9 +70,8 @@ namespace cling {
break;
}
cling::StoredValueRef result;
cling::Interpreter::CompilationResult compRes;
int indent = m_MetaProcessor->process(line.c_str(), result, compRes);
int indent = m_MetaProcessor->process(line.c_str(), compRes, 0/*result*/);
// Quit requested
if (indent < 0)
break;

View File

@ -54,9 +54,8 @@ int main( int argc, char **argv ) {
for (size_t I = 0, N = Inputs.size(); I < N; ++I) {
std::string line(".x ");
line += Inputs[I].getFile();
cling::StoredValueRef result;
cling::Interpreter::CompilationResult compRes;
ui.getMetaProcessor()->process(line.c_str(), result, compRes);
ui.getMetaProcessor()->process(line.c_str(), compRes, 0);
ret = !CI->getDiagnostics().getClient()->getNumErrors();
}
}