From: Ted Kremenek Date: Fri, 21 Nov 2008 19:41:29 +0000 (+0000) Subject: When creating raw tokens for the PTHLexer specially handle angled strings for #includ... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c840f0cbd9552a28adc548ee353303c4b838f61c;p=clang When creating raw tokens for the PTHLexer specially handle angled strings for #include directives. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59840 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index a12309a7bf..da877493a0 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/lib/Lex/PPLexerChange.cpp @@ -90,18 +90,42 @@ void Preprocessor::EnterSourceFile(unsigned FileID, // Lex the file, populating our data structures. std::vector* Tokens = new std::vector(); - Token Tok; + Token Tok; do { L.LexFromRawLexer(Tok); - if (Tok.is(tok::identifier)) + if (Tok.is(tok::identifier)) { Tok.setIdentifierInfo(LookUpIdentifierInfo(Tok)); - - // Store the token. - Tokens->push_back(Tok); + } + else if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) { + // Special processing for #include. Store the '#' token and lex + // the next token. + Tokens->push_back(Tok); + L.LexFromRawLexer(Tok); + + // Did we see 'include'/'import'/'include_next'? + if (!Tok.is(tok::identifier)) + continue; + + IdentifierInfo* II = LookUpIdentifierInfo(Tok); + Tok.setIdentifierInfo(II); + tok::PPKeywordKind K = II->getPPKeywordID(); + + if (K == tok::pp_include || K == tok::pp_import || + K == tok::pp_include_next) { + + // Save the 'include' token. + Tokens->push_back(Tok); + + // Lex the next token as an include string. + L.ParsingPreprocessorDirective = true; + L.LexIncludeFilename(Tok); + L.ParsingPreprocessorDirective = false; + } + } } - while (Tok.isNot(tok::eof)); + while (Tokens->push_back(Tok), Tok.isNot(tok::eof)); if (CurPPLexer || CurTokenLexer) PushIncludeMacroStack();