Can you add a new test testing for what regressed?<div><br><div class="gmail_quote">On Wed, Sep 26, 2012 at 9:21 AM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Reverted in r164672. The test you added surprisingly passes even with<br>
the code changes reverted, so I kept the test around.<br>
<br>
Nico<br>
<br>
On Wed, Sep 26, 2012 at 4:56 PM, Nico Weber <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>> wrote:<br>
> In case anyone was wondering, here's the actual diff to PPMacroExpansion.cpp:<br>
><br>
> Nicos-MacBook-Pro:clang thakis$ diff -u ~/triton-before.txt ~/triton-after.txt<br>
> --- /Users/thakis/triton-before.txt 2012-09-26 16:54:53.000000000 +0900<br>
> +++ /Users/thakis/triton-after.txt 2012-09-26 16:55:04.000000000 +0900<br>
> @@ -403,7 +403,11 @@<br>
> }<br>
> } else if (Tok.is(tok::l_paren)) {<br>
> ++NumParens;<br>
> - } else if (Tok.is(tok::comma) && NumParens == 0) {<br>
> + // In Microsoft-compatibility mode, commas from nested macro expan-<br>
> + // sions should not be considered as argument separators. We test<br>
> + // for this with the IgnoredComma token flag.<br>
> + } else if (Tok.is(tok::comma)<br>
> + && !(Tok.getFlags() & Token::IgnoredComma) && NumParens == 0) {<br>
> // Comma ends this argument if there are more fixed arguments expected.<br>
> // However, if this is a variadic macro, and this is part of the<br>
> // variadic part, then the comma is just an argument token.<br>
> @@ -1171,3 +1175,4 @@<br>
> WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());<br>
> MI->setIsUsed(true);<br>
> }<br>
><br>
><br>
><br>
> This change caused PR13924, I might roll it out.<br>
><br>
> On Wed, Sep 5, 2012 at 2:10 AM, João Matos <<a href="mailto:ripzonetriton@gmail.com">ripzonetriton@gmail.com</a>> wrote:<br>
>> Will do. Yes, the this line endings problem was really annoying. I was not<br>
>> aware VS didn't respect them. I've introduced some measures locally so<br>
>> hopefully this won't happen in the future.<br>
>><br>
>> Regarding your concerns, I didn't benchmark this, but I did had the<br>
>> performance nature of the preprocessor when writing the code, and tried to<br>
>> make minimal changes to not affect it.<br>
>><br>
>><br>
>> On Tue, Sep 4, 2012 at 5:56 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>><br>
>> wrote:<br>
>>><br>
>>> On Fri, Aug 31, 2012 at 5:10 PM, Joao Matos <<a href="mailto:ripzonetriton@gmail.com">ripzonetriton@gmail.com</a>><br>
>>> wrote:<br>
>>>><br>
>>>> Author: triton<br>
>>>> Date: Fri Aug 31 16:10:54 2012<br>
>>>> New Revision: 163022<br>
>>>><br>
>>>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=163022&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=163022&view=rev</a><br>
>>>> Log:<br>
>>>> Emulate MSVC's preprocessor macro argument separator behavior by not<br>
>>>> considering commas from nested macro expansions as argument separators.<br>
>>>> Fixes parsing of VS 2012 headers.<br>
>>><br>
>>><br>
>>> Arg, no one can review this patch now because the line endings got<br>
>>> thrashed.<br>
>>><br>
>>> In the future, if you have trouble with line endings, *please* revert the<br>
>>> patch first, and then commit a new patch with only the intended edits. That<br>
>>> way our post-commit review can proceed normally.<br>
>>><br>
>>> That said, I have some significant concerns about this patch that didn't<br>
>>> come up in the initial review, and I think might merit reverting the patch<br>
>>> temporarily until we understand them.<br>
>>><br>
>>> What is the performance impact of this patch? The performance of the<br>
>>> preprocessor is *incredibly* sensitive. Have you benchmarked the patch in<br>
>>> microsoft mode and non-microsoft mode, before and after, with some of the<br>
>>> heavy users of preprocess macros? The single-source GCC version, or some of<br>
>>> the Boost preprocessor libraries might make excellent benchmarks.<br>
>>><br>
>>> Also, more test cases would seem to be in order. How does this interact<br>
>>> with token pasting? How does it interact with variadic macros which also<br>
>>> have strange comma behavior?<br>
>>><br>
>>>><br>
>>>><br>
>>>> Added:<br>
>>>> cfe/trunk/test/Preprocessor/microsoft-ext.c<br>
>>>> Modified:<br>
>>>> cfe/trunk/include/clang/Lex/Token.h<br>
>>>> cfe/trunk/lib/Lex/PPMacroExpansion.cpp<br>
>>>> cfe/trunk/lib/Lex/TokenLexer.cpp<br>
>>>><br>
>>>> Modified: cfe/trunk/include/clang/Lex/Token.h<br>
>>>> URL:<br>
>>>> <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Token.h?rev=163022&r1=163021&r2=163022&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Token.h?rev=163022&r1=163021&r2=163022&view=diff</a><br>
>>>><br>
>>>> ==============================================================================<br>
>>>> --- cfe/trunk/include/clang/Lex/Token.h (original)<br>
>>>> +++ cfe/trunk/include/clang/Lex/Token.h Fri Aug 31 16:10:54 2012<br>
>>>> @@ -76,7 +76,8 @@<br>
>>>> DisableExpand = 0x04, // This identifier may never be macro<br>
>>>> expanded.<br>
>>>> NeedsCleaning = 0x08, // Contained an escaped newline or trigraph.<br>
>>>> LeadingEmptyMacro = 0x10, // Empty macro exists before this token.<br>
>>>> - HasUDSuffix = 0x20 // This string or character literal has a<br>
>>>> ud-suffix.<br>
>>>> + HasUDSuffix = 0x20, // This string or character literal has a<br>
>>>> ud-suffix.<br>
>>>> + IgnoredComma = 0x40 // Flags ignored commas from nested macro<br>
>>>> expansions.<br>
>>>> };<br>
>>>><br>
>>>> tok::TokenKind getKind() const { return (tok::TokenKind)Kind; }<br>
>>>><br>
>>>> Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp<br>
>>>> URL:<br>
>>>> <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=163022&r1=163021&r2=163022&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=163022&r1=163021&r2=163022&view=diff</a><br>
>>>><br>
>>>> ==============================================================================<br>
>>>> --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)<br>
>>>> +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Fri Aug 31 16:10:54 2012<br>
>>>> @@ -1,1173 +1,1177 @@<br>
>>>> -//===--- MacroExpansion.cpp - Top level Macro Expansion<br>
>>>> -------------------===//<br>
>>>> -//<br>
>>>> -// The LLVM Compiler Infrastructure<br>
>>>> -//<br>
>>>> -// This file is distributed under the University of Illinois Open Source<br>
>>>> -// License. See LICENSE.TXT for details.<br>
>>>> -//<br>
>>>><br>
>>>> -//===----------------------------------------------------------------------===//<br>
>>>> -//<br>
>>>> -// This file implements the top level handling of macro expasion for the<br>
>>>> -// preprocessor.<br>
>>>> -//<br>
>>>><br>
>>>> -//===----------------------------------------------------------------------===//<br>
>>>> -<br>
>>>> -#include "clang/Lex/Preprocessor.h"<br>
>>>> -#include "MacroArgs.h"<br>
>>>> -#include "clang/Lex/MacroInfo.h"<br>
>>>> -#include "clang/Basic/SourceManager.h"<br>
>>>> -#include "clang/Basic/FileManager.h"<br>
>>>> -#include "clang/Basic/TargetInfo.h"<br>
>>>> -#include "clang/Lex/LexDiagnostic.h"<br>
>>>> -#include "clang/Lex/CodeCompletionHandler.h"<br>
>>>> -#include "clang/Lex/ExternalPreprocessorSource.h"<br>
>>>> -#include "clang/Lex/LiteralSupport.h"<br>
>>>> -#include "llvm/ADT/StringSwitch.h"<br>
>>>> -#include "llvm/ADT/STLExtras.h"<br>
>>>> -#include "llvm/Config/llvm-config.h"<br>
>>>> -#include "llvm/Support/raw_ostream.h"<br>
>>>> -#include "llvm/Support/ErrorHandling.h"<br>
>>>> -#include <cstdio><br>
>>>> -#include <ctime><br>
>>>> -using namespace clang;<br>
>>>> -<br>
>>>> -MacroInfo *Preprocessor::getInfoForMacro(IdentifierInfo *II) const {<br>
>>>> - assert(II->hasMacroDefinition() && "Identifier is not a macro!");<br>
>>>> -<br>
>>>> - macro_iterator Pos = Macros.find(II);<br>
>>>> - if (Pos == Macros.end()) {<br>
>>>> - // Load this macro from the external source.<br>
>>>> - getExternalSource()->LoadMacroDefinition(II);<br>
>>>> - Pos = Macros.find(II);<br>
>>>> - }<br>
>>>> - assert(Pos != Macros.end() && "Identifier macro info is missing!");<br>
>>>> - assert(Pos->second->getUndefLoc().isInvalid() && "Macro is<br>
>>>> undefined!");<br>
>>>> - return Pos->second;<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// setMacroInfo - Specify a macro for this identifier.<br>
>>>> -///<br>
>>>> -void Preprocessor::setMacroInfo(IdentifierInfo *II, MacroInfo *MI,<br>
>>>> - bool LoadedFromAST) {<br>
>>>> - assert(MI && "MacroInfo should be non-zero!");<br>
>>>> - MI->setPreviousDefinition(Macros[II]);<br>
>>>> - Macros[II] = MI;<br>
>>>> - II->setHasMacroDefinition(true);<br>
>>>> - if (II->isFromAST() && !LoadedFromAST)<br>
>>>> - II->setChangedSinceDeserialization();<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// \brief Undefine a macro for this identifier.<br>
>>>> -void Preprocessor::clearMacroInfo(IdentifierInfo *II) {<br>
>>>> - assert(II->hasMacroDefinition() && "Macro is not defined!");<br>
>>>> - assert(Macros[II]->getUndefLoc().isValid() && "Macro is still<br>
>>>> defined!");<br>
>>>> - II->setHasMacroDefinition(false);<br>
>>>> - if (II->isFromAST())<br>
>>>> - II->setChangedSinceDeserialization();<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// RegisterBuiltinMacro - Register the specified identifier in the<br>
>>>> identifier<br>
>>>> -/// table and mark it as a builtin macro to be expanded.<br>
>>>> -static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char<br>
>>>> *Name){<br>
>>>> - // Get the identifier.<br>
>>>> - IdentifierInfo *Id = PP.getIdentifierInfo(Name);<br>
>>>> -<br>
>>>> - // Mark it as being a macro that is builtin.<br>
>>>> - MacroInfo *MI = PP.AllocateMacroInfo(SourceLocation());<br>
>>>> - MI->setIsBuiltinMacro();<br>
>>>> - PP.setMacroInfo(Id, MI);<br>
>>>> - return Id;<br>
>>>> -}<br>
>>>> -<br>
>>>> -<br>
>>>> -/// RegisterBuiltinMacros - Register builtin macros, such as __LINE__<br>
>>>> with the<br>
>>>> -/// identifier table.<br>
>>>> -void Preprocessor::RegisterBuiltinMacros() {<br>
>>>> - Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");<br>
>>>> - Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");<br>
>>>> - Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");<br>
>>>> - Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");<br>
>>>> - Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");<br>
>>>> - Ident_Pragma = RegisterBuiltinMacro(*this, "_Pragma");<br>
>>>> -<br>
>>>> - // GCC Extensions.<br>
>>>> - Ident__BASE_FILE__ = RegisterBuiltinMacro(*this, "__BASE_FILE__");<br>
>>>> - Ident__INCLUDE_LEVEL__ = RegisterBuiltinMacro(*this,<br>
>>>> "__INCLUDE_LEVEL__");<br>
>>>> - Ident__TIMESTAMP__ = RegisterBuiltinMacro(*this, "__TIMESTAMP__");<br>
>>>> -<br>
>>>> - // Clang Extensions.<br>
>>>> - Ident__has_feature = RegisterBuiltinMacro(*this,<br>
>>>> "__has_feature");<br>
>>>> - Ident__has_extension = RegisterBuiltinMacro(*this,<br>
>>>> "__has_extension");<br>
>>>> - Ident__has_builtin = RegisterBuiltinMacro(*this,<br>
>>>> "__has_builtin");<br>
>>>> - Ident__has_attribute = RegisterBuiltinMacro(*this,<br>
>>>> "__has_attribute");<br>
>>>> - Ident__has_include = RegisterBuiltinMacro(*this,<br>
>>>> "__has_include");<br>
>>>> - Ident__has_include_next = RegisterBuiltinMacro(*this,<br>
>>>> "__has_include_next");<br>
>>>> - Ident__has_warning = RegisterBuiltinMacro(*this,<br>
>>>> "__has_warning");<br>
>>>> -<br>
>>>> - // Microsoft Extensions.<br>
>>>> - if (LangOpts.MicrosoftExt)<br>
>>>> - Ident__pragma = RegisterBuiltinMacro(*this, "__pragma");<br>
>>>> - else<br>
>>>> - Ident__pragma = 0;<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// isTrivialSingleTokenExpansion - Return true if MI, which has a<br>
>>>> single token<br>
>>>> -/// in its expansion, currently expands to that token literally.<br>
>>>> -static bool isTrivialSingleTokenExpansion(const MacroInfo *MI,<br>
>>>> - const IdentifierInfo<br>
>>>> *MacroIdent,<br>
>>>> - Preprocessor &PP) {<br>
>>>> - IdentifierInfo *II = MI->getReplacementToken(0).getIdentifierInfo();<br>
>>>> -<br>
>>>> - // If the token isn't an identifier, it's always literally expanded.<br>
>>>> - if (II == 0) return true;<br>
>>>> -<br>
>>>> - // If the information about this identifier is out of date, update it<br>
>>>> from<br>
>>>> - // the external source.<br>
>>>> - if (II->isOutOfDate())<br>
>>>> - PP.getExternalSource()->updateOutOfDateIdentifier(*II);<br>
>>>> -<br>
>>>> - // If the identifier is a macro, and if that macro is enabled, it may<br>
>>>> be<br>
>>>> - // expanded so it's not a trivial expansion.<br>
>>>> - if (II->hasMacroDefinition() && PP.getMacroInfo(II)->isEnabled() &&<br>
>>>> - // Fast expanding "#define X X" is ok, because X would be<br>
>>>> disabled.<br>
>>>> - II != MacroIdent)<br>
>>>> - return false;<br>
>>>> -<br>
>>>> - // If this is an object-like macro invocation, it is safe to trivially<br>
>>>> expand<br>
>>>> - // it.<br>
>>>> - if (MI->isObjectLike()) return true;<br>
>>>> -<br>
>>>> - // If this is a function-like macro invocation, it's safe to trivially<br>
>>>> expand<br>
>>>> - // as long as the identifier is not a macro argument.<br>
>>>> - for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end();<br>
>>>> - I != E; ++I)<br>
>>>> - if (*I == II)<br>
>>>> - return false; // Identifier is a macro argument.<br>
>>>> -<br>
>>>> - return true;<br>
>>>> -}<br>
>>>> -<br>
>>>> -<br>
>>>> -/// isNextPPTokenLParen - Determine whether the next preprocessor token<br>
>>>> to be<br>
>>>> -/// lexed is a '('. If so, consume the token and return true, if not,<br>
>>>> this<br>
>>>> -/// method should have no observable side-effect on the lexed tokens.<br>
>>>> -bool Preprocessor::isNextPPTokenLParen() {<br>
>>>> - // Do some quick tests for rejection cases.<br>
>>>> - unsigned Val;<br>
>>>> - if (CurLexer)<br>
>>>> - Val = CurLexer->isNextPPTokenLParen();<br>
>>>> - else if (CurPTHLexer)<br>
>>>> - Val = CurPTHLexer->isNextPPTokenLParen();<br>
>>>> - else<br>
>>>> - Val = CurTokenLexer->isNextTokenLParen();<br>
>>>> -<br>
>>>> - if (Val == 2) {<br>
>>>> - // We have run off the end. If it's a source file we don't<br>
>>>> - // examine enclosing ones (C99 5.1.1.2p4). Otherwise walk up the<br>
>>>> - // macro stack.<br>
>>>> - if (CurPPLexer)<br>
>>>> - return false;<br>
>>>> - for (unsigned i = IncludeMacroStack.size(); i != 0; --i) {<br>
>>>> - IncludeStackInfo &Entry = IncludeMacroStack[i-1];<br>
>>>> - if (Entry.TheLexer)<br>
>>>> - Val = Entry.TheLexer->isNextPPTokenLParen();<br>
>>>> - else if (Entry.ThePTHLexer)<br>
>>>> - Val = Entry.ThePTHLexer->isNextPPTokenLParen();<br>
>>>> - else<br>
>>>> - Val = Entry.TheTokenLexer->isNextTokenLParen();<br>
>>>> -<br>
>>>> - if (Val != 2)<br>
>>>> - break;<br>
>>>> -<br>
>>>> - // Ran off the end of a source file?<br>
>>>> - if (Entry.ThePPLexer)<br>
>>>> - return false;<br>
>>>> - }<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Okay, if we know that the token is a '(', lex it and return.<br>
>>>> Otherwise we<br>
>>>> - // have found something that isn't a '(' or we found the end of the<br>
>>>> - // translation unit. In either case, return false.<br>
>>>> - return Val == 1;<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// HandleMacroExpandedIdentifier - If an identifier token is read that<br>
>>>> is to be<br>
>>>> -/// expanded as a macro, handle it and return the next token as<br>
>>>> 'Identifier'.<br>
>>>> -bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,<br>
>>>> - MacroInfo *MI) {<br>
>>>> - // If this is a macro expansion in the "#if !defined(x)" line for the<br>
>>>> file,<br>
>>>> - // then the macro could expand to different things in other contexts,<br>
>>>> we need<br>
>>>> - // to disable the optimization in this case.<br>
>>>> - if (CurPPLexer) CurPPLexer->MIOpt.ExpandedMacro();<br>
>>>> -<br>
>>>> - // If this is a builtin macro, like __LINE__ or _Pragma, handle it<br>
>>>> specially.<br>
>>>> - if (MI->isBuiltinMacro()) {<br>
>>>> - if (Callbacks) Callbacks->MacroExpands(Identifier, MI,<br>
>>>> - Identifier.getLocation());<br>
>>>> - ExpandBuiltinMacro(Identifier);<br>
>>>> - return false;<br>
>>>> - }<br>
>>>> -<br>
>>>> - /// Args - If this is a function-like macro expansion, this contains,<br>
>>>> - /// for each macro argument, the list of tokens that were provided to<br>
>>>> the<br>
>>>> - /// invocation.<br>
>>>> - MacroArgs *Args = 0;<br>
>>>> -<br>
>>>> - // Remember where the end of the expansion occurred. For an<br>
>>>> object-like<br>
>>>> - // macro, this is the identifier. For a function-like macro, this is<br>
>>>> the ')'.<br>
>>>> - SourceLocation ExpansionEnd = Identifier.getLocation();<br>
>>>> -<br>
>>>> - // If this is a function-like macro, read the arguments.<br>
>>>> - if (MI->isFunctionLike()) {<br>
>>>> - // C99 6.10.3p10: If the preprocessing token immediately after the<br>
>>>> macro<br>
>>>> - // name isn't a '(', this macro should not be expanded.<br>
>>>> - if (!isNextPPTokenLParen())<br>
>>>> - return true;<br>
>>>> -<br>
>>>> - // Remember that we are now parsing the arguments to a macro<br>
>>>> invocation.<br>
>>>> - // Preprocessor directives used inside macro arguments are not<br>
>>>> portable, and<br>
>>>> - // this enables the warning.<br>
>>>> - InMacroArgs = true;<br>
>>>> - Args = ReadFunctionLikeMacroArgs(Identifier, MI, ExpansionEnd);<br>
>>>> -<br>
>>>> - // Finished parsing args.<br>
>>>> - InMacroArgs = false;<br>
>>>> -<br>
>>>> - // If there was an error parsing the arguments, bail out.<br>
>>>> - if (Args == 0) return false;<br>
>>>> -<br>
>>>> - ++NumFnMacroExpanded;<br>
>>>> - } else {<br>
>>>> - ++NumMacroExpanded;<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Notice that this macro has been used.<br>
>>>> - markMacroAsUsed(MI);<br>
>>>> -<br>
>>>> - // Remember where the token is expanded.<br>
>>>> - SourceLocation ExpandLoc = Identifier.getLocation();<br>
>>>> - SourceRange ExpansionRange(ExpandLoc, ExpansionEnd);<br>
>>>> -<br>
>>>> - if (Callbacks) {<br>
>>>> - if (InMacroArgs) {<br>
>>>> - // We can have macro expansion inside a conditional directive<br>
>>>> while<br>
>>>> - // reading the function macro arguments. To ensure, in that case,<br>
>>>> that<br>
>>>> - // MacroExpands callbacks still happen in source order, queue this<br>
>>>> - // callback to have it happen after the function macro callback.<br>
>>>> - DelayedMacroExpandsCallbacks.push_back(<br>
>>>> - MacroExpandsInfo(Identifier, MI,<br>
>>>> ExpansionRange));<br>
>>>> - } else {<br>
>>>> - Callbacks->MacroExpands(Identifier, MI, ExpansionRange);<br>
>>>> - if (!DelayedMacroExpandsCallbacks.empty()) {<br>
>>>> - for (unsigned i=0, e = DelayedMacroExpandsCallbacks.size();<br>
>>>> i!=e; ++i) {<br>
>>>> - MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i];<br>
>>>> - Callbacks->MacroExpands(Info.Tok, Info.MI, Info.Range);<br>
>>>> - }<br>
>>>> - DelayedMacroExpandsCallbacks.clear();<br>
>>>> - }<br>
>>>> - }<br>
>>>> - }<br>
>>>> -<br>
>>>> - // If we started lexing a macro, enter the macro expansion body.<br>
>>>> -<br>
>>>> - // If this macro expands to no tokens, don't bother to push it onto<br>
>>>> the<br>
>>>> - // expansion stack, only to take it right back off.<br>
>>>> - if (MI->getNumTokens() == 0) {<br>
>>>> - // No need for arg info.<br>
>>>> - if (Args) Args->destroy(*this);<br>
>>>> -<br>
>>>> - // Ignore this macro use, just return the next token in the current<br>
>>>> - // buffer.<br>
>>>> - bool HadLeadingSpace = Identifier.hasLeadingSpace();<br>
>>>> - bool IsAtStartOfLine = Identifier.isAtStartOfLine();<br>
>>>> -<br>
>>>> - Lex(Identifier);<br>
>>>> -<br>
>>>> - // If the identifier isn't on some OTHER line, inherit the leading<br>
>>>> - // whitespace/first-on-a-line property of this token. This handles<br>
>>>> - // stuff like "! XX," -> "! ," and " XX," -> " ,", when XX is<br>
>>>> - // empty.<br>
>>>> - if (!Identifier.isAtStartOfLine()) {<br>
>>>> - if (IsAtStartOfLine) Identifier.setFlag(Token::StartOfLine);<br>
>>>> - if (HadLeadingSpace) Identifier.setFlag(Token::LeadingSpace);<br>
>>>> - }<br>
>>>> - Identifier.setFlag(Token::LeadingEmptyMacro);<br>
>>>> - ++NumFastMacroExpanded;<br>
>>>> - return false;<br>
>>>> -<br>
>>>> - } else if (MI->getNumTokens() == 1 &&<br>
>>>> - isTrivialSingleTokenExpansion(MI,<br>
>>>> Identifier.getIdentifierInfo(),<br>
>>>> - *this)) {<br>
>>>> - // Otherwise, if this macro expands into a single trivially-expanded<br>
>>>> - // token: expand it now. This handles common cases like<br>
>>>> - // "#define VAL 42".<br>
>>>> -<br>
>>>> - // No need for arg info.<br>
>>>> - if (Args) Args->destroy(*this);<br>
>>>> -<br>
>>>> - // Propagate the isAtStartOfLine/hasLeadingSpace markers of the<br>
>>>> macro<br>
>>>> - // identifier to the expanded token.<br>
>>>> - bool isAtStartOfLine = Identifier.isAtStartOfLine();<br>
>>>> - bool hasLeadingSpace = Identifier.hasLeadingSpace();<br>
>>>> -<br>
>>>> - // Replace the result token.<br>
>>>> - Identifier = MI->getReplacementToken(0);<br>
>>>> -<br>
>>>> - // Restore the StartOfLine/LeadingSpace markers.<br>
>>>> - Identifier.setFlagValue(Token::StartOfLine , isAtStartOfLine);<br>
>>>> - Identifier.setFlagValue(Token::LeadingSpace, hasLeadingSpace);<br>
>>>> -<br>
>>>> - // Update the tokens location to include both its expansion and<br>
>>>> physical<br>
>>>> - // locations.<br>
>>>> - SourceLocation Loc =<br>
>>>> - SourceMgr.createExpansionLoc(Identifier.getLocation(), ExpandLoc,<br>
>>>> - ExpansionEnd,Identifier.getLength());<br>
>>>> - Identifier.setLocation(Loc);<br>
>>>> -<br>
>>>> - // If this is a disabled macro or #define X X, we must mark the<br>
>>>> result as<br>
>>>> - // unexpandable.<br>
>>>> - if (IdentifierInfo *NewII = Identifier.getIdentifierInfo()) {<br>
>>>> - if (MacroInfo *NewMI = getMacroInfo(NewII))<br>
>>>> - if (!NewMI->isEnabled() || NewMI == MI) {<br>
>>>> - Identifier.setFlag(Token::DisableExpand);<br>
>>>> - Diag(Identifier, diag::pp_disabled_macro_expansion);<br>
>>>> - }<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Since this is not an identifier token, it can't be macro<br>
>>>> expanded, so<br>
>>>> - // we're done.<br>
>>>> - ++NumFastMacroExpanded;<br>
>>>> - return false;<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Start expanding the macro.<br>
>>>> - EnterMacro(Identifier, ExpansionEnd, MI, Args);<br>
>>>> -<br>
>>>> - // Now that the macro is at the top of the include stack, ask the<br>
>>>> - // preprocessor to read the next token from it.<br>
>>>> - Lex(Identifier);<br>
>>>> - return false;<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// ReadFunctionLikeMacroArgs - After reading "MACRO" and knowing that<br>
>>>> the next<br>
>>>> -/// token is the '(' of the macro, this method is invoked to read all of<br>
>>>> the<br>
>>>> -/// actual arguments specified for the macro invocation. This returns<br>
>>>> null on<br>
>>>> -/// error.<br>
>>>> -MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,<br>
>>>> - MacroInfo *MI,<br>
>>>> - SourceLocation<br>
>>>> &MacroEnd) {<br>
>>>> - // The number of fixed arguments to parse.<br>
>>>> - unsigned NumFixedArgsLeft = MI->getNumArgs();<br>
>>>> - bool isVariadic = MI->isVariadic();<br>
>>>> -<br>
>>>> - // Outer loop, while there are more arguments, keep reading them.<br>
>>>> - Token Tok;<br>
>>>> -<br>
>>>> - // Read arguments as unexpanded tokens. This avoids issues, e.g.,<br>
>>>> where<br>
>>>> - // an argument value in a macro could expand to ',' or '(' or ')'.<br>
>>>> - LexUnexpandedToken(Tok);<br>
>>>> - assert(Tok.is(tok::l_paren) && "Error computing l-paren-ness?");<br>
>>>> -<br>
>>>> - // ArgTokens - Build up a list of tokens that make up each argument.<br>
>>>> Each<br>
>>>> - // argument is separated by an EOF token. Use a SmallVector so we can<br>
>>>> avoid<br>
>>>> - // heap allocations in the common case.<br>
>>>> - SmallVector<Token, 64> ArgTokens;<br>
>>>> -<br>
>>>> - unsigned NumActuals = 0;<br>
>>>> - while (Tok.isNot(tok::r_paren)) {<br>
>>>> - assert((Tok.is(tok::l_paren) || Tok.is(tok::comma)) &&<br>
>>>> - "only expect argument separators here");<br>
>>>> -<br>
>>>> - unsigned ArgTokenStart = ArgTokens.size();<br>
>>>> - SourceLocation ArgStartLoc = Tok.getLocation();<br>
>>>> -<br>
>>>> - // C99 6.10.3p11: Keep track of the number of l_parens we have seen.<br>
>>>> Note<br>
>>>> - // that we already consumed the first one.<br>
>>>> - unsigned NumParens = 0;<br>
>>>> -<br>
>>>> - while (1) {<br>
>>>> - // Read arguments as unexpanded tokens. This avoids issues, e.g.,<br>
>>>> where<br>
>>>> - // an argument value in a macro could expand to ',' or '(' or ')'.<br>
>>>> - LexUnexpandedToken(Tok);<br>
>>>> -<br>
>>>> - if (Tok.is(tok::eof) || Tok.is(tok::eod)) { // "#if f(<eof>" &<br>
>>>> "#if f(\n"<br>
>>>> - Diag(MacroName, diag::err_unterm_macro_invoc);<br>
>>>> - // Do not lose the EOF/EOD. Return it to the client.<br>
>>>> - MacroName = Tok;<br>
>>>> - return 0;<br>
>>>> - } else if (Tok.is(tok::r_paren)) {<br>
>>>> - // If we found the ) token, the macro arg list is done.<br>
>>>> - if (NumParens-- == 0) {<br>
>>>> - MacroEnd = Tok.getLocation();<br>
>>>> - break;<br>
>>>> - }<br>
>>>> - } else if (Tok.is(tok::l_paren)) {<br>
>>>> - ++NumParens;<br>
>>>> - } else if (Tok.is(tok::comma) && NumParens == 0) {<br>
>>>> - // Comma ends this argument if there are more fixed arguments<br>
>>>> expected.<br>
>>>> - // However, if this is a variadic macro, and this is part of the<br>
>>>> - // variadic part, then the comma is just an argument token.<br>
>>>> - if (!isVariadic) break;<br>
>>>> - if (NumFixedArgsLeft > 1)<br>
>>>> - break;<br>
>>>> - } else if (Tok.is(tok::comment) && !KeepMacroComments) {<br>
>>>> - // If this is a comment token in the argument list and we're<br>
>>>> just in<br>
>>>> - // -C mode (not -CC mode), discard the comment.<br>
>>>> - continue;<br>
>>>> - } else if (Tok.getIdentifierInfo() != 0) {<br>
>>>> - // Reading macro arguments can cause macros that we are<br>
>>>> currently<br>
>>>> - // expanding from to be popped off the expansion stack. Doing<br>
>>>> so causes<br>
>>>> - // them to be reenabled for expansion. Here we record whether<br>
>>>> any<br>
>>>> - // identifiers we lex as macro arguments correspond to disabled<br>
>>>> macros.<br>
>>>> - // If so, we mark the token as noexpand. This is a subtle<br>
>>>> aspect of<br>
>>>> - // C99 6.10.3.4p2.<br>
>>>> - if (MacroInfo *MI = getMacroInfo(Tok.getIdentifierInfo()))<br>
>>>> - if (!MI->isEnabled())<br>
>>>> - Tok.setFlag(Token::DisableExpand);<br>
>>>> - } else if (Tok.is(tok::code_completion)) {<br>
>>>> - if (CodeComplete)<br>
>>>> -<br>
>>>> CodeComplete->CodeCompleteMacroArgument(MacroName.getIdentifierInfo(),<br>
>>>> - MI, NumActuals);<br>
>>>> - // Don't mark that we reached the code-completion point because<br>
>>>> the<br>
>>>> - // parser is going to handle the token and there will be another<br>
>>>> - // code-completion callback.<br>
>>>> - }<br>
>>>> -<br>
>>>> - ArgTokens.push_back(Tok);<br>
>>>> - }<br>
>>>> -<br>
>>>> - // If this was an empty argument list foo(), don't add this as an<br>
>>>> empty<br>
>>>> - // argument.<br>
>>>> - if (ArgTokens.empty() && Tok.getKind() == tok::r_paren)<br>
>>>> - break;<br>
>>>> -<br>
>>>> - // If this is not a variadic macro, and too many args were<br>
>>>> specified, emit<br>
>>>> - // an error.<br>
>>>> - if (!isVariadic && NumFixedArgsLeft == 0) {<br>
>>>> - if (ArgTokens.size() != ArgTokenStart)<br>
>>>> - ArgStartLoc = ArgTokens[ArgTokenStart].getLocation();<br>
>>>> -<br>
>>>> - // Emit the diagnostic at the macro name in case there is a<br>
>>>> missing ).<br>
>>>> - // Emitting it at the , could be far away from the macro name.<br>
>>>> - Diag(ArgStartLoc, diag::err_too_many_args_in_macro_invoc);<br>
>>>> - return 0;<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Empty arguments are standard in C99 and C++0x, and are supported<br>
>>>> as an extension in<br>
>>>> - // other modes.<br>
>>>> - if (ArgTokens.size() == ArgTokenStart && !LangOpts.C99)<br>
>>>> - Diag(Tok, LangOpts.CPlusPlus0x ?<br>
>>>> - diag::warn_cxx98_compat_empty_fnmacro_arg :<br>
>>>> - diag::ext_empty_fnmacro_arg);<br>
>>>> -<br>
>>>> - // Add a marker EOF token to the end of the token list for this<br>
>>>> argument.<br>
>>>> - Token EOFTok;<br>
>>>> - EOFTok.startToken();<br>
>>>> - EOFTok.setKind(tok::eof);<br>
>>>> - EOFTok.setLocation(Tok.getLocation());<br>
>>>> - EOFTok.setLength(0);<br>
>>>> - ArgTokens.push_back(EOFTok);<br>
>>>> - ++NumActuals;<br>
>>>> - assert(NumFixedArgsLeft != 0 && "Too many arguments parsed");<br>
>>>> - --NumFixedArgsLeft;<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Okay, we either found the r_paren. Check to see if we parsed too<br>
>>>> few<br>
>>>> - // arguments.<br>
>>>> - unsigned MinArgsExpected = MI->getNumArgs();<br>
>>>> -<br>
>>>> - // See MacroArgs instance var for description of this.<br>
>>>> - bool isVarargsElided = false;<br>
>>>> -<br>
>>>> - if (NumActuals < MinArgsExpected) {<br>
>>>> - // There are several cases where too few arguments is ok, handle<br>
>>>> them now.<br>
>>>> - if (NumActuals == 0 && MinArgsExpected == 1) {<br>
>>>> - // #define A(X) or #define A(...) ---> A()<br>
>>>> -<br>
>>>> - // If there is exactly one argument, and that argument is missing,<br>
>>>> - // then we have an empty "()" argument empty list. This is fine,<br>
>>>> even if<br>
>>>> - // the macro expects one argument (the argument is just empty).<br>
>>>> - isVarargsElided = MI->isVariadic();<br>
>>>> - } else if (MI->isVariadic() &&<br>
>>>> - (NumActuals+1 == MinArgsExpected || // A(x, ...) -> A(X)<br>
>>>> - (NumActuals == 0 && MinArgsExpected == 2))) {// A(x,...)<br>
>>>> -> A()<br>
>>>> - // Varargs where the named vararg parameter is missing: OK as<br>
>>>> extension.<br>
>>>> - // #define A(x, ...)<br>
>>>> - // A("blah")<br>
>>>> - Diag(Tok, diag::ext_missing_varargs_arg);<br>
>>>> - Diag(MI->getDefinitionLoc(), diag::note_macro_here)<br>
>>>> - << MacroName.getIdentifierInfo();<br>
>>>> -<br>
>>>> - // Remember this occurred, allowing us to elide the comma when<br>
>>>> used for<br>
>>>> - // cases like:<br>
>>>> - // #define A(x, foo...) blah(a, ## foo)<br>
>>>> - // #define B(x, ...) blah(a, ## __VA_ARGS__)<br>
>>>> - // #define C(...) blah(a, ## __VA_ARGS__)<br>
>>>> - // A(x) B(x) C()<br>
>>>> - isVarargsElided = true;<br>
>>>> - } else {<br>
>>>> - // Otherwise, emit the error.<br>
>>>> - Diag(Tok, diag::err_too_few_args_in_macro_invoc);<br>
>>>> - return 0;<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Add a marker EOF token to the end of the token list for this<br>
>>>> argument.<br>
>>>> - SourceLocation EndLoc = Tok.getLocation();<br>
>>>> - Tok.startToken();<br>
>>>> - Tok.setKind(tok::eof);<br>
>>>> - Tok.setLocation(EndLoc);<br>
>>>> - Tok.setLength(0);<br>
>>>> - ArgTokens.push_back(Tok);<br>
>>>> -<br>
>>>> - // If we expect two arguments, add both as empty.<br>
>>>> - if (NumActuals == 0 && MinArgsExpected == 2)<br>
>>>> - ArgTokens.push_back(Tok);<br>
>>>> -<br>
>>>> - } else if (NumActuals > MinArgsExpected && !MI->isVariadic()) {<br>
>>>> - // Emit the diagnostic at the macro name in case there is a missing<br>
>>>> ).<br>
>>>> - // Emitting it at the , could be far away from the macro name.<br>
>>>> - Diag(MacroName, diag::err_too_many_args_in_macro_invoc);<br>
>>>> - return 0;<br>
>>>> - }<br>
>>>> -<br>
>>>> - return MacroArgs::create(MI, ArgTokens, isVarargsElided, *this);<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// \brief Keeps macro expanded tokens for TokenLexers.<br>
>>>> -//<br>
>>>> -/// Works like a stack; a TokenLexer adds the macro expanded tokens that<br>
>>>> is<br>
>>>> -/// going to lex in the cache and when it finishes the tokens are<br>
>>>> removed<br>
>>>> -/// from the end of the cache.<br>
>>>> -Token *Preprocessor::cacheMacroExpandedTokens(TokenLexer *tokLexer,<br>
>>>> - ArrayRef<Token> tokens) {<br>
>>>> - assert(tokLexer);<br>
>>>> - if (tokens.empty())<br>
>>>> - return 0;<br>
>>>> -<br>
>>>> - size_t newIndex = MacroExpandedTokens.size();<br>
>>>> - bool cacheNeedsToGrow = tokens.size() ><br>
>>>> -<br>
>>>> MacroExpandedTokens.capacity()-MacroExpandedTokens.size();<br>
>>>> - MacroExpandedTokens.append(tokens.begin(), tokens.end());<br>
>>>> -<br>
>>>> - if (cacheNeedsToGrow) {<br>
>>>> - // Go through all the TokenLexers whose 'Tokens' pointer points in<br>
>>>> the<br>
>>>> - // buffer and update the pointers to the (potential) new buffer<br>
>>>> array.<br>
>>>> - for (unsigned i = 0, e = MacroExpandingLexersStack.size(); i != e;<br>
>>>> ++i) {<br>
>>>> - TokenLexer *prevLexer;<br>
>>>> - size_t tokIndex;<br>
>>>> - llvm::tie(prevLexer, tokIndex) = MacroExpandingLexersStack[i];<br>
>>>> - prevLexer->Tokens = MacroExpandedTokens.data() + tokIndex;<br>
>>>> - }<br>
>>>> - }<br>
>>>> -<br>
>>>> - MacroExpandingLexersStack.push_back(std::make_pair(tokLexer,<br>
>>>> newIndex));<br>
>>>> - return MacroExpandedTokens.data() + newIndex;<br>
>>>> -}<br>
>>>> -<br>
>>>> -void Preprocessor::removeCachedMacroExpandedTokensOfLastLexer() {<br>
>>>> - assert(!MacroExpandingLexersStack.empty());<br>
>>>> - size_t tokIndex = MacroExpandingLexersStack.back().second;<br>
>>>> - assert(tokIndex < MacroExpandedTokens.size());<br>
>>>> - // Pop the cached macro expanded tokens from the end.<br>
>>>> - MacroExpandedTokens.resize(tokIndex);<br>
>>>> - MacroExpandingLexersStack.pop_back();<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// ComputeDATE_TIME - Compute the current time, enter it into the<br>
>>>> specified<br>
>>>> -/// scratch buffer, then return DATELoc/TIMELoc locations with the<br>
>>>> position of<br>
>>>> -/// the identifier tokens inserted.<br>
>>>> -static void ComputeDATE_TIME(SourceLocation &DATELoc, SourceLocation<br>
>>>> &TIMELoc,<br>
>>>> - Preprocessor &PP) {<br>
>>>> - time_t TT = time(0);<br>
>>>> - struct tm *TM = localtime(&TT);<br>
>>>> -<br>
>>>> - static const char * const Months[] = {<br>
>>>> -<br>
>>>> "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"<br>
>>>> - };<br>
>>>> -<br>
>>>> - char TmpBuffer[32];<br>
>>>> -#ifdef LLVM_ON_WIN32<br>
>>>> - sprintf(TmpBuffer, "\"%s %2d %4d\"", Months[TM->tm_mon], TM->tm_mday,<br>
>>>> - TM->tm_year+1900);<br>
>>>> -#else<br>
>>>> - snprintf(TmpBuffer, sizeof(TmpBuffer), "\"%s %2d %4d\"",<br>
>>>> Months[TM->tm_mon], TM->tm_mday,<br>
>>>> - TM->tm_year+1900);<br>
>>>> -#endif<br>
>>>> -<br>
>>>> - Token TmpTok;<br>
>>>> - TmpTok.startToken();<br>
>>>> - PP.CreateString(TmpBuffer, strlen(TmpBuffer), TmpTok);<br>
>>>> - DATELoc = TmpTok.getLocation();<br>
>>>> -<br>
>>>> -#ifdef LLVM_ON_WIN32<br>
>>>> - sprintf(TmpBuffer, "\"%02d:%02d:%02d\"", TM->tm_hour, TM->tm_min,<br>
>>>> TM->tm_sec);<br>
>>>> -#else<br>
>>>> - snprintf(TmpBuffer, sizeof(TmpBuffer), "\"%02d:%02d:%02d\"",<br>
>>>> TM->tm_hour, TM->tm_min, TM->tm_sec);<br>
>>>> -#endif<br>
>>>> - PP.CreateString(TmpBuffer, strlen(TmpBuffer), TmpTok);<br>
>>>> - TIMELoc = TmpTok.getLocation();<br>
>>>> -}<br>
>>>> -<br>
>>>> -<br>
>>>> -/// HasFeature - Return true if we recognize and implement the feature<br>
>>>> -/// specified by the identifier as a standard language feature.<br>
>>>> -static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II)<br>
>>>> {<br>
>>>> - const LangOptions &LangOpts = PP.getLangOpts();<br>
>>>> - StringRef Feature = II->getName();<br>
>>>> -<br>
>>>> - // Normalize the feature name, __foo__ becomes foo.<br>
>>>> - if (Feature.startswith("__") && Feature.endswith("__") &&<br>
>>>> Feature.size() >= 4)<br>
>>>> - Feature = Feature.substr(2, Feature.size() - 4);<br>
>>>> -<br>
>>>> - return llvm::StringSwitch<bool>(Feature)<br>
>>>> - .Case("address_sanitizer", LangOpts.AddressSanitizer)<br>
>>>> - .Case("attribute_analyzer_noreturn", true)<br>
>>>> - .Case("attribute_availability", true)<br>
>>>> - .Case("attribute_availability_with_message", true)<br>
>>>> - .Case("attribute_cf_returns_not_retained", true)<br>
>>>> - .Case("attribute_cf_returns_retained", true)<br>
>>>> - .Case("attribute_deprecated_with_message", true)<br>
>>>> - .Case("attribute_ext_vector_type", true)<br>
>>>> - .Case("attribute_ns_returns_not_retained", true)<br>
>>>> - .Case("attribute_ns_returns_retained", true)<br>
>>>> - .Case("attribute_ns_consumes_self", true)<br>
>>>> - .Case("attribute_ns_consumed", true)<br>
>>>> - .Case("attribute_cf_consumed", true)<br>
>>>> - .Case("attribute_objc_ivar_unused", true)<br>
>>>> - .Case("attribute_objc_method_family", true)<br>
>>>> - .Case("attribute_overloadable", true)<br>
>>>> - .Case("attribute_unavailable_with_message", true)<br>
>>>> - .Case("attribute_unused_on_fields", true)<br>
>>>> - .Case("blocks", LangOpts.Blocks)<br>
>>>> - .Case("cxx_exceptions", LangOpts.Exceptions)<br>
>>>> - .Case("cxx_rtti", LangOpts.RTTI)<br>
>>>> - .Case("enumerator_attributes", true)<br>
>>>> - // Objective-C features<br>
>>>> - .Case("objc_arr", LangOpts.ObjCAutoRefCount) // FIXME:<br>
>>>> REMOVE?<br>
>>>> - .Case("objc_arc", LangOpts.ObjCAutoRefCount)<br>
>>>> - .Case("objc_arc_weak", LangOpts.ObjCARCWeak)<br>
>>>> - .Case("objc_default_synthesize_properties", LangOpts.ObjC2)<br>
>>>> - .Case("objc_fixed_enum", LangOpts.ObjC2)<br>
>>>> - .Case("objc_instancetype", LangOpts.ObjC2)<br>
>>>> - .Case("objc_modules", LangOpts.ObjC2 && LangOpts.Modules)<br>
>>>> - .Case("objc_nonfragile_abi",<br>
>>>> LangOpts.ObjCRuntime.isNonFragile())<br>
>>>> - .Case("objc_weak_class",<br>
>>>> LangOpts.ObjCRuntime.hasWeakClassImport())<br>
>>>> - .Case("ownership_holds", true)<br>
>>>> - .Case("ownership_returns", true)<br>
>>>> - .Case("ownership_takes", true)<br>
>>>> - .Case("objc_bool", true)<br>
>>>> - .Case("objc_subscripting",<br>
>>>> LangOpts.ObjCRuntime.isNonFragile())<br>
>>>> - .Case("objc_array_literals", LangOpts.ObjC2)<br>
>>>> - .Case("objc_dictionary_literals", LangOpts.ObjC2)<br>
>>>> - .Case("objc_boxed_expressions", LangOpts.ObjC2)<br>
>>>> - .Case("arc_cf_code_audited", true)<br>
>>>> - // C11 features<br>
>>>> - .Case("c_alignas", LangOpts.C11)<br>
>>>> - .Case("c_atomic", LangOpts.C11)<br>
>>>> - .Case("c_generic_selections", LangOpts.C11)<br>
>>>> - .Case("c_static_assert", LangOpts.C11)<br>
>>>> - // C++11 features<br>
>>>> - .Case("cxx_access_control_sfinae", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_alias_templates", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_alignas", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_atomic", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_attributes", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_auto_type", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_constexpr", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_decltype", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_decltype_incomplete_return_types",<br>
>>>> LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_default_function_template_args",<br>
>>>> LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_defaulted_functions", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_delegating_constructors", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_deleted_functions", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_explicit_conversions", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_generalized_initializers", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_implicit_moves", LangOpts.CPlusPlus0x)<br>
>>>> - //.Case("cxx_inheriting_constructors", false)<br>
>>>> - .Case("cxx_inline_namespaces", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_lambdas", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_local_type_template_args", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_nonstatic_member_init", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_noexcept", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_nullptr", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_override_control", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_range_for", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_raw_string_literals", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_reference_qualified_functions",<br>
>>>> LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_rvalue_references", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_strong_enums", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_static_assert", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_trailing_return", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_unicode_literals", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_unrestricted_unions", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_user_literals", LangOpts.CPlusPlus0x)<br>
>>>> - .Case("cxx_variadic_templates", LangOpts.CPlusPlus0x)<br>
>>>> - // Type traits<br>
>>>> - .Case("has_nothrow_assign", LangOpts.CPlusPlus)<br>
>>>> - .Case("has_nothrow_copy", LangOpts.CPlusPlus)<br>
>>>> - .Case("has_nothrow_constructor", LangOpts.CPlusPlus)<br>
>>>> - .Case("has_trivial_assign", LangOpts.CPlusPlus)<br>
>>>> - .Case("has_trivial_copy", LangOpts.CPlusPlus)<br>
>>>> - .Case("has_trivial_constructor", LangOpts.CPlusPlus)<br>
>>>> - .Case("has_trivial_destructor", LangOpts.CPlusPlus)<br>
>>>> - .Case("has_virtual_destructor", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_abstract", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_base_of", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_class", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_convertible_to", LangOpts.CPlusPlus)<br>
>>>> - // __is_empty is available only if the horrible<br>
>>>> - // "struct __is_empty" parsing hack hasn't been needed in<br>
>>>> this<br>
>>>> - // translation unit. If it has, __is_empty reverts to a<br>
>>>> normal<br>
>>>> - // identifier and __has_feature(is_empty) evaluates false.<br>
>>>> - .Case("is_empty", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_enum", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_final", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_literal", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_standard_layout", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_pod", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_polymorphic", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_trivial", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_trivially_assignable", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_trivially_constructible", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_trivially_copyable", LangOpts.CPlusPlus)<br>
>>>> - .Case("is_union", LangOpts.CPlusPlus)<br>
>>>> - .Case("modules", LangOpts.Modules)<br>
>>>> - .Case("tls", PP.getTargetInfo().isTLSSupported())<br>
>>>> - .Case("underlying_type", LangOpts.CPlusPlus)<br>
>>>> - .Default(false);<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// HasExtension - Return true if we recognize and implement the feature<br>
>>>> -/// specified by the identifier, either as an extension or a standard<br>
>>>> language<br>
>>>> -/// feature.<br>
>>>> -static bool HasExtension(const Preprocessor &PP, const IdentifierInfo<br>
>>>> *II) {<br>
>>>> - if (HasFeature(PP, II))<br>
>>>> - return true;<br>
>>>> -<br>
>>>> - // If the use of an extension results in an error diagnostic,<br>
>>>> extensions are<br>
>>>> - // effectively unavailable, so just return false here.<br>
>>>> - if (PP.getDiagnostics().getExtensionHandlingBehavior() ==<br>
>>>> - DiagnosticsEngine::Ext_Error)<br>
>>>> - return false;<br>
>>>> -<br>
>>>> - const LangOptions &LangOpts = PP.getLangOpts();<br>
>>>> - StringRef Extension = II->getName();<br>
>>>> -<br>
>>>> - // Normalize the extension name, __foo__ becomes foo.<br>
>>>> - if (Extension.startswith("__") && Extension.endswith("__") &&<br>
>>>> - Extension.size() >= 4)<br>
>>>> - Extension = Extension.substr(2, Extension.size() - 4);<br>
>>>> -<br>
>>>> - // Because we inherit the feature list from HasFeature, this string<br>
>>>> switch<br>
>>>> - // must be less restrictive than HasFeature's.<br>
>>>> - return llvm::StringSwitch<bool>(Extension)<br>
>>>> - // C11 features supported by other languages as extensions.<br>
>>>> - .Case("c_alignas", true)<br>
>>>> - .Case("c_atomic", true)<br>
>>>> - .Case("c_generic_selections", true)<br>
>>>> - .Case("c_static_assert", true)<br>
>>>> - // C++0x features supported by other languages as extensions.<br>
>>>> - .Case("cxx_atomic", LangOpts.CPlusPlus)<br>
>>>> - .Case("cxx_deleted_functions", LangOpts.CPlusPlus)<br>
>>>> - .Case("cxx_explicit_conversions", LangOpts.CPlusPlus)<br>
>>>> - .Case("cxx_inline_namespaces", LangOpts.CPlusPlus)<br>
>>>> - .Case("cxx_local_type_template_args", LangOpts.CPlusPlus)<br>
>>>> - .Case("cxx_nonstatic_member_init", LangOpts.CPlusPlus)<br>
>>>> - .Case("cxx_override_control", LangOpts.CPlusPlus)<br>
>>>> - .Case("cxx_range_for", LangOpts.CPlusPlus)<br>
>>>> - .Case("cxx_reference_qualified_functions",<br>
>>>> LangOpts.CPlusPlus)<br>
>>>> - .Case("cxx_rvalue_references", LangOpts.CPlusPlus)<br>
>>>> - .Default(false);<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// HasAttribute - Return true if we recognize and implement the<br>
>>>> attribute<br>
>>>> -/// specified by the given identifier.<br>
>>>> -static bool HasAttribute(const IdentifierInfo *II) {<br>
>>>> - StringRef Name = II->getName();<br>
>>>> - // Normalize the attribute name, __foo__ becomes foo.<br>
>>>> - if (Name.startswith("__") && Name.endswith("__") && Name.size() >= 4)<br>
>>>> - Name = Name.substr(2, Name.size() - 4);<br>
>>>> -<br>
>>>> - // FIXME: Do we need to handle namespaces here?<br>
>>>> - return llvm::StringSwitch<bool>(Name)<br>
>>>> -#include "clang/Lex/AttrSpellings.inc"<br>
>>>> - .Default(false);<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// EvaluateHasIncludeCommon - Process a '__has_include("path")'<br>
>>>> -/// or '__has_include_next("path")' expression.<br>
>>>> -/// Returns true if successful.<br>
>>>> -static bool EvaluateHasIncludeCommon(Token &Tok,<br>
>>>> - IdentifierInfo *II, Preprocessor<br>
>>>> &PP,<br>
>>>> - const DirectoryLookup *LookupFrom)<br>
>>>> {<br>
>>>> - SourceLocation LParenLoc;<br>
>>>> -<br>
>>>> - // Get '('.<br>
>>>> - PP.LexNonComment(Tok);<br>
>>>> -<br>
>>>> - // Ensure we have a '('.<br>
>>>> - if (Tok.isNot(tok::l_paren)) {<br>
>>>> - PP.Diag(Tok.getLocation(), diag::err_pp_missing_lparen) <<<br>
>>>> II->getName();<br>
>>>> - return false;<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Save '(' location for possible missing ')' message.<br>
>>>> - LParenLoc = Tok.getLocation();<br>
>>>> -<br>
>>>> - // Get the file name.<br>
>>>> - PP.getCurrentLexer()->LexIncludeFilename(Tok);<br>
>>>> -<br>
>>>> - // Reserve a buffer to get the spelling.<br>
>>>> - SmallString<128> FilenameBuffer;<br>
>>>> - StringRef Filename;<br>
>>>> - SourceLocation EndLoc;<br>
>>>> -<br>
>>>> - switch (Tok.getKind()) {<br>
>>>> - case tok::eod:<br>
>>>> - // If the token kind is EOD, the error has already been diagnosed.<br>
>>>> - return false;<br>
>>>> -<br>
>>>> - case tok::angle_string_literal:<br>
>>>> - case tok::string_literal: {<br>
>>>> - bool Invalid = false;<br>
>>>> - Filename = PP.getSpelling(Tok, FilenameBuffer, &Invalid);<br>
>>>> - if (Invalid)<br>
>>>> - return false;<br>
>>>> - break;<br>
>>>> - }<br>
>>>> -<br>
>>>> - case tok::less:<br>
>>>> - // This could be a <foo/bar.h> file coming from a macro expansion.<br>
>>>> In this<br>
>>>> - // case, glue the tokens together into FilenameBuffer and interpret<br>
>>>> those.<br>
>>>> - FilenameBuffer.push_back('<');<br>
>>>> - if (PP.ConcatenateIncludeName(FilenameBuffer, EndLoc))<br>
>>>> - return false; // Found <eod> but no ">"? Diagnostic already<br>
>>>> emitted.<br>
>>>> - Filename = FilenameBuffer.str();<br>
>>>> - break;<br>
>>>> - default:<br>
>>>> - PP.Diag(Tok.getLocation(), diag::err_pp_expects_filename);<br>
>>>> - return false;<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Get ')'.<br>
>>>> - PP.LexNonComment(Tok);<br>
>>>> -<br>
>>>> - // Ensure we have a trailing ).<br>
>>>> - if (Tok.isNot(tok::r_paren)) {<br>
>>>> - PP.Diag(Tok.getLocation(), diag::err_pp_missing_rparen) <<<br>
>>>> II->getName();<br>
>>>> - PP.Diag(LParenLoc, diag::note_matching) << "(";<br>
>>>> - return false;<br>
>>>> - }<br>
>>>> -<br>
>>>> - bool isAngled = PP.GetIncludeFilenameSpelling(Tok.getLocation(),<br>
>>>> Filename);<br>
>>>> - // If GetIncludeFilenameSpelling set the start ptr to null, there was<br>
>>>> an<br>
>>>> - // error.<br>
>>>> - if (Filename.empty())<br>
>>>> - return false;<br>
>>>> -<br>
>>>> - // Search include directories.<br>
>>>> - const DirectoryLookup *CurDir;<br>
>>>> - const FileEntry *File =<br>
>>>> - PP.LookupFile(Filename, isAngled, LookupFrom, CurDir, NULL, NULL,<br>
>>>> NULL);<br>
>>>> -<br>
>>>> - // Get the result value. A result of true means the file exists.<br>
>>>> - return File != 0;<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// EvaluateHasInclude - Process a '__has_include("path")' expression.<br>
>>>> -/// Returns true if successful.<br>
>>>> -static bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II,<br>
>>>> - Preprocessor &PP) {<br>
>>>> - return EvaluateHasIncludeCommon(Tok, II, PP, NULL);<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// EvaluateHasIncludeNext - Process '__has_include_next("path")'<br>
>>>> expression.<br>
>>>> -/// Returns true if successful.<br>
>>>> -static bool EvaluateHasIncludeNext(Token &Tok,<br>
>>>> - IdentifierInfo *II, Preprocessor &PP)<br>
>>>> {<br>
>>>> - // __has_include_next is like __has_include, except that we start<br>
>>>> - // searching after the current found directory. If we can't do this,<br>
>>>> - // issue a diagnostic.<br>
>>>> - const DirectoryLookup *Lookup = PP.GetCurDirLookup();<br>
>>>> - if (PP.isInPrimaryFile()) {<br>
>>>> - Lookup = 0;<br>
>>>> - PP.Diag(Tok, diag::pp_include_next_in_primary);<br>
>>>> - } else if (Lookup == 0) {<br>
>>>> - PP.Diag(Tok, diag::pp_include_next_absolute_path);<br>
>>>> - } else {<br>
>>>> - // Start looking up in the next directory.<br>
>>>> - ++Lookup;<br>
>>>> - }<br>
>>>> -<br>
>>>> - return EvaluateHasIncludeCommon(Tok, II, PP, Lookup);<br>
>>>> -}<br>
>>>> -<br>
>>>> -/// ExpandBuiltinMacro - If an identifier token is read that is to be<br>
>>>> expanded<br>
>>>> -/// as a builtin macro, handle it and return the next token as 'Tok'.<br>
>>>> -void Preprocessor::ExpandBuiltinMacro(Token &Tok) {<br>
>>>> - // Figure out which token this is.<br>
>>>> - IdentifierInfo *II = Tok.getIdentifierInfo();<br>
>>>> - assert(II && "Can't be a macro without id info!");<br>
>>>> -<br>
>>>> - // If this is an _Pragma or Microsoft __pragma directive, expand it,<br>
>>>> - // invoke the pragma handler, then lex the token after it.<br>
>>>> - if (II == Ident_Pragma)<br>
>>>> - return Handle_Pragma(Tok);<br>
>>>> - else if (II == Ident__pragma) // in non-MS mode this is null<br>
>>>> - return HandleMicrosoft__pragma(Tok);<br>
>>>> -<br>
>>>> - ++NumBuiltinMacroExpanded;<br>
>>>> -<br>
>>>> - SmallString<128> TmpBuffer;<br>
>>>> - llvm::raw_svector_ostream OS(TmpBuffer);<br>
>>>> -<br>
>>>> - // Set up the return result.<br>
>>>> - Tok.setIdentifierInfo(0);<br>
>>>> - Tok.clearFlag(Token::NeedsCleaning);<br>
>>>> -<br>
>>>> - if (II == Ident__LINE__) {<br>
>>>> - // C99 6.10.8: "__LINE__: The presumed line number (within the<br>
>>>> current<br>
>>>> - // source file) of the current source line (an integer constant)".<br>
>>>> This can<br>
>>>> - // be affected by #line.<br>
>>>> - SourceLocation Loc = Tok.getLocation();<br>
>>>> -<br>
>>>> - // Advance to the location of the first _, this might not be the<br>
>>>> first byte<br>
>>>> - // of the token if it starts with an escaped newline.<br>
>>>> - Loc = AdvanceToTokenCharacter(Loc, 0);<br>
>>>> -<br>
>>>> - // One wrinkle here is that GCC expands __LINE__ to location of the<br>
>>>> *end* of<br>
>>>> - // a macro expansion. This doesn't matter for object-like macros,<br>
>>>> but<br>
>>>> - // can matter for a function-like macro that expands to contain<br>
>>>> __LINE__.<br>
>>>> - // Skip down through expansion points until we find a file loc for<br>
>>>> the<br>
>>>> - // end of the expansion history.<br>
>>>> - Loc = SourceMgr.getExpansionRange(Loc).second;<br>
>>>> - PresumedLoc PLoc = SourceMgr.getPresumedLoc(Loc);<br>
>>>> -<br>
>>>> - // __LINE__ expands to a simple numeric value.<br>
>>>> - OS << (PLoc.isValid()? PLoc.getLine() : 1);<br>
>>>> - Tok.setKind(tok::numeric_constant);<br>
>>>> - } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {<br>
>>>> - // C99 6.10.8: "__FILE__: The presumed name of the current source<br>
>>>> file (a<br>
>>>> - // character string literal)". This can be affected by #line.<br>
>>>> - PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());<br>
>>>> -<br>
>>>> - // __BASE_FILE__ is a GNU extension that returns the top of the<br>
>>>> presumed<br>
>>>> - // #include stack instead of the current file.<br>
>>>> - if (II == Ident__BASE_FILE__ && PLoc.isValid()) {<br>
>>>> - SourceLocation NextLoc = PLoc.getIncludeLoc();<br>
>>>> - while (NextLoc.isValid()) {<br>
>>>> - PLoc = SourceMgr.getPresumedLoc(NextLoc);<br>
>>>> - if (PLoc.isInvalid())<br>
>>>> - break;<br>
>>>> -<br>
>>>> - NextLoc = PLoc.getIncludeLoc();<br>
>>>> - }<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Escape this filename. Turn '\' -> '\\' '"' -> '\"'<br>
>>>> - SmallString<128> FN;<br>
>>>> - if (PLoc.isValid()) {<br>
>>>> - FN += PLoc.getFilename();<br>
>>>> - Lexer::Stringify(FN);<br>
>>>> - OS << '"' << FN.str() << '"';<br>
>>>> - }<br>
>>>> - Tok.setKind(tok::string_literal);<br>
>>>> - } else if (II == Ident__DATE__) {<br>
>>>> - if (!DATELoc.isValid())<br>
>>>> - ComputeDATE_TIME(DATELoc, TIMELoc, *this);<br>
>>>> - Tok.setKind(tok::string_literal);<br>
>>>> - Tok.setLength(strlen("\"Mmm dd yyyy\""));<br>
>>>> - Tok.setLocation(SourceMgr.createExpansionLoc(DATELoc,<br>
>>>> Tok.getLocation(),<br>
>>>> - Tok.getLocation(),<br>
>>>> - Tok.getLength()));<br>
>>>> - return;<br>
>>>> - } else if (II == Ident__TIME__) {<br>
>>>> - if (!TIMELoc.isValid())<br>
>>>> - ComputeDATE_TIME(DATELoc, TIMELoc, *this);<br>
>>>> - Tok.setKind(tok::string_literal);<br>
>>>> - Tok.setLength(strlen("\"hh:mm:ss\""));<br>
>>>> - Tok.setLocation(SourceMgr.createExpansionLoc(TIMELoc,<br>
>>>> Tok.getLocation(),<br>
>>>> - Tok.getLocation(),<br>
>>>> - Tok.getLength()));<br>
>>>> - return;<br>
>>>> - } else if (II == Ident__INCLUDE_LEVEL__) {<br>
>>>> - // Compute the presumed include depth of this token. This can be<br>
>>>> affected<br>
>>>> - // by GNU line markers.<br>
>>>> - unsigned Depth = 0;<br>
>>>> -<br>
>>>> - PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());<br>
>>>> - if (PLoc.isValid()) {<br>
>>>> - PLoc = SourceMgr.getPresumedLoc(PLoc.getIncludeLoc());<br>
>>>> - for (; PLoc.isValid(); ++Depth)<br>
>>>> - PLoc = SourceMgr.getPresumedLoc(PLoc.getIncludeLoc());<br>
>>>> - }<br>
>>>> -<br>
>>>> - // __INCLUDE_LEVEL__ expands to a simple numeric value.<br>
>>>> - OS << Depth;<br>
>>>> - Tok.setKind(tok::numeric_constant);<br>
>>>> - } else if (II == Ident__TIMESTAMP__) {<br>
>>>> - // MSVC, ICC, GCC, VisualAge C++ extension. The generated string<br>
>>>> should be<br>
>>>> - // of the form "Ddd Mmm dd hh::mm::ss yyyy", which is returned by<br>
>>>> asctime.<br>
>>>> -<br>
>>>> - // Get the file that we are lexing out of. If we're currently<br>
>>>> lexing from<br>
>>>> - // a macro, dig into the include stack.<br>
>>>> - const FileEntry *CurFile = 0;<br>
>>>> - PreprocessorLexer *TheLexer = getCurrentFileLexer();<br>
>>>> -<br>
>>>> - if (TheLexer)<br>
>>>> - CurFile = SourceMgr.getFileEntryForID(TheLexer->getFileID());<br>
>>>> -<br>
>>>> - const char *Result;<br>
>>>> - if (CurFile) {<br>
>>>> - time_t TT = CurFile->getModificationTime();<br>
>>>> - struct tm *TM = localtime(&TT);<br>
>>>> - Result = asctime(TM);<br>
>>>> - } else {<br>
>>>> - Result = "??? ??? ?? ??:??:?? ????\n";<br>
>>>> - }<br>
>>>> - // Surround the string with " and strip the trailing newline.<br>
>>>> - OS << '"' << StringRef(Result, strlen(Result)-1) << '"';<br>
>>>> - Tok.setKind(tok::string_literal);<br>
>>>> - } else if (II == Ident__COUNTER__) {<br>
>>>> - // __COUNTER__ expands to a simple numeric value.<br>
>>>> - OS << CounterValue++;<br>
>>>> - Tok.setKind(tok::numeric_constant);<br>
>>>> - } else if (II == Ident__has_feature ||<br>
>>>> - II == Ident__has_extension ||<br>
>>>> - II == Ident__has_builtin ||<br>
>>>> - II == Ident__has_attribute) {<br>
>>>> - // The argument to these builtins should be a parenthesized<br>
>>>> identifier.<br>
>>>> - SourceLocation StartLoc = Tok.getLocation();<br>
>>>> -<br>
>>>> - bool IsValid = false;<br>
>>>> - IdentifierInfo *FeatureII = 0;<br>
>>>> -<br>
>>>> - // Read the '('.<br>
>>>> - Lex(Tok);<br>
>>>> - if (Tok.is(tok::l_paren)) {<br>
>>>> - // Read the identifier<br>
>>>> - Lex(Tok);<br>
>>>> - if (Tok.is(tok::identifier) || Tok.is(tok::kw_const)) {<br>
>>>> - FeatureII = Tok.getIdentifierInfo();<br>
>>>> -<br>
>>>> - // Read the ')'.<br>
>>>> - Lex(Tok);<br>
>>>> - if (Tok.is(tok::r_paren))<br>
>>>> - IsValid = true;<br>
>>>> - }<br>
>>>> - }<br>
>>>> -<br>
>>>> - bool Value = false;<br>
>>>> - if (!IsValid)<br>
>>>> - Diag(StartLoc, diag::err_feature_check_malformed);<br>
>>>> - else if (II == Ident__has_builtin) {<br>
>>>> - // Check for a builtin is trivial.<br>
>>>> - Value = FeatureII->getBuiltinID() != 0;<br>
>>>> - } else if (II == Ident__has_attribute)<br>
>>>> - Value = HasAttribute(FeatureII);<br>
>>>> - else if (II == Ident__has_extension)<br>
>>>> - Value = HasExtension(*this, FeatureII);<br>
>>>> - else {<br>
>>>> - assert(II == Ident__has_feature && "Must be feature check");<br>
>>>> - Value = HasFeature(*this, FeatureII);<br>
>>>> - }<br>
>>>> -<br>
>>>> - OS << (int)Value;<br>
>>>> - if (IsValid)<br>
>>>> - Tok.setKind(tok::numeric_constant);<br>
>>>> - } else if (II == Ident__has_include ||<br>
>>>> - II == Ident__has_include_next) {<br>
>>>> - // The argument to these two builtins should be a parenthesized<br>
>>>> - // file name string literal using angle brackets (<>) or<br>
>>>> - // double-quotes ("").<br>
>>>> - bool Value;<br>
>>>> - if (II == Ident__has_include)<br>
>>>> - Value = EvaluateHasInclude(Tok, II, *this);<br>
>>>> - else<br>
>>>> - Value = EvaluateHasIncludeNext(Tok, II, *this);<br>
>>>> - OS << (int)Value;<br>
>>>> - Tok.setKind(tok::numeric_constant);<br>
>>>> - } else if (II == Ident__has_warning) {<br>
>>>> - // The argument should be a parenthesized string literal.<br>
>>>> - // The argument to these builtins should be a parenthesized<br>
>>>> identifier.<br>
>>>> - SourceLocation StartLoc = Tok.getLocation();<br>
>>>> - bool IsValid = false;<br>
>>>> - bool Value = false;<br>
>>>> - // Read the '('.<br>
>>>> - Lex(Tok);<br>
>>>> - do {<br>
>>>> - if (Tok.is(tok::l_paren)) {<br>
>>>> - // Read the string.<br>
>>>> - Lex(Tok);<br>
>>>> -<br>
>>>> - // We need at least one string literal.<br>
>>>> - if (!Tok.is(tok::string_literal)) {<br>
>>>> - StartLoc = Tok.getLocation();<br>
>>>> - IsValid = false;<br>
>>>> - // Eat tokens until ')'.<br>
>>>> - do Lex(Tok); while (!(Tok.is(tok::r_paren) ||<br>
>>>> Tok.is(tok::eod)));<br>
>>>> - break;<br>
>>>> - }<br>
>>>> -<br>
>>>> - // String concatenation allows multiple strings, which can even<br>
>>>> come<br>
>>>> - // from macro expansion.<br>
>>>> - SmallVector<Token, 4> StrToks;<br>
>>>> - while (Tok.is(tok::string_literal)) {<br>
>>>> - // Complain about, and drop, any ud-suffix.<br>
>>>> - if (Tok.hasUDSuffix())<br>
>>>> - Diag(Tok, diag::err_invalid_string_udl);<br>
>>>> - StrToks.push_back(Tok);<br>
>>>> - LexUnexpandedToken(Tok);<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Is the end a ')'?<br>
>>>> - if (!(IsValid = Tok.is(tok::r_paren)))<br>
>>>> - break;<br>
>>>> -<br>
>>>> - // Concatenate and parse the strings.<br>
>>>> - StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this);<br>
>>>> - assert(Literal.isAscii() && "Didn't allow wide strings in");<br>
>>>> - if (Literal.hadError)<br>
>>>> - break;<br>
>>>> - if (Literal.Pascal) {<br>
>>>> - Diag(Tok, diag::warn_pragma_diagnostic_invalid);<br>
>>>> - break;<br>
>>>> - }<br>
>>>> -<br>
>>>> - StringRef WarningName(Literal.GetString());<br>
>>>> -<br>
>>>> - if (WarningName.size() < 3 || WarningName[0] != '-' ||<br>
>>>> - WarningName[1] != 'W') {<br>
>>>> - Diag(StrToks[0].getLocation(),<br>
>>>> diag::warn_has_warning_invalid_option);<br>
>>>> - break;<br>
>>>> - }<br>
>>>> -<br>
>>>> - // Finally, check if the warning flags maps to a diagnostic<br>
>>>> group.<br>
>>>> - // We construct a SmallVector here to talk to<br>
>>>> getDiagnosticIDs().<br>
>>>> - // Although we don't use the result, this isn't a hot path, and<br>
>>>> not<br>
>>>> - // worth special casing.<br>
>>>> - llvm::SmallVector<diag::kind, 10> Diags;<br>
>>>> - Value = !getDiagnostics().getDiagnosticIDs()-><br>
>>>> - getDiagnosticsInGroup(WarningName.substr(2), Diags);<br>
>>>> - }<br>
>>>> - } while (false);<br>
>>>> -<br>
>>>> - if (!IsValid)<br>
>>>> - Diag(StartLoc, diag::err_warning_check_malformed);<br>
>>>> -<br>
>>>> - OS << (int)Value;<br>
>>>> - Tok.setKind(tok::numeric_constant);<br>
>>>> - } else {<br>
>>>> - llvm_unreachable("Unknown identifier!");<br>
>>>> - }<br>
>>>> - CreateString(OS.str().data(), OS.str().size(), Tok,<br>
>>>> - Tok.getLocation(), Tok.getLocation());<br>
>>>> -}<br>
>>>> -<br>
>>>> -void Preprocessor::markMacroAsUsed(MacroInfo *MI) {<br>
>>>> - // If the 'used' status changed, and the macro requires 'unused'<br>
>>>> warning,<br>
>>>> - // remove its SourceLocation from the warn-for-unused-macro locations.<br>
>>>> - if (MI->isWarnIfUnused() && !MI->isUsed())<br>
>>>> - WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());<br>
>>>> - MI->setIsUsed(true);<br>
>>>> -}<br>
>>>> +//===--- MacroExpansion.cpp - Top level Macro Expansion<br>
>>>> -------------------===//<br>
>>>> +//<br>
>>>> +// The LLVM Compiler Infrastructure<br>
>>>> +//<br>
>>>> +// This file is distributed under the University of Illinois Open Source<br>
>>>> +// License. See LICENSE.TXT for details.<br>
>>>> +//<br>
>>>><br>
>>>> +//===----------------------------------------------------------------------===//<br>
>>>> +//<br>
>>>> +// This file implements the top level handling of macro expasion for the<br>
>>>> +// preprocessor.<br>
>>>> +//<br>
>>>><br>
>>>> +//===----------------------------------------------------------------------===//<br>
>>>> +<br>
>>>> +#include "clang/Lex/Preprocessor.h"<br>
>>>> +#include "MacroArgs.h"<br>
>>>> +#include "clang/Lex/MacroInfo.h"<br>
>>>> +#include "clang/Basic/SourceManager.h"<br>
>>>> +#include "clang/Basic/FileManager.h"<br>
>>>> +#include "clang/Basic/TargetInfo.h"<br>
>>>> +#include "clang/Lex/LexDiagnostic.h"<br>
>>>> +#include "clang/Lex/CodeCompletionHandler.h"<br>
>>>> +#include "clang/Lex/ExternalPreprocessorSource.h"<br>
>>>> +#include "clang/Lex/LiteralSupport.h"<br>
>>>> +#include "llvm/ADT/StringSwitch.h"<br>
>>>> +#include "llvm/ADT/STLExtras.h"<br>
>>>> +#include "llvm/Config/llvm-config.h"<br>
>>>> +#include "llvm/Support/raw_ostream.h"<br>
>>>> +#include "llvm/Support/ErrorHandling.h"<br>
>>>> +#include <cstdio><br>
>>>> +#include <ctime><br>
>>>> +using namespace clang;<br>
>>>> +<br>
>>>> +MacroInfo *Preprocessor::getInfoForMacro(IdentifierInfo *II) const {<br>
>>>> + assert(II->hasMacroDefinition() && "Identifier is not a macro!");<br>
>>>> +<br>
>>>> + macro_iterator Pos = Macros.find(II);<br>
>>>> + if (Pos == Macros.end()) {<br>
>>>> + // Load this macro from the external source.<br>
>>>> + getExternalSource()->LoadMacroDefinition(II);<br>
>>>> + Pos = Macros.find(II);<br>
>>>> + }<br>
>>>> + assert(Pos != Macros.end() && "Identifier macro info is missing!");<br>
>>>> + assert(Pos->second->getUndefLoc().isInvalid() && "Macro is<br>
>>>> undefined!");<br>
>>>> + return Pos->second;<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// setMacroInfo - Specify a macro for this identifier.<br>
>>>> +///<br>
>>>> +void Preprocessor::setMacroInfo(IdentifierInfo *II, MacroInfo *MI,<br>
>>>> + bool LoadedFromAST) {<br>
>>>> + assert(MI && "MacroInfo should be non-zero!");<br>
>>>> + MI->setPreviousDefinition(Macros[II]);<br>
>>>> + Macros[II] = MI;<br>
>>>> + II->setHasMacroDefinition(true);<br>
>>>> + if (II->isFromAST() && !LoadedFromAST)<br>
>>>> + II->setChangedSinceDeserialization();<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// \brief Undefine a macro for this identifier.<br>
>>>> +void Preprocessor::clearMacroInfo(IdentifierInfo *II) {<br>
>>>> + assert(II->hasMacroDefinition() && "Macro is not defined!");<br>
>>>> + assert(Macros[II]->getUndefLoc().isValid() && "Macro is still<br>
>>>> defined!");<br>
>>>> + II->setHasMacroDefinition(false);<br>
>>>> + if (II->isFromAST())<br>
>>>> + II->setChangedSinceDeserialization();<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// RegisterBuiltinMacro - Register the specified identifier in the<br>
>>>> identifier<br>
>>>> +/// table and mark it as a builtin macro to be expanded.<br>
>>>> +static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char<br>
>>>> *Name){<br>
>>>> + // Get the identifier.<br>
>>>> + IdentifierInfo *Id = PP.getIdentifierInfo(Name);<br>
>>>> +<br>
>>>> + // Mark it as being a macro that is builtin.<br>
>>>> + MacroInfo *MI = PP.AllocateMacroInfo(SourceLocation());<br>
>>>> + MI->setIsBuiltinMacro();<br>
>>>> + PP.setMacroInfo(Id, MI);<br>
>>>> + return Id;<br>
>>>> +}<br>
>>>> +<br>
>>>> +<br>
>>>> +/// RegisterBuiltinMacros - Register builtin macros, such as __LINE__<br>
>>>> with the<br>
>>>> +/// identifier table.<br>
>>>> +void Preprocessor::RegisterBuiltinMacros() {<br>
>>>> + Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");<br>
>>>> + Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");<br>
>>>> + Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");<br>
>>>> + Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");<br>
>>>> + Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");<br>
>>>> + Ident_Pragma = RegisterBuiltinMacro(*this, "_Pragma");<br>
>>>> +<br>
>>>> + // GCC Extensions.<br>
>>>> + Ident__BASE_FILE__ = RegisterBuiltinMacro(*this, "__BASE_FILE__");<br>
>>>> + Ident__INCLUDE_LEVEL__ = RegisterBuiltinMacro(*this,<br>
>>>> "__INCLUDE_LEVEL__");<br>
>>>> + Ident__TIMESTAMP__ = RegisterBuiltinMacro(*this, "__TIMESTAMP__");<br>
>>>> +<br>
>>>> + // Clang Extensions.<br>
>>>> + Ident__has_feature = RegisterBuiltinMacro(*this,<br>
>>>> "__has_feature");<br>
>>>> + Ident__has_extension = RegisterBuiltinMacro(*this,<br>
>>>> "__has_extension");<br>
>>>> + Ident__has_builtin = RegisterBuiltinMacro(*this,<br>
>>>> "__has_builtin");<br>
>>>> + Ident__has_attribute = RegisterBuiltinMacro(*this,<br>
>>>> "__has_attribute");<br>
>>>> + Ident__has_include = RegisterBuiltinMacro(*this,<br>
>>>> "__has_include");<br>
>>>> + Ident__has_include_next = RegisterBuiltinMacro(*this,<br>
>>>> "__has_include_next");<br>
>>>> + Ident__has_warning = RegisterBuiltinMacro(*this,<br>
>>>> "__has_warning");<br>
>>>> +<br>
>>>> + // Microsoft Extensions.<br>
>>>> + if (LangOpts.MicrosoftExt)<br>
>>>> + Ident__pragma = RegisterBuiltinMacro(*this, "__pragma");<br>
>>>> + else<br>
>>>> + Ident__pragma = 0;<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// isTrivialSingleTokenExpansion - Return true if MI, which has a<br>
>>>> single token<br>
>>>> +/// in its expansion, currently expands to that token literally.<br>
>>>> +static bool isTrivialSingleTokenExpansion(const MacroInfo *MI,<br>
>>>> + const IdentifierInfo<br>
>>>> *MacroIdent,<br>
>>>> + Preprocessor &PP) {<br>
>>>> + IdentifierInfo *II = MI->getReplacementToken(0).getIdentifierInfo();<br>
>>>> +<br>
>>>> + // If the token isn't an identifier, it's always literally expanded.<br>
>>>> + if (II == 0) return true;<br>
>>>> +<br>
>>>> + // If the information about this identifier is out of date, update it<br>
>>>> from<br>
>>>> + // the external source.<br>
>>>> + if (II->isOutOfDate())<br>
>>>> + PP.getExternalSource()->updateOutOfDateIdentifier(*II);<br>
>>>> +<br>
>>>> + // If the identifier is a macro, and if that macro is enabled, it may<br>
>>>> be<br>
>>>> + // expanded so it's not a trivial expansion.<br>
>>>> + if (II->hasMacroDefinition() && PP.getMacroInfo(II)->isEnabled() &&<br>
>>>> + // Fast expanding "#define X X" is ok, because X would be<br>
>>>> disabled.<br>
>>>> + II != MacroIdent)<br>
>>>> + return false;<br>
>>>> +<br>
>>>> + // If this is an object-like macro invocation, it is safe to trivially<br>
>>>> expand<br>
>>>> + // it.<br>
>>>> + if (MI->isObjectLike()) return true;<br>
>>>> +<br>
>>>> + // If this is a function-like macro invocation, it's safe to trivially<br>
>>>> expand<br>
>>>> + // as long as the identifier is not a macro argument.<br>
>>>> + for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end();<br>
>>>> + I != E; ++I)<br>
>>>> + if (*I == II)<br>
>>>> + return false; // Identifier is a macro argument.<br>
>>>> +<br>
>>>> + return true;<br>
>>>> +}<br>
>>>> +<br>
>>>> +<br>
>>>> +/// isNextPPTokenLParen - Determine whether the next preprocessor token<br>
>>>> to be<br>
>>>> +/// lexed is a '('. If so, consume the token and return true, if not,<br>
>>>> this<br>
>>>> +/// method should have no observable side-effect on the lexed tokens.<br>
>>>> +bool Preprocessor::isNextPPTokenLParen() {<br>
>>>> + // Do some quick tests for rejection cases.<br>
>>>> + unsigned Val;<br>
>>>> + if (CurLexer)<br>
>>>> + Val = CurLexer->isNextPPTokenLParen();<br>
>>>> + else if (CurPTHLexer)<br>
>>>> + Val = CurPTHLexer->isNextPPTokenLParen();<br>
>>>> + else<br>
>>>> + Val = CurTokenLexer->isNextTokenLParen();<br>
>>>> +<br>
>>>> + if (Val == 2) {<br>
>>>> + // We have run off the end. If it's a source file we don't<br>
>>>> + // examine enclosing ones (C99 5.1.1.2p4). Otherwise walk up the<br>
>>>> + // macro stack.<br>
>>>> + if (CurPPLexer)<br>
>>>> + return false;<br>
>>>> + for (unsigned i = IncludeMacroStack.size(); i != 0; --i) {<br>
>>>> + IncludeStackInfo &Entry = IncludeMacroStack[i-1];<br>
>>>> + if (Entry.TheLexer)<br>
>>>> + Val = Entry.TheLexer->isNextPPTokenLParen();<br>
>>>> + else if (Entry.ThePTHLexer)<br>
>>>> + Val = Entry.ThePTHLexer->isNextPPTokenLParen();<br>
>>>> + else<br>
>>>> + Val = Entry.TheTokenLexer->isNextTokenLParen();<br>
>>>> +<br>
>>>> + if (Val != 2)<br>
>>>> + break;<br>
>>>> +<br>
>>>> + // Ran off the end of a source file?<br>
>>>> + if (Entry.ThePPLexer)<br>
>>>> + return false;<br>
>>>> + }<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Okay, if we know that the token is a '(', lex it and return.<br>
>>>> Otherwise we<br>
>>>> + // have found something that isn't a '(' or we found the end of the<br>
>>>> + // translation unit. In either case, return false.<br>
>>>> + return Val == 1;<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// HandleMacroExpandedIdentifier - If an identifier token is read that<br>
>>>> is to be<br>
>>>> +/// expanded as a macro, handle it and return the next token as<br>
>>>> 'Identifier'.<br>
>>>> +bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,<br>
>>>> + MacroInfo *MI) {<br>
>>>> + // If this is a macro expansion in the "#if !defined(x)" line for the<br>
>>>> file,<br>
>>>> + // then the macro could expand to different things in other contexts,<br>
>>>> we need<br>
>>>> + // to disable the optimization in this case.<br>
>>>> + if (CurPPLexer) CurPPLexer->MIOpt.ExpandedMacro();<br>
>>>> +<br>
>>>> + // If this is a builtin macro, like __LINE__ or _Pragma, handle it<br>
>>>> specially.<br>
>>>> + if (MI->isBuiltinMacro()) {<br>
>>>> + if (Callbacks) Callbacks->MacroExpands(Identifier, MI,<br>
>>>> + Identifier.getLocation());<br>
>>>> + ExpandBuiltinMacro(Identifier);<br>
>>>> + return false;<br>
>>>> + }<br>
>>>> +<br>
>>>> + /// Args - If this is a function-like macro expansion, this contains,<br>
>>>> + /// for each macro argument, the list of tokens that were provided to<br>
>>>> the<br>
>>>> + /// invocation.<br>
>>>> + MacroArgs *Args = 0;<br>
>>>> +<br>
>>>> + // Remember where the end of the expansion occurred. For an<br>
>>>> object-like<br>
>>>> + // macro, this is the identifier. For a function-like macro, this is<br>
>>>> the ')'.<br>
>>>> + SourceLocation ExpansionEnd = Identifier.getLocation();<br>
>>>> +<br>
>>>> + // If this is a function-like macro, read the arguments.<br>
>>>> + if (MI->isFunctionLike()) {<br>
>>>> + // C99 6.10.3p10: If the preprocessing token immediately after the<br>
>>>> macro<br>
>>>> + // name isn't a '(', this macro should not be expanded.<br>
>>>> + if (!isNextPPTokenLParen())<br>
>>>> + return true;<br>
>>>> +<br>
>>>> + // Remember that we are now parsing the arguments to a macro<br>
>>>> invocation.<br>
>>>> + // Preprocessor directives used inside macro arguments are not<br>
>>>> portable, and<br>
>>>> + // this enables the warning.<br>
>>>> + InMacroArgs = true;<br>
>>>> + Args = ReadFunctionLikeMacroArgs(Identifier, MI, ExpansionEnd);<br>
>>>> +<br>
>>>> + // Finished parsing args.<br>
>>>> + InMacroArgs = false;<br>
>>>> +<br>
>>>> + // If there was an error parsing the arguments, bail out.<br>
>>>> + if (Args == 0) return false;<br>
>>>> +<br>
>>>> + ++NumFnMacroExpanded;<br>
>>>> + } else {<br>
>>>> + ++NumMacroExpanded;<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Notice that this macro has been used.<br>
>>>> + markMacroAsUsed(MI);<br>
>>>> +<br>
>>>> + // Remember where the token is expanded.<br>
>>>> + SourceLocation ExpandLoc = Identifier.getLocation();<br>
>>>> + SourceRange ExpansionRange(ExpandLoc, ExpansionEnd);<br>
>>>> +<br>
>>>> + if (Callbacks) {<br>
>>>> + if (InMacroArgs) {<br>
>>>> + // We can have macro expansion inside a conditional directive<br>
>>>> while<br>
>>>> + // reading the function macro arguments. To ensure, in that case,<br>
>>>> that<br>
>>>> + // MacroExpands callbacks still happen in source order, queue this<br>
>>>> + // callback to have it happen after the function macro callback.<br>
>>>> + DelayedMacroExpandsCallbacks.push_back(<br>
>>>> + MacroExpandsInfo(Identifier, MI,<br>
>>>> ExpansionRange));<br>
>>>> + } else {<br>
>>>> + Callbacks->MacroExpands(Identifier, MI, ExpansionRange);<br>
>>>> + if (!DelayedMacroExpandsCallbacks.empty()) {<br>
>>>> + for (unsigned i=0, e = DelayedMacroExpandsCallbacks.size();<br>
>>>> i!=e; ++i) {<br>
>>>> + MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i];<br>
>>>> + Callbacks->MacroExpands(Info.Tok, Info.MI, Info.Range);<br>
>>>> + }<br>
>>>> + DelayedMacroExpandsCallbacks.clear();<br>
>>>> + }<br>
>>>> + }<br>
>>>> + }<br>
>>>> +<br>
>>>> + // If we started lexing a macro, enter the macro expansion body.<br>
>>>> +<br>
>>>> + // If this macro expands to no tokens, don't bother to push it onto<br>
>>>> the<br>
>>>> + // expansion stack, only to take it right back off.<br>
>>>> + if (MI->getNumTokens() == 0) {<br>
>>>> + // No need for arg info.<br>
>>>> + if (Args) Args->destroy(*this);<br>
>>>> +<br>
>>>> + // Ignore this macro use, just return the next token in the current<br>
>>>> + // buffer.<br>
>>>> + bool HadLeadingSpace = Identifier.hasLeadingSpace();<br>
>>>> + bool IsAtStartOfLine = Identifier.isAtStartOfLine();<br>
>>>> +<br>
>>>> + Lex(Identifier);<br>
>>>> +<br>
>>>> + // If the identifier isn't on some OTHER line, inherit the leading<br>
>>>> + // whitespace/first-on-a-line property of this token. This handles<br>
>>>> + // stuff like "! XX," -> "! ," and " XX," -> " ,", when XX is<br>
>>>> + // empty.<br>
>>>> + if (!Identifier.isAtStartOfLine()) {<br>
>>>> + if (IsAtStartOfLine) Identifier.setFlag(Token::StartOfLine);<br>
>>>> + if (HadLeadingSpace) Identifier.setFlag(Token::LeadingSpace);<br>
>>>> + }<br>
>>>> + Identifier.setFlag(Token::LeadingEmptyMacro);<br>
>>>> + ++NumFastMacroExpanded;<br>
>>>> + return false;<br>
>>>> +<br>
>>>> + } else if (MI->getNumTokens() == 1 &&<br>
>>>> + isTrivialSingleTokenExpansion(MI,<br>
>>>> Identifier.getIdentifierInfo(),<br>
>>>> + *this)) {<br>
>>>> + // Otherwise, if this macro expands into a single trivially-expanded<br>
>>>> + // token: expand it now. This handles common cases like<br>
>>>> + // "#define VAL 42".<br>
>>>> +<br>
>>>> + // No need for arg info.<br>
>>>> + if (Args) Args->destroy(*this);<br>
>>>> +<br>
>>>> + // Propagate the isAtStartOfLine/hasLeadingSpace markers of the<br>
>>>> macro<br>
>>>> + // identifier to the expanded token.<br>
>>>> + bool isAtStartOfLine = Identifier.isAtStartOfLine();<br>
>>>> + bool hasLeadingSpace = Identifier.hasLeadingSpace();<br>
>>>> +<br>
>>>> + // Replace the result token.<br>
>>>> + Identifier = MI->getReplacementToken(0);<br>
>>>> +<br>
>>>> + // Restore the StartOfLine/LeadingSpace markers.<br>
>>>> + Identifier.setFlagValue(Token::StartOfLine , isAtStartOfLine);<br>
>>>> + Identifier.setFlagValue(Token::LeadingSpace, hasLeadingSpace);<br>
>>>> +<br>
>>>> + // Update the tokens location to include both its expansion and<br>
>>>> physical<br>
>>>> + // locations.<br>
>>>> + SourceLocation Loc =<br>
>>>> + SourceMgr.createExpansionLoc(Identifier.getLocation(), ExpandLoc,<br>
>>>> + ExpansionEnd,Identifier.getLength());<br>
>>>> + Identifier.setLocation(Loc);<br>
>>>> +<br>
>>>> + // If this is a disabled macro or #define X X, we must mark the<br>
>>>> result as<br>
>>>> + // unexpandable.<br>
>>>> + if (IdentifierInfo *NewII = Identifier.getIdentifierInfo()) {<br>
>>>> + if (MacroInfo *NewMI = getMacroInfo(NewII))<br>
>>>> + if (!NewMI->isEnabled() || NewMI == MI) {<br>
>>>> + Identifier.setFlag(Token::DisableExpand);<br>
>>>> + Diag(Identifier, diag::pp_disabled_macro_expansion);<br>
>>>> + }<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Since this is not an identifier token, it can't be macro<br>
>>>> expanded, so<br>
>>>> + // we're done.<br>
>>>> + ++NumFastMacroExpanded;<br>
>>>> + return false;<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Start expanding the macro.<br>
>>>> + EnterMacro(Identifier, ExpansionEnd, MI, Args);<br>
>>>> +<br>
>>>> + // Now that the macro is at the top of the include stack, ask the<br>
>>>> + // preprocessor to read the next token from it.<br>
>>>> + Lex(Identifier);<br>
>>>> + return false;<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// ReadFunctionLikeMacroArgs - After reading "MACRO" and knowing that<br>
>>>> the next<br>
>>>> +/// token is the '(' of the macro, this method is invoked to read all of<br>
>>>> the<br>
>>>> +/// actual arguments specified for the macro invocation. This returns<br>
>>>> null on<br>
>>>> +/// error.<br>
>>>> +MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,<br>
>>>> + MacroInfo *MI,<br>
>>>> + SourceLocation<br>
>>>> &MacroEnd) {<br>
>>>> + // The number of fixed arguments to parse.<br>
>>>> + unsigned NumFixedArgsLeft = MI->getNumArgs();<br>
>>>> + bool isVariadic = MI->isVariadic();<br>
>>>> +<br>
>>>> + // Outer loop, while there are more arguments, keep reading them.<br>
>>>> + Token Tok;<br>
>>>> +<br>
>>>> + // Read arguments as unexpanded tokens. This avoids issues, e.g.,<br>
>>>> where<br>
>>>> + // an argument value in a macro could expand to ',' or '(' or ')'.<br>
>>>> + LexUnexpandedToken(Tok);<br>
>>>> + assert(Tok.is(tok::l_paren) && "Error computing l-paren-ness?");<br>
>>>> +<br>
>>>> + // ArgTokens - Build up a list of tokens that make up each argument.<br>
>>>> Each<br>
>>>> + // argument is separated by an EOF token. Use a SmallVector so we can<br>
>>>> avoid<br>
>>>> + // heap allocations in the common case.<br>
>>>> + SmallVector<Token, 64> ArgTokens;<br>
>>>> +<br>
>>>> + unsigned NumActuals = 0;<br>
>>>> + while (Tok.isNot(tok::r_paren)) {<br>
>>>> + assert((Tok.is(tok::l_paren) || Tok.is(tok::comma)) &&<br>
>>>> + "only expect argument separators here");<br>
>>>> +<br>
>>>> + unsigned ArgTokenStart = ArgTokens.size();<br>
>>>> + SourceLocation ArgStartLoc = Tok.getLocation();<br>
>>>> +<br>
>>>> + // C99 6.10.3p11: Keep track of the number of l_parens we have seen.<br>
>>>> Note<br>
>>>> + // that we already consumed the first one.<br>
>>>> + unsigned NumParens = 0;<br>
>>>> +<br>
>>>> + while (1) {<br>
>>>> + // Read arguments as unexpanded tokens. This avoids issues, e.g.,<br>
>>>> where<br>
>>>> + // an argument value in a macro could expand to ',' or '(' or ')'.<br>
>>>> + LexUnexpandedToken(Tok);<br>
>>>> +<br>
>>>> + if (Tok.is(tok::eof) || Tok.is(tok::eod)) { // "#if f(<eof>" &<br>
>>>> "#if f(\n"<br>
>>>> + Diag(MacroName, diag::err_unterm_macro_invoc);<br>
>>>> + // Do not lose the EOF/EOD. Return it to the client.<br>
>>>> + MacroName = Tok;<br>
>>>> + return 0;<br>
>>>> + } else if (Tok.is(tok::r_paren)) {<br>
>>>> + // If we found the ) token, the macro arg list is done.<br>
>>>> + if (NumParens-- == 0) {<br>
>>>> + MacroEnd = Tok.getLocation();<br>
>>>> + break;<br>
>>>> + }<br>
>>>> + } else if (Tok.is(tok::l_paren)) {<br>
>>>> + ++NumParens;<br>
>>>> + // In Microsoft-compatibility mode, commas from nested macro<br>
>>>> expan-<br>
>>>> + // sions should not be considered as argument separators. We test<br>
>>>> + // for this with the IgnoredComma token flag.<br>
>>>> + } else if (Tok.is(tok::comma)<br>
>>>> + && !(Tok.getFlags() & Token::IgnoredComma) && NumParens == 0)<br>
>>>> {<br>
>>>> + // Comma ends this argument if there are more fixed arguments<br>
>>>> expected.<br>
>>>> + // However, if this is a variadic macro, and this is part of the<br>
>>>> + // variadic part, then the comma is just an argument token.<br>
>>>> + if (!isVariadic) break;<br>
>>>> + if (NumFixedArgsLeft > 1)<br>
>>>> + break;<br>
>>>> + } else if (Tok.is(tok::comment) && !KeepMacroComments) {<br>
>>>> + // If this is a comment token in the argument list and we're<br>
>>>> just in<br>
>>>> + // -C mode (not -CC mode), discard the comment.<br>
>>>> + continue;<br>
>>>> + } else if (Tok.getIdentifierInfo() != 0) {<br>
>>>> + // Reading macro arguments can cause macros that we are<br>
>>>> currently<br>
>>>> + // expanding from to be popped off the expansion stack. Doing<br>
>>>> so causes<br>
>>>> + // them to be reenabled for expansion. Here we record whether<br>
>>>> any<br>
>>>> + // identifiers we lex as macro arguments correspond to disabled<br>
>>>> macros.<br>
>>>> + // If so, we mark the token as noexpand. This is a subtle<br>
>>>> aspect of<br>
>>>> + // C99 6.10.3.4p2.<br>
>>>> + if (MacroInfo *MI = getMacroInfo(Tok.getIdentifierInfo()))<br>
>>>> + if (!MI->isEnabled())<br>
>>>> + Tok.setFlag(Token::DisableExpand);<br>
>>>> + } else if (Tok.is(tok::code_completion)) {<br>
>>>> + if (CodeComplete)<br>
>>>> +<br>
>>>> CodeComplete->CodeCompleteMacroArgument(MacroName.getIdentifierInfo(),<br>
>>>> + MI, NumActuals);<br>
>>>> + // Don't mark that we reached the code-completion point because<br>
>>>> the<br>
>>>> + // parser is going to handle the token and there will be another<br>
>>>> + // code-completion callback.<br>
>>>> + }<br>
>>>> +<br>
>>>> + ArgTokens.push_back(Tok);<br>
>>>> + }<br>
>>>> +<br>
>>>> + // If this was an empty argument list foo(), don't add this as an<br>
>>>> empty<br>
>>>> + // argument.<br>
>>>> + if (ArgTokens.empty() && Tok.getKind() == tok::r_paren)<br>
>>>> + break;<br>
>>>> +<br>
>>>> + // If this is not a variadic macro, and too many args were<br>
>>>> specified, emit<br>
>>>> + // an error.<br>
>>>> + if (!isVariadic && NumFixedArgsLeft == 0) {<br>
>>>> + if (ArgTokens.size() != ArgTokenStart)<br>
>>>> + ArgStartLoc = ArgTokens[ArgTokenStart].getLocation();<br>
>>>> +<br>
>>>> + // Emit the diagnostic at the macro name in case there is a<br>
>>>> missing ).<br>
>>>> + // Emitting it at the , could be far away from the macro name.<br>
>>>> + Diag(ArgStartLoc, diag::err_too_many_args_in_macro_invoc);<br>
>>>> + return 0;<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Empty arguments are standard in C99 and C++0x, and are supported<br>
>>>> as an extension in<br>
>>>> + // other modes.<br>
>>>> + if (ArgTokens.size() == ArgTokenStart && !LangOpts.C99)<br>
>>>> + Diag(Tok, LangOpts.CPlusPlus0x ?<br>
>>>> + diag::warn_cxx98_compat_empty_fnmacro_arg :<br>
>>>> + diag::ext_empty_fnmacro_arg);<br>
>>>> +<br>
>>>> + // Add a marker EOF token to the end of the token list for this<br>
>>>> argument.<br>
>>>> + Token EOFTok;<br>
>>>> + EOFTok.startToken();<br>
>>>> + EOFTok.setKind(tok::eof);<br>
>>>> + EOFTok.setLocation(Tok.getLocation());<br>
>>>> + EOFTok.setLength(0);<br>
>>>> + ArgTokens.push_back(EOFTok);<br>
>>>> + ++NumActuals;<br>
>>>> + assert(NumFixedArgsLeft != 0 && "Too many arguments parsed");<br>
>>>> + --NumFixedArgsLeft;<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Okay, we either found the r_paren. Check to see if we parsed too<br>
>>>> few<br>
>>>> + // arguments.<br>
>>>> + unsigned MinArgsExpected = MI->getNumArgs();<br>
>>>> +<br>
>>>> + // See MacroArgs instance var for description of this.<br>
>>>> + bool isVarargsElided = false;<br>
>>>> +<br>
>>>> + if (NumActuals < MinArgsExpected) {<br>
>>>> + // There are several cases where too few arguments is ok, handle<br>
>>>> them now.<br>
>>>> + if (NumActuals == 0 && MinArgsExpected == 1) {<br>
>>>> + // #define A(X) or #define A(...) ---> A()<br>
>>>> +<br>
>>>> + // If there is exactly one argument, and that argument is missing,<br>
>>>> + // then we have an empty "()" argument empty list. This is fine,<br>
>>>> even if<br>
>>>> + // the macro expects one argument (the argument is just empty).<br>
>>>> + isVarargsElided = MI->isVariadic();<br>
>>>> + } else if (MI->isVariadic() &&<br>
>>>> + (NumActuals+1 == MinArgsExpected || // A(x, ...) -> A(X)<br>
>>>> + (NumActuals == 0 && MinArgsExpected == 2))) {// A(x,...)<br>
>>>> -> A()<br>
>>>> + // Varargs where the named vararg parameter is missing: OK as<br>
>>>> extension.<br>
>>>> + // #define A(x, ...)<br>
>>>> + // A("blah")<br>
>>>> + Diag(Tok, diag::ext_missing_varargs_arg);<br>
>>>> + Diag(MI->getDefinitionLoc(), diag::note_macro_here)<br>
>>>> + << MacroName.getIdentifierInfo();<br>
>>>> +<br>
>>>> + // Remember this occurred, allowing us to elide the comma when<br>
>>>> used for<br>
>>>> + // cases like:<br>
>>>> + // #define A(x, foo...) blah(a, ## foo)<br>
>>>> + // #define B(x, ...) blah(a, ## __VA_ARGS__)<br>
>>>> + // #define C(...) blah(a, ## __VA_ARGS__)<br>
>>>> + // A(x) B(x) C()<br>
>>>> + isVarargsElided = true;<br>
>>>> + } else {<br>
>>>> + // Otherwise, emit the error.<br>
>>>> + Diag(Tok, diag::err_too_few_args_in_macro_invoc);<br>
>>>> + return 0;<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Add a marker EOF token to the end of the token list for this<br>
>>>> argument.<br>
>>>> + SourceLocation EndLoc = Tok.getLocation();<br>
>>>> + Tok.startToken();<br>
>>>> + Tok.setKind(tok::eof);<br>
>>>> + Tok.setLocation(EndLoc);<br>
>>>> + Tok.setLength(0);<br>
>>>> + ArgTokens.push_back(Tok);<br>
>>>> +<br>
>>>> + // If we expect two arguments, add both as empty.<br>
>>>> + if (NumActuals == 0 && MinArgsExpected == 2)<br>
>>>> + ArgTokens.push_back(Tok);<br>
>>>> +<br>
>>>> + } else if (NumActuals > MinArgsExpected && !MI->isVariadic()) {<br>
>>>> + // Emit the diagnostic at the macro name in case there is a missing<br>
>>>> ).<br>
>>>> + // Emitting it at the , could be far away from the macro name.<br>
>>>> + Diag(MacroName, diag::err_too_many_args_in_macro_invoc);<br>
>>>> + return 0;<br>
>>>> + }<br>
>>>> +<br>
>>>> + return MacroArgs::create(MI, ArgTokens, isVarargsElided, *this);<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// \brief Keeps macro expanded tokens for TokenLexers.<br>
>>>> +//<br>
>>>> +/// Works like a stack; a TokenLexer adds the macro expanded tokens that<br>
>>>> is<br>
>>>> +/// going to lex in the cache and when it finishes the tokens are<br>
>>>> removed<br>
>>>> +/// from the end of the cache.<br>
>>>> +Token *Preprocessor::cacheMacroExpandedTokens(TokenLexer *tokLexer,<br>
>>>> + ArrayRef<Token> tokens) {<br>
>>>> + assert(tokLexer);<br>
>>>> + if (tokens.empty())<br>
>>>> + return 0;<br>
>>>> +<br>
>>>> + size_t newIndex = MacroExpandedTokens.size();<br>
>>>> + bool cacheNeedsToGrow = tokens.size() ><br>
>>>> +<br>
>>>> MacroExpandedTokens.capacity()-MacroExpandedTokens.size();<br>
>>>> + MacroExpandedTokens.append(tokens.begin(), tokens.end());<br>
>>>> +<br>
>>>> + if (cacheNeedsToGrow) {<br>
>>>> + // Go through all the TokenLexers whose 'Tokens' pointer points in<br>
>>>> the<br>
>>>> + // buffer and update the pointers to the (potential) new buffer<br>
>>>> array.<br>
>>>> + for (unsigned i = 0, e = MacroExpandingLexersStack.size(); i != e;<br>
>>>> ++i) {<br>
>>>> + TokenLexer *prevLexer;<br>
>>>> + size_t tokIndex;<br>
>>>> + llvm::tie(prevLexer, tokIndex) = MacroExpandingLexersStack[i];<br>
>>>> + prevLexer->Tokens = MacroExpandedTokens.data() + tokIndex;<br>
>>>> + }<br>
>>>> + }<br>
>>>> +<br>
>>>> + MacroExpandingLexersStack.push_back(std::make_pair(tokLexer,<br>
>>>> newIndex));<br>
>>>> + return MacroExpandedTokens.data() + newIndex;<br>
>>>> +}<br>
>>>> +<br>
>>>> +void Preprocessor::removeCachedMacroExpandedTokensOfLastLexer() {<br>
>>>> + assert(!MacroExpandingLexersStack.empty());<br>
>>>> + size_t tokIndex = MacroExpandingLexersStack.back().second;<br>
>>>> + assert(tokIndex < MacroExpandedTokens.size());<br>
>>>> + // Pop the cached macro expanded tokens from the end.<br>
>>>> + MacroExpandedTokens.resize(tokIndex);<br>
>>>> + MacroExpandingLexersStack.pop_back();<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// ComputeDATE_TIME - Compute the current time, enter it into the<br>
>>>> specified<br>
>>>> +/// scratch buffer, then return DATELoc/TIMELoc locations with the<br>
>>>> position of<br>
>>>> +/// the identifier tokens inserted.<br>
>>>> +static void ComputeDATE_TIME(SourceLocation &DATELoc, SourceLocation<br>
>>>> &TIMELoc,<br>
>>>> + Preprocessor &PP) {<br>
>>>> + time_t TT = time(0);<br>
>>>> + struct tm *TM = localtime(&TT);<br>
>>>> +<br>
>>>> + static const char * const Months[] = {<br>
>>>> +<br>
>>>> "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"<br>
>>>> + };<br>
>>>> +<br>
>>>> + char TmpBuffer[32];<br>
>>>> +#ifdef LLVM_ON_WIN32<br>
>>>> + sprintf(TmpBuffer, "\"%s %2d %4d\"", Months[TM->tm_mon], TM->tm_mday,<br>
>>>> + TM->tm_year+1900);<br>
>>>> +#else<br>
>>>> + snprintf(TmpBuffer, sizeof(TmpBuffer), "\"%s %2d %4d\"",<br>
>>>> Months[TM->tm_mon], TM->tm_mday,<br>
>>>> + TM->tm_year+1900);<br>
>>>> +#endif<br>
>>>> +<br>
>>>> + Token TmpTok;<br>
>>>> + TmpTok.startToken();<br>
>>>> + PP.CreateString(TmpBuffer, strlen(TmpBuffer), TmpTok);<br>
>>>> + DATELoc = TmpTok.getLocation();<br>
>>>> +<br>
>>>> +#ifdef LLVM_ON_WIN32<br>
>>>> + sprintf(TmpBuffer, "\"%02d:%02d:%02d\"", TM->tm_hour, TM->tm_min,<br>
>>>> TM->tm_sec);<br>
>>>> +#else<br>
>>>> + snprintf(TmpBuffer, sizeof(TmpBuffer), "\"%02d:%02d:%02d\"",<br>
>>>> TM->tm_hour, TM->tm_min, TM->tm_sec);<br>
>>>> +#endif<br>
>>>> + PP.CreateString(TmpBuffer, strlen(TmpBuffer), TmpTok);<br>
>>>> + TIMELoc = TmpTok.getLocation();<br>
>>>> +}<br>
>>>> +<br>
>>>> +<br>
>>>> +/// HasFeature - Return true if we recognize and implement the feature<br>
>>>> +/// specified by the identifier as a standard language feature.<br>
>>>> +static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II)<br>
>>>> {<br>
>>>> + const LangOptions &LangOpts = PP.getLangOpts();<br>
>>>> + StringRef Feature = II->getName();<br>
>>>> +<br>
>>>> + // Normalize the feature name, __foo__ becomes foo.<br>
>>>> + if (Feature.startswith("__") && Feature.endswith("__") &&<br>
>>>> Feature.size() >= 4)<br>
>>>> + Feature = Feature.substr(2, Feature.size() - 4);<br>
>>>> +<br>
>>>> + return llvm::StringSwitch<bool>(Feature)<br>
>>>> + .Case("address_sanitizer", LangOpts.AddressSanitizer)<br>
>>>> + .Case("attribute_analyzer_noreturn", true)<br>
>>>> + .Case("attribute_availability", true)<br>
>>>> + .Case("attribute_availability_with_message", true)<br>
>>>> + .Case("attribute_cf_returns_not_retained", true)<br>
>>>> + .Case("attribute_cf_returns_retained", true)<br>
>>>> + .Case("attribute_deprecated_with_message", true)<br>
>>>> + .Case("attribute_ext_vector_type", true)<br>
>>>> + .Case("attribute_ns_returns_not_retained", true)<br>
>>>> + .Case("attribute_ns_returns_retained", true)<br>
>>>> + .Case("attribute_ns_consumes_self", true)<br>
>>>> + .Case("attribute_ns_consumed", true)<br>
>>>> + .Case("attribute_cf_consumed", true)<br>
>>>> + .Case("attribute_objc_ivar_unused", true)<br>
>>>> + .Case("attribute_objc_method_family", true)<br>
>>>> + .Case("attribute_overloadable", true)<br>
>>>> + .Case("attribute_unavailable_with_message", true)<br>
>>>> + .Case("attribute_unused_on_fields", true)<br>
>>>> + .Case("blocks", LangOpts.Blocks)<br>
>>>> + .Case("cxx_exceptions", LangOpts.Exceptions)<br>
>>>> + .Case("cxx_rtti", LangOpts.RTTI)<br>
>>>> + .Case("enumerator_attributes", true)<br>
>>>> + // Objective-C features<br>
>>>> + .Case("objc_arr", LangOpts.ObjCAutoRefCount) // FIXME:<br>
>>>> REMOVE?<br>
>>>> + .Case("objc_arc", LangOpts.ObjCAutoRefCount)<br>
>>>> + .Case("objc_arc_weak", LangOpts.ObjCARCWeak)<br>
>>>> + .Case("objc_default_synthesize_properties", LangOpts.ObjC2)<br>
>>>> + .Case("objc_fixed_enum", LangOpts.ObjC2)<br>
>>>> + .Case("objc_instancetype", LangOpts.ObjC2)<br>
>>>> + .Case("objc_modules", LangOpts.ObjC2 && LangOpts.Modules)<br>
>>>> + .Case("objc_nonfragile_abi",<br>
>>>> LangOpts.ObjCRuntime.isNonFragile())<br>
>>>> + .Case("objc_weak_class",<br>
>>>> LangOpts.ObjCRuntime.hasWeakClassImport())<br>
>>>> + .Case("ownership_holds", true)<br>
>>>> + .Case("ownership_returns", true)<br>
>>>> + .Case("ownership_takes", true)<br>
>>>> + .Case("objc_bool", true)<br>
>>>> + .Case("objc_subscripting",<br>
>>>> LangOpts.ObjCRuntime.isNonFragile())<br>
>>>> + .Case("objc_array_literals", LangOpts.ObjC2)<br>
>>>> + .Case("objc_dictionary_literals", LangOpts.ObjC2)<br>
>>>> + .Case("objc_boxed_expressions", LangOpts.ObjC2)<br>
>>>> + .Case("arc_cf_code_audited", true)<br>
>>>> + // C11 features<br>
>>>> + .Case("c_alignas", LangOpts.C11)<br>
>>>> + .Case("c_atomic", LangOpts.C11)<br>
>>>> + .Case("c_generic_selections", LangOpts.C11)<br>
>>>> + .Case("c_static_assert", LangOpts.C11)<br>
>>>> + // C++11 features<br>
>>>> + .Case("cxx_access_control_sfinae", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_alias_templates", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_alignas", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_atomic", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_attributes", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_auto_type", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_constexpr", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_decltype", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_decltype_incomplete_return_types",<br>
>>>> LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_default_function_template_args",<br>
>>>> LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_defaulted_functions", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_delegating_constructors", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_deleted_functions", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_explicit_conversions", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_generalized_initializers", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_implicit_moves", LangOpts.CPlusPlus0x)<br>
>>>> + //.Case("cxx_inheriting_constructors", false)<br>
>>>> + .Case("cxx_inline_namespaces", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_lambdas", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_local_type_template_args", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_nonstatic_member_init", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_noexcept", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_nullptr", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_override_control", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_range_for", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_raw_string_literals", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_reference_qualified_functions",<br>
>>>> LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_rvalue_references", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_strong_enums", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_static_assert", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_trailing_return", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_unicode_literals", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_unrestricted_unions", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_user_literals", LangOpts.CPlusPlus0x)<br>
>>>> + .Case("cxx_variadic_templates", LangOpts.CPlusPlus0x)<br>
>>>> + // Type traits<br>
>>>> + .Case("has_nothrow_assign", LangOpts.CPlusPlus)<br>
>>>> + .Case("has_nothrow_copy", LangOpts.CPlusPlus)<br>
>>>> + .Case("has_nothrow_constructor", LangOpts.CPlusPlus)<br>
>>>> + .Case("has_trivial_assign", LangOpts.CPlusPlus)<br>
>>>> + .Case("has_trivial_copy", LangOpts.CPlusPlus)<br>
>>>> + .Case("has_trivial_constructor", LangOpts.CPlusPlus)<br>
>>>> + .Case("has_trivial_destructor", LangOpts.CPlusPlus)<br>
>>>> + .Case("has_virtual_destructor", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_abstract", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_base_of", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_class", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_convertible_to", LangOpts.CPlusPlus)<br>
>>>> + // __is_empty is available only if the horrible<br>
>>>> + // "struct __is_empty" parsing hack hasn't been needed in<br>
>>>> this<br>
>>>> + // translation unit. If it has, __is_empty reverts to a<br>
>>>> normal<br>
>>>> + // identifier and __has_feature(is_empty) evaluates false.<br>
>>>> + .Case("is_empty", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_enum", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_final", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_literal", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_standard_layout", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_pod", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_polymorphic", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_trivial", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_trivially_assignable", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_trivially_constructible", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_trivially_copyable", LangOpts.CPlusPlus)<br>
>>>> + .Case("is_union", LangOpts.CPlusPlus)<br>
>>>> + .Case("modules", LangOpts.Modules)<br>
>>>> + .Case("tls", PP.getTargetInfo().isTLSSupported())<br>
>>>> + .Case("underlying_type", LangOpts.CPlusPlus)<br>
>>>> + .Default(false);<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// HasExtension - Return true if we recognize and implement the feature<br>
>>>> +/// specified by the identifier, either as an extension or a standard<br>
>>>> language<br>
>>>> +/// feature.<br>
>>>> +static bool HasExtension(const Preprocessor &PP, const IdentifierInfo<br>
>>>> *II) {<br>
>>>> + if (HasFeature(PP, II))<br>
>>>> + return true;<br>
>>>> +<br>
>>>> + // If the use of an extension results in an error diagnostic,<br>
>>>> extensions are<br>
>>>> + // effectively unavailable, so just return false here.<br>
>>>> + if (PP.getDiagnostics().getExtensionHandlingBehavior() ==<br>
>>>> + DiagnosticsEngine::Ext_Error)<br>
>>>> + return false;<br>
>>>> +<br>
>>>> + const LangOptions &LangOpts = PP.getLangOpts();<br>
>>>> + StringRef Extension = II->getName();<br>
>>>> +<br>
>>>> + // Normalize the extension name, __foo__ becomes foo.<br>
>>>> + if (Extension.startswith("__") && Extension.endswith("__") &&<br>
>>>> + Extension.size() >= 4)<br>
>>>> + Extension = Extension.substr(2, Extension.size() - 4);<br>
>>>> +<br>
>>>> + // Because we inherit the feature list from HasFeature, this string<br>
>>>> switch<br>
>>>> + // must be less restrictive than HasFeature's.<br>
>>>> + return llvm::StringSwitch<bool>(Extension)<br>
>>>> + // C11 features supported by other languages as extensions.<br>
>>>> + .Case("c_alignas", true)<br>
>>>> + .Case("c_atomic", true)<br>
>>>> + .Case("c_generic_selections", true)<br>
>>>> + .Case("c_static_assert", true)<br>
>>>> + // C++0x features supported by other languages as extensions.<br>
>>>> + .Case("cxx_atomic", LangOpts.CPlusPlus)<br>
>>>> + .Case("cxx_deleted_functions", LangOpts.CPlusPlus)<br>
>>>> + .Case("cxx_explicit_conversions", LangOpts.CPlusPlus)<br>
>>>> + .Case("cxx_inline_namespaces", LangOpts.CPlusPlus)<br>
>>>> + .Case("cxx_local_type_template_args", LangOpts.CPlusPlus)<br>
>>>> + .Case("cxx_nonstatic_member_init", LangOpts.CPlusPlus)<br>
>>>> + .Case("cxx_override_control", LangOpts.CPlusPlus)<br>
>>>> + .Case("cxx_range_for", LangOpts.CPlusPlus)<br>
>>>> + .Case("cxx_reference_qualified_functions",<br>
>>>> LangOpts.CPlusPlus)<br>
>>>> + .Case("cxx_rvalue_references", LangOpts.CPlusPlus)<br>
>>>> + .Default(false);<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// HasAttribute - Return true if we recognize and implement the<br>
>>>> attribute<br>
>>>> +/// specified by the given identifier.<br>
>>>> +static bool HasAttribute(const IdentifierInfo *II) {<br>
>>>> + StringRef Name = II->getName();<br>
>>>> + // Normalize the attribute name, __foo__ becomes foo.<br>
>>>> + if (Name.startswith("__") && Name.endswith("__") && Name.size() >= 4)<br>
>>>> + Name = Name.substr(2, Name.size() - 4);<br>
>>>> +<br>
>>>> + // FIXME: Do we need to handle namespaces here?<br>
>>>> + return llvm::StringSwitch<bool>(Name)<br>
>>>> +#include "clang/Lex/AttrSpellings.inc"<br>
>>>> + .Default(false);<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// EvaluateHasIncludeCommon - Process a '__has_include("path")'<br>
>>>> +/// or '__has_include_next("path")' expression.<br>
>>>> +/// Returns true if successful.<br>
>>>> +static bool EvaluateHasIncludeCommon(Token &Tok,<br>
>>>> + IdentifierInfo *II, Preprocessor<br>
>>>> &PP,<br>
>>>> + const DirectoryLookup *LookupFrom)<br>
>>>> {<br>
>>>> + SourceLocation LParenLoc;<br>
>>>> +<br>
>>>> + // Get '('.<br>
>>>> + PP.LexNonComment(Tok);<br>
>>>> +<br>
>>>> + // Ensure we have a '('.<br>
>>>> + if (Tok.isNot(tok::l_paren)) {<br>
>>>> + PP.Diag(Tok.getLocation(), diag::err_pp_missing_lparen) <<<br>
>>>> II->getName();<br>
>>>> + return false;<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Save '(' location for possible missing ')' message.<br>
>>>> + LParenLoc = Tok.getLocation();<br>
>>>> +<br>
>>>> + // Get the file name.<br>
>>>> + PP.getCurrentLexer()->LexIncludeFilename(Tok);<br>
>>>> +<br>
>>>> + // Reserve a buffer to get the spelling.<br>
>>>> + SmallString<128> FilenameBuffer;<br>
>>>> + StringRef Filename;<br>
>>>> + SourceLocation EndLoc;<br>
>>>> +<br>
>>>> + switch (Tok.getKind()) {<br>
>>>> + case tok::eod:<br>
>>>> + // If the token kind is EOD, the error has already been diagnosed.<br>
>>>> + return false;<br>
>>>> +<br>
>>>> + case tok::angle_string_literal:<br>
>>>> + case tok::string_literal: {<br>
>>>> + bool Invalid = false;<br>
>>>> + Filename = PP.getSpelling(Tok, FilenameBuffer, &Invalid);<br>
>>>> + if (Invalid)<br>
>>>> + return false;<br>
>>>> + break;<br>
>>>> + }<br>
>>>> +<br>
>>>> + case tok::less:<br>
>>>> + // This could be a <foo/bar.h> file coming from a macro expansion.<br>
>>>> In this<br>
>>>> + // case, glue the tokens together into FilenameBuffer and interpret<br>
>>>> those.<br>
>>>> + FilenameBuffer.push_back('<');<br>
>>>> + if (PP.ConcatenateIncludeName(FilenameBuffer, EndLoc))<br>
>>>> + return false; // Found <eod> but no ">"? Diagnostic already<br>
>>>> emitted.<br>
>>>> + Filename = FilenameBuffer.str();<br>
>>>> + break;<br>
>>>> + default:<br>
>>>> + PP.Diag(Tok.getLocation(), diag::err_pp_expects_filename);<br>
>>>> + return false;<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Get ')'.<br>
>>>> + PP.LexNonComment(Tok);<br>
>>>> +<br>
>>>> + // Ensure we have a trailing ).<br>
>>>> + if (Tok.isNot(tok::r_paren)) {<br>
>>>> + PP.Diag(Tok.getLocation(), diag::err_pp_missing_rparen) <<<br>
>>>> II->getName();<br>
>>>> + PP.Diag(LParenLoc, diag::note_matching) << "(";<br>
>>>> + return false;<br>
>>>> + }<br>
>>>> +<br>
>>>> + bool isAngled = PP.GetIncludeFilenameSpelling(Tok.getLocation(),<br>
>>>> Filename);<br>
>>>> + // If GetIncludeFilenameSpelling set the start ptr to null, there was<br>
>>>> an<br>
>>>> + // error.<br>
>>>> + if (Filename.empty())<br>
>>>> + return false;<br>
>>>> +<br>
>>>> + // Search include directories.<br>
>>>> + const DirectoryLookup *CurDir;<br>
>>>> + const FileEntry *File =<br>
>>>> + PP.LookupFile(Filename, isAngled, LookupFrom, CurDir, NULL, NULL,<br>
>>>> NULL);<br>
>>>> +<br>
>>>> + // Get the result value. A result of true means the file exists.<br>
>>>> + return File != 0;<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// EvaluateHasInclude - Process a '__has_include("path")' expression.<br>
>>>> +/// Returns true if successful.<br>
>>>> +static bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II,<br>
>>>> + Preprocessor &PP) {<br>
>>>> + return EvaluateHasIncludeCommon(Tok, II, PP, NULL);<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// EvaluateHasIncludeNext - Process '__has_include_next("path")'<br>
>>>> expression.<br>
>>>> +/// Returns true if successful.<br>
>>>> +static bool EvaluateHasIncludeNext(Token &Tok,<br>
>>>> + IdentifierInfo *II, Preprocessor &PP)<br>
>>>> {<br>
>>>> + // __has_include_next is like __has_include, except that we start<br>
>>>> + // searching after the current found directory. If we can't do this,<br>
>>>> + // issue a diagnostic.<br>
>>>> + const DirectoryLookup *Lookup = PP.GetCurDirLookup();<br>
>>>> + if (PP.isInPrimaryFile()) {<br>
>>>> + Lookup = 0;<br>
>>>> + PP.Diag(Tok, diag::pp_include_next_in_primary);<br>
>>>> + } else if (Lookup == 0) {<br>
>>>> + PP.Diag(Tok, diag::pp_include_next_absolute_path);<br>
>>>> + } else {<br>
>>>> + // Start looking up in the next directory.<br>
>>>> + ++Lookup;<br>
>>>> + }<br>
>>>> +<br>
>>>> + return EvaluateHasIncludeCommon(Tok, II, PP, Lookup);<br>
>>>> +}<br>
>>>> +<br>
>>>> +/// ExpandBuiltinMacro - If an identifier token is read that is to be<br>
>>>> expanded<br>
>>>> +/// as a builtin macro, handle it and return the next token as 'Tok'.<br>
>>>> +void Preprocessor::ExpandBuiltinMacro(Token &Tok) {<br>
>>>> + // Figure out which token this is.<br>
>>>> + IdentifierInfo *II = Tok.getIdentifierInfo();<br>
>>>> + assert(II && "Can't be a macro without id info!");<br>
>>>> +<br>
>>>> + // If this is an _Pragma or Microsoft __pragma directive, expand it,<br>
>>>> + // invoke the pragma handler, then lex the token after it.<br>
>>>> + if (II == Ident_Pragma)<br>
>>>> + return Handle_Pragma(Tok);<br>
>>>> + else if (II == Ident__pragma) // in non-MS mode this is null<br>
>>>> + return HandleMicrosoft__pragma(Tok);<br>
>>>> +<br>
>>>> + ++NumBuiltinMacroExpanded;<br>
>>>> +<br>
>>>> + SmallString<128> TmpBuffer;<br>
>>>> + llvm::raw_svector_ostream OS(TmpBuffer);<br>
>>>> +<br>
>>>> + // Set up the return result.<br>
>>>> + Tok.setIdentifierInfo(0);<br>
>>>> + Tok.clearFlag(Token::NeedsCleaning);<br>
>>>> +<br>
>>>> + if (II == Ident__LINE__) {<br>
>>>> + // C99 6.10.8: "__LINE__: The presumed line number (within the<br>
>>>> current<br>
>>>> + // source file) of the current source line (an integer constant)".<br>
>>>> This can<br>
>>>> + // be affected by #line.<br>
>>>> + SourceLocation Loc = Tok.getLocation();<br>
>>>> +<br>
>>>> + // Advance to the location of the first _, this might not be the<br>
>>>> first byte<br>
>>>> + // of the token if it starts with an escaped newline.<br>
>>>> + Loc = AdvanceToTokenCharacter(Loc, 0);<br>
>>>> +<br>
>>>> + // One wrinkle here is that GCC expands __LINE__ to location of the<br>
>>>> *end* of<br>
>>>> + // a macro expansion. This doesn't matter for object-like macros,<br>
>>>> but<br>
>>>> + // can matter for a function-like macro that expands to contain<br>
>>>> __LINE__.<br>
>>>> + // Skip down through expansion points until we find a file loc for<br>
>>>> the<br>
>>>> + // end of the expansion history.<br>
>>>> + Loc = SourceMgr.getExpansionRange(Loc).second;<br>
>>>> + PresumedLoc PLoc = SourceMgr.getPresumedLoc(Loc);<br>
>>>> +<br>
>>>> + // __LINE__ expands to a simple numeric value.<br>
>>>> + OS << (PLoc.isValid()? PLoc.getLine() : 1);<br>
>>>> + Tok.setKind(tok::numeric_constant);<br>
>>>> + } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {<br>
>>>> + // C99 6.10.8: "__FILE__: The presumed name of the current source<br>
>>>> file (a<br>
>>>> + // character string literal)". This can be affected by #line.<br>
>>>> + PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());<br>
>>>> +<br>
>>>> + // __BASE_FILE__ is a GNU extension that returns the top of the<br>
>>>> presumed<br>
>>>> + // #include stack instead of the current file.<br>
>>>> + if (II == Ident__BASE_FILE__ && PLoc.isValid()) {<br>
>>>> + SourceLocation NextLoc = PLoc.getIncludeLoc();<br>
>>>> + while (NextLoc.isValid()) {<br>
>>>> + PLoc = SourceMgr.getPresumedLoc(NextLoc);<br>
>>>> + if (PLoc.isInvalid())<br>
>>>> + break;<br>
>>>> +<br>
>>>> + NextLoc = PLoc.getIncludeLoc();<br>
>>>> + }<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Escape this filename. Turn '\' -> '\\' '"' -> '\"'<br>
>>>> + SmallString<128> FN;<br>
>>>> + if (PLoc.isValid()) {<br>
>>>> + FN += PLoc.getFilename();<br>
>>>> + Lexer::Stringify(FN);<br>
>>>> + OS << '"' << FN.str() << '"';<br>
>>>> + }<br>
>>>> + Tok.setKind(tok::string_literal);<br>
>>>> + } else if (II == Ident__DATE__) {<br>
>>>> + if (!DATELoc.isValid())<br>
>>>> + ComputeDATE_TIME(DATELoc, TIMELoc, *this);<br>
>>>> + Tok.setKind(tok::string_literal);<br>
>>>> + Tok.setLength(strlen("\"Mmm dd yyyy\""));<br>
>>>> + Tok.setLocation(SourceMgr.createExpansionLoc(DATELoc,<br>
>>>> Tok.getLocation(),<br>
>>>> + Tok.getLocation(),<br>
>>>> + Tok.getLength()));<br>
>>>> + return;<br>
>>>> + } else if (II == Ident__TIME__) {<br>
>>>> + if (!TIMELoc.isValid())<br>
>>>> + ComputeDATE_TIME(DATELoc, TIMELoc, *this);<br>
>>>> + Tok.setKind(tok::string_literal);<br>
>>>> + Tok.setLength(strlen("\"hh:mm:ss\""));<br>
>>>> + Tok.setLocation(SourceMgr.createExpansionLoc(TIMELoc,<br>
>>>> Tok.getLocation(),<br>
>>>> + Tok.getLocation(),<br>
>>>> + Tok.getLength()));<br>
>>>> + return;<br>
>>>> + } else if (II == Ident__INCLUDE_LEVEL__) {<br>
>>>> + // Compute the presumed include depth of this token. This can be<br>
>>>> affected<br>
>>>> + // by GNU line markers.<br>
>>>> + unsigned Depth = 0;<br>
>>>> +<br>
>>>> + PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());<br>
>>>> + if (PLoc.isValid()) {<br>
>>>> + PLoc = SourceMgr.getPresumedLoc(PLoc.getIncludeLoc());<br>
>>>> + for (; PLoc.isValid(); ++Depth)<br>
>>>> + PLoc = SourceMgr.getPresumedLoc(PLoc.getIncludeLoc());<br>
>>>> + }<br>
>>>> +<br>
>>>> + // __INCLUDE_LEVEL__ expands to a simple numeric value.<br>
>>>> + OS << Depth;<br>
>>>> + Tok.setKind(tok::numeric_constant);<br>
>>>> + } else if (II == Ident__TIMESTAMP__) {<br>
>>>> + // MSVC, ICC, GCC, VisualAge C++ extension. The generated string<br>
>>>> should be<br>
>>>> + // of the form "Ddd Mmm dd hh::mm::ss yyyy", which is returned by<br>
>>>> asctime.<br>
>>>> +<br>
>>>> + // Get the file that we are lexing out of. If we're currently<br>
>>>> lexing from<br>
>>>> + // a macro, dig into the include stack.<br>
>>>> + const FileEntry *CurFile = 0;<br>
>>>> + PreprocessorLexer *TheLexer = getCurrentFileLexer();<br>
>>>> +<br>
>>>> + if (TheLexer)<br>
>>>> + CurFile = SourceMgr.getFileEntryForID(TheLexer->getFileID());<br>
>>>> +<br>
>>>> + const char *Result;<br>
>>>> + if (CurFile) {<br>
>>>> + time_t TT = CurFile->getModificationTime();<br>
>>>> + struct tm *TM = localtime(&TT);<br>
>>>> + Result = asctime(TM);<br>
>>>> + } else {<br>
>>>> + Result = "??? ??? ?? ??:??:?? ????\n";<br>
>>>> + }<br>
>>>> + // Surround the string with " and strip the trailing newline.<br>
>>>> + OS << '"' << StringRef(Result, strlen(Result)-1) << '"';<br>
>>>> + Tok.setKind(tok::string_literal);<br>
>>>> + } else if (II == Ident__COUNTER__) {<br>
>>>> + // __COUNTER__ expands to a simple numeric value.<br>
>>>> + OS << CounterValue++;<br>
>>>> + Tok.setKind(tok::numeric_constant);<br>
>>>> + } else if (II == Ident__has_feature ||<br>
>>>> + II == Ident__has_extension ||<br>
>>>> + II == Ident__has_builtin ||<br>
>>>> + II == Ident__has_attribute) {<br>
>>>> + // The argument to these builtins should be a parenthesized<br>
>>>> identifier.<br>
>>>> + SourceLocation StartLoc = Tok.getLocation();<br>
>>>> +<br>
>>>> + bool IsValid = false;<br>
>>>> + IdentifierInfo *FeatureII = 0;<br>
>>>> +<br>
>>>> + // Read the '('.<br>
>>>> + Lex(Tok);<br>
>>>> + if (Tok.is(tok::l_paren)) {<br>
>>>> + // Read the identifier<br>
>>>> + Lex(Tok);<br>
>>>> + if (Tok.is(tok::identifier) || Tok.is(tok::kw_const)) {<br>
>>>> + FeatureII = Tok.getIdentifierInfo();<br>
>>>> +<br>
>>>> + // Read the ')'.<br>
>>>> + Lex(Tok);<br>
>>>> + if (Tok.is(tok::r_paren))<br>
>>>> + IsValid = true;<br>
>>>> + }<br>
>>>> + }<br>
>>>> +<br>
>>>> + bool Value = false;<br>
>>>> + if (!IsValid)<br>
>>>> + Diag(StartLoc, diag::err_feature_check_malformed);<br>
>>>> + else if (II == Ident__has_builtin) {<br>
>>>> + // Check for a builtin is trivial.<br>
>>>> + Value = FeatureII->getBuiltinID() != 0;<br>
>>>> + } else if (II == Ident__has_attribute)<br>
>>>> + Value = HasAttribute(FeatureII);<br>
>>>> + else if (II == Ident__has_extension)<br>
>>>> + Value = HasExtension(*this, FeatureII);<br>
>>>> + else {<br>
>>>> + assert(II == Ident__has_feature && "Must be feature check");<br>
>>>> + Value = HasFeature(*this, FeatureII);<br>
>>>> + }<br>
>>>> +<br>
>>>> + OS << (int)Value;<br>
>>>> + if (IsValid)<br>
>>>> + Tok.setKind(tok::numeric_constant);<br>
>>>> + } else if (II == Ident__has_include ||<br>
>>>> + II == Ident__has_include_next) {<br>
>>>> + // The argument to these two builtins should be a parenthesized<br>
>>>> + // file name string literal using angle brackets (<>) or<br>
>>>> + // double-quotes ("").<br>
>>>> + bool Value;<br>
>>>> + if (II == Ident__has_include)<br>
>>>> + Value = EvaluateHasInclude(Tok, II, *this);<br>
>>>> + else<br>
>>>> + Value = EvaluateHasIncludeNext(Tok, II, *this);<br>
>>>> + OS << (int)Value;<br>
>>>> + Tok.setKind(tok::numeric_constant);<br>
>>>> + } else if (II == Ident__has_warning) {<br>
>>>> + // The argument should be a parenthesized string literal.<br>
>>>> + // The argument to these builtins should be a parenthesized<br>
>>>> identifier.<br>
>>>> + SourceLocation StartLoc = Tok.getLocation();<br>
>>>> + bool IsValid = false;<br>
>>>> + bool Value = false;<br>
>>>> + // Read the '('.<br>
>>>> + Lex(Tok);<br>
>>>> + do {<br>
>>>> + if (Tok.is(tok::l_paren)) {<br>
>>>> + // Read the string.<br>
>>>> + Lex(Tok);<br>
>>>> +<br>
>>>> + // We need at least one string literal.<br>
>>>> + if (!Tok.is(tok::string_literal)) {<br>
>>>> + StartLoc = Tok.getLocation();<br>
>>>> + IsValid = false;<br>
>>>> + // Eat tokens until ')'.<br>
>>>> + do Lex(Tok); while (!(Tok.is(tok::r_paren) ||<br>
>>>> Tok.is(tok::eod)));<br>
>>>> + break;<br>
>>>> + }<br>
>>>> +<br>
>>>> + // String concatenation allows multiple strings, which can even<br>
>>>> come<br>
>>>> + // from macro expansion.<br>
>>>> + SmallVector<Token, 4> StrToks;<br>
>>>> + while (Tok.is(tok::string_literal)) {<br>
>>>> + // Complain about, and drop, any ud-suffix.<br>
>>>> + if (Tok.hasUDSuffix())<br>
>>>> + Diag(Tok, diag::err_invalid_string_udl);<br>
>>>> + StrToks.push_back(Tok);<br>
>>>> + LexUnexpandedToken(Tok);<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Is the end a ')'?<br>
>>>> + if (!(IsValid = Tok.is(tok::r_paren)))<br>
>>>> + break;<br>
>>>> +<br>
>>>> + // Concatenate and parse the strings.<br>
>>>> + StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this);<br>
>>>> + assert(Literal.isAscii() && "Didn't allow wide strings in");<br>
>>>> + if (Literal.hadError)<br>
>>>> + break;<br>
>>>> + if (Literal.Pascal) {<br>
>>>> + Diag(Tok, diag::warn_pragma_diagnostic_invalid);<br>
>>>> + break;<br>
>>>> + }<br>
>>>> +<br>
>>>> + StringRef WarningName(Literal.GetString());<br>
>>>> +<br>
>>>> + if (WarningName.size() < 3 || WarningName[0] != '-' ||<br>
>>>> + WarningName[1] != 'W') {<br>
>>>> + Diag(StrToks[0].getLocation(),<br>
>>>> diag::warn_has_warning_invalid_option);<br>
>>>> + break;<br>
>>>> + }<br>
>>>> +<br>
>>>> + // Finally, check if the warning flags maps to a diagnostic<br>
>>>> group.<br>
>>>> + // We construct a SmallVector here to talk to<br>
>>>> getDiagnosticIDs().<br>
>>>> + // Although we don't use the result, this isn't a hot path, and<br>
>>>> not<br>
>>>> + // worth special casing.<br>
>>>> + llvm::SmallVector<diag::kind, 10> Diags;<br>
>>>> + Value = !getDiagnostics().getDiagnosticIDs()-><br>
>>>> + getDiagnosticsInGroup(WarningName.substr(2), Diags);<br>
>>>> + }<br>
>>>> + } while (false);<br>
>>>> +<br>
>>>> + if (!IsValid)<br>
>>>> + Diag(StartLoc, diag::err_warning_check_malformed);<br>
>>>> +<br>
>>>> + OS << (int)Value;<br>
>>>> + Tok.setKind(tok::numeric_constant);<br>
>>>> + } else {<br>
>>>> + llvm_unreachable("Unknown identifier!");<br>
>>>> + }<br>
>>>> + CreateString(OS.str().data(), OS.str().size(), Tok,<br>
>>>> + Tok.getLocation(), Tok.getLocation());<br>
>>>> +}<br>
>>>> +<br>
>>>> +void Preprocessor::markMacroAsUsed(MacroInfo *MI) {<br>
>>>> + // If the 'used' status changed, and the macro requires 'unused'<br>
>>>> warning,<br>
>>>> + // remove its SourceLocation from the warn-for-unused-macro locations.<br>
>>>> + if (MI->isWarnIfUnused() && !MI->isUsed())<br>
>>>> + WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());<br>
>>>> + MI->setIsUsed(true);<br>
>>>> +}<br>
>>>><br>
>>>> Modified: cfe/trunk/lib/Lex/TokenLexer.cpp<br>
>>>> URL:<br>
>>>> <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=163022&r1=163021&r2=163022&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=163022&r1=163021&r2=163022&view=diff</a><br>
>>>><br>
>>>> ==============================================================================<br>
>>>> --- cfe/trunk/lib/Lex/TokenLexer.cpp (original)<br>
>>>> +++ cfe/trunk/lib/Lex/TokenLexer.cpp Fri Aug 31 16:10:54 2012<br>
>>>> @@ -225,6 +225,12 @@<br>
>>>> Token &Tok = ResultToks[i];<br>
>>>> if (Tok.is(tok::hashhash))<br>
>>>> Tok.setKind(tok::unknown);<br>
>>>> + // In Microsoft-compatibility mode, we follow MSVC's<br>
>>>> preprocessing<br>
>>>> + // behaviour by not considering commas from nested macro<br>
>>>> expansions<br>
>>>> + // as argument separators. Set a flag on the token so we can<br>
>>>> test<br>
>>>> + // for this later when the macro expansion is processed.<br>
>>>> + if (Tok.is(tok::comma) && PP.getLangOpts().MicrosoftMode)<br>
>>>> + Tok.setFlag(Token::IgnoredComma);<br>
>>>> }<br>
>>>><br>
>>>> if(ExpandLocStart.isValid()) {<br>
>>>><br>
>>>> Added: cfe/trunk/test/Preprocessor/microsoft-ext.c<br>
>>>> URL:<br>
>>>> <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/microsoft-ext.c?rev=163022&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/microsoft-ext.c?rev=163022&view=auto</a><br>
>>>><br>
>>>> ==============================================================================<br>
>>>> --- cfe/trunk/test/Preprocessor/microsoft-ext.c (added)<br>
>>>> +++ cfe/trunk/test/Preprocessor/microsoft-ext.c Fri Aug 31 16:10:54 2012<br>
>>>> @@ -0,0 +1,7 @@<br>
>>>> +// RUN: %clang_cc1 -E -fms-compatibility %s | FileCheck %s<br>
>>>> +<br>
>>>> +# define M2(x, y) x + y<br>
>>>> +# define P(x, y) {x, y}<br>
>>>> +# define M(x, y) M2(x, P(x, y))<br>
>>>> +M(a, b) // CHECK: a + {a, b}<br>
>>>> +<br>
>>>><br>
>>>><br>
>>>> _______________________________________________<br>
>>>> cfe-commits mailing list<br>
>>>> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
>>>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
>>><br>
>>><br>
>><br>
>><br>
<span class="HOEnZb"><font color="#888888">>><br>
>> --<br>
>> João Matos<br>
>><br>
>> _______________________________________________<br>
>> cfe-commits mailing list<br>
>> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
>><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>João Matos<br>
</div>