Skip to content
Snippets Groups Projects
Commit 0c6c5a75 authored by Vassil Vassilev's avatar Vassil Vassilev
Browse files

Simplify the implementation of the parsing the meta commands. Read the buffer

to the end when we expect path or whatever. When we need it we can enforce 
stronger checks on the arguments of the parsed meta command.


git-svn-id: http://root.cern.ch/svn/root/trunk@43479 27541ba8-7e3a-0410-8455-c3a389f83636
parent 5a4ef515
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
#include <string> #include <string>
namespace clang {
class Lexer;
}
namespace cling { namespace cling {
class Interpreter; class Interpreter;
...@@ -96,6 +100,9 @@ namespace cling { ...@@ -96,6 +100,9 @@ namespace cling {
/// ///
std::string GetRawTokenName(const clang::Token& Tok); std::string GetRawTokenName(const clang::Token& Tok);
llvm::StringRef ReadToEndOfBuffer(clang::Lexer& RawLexer,
llvm::MemoryBuffer* MB);
///\brief Shows help for the use of interpreter's meta commands ///\brief Shows help for the use of interpreter's meta commands
/// ///
void PrintCommandHelp(); void PrintCommandHelp();
......
...@@ -93,13 +93,8 @@ namespace cling { ...@@ -93,13 +93,8 @@ namespace cling {
} }
// .L <filename> // Load code fragment. // .L <filename> // Load code fragment.
else if (Command == "L") { else if (Command == "L") {
// Check for params // TODO: Additional checks on params
RawLexer.LexFromRawLexer(Tok); bool success = m_Interp.loadFile(ReadToEndOfBuffer(RawLexer, MB));
if (!Tok.isAnyIdentifier())
return false;
Param = GetRawTokenName(Tok);
bool success = m_Interp.loadFile(Param);
if (!success) { if (!success) {
llvm::errs() << "Load file failed.\n"; llvm::errs() << "Load file failed.\n";
} }
...@@ -108,17 +103,8 @@ namespace cling { ...@@ -108,17 +103,8 @@ namespace cling {
// .(x|X) <filename> // Execute function from file, function name is // .(x|X) <filename> // Execute function from file, function name is
// // filename without extension. // // filename without extension.
else if ((Command == "x") || (Command == "X")) { else if ((Command == "x") || (Command == "X")) {
// TODO: add extensive checks the folder paths and filenames // TODO: Additional checks on params
//RawLexer->LexFromRawLexer(Tok); llvm::sys::Path path(ReadToEndOfBuffer(RawLexer, MB));
//if (!Tok.isAnyIdentifier())
// return false;
const char* CurPtr = RawLexer.getBufferLocation();;
Token TmpTok;
RawLexer.getAndAdvanceChar(CurPtr, TmpTok);
llvm::StringRef Param(CurPtr,
MB->getBufferSize() - (CurPtr - MB->getBufferStart()));
llvm::sys::Path path(Param);
if (!path.isValid()) if (!path.isValid())
return false; return false;
...@@ -204,13 +190,8 @@ namespace cling { ...@@ -204,13 +190,8 @@ namespace cling {
if (Tok.is(tok::eof)) if (Tok.is(tok::eof))
m_Interp.DumpIncludePath(); m_Interp.DumpIncludePath();
else { else {
// TODO: add extensive checks the folder paths and filenames // TODO: Additional checks on params
const char* CurPtr = RawLexer.getBufferLocation();; llvm::sys::Path path(ReadToEndOfBuffer(RawLexer, MB));
Token TmpTok;
RawLexer.getAndAdvanceChar(CurPtr, TmpTok);
llvm::StringRef Param(CurPtr,
MB->getBufferSize()-(CurPtr-MB->getBufferStart()));
llvm::sys::Path path(Param);
if (path.isValid()) if (path.isValid())
m_Interp.AddIncludePath(path.c_str()); m_Interp.AddIncludePath(path.c_str());
...@@ -273,6 +254,14 @@ namespace cling { ...@@ -273,6 +254,14 @@ namespace cling {
} }
llvm::StringRef MetaProcessor::ReadToEndOfBuffer(Lexer& RawLexer,
llvm::MemoryBuffer* MB) {
const char* CurPtr = RawLexer.getBufferLocation();
Token TmpTok;
RawLexer.getAndAdvanceChar(CurPtr, TmpTok);
return StringRef(CurPtr, MB->getBufferSize()-(CurPtr-MB->getBufferStart()));
}
void MetaProcessor::PrintCommandHelp() { void MetaProcessor::PrintCommandHelp() {
llvm::outs() << "Cling meta commands usage\n"; llvm::outs() << "Cling meta commands usage\n";
llvm::outs() << "Syntax: .Command [arg0 arg1 ... argN]\n"; llvm::outs() << "Syntax: .Command [arg0 arg1 ... argN]\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment