yurai007 created this revision.
yurai007 added reviewers: serge-sans-paille, cor3ntin, jansvoboda11, ymandel,
nikic, xbolva00.
yurai007 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Give that there is only one external user of Lexer::getLangOpts
we can remove getter entirely without much pain.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D120404
Files:
clang/include/clang/Lex/Lexer.h
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/ModuleMap.cpp
Index: clang/lib/Lex/ModuleMap.cpp
===================================================================
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1614,8 +1614,7 @@
SmallString<32> SpellingBuffer;
SpellingBuffer.resize(LToken.getLength() + 1);
const char *Start = SpellingBuffer.data();
- unsigned Length =
- Lexer::getSpelling(LToken, Start, SourceMgr, L.getLangOpts());
+ unsigned Length = L.getSpelling(LToken, Start, SourceMgr);
uint64_t Value;
if (StringRef(Start, Length).getAsInteger(0, Value)) {
Diags.Report(Tok.getLocation(), diag::err_mmap_unknown_token);
Index: clang/lib/Lex/Lexer.cpp
===================================================================
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -444,6 +444,11 @@
return getSpellingSlow(Tok, TokStart, LangOpts, const_cast<char*>(Buffer));
}
+unsigned Lexer::getSpelling(const Token &Tok, const char *&Buffer,
+ const SourceManager &SourceMgr, bool *Invalid) {
+ return getSpelling(Tok, Buffer, SourceMgr, LangOpts, Invalid);
+}
+
/// MeasureTokenLength - Relex the token at the specified location and return
/// its length in bytes in the input file. If the token needs cleaning (e.g.
/// includes a trigraph or an escaped newline) then this count includes bytes
@@ -1193,11 +1198,11 @@
/// prefixed with ??, emit a trigraph warning. If trigraphs are enabled,
/// return the result character. Finally, emit a warning about trigraph use
/// whether trigraphs are enabled or not.
-static char DecodeTrigraphChar(const char *CP, Lexer *L) {
+static char DecodeTrigraphChar(const char *CP, Lexer *L, bool Trigraphs) {
char Res = GetTrigraphCharForLetter(*CP);
if (!Res || !L) return Res;
- if (!L->getLangOpts().Trigraphs) {
+ if (!Trigraphs) {
if (!L->isLexingRawMode())
L->Diag(CP-2, diag::trigraph_ignored);
return 0;
@@ -1371,7 +1376,8 @@
if (Ptr[0] == '?' && Ptr[1] == '?') {
// If this is actually a legal trigraph (not something like "??x"), emit
// a trigraph warning. If so, and if trigraphs are enabled, return it.
- if (char C = DecodeTrigraphChar(Ptr+2, Tok ? this : nullptr)) {
+ if (char C = DecodeTrigraphChar(Ptr + 2, Tok ? this : nullptr,
+ LangOpts.Trigraphs)) {
// Remember that this token needs to be cleaned.
if (Tok) Tok->setFlag(Token::NeedsCleaning);
@@ -2542,8 +2548,8 @@
/// isBlockCommentEndOfEscapedNewLine - Return true if the specified newline
/// character (either \\n or \\r) is part of an escaped newline sequence. Issue
/// a diagnostic if so. We know that the newline is inside of a block comment.
-static bool isEndOfBlockCommentWithEscapedNewLine(const char *CurPtr,
- Lexer *L) {
+static bool isEndOfBlockCommentWithEscapedNewLine(const char *CurPtr, Lexer *L,
+ bool Trigraphs) {
assert(CurPtr[0] == '\n' || CurPtr[0] == '\r');
// Position of the first trigraph in the ending sequence.
@@ -2594,7 +2600,7 @@
if (TrigraphPos) {
// If no trigraphs are enabled, warn that we ignored this trigraph and
// ignore this * character.
- if (!L->getLangOpts().Trigraphs) {
+ if (!Trigraphs) {
if (!L->isLexingRawMode())
L->Diag(TrigraphPos, diag::trigraph_ignored_block_comment);
return false;
@@ -2724,7 +2730,8 @@
break;
if ((CurPtr[-2] == '\n' || CurPtr[-2] == '\r')) {
- if (isEndOfBlockCommentWithEscapedNewLine(CurPtr-2, this)) {
+ if (isEndOfBlockCommentWithEscapedNewLine(CurPtr - 2, this,
+ LangOpts.Trigraphs)) {
// We found the final */, though it had an escaped newline between the
// * and /. We're done!
break;
Index: clang/include/clang/Lex/Lexer.h
===================================================================
--- clang/include/clang/Lex/Lexer.h
+++ clang/include/clang/Lex/Lexer.h
@@ -173,10 +173,6 @@
SourceLocation ExpansionLocEnd,
unsigned TokLen, Preprocessor &PP);
- /// getLangOpts - Return the language features currently enabled.
- /// NOTE: this lexer modifies features as a file is parsed!
- const LangOptions &getLangOpts() const { return LangOpts; }
-
/// getFileLoc - Return the File Location for the file we are lexing out of.
/// The physical location encodes the location where the characters come from,
/// the virtual location encodes where we should *claim* the characters came
@@ -314,6 +310,11 @@
const LangOptions &LangOpts,
bool *Invalid = nullptr);
+ /// getSpelling - This is non-staic variant of getSpelling method which
+ /// doesn't require passing LangOpts argument.
+ unsigned getSpelling(const Token &Tok, const char *&Buffer,
+ const SourceManager &SourceMgr, bool *Invalid = nullptr);
+
/// getSpelling() - Return the 'spelling' of the Tok token. The spelling of a
/// token is the characters used to represent the token in the source file
/// after trigraph expansion and escaped-newline folding. In particular, this
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits