forked from OSchip/llvm-project
Parser: Add support for #pragma align, which is just another spelling of #pragma
options align. llvm-svn: 109952
This commit is contained in:
parent
e490460fc8
commit
cb82acb884
|
@ -374,10 +374,10 @@ def warn_pragma_extra_tokens_at_eol : Warning<
|
|||
// - #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">;
|
||||
|
|
|
@ -109,6 +109,7 @@ class Parser {
|
|||
IdentifierInfo *Ident_vector;
|
||||
IdentifierInfo *Ident_pixel;
|
||||
|
||||
llvm::OwningPtr<PragmaHandler> AlignHandler;
|
||||
llvm::OwningPtr<PragmaHandler> OptionsHandler;
|
||||
llvm::OwningPtr<PragmaHandler> PackHandler;
|
||||
llvm::OwningPtr<PragmaHandler> UnusedHandler;
|
||||
|
|
|
@ -110,27 +110,32 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP, Token &PackTok) {
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -149,7 +154,8 @@ void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, Token &OptionsTok) {
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -157,11 +163,19 @@ void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, Token &OptionsTok) {
|
|||
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)
|
||||
|
|
|
@ -20,6 +20,14 @@ namespace clang {
|
|||
class Action;
|
||||
class Parser;
|
||||
|
||||
class PragmaAlignHandler : public PragmaHandler {
|
||||
Action &Actions;
|
||||
public:
|
||||
explicit PragmaAlignHandler(Action &A) : PragmaHandler("align"), Actions(A) {}
|
||||
|
||||
virtual void HandlePragma(Preprocessor &PP, Token &FirstToken);
|
||||
};
|
||||
|
||||
class PragmaOptionsHandler : public PragmaHandler {
|
||||
Action &Actions;
|
||||
public:
|
||||
|
|
|
@ -33,6 +33,9 @@ Parser::Parser(Preprocessor &pp, Action &actions)
|
|||
|
||||
// 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());
|
||||
|
||||
|
@ -298,6 +301,8 @@ Parser::~Parser() {
|
|||
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());
|
||||
|
|
|
@ -10,3 +10,13 @@
|
|||
#pragma options align=reset
|
||||
#pragma options align=mac68k
|
||||
#pragma options align=power
|
||||
|
||||
/* expected-warning {{expected '=' following '#pragma align'}} */ #pragma align
|
||||
/* expected-warning {{expected identifier in '#pragma align'}} */ #pragma align =
|
||||
/* expected-warning {{invalid alignment option in '#pragma align'}} */ #pragma align = foo
|
||||
/* expected-warning {{extra tokens at end of '#pragma align'}} */ #pragma align = reset foo
|
||||
|
||||
#pragma align=natural
|
||||
#pragma align=reset
|
||||
#pragma align=mac68k
|
||||
#pragma align=power
|
||||
|
|
Loading…
Reference in New Issue