diff --git a/include/cling/Interpreter/Interpreter.h b/include/cling/Interpreter/Interpreter.h index ee8cd8f0..e4e480b8 100644 --- a/include/cling/Interpreter/Interpreter.h +++ b/include/cling/Interpreter/Interpreter.h @@ -297,7 +297,7 @@ namespace cling { /// ///\returns true if the input should be wrapped. /// - bool ShouldWrapInput(llvm::StringRef input); + bool ShouldWrapInput(const std::string& input); ///\brief Wraps a given input. /// diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index afc99357..f3809a1d 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -475,15 +475,15 @@ namespace cling { return Interpreter::kFailure; } - bool Interpreter::ShouldWrapInput(llvm::StringRef input) { + bool Interpreter::ShouldWrapInput(const std::string& input) { llvm::OwningPtr buf; buf.reset(llvm::MemoryBuffer::getMemBuffer(input, "Cling Preparse Buf")); - Lexer WrapLexer(SourceLocation(), getSema().getLangOpts(), input.data(), - input.data(), input.data() + input.size()); + Lexer WrapLexer(SourceLocation(), getSema().getLangOpts(), input.c_str(), + input.c_str(), input.c_str() + input.size()); Token Tok; WrapLexer.Lex(Tok); - tok::TokenKind kind = Tok.getKind(); + const tok::TokenKind kind = Tok.getKind(); if (kind == tok::raw_identifier && !Tok.needsCleaning()) { StringRef keyword(Tok.getRawIdentifierData(), Tok.getLength()); @@ -494,12 +494,16 @@ namespace cling { if (keyword.equals("namespace")) return false; } - - switch (kind) { - case tok::hash : return false; - default: - return true; + else if (kind == tok::hash) { + WrapLexer.Lex(Tok); + if (Tok.is(tok::raw_identifier) && !Tok.needsCleaning()) { + StringRef keyword(Tok.getRawIdentifierData(), Tok.getLength()); + if (keyword.equals("include")) + return false; + } } + + return true; }