Teach the input validator to handle imbalance of ' or ".
Add constness to the reference. Improve style. git-svn-id: http://root.cern.ch/svn/root/trunk@47587 27541ba8-7e3a-0410-8455-c3a389f83636
This commit is contained in:
parent
e02c6a1da8
commit
6ff2764fc1
@ -12,7 +12,7 @@ using namespace clang;
|
||||
|
||||
namespace cling {
|
||||
InputValidator::ValidationResult
|
||||
InputValidator::validate(llvm::StringRef line, LangOptions& LO) {
|
||||
InputValidator::validate(llvm::StringRef line, const LangOptions& LO) {
|
||||
if (!m_Input.empty())
|
||||
m_Input.append("\n");
|
||||
else
|
||||
@ -20,8 +20,16 @@ namespace cling {
|
||||
|
||||
m_Input.append(line);
|
||||
|
||||
|
||||
// Imballanced ' or " drives our lexer nuts.
|
||||
llvm::StringRef fullInput(m_Input);
|
||||
if (fullInput.count('\'') % 2 || fullInput.count('"') % 2) {
|
||||
return kIncomplete;
|
||||
}
|
||||
|
||||
llvm::OwningPtr<llvm::MemoryBuffer> MB;
|
||||
MB.reset(llvm::MemoryBuffer::getMemBuffer(line));
|
||||
|
||||
Lexer RawLexer(SourceLocation(), LO, MB->getBufferStart(),
|
||||
MB->getBufferStart(), MB->getBufferEnd());
|
||||
Token Tok;
|
||||
@ -33,9 +41,11 @@ namespace cling {
|
||||
kind -= (int)tok::l_square;
|
||||
if (kind % 2) {
|
||||
// closing the right one?
|
||||
if (m_ParenStack.empty()) return kMismatch;
|
||||
if (m_ParenStack.empty())
|
||||
return kMismatch;
|
||||
int prev = m_ParenStack.top();
|
||||
if (prev != kind - 1) return kMismatch;
|
||||
if (prev != kind - 1)
|
||||
return kMismatch;
|
||||
m_ParenStack.pop();
|
||||
} else {
|
||||
m_ParenStack.push(kind);
|
||||
@ -43,6 +53,7 @@ namespace cling {
|
||||
}
|
||||
}
|
||||
while (Tok.isNot(tok::eof));
|
||||
|
||||
if (!m_ParenStack.empty())
|
||||
return kIncomplete;
|
||||
|
||||
|
@ -7,6 +7,8 @@
|
||||
#ifndef CLING_INPUT_VALIDATOR_H
|
||||
#define CLING_INPUT_VALIDATOR_H
|
||||
|
||||
#include "clang/Basic/TokenKinds.h"
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
#include <stack>
|
||||
@ -22,6 +24,7 @@ namespace cling {
|
||||
///
|
||||
class InputValidator {
|
||||
private:
|
||||
|
||||
///\brief The input being collected.
|
||||
///
|
||||
std::string m_Input;
|
||||
@ -48,7 +51,8 @@ namespace cling {
|
||||
///\param[in] LO - Langluage options to validate against.
|
||||
///\returns Information about the outcome of the validation.
|
||||
///
|
||||
ValidationResult validate(llvm::StringRef line, clang::LangOptions& LO);
|
||||
ValidationResult validate(llvm::StringRef line,
|
||||
const clang::LangOptions& LO);
|
||||
|
||||
///\returns Reference to the collected input.
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user