Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 1 | //===--- ParsePragma.cpp - Language specific pragma parsing ---------------===// |
| 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 language specific #pragma handlers. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ParsePragma.h" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 15 | #include "clang/Parse/ParseDiagnostic.h" |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 16 | #include "clang/Parse/Parser.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Lex/Preprocessor.h" |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
Eli Friedman | aa8b0d1 | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 20 | |
| 21 | // #pragma GCC visibility comes in two variants: |
| 22 | // 'push' '(' [visibility] ')' |
| 23 | // 'pop' |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame^] | 24 | void PragmaGCCVisibilityHandler::HandlePragma(Preprocessor &PP, |
| 25 | PragmaIntroducerKind Introducer, |
| 26 | Token &VisTok) { |
Eli Friedman | aa8b0d1 | 2010-08-05 06:57:20 +0000 | [diff] [blame] | 27 | SourceLocation VisLoc = VisTok.getLocation(); |
| 28 | |
| 29 | Token Tok; |
| 30 | PP.Lex(Tok); |
| 31 | |
| 32 | const IdentifierInfo *PushPop = Tok.getIdentifierInfo(); |
| 33 | |
| 34 | bool IsPush; |
| 35 | const IdentifierInfo *VisType; |
| 36 | if (PushPop && PushPop->isStr("pop")) { |
| 37 | IsPush = false; |
| 38 | VisType = 0; |
| 39 | } else if (PushPop && PushPop->isStr("push")) { |
| 40 | IsPush = true; |
| 41 | PP.Lex(Tok); |
| 42 | if (Tok.isNot(tok::l_paren)) { |
| 43 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) |
| 44 | << "visibility"; |
| 45 | return; |
| 46 | } |
| 47 | PP.Lex(Tok); |
| 48 | VisType = Tok.getIdentifierInfo(); |
| 49 | if (!VisType) { |
| 50 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
| 51 | << "visibility"; |
| 52 | return; |
| 53 | } |
| 54 | PP.Lex(Tok); |
| 55 | if (Tok.isNot(tok::r_paren)) { |
| 56 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen) |
| 57 | << "visibility"; |
| 58 | return; |
| 59 | } |
| 60 | } else { |
| 61 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
| 62 | << "visibility"; |
| 63 | return; |
| 64 | } |
| 65 | PP.Lex(Tok); |
| 66 | if (Tok.isNot(tok::eom)) { |
| 67 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
| 68 | << "visibility"; |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | Actions.ActOnPragmaVisibility(IsPush, VisType, VisLoc); |
| 73 | } |
| 74 | |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 75 | // #pragma pack(...) comes in the following delicious flavors: |
| 76 | // pack '(' [integer] ')' |
| 77 | // pack '(' 'show' ')' |
| 78 | // pack '(' ('push' | 'pop') [',' identifier] [, integer] ')' |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame^] | 79 | void PragmaPackHandler::HandlePragma(Preprocessor &PP, |
| 80 | PragmaIntroducerKind Introducer, |
| 81 | Token &PackTok) { |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 82 | SourceLocation PackLoc = PackTok.getLocation(); |
| 83 | |
| 84 | Token Tok; |
| 85 | PP.Lex(Tok); |
| 86 | if (Tok.isNot(tok::l_paren)) { |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 87 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "pack"; |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 88 | return; |
| 89 | } |
| 90 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 91 | Sema::PragmaPackKind Kind = Sema::PPK_Default; |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 92 | IdentifierInfo *Name = 0; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 93 | ExprResult Alignment; |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 94 | SourceLocation LParenLoc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 95 | PP.Lex(Tok); |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 96 | if (Tok.is(tok::numeric_constant)) { |
| 97 | Alignment = Actions.ActOnNumericConstant(Tok); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 98 | if (Alignment.isInvalid()) |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 99 | return; |
| 100 | |
| 101 | PP.Lex(Tok); |
| 102 | } else if (Tok.is(tok::identifier)) { |
| 103 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 104 | if (II->isStr("show")) { |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 105 | Kind = Sema::PPK_Show; |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 106 | PP.Lex(Tok); |
| 107 | } else { |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 108 | if (II->isStr("push")) { |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 109 | Kind = Sema::PPK_Push; |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 110 | } else if (II->isStr("pop")) { |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 111 | Kind = Sema::PPK_Pop; |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 112 | } else { |
| 113 | PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_invalid_action); |
| 114 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | } |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 116 | PP.Lex(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 118 | if (Tok.is(tok::comma)) { |
| 119 | PP.Lex(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 121 | if (Tok.is(tok::numeric_constant)) { |
| 122 | Alignment = Actions.ActOnNumericConstant(Tok); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 123 | if (Alignment.isInvalid()) |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 124 | return; |
| 125 | |
| 126 | PP.Lex(Tok); |
| 127 | } else if (Tok.is(tok::identifier)) { |
| 128 | Name = Tok.getIdentifierInfo(); |
| 129 | PP.Lex(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 130 | |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 131 | if (Tok.is(tok::comma)) { |
| 132 | PP.Lex(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 133 | |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 134 | if (Tok.isNot(tok::numeric_constant)) { |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 135 | PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed); |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 136 | return; |
| 137 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 139 | Alignment = Actions.ActOnNumericConstant(Tok); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 140 | if (Alignment.isInvalid()) |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 141 | return; |
| 142 | |
| 143 | PP.Lex(Tok); |
| 144 | } |
| 145 | } else { |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 146 | PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed); |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 147 | return; |
| 148 | } |
| 149 | } |
| 150 | } |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 151 | } |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 152 | |
| 153 | if (Tok.isNot(tok::r_paren)) { |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 154 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen) << "pack"; |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 155 | return; |
| 156 | } |
| 157 | |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 158 | SourceLocation RParenLoc = Tok.getLocation(); |
Eli Friedman | 9991479 | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 159 | PP.Lex(Tok); |
| 160 | if (Tok.isNot(tok::eom)) { |
| 161 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "pack"; |
| 162 | return; |
| 163 | } |
| 164 | |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 165 | Actions.ActOnPragmaPack(Kind, Name, Alignment.release(), PackLoc, |
Daniel Dunbar | fcdd8fe | 2008-10-04 19:21:03 +0000 | [diff] [blame] | 166 | LParenLoc, RParenLoc); |
| 167 | } |
| 168 | |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 169 | // #pragma 'align' '=' {'native','natural','mac68k','power','reset'} |
| 170 | // #pragma 'options 'align' '=' {'native','natural','mac68k','power','reset'} |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 171 | static void ParseAlignPragma(Sema &Actions, Preprocessor &PP, Token &FirstTok, |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 172 | bool IsOptions) { |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 173 | Token Tok; |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 174 | |
| 175 | if (IsOptions) { |
| 176 | PP.Lex(Tok); |
| 177 | if (Tok.isNot(tok::identifier) || |
| 178 | !Tok.getIdentifierInfo()->isStr("align")) { |
| 179 | PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_align); |
| 180 | return; |
| 181 | } |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 182 | } |
Daniel Dunbar | 638e7cf | 2010-05-27 18:42:09 +0000 | [diff] [blame] | 183 | |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 184 | PP.Lex(Tok); |
| 185 | if (Tok.isNot(tok::equal)) { |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 186 | PP.Diag(Tok.getLocation(), diag::warn_pragma_align_expected_equal) |
| 187 | << IsOptions; |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | |
| 191 | PP.Lex(Tok); |
| 192 | if (Tok.isNot(tok::identifier)) { |
| 193 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 194 | << (IsOptions ? "options" : "align"); |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 198 | Sema::PragmaOptionsAlignKind Kind = Sema::POAK_Natural; |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 199 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Daniel Dunbar | 638e7cf | 2010-05-27 18:42:09 +0000 | [diff] [blame] | 200 | if (II->isStr("native")) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 201 | Kind = Sema::POAK_Native; |
Daniel Dunbar | 638e7cf | 2010-05-27 18:42:09 +0000 | [diff] [blame] | 202 | else if (II->isStr("natural")) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 203 | Kind = Sema::POAK_Natural; |
Daniel Dunbar | 6f73914 | 2010-05-27 18:42:17 +0000 | [diff] [blame] | 204 | else if (II->isStr("packed")) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 205 | Kind = Sema::POAK_Packed; |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 206 | else if (II->isStr("power")) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 207 | Kind = Sema::POAK_Power; |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 208 | else if (II->isStr("mac68k")) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 209 | Kind = Sema::POAK_Mac68k; |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 210 | else if (II->isStr("reset")) |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 211 | Kind = Sema::POAK_Reset; |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 212 | else { |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 213 | PP.Diag(Tok.getLocation(), diag::warn_pragma_align_invalid_option) |
| 214 | << IsOptions; |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 215 | return; |
| 216 | } |
| 217 | |
| 218 | SourceLocation KindLoc = Tok.getLocation(); |
| 219 | PP.Lex(Tok); |
| 220 | if (Tok.isNot(tok::eom)) { |
| 221 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 222 | << (IsOptions ? "options" : "align"); |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 223 | return; |
| 224 | } |
| 225 | |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 226 | Actions.ActOnPragmaOptionsAlign(Kind, FirstTok.getLocation(), KindLoc); |
| 227 | } |
| 228 | |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame^] | 229 | void PragmaAlignHandler::HandlePragma(Preprocessor &PP, |
| 230 | PragmaIntroducerKind Introducer, |
| 231 | Token &AlignTok) { |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 232 | ParseAlignPragma(Actions, PP, AlignTok, /*IsOptions=*/false); |
| 233 | } |
| 234 | |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame^] | 235 | void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, |
| 236 | PragmaIntroducerKind Introducer, |
| 237 | Token &OptionsTok) { |
Daniel Dunbar | cbb98ed | 2010-07-31 19:17:07 +0000 | [diff] [blame] | 238 | ParseAlignPragma(Actions, PP, OptionsTok, /*IsOptions=*/true); |
Daniel Dunbar | 861800c | 2010-05-26 23:29:06 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 241 | // #pragma unused(identifier) |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame^] | 242 | void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, |
| 243 | PragmaIntroducerKind Introducer, |
| 244 | Token &UnusedTok) { |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 245 | // FIXME: Should we be expanding macros here? My guess is no. |
| 246 | SourceLocation UnusedLoc = UnusedTok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 247 | |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 248 | // Lex the left '('. |
| 249 | Token Tok; |
| 250 | PP.Lex(Tok); |
| 251 | if (Tok.isNot(tok::l_paren)) { |
| 252 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "unused"; |
| 253 | return; |
| 254 | } |
| 255 | SourceLocation LParenLoc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 256 | |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 257 | // Lex the declaration reference(s). |
Ted Kremenek | 7a02a37 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 258 | llvm::SmallVector<Token, 5> Identifiers; |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 259 | SourceLocation RParenLoc; |
| 260 | bool LexID = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 261 | |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 262 | while (true) { |
| 263 | PP.Lex(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 264 | |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 265 | if (LexID) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 266 | if (Tok.is(tok::identifier)) { |
Ted Kremenek | 7a02a37 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 267 | Identifiers.push_back(Tok); |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 268 | LexID = false; |
| 269 | continue; |
| 270 | } |
| 271 | |
Ted Kremenek | 7a02a37 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 272 | // Illegal token! |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 273 | PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_var); |
| 274 | return; |
| 275 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 277 | // We are execting a ')' or a ','. |
| 278 | if (Tok.is(tok::comma)) { |
| 279 | LexID = true; |
| 280 | continue; |
| 281 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 283 | if (Tok.is(tok::r_paren)) { |
| 284 | RParenLoc = Tok.getLocation(); |
| 285 | break; |
| 286 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 287 | |
Ted Kremenek | 7a02a37 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 288 | // Illegal token! |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 289 | PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_punc); |
| 290 | return; |
| 291 | } |
Eli Friedman | 9991479 | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 292 | |
| 293 | PP.Lex(Tok); |
| 294 | if (Tok.isNot(tok::eom)) { |
| 295 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << |
| 296 | "unused"; |
| 297 | return; |
| 298 | } |
| 299 | |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 300 | // Verify that we have a location for the right parenthesis. |
| 301 | assert(RParenLoc.isValid() && "Valid '#pragma unused' must have ')'"); |
Ted Kremenek | 7a02a37 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 302 | assert(!Identifiers.empty() && "Valid '#pragma unused' must have arguments"); |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 303 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | // Perform the action to handle the pragma. |
Ted Kremenek | 7a02a37 | 2009-08-03 23:24:57 +0000 | [diff] [blame] | 305 | Actions.ActOnPragmaUnused(Identifiers.data(), Identifiers.size(), |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 306 | parser.getCurScope(), UnusedLoc, LParenLoc, RParenLoc); |
Ted Kremenek | 4726d03 | 2009-03-23 22:28:25 +0000 | [diff] [blame] | 307 | } |
Eli Friedman | 9991479 | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 308 | |
| 309 | // #pragma weak identifier |
| 310 | // #pragma weak identifier '=' identifier |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame^] | 311 | void PragmaWeakHandler::HandlePragma(Preprocessor &PP, |
| 312 | PragmaIntroducerKind Introducer, |
| 313 | Token &WeakTok) { |
Eli Friedman | 9991479 | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 314 | // FIXME: Should we be expanding macros here? My guess is no. |
| 315 | SourceLocation WeakLoc = WeakTok.getLocation(); |
| 316 | |
| 317 | Token Tok; |
| 318 | PP.Lex(Tok); |
| 319 | if (Tok.isNot(tok::identifier)) { |
| 320 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) << "weak"; |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | IdentifierInfo *WeakName = Tok.getIdentifierInfo(), *AliasName = 0; |
| 325 | SourceLocation WeakNameLoc = Tok.getLocation(), AliasNameLoc; |
| 326 | |
| 327 | PP.Lex(Tok); |
| 328 | if (Tok.is(tok::equal)) { |
| 329 | PP.Lex(Tok); |
| 330 | if (Tok.isNot(tok::identifier)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 331 | PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) |
Eli Friedman | 9991479 | 2009-06-05 00:49:58 +0000 | [diff] [blame] | 332 | << "weak"; |
| 333 | return; |
| 334 | } |
| 335 | AliasName = Tok.getIdentifierInfo(); |
| 336 | AliasNameLoc = Tok.getLocation(); |
| 337 | PP.Lex(Tok); |
| 338 | } |
| 339 | |
| 340 | if (Tok.isNot(tok::eom)) { |
| 341 | PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "weak"; |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | if (AliasName) { |
| 346 | Actions.ActOnPragmaWeakAlias(WeakName, AliasName, WeakLoc, WeakNameLoc, |
| 347 | AliasNameLoc); |
| 348 | } else { |
| 349 | Actions.ActOnPragmaWeakID(WeakName, WeakLoc, WeakNameLoc); |
| 350 | } |
| 351 | } |