diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 18:03:49 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2009-10-14 18:03:49 +0000 |
commit | 9092c3e0fa01f3139b016d05d267a89e3b07747a (patch) | |
tree | 137ebebcae16fb0ce7ab4af456992bbd8d22fced /lib/Lex/PPDirectives.cpp | |
parent | 4981926bf654fe5a2c3893f24ca44106b217e71e (diff) | |
download | FreeBSD-src-9092c3e0fa01f3139b016d05d267a89e3b07747a.zip FreeBSD-src-9092c3e0fa01f3139b016d05d267a89e3b07747a.tar.gz |
Update clang to r84119.
Diffstat (limited to 'lib/Lex/PPDirectives.cpp')
-rw-r--r-- | lib/Lex/PPDirectives.cpp | 352 |
1 files changed, 176 insertions, 176 deletions
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index af59ded..196a77f 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -26,7 +26,7 @@ using namespace clang; MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) { MacroInfo *MI; - + if (!MICache.empty()) { MI = MICache.back(); MICache.pop_back(); @@ -61,13 +61,13 @@ void Preprocessor::DiscardUntilEndOfDirective() { void Preprocessor::ReadMacroName(Token &MacroNameTok, char isDefineUndef) { // Read the token, don't allow macro expansion on it. LexUnexpandedToken(MacroNameTok); - + // Missing macro name? if (MacroNameTok.is(tok::eom)) { Diag(MacroNameTok, diag::err_pp_missing_macro_name); return; } - + IdentifierInfo *II = MacroNameTok.getIdentifierInfo(); if (II == 0) { std::string Spelling = getSpelling(MacroNameTok); @@ -93,7 +93,7 @@ void Preprocessor::ReadMacroName(Token &MacroNameTok, char isDefineUndef) { // Okay, we got a good identifier node. Return it. return; } - + // Invalid macro name, read and discard the rest of the line. Then set the // token kind to tok::eom. MacroNameTok.setKind(tok::eom); @@ -112,12 +112,12 @@ void Preprocessor::CheckEndOfDirective(const char *DirType, bool EnableMacros) { Lex(Tmp); else LexUnexpandedToken(Tmp); - + // There should be no tokens after the directive, but we allow them as an // extension. while (Tmp.is(tok::comment)) // Skip comments in -C mode. LexUnexpandedToken(Tmp); - + if (Tmp.isNot(tok::eom)) { // Add a fixit in GNU/C99/C++ mode. Don't offer a fixit for strict-C89, // because it is more trouble than it is worth to insert /**/ and check that @@ -148,12 +148,12 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, CurPPLexer->pushConditionalLevel(IfTokenLoc, /*isSkipping*/false, FoundNonSkipPortion, FoundElse); - + if (CurPTHLexer) { PTHSkipExcludedConditionalBlock(); return; } - + // Enter raw mode to disable identifier lookup (and thus macro expansion), // disabling warnings, etc. CurPPLexer->LexingRawMode = true; @@ -163,7 +163,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, CurLexer->Lex(Tok); else CurPTHLexer->Lex(Tok); - + // If this is the end of the buffer, we have an error. if (Tok.is(tok::eof)) { // Emit errors for each unterminated conditional on the stack, including @@ -172,26 +172,26 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, Diag(CurPPLexer->ConditionalStack.back().IfLoc, diag::err_pp_unterminated_conditional); CurPPLexer->ConditionalStack.pop_back(); - } - + } + // Just return and let the caller lex after this #include. break; } - + // If this token is not a preprocessor directive, just skip it. if (Tok.isNot(tok::hash) || !Tok.isAtStartOfLine()) continue; - + // We just parsed a # character at the start of a line, so we're in // directive mode. Tell the lexer this so any newlines we see will be // converted into an EOM token (this terminates the macro). CurPPLexer->ParsingPreprocessorDirective = true; if (CurLexer) CurLexer->SetCommentRetentionState(false); - + // Read the next token, the directive flavor. LexUnexpandedToken(Tok); - + // If this isn't an identifier directive (e.g. is "# 1\n" or "#\n", or // something bogus), skip it. if (Tok.isNot(tok::identifier)) { @@ -208,14 +208,14 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, // other common directives. const char *RawCharData = SourceMgr.getCharacterData(Tok.getLocation()); char FirstChar = RawCharData[0]; - if (FirstChar >= 'a' && FirstChar <= 'z' && + if (FirstChar >= 'a' && FirstChar <= 'z' && FirstChar != 'i' && FirstChar != 'e') { CurPPLexer->ParsingPreprocessorDirective = false; // Restore comment saving mode. if (CurLexer) CurLexer->SetCommentRetentionState(KeepComments); continue; } - + // Get the identifier name without trigraphs or embedded newlines. Note // that we can't use Tok.getIdentifierInfo() because its lookup is disabled // when skipping. @@ -240,7 +240,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, Directive[IdLen] = 0; FirstChar = Directive[0]; } - + if (FirstChar == 'i' && Directive[1] == 'f') { if ((IdLen == 2) || // "if" (IdLen == 5 && !strcmp(Directive+2, "def")) || // "ifdef" @@ -260,7 +260,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, bool InCond = CurPPLexer->popConditionalLevel(CondInfo); InCond = InCond; // Silence warning in no-asserts mode. assert(!InCond && "Can't be skipping if not in a conditional!"); - + // If we popped the outermost skipping block, we're done skipping! if (!CondInfo.WasSkipping) break; @@ -270,13 +270,13 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, // as a non-skipping conditional. DiscardUntilEndOfDirective(); // C99 6.10p4. PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel(); - + // If this is a #else with a #else before it, report the error. if (CondInfo.FoundElse) Diag(Tok, diag::pp_err_else_after_else); - + // Note that we've seen a #else in this conditional. CondInfo.FoundElse = true; - + // If the conditional is at the top level, and the #if block wasn't // entered, enter the #else block now. if (!CondInfo.WasSkipping && !CondInfo.FoundNonSkip) { @@ -301,10 +301,10 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro); CurPPLexer->LexingRawMode = true; } - + // If this is a #elif with a #else before it, report the error. if (CondInfo.FoundElse) Diag(Tok, diag::pp_err_elif_after_else); - + // If this condition is true, enter it! if (ShouldEnter) { CondInfo.FoundNonSkip = true; @@ -312,7 +312,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, } } } - + CurPPLexer->ParsingPreprocessorDirective = false; // Restore comment saving mode. if (CurLexer) CurLexer->SetCommentRetentionState(KeepComments); @@ -325,11 +325,11 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, } void Preprocessor::PTHSkipExcludedConditionalBlock() { - - while(1) { + + while (1) { assert(CurPTHLexer); assert(CurPTHLexer->LexingRawMode == false); - + // Skip to the next '#else', '#elif', or #endif. if (CurPTHLexer->SkipBlock()) { // We have reached an #endif. Both the '#' and 'endif' tokens @@ -340,12 +340,12 @@ void Preprocessor::PTHSkipExcludedConditionalBlock() { assert(!InCond && "Can't be skipping if not in a conditional!"); break; } - + // We have reached a '#else' or '#elif'. Lex the next token to get // the directive flavor. Token Tok; LexUnexpandedToken(Tok); - + // We can actually look up the IdentifierInfo here since we aren't in // raw mode. tok::PPKeywordKind K = Tok.getIdentifierInfo()->getPPKeywordID(); @@ -357,32 +357,32 @@ void Preprocessor::PTHSkipExcludedConditionalBlock() { PPConditionalInfo &CondInfo = CurPTHLexer->peekConditionalLevel(); // Note that we've seen a #else in this conditional. CondInfo.FoundElse = true; - + // If the #if block wasn't entered then enter the #else block now. if (!CondInfo.FoundNonSkip) { CondInfo.FoundNonSkip = true; - + // Scan until the eom token. CurPTHLexer->ParsingPreprocessorDirective = true; DiscardUntilEndOfDirective(); CurPTHLexer->ParsingPreprocessorDirective = false; - + break; } - + // Otherwise skip this block. continue; } - + assert(K == tok::pp_elif); PPConditionalInfo &CondInfo = CurPTHLexer->peekConditionalLevel(); // If this is a #elif with a #else before it, report the error. if (CondInfo.FoundElse) Diag(Tok, diag::pp_err_elif_after_else); - + // If this is in a skipping block or if we're already handled this #if - // block, don't bother parsing the condition. We just skip this block. + // block, don't bother parsing the condition. We just skip this block. if (CondInfo.FoundNonSkip) continue; @@ -417,7 +417,7 @@ const FileEntry *Preprocessor::LookupFile(const char *FilenameStart, if (!FromDir) { FileID FID = getCurrentFileLexer()->getFileID(); CurFileEnt = SourceMgr.getFileEntryForID(FID); - + // If there is no file entry associated with this file, it must be the // predefines buffer. Any other file is not lexed with a normal lexer, so // it won't be scanned for preprocessor directives. If we have the @@ -429,14 +429,14 @@ const FileEntry *Preprocessor::LookupFile(const char *FilenameStart, CurFileEnt = SourceMgr.getFileEntryForID(FID); } } - + // Do a standard file entry lookup. CurDir = CurDirLookup; const FileEntry *FE = HeaderInfo.LookupFile(FilenameStart, FilenameEnd, isAngled, FromDir, CurDir, CurFileEnt); if (FE) return FE; - + // Otherwise, see if this is a subframework header. If so, this is relative // to one of the headers on the #include stack. Walk the list of the current // headers on the #include stack and pass them to HeaderInfo. @@ -446,18 +446,18 @@ const FileEntry *Preprocessor::LookupFile(const char *FilenameStart, CurFileEnt))) return FE; } - + for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) { IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1]; if (IsFileLexer(ISEntry)) { - if ((CurFileEnt = + if ((CurFileEnt = SourceMgr.getFileEntryForID(ISEntry.ThePPLexer->getFileID()))) if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart, FilenameEnd, CurFileEnt))) return FE; } } - + // Otherwise, we really couldn't find the file. return 0; } @@ -468,31 +468,31 @@ const FileEntry *Preprocessor::LookupFile(const char *FilenameStart, //===----------------------------------------------------------------------===// /// HandleDirective - This callback is invoked when the lexer sees a # token -/// at the start of a line. This consumes the directive, modifies the +/// at the start of a line. This consumes the directive, modifies the /// lexer/preprocessor state, and advances the lexer(s) so that the next token /// read is the correct one. void Preprocessor::HandleDirective(Token &Result) { // FIXME: Traditional: # with whitespace before it not recognized by K&R? - + // We just parsed a # character at the start of a line, so we're in directive // mode. Tell the lexer this so any newlines we see will be converted into an // EOM token (which terminates the directive). CurPPLexer->ParsingPreprocessorDirective = true; - + ++NumDirectives; - + // We are about to read a token. For the multiple-include optimization FA to - // work, we have to remember if we had read any tokens *before* this + // work, we have to remember if we had read any tokens *before* this // pp-directive. bool ReadAnyTokensBeforeDirective = CurPPLexer->MIOpt.getHasReadAnyTokensVal(); - + // Save the '#' token in case we need to return it later. Token SavedHash = Result; - + // Read the next token, the directive flavor. This isn't expanded due to // C99 6.10.3p8. LexUnexpandedToken(Result); - + // C99 6.10.3p11: Is this preprocessor directive in macro invocation? e.g.: // #define A(x) #x // A(abc @@ -501,7 +501,7 @@ void Preprocessor::HandleDirective(Token &Result) { // If so, the user is relying on non-portable behavior, emit a diagnostic. if (InMacroArgs) Diag(Result, diag::ext_embedded_directive); - + TryAgain: switch (Result.getKind()) { case tok::eom: @@ -518,7 +518,7 @@ TryAgain: default: IdentifierInfo *II = Result.getIdentifierInfo(); if (II == 0) break; // Not an identifier. - + // Ask what the preprocessor keyword ID is. switch (II->getPPKeywordID()) { default: break; @@ -535,13 +535,13 @@ TryAgain: return HandleElseDirective(Result); case tok::pp_endif: return HandleEndifDirective(Result); - + // C99 6.10.2 - Source File Inclusion. case tok::pp_include: return HandleIncludeDirective(Result); // Handle #include. case tok::pp___include_macros: return HandleIncludeMacrosDirective(Result); // Handle -imacros. - + // C99 6.10.3 - Macro Replacement. case tok::pp_define: return HandleDefineDirective(Result); @@ -551,21 +551,21 @@ TryAgain: // C99 6.10.4 - Line Control. case tok::pp_line: return HandleLineDirective(Result); - + // C99 6.10.5 - Error Directive. case tok::pp_error: return HandleUserDiagnosticDirective(Result, false); - + // C99 6.10.6 - Pragma Directive. case tok::pp_pragma: return HandlePragmaDirective(); - + // GNU Extensions. case tok::pp_import: return HandleImportDirective(Result); case tok::pp_include_next: return HandleIncludeNextDirective(Result); - + case tok::pp_warning: Diag(Result, diag::ext_pp_warning_directive); return HandleUserDiagnosticDirective(Result, true); @@ -582,15 +582,15 @@ TryAgain: } break; } - + // If this is a .S file, treat unknown # directives as non-preprocessor // directives. This is important because # may be a comment or introduce // various pseudo-ops. Just return the # token and push back the following // token to be lexed next time. if (getLangOptions().AsmPreprocessor) { - Token *Toks = new Token[2](); + Token *Toks = new Token[2]; // Return the # and the token after it. - Toks[0] = SavedHash; + Toks[0] = SavedHash; Toks[1] = Result; // Enter this token stream so that we re-lex the tokens. Make sure to // enable macro expansion, in case the token after the # is an identifier @@ -598,13 +598,13 @@ TryAgain: EnterTokenStream(Toks, 2, false, true); return; } - + // If we reached here, the preprocessing token is not valid! Diag(Result, diag::err_pp_invalid_directive); - + // Read the rest of the PP line. DiscardUntilEndOfDirective(); - + // Okay, we're done parsing the directive. } @@ -614,17 +614,17 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val, unsigned DiagID, Preprocessor &PP) { if (DigitTok.isNot(tok::numeric_constant)) { PP.Diag(DigitTok, DiagID); - + if (DigitTok.isNot(tok::eom)) PP.DiscardUntilEndOfDirective(); return true; } - + llvm::SmallString<64> IntegerBuffer; IntegerBuffer.resize(DigitTok.getLength()); const char *DigitTokBegin = &IntegerBuffer[0]; unsigned ActualLength = PP.getSpelling(DigitTok, DigitTokBegin); - + // Verify that we have a simple digit-sequence, and compute the value. This // is always a simple digit string computed in decimal, so we do this manually // here. @@ -636,7 +636,7 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val, PP.DiscardUntilEndOfDirective(); return true; } - + unsigned NextVal = Val*10+(DigitTokBegin[i]-'0'); if (NextVal < Val) { // overflow. PP.Diag(DigitTok, DiagID); @@ -645,21 +645,21 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val, } Val = NextVal; } - - // Reject 0, this is needed both by #line numbers and flags. + + // Reject 0, this is needed both by #line numbers and flags. if (Val == 0) { PP.Diag(DigitTok, DiagID); PP.DiscardUntilEndOfDirective(); return true; } - + if (DigitTokBegin[0] == '0') PP.Diag(DigitTok.getLocation(), diag::warn_pp_line_decimal); - + return false; } -/// HandleLineDirective - Handle #line directive: C99 6.10.4. The two +/// HandleLineDirective - Handle #line directive: C99 6.10.4. The two /// acceptable forms are: /// # line digit-sequence /// # line digit-sequence "s-char-sequence" @@ -679,14 +679,14 @@ void Preprocessor::HandleLineDirective(Token &Tok) { unsigned LineLimit = Features.C99 ? 2147483648U : 32768U; if (LineNo >= LineLimit) Diag(DigitTok, diag::ext_pp_line_too_big) << LineLimit; - + int FilenameID = -1; Token StrTok; Lex(StrTok); // If the StrTok is "eom", then it wasn't present. Otherwise, it must be a // string followed by eom. - if (StrTok.is(tok::eom)) + if (StrTok.is(tok::eom)) ; // ok else if (StrTok.isNot(tok::string_literal)) { Diag(StrTok, diag::err_pp_line_invalid_filename); @@ -704,14 +704,14 @@ void Preprocessor::HandleLineDirective(Token &Tok) { } FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString(), Literal.GetStringLength()); - + // Verify that there is nothing after the string, other than EOM. Because // of C99 6.10.4p5, macros that expand to empty tokens are ok. CheckEndOfDirective("line", true); } - + SourceMgr.AddLineNote(DigitTok.getLocation(), LineNo, FilenameID); - + if (Callbacks) Callbacks->FileChanged(DigitTok.getLocation(), PPCallbacks::RenameFile, SrcMgr::C_User); @@ -731,21 +731,21 @@ static bool ReadLineMarkerFlags(bool &IsFileEntry, bool &IsFileExit, if (FlagVal == 1) { IsFileEntry = true; - + PP.Lex(FlagTok); if (FlagTok.is(tok::eom)) return false; if (GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag,PP)) return true; } else if (FlagVal == 2) { IsFileExit = true; - + SourceManager &SM = PP.getSourceManager(); // If we are leaving the current presumed file, check to make sure the // presumed include stack isn't empty! FileID CurFileID = SM.getDecomposedInstantiationLoc(FlagTok.getLocation()).first; PresumedLoc PLoc = SM.getPresumedLoc(FlagTok.getLocation()); - + // If there is no include loc (main file) or if the include loc is in a // different physical file, then we aren't in a "1" line marker flag region. SourceLocation IncLoc = PLoc.getIncludeLoc(); @@ -755,7 +755,7 @@ static bool ReadLineMarkerFlags(bool &IsFileEntry, bool &IsFileExit, PP.DiscardUntilEndOfDirective(); return true; } - + PP.Lex(FlagTok); if (FlagTok.is(tok::eom)) return false; if (GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag,PP)) @@ -768,9 +768,9 @@ static bool ReadLineMarkerFlags(bool &IsFileEntry, bool &IsFileExit, PP.DiscardUntilEndOfDirective(); return true; } - + IsSystemHeader = true; - + PP.Lex(FlagTok); if (FlagTok.is(tok::eom)) return false; if (GetLineValue(FlagTok, FlagVal, diag::err_pp_linemarker_invalid_flag, PP)) @@ -782,9 +782,9 @@ static bool ReadLineMarkerFlags(bool &IsFileEntry, bool &IsFileExit, PP.DiscardUntilEndOfDirective(); return true; } - + IsExternCHeader = true; - + PP.Lex(FlagTok); if (FlagTok.is(tok::eom)) return false; @@ -798,7 +798,7 @@ static bool ReadLineMarkerFlags(bool &IsFileEntry, bool &IsFileExit, /// one of the following forms: /// /// # 42 -/// # 42 "file" ('1' | '2')? +/// # 42 "file" ('1' | '2')? /// # 42 "file" ('1' | '2')? '3' '4'? /// void Preprocessor::HandleDigitDirective(Token &DigitTok) { @@ -808,17 +808,17 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) { if (GetLineValue(DigitTok, LineNo, diag::err_pp_linemarker_requires_integer, *this)) return; - + Token StrTok; Lex(StrTok); - + bool IsFileEntry = false, IsFileExit = false; bool IsSystemHeader = false, IsExternCHeader = false; int FilenameID = -1; // If the StrTok is "eom", then it wasn't present. Otherwise, it must be a // string followed by eom. - if (StrTok.is(tok::eom)) + if (StrTok.is(tok::eom)) ; // ok else if (StrTok.isNot(tok::string_literal)) { Diag(StrTok, diag::err_pp_linemarker_invalid_filename); @@ -835,18 +835,18 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) { } FilenameID = SourceMgr.getLineTableFilenameID(Literal.GetString(), Literal.GetStringLength()); - + // If a filename was present, read any flags that are present. - if (ReadLineMarkerFlags(IsFileEntry, IsFileExit, + if (ReadLineMarkerFlags(IsFileEntry, IsFileExit, IsSystemHeader, IsExternCHeader, *this)) return; } - + // Create a line note with this information. SourceMgr.AddLineNote(DigitTok.getLocation(), LineNo, FilenameID, - IsFileEntry, IsFileExit, + IsFileEntry, IsFileExit, IsSystemHeader, IsExternCHeader); - + // If the preprocessor has callbacks installed, notify them of the #line // change. This is used so that the line marker comes out in -E mode for // example. @@ -861,7 +861,7 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) { FileKind = SrcMgr::C_ExternCSystem; else if (IsSystemHeader) FileKind = SrcMgr::C_System; - + Callbacks->FileChanged(DigitTok.getLocation(), Reason, FileKind); } } @@ -869,7 +869,7 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) { /// HandleUserDiagnosticDirective - Handle a #warning or #error directive. /// -void Preprocessor::HandleUserDiagnosticDirective(Token &Tok, +void Preprocessor::HandleUserDiagnosticDirective(Token &Tok, bool isWarning) { // PTH doesn't emit #warning or #error directives. if (CurPTHLexer) @@ -892,11 +892,11 @@ void Preprocessor::HandleUserDiagnosticDirective(Token &Tok, void Preprocessor::HandleIdentSCCSDirective(Token &Tok) { // Yes, this directive is an extension. Diag(Tok, diag::ext_pp_ident_directive); - + // Read the string argument. Token StrTok; Lex(StrTok); - + // If the token kind isn't a string, it's a malformed directive. if (StrTok.isNot(tok::string_literal) && StrTok.isNot(tok::wide_string_literal)) { @@ -905,7 +905,7 @@ void Preprocessor::HandleIdentSCCSDirective(Token &Tok) { DiscardUntilEndOfDirective(); return; } - + // Verify that there is nothing after the string, other than EOM. CheckEndOfDirective("ident"); @@ -928,7 +928,7 @@ bool Preprocessor::GetIncludeFilenameSpelling(SourceLocation Loc, const char *&BufEnd) { // Get the text form of the filename. assert(BufStart != BufEnd && "Can't have tokens with empty spellings!"); - + // Make sure the filename is <x> or "x". bool isAngled; if (BufStart[0] == '<') { @@ -950,14 +950,14 @@ bool Preprocessor::GetIncludeFilenameSpelling(SourceLocation Loc, BufStart = 0; return true; } - + // Diagnose #include "" as invalid. if (BufEnd-BufStart <= 2) { Diag(Loc, diag::err_pp_empty_filename); BufStart = 0; return ""; } - + // Skip the brackets. ++BufStart; --BufEnd; @@ -977,33 +977,33 @@ bool Preprocessor::GetIncludeFilenameSpelling(SourceLocation Loc, static bool ConcatenateIncludeName(llvm::SmallVector<char, 128> &FilenameBuffer, Preprocessor &PP) { Token CurTok; - + PP.Lex(CurTok); while (CurTok.isNot(tok::eom)) { // Append the spelling of this token to the buffer. If there was a space // before it, add it now. if (CurTok.hasLeadingSpace()) FilenameBuffer.push_back(' '); - + // Get the spelling of the token, directly into FilenameBuffer if possible. unsigned PreAppendSize = FilenameBuffer.size(); FilenameBuffer.resize(PreAppendSize+CurTok.getLength()); - + const char *BufPtr = &FilenameBuffer[PreAppendSize]; unsigned ActualLen = PP.getSpelling(CurTok, BufPtr); - + // If the token was spelled somewhere else, copy it into FilenameBuffer. if (BufPtr != &FilenameBuffer[PreAppendSize]) memcpy(&FilenameBuffer[PreAppendSize], BufPtr, ActualLen); - + // Resize FilenameBuffer to the correct size. if (CurTok.getLength() != ActualLen) FilenameBuffer.resize(PreAppendSize+ActualLen); - + // If we found the '>' marker, return success. if (CurTok.is(tok::greater)) return false; - + PP.Lex(CurTok); } @@ -1017,14 +1017,14 @@ static bool ConcatenateIncludeName(llvm::SmallVector<char, 128> &FilenameBuffer, /// file to be included from the lexer, then include it! This is a common /// routine with functionality shared between #include, #include_next and /// #import. LookupFrom is set when this is a #include_next directive, it -/// specifies the file to start searching from. +/// specifies the file to start searching from. void Preprocessor::HandleIncludeDirective(Token &IncludeTok, const DirectoryLookup *LookupFrom, bool isImport) { Token FilenameTok; CurPPLexer->LexIncludeFilename(FilenameTok); - + // Reserve a buffer to get the spelling. llvm::SmallVector<char, 128> FilenameBuffer; const char *FilenameStart, *FilenameEnd; @@ -1033,7 +1033,7 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, case tok::eom: // If the token kind is EOM, the error has already been diagnosed. return; - + case tok::angle_string_literal: case tok::string_literal: { FilenameBuffer.resize(FilenameTok.getLength()); @@ -1042,7 +1042,7 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, FilenameEnd = FilenameStart+Len; break; } - + case tok::less: // This could be a <foo/bar.h> file coming from a macro expansion. In this // case, glue the tokens together into FilenameBuffer and interpret those. @@ -1057,7 +1057,7 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, DiscardUntilEndOfDirective(); return; } - + bool isAngled = GetIncludeFilenameSpelling(FilenameTok.getLocation(), FilenameStart, FilenameEnd); // If GetIncludeFilenameSpelling set the start ptr to null, there was an @@ -1066,7 +1066,7 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, DiscardUntilEndOfDirective(); return; } - + // Verify that there is nothing after the filename, other than EOM. Note that // we allow macros that expand to nothing after the filename, because this // falls into the category of "#include pp-tokens new-line" specified in @@ -1078,7 +1078,7 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, Diag(FilenameTok, diag::err_pp_include_too_deep); return; } - + // Search include directories. const DirectoryLookup *CurDir; const FileEntry *File = LookupFile(FilenameStart, FilenameEnd, @@ -1088,19 +1088,19 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, << std::string(FilenameStart, FilenameEnd); return; } - + // Ask HeaderInfo if we should enter this #include file. If not, #including // this file will have no effect. if (!HeaderInfo.ShouldEnterIncludeFile(File, isImport)) return; - + // The #included file will be considered to be a system header if either it is // in a system include directory, or if the #includer is a system include // header. - SrcMgr::CharacteristicKind FileCharacter = + SrcMgr::CharacteristicKind FileCharacter = std::max(HeaderInfo.getFileDirFlavor(File), SourceMgr.getFileCharacteristic(FilenameTok.getLocation())); - + // Look up the file, create a File ID for it. FileID FID = SourceMgr.createFileID(File, FilenameTok.getLocation(), FileCharacter); @@ -1118,7 +1118,7 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, /// void Preprocessor::HandleIncludeNextDirective(Token &IncludeNextTok) { Diag(IncludeNextTok, diag::ext_pp_include_next_directive); - + // #include_next is like #include, except that we start searching after // the current found directory. If we can't do this, issue a // diagnostic. @@ -1132,7 +1132,7 @@ void Preprocessor::HandleIncludeNextDirective(Token &IncludeNextTok) { // Start looking up in the next directory. ++Lookup; } - + return HandleIncludeDirective(IncludeNextTok, Lookup); } @@ -1141,7 +1141,7 @@ void Preprocessor::HandleIncludeNextDirective(Token &IncludeNextTok) { void Preprocessor::HandleImportDirective(Token &ImportTok) { if (!Features.ObjC1) // #import is standard for ObjC. Diag(ImportTok, diag::ext_pp_import_directive); - + return HandleIncludeDirective(ImportTok, 0, true); } @@ -1159,11 +1159,11 @@ void Preprocessor::HandleIncludeMacrosDirective(Token &IncludeMacrosTok) { DiscardUntilEndOfDirective(); return; } - + // Treat this as a normal #include for checking purposes. If this is // successful, it will push a new lexer onto the include stack. HandleIncludeDirective(IncludeMacrosTok, 0, false); - + Token TmpTok; do { Lex(TmpTok); @@ -1181,7 +1181,7 @@ void Preprocessor::HandleIncludeMacrosDirective(Token &IncludeMacrosTok) { /// parsing the arg list. bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI) { llvm::SmallVector<IdentifierInfo*, 32> Arguments; - + Token Tok; while (1) { LexUnexpandedToken(Tok); @@ -1223,18 +1223,18 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI) { // If this is already used as an argument, it is used multiple times (e.g. // #define X(A,A. - if (std::find(Arguments.begin(), Arguments.end(), II) != + if (std::find(Arguments.begin(), Arguments.end(), II) != Arguments.end()) { // C99 6.10.3p6 Diag(Tok, diag::err_pp_duplicate_name_in_arg_list) << II; return true; } - + // Add the argument to the macro info. Arguments.push_back(II); - + // Lex the token after the identifier. LexUnexpandedToken(Tok); - + switch (Tok.getKind()) { default: // #define X(A B Diag(Tok, diag::err_pp_expected_comma_in_arg_list); @@ -1247,14 +1247,14 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI) { case tok::ellipsis: // #define X(A... -> GCC extension // Diagnose extension. Diag(Tok, diag::ext_named_variadic_macro); - + // Lex the token after the identifier. LexUnexpandedToken(Tok); if (Tok.isNot(tok::r_paren)) { Diag(Tok, diag::err_pp_missing_rparen_in_macro_def); return true; } - + MI->setIsGNUVarargs(); MI->setArgumentList(&Arguments[0], Arguments.size(), BP); return false; @@ -1270,7 +1270,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { Token MacroNameTok; ReadMacroName(MacroNameTok, 1); - + // Error reading macro name? If so, diagnostic already issued. if (MacroNameTok.is(tok::eom)) return; @@ -1280,13 +1280,13 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { // If we are supposed to keep comments in #defines, reenable comment saving // mode. if (CurLexer) CurLexer->SetCommentRetentionState(KeepMacroComments); - + // Create the new macro. MacroInfo *MI = AllocateMacroInfo(MacroNameTok.getLocation()); - + Token Tok; LexUnexpandedToken(Tok); - + // If this is a function-like macro definition, parse the argument list, // marking each of the identifiers as being used as macro arguments. Also, // check other constraints on the first token of the macro body. @@ -1310,13 +1310,13 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { // If this is a definition of a variadic C99 function-like macro, not using // the GNU named varargs extension, enabled __VA_ARGS__. - + // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro. // This gets unpoisoned where it is allowed. assert(Ident__VA_ARGS__->isPoisoned() && "__VA_ARGS__ should be poisoned!"); if (MI->isC99Varargs()) Ident__VA_ARGS__->setIsPoisoned(false); - + // Read the first token after the arg list for down below. LexUnexpandedToken(Tok); } else if (Features.C99) { @@ -1357,7 +1357,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { // Get the next token of the macro. LexUnexpandedToken(Tok); } - + } else { // Otherwise, read the body of a function-like macro. While we are at it, // check C99 6.10.3.2p1: ensure that # operators are followed by macro @@ -1367,15 +1367,15 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { if (Tok.isNot(tok::hash)) { MI->AddTokenToBody(Tok); - + // Get the next token of the macro. LexUnexpandedToken(Tok); continue; } - + // Get the next token of the macro. LexUnexpandedToken(Tok); - + // Check for a valid macro arg identifier. if (Tok.getIdentifierInfo() == 0 || MI->getArgumentNum(Tok.getIdentifierInfo()) == -1) { @@ -1389,24 +1389,24 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { } else { Diag(Tok, diag::err_pp_stringize_not_parameter); ReleaseMacroInfo(MI); - + // Disable __VA_ARGS__ again. Ident__VA_ARGS__->setIsPoisoned(true); return; } } - + // Things look ok, add the '#' and param name tokens to the macro. MI->AddTokenToBody(LastTok); MI->AddTokenToBody(Tok); LastTok = Tok; - + // Get the next token of the macro. LexUnexpandedToken(Tok); } } - - + + // Disable __VA_ARGS__ again. Ident__VA_ARGS__->setIsPoisoned(true); @@ -1425,14 +1425,14 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { return; } } - + // If this is the primary source file, remember that this macro hasn't been // used yet. if (isInPrimaryFile()) MI->setIsUsed(false); MI->setDefinitionEndLoc(LastTok.getLocation()); - + // Finally, if this identifier already had a macro defined for it, verify that // the macro bodies are identical and free the old definition. if (MacroInfo *OtherMI = getMacroInfo(MacroNameTok.getIdentifierInfo())) { @@ -1452,12 +1452,12 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) { Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition); } } - + ReleaseMacroInfo(OtherMI); } - + setMacroInfo(MacroNameTok.getIdentifierInfo(), MI); - + // If the callbacks want to know, tell them about the macro definition. if (Callbacks) Callbacks->MacroDefined(MacroNameTok.getIdentifierInfo(), MI); @@ -1470,17 +1470,17 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) { Token MacroNameTok; ReadMacroName(MacroNameTok, 2); - + // Error reading macro name? If so, diagnostic already issued. if (MacroNameTok.is(tok::eom)) return; - + // Check to see if this is the last token on the #undef line. CheckEndOfDirective("undef"); - + // Okay, we finally have a valid identifier to undef. MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo()); - + // If the macro is not defined, this is a noop undef, just return. if (MI == 0) return; @@ -1513,7 +1513,7 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef, Token MacroNameTok; ReadMacroName(MacroNameTok); - + // Error reading macro name? If so, diagnostic already issued. if (MacroNameTok.is(tok::eom)) { // Skip code until we get to #endif. This helps with recovery by not @@ -1522,7 +1522,7 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef, /*Foundnonskip*/false, /*FoundElse*/false); return; } - + // Check to see if this is the last token on the #if[n]def line. CheckEndOfDirective(isIfndef ? "ifndef" : "ifdef"); @@ -1541,7 +1541,7 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef, // If there is a macro, process it. if (MI) // Mark it used. MI->setIsUsed(true); - + // Should we include the stuff contained by this directive? if (!MI == isIfndef) { // Yes, remember that we are inside a conditional, then lex the next token. @@ -1550,7 +1550,7 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef, } else { // No, skip the contents of this block and return the first token after it. SkipExcludedConditionalBlock(DirectiveTok.getLocation(), - /*Foundnonskip*/false, + /*Foundnonskip*/false, /*FoundElse*/false); } } @@ -1560,11 +1560,11 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef, void Preprocessor::HandleIfDirective(Token &IfToken, bool ReadAnyTokensBeforeDirective) { ++NumIf; - + // Parse and evaluation the conditional expression. IdentifierInfo *IfNDefMacro = 0; bool ConditionalTrue = EvaluateDirectiveExpression(IfNDefMacro); - + // If this condition is equivalent to #ifndef X, and if this is the first // directive seen, handle it for the multiple-include optimization. @@ -1582,7 +1582,7 @@ void Preprocessor::HandleIfDirective(Token &IfToken, /*foundnonskip*/true, /*foundelse*/false); } else { // No, skip the contents of this block and return the first token after it. - SkipExcludedConditionalBlock(IfToken.getLocation(), /*Foundnonskip*/false, + SkipExcludedConditionalBlock(IfToken.getLocation(), /*Foundnonskip*/false, /*FoundElse*/false); } } @@ -1591,21 +1591,21 @@ void Preprocessor::HandleIfDirective(Token &IfToken, /// void Preprocessor::HandleEndifDirective(Token &EndifToken) { ++NumEndif; - + // Check that this is the whole directive. CheckEndOfDirective("endif"); - + PPConditionalInfo CondInfo; if (CurPPLexer->popConditionalLevel(CondInfo)) { // No conditionals on the stack: this is an #endif without an #if. Diag(EndifToken, diag::err_pp_endif_without_if); return; } - + // If this the end of a top-level #endif, inform MIOpt. if (CurPPLexer->getConditionalStackDepth() == 0) CurPPLexer->MIOpt.ExitTopLevelConditional(); - + assert(!CondInfo.WasSkipping && !CurPPLexer->LexingRawMode && "This code should only be reachable in the non-skipping case!"); } @@ -1613,23 +1613,23 @@ void Preprocessor::HandleEndifDirective(Token &EndifToken) { void Preprocessor::HandleElseDirective(Token &Result) { ++NumElse; - + // #else directive in a non-skipping conditional... start skipping. CheckEndOfDirective("else"); - + PPConditionalInfo CI; if (CurPPLexer->popConditionalLevel(CI)) { Diag(Result, diag::pp_err_else_without_if); return; } - + // If this is a top-level #else, inform the MIOpt. if (CurPPLexer->getConditionalStackDepth() == 0) CurPPLexer->MIOpt.EnterTopLevelConditional(); // If this is a #else with a #else before it, report the error. if (CI.FoundElse) Diag(Result, diag::pp_err_else_after_else); - + // Finally, skip the rest of the contents of this block and return the first // token after it. return SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true, @@ -1638,7 +1638,7 @@ void Preprocessor::HandleElseDirective(Token &Result) { void Preprocessor::HandleElifDirective(Token &ElifToken) { ++NumElse; - + // #elif directive in a non-skipping conditional... start skipping. // We don't care what the condition is, because we will always skip it (since // the block immediately before it was included). @@ -1649,11 +1649,11 @@ void Preprocessor::HandleElifDirective(Token &ElifToken) { Diag(ElifToken, diag::pp_err_elif_without_if); return; } - + // If this is a top-level #elif, inform the MIOpt. if (CurPPLexer->getConditionalStackDepth() == 0) CurPPLexer->MIOpt.EnterTopLevelConditional(); - + // If this is a #elif with a #else before it, report the error. if (CI.FoundElse) Diag(ElifToken, diag::pp_err_elif_after_else); |