diff --git a/interpreter/cling/include/cling/MetaProcessor/MetaParser.h b/interpreter/cling/include/cling/MetaProcessor/MetaParser.h index 63f181a63e14d..7591eb62ab3f3 100644 --- a/interpreter/cling/include/cling/MetaProcessor/MetaParser.h +++ b/interpreter/cling/include/cling/MetaProcessor/MetaParser.h @@ -65,7 +65,7 @@ namespace cling { class MetaParser { private: MetaLexer m_Lexer; - std::unique_ptr m_Actions; + MetaSema &m_Actions; llvm::SmallVector m_TokenCache; llvm::SmallVector m_MetaSymbolCache; private: @@ -113,8 +113,7 @@ namespace cling { bool isShellCommand(MetaSema::ActionResult& actionResult, Value* resultValue); public: - MetaParser(MetaSema* Actions); - void enterNewInputLine(llvm::StringRef Line); + MetaParser(MetaSema &Actions, llvm::StringRef Line); ///\brief Drives the recursive decendent parsing. /// @@ -127,7 +126,7 @@ namespace cling { /// bool isQuitRequested() const; - MetaSema& getActions() const { return *m_Actions.get(); } + MetaSema& getActions() const { return m_Actions; } }; } // end namespace cling diff --git a/interpreter/cling/include/cling/MetaProcessor/MetaProcessor.h b/interpreter/cling/include/cling/MetaProcessor/MetaProcessor.h index aa3716f8d8ac6..1469e5ed1dcb0 100644 --- a/interpreter/cling/include/cling/MetaProcessor/MetaProcessor.h +++ b/interpreter/cling/include/cling/MetaProcessor/MetaProcessor.h @@ -24,7 +24,7 @@ namespace cling { class Interpreter; class InputValidator; - class MetaParser; + class MetaSema; class Value; ///\brief Class that helps processing meta commands, which add extra @@ -43,7 +43,7 @@ namespace cling { ///\brief The parser used to parse our tiny "meta" language /// - std::unique_ptr m_MetaParser; + std::unique_ptr m_MetaSema; ///\brief Currently executing file as passed into executeFile /// diff --git a/interpreter/cling/lib/MetaProcessor/MetaParser.cpp b/interpreter/cling/lib/MetaProcessor/MetaParser.cpp index 61387fc8055a4..0d3ab3c74a733 100644 --- a/interpreter/cling/lib/MetaProcessor/MetaParser.cpp +++ b/interpreter/cling/lib/MetaProcessor/MetaParser.cpp @@ -24,9 +24,9 @@ namespace cling { - MetaParser::MetaParser(MetaSema* Actions) : m_Lexer("") { - m_Actions.reset(Actions); - const InvocationOptions& Opts = Actions->getInterpreter().getOptions(); + MetaParser::MetaParser(MetaSema &Actions, llvm::StringRef Line) : + m_Lexer(Line), m_Actions(Actions) { + const InvocationOptions& Opts = Actions.getInterpreter().getOptions(); MetaLexer metaSymbolLexer(Opts.MetaString); Token Tok; while(true) { @@ -37,11 +37,6 @@ namespace cling { } } - void MetaParser::enterNewInputLine(llvm::StringRef Line) { - m_Lexer.reset(Line); - m_TokenCache.clear(); - } - void MetaParser::consumeToken() { if (m_TokenCache.size()) m_TokenCache.erase(m_TokenCache.begin()); @@ -102,7 +97,7 @@ namespace cling { } bool MetaParser::isQuitRequested() const { - return m_Actions->isQuitRequested(); + return m_Actions.isQuitRequested(); } bool MetaParser::isCommandSymbol() { @@ -143,11 +138,11 @@ namespace cling { consumeAnyStringToken(tok::comment); if (getCurTok().is(tok::raw_ident)) { result = true; - actionResult = m_Actions->actOnLCommand(getCurTok().getIdent()); + actionResult = m_Actions.actOnLCommand(getCurTok().getIdent()); consumeToken(); if (getCurTok().is(tok::comment)) { consumeAnyStringToken(tok::eof); - m_Actions->actOnComment(getCurTok().getIdent()); + m_Actions.actOnComment(getCurTok().getIdent()); } } } @@ -168,7 +163,7 @@ namespace cling { if (getCurTok().is(tok::raw_ident)) { result = true; std::string outputFile = getCurTok().getIdent(); - actionResult = m_Actions->actOnTCommand(inputFile, outputFile); + actionResult = m_Actions.actOnTCommand(inputFile, outputFile); } } } @@ -257,9 +252,9 @@ namespace cling { } // Empty file means std. actionResult = - m_Actions->actOnRedirectCommand(file/*file*/, - stream/*which stream to redirect*/, - append/*append mode*/); + m_Actions.actOnRedirectCommand(file/*file*/, + stream/*which stream to redirect*/, + append/*append mode*/); return true; } return false; @@ -316,7 +311,7 @@ namespace cling { if (args.empty()) args = "()"; - actionResult = m_Actions->actOnxCommand(file, args, resultValue); + actionResult = m_Actions.actOnxCommand(file, args, resultValue); return true; } @@ -335,7 +330,7 @@ namespace cling { bool result = false; if (getCurTok().is(tok::ident) && getCurTok().getIdent().equals("q")) { result = true; - m_Actions->actOnqCommand(); + m_Actions.actOnqCommand(); } return result; } @@ -346,7 +341,7 @@ namespace cling { llvm::StringRef path; if (getCurTok().is(tok::raw_ident)) { path = getCurTok().getIdent(); - actionResult = m_Actions->actOnUCommand(path); + actionResult = m_Actions.actOnUCommand(path); return true; } } @@ -361,7 +356,7 @@ namespace cling { llvm::StringRef path; if (getCurTok().is(tok::raw_ident)) path = getCurTok().getIdent(); - m_Actions->actOnICommand(path); + m_Actions.actOnICommand(path); return true; } return false; @@ -378,7 +373,7 @@ namespace cling { consumeAnyStringToken(tok::eof); if (getCurTok().is(tok::raw_ident)) return false; - actionResult = m_Actions->actOnOCommand(level); + actionResult = m_Actions.actOnOCommand(level); return true; } } else { @@ -389,11 +384,11 @@ namespace cling { int level = 0; if (!lastStringToken.getIdent().getAsInteger(10, level) && level >= 0) { - actionResult = m_Actions->actOnOCommand(level); + actionResult = m_Actions.actOnOCommand(level); return true; } } else { - m_Actions->actOnOCommand(); + m_Actions.actOnOCommand(); actionResult = MetaSema::AR_Success; return true; } @@ -409,7 +404,7 @@ namespace cling { ) { consumeToken(); skipWhitespace(); - m_Actions->actOnAtCommand(); + m_Actions.actOnAtCommand(); return true; } return false; @@ -423,7 +418,7 @@ namespace cling { skipWhitespace(); if (getCurTok().is(tok::constant)) mode = (MetaSema::SwitchMode)getCurTok().getConstantAsBool(); - m_Actions->actOnrawInputCommand(mode); + m_Actions.actOnrawInputCommand(mode); return true; } return false; @@ -437,7 +432,7 @@ namespace cling { skipWhitespace(); if (getCurTok().is(tok::constant)) mode = getCurTok().getConstant(); - m_Actions->actOndebugCommand(mode); + m_Actions.actOndebugCommand(mode); return true; } return false; @@ -451,7 +446,7 @@ namespace cling { skipWhitespace(); if (getCurTok().is(tok::constant)) mode = (MetaSema::SwitchMode)getCurTok().getConstantAsBool(); - m_Actions->actOnprintDebugCommand(mode); + m_Actions.actOnprintDebugCommand(mode); return true; } return false; @@ -467,7 +462,7 @@ namespace cling { return false; // FIXME: Issue proper diagnostics std::string ident = getCurTok().getIdentNoQuotes(); consumeToken(); - m_Actions->actOnstoreStateCommand(ident); + m_Actions.actOnstoreStateCommand(ident); return true; } return false; @@ -483,7 +478,7 @@ namespace cling { return false; // FIXME: Issue proper diagnostics std::string ident = getCurTok().getIdentNoQuotes(); consumeToken(); - m_Actions->actOncompareStateCommand(ident); + m_Actions.actOncompareStateCommand(ident); return true; } return false; @@ -500,7 +495,7 @@ namespace cling { consumeToken(); skipWhitespace(); const Token& next = getCurTok(); - m_Actions->actOnstatsCommand(what, next.is(tok::ident) + m_Actions.actOnstatsCommand(what, next.is(tok::ident) ? next.getIdent() : llvm::StringRef()); return true; } @@ -518,7 +513,7 @@ namespace cling { llvm::StringRef ident = getCurTok().getIdent(); consumeToken(); skipWhitespace(); - m_Actions->actOnstatsCommand(ident.equals("ast") + m_Actions.actOnstatsCommand(ident.equals("ast") ? llvm::StringRef("asttree") : ident, getCurTok().is(tok::ident) ? getCurTok().getIdent() : llvm::StringRef()); consumeToken(); @@ -534,9 +529,9 @@ namespace cling { skipWhitespace(); const Token& next = getCurTok(); if (next.is(tok::constant)) - m_Actions->actOnUndoCommand(next.getConstant()); + m_Actions.actOnUndoCommand(next.getConstant()); else - m_Actions->actOnUndoCommand(); + m_Actions.actOnUndoCommand(); return true; } return false; @@ -550,7 +545,7 @@ namespace cling { skipWhitespace(); if (getCurTok().is(tok::constant)) mode = (MetaSema::SwitchMode)getCurTok().getConstantAsBool(); - m_Actions->actOndynamicExtensionsCommand(mode); + m_Actions.actOndynamicExtensionsCommand(mode); return true; } return false; @@ -560,7 +555,7 @@ namespace cling { const Token& Tok = getCurTok(); if (Tok.is(tok::quest_mark) || (Tok.is(tok::ident) && Tok.getIdent().equals("help"))) { - m_Actions->actOnhelpCommand(); + m_Actions.actOnhelpCommand(); return true; } return false; @@ -568,7 +563,7 @@ namespace cling { bool MetaParser::isfileExCommand() { if (getCurTok().is(tok::ident) && getCurTok().getIdent().equals("fileEx")) { - m_Actions->actOnfileExCommand(); + m_Actions.actOnfileExCommand(); return true; } return false; @@ -576,7 +571,7 @@ namespace cling { bool MetaParser::isfilesCommand() { if (getCurTok().is(tok::ident) && getCurTok().getIdent().equals("files")) { - m_Actions->actOnfilesCommand(); + m_Actions.actOnfilesCommand(); return true; } return false; @@ -591,11 +586,11 @@ namespace cling { llvm::StringRef className; if (NextTok.is(tok::raw_ident)) className = NextTok.getIdent(); - m_Actions->actOnclassCommand(className); + m_Actions.actOnclassCommand(className); return true; } else if (Tok.getIdent().equals("Class")) { - m_Actions->actOnClassCommand(); + m_Actions.actOnClassCommand(); return true; } } @@ -609,7 +604,7 @@ namespace cling { consumeAnyStringToken(tok::eof); if (getCurTok().is(tok::raw_ident)) return false; - m_Actions->actOnNamespaceCommand(); + m_Actions.actOnNamespaceCommand(); return true; } } @@ -623,7 +618,7 @@ namespace cling { llvm::StringRef varName; if (getCurTok().is(tok::ident)) varName = getCurTok().getIdent(); - m_Actions->actOngCommand(varName); + m_Actions.actOngCommand(varName); return true; } return false; @@ -638,7 +633,7 @@ namespace cling { llvm::StringRef typedefName; if (NextTok.is(tok::raw_ident)) typedefName = NextTok.getIdent(); - m_Actions->actOnTypedefCommand(typedefName); + m_Actions.actOnTypedefCommand(typedefName); return true; } } @@ -656,7 +651,7 @@ namespace cling { if (NextTok.is(tok::raw_ident)) { llvm::StringRef commandLine(NextTok.getIdent()); if (!commandLine.empty()) - actionResult = m_Actions->actOnShellCommand(commandLine, + actionResult = m_Actions.actOnShellCommand(commandLine, resultValue); } return true; diff --git a/interpreter/cling/lib/MetaProcessor/MetaProcessor.cpp b/interpreter/cling/lib/MetaProcessor/MetaProcessor.cpp index 4e14ff24ed36c..13bf73da9833b 100644 --- a/interpreter/cling/lib/MetaProcessor/MetaProcessor.cpp +++ b/interpreter/cling/lib/MetaProcessor/MetaProcessor.cpp @@ -286,7 +286,7 @@ namespace cling { MetaProcessor::MetaProcessor(Interpreter& interp, raw_ostream& outs) : m_Interp(interp), m_Outs(&outs) { m_InputValidator.reset(new InputValidator()); - m_MetaParser.reset(new MetaParser(new MetaSema(interp, *this))); + m_MetaSema.reset(new MetaSema(interp, *this)); } MetaProcessor::~MetaProcessor() { @@ -311,12 +311,12 @@ namespace cling { } // Check for and handle meta commands. - m_MetaParser->enterNewInputLine(input_line); + MetaParser parser(*m_MetaSema, input_line); MetaSema::ActionResult actionResult = MetaSema::AR_Success; if (!m_InputValidator->inBlockComment() && - m_MetaParser->isMetaCommand(actionResult, result)) { + parser.isMetaCommand(actionResult, result)) { - if (m_MetaParser->isQuitRequested()) + if (parser.isQuitRequested()) return -1; if (actionResult != MetaSema::AR_Success) @@ -525,7 +525,7 @@ namespace cling { void MetaProcessor::registerUnloadPoint(const Transaction* T, llvm::StringRef filename) { - m_MetaParser->getActions().registerUnloadPoint(T, filename); + m_MetaSema->registerUnloadPoint(T, filename); } } // end namespace cling