diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h --- a/clang/include/clang/Lex/Lexer.h +++ b/clang/include/clang/Lex/Lexer.h @@ -13,7 +13,6 @@ #ifndef LLVM_CLANG_LEX_LEXER_H #define LLVM_CLANG_LEX_LEXER_H -#include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TokenKinds.h" #include "clang/Lex/PreprocessorLexer.h" @@ -36,6 +35,7 @@ class DiagnosticBuilder; class Preprocessor; class SourceManager; +class LangOptions; /// ConflictMarkerKind - Kinds of conflict marker which the lexer might be /// recovering from. @@ -90,8 +90,11 @@ // Location for start of file. SourceLocation FileLoc; - // LangOpts enabled by this language (cache). - LangOptions LangOpts; + // LangOpts enabled by this language. + const LangOptions &LangOpts; + + // True if '//' line comments are enabled. + bool LineComment; // True if lexer for _Pragma handling. bool Is_PragmaLexer; diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -136,7 +136,8 @@ Preprocessor &PP, bool IsFirstIncludeOfFile) : PreprocessorLexer(&PP, FID), FileLoc(PP.getSourceManager().getLocForStartOfFile(FID)), - LangOpts(PP.getLangOpts()), IsFirstTimeLexingFile(IsFirstIncludeOfFile) { + LangOpts(PP.getLangOpts()), LineComment(LangOpts.LineComment), + IsFirstTimeLexingFile(IsFirstIncludeOfFile) { InitLexer(InputFile.getBufferStart(), InputFile.getBufferStart(), InputFile.getBufferEnd()); @@ -149,7 +150,7 @@ Lexer::Lexer(SourceLocation fileloc, const LangOptions &langOpts, const char *BufStart, const char *BufPtr, const char *BufEnd, bool IsFirstIncludeOfFile) - : FileLoc(fileloc), LangOpts(langOpts), + : FileLoc(fileloc), LangOpts(langOpts), LineComment(LangOpts.LineComment), IsFirstTimeLexingFile(IsFirstIncludeOfFile) { InitLexer(BufStart, BufPtr, BufEnd); @@ -2376,13 +2377,13 @@ bool &TokAtPhysicalStartOfLine) { // If Line comments aren't explicitly enabled for this language, emit an // extension warning. - if (!LangOpts.LineComment) { + if (!LineComment) { if (!isLexingRawMode()) // There's no PP in raw mode, so can't emit diags. Diag(BufferPtr, diag::ext_line_comment); // Mark them enabled so we only emit one warning for this translation // unit. - LangOpts.LineComment = true; + LineComment = true; } // Scan over the body of the comment. The common case, when scanning, is that @@ -3433,8 +3434,7 @@ // If the next token is obviously a // or /* */ comment, skip it efficiently // too (without going through the big switch stmt). if (CurPtr[0] == '/' && CurPtr[1] == '/' && !inKeepCommentMode() && - LangOpts.LineComment && - (LangOpts.CPlusPlus || !LangOpts.TraditionalCPP)) { + LineComment && (LangOpts.CPlusPlus || !LangOpts.TraditionalCPP)) { if (SkipLineComment(Result, CurPtr+2, TokAtPhysicalStartOfLine)) return true; // There is a token to return. goto SkipIgnoredUnits; @@ -3741,8 +3741,8 @@ // "foo". Check to see if the character after the second slash is a '*'. // If so, we will lex that as a "/" instead of the start of a comment. // However, we never do this if we are just preprocessing. - bool TreatAsComment = LangOpts.LineComment && - (LangOpts.CPlusPlus || !LangOpts.TraditionalCPP); + bool TreatAsComment = + LineComment && (LangOpts.CPlusPlus || !LangOpts.TraditionalCPP); if (!TreatAsComment) if (!(PP && PP->isPreprocessedOutput())) TreatAsComment = getCharAndSize(CurPtr+SizeTmp, SizeTmp2) != '*';