// - #pragma options
def warn_pragma_options_expected_align : Warning<
"expected 'align' following '#pragma options' - ignored">;
-def warn_pragma_options_expected_equal : Warning<
- "expected '=' following '#pragma options align' - ignored">;
-def warn_pragma_options_invalid_option : Warning<
- "invalid alignment option in '#pragma options align' - ignored">;
+def warn_pragma_align_expected_equal : Warning<
+ "expected '=' following '#pragma %select{align|options align}0' - ignored">;
+def warn_pragma_align_invalid_option : Warning<
+ "invalid alignment option in '#pragma %select{align|options align}0' - ignored">;
// - #pragma pack
def warn_pragma_pack_invalid_action : Warning<
"unknown action for '#pragma pack' - ignored">;
LParenLoc, RParenLoc);
}
-// #pragma 'options' 'align' '=' {'native','natural','mac68k','power','reset'}
-void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, Token &OptionsTok) {
- SourceLocation OptionsLoc = OptionsTok.getLocation();
-
+// #pragma 'align' '=' {'native','natural','mac68k','power','reset'}
+// #pragma 'options 'align' '=' {'native','natural','mac68k','power','reset'}
+static void ParseAlignPragma(Action &Actions, Preprocessor &PP, Token &FirstTok,
+ bool IsOptions) {
Token Tok;
- PP.Lex(Tok);
- if (Tok.isNot(tok::identifier) || !Tok.getIdentifierInfo()->isStr("align")) {
- PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_align);
- return;
+
+ if (IsOptions) {
+ PP.Lex(Tok);
+ if (Tok.isNot(tok::identifier) ||
+ !Tok.getIdentifierInfo()->isStr("align")) {
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_align);
+ return;
+ }
}
PP.Lex(Tok);
if (Tok.isNot(tok::equal)) {
- PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_equal);
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_align_expected_equal)
+ << IsOptions;
return;
}
PP.Lex(Tok);
if (Tok.isNot(tok::identifier)) {
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
- << "options";
+ << (IsOptions ? "options" : "align");
return;
}
else if (II->isStr("reset"))
Kind = Action::POAK_Reset;
else {
- PP.Diag(Tok.getLocation(), diag::warn_pragma_options_invalid_option);
+ PP.Diag(Tok.getLocation(), diag::warn_pragma_align_invalid_option)
+ << IsOptions;
return;
}
PP.Lex(Tok);
if (Tok.isNot(tok::eom)) {
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
- << "options";
+ << (IsOptions ? "options" : "align");
return;
}
- Actions.ActOnPragmaOptionsAlign(Kind, OptionsLoc, KindLoc);
+ Actions.ActOnPragmaOptionsAlign(Kind, FirstTok.getLocation(), KindLoc);
+}
+
+void PragmaAlignHandler::HandlePragma(Preprocessor &PP, Token &AlignTok) {
+ ParseAlignPragma(Actions, PP, AlignTok, /*IsOptions=*/false);
+}
+
+void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, Token &OptionsTok) {
+ ParseAlignPragma(Actions, PP, OptionsTok, /*IsOptions=*/true);
}
// #pragma unused(identifier)
// Add #pragma handlers. These are removed and destroyed in the
// destructor.
+ AlignHandler.reset(new PragmaAlignHandler(actions));
+ PP.AddPragmaHandler(AlignHandler.get());
+
OptionsHandler.reset(new PragmaOptionsHandler(actions));
PP.AddPragmaHandler(OptionsHandler.get());
delete ScopeCache[i];
// Remove the pragma handlers we installed.
+ PP.RemovePragmaHandler(AlignHandler.get());
+ AlignHandler.reset();
PP.RemovePragmaHandler(OptionsHandler.get());
OptionsHandler.reset();
PP.RemovePragmaHandler(PackHandler.get());