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