forked from OSchip/llvm-project
Parse: Add support for '#pragma options align'.
Also, fix a source location bug with the rparen in #pragma pack. llvm-svn: 104784
This commit is contained in:
parent
d67defdfe2
commit
75c9be7e80
|
@ -363,6 +363,13 @@ def warn_pragma_expected_identifier : Warning<
|
|||
"expected identifier in '#pragma %0' - ignored">;
|
||||
def warn_pragma_extra_tokens_at_eol : Warning<
|
||||
"extra tokens at end of '#pragma %0' - ignored">;
|
||||
// - #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">;
|
||||
// - #pragma pack
|
||||
def warn_pragma_pack_invalid_action : Warning<
|
||||
"unknown action for '#pragma pack' - ignored">;
|
||||
|
|
|
@ -2564,6 +2564,21 @@ public:
|
|||
|
||||
//===---------------------------- Pragmas -------------------------------===//
|
||||
|
||||
enum PragmaOptionsAlignKind {
|
||||
POAK_Natural, // #pragma options align=natural
|
||||
POAK_Power, // #pragma options align=power
|
||||
POAK_Mac68k, // #pragma options align=mac68k
|
||||
POAK_Reset // #pragma options align=reset
|
||||
};
|
||||
|
||||
/// ActOnPragmaOptionsAlign - Called on well formed #pragma options
|
||||
/// align={...}.
|
||||
virtual void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
|
||||
SourceLocation PragmaLoc,
|
||||
SourceLocation KindLoc) {
|
||||
return;
|
||||
}
|
||||
|
||||
enum PragmaPackKind {
|
||||
PPK_Default, // #pragma pack([n])
|
||||
PPK_Show, // #pragma pack(show), only supported by MSVC.
|
||||
|
|
|
@ -110,6 +110,7 @@ class Parser {
|
|||
IdentifierInfo *Ident_vector;
|
||||
IdentifierInfo *Ident_pixel;
|
||||
|
||||
llvm::OwningPtr<PragmaHandler> OptionsHandler;
|
||||
llvm::OwningPtr<PragmaHandler> PackHandler;
|
||||
llvm::OwningPtr<PragmaHandler> UnusedHandler;
|
||||
llvm::OwningPtr<PragmaHandler> WeakHandler;
|
||||
|
|
|
@ -23,7 +23,6 @@ using namespace clang;
|
|||
// pack '(' 'show' ')'
|
||||
// pack '(' ('push' | 'pop') [',' identifier] [, integer] ')'
|
||||
void PragmaPackHandler::HandlePragma(Preprocessor &PP, Token &PackTok) {
|
||||
// FIXME: Should we be expanding macros here? My guess is no.
|
||||
SourceLocation PackLoc = PackTok.getLocation();
|
||||
|
||||
Token Tok;
|
||||
|
@ -100,17 +99,67 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP, Token &PackTok) {
|
|||
return;
|
||||
}
|
||||
|
||||
SourceLocation RParenLoc = Tok.getLocation();
|
||||
PP.Lex(Tok);
|
||||
if (Tok.isNot(tok::eom)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "pack";
|
||||
return;
|
||||
}
|
||||
|
||||
SourceLocation RParenLoc = Tok.getLocation();
|
||||
Actions.ActOnPragmaPack(Kind, Name, Alignment.release(), PackLoc,
|
||||
LParenLoc, RParenLoc);
|
||||
}
|
||||
|
||||
// #pragma 'options' 'align' '=' {'natural', 'mac68k', 'power', 'reset'}
|
||||
void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, Token &OptionsTok) {
|
||||
SourceLocation OptionsLoc = OptionsTok.getLocation();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
PP.Lex(Tok);
|
||||
if (Tok.isNot(tok::equal)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_equal);
|
||||
return;
|
||||
}
|
||||
|
||||
PP.Lex(Tok);
|
||||
if (Tok.isNot(tok::identifier)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
||||
<< "options";
|
||||
return;
|
||||
}
|
||||
|
||||
Action::PragmaOptionsAlignKind Kind = Action::POAK_Natural;
|
||||
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
||||
if (II->isStr("natural"))
|
||||
Kind = Action::POAK_Natural;
|
||||
else if (II->isStr("power"))
|
||||
Kind = Action::POAK_Power;
|
||||
else if (II->isStr("mac68k"))
|
||||
Kind = Action::POAK_Mac68k;
|
||||
else if (II->isStr("reset"))
|
||||
Kind = Action::POAK_Reset;
|
||||
else {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_options_invalid_option);
|
||||
return;
|
||||
}
|
||||
|
||||
SourceLocation KindLoc = Tok.getLocation();
|
||||
PP.Lex(Tok);
|
||||
if (Tok.isNot(tok::eom)) {
|
||||
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
||||
<< "options";
|
||||
return;
|
||||
}
|
||||
|
||||
Actions.ActOnPragmaOptionsAlign(Kind, OptionsLoc, KindLoc);
|
||||
}
|
||||
|
||||
// #pragma unused(identifier)
|
||||
void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, Token &UnusedTok) {
|
||||
// FIXME: Should we be expanding macros here? My guess is no.
|
||||
|
|
|
@ -20,6 +20,15 @@ namespace clang {
|
|||
class Action;
|
||||
class Parser;
|
||||
|
||||
class PragmaOptionsHandler : public PragmaHandler {
|
||||
Action &Actions;
|
||||
public:
|
||||
PragmaOptionsHandler(const IdentifierInfo *N, Action &A) : PragmaHandler(N),
|
||||
Actions(A) {}
|
||||
|
||||
virtual void HandlePragma(Preprocessor &PP, Token &FirstToken);
|
||||
};
|
||||
|
||||
class PragmaPackHandler : public PragmaHandler {
|
||||
Action &Actions;
|
||||
public:
|
||||
|
|
|
@ -33,6 +33,11 @@ Parser::Parser(Preprocessor &pp, Action &actions)
|
|||
|
||||
// Add #pragma handlers. These are removed and destroyed in the
|
||||
// destructor.
|
||||
OptionsHandler.reset(new
|
||||
PragmaOptionsHandler(&PP.getIdentifierTable().get("options"),
|
||||
actions));
|
||||
PP.AddPragmaHandler(0, OptionsHandler.get());
|
||||
|
||||
PackHandler.reset(new
|
||||
PragmaPackHandler(&PP.getIdentifierTable().get("pack"), actions));
|
||||
PP.AddPragmaHandler(0, PackHandler.get());
|
||||
|
@ -298,6 +303,8 @@ Parser::~Parser() {
|
|||
delete ScopeCache[i];
|
||||
|
||||
// Remove the pragma handlers we installed.
|
||||
PP.RemovePragmaHandler(0, OptionsHandler.get());
|
||||
OptionsHandler.reset();
|
||||
PP.RemovePragmaHandler(0, PackHandler.get());
|
||||
PackHandler.reset();
|
||||
PP.RemovePragmaHandler(0, UnusedHandler.get());
|
||||
|
|
Loading…
Reference in New Issue