Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 1 | //===--- MacroExpansion.cpp - Top level Macro Expansion -------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the top level handling of macro expasion for the |
| 11 | // preprocessor. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Lex/Preprocessor.h" |
| 16 | #include "MacroArgs.h" |
| 17 | #include "clang/Lex/MacroInfo.h" |
| 18 | #include "clang/Basic/SourceManager.h" |
| 19 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 20 | #include "clang/Lex/LexDiagnostic.h" |
Benjamin Kramer | 32592e8 | 2010-01-09 18:53:11 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringSwitch.h" |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 23 | #include <cstdio> |
Chris Lattner | f90a248 | 2008-03-18 05:59:11 +0000 | [diff] [blame] | 24 | #include <ctime> |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 25 | using namespace clang; |
| 26 | |
| 27 | /// setMacroInfo - Specify a macro for this identifier. |
| 28 | /// |
| 29 | void Preprocessor::setMacroInfo(IdentifierInfo *II, MacroInfo *MI) { |
Chris Lattner | 555589d | 2009-04-10 21:17:07 +0000 | [diff] [blame] | 30 | if (MI) { |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 31 | Macros[II] = MI; |
| 32 | II->setHasMacroDefinition(true); |
Chris Lattner | 555589d | 2009-04-10 21:17:07 +0000 | [diff] [blame] | 33 | } else if (II->hasMacroDefinition()) { |
| 34 | Macros.erase(II); |
| 35 | II->setHasMacroDefinition(false); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
| 39 | /// RegisterBuiltinMacro - Register the specified identifier in the identifier |
| 40 | /// table and mark it as a builtin macro to be expanded. |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 41 | static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char *Name){ |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 42 | // Get the identifier. |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 43 | IdentifierInfo *Id = PP.getIdentifierInfo(Name); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 44 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 45 | // Mark it as being a macro that is builtin. |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 46 | MacroInfo *MI = PP.AllocateMacroInfo(SourceLocation()); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 47 | MI->setIsBuiltinMacro(); |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 48 | PP.setMacroInfo(Id, MI); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 49 | return Id; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /// RegisterBuiltinMacros - Register builtin macros, such as __LINE__ with the |
| 54 | /// identifier table. |
| 55 | void Preprocessor::RegisterBuiltinMacros() { |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 56 | Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__"); |
| 57 | Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__"); |
| 58 | Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__"); |
| 59 | Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__"); |
| 60 | Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__"); |
| 61 | Ident_Pragma = RegisterBuiltinMacro(*this, "_Pragma"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 62 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 63 | // GCC Extensions. |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 64 | Ident__BASE_FILE__ = RegisterBuiltinMacro(*this, "__BASE_FILE__"); |
| 65 | Ident__INCLUDE_LEVEL__ = RegisterBuiltinMacro(*this, "__INCLUDE_LEVEL__"); |
| 66 | Ident__TIMESTAMP__ = RegisterBuiltinMacro(*this, "__TIMESTAMP__"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 67 | |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 68 | // Clang Extensions. |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 69 | Ident__has_feature = RegisterBuiltinMacro(*this, "__has_feature"); |
| 70 | Ident__has_builtin = RegisterBuiltinMacro(*this, "__has_builtin"); |
| 71 | Ident__has_include = RegisterBuiltinMacro(*this, "__has_include"); |
| 72 | Ident__has_include_next = RegisterBuiltinMacro(*this, "__has_include_next"); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /// isTrivialSingleTokenExpansion - Return true if MI, which has a single token |
| 76 | /// in its expansion, currently expands to that token literally. |
| 77 | static bool isTrivialSingleTokenExpansion(const MacroInfo *MI, |
| 78 | const IdentifierInfo *MacroIdent, |
| 79 | Preprocessor &PP) { |
| 80 | IdentifierInfo *II = MI->getReplacementToken(0).getIdentifierInfo(); |
| 81 | |
| 82 | // If the token isn't an identifier, it's always literally expanded. |
| 83 | if (II == 0) return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 85 | // If the identifier is a macro, and if that macro is enabled, it may be |
| 86 | // expanded so it's not a trivial expansion. |
| 87 | if (II->hasMacroDefinition() && PP.getMacroInfo(II)->isEnabled() && |
| 88 | // Fast expanding "#define X X" is ok, because X would be disabled. |
| 89 | II != MacroIdent) |
| 90 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 91 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 92 | // If this is an object-like macro invocation, it is safe to trivially expand |
| 93 | // it. |
| 94 | if (MI->isObjectLike()) return true; |
| 95 | |
| 96 | // If this is a function-like macro invocation, it's safe to trivially expand |
| 97 | // as long as the identifier is not a macro argument. |
| 98 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 99 | I != E; ++I) |
| 100 | if (*I == II) |
| 101 | return false; // Identifier is a macro argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 103 | return true; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /// isNextPPTokenLParen - Determine whether the next preprocessor token to be |
| 108 | /// lexed is a '('. If so, consume the token and return true, if not, this |
| 109 | /// method should have no observable side-effect on the lexed tokens. |
| 110 | bool Preprocessor::isNextPPTokenLParen() { |
| 111 | // Do some quick tests for rejection cases. |
| 112 | unsigned Val; |
| 113 | if (CurLexer) |
| 114 | Val = CurLexer->isNextPPTokenLParen(); |
Ted Kremenek | 1a53157 | 2008-11-19 22:43:49 +0000 | [diff] [blame] | 115 | else if (CurPTHLexer) |
| 116 | Val = CurPTHLexer->isNextPPTokenLParen(); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 117 | else |
| 118 | Val = CurTokenLexer->isNextTokenLParen(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 120 | if (Val == 2) { |
| 121 | // We have run off the end. If it's a source file we don't |
| 122 | // examine enclosing ones (C99 5.1.1.2p4). Otherwise walk up the |
| 123 | // macro stack. |
Ted Kremenek | 17ff58a | 2008-11-19 22:21:33 +0000 | [diff] [blame] | 124 | if (CurPPLexer) |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 125 | return false; |
| 126 | for (unsigned i = IncludeMacroStack.size(); i != 0; --i) { |
| 127 | IncludeStackInfo &Entry = IncludeMacroStack[i-1]; |
| 128 | if (Entry.TheLexer) |
| 129 | Val = Entry.TheLexer->isNextPPTokenLParen(); |
Ted Kremenek | dd95d6c | 2008-11-20 16:46:54 +0000 | [diff] [blame] | 130 | else if (Entry.ThePTHLexer) |
| 131 | Val = Entry.ThePTHLexer->isNextPPTokenLParen(); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 132 | else |
| 133 | Val = Entry.TheTokenLexer->isNextTokenLParen(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 134 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 135 | if (Val != 2) |
| 136 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 137 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 138 | // Ran off the end of a source file? |
Ted Kremenek | dd95d6c | 2008-11-20 16:46:54 +0000 | [diff] [blame] | 139 | if (Entry.ThePPLexer) |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 140 | return false; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // Okay, if we know that the token is a '(', lex it and return. Otherwise we |
| 145 | // have found something that isn't a '(' or we found the end of the |
| 146 | // translation unit. In either case, return false. |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 147 | return Val == 1; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /// HandleMacroExpandedIdentifier - If an identifier token is read that is to be |
| 151 | /// expanded as a macro, handle it and return the next token as 'Identifier'. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 152 | bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 153 | MacroInfo *MI) { |
Chris Lattner | ba9eee3 | 2009-03-12 17:31:43 +0000 | [diff] [blame] | 154 | if (Callbacks) Callbacks->MacroExpands(Identifier, MI); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 155 | |
Douglas Gregor | 1367897 | 2010-01-26 19:43:43 +0000 | [diff] [blame] | 156 | // If this is a macro expansion in the "#if !defined(x)" line for the file, |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 157 | // then the macro could expand to different things in other contexts, we need |
| 158 | // to disable the optimization in this case. |
Ted Kremenek | 68a91d5 | 2008-11-18 01:12:54 +0000 | [diff] [blame] | 159 | if (CurPPLexer) CurPPLexer->MIOpt.ExpandedMacro(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 161 | // If this is a builtin macro, like __LINE__ or _Pragma, handle it specially. |
| 162 | if (MI->isBuiltinMacro()) { |
| 163 | ExpandBuiltinMacro(Identifier); |
| 164 | return false; |
| 165 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 166 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 167 | /// Args - If this is a function-like macro expansion, this contains, |
| 168 | /// for each macro argument, the list of tokens that were provided to the |
| 169 | /// invocation. |
| 170 | MacroArgs *Args = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 171 | |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 172 | // Remember where the end of the instantiation occurred. For an object-like |
| 173 | // macro, this is the identifier. For a function-like macro, this is the ')'. |
| 174 | SourceLocation InstantiationEnd = Identifier.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 176 | // If this is a function-like macro, read the arguments. |
| 177 | if (MI->isFunctionLike()) { |
| 178 | // C99 6.10.3p10: If the preprocessing token immediately after the the macro |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 179 | // name isn't a '(', this macro should not be expanded. |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 180 | if (!isNextPPTokenLParen()) |
| 181 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 183 | // Remember that we are now parsing the arguments to a macro invocation. |
| 184 | // Preprocessor directives used inside macro arguments are not portable, and |
| 185 | // this enables the warning. |
| 186 | InMacroArgs = true; |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 187 | Args = ReadFunctionLikeMacroArgs(Identifier, MI, InstantiationEnd); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 189 | // Finished parsing args. |
| 190 | InMacroArgs = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 191 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 192 | // If there was an error parsing the arguments, bail out. |
| 193 | if (Args == 0) return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 195 | ++NumFnMacroExpanded; |
| 196 | } else { |
| 197 | ++NumMacroExpanded; |
| 198 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 200 | // Notice that this macro has been used. |
| 201 | MI->setIsUsed(true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 202 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 203 | // If we started lexing a macro, enter the macro expansion body. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 204 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 205 | // If this macro expands to no tokens, don't bother to push it onto the |
| 206 | // expansion stack, only to take it right back off. |
| 207 | if (MI->getNumTokens() == 0) { |
| 208 | // No need for arg info. |
Chris Lattner | 561395b | 2009-12-14 22:12:52 +0000 | [diff] [blame] | 209 | if (Args) Args->destroy(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 210 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 211 | // Ignore this macro use, just return the next token in the current |
| 212 | // buffer. |
| 213 | bool HadLeadingSpace = Identifier.hasLeadingSpace(); |
| 214 | bool IsAtStartOfLine = Identifier.isAtStartOfLine(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 215 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 216 | Lex(Identifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 217 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 218 | // If the identifier isn't on some OTHER line, inherit the leading |
| 219 | // whitespace/first-on-a-line property of this token. This handles |
| 220 | // stuff like "! XX," -> "! ," and " XX," -> " ,", when XX is |
| 221 | // empty. |
| 222 | if (!Identifier.isAtStartOfLine()) { |
| 223 | if (IsAtStartOfLine) Identifier.setFlag(Token::StartOfLine); |
| 224 | if (HadLeadingSpace) Identifier.setFlag(Token::LeadingSpace); |
| 225 | } |
| 226 | ++NumFastMacroExpanded; |
| 227 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 228 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 229 | } else if (MI->getNumTokens() == 1 && |
| 230 | isTrivialSingleTokenExpansion(MI, Identifier.getIdentifierInfo(), |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 231 | *this)) { |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 232 | // Otherwise, if this macro expands into a single trivially-expanded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 233 | // token: expand it now. This handles common cases like |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 234 | // "#define VAL 42". |
Sam Bishop | 9a4939f | 2008-03-21 07:13:02 +0000 | [diff] [blame] | 235 | |
| 236 | // No need for arg info. |
Chris Lattner | 561395b | 2009-12-14 22:12:52 +0000 | [diff] [blame] | 237 | if (Args) Args->destroy(*this); |
Sam Bishop | 9a4939f | 2008-03-21 07:13:02 +0000 | [diff] [blame] | 238 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 239 | // Propagate the isAtStartOfLine/hasLeadingSpace markers of the macro |
| 240 | // identifier to the expanded token. |
| 241 | bool isAtStartOfLine = Identifier.isAtStartOfLine(); |
| 242 | bool hasLeadingSpace = Identifier.hasLeadingSpace(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 243 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 244 | // Remember where the token is instantiated. |
| 245 | SourceLocation InstantiateLoc = Identifier.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 246 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 247 | // Replace the result token. |
| 248 | Identifier = MI->getReplacementToken(0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 250 | // Restore the StartOfLine/LeadingSpace markers. |
| 251 | Identifier.setFlagValue(Token::StartOfLine , isAtStartOfLine); |
| 252 | Identifier.setFlagValue(Token::LeadingSpace, hasLeadingSpace); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 253 | |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 254 | // Update the tokens location to include both its instantiation and physical |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 255 | // locations. |
| 256 | SourceLocation Loc = |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 257 | SourceMgr.createInstantiationLoc(Identifier.getLocation(), InstantiateLoc, |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 258 | InstantiationEnd,Identifier.getLength()); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 259 | Identifier.setLocation(Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 260 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 261 | // If this is #define X X, we must mark the result as unexpandible. |
| 262 | if (IdentifierInfo *NewII = Identifier.getIdentifierInfo()) |
| 263 | if (getMacroInfo(NewII) == MI) |
| 264 | Identifier.setFlag(Token::DisableExpand); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 266 | // Since this is not an identifier token, it can't be macro expanded, so |
| 267 | // we're done. |
| 268 | ++NumFastMacroExpanded; |
| 269 | return false; |
| 270 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 271 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 272 | // Start expanding the macro. |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 273 | EnterMacro(Identifier, InstantiationEnd, Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 274 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 275 | // Now that the macro is at the top of the include stack, ask the |
| 276 | // preprocessor to read the next token from it. |
| 277 | Lex(Identifier); |
| 278 | return false; |
| 279 | } |
| 280 | |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 281 | /// ReadFunctionLikeMacroArgs - After reading "MACRO" and knowing that the next |
| 282 | /// token is the '(' of the macro, this method is invoked to read all of the |
| 283 | /// actual arguments specified for the macro invocation. This returns null on |
| 284 | /// error. |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 285 | MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName, |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 286 | MacroInfo *MI, |
| 287 | SourceLocation &MacroEnd) { |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 288 | // The number of fixed arguments to parse. |
| 289 | unsigned NumFixedArgsLeft = MI->getNumArgs(); |
| 290 | bool isVariadic = MI->isVariadic(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 292 | // Outer loop, while there are more arguments, keep reading them. |
| 293 | Token Tok; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 294 | |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 295 | // Read arguments as unexpanded tokens. This avoids issues, e.g., where |
| 296 | // an argument value in a macro could expand to ',' or '(' or ')'. |
| 297 | LexUnexpandedToken(Tok); |
| 298 | assert(Tok.is(tok::l_paren) && "Error computing l-paren-ness?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 299 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 300 | // ArgTokens - Build up a list of tokens that make up each argument. Each |
| 301 | // argument is separated by an EOF token. Use a SmallVector so we can avoid |
| 302 | // heap allocations in the common case. |
| 303 | llvm::SmallVector<Token, 64> ArgTokens; |
| 304 | |
| 305 | unsigned NumActuals = 0; |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 306 | while (Tok.isNot(tok::r_paren)) { |
| 307 | assert((Tok.is(tok::l_paren) || Tok.is(tok::comma)) && |
| 308 | "only expect argument separators here"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 309 | |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 310 | unsigned ArgTokenStart = ArgTokens.size(); |
| 311 | SourceLocation ArgStartLoc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 313 | // C99 6.10.3p11: Keep track of the number of l_parens we have seen. Note |
| 314 | // that we already consumed the first one. |
| 315 | unsigned NumParens = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 316 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 317 | while (1) { |
| 318 | // Read arguments as unexpanded tokens. This avoids issues, e.g., where |
| 319 | // an argument value in a macro could expand to ',' or '(' or ')'. |
| 320 | LexUnexpandedToken(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 321 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 322 | if (Tok.is(tok::eof) || Tok.is(tok::eom)) { // "#if f(<eof>" & "#if f(\n" |
| 323 | Diag(MacroName, diag::err_unterm_macro_invoc); |
| 324 | // Do not lose the EOF/EOM. Return it to the client. |
| 325 | MacroName = Tok; |
| 326 | return 0; |
| 327 | } else if (Tok.is(tok::r_paren)) { |
| 328 | // If we found the ) token, the macro arg list is done. |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 329 | if (NumParens-- == 0) { |
| 330 | MacroEnd = Tok.getLocation(); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 331 | break; |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 332 | } |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 333 | } else if (Tok.is(tok::l_paren)) { |
| 334 | ++NumParens; |
| 335 | } else if (Tok.is(tok::comma) && NumParens == 0) { |
| 336 | // Comma ends this argument if there are more fixed arguments expected. |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 337 | // However, if this is a variadic macro, and this is part of the |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 338 | // variadic part, then the comma is just an argument token. |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 339 | if (!isVariadic) break; |
| 340 | if (NumFixedArgsLeft > 1) |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 341 | break; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 342 | } else if (Tok.is(tok::comment) && !KeepMacroComments) { |
| 343 | // If this is a comment token in the argument list and we're just in |
| 344 | // -C mode (not -CC mode), discard the comment. |
| 345 | continue; |
Chris Lattner | 5c497a8 | 2009-04-18 06:44:18 +0000 | [diff] [blame] | 346 | } else if (Tok.getIdentifierInfo() != 0) { |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 347 | // Reading macro arguments can cause macros that we are currently |
| 348 | // expanding from to be popped off the expansion stack. Doing so causes |
| 349 | // them to be reenabled for expansion. Here we record whether any |
| 350 | // identifiers we lex as macro arguments correspond to disabled macros. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 351 | // If so, we mark the token as noexpand. This is a subtle aspect of |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 352 | // C99 6.10.3.4p2. |
| 353 | if (MacroInfo *MI = getMacroInfo(Tok.getIdentifierInfo())) |
| 354 | if (!MI->isEnabled()) |
| 355 | Tok.setFlag(Token::DisableExpand); |
| 356 | } |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 357 | ArgTokens.push_back(Tok); |
| 358 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 360 | // If this was an empty argument list foo(), don't add this as an empty |
| 361 | // argument. |
| 362 | if (ArgTokens.empty() && Tok.getKind() == tok::r_paren) |
| 363 | break; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 364 | |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 365 | // If this is not a variadic macro, and too many args were specified, emit |
| 366 | // an error. |
| 367 | if (!isVariadic && NumFixedArgsLeft == 0) { |
| 368 | if (ArgTokens.size() != ArgTokenStart) |
| 369 | ArgStartLoc = ArgTokens[ArgTokenStart].getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 371 | // Emit the diagnostic at the macro name in case there is a missing ). |
| 372 | // Emitting it at the , could be far away from the macro name. |
| 373 | Diag(ArgStartLoc, diag::err_too_many_args_in_macro_invoc); |
| 374 | return 0; |
| 375 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 376 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 377 | // Empty arguments are standard in C99 and supported as an extension in |
| 378 | // other modes. |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 379 | if (ArgTokens.size() == ArgTokenStart && !Features.C99) |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 380 | Diag(Tok, diag::ext_empty_fnmacro_arg); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 382 | // Add a marker EOF token to the end of the token list for this argument. |
| 383 | Token EOFTok; |
| 384 | EOFTok.startToken(); |
| 385 | EOFTok.setKind(tok::eof); |
Chris Lattner | e768988 | 2009-01-26 20:24:53 +0000 | [diff] [blame] | 386 | EOFTok.setLocation(Tok.getLocation()); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 387 | EOFTok.setLength(0); |
| 388 | ArgTokens.push_back(EOFTok); |
| 389 | ++NumActuals; |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 390 | assert(NumFixedArgsLeft != 0 && "Too many arguments parsed"); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 391 | --NumFixedArgsLeft; |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 392 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 394 | // Okay, we either found the r_paren. Check to see if we parsed too few |
| 395 | // arguments. |
| 396 | unsigned MinArgsExpected = MI->getNumArgs(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 398 | // See MacroArgs instance var for description of this. |
| 399 | bool isVarargsElided = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 401 | if (NumActuals < MinArgsExpected) { |
| 402 | // There are several cases where too few arguments is ok, handle them now. |
Chris Lattner | 97e2de1 | 2009-04-20 21:08:10 +0000 | [diff] [blame] | 403 | if (NumActuals == 0 && MinArgsExpected == 1) { |
| 404 | // #define A(X) or #define A(...) ---> A() |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 405 | |
Chris Lattner | 97e2de1 | 2009-04-20 21:08:10 +0000 | [diff] [blame] | 406 | // If there is exactly one argument, and that argument is missing, |
| 407 | // then we have an empty "()" argument empty list. This is fine, even if |
| 408 | // the macro expects one argument (the argument is just empty). |
| 409 | isVarargsElided = MI->isVariadic(); |
| 410 | } else if (MI->isVariadic() && |
| 411 | (NumActuals+1 == MinArgsExpected || // A(x, ...) -> A(X) |
| 412 | (NumActuals == 0 && MinArgsExpected == 2))) {// A(x,...) -> A() |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 413 | // Varargs where the named vararg parameter is missing: ok as extension. |
| 414 | // #define A(x, ...) |
| 415 | // A("blah") |
| 416 | Diag(Tok, diag::ext_missing_varargs_arg); |
| 417 | |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 418 | // Remember this occurred, allowing us to elide the comma when used for |
Chris Lattner | 63bc035 | 2008-05-08 05:10:33 +0000 | [diff] [blame] | 419 | // cases like: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | // #define A(x, foo...) blah(a, ## foo) |
| 421 | // #define B(x, ...) blah(a, ## __VA_ARGS__) |
| 422 | // #define C(...) blah(a, ## __VA_ARGS__) |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 423 | // A(x) B(x) C() |
Chris Lattner | 97e2de1 | 2009-04-20 21:08:10 +0000 | [diff] [blame] | 424 | isVarargsElided = true; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 425 | } else { |
| 426 | // Otherwise, emit the error. |
| 427 | Diag(Tok, diag::err_too_few_args_in_macro_invoc); |
| 428 | return 0; |
| 429 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 431 | // Add a marker EOF token to the end of the token list for this argument. |
| 432 | SourceLocation EndLoc = Tok.getLocation(); |
| 433 | Tok.startToken(); |
| 434 | Tok.setKind(tok::eof); |
| 435 | Tok.setLocation(EndLoc); |
| 436 | Tok.setLength(0); |
| 437 | ArgTokens.push_back(Tok); |
Chris Lattner | 9fc9e77 | 2009-05-13 00:55:26 +0000 | [diff] [blame] | 438 | |
| 439 | // If we expect two arguments, add both as empty. |
| 440 | if (NumActuals == 0 && MinArgsExpected == 2) |
| 441 | ArgTokens.push_back(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 442 | |
Chris Lattner | 0a4f1b9 | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 443 | } else if (NumActuals > MinArgsExpected && !MI->isVariadic()) { |
| 444 | // Emit the diagnostic at the macro name in case there is a missing ). |
| 445 | // Emitting it at the , could be far away from the macro name. |
| 446 | Diag(MacroName, diag::err_too_many_args_in_macro_invoc); |
| 447 | return 0; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 448 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 450 | return MacroArgs::create(MI, ArgTokens.data(), ArgTokens.size(), |
Chris Lattner | 561395b | 2009-12-14 22:12:52 +0000 | [diff] [blame] | 451 | isVarargsElided, *this); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /// ComputeDATE_TIME - Compute the current time, enter it into the specified |
| 455 | /// scratch buffer, then return DATELoc/TIMELoc locations with the position of |
| 456 | /// the identifier tokens inserted. |
| 457 | static void ComputeDATE_TIME(SourceLocation &DATELoc, SourceLocation &TIMELoc, |
| 458 | Preprocessor &PP) { |
| 459 | time_t TT = time(0); |
| 460 | struct tm *TM = localtime(&TT); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 461 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 462 | static const char * const Months[] = { |
| 463 | "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" |
| 464 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 465 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 466 | char TmpBuffer[100]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 467 | sprintf(TmpBuffer, "\"%s %2d %4d\"", Months[TM->tm_mon], TM->tm_mday, |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 468 | TM->tm_year+1900); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | |
Chris Lattner | 47246be | 2009-01-26 19:29:26 +0000 | [diff] [blame] | 470 | Token TmpTok; |
| 471 | TmpTok.startToken(); |
| 472 | PP.CreateString(TmpBuffer, strlen(TmpBuffer), TmpTok); |
| 473 | DATELoc = TmpTok.getLocation(); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 474 | |
| 475 | sprintf(TmpBuffer, "\"%02d:%02d:%02d\"", TM->tm_hour, TM->tm_min, TM->tm_sec); |
Chris Lattner | 47246be | 2009-01-26 19:29:26 +0000 | [diff] [blame] | 476 | PP.CreateString(TmpBuffer, strlen(TmpBuffer), TmpTok); |
| 477 | TIMELoc = TmpTok.getLocation(); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 480 | |
| 481 | /// HasFeature - Return true if we recognize and implement the specified feature |
| 482 | /// specified by the identifier. |
| 483 | static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) { |
| 484 | const LangOptions &LangOpts = PP.getLangOptions(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 485 | |
Benjamin Kramer | 32592e8 | 2010-01-09 18:53:11 +0000 | [diff] [blame] | 486 | return llvm::StringSwitch<bool>(II->getName()) |
| 487 | .Case("blocks", LangOpts.Blocks) |
| 488 | .Case("cxx_rtti", LangOpts.RTTI) |
Sean Hunt | 4ef4c6b | 2010-01-13 08:31:49 +0000 | [diff] [blame] | 489 | //.Case("cxx_lambdas", false) |
| 490 | //.Case("cxx_nullptr", false) |
| 491 | //.Case("cxx_concepts", false) |
| 492 | .Case("cxx_decltype", LangOpts.CPlusPlus0x) |
| 493 | .Case("cxx_auto_type", LangOpts.CPlusPlus0x) |
Benjamin Kramer | 32592e8 | 2010-01-09 18:53:11 +0000 | [diff] [blame] | 494 | .Case("cxx_exceptions", LangOpts.Exceptions) |
Sean Hunt | 4ef4c6b | 2010-01-13 08:31:49 +0000 | [diff] [blame] | 495 | .Case("cxx_attributes", LangOpts.CPlusPlus0x) |
| 496 | .Case("cxx_static_assert", LangOpts.CPlusPlus0x) |
Benjamin Kramer | 32592e8 | 2010-01-09 18:53:11 +0000 | [diff] [blame] | 497 | .Case("objc_nonfragile_abi", LangOpts.ObjCNonFragileABI) |
Sean Hunt | 4ef4c6b | 2010-01-13 08:31:49 +0000 | [diff] [blame] | 498 | .Case("cxx_deleted_functions", LangOpts.CPlusPlus0x) |
| 499 | //.Case("cxx_rvalue_references", false) |
Benjamin Kramer | 32592e8 | 2010-01-09 18:53:11 +0000 | [diff] [blame] | 500 | .Case("attribute_overloadable", true) |
Sean Hunt | 4ef4c6b | 2010-01-13 08:31:49 +0000 | [diff] [blame] | 501 | //.Case("cxx_variadic_templates", false) |
Benjamin Kramer | 32592e8 | 2010-01-09 18:53:11 +0000 | [diff] [blame] | 502 | .Case("attribute_ext_vector_type", true) |
| 503 | .Case("attribute_analyzer_noreturn", true) |
Ted Kremenek | 1359300 | 2010-02-18 00:06:04 +0000 | [diff] [blame] | 504 | .Case("attribute_cf_returns_not_retained", true) |
Benjamin Kramer | 32592e8 | 2010-01-09 18:53:11 +0000 | [diff] [blame] | 505 | .Case("attribute_cf_returns_retained", true) |
Ted Kremenek | 1359300 | 2010-02-18 00:06:04 +0000 | [diff] [blame] | 506 | .Case("attribute_ns_returns_not_retained", true) |
| 507 | .Case("attribute_ns_returns_retained", true) |
Benjamin Kramer | 32592e8 | 2010-01-09 18:53:11 +0000 | [diff] [blame] | 508 | .Default(false); |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 509 | } |
| 510 | |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 511 | /// EvaluateHasIncludeCommon - Process a '__has_include("path")' |
| 512 | /// or '__has_include_next("path")' expression. |
| 513 | /// Returns true if successful. |
| 514 | static bool EvaluateHasIncludeCommon(bool &Result, Token &Tok, |
| 515 | IdentifierInfo *II, Preprocessor &PP, |
| 516 | const DirectoryLookup *LookupFrom) { |
| 517 | SourceLocation LParenLoc; |
| 518 | |
| 519 | // Get '('. |
| 520 | PP.LexNonComment(Tok); |
| 521 | |
| 522 | // Ensure we have a '('. |
| 523 | if (Tok.isNot(tok::l_paren)) { |
| 524 | PP.Diag(Tok.getLocation(), diag::err_pp_missing_lparen) << II->getName(); |
| 525 | return false; |
| 526 | } |
| 527 | |
| 528 | // Save '(' location for possible missing ')' message. |
| 529 | LParenLoc = Tok.getLocation(); |
| 530 | |
| 531 | // Get the file name. |
| 532 | PP.getCurrentLexer()->LexIncludeFilename(Tok); |
| 533 | |
| 534 | // Reserve a buffer to get the spelling. |
Chris Lattner | a139481 | 2010-01-10 01:35:12 +0000 | [diff] [blame] | 535 | llvm::SmallString<128> FilenameBuffer; |
| 536 | llvm::StringRef Filename; |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 537 | |
| 538 | switch (Tok.getKind()) { |
| 539 | case tok::eom: |
| 540 | // If the token kind is EOM, the error has already been diagnosed. |
| 541 | return false; |
| 542 | |
| 543 | case tok::angle_string_literal: |
Benjamin Kramer | ddeea56 | 2010-02-27 13:44:12 +0000 | [diff] [blame^] | 544 | case tok::string_literal: |
| 545 | Filename = PP.getSpelling(Tok, FilenameBuffer); |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 546 | break; |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 547 | |
| 548 | case tok::less: |
| 549 | // This could be a <foo/bar.h> file coming from a macro expansion. In this |
| 550 | // case, glue the tokens together into FilenameBuffer and interpret those. |
| 551 | FilenameBuffer.push_back('<'); |
| 552 | if (PP.ConcatenateIncludeName(FilenameBuffer)) |
| 553 | return false; // Found <eom> but no ">"? Diagnostic already emitted. |
Chris Lattner | a139481 | 2010-01-10 01:35:12 +0000 | [diff] [blame] | 554 | Filename = FilenameBuffer.str(); |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 555 | break; |
| 556 | default: |
| 557 | PP.Diag(Tok.getLocation(), diag::err_pp_expects_filename); |
| 558 | return false; |
| 559 | } |
| 560 | |
Chris Lattner | a139481 | 2010-01-10 01:35:12 +0000 | [diff] [blame] | 561 | bool isAngled = PP.GetIncludeFilenameSpelling(Tok.getLocation(), Filename); |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 562 | // If GetIncludeFilenameSpelling set the start ptr to null, there was an |
| 563 | // error. |
Chris Lattner | a139481 | 2010-01-10 01:35:12 +0000 | [diff] [blame] | 564 | if (Filename.empty()) |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 565 | return false; |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 566 | |
| 567 | // Search include directories. |
| 568 | const DirectoryLookup *CurDir; |
Chris Lattner | f45b646 | 2010-01-22 00:14:44 +0000 | [diff] [blame] | 569 | const FileEntry *File = PP.LookupFile(Filename, isAngled, LookupFrom, CurDir); |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 570 | |
| 571 | // Get the result value. Result = true means the file exists. |
| 572 | Result = File != 0; |
| 573 | |
| 574 | // Get ')'. |
| 575 | PP.LexNonComment(Tok); |
| 576 | |
| 577 | // Ensure we have a trailing ). |
| 578 | if (Tok.isNot(tok::r_paren)) { |
| 579 | PP.Diag(Tok.getLocation(), diag::err_pp_missing_rparen) << II->getName(); |
| 580 | PP.Diag(LParenLoc, diag::note_matching) << "("; |
| 581 | return false; |
| 582 | } |
| 583 | |
| 584 | return true; |
| 585 | } |
| 586 | |
| 587 | /// EvaluateHasInclude - Process a '__has_include("path")' expression. |
| 588 | /// Returns true if successful. |
| 589 | static bool EvaluateHasInclude(bool &Result, Token &Tok, IdentifierInfo *II, |
| 590 | Preprocessor &PP) { |
| 591 | return(EvaluateHasIncludeCommon(Result, Tok, II, PP, NULL)); |
| 592 | } |
| 593 | |
| 594 | /// EvaluateHasIncludeNext - Process '__has_include_next("path")' expression. |
| 595 | /// Returns true if successful. |
| 596 | static bool EvaluateHasIncludeNext(bool &Result, Token &Tok, |
| 597 | IdentifierInfo *II, Preprocessor &PP) { |
| 598 | // __has_include_next is like __has_include, except that we start |
| 599 | // searching after the current found directory. If we can't do this, |
| 600 | // issue a diagnostic. |
| 601 | const DirectoryLookup *Lookup = PP.GetCurDirLookup(); |
| 602 | if (PP.isInPrimaryFile()) { |
| 603 | Lookup = 0; |
| 604 | PP.Diag(Tok, diag::pp_include_next_in_primary); |
| 605 | } else if (Lookup == 0) { |
| 606 | PP.Diag(Tok, diag::pp_include_next_absolute_path); |
| 607 | } else { |
| 608 | // Start looking up in the next directory. |
| 609 | ++Lookup; |
| 610 | } |
| 611 | |
| 612 | return(EvaluateHasIncludeCommon(Result, Tok, II, PP, Lookup)); |
| 613 | } |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 614 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 615 | /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded |
| 616 | /// as a builtin macro, handle it and return the next token as 'Tok'. |
| 617 | void Preprocessor::ExpandBuiltinMacro(Token &Tok) { |
| 618 | // Figure out which token this is. |
| 619 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 620 | assert(II && "Can't be a macro without id info!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 621 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 622 | // If this is an _Pragma directive, expand it, invoke the pragma handler, then |
| 623 | // lex the token after it. |
| 624 | if (II == Ident_Pragma) |
| 625 | return Handle_Pragma(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 627 | ++NumBuiltinMacroExpanded; |
| 628 | |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 629 | llvm::SmallString<128> TmpBuffer; |
| 630 | llvm::raw_svector_ostream OS(TmpBuffer); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 631 | |
| 632 | // Set up the return result. |
| 633 | Tok.setIdentifierInfo(0); |
| 634 | Tok.clearFlag(Token::NeedsCleaning); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 636 | if (II == Ident__LINE__) { |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 637 | // C99 6.10.8: "__LINE__: The presumed line number (within the current |
| 638 | // source file) of the current source line (an integer constant)". This can |
| 639 | // be affected by #line. |
Chris Lattner | 081927b | 2009-02-15 21:06:39 +0000 | [diff] [blame] | 640 | SourceLocation Loc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | |
Chris Lattner | dff070f | 2009-04-18 22:29:33 +0000 | [diff] [blame] | 642 | // Advance to the location of the first _, this might not be the first byte |
| 643 | // of the token if it starts with an escaped newline. |
| 644 | Loc = AdvanceToTokenCharacter(Loc, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 645 | |
Chris Lattner | 081927b | 2009-02-15 21:06:39 +0000 | [diff] [blame] | 646 | // One wrinkle here is that GCC expands __LINE__ to location of the *end* of |
| 647 | // a macro instantiation. This doesn't matter for object-like macros, but |
| 648 | // can matter for a function-like macro that expands to contain __LINE__. |
| 649 | // Skip down through instantiation points until we find a file loc for the |
| 650 | // end of the instantiation history. |
Chris Lattner | 6678133 | 2009-02-15 21:26:50 +0000 | [diff] [blame] | 651 | Loc = SourceMgr.getInstantiationRange(Loc).second; |
Chris Lattner | 081927b | 2009-02-15 21:06:39 +0000 | [diff] [blame] | 652 | PresumedLoc PLoc = SourceMgr.getPresumedLoc(Loc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 653 | |
Chris Lattner | 1fa4953 | 2009-03-08 08:08:45 +0000 | [diff] [blame] | 654 | // __LINE__ expands to a simple numeric value. |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 655 | OS << PLoc.getLine(); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 656 | Tok.setKind(tok::numeric_constant); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 657 | } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) { |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 658 | // C99 6.10.8: "__FILE__: The presumed name of the current source file (a |
| 659 | // character string literal)". This can be affected by #line. |
| 660 | PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation()); |
| 661 | |
| 662 | // __BASE_FILE__ is a GNU extension that returns the top of the presumed |
| 663 | // #include stack instead of the current file. |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 664 | if (II == Ident__BASE_FILE__) { |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 665 | SourceLocation NextLoc = PLoc.getIncludeLoc(); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 666 | while (NextLoc.isValid()) { |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 667 | PLoc = SourceMgr.getPresumedLoc(NextLoc); |
| 668 | NextLoc = PLoc.getIncludeLoc(); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 669 | } |
| 670 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 672 | // Escape this filename. Turn '\' -> '\\' '"' -> '\"' |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 673 | llvm::SmallString<128> FN; |
| 674 | FN += PLoc.getFilename(); |
| 675 | Lexer::Stringify(FN); |
| 676 | OS << '"' << FN.str() << '"'; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 677 | Tok.setKind(tok::string_literal); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 678 | } else if (II == Ident__DATE__) { |
| 679 | if (!DATELoc.isValid()) |
| 680 | ComputeDATE_TIME(DATELoc, TIMELoc, *this); |
| 681 | Tok.setKind(tok::string_literal); |
| 682 | Tok.setLength(strlen("\"Mmm dd yyyy\"")); |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 683 | Tok.setLocation(SourceMgr.createInstantiationLoc(DATELoc, Tok.getLocation(), |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 684 | Tok.getLocation(), |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 685 | Tok.getLength())); |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 686 | return; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 687 | } else if (II == Ident__TIME__) { |
| 688 | if (!TIMELoc.isValid()) |
| 689 | ComputeDATE_TIME(DATELoc, TIMELoc, *this); |
| 690 | Tok.setKind(tok::string_literal); |
| 691 | Tok.setLength(strlen("\"hh:mm:ss\"")); |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 692 | Tok.setLocation(SourceMgr.createInstantiationLoc(TIMELoc, Tok.getLocation(), |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 693 | Tok.getLocation(), |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 694 | Tok.getLength())); |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 695 | return; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 696 | } else if (II == Ident__INCLUDE_LEVEL__) { |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 697 | // Compute the presumed include depth of this token. This can be affected |
| 698 | // by GNU line markers. |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 699 | unsigned Depth = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 700 | |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 701 | PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation()); |
| 702 | PLoc = SourceMgr.getPresumedLoc(PLoc.getIncludeLoc()); |
| 703 | for (; PLoc.isValid(); ++Depth) |
| 704 | PLoc = SourceMgr.getPresumedLoc(PLoc.getIncludeLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | |
Chris Lattner | 1fa4953 | 2009-03-08 08:08:45 +0000 | [diff] [blame] | 706 | // __INCLUDE_LEVEL__ expands to a simple numeric value. |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 707 | OS << Depth; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 708 | Tok.setKind(tok::numeric_constant); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 709 | } else if (II == Ident__TIMESTAMP__) { |
| 710 | // MSVC, ICC, GCC, VisualAge C++ extension. The generated string should be |
| 711 | // of the form "Ddd Mmm dd hh::mm::ss yyyy", which is returned by asctime. |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 712 | |
| 713 | // Get the file that we are lexing out of. If we're currently lexing from |
| 714 | // a macro, dig into the include stack. |
| 715 | const FileEntry *CurFile = 0; |
Ted Kremenek | a275a19 | 2008-11-20 01:35:24 +0000 | [diff] [blame] | 716 | PreprocessorLexer *TheLexer = getCurrentFileLexer(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 717 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 718 | if (TheLexer) |
Ted Kremenek | ac80c6e | 2008-11-19 22:55:25 +0000 | [diff] [blame] | 719 | CurFile = SourceMgr.getFileEntryForID(TheLexer->getFileID()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 720 | |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 721 | const char *Result; |
| 722 | if (CurFile) { |
| 723 | time_t TT = CurFile->getModificationTime(); |
| 724 | struct tm *TM = localtime(&TT); |
| 725 | Result = asctime(TM); |
| 726 | } else { |
| 727 | Result = "??? ??? ?? ??:??:?? ????\n"; |
| 728 | } |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 729 | // Surround the string with " and strip the trailing newline. |
| 730 | OS << '"' << llvm::StringRef(Result, strlen(Result)-1) << '"'; |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 731 | Tok.setKind(tok::string_literal); |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 732 | } else if (II == Ident__COUNTER__) { |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 733 | // __COUNTER__ expands to a simple numeric value. |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 734 | OS << CounterValue++; |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 735 | Tok.setKind(tok::numeric_constant); |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 736 | } else if (II == Ident__has_feature || |
| 737 | II == Ident__has_builtin) { |
| 738 | // The argument to these two builtins should be a parenthesized identifier. |
| 739 | SourceLocation StartLoc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 741 | bool IsValid = false; |
| 742 | IdentifierInfo *FeatureII = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 744 | // Read the '('. |
| 745 | Lex(Tok); |
| 746 | if (Tok.is(tok::l_paren)) { |
| 747 | // Read the identifier |
| 748 | Lex(Tok); |
| 749 | if (Tok.is(tok::identifier)) { |
| 750 | FeatureII = Tok.getIdentifierInfo(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 752 | // Read the ')'. |
| 753 | Lex(Tok); |
| 754 | if (Tok.is(tok::r_paren)) |
| 755 | IsValid = true; |
| 756 | } |
| 757 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 759 | bool Value = false; |
| 760 | if (!IsValid) |
| 761 | Diag(StartLoc, diag::err_feature_check_malformed); |
| 762 | else if (II == Ident__has_builtin) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 763 | // Check for a builtin is trivial. |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 764 | Value = FeatureII->getBuiltinID() != 0; |
| 765 | } else { |
| 766 | assert(II == Ident__has_feature && "Must be feature check"); |
| 767 | Value = HasFeature(*this, FeatureII); |
| 768 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 770 | OS << (int)Value; |
Chris Lattner | 148772a | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 771 | Tok.setKind(tok::numeric_constant); |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 772 | } else if (II == Ident__has_include || |
| 773 | II == Ident__has_include_next) { |
| 774 | // The argument to these two builtins should be a parenthesized |
| 775 | // file name string literal using angle brackets (<>) or |
| 776 | // double-quotes (""). |
| 777 | bool Value = false; |
| 778 | bool IsValid; |
| 779 | if (II == Ident__has_include) |
| 780 | IsValid = EvaluateHasInclude(Value, Tok, II, *this); |
| 781 | else |
| 782 | IsValid = EvaluateHasIncludeNext(Value, Tok, II, *this); |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 783 | OS << (int)Value; |
John Thompson | 92bd8c7 | 2009-11-02 22:28:12 +0000 | [diff] [blame] | 784 | Tok.setKind(tok::numeric_constant); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 785 | } else { |
| 786 | assert(0 && "Unknown identifier!"); |
| 787 | } |
Benjamin Kramer | b176591 | 2010-01-27 16:38:22 +0000 | [diff] [blame] | 788 | CreateString(OS.str().data(), OS.str().size(), Tok, Tok.getLocation()); |
Chris Lattner | a3b605e | 2008-03-09 03:13:06 +0000 | [diff] [blame] | 789 | } |