2008-10-04 23:21:03 +04:00
|
|
|
//===--- ParsePragma.cpp - Language specific pragma parsing ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the language specific #pragma handlers.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ParsePragma.h"
|
2012-12-04 13:13:33 +04:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2009-01-29 08:15:15 +03:00
|
|
|
#include "clang/Parse/ParseDiagnostic.h"
|
2009-03-24 01:28:25 +03:00
|
|
|
#include "clang/Parse/Parser.h"
|
2008-10-04 23:21:03 +04:00
|
|
|
using namespace clang;
|
|
|
|
|
2011-01-17 21:58:44 +03:00
|
|
|
/// \brief Handle the annotation token produced for #pragma unused(...)
|
|
|
|
///
|
|
|
|
/// Each annot_pragma_unused is followed by the argument token so e.g.
|
|
|
|
/// "#pragma unused(x,y)" becomes:
|
|
|
|
/// annot_pragma_unused 'x' annot_pragma_unused 'y'
|
|
|
|
void Parser::HandlePragmaUnused() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_unused));
|
|
|
|
SourceLocation UnusedLoc = ConsumeToken();
|
|
|
|
Actions.ActOnPragmaUnused(Tok, getCurScope(), UnusedLoc);
|
|
|
|
ConsumeToken(); // The argument token.
|
|
|
|
}
|
2010-08-05 10:57:20 +04:00
|
|
|
|
2012-01-26 06:02:57 +04:00
|
|
|
void Parser::HandlePragmaVisibility() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_vis));
|
|
|
|
const IdentifierInfo *VisType =
|
|
|
|
static_cast<IdentifierInfo *>(Tok.getAnnotationValue());
|
|
|
|
SourceLocation VisLoc = ConsumeToken();
|
|
|
|
Actions.ActOnPragmaVisibility(VisType, VisLoc);
|
|
|
|
}
|
|
|
|
|
2012-02-24 03:47:16 +04:00
|
|
|
struct PragmaPackInfo {
|
|
|
|
Sema::PragmaPackKind Kind;
|
|
|
|
IdentifierInfo *Name;
|
2012-10-04 06:36:51 +04:00
|
|
|
Token Alignment;
|
2012-02-24 03:47:16 +04:00
|
|
|
SourceLocation LParenLoc;
|
|
|
|
SourceLocation RParenLoc;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Parser::HandlePragmaPack() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_pack));
|
|
|
|
PragmaPackInfo *Info =
|
|
|
|
static_cast<PragmaPackInfo *>(Tok.getAnnotationValue());
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken();
|
2012-10-04 06:36:51 +04:00
|
|
|
ExprResult Alignment;
|
|
|
|
if (Info->Alignment.is(tok::numeric_constant)) {
|
|
|
|
Alignment = Actions.ActOnNumericConstant(Info->Alignment);
|
|
|
|
if (Alignment.isInvalid())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Actions.ActOnPragmaPack(Info->Kind, Info->Name, Alignment.get(), PragmaLoc,
|
2012-02-24 03:47:16 +04:00
|
|
|
Info->LParenLoc, Info->RParenLoc);
|
|
|
|
}
|
|
|
|
|
2012-10-04 06:36:51 +04:00
|
|
|
void Parser::HandlePragmaMSStruct() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_msstruct));
|
|
|
|
Sema::PragmaMSStructKind Kind =
|
|
|
|
static_cast<Sema::PragmaMSStructKind>(
|
|
|
|
reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));
|
|
|
|
Actions.ActOnPragmaMSStruct(Kind);
|
|
|
|
ConsumeToken(); // The annotation token.
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaAlign() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_align));
|
|
|
|
Sema::PragmaOptionsAlignKind Kind =
|
|
|
|
static_cast<Sema::PragmaOptionsAlignKind>(
|
|
|
|
reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken();
|
|
|
|
Actions.ActOnPragmaOptionsAlign(Kind, PragmaLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaWeak() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_weak));
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken();
|
|
|
|
Actions.ActOnPragmaWeakID(Tok.getIdentifierInfo(), PragmaLoc,
|
|
|
|
Tok.getLocation());
|
|
|
|
ConsumeToken(); // The weak name.
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaWeakAlias() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_weakalias));
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken();
|
|
|
|
IdentifierInfo *WeakName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation WeakNameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
IdentifierInfo *AliasName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation AliasNameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
Actions.ActOnPragmaWeakAlias(WeakName, AliasName, PragmaLoc,
|
|
|
|
WeakNameLoc, AliasNameLoc);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaRedefineExtname() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_redefine_extname));
|
|
|
|
SourceLocation RedefLoc = ConsumeToken();
|
|
|
|
IdentifierInfo *RedefName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation RedefNameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
IdentifierInfo *AliasName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation AliasNameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
Actions.ActOnPragmaRedefineExtname(RedefName, AliasName, RedefLoc,
|
|
|
|
RedefNameLoc, AliasNameLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaFPContract() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_fp_contract));
|
|
|
|
tok::OnOffSwitch OOS =
|
|
|
|
static_cast<tok::OnOffSwitch>(
|
|
|
|
reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));
|
|
|
|
Actions.ActOnPragmaFPContract(OOS);
|
|
|
|
ConsumeToken(); // The annotation token.
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
typedef llvm::PointerIntPair<IdentifierInfo *, 1, bool> OpenCLExtData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaOpenCLExtension() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_opencl_extension));
|
|
|
|
OpenCLExtData data =
|
|
|
|
OpenCLExtData::getFromOpaqueValue(Tok.getAnnotationValue());
|
|
|
|
unsigned state = data.getInt();
|
|
|
|
IdentifierInfo *ename = data.getPointer();
|
|
|
|
SourceLocation NameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken(); // The annotation token.
|
|
|
|
|
|
|
|
OpenCLOptions &f = Actions.getOpenCLOptions();
|
|
|
|
// OpenCL 1.1 9.1: "The all variant sets the behavior for all extensions,
|
|
|
|
// overriding all previously issued extension directives, but only if the
|
|
|
|
// behavior is set to disable."
|
|
|
|
if (state == 0 && ename->isStr("all")) {
|
|
|
|
#define OPENCLEXT(nm) f.nm = 0;
|
|
|
|
#include "clang/Basic/OpenCLExtensions.def"
|
|
|
|
}
|
|
|
|
#define OPENCLEXT(nm) else if (ename->isStr(#nm)) { f.nm = state; }
|
|
|
|
#include "clang/Basic/OpenCLExtensions.def"
|
|
|
|
else {
|
|
|
|
PP.Diag(NameLoc, diag::warn_pragma_unknown_extension) << ename;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-05 10:57:20 +04:00
|
|
|
// #pragma GCC visibility comes in two variants:
|
|
|
|
// 'push' '(' [visibility] ')'
|
|
|
|
// 'pop'
|
2010-09-10 02:45:38 +04:00
|
|
|
void PragmaGCCVisibilityHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &VisTok) {
|
2010-08-05 10:57:20 +04:00
|
|
|
SourceLocation VisLoc = VisTok.getLocation();
|
|
|
|
|
|
|
|
Token Tok;
|
2011-07-20 05:03:50 +04:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2010-08-05 10:57:20 +04:00
|
|
|
|
|
|
|
const IdentifierInfo *PushPop = Tok.getIdentifierInfo();
|
|
|
|
|
|
|
|
const IdentifierInfo *VisType;
|
|
|
|
if (PushPop && PushPop->isStr("pop")) {
|
|
|
|
VisType = 0;
|
|
|
|
} else if (PushPop && PushPop->isStr("push")) {
|
2011-07-20 05:03:50 +04:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2010-08-05 10:57:20 +04:00
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
2011-07-20 05:03:50 +04:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2010-08-05 10:57:20 +04:00
|
|
|
VisType = Tok.getIdentifierInfo();
|
|
|
|
if (!VisType) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
2011-07-20 05:03:50 +04:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2010-08-05 10:57:20 +04:00
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
2011-07-20 05:03:50 +04:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2011-02-28 05:37:51 +03:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2010-08-05 10:57:20 +04:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-26 06:02:57 +04:00
|
|
|
Token *Toks = new Token[1];
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_vis);
|
|
|
|
Toks[0].setLocation(VisLoc);
|
|
|
|
Toks[0].setAnnotationValue(
|
|
|
|
const_cast<void*>(static_cast<const void*>(VisType)));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/true);
|
2010-08-05 10:57:20 +04:00
|
|
|
}
|
|
|
|
|
2008-10-04 23:21:03 +04:00
|
|
|
// #pragma pack(...) comes in the following delicious flavors:
|
|
|
|
// pack '(' [integer] ')'
|
|
|
|
// pack '(' 'show' ')'
|
|
|
|
// pack '(' ('push' | 'pop') [',' identifier] [, integer] ')'
|
2010-09-10 02:45:38 +04:00
|
|
|
void PragmaPackHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &PackTok) {
|
2008-10-04 23:21:03 +04:00
|
|
|
SourceLocation PackLoc = PackTok.getLocation();
|
|
|
|
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
2009-03-24 01:28:25 +03:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "pack";
|
2008-10-04 23:21:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-27 03:41:50 +04:00
|
|
|
Sema::PragmaPackKind Kind = Sema::PPK_Default;
|
2008-10-04 23:21:03 +04:00
|
|
|
IdentifierInfo *Name = 0;
|
2012-10-04 06:36:51 +04:00
|
|
|
Token Alignment;
|
|
|
|
Alignment.startToken();
|
2008-10-04 23:21:03 +04:00
|
|
|
SourceLocation LParenLoc = Tok.getLocation();
|
2009-09-09 19:08:12 +04:00
|
|
|
PP.Lex(Tok);
|
2008-10-04 23:21:03 +04:00
|
|
|
if (Tok.is(tok::numeric_constant)) {
|
2012-10-04 06:36:51 +04:00
|
|
|
Alignment = Tok;
|
2008-10-04 23:21:03 +04:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
2011-11-02 05:53:16 +04:00
|
|
|
|
|
|
|
// In MSVC/gcc, #pragma pack(4) sets the alignment without affecting
|
|
|
|
// the push/pop stack.
|
|
|
|
// In Apple gcc, #pragma pack(4) is equivalent to #pragma pack(push, 4)
|
2012-03-11 11:00:24 +04:00
|
|
|
if (PP.getLangOpts().ApplePragmaPack)
|
2011-11-02 05:53:16 +04:00
|
|
|
Kind = Sema::PPK_Push;
|
2008-10-04 23:21:03 +04:00
|
|
|
} else if (Tok.is(tok::identifier)) {
|
|
|
|
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
2008-11-24 00:45:46 +03:00
|
|
|
if (II->isStr("show")) {
|
2010-08-27 03:41:50 +04:00
|
|
|
Kind = Sema::PPK_Show;
|
2008-10-04 23:21:03 +04:00
|
|
|
PP.Lex(Tok);
|
|
|
|
} else {
|
2008-11-24 00:45:46 +03:00
|
|
|
if (II->isStr("push")) {
|
2010-08-27 03:41:50 +04:00
|
|
|
Kind = Sema::PPK_Push;
|
2008-11-24 00:45:46 +03:00
|
|
|
} else if (II->isStr("pop")) {
|
2010-08-27 03:41:50 +04:00
|
|
|
Kind = Sema::PPK_Pop;
|
2008-10-04 23:21:03 +04:00
|
|
|
} else {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_invalid_action);
|
|
|
|
return;
|
2009-09-09 19:08:12 +04:00
|
|
|
}
|
2008-10-04 23:21:03 +04:00
|
|
|
PP.Lex(Tok);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-10-04 23:21:03 +04:00
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
PP.Lex(Tok);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-10-04 23:21:03 +04:00
|
|
|
if (Tok.is(tok::numeric_constant)) {
|
2012-10-04 06:36:51 +04:00
|
|
|
Alignment = Tok;
|
2008-10-04 23:21:03 +04:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
} else if (Tok.is(tok::identifier)) {
|
|
|
|
Name = Tok.getIdentifierInfo();
|
|
|
|
PP.Lex(Tok);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-10-04 23:21:03 +04:00
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
PP.Lex(Tok);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-10-04 23:21:03 +04:00
|
|
|
if (Tok.isNot(tok::numeric_constant)) {
|
2008-11-24 00:45:46 +03:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed);
|
2008-10-04 23:21:03 +04:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2012-10-04 06:36:51 +04:00
|
|
|
Alignment = Tok;
|
2008-10-04 23:21:03 +04:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
} else {
|
2008-11-24 00:45:46 +03:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed);
|
2008-10-04 23:21:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-11 11:00:24 +04:00
|
|
|
} else if (PP.getLangOpts().ApplePragmaPack) {
|
2011-11-02 05:53:16 +04:00
|
|
|
// In MSVC/gcc, #pragma pack() resets the alignment without affecting
|
|
|
|
// the push/pop stack.
|
|
|
|
// In Apple gcc #pragma pack() is equivalent to #pragma pack(pop).
|
|
|
|
Kind = Sema::PPK_Pop;
|
2008-12-09 16:15:23 +03:00
|
|
|
}
|
2008-10-04 23:21:03 +04:00
|
|
|
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
2009-03-24 01:28:25 +03:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen) << "pack";
|
2008-10-04 23:21:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-27 03:29:06 +04:00
|
|
|
SourceLocation RParenLoc = Tok.getLocation();
|
2009-06-05 04:49:58 +04:00
|
|
|
PP.Lex(Tok);
|
2011-02-28 05:37:51 +03:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2009-06-05 04:49:58 +04:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "pack";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-29 05:38:22 +04:00
|
|
|
PragmaPackInfo *Info =
|
|
|
|
(PragmaPackInfo*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(PragmaPackInfo), llvm::alignOf<PragmaPackInfo>());
|
|
|
|
new (Info) PragmaPackInfo();
|
2012-02-24 03:47:16 +04:00
|
|
|
Info->Kind = Kind;
|
|
|
|
Info->Name = Name;
|
2012-10-04 06:36:51 +04:00
|
|
|
Info->Alignment = Alignment;
|
2012-02-24 03:47:16 +04:00
|
|
|
Info->LParenLoc = LParenLoc;
|
|
|
|
Info->RParenLoc = RParenLoc;
|
|
|
|
|
2012-02-29 05:38:22 +04:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
2012-02-24 03:47:16 +04:00
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_pack);
|
|
|
|
Toks[0].setLocation(PackLoc);
|
|
|
|
Toks[0].setAnnotationValue(static_cast<void*>(Info));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
2012-02-29 05:38:22 +04:00
|
|
|
/*OwnsTokens=*/false);
|
2008-10-04 23:21:03 +04:00
|
|
|
}
|
|
|
|
|
2011-04-25 22:49:15 +04:00
|
|
|
// #pragma ms_struct on
|
|
|
|
// #pragma ms_struct off
|
|
|
|
void PragmaMSStructHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &MSStructTok) {
|
|
|
|
Sema::PragmaMSStructKind Kind = Sema::PMSST_OFF;
|
|
|
|
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_ms_struct);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
|
|
|
if (II->isStr("on")) {
|
|
|
|
Kind = Sema::PMSST_ON;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
else if (II->isStr("off") || II->isStr("reset"))
|
|
|
|
PP.Lex(Tok);
|
|
|
|
else {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_ms_struct);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
2012-02-29 05:38:22 +04:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< "ms_struct";
|
2011-04-25 22:49:15 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-10-04 06:36:51 +04:00
|
|
|
|
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_msstruct);
|
|
|
|
Toks[0].setLocation(MSStructTok.getLocation());
|
|
|
|
Toks[0].setAnnotationValue(reinterpret_cast<void*>(
|
|
|
|
static_cast<uintptr_t>(Kind)));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/false);
|
2011-04-25 22:49:15 +04:00
|
|
|
}
|
|
|
|
|
2010-07-31 23:17:07 +04:00
|
|
|
// #pragma 'align' '=' {'native','natural','mac68k','power','reset'}
|
|
|
|
// #pragma 'options 'align' '=' {'native','natural','mac68k','power','reset'}
|
2012-10-04 06:36:51 +04:00
|
|
|
static void ParseAlignPragma(Preprocessor &PP, Token &FirstTok,
|
2010-07-31 23:17:07 +04:00
|
|
|
bool IsOptions) {
|
2010-05-27 03:29:06 +04:00
|
|
|
Token Tok;
|
2010-07-31 23:17:07 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2010-05-27 03:29:06 +04:00
|
|
|
}
|
2010-05-27 22:42:09 +04:00
|
|
|
|
2010-05-27 03:29:06 +04:00
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::equal)) {
|
2010-07-31 23:17:07 +04:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_align_expected_equal)
|
|
|
|
<< IsOptions;
|
2010-05-27 03:29:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
2010-07-31 23:17:07 +04:00
|
|
|
<< (IsOptions ? "options" : "align");
|
2010-05-27 03:29:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-27 03:41:50 +04:00
|
|
|
Sema::PragmaOptionsAlignKind Kind = Sema::POAK_Natural;
|
2010-05-27 03:29:06 +04:00
|
|
|
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
2010-05-27 22:42:09 +04:00
|
|
|
if (II->isStr("native"))
|
2010-08-27 03:41:50 +04:00
|
|
|
Kind = Sema::POAK_Native;
|
2010-05-27 22:42:09 +04:00
|
|
|
else if (II->isStr("natural"))
|
2010-08-27 03:41:50 +04:00
|
|
|
Kind = Sema::POAK_Natural;
|
2010-05-27 22:42:17 +04:00
|
|
|
else if (II->isStr("packed"))
|
2010-08-27 03:41:50 +04:00
|
|
|
Kind = Sema::POAK_Packed;
|
2010-05-27 03:29:06 +04:00
|
|
|
else if (II->isStr("power"))
|
2010-08-27 03:41:50 +04:00
|
|
|
Kind = Sema::POAK_Power;
|
2010-05-27 03:29:06 +04:00
|
|
|
else if (II->isStr("mac68k"))
|
2010-08-27 03:41:50 +04:00
|
|
|
Kind = Sema::POAK_Mac68k;
|
2010-05-27 03:29:06 +04:00
|
|
|
else if (II->isStr("reset"))
|
2010-08-27 03:41:50 +04:00
|
|
|
Kind = Sema::POAK_Reset;
|
2010-05-27 03:29:06 +04:00
|
|
|
else {
|
2010-07-31 23:17:07 +04:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_align_invalid_option)
|
|
|
|
<< IsOptions;
|
2010-05-27 03:29:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PP.Lex(Tok);
|
2011-02-28 05:37:51 +03:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2010-05-27 03:29:06 +04:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
2010-07-31 23:17:07 +04:00
|
|
|
<< (IsOptions ? "options" : "align");
|
2010-05-27 03:29:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 06:36:51 +04:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_align);
|
|
|
|
Toks[0].setLocation(FirstTok.getLocation());
|
|
|
|
Toks[0].setAnnotationValue(reinterpret_cast<void*>(
|
|
|
|
static_cast<uintptr_t>(Kind)));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/false);
|
2010-07-31 23:17:07 +04:00
|
|
|
}
|
|
|
|
|
2010-09-10 02:45:38 +04:00
|
|
|
void PragmaAlignHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &AlignTok) {
|
2012-10-04 06:36:51 +04:00
|
|
|
ParseAlignPragma(PP, AlignTok, /*IsOptions=*/false);
|
2010-07-31 23:17:07 +04:00
|
|
|
}
|
|
|
|
|
2010-09-10 02:45:38 +04:00
|
|
|
void PragmaOptionsHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &OptionsTok) {
|
2012-10-04 06:36:51 +04:00
|
|
|
ParseAlignPragma(PP, OptionsTok, /*IsOptions=*/true);
|
2010-05-27 03:29:06 +04:00
|
|
|
}
|
|
|
|
|
2009-03-24 01:28:25 +03:00
|
|
|
// #pragma unused(identifier)
|
2010-09-10 02:45:38 +04:00
|
|
|
void PragmaUnusedHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &UnusedTok) {
|
2009-03-24 01:28:25 +03:00
|
|
|
// FIXME: Should we be expanding macros here? My guess is no.
|
|
|
|
SourceLocation UnusedLoc = UnusedTok.getLocation();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-24 01:28:25 +03:00
|
|
|
// Lex the left '('.
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "unused";
|
|
|
|
return;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-24 01:28:25 +03:00
|
|
|
// Lex the declaration reference(s).
|
2011-07-23 14:55:15 +04:00
|
|
|
SmallVector<Token, 5> Identifiers;
|
2009-03-24 01:28:25 +03:00
|
|
|
SourceLocation RParenLoc;
|
|
|
|
bool LexID = true;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-24 01:28:25 +03:00
|
|
|
while (true) {
|
|
|
|
PP.Lex(Tok);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-24 01:28:25 +03:00
|
|
|
if (LexID) {
|
2009-09-09 19:08:12 +04:00
|
|
|
if (Tok.is(tok::identifier)) {
|
2009-08-04 03:24:57 +04:00
|
|
|
Identifiers.push_back(Tok);
|
2009-03-24 01:28:25 +03:00
|
|
|
LexID = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-04 03:24:57 +04:00
|
|
|
// Illegal token!
|
2009-03-24 01:28:25 +03:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_var);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-24 01:28:25 +03:00
|
|
|
// We are execting a ')' or a ','.
|
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
LexID = true;
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-24 01:28:25 +03:00
|
|
|
if (Tok.is(tok::r_paren)) {
|
|
|
|
RParenLoc = Tok.getLocation();
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-04 03:24:57 +04:00
|
|
|
// Illegal token!
|
2009-03-24 01:28:25 +03:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_punc);
|
|
|
|
return;
|
|
|
|
}
|
2009-06-05 04:49:58 +04:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
2011-02-28 05:37:51 +03:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2009-06-05 04:49:58 +04:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
|
|
|
|
"unused";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-24 01:28:25 +03:00
|
|
|
// Verify that we have a location for the right parenthesis.
|
|
|
|
assert(RParenLoc.isValid() && "Valid '#pragma unused' must have ')'");
|
2009-08-04 03:24:57 +04:00
|
|
|
assert(!Identifiers.empty() && "Valid '#pragma unused' must have arguments");
|
2009-03-24 01:28:25 +03:00
|
|
|
|
2011-01-17 21:58:44 +03:00
|
|
|
// For each identifier token, insert into the token stream a
|
|
|
|
// annot_pragma_unused token followed by the identifier token.
|
|
|
|
// This allows us to cache a "#pragma unused" that occurs inside an inline
|
|
|
|
// C++ member function.
|
|
|
|
|
2012-02-29 05:38:22 +04:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 2 * Identifiers.size(), llvm::alignOf<Token>());
|
2011-01-17 21:58:44 +03:00
|
|
|
for (unsigned i=0; i != Identifiers.size(); i++) {
|
|
|
|
Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
|
|
|
|
pragmaUnusedTok.startToken();
|
|
|
|
pragmaUnusedTok.setKind(tok::annot_pragma_unused);
|
|
|
|
pragmaUnusedTok.setLocation(UnusedLoc);
|
|
|
|
idTok = Identifiers[i];
|
|
|
|
}
|
2012-02-29 05:38:22 +04:00
|
|
|
PP.EnterTokenStream(Toks, 2*Identifiers.size(),
|
|
|
|
/*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
|
2009-03-24 01:28:25 +03:00
|
|
|
}
|
2009-06-05 04:49:58 +04:00
|
|
|
|
|
|
|
// #pragma weak identifier
|
|
|
|
// #pragma weak identifier '=' identifier
|
2010-09-10 02:45:38 +04:00
|
|
|
void PragmaWeakHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &WeakTok) {
|
2009-06-05 04:49:58 +04:00
|
|
|
SourceLocation WeakLoc = WeakTok.getLocation();
|
|
|
|
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) << "weak";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 06:36:51 +04:00
|
|
|
Token WeakName = Tok;
|
|
|
|
bool HasAlias = false;
|
|
|
|
Token AliasName;
|
2009-06-05 04:49:58 +04:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.is(tok::equal)) {
|
2012-10-04 06:36:51 +04:00
|
|
|
HasAlias = true;
|
2009-06-05 04:49:58 +04:00
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
2009-09-09 19:08:12 +04:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
2009-06-05 04:49:58 +04:00
|
|
|
<< "weak";
|
|
|
|
return;
|
|
|
|
}
|
2012-10-04 06:36:51 +04:00
|
|
|
AliasName = Tok;
|
2009-06-05 04:49:58 +04:00
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
|
2011-02-28 05:37:51 +03:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2009-06-05 04:49:58 +04:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "weak";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 06:36:51 +04:00
|
|
|
if (HasAlias) {
|
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 3, llvm::alignOf<Token>());
|
|
|
|
Token &pragmaUnusedTok = Toks[0];
|
|
|
|
pragmaUnusedTok.startToken();
|
|
|
|
pragmaUnusedTok.setKind(tok::annot_pragma_weakalias);
|
|
|
|
pragmaUnusedTok.setLocation(WeakLoc);
|
|
|
|
Toks[1] = WeakName;
|
|
|
|
Toks[2] = AliasName;
|
|
|
|
PP.EnterTokenStream(Toks, 3,
|
|
|
|
/*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
|
2009-06-05 04:49:58 +04:00
|
|
|
} else {
|
2012-10-04 06:36:51 +04:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 2, llvm::alignOf<Token>());
|
|
|
|
Token &pragmaUnusedTok = Toks[0];
|
|
|
|
pragmaUnusedTok.startToken();
|
|
|
|
pragmaUnusedTok.setKind(tok::annot_pragma_weak);
|
|
|
|
pragmaUnusedTok.setLocation(WeakLoc);
|
|
|
|
Toks[1] = WeakName;
|
|
|
|
PP.EnterTokenStream(Toks, 2,
|
|
|
|
/*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
|
2009-06-05 04:49:58 +04:00
|
|
|
}
|
|
|
|
}
|
2011-02-14 04:42:35 +03:00
|
|
|
|
2012-02-18 20:12:34 +04:00
|
|
|
// #pragma redefine_extname identifier identifier
|
|
|
|
void PragmaRedefineExtnameHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &RedefToken) {
|
|
|
|
SourceLocation RedefLoc = RedefToken.getLocation();
|
|
|
|
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) <<
|
|
|
|
"redefine_extname";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 06:36:51 +04:00
|
|
|
Token RedefName = Tok;
|
2012-02-18 20:12:34 +04:00
|
|
|
PP.Lex(Tok);
|
2012-10-04 06:36:51 +04:00
|
|
|
|
2012-02-18 20:12:34 +04:00
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
|
|
|
<< "redefine_extname";
|
|
|
|
return;
|
|
|
|
}
|
2012-10-04 06:36:51 +04:00
|
|
|
|
|
|
|
Token AliasName = Tok;
|
2012-02-18 20:12:34 +04:00
|
|
|
PP.Lex(Tok);
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
|
|
|
|
"redefine_extname";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 06:36:51 +04:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 3, llvm::alignOf<Token>());
|
|
|
|
Token &pragmaRedefTok = Toks[0];
|
|
|
|
pragmaRedefTok.startToken();
|
|
|
|
pragmaRedefTok.setKind(tok::annot_pragma_redefine_extname);
|
|
|
|
pragmaRedefTok.setLocation(RedefLoc);
|
|
|
|
Toks[1] = RedefName;
|
|
|
|
Toks[2] = AliasName;
|
|
|
|
PP.EnterTokenStream(Toks, 3,
|
|
|
|
/*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
|
2012-02-18 20:12:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-14 04:42:35 +03:00
|
|
|
void
|
|
|
|
PragmaFPContractHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
|
|
|
tok::OnOffSwitch OOS;
|
|
|
|
if (PP.LexOnOffSwitch(OOS))
|
|
|
|
return;
|
|
|
|
|
2012-10-04 06:36:51 +04:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_fp_contract);
|
|
|
|
Toks[0].setLocation(Tok.getLocation());
|
|
|
|
Toks[0].setAnnotationValue(reinterpret_cast<void*>(
|
|
|
|
static_cast<uintptr_t>(OOS)));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/false);
|
2011-02-14 04:42:35 +03:00
|
|
|
}
|
2011-02-14 04:42:53 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
PragmaOpenCLExtensionHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
2011-04-15 03:35:31 +04:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2011-02-14 04:42:53 +03:00
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) <<
|
|
|
|
"OPENCL";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IdentifierInfo *ename = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation NameLoc = Tok.getLocation();
|
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::colon)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_colon) << ename;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_enable_disable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IdentifierInfo *op = Tok.getIdentifierInfo();
|
|
|
|
|
|
|
|
unsigned state;
|
|
|
|
if (op->isStr("enable")) {
|
|
|
|
state = 1;
|
|
|
|
} else if (op->isStr("disable")) {
|
|
|
|
state = 0;
|
|
|
|
} else {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_enable_disable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 06:36:51 +04:00
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
|
|
|
|
"OPENCL EXTENSION";
|
2011-02-14 04:42:53 +03:00
|
|
|
return;
|
|
|
|
}
|
2012-10-04 06:36:51 +04:00
|
|
|
|
|
|
|
OpenCLExtData data(ename, state);
|
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_opencl_extension);
|
|
|
|
Toks[0].setLocation(NameLoc);
|
|
|
|
Toks[0].setAnnotationValue(data.getOpaqueValue());
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/false);
|
2011-02-14 04:42:53 +03:00
|
|
|
}
|
|
|
|
|
2013-03-22 10:34:35 +04:00
|
|
|
/// \brief Handle '#pragma omp ...' when OpenMP is disabled.
|
|
|
|
///
|
|
|
|
void
|
|
|
|
PragmaNoOpenMPHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstTok) {
|
|
|
|
if (PP.getDiagnostics().getDiagnosticLevel(diag::warn_pragma_omp_ignored,
|
|
|
|
FirstTok.getLocation()) !=
|
|
|
|
DiagnosticsEngine::Ignored) {
|
|
|
|
PP.Diag(FirstTok, diag::warn_pragma_omp_ignored);
|
|
|
|
PP.getDiagnostics().setDiagnosticMapping(diag::warn_pragma_omp_ignored,
|
|
|
|
diag::MAP_IGNORE,
|
|
|
|
SourceLocation());
|
|
|
|
}
|
|
|
|
PP.DiscardUntilEndOfDirective();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Handle '#pragma omp ...' when OpenMP is enabled.
|
|
|
|
///
|
|
|
|
void
|
|
|
|
PragmaOpenMPHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstTok) {
|
|
|
|
SmallVector<Token, 16> Pragma;
|
|
|
|
Token Tok;
|
|
|
|
Tok.startToken();
|
|
|
|
Tok.setKind(tok::annot_pragma_openmp);
|
|
|
|
Tok.setLocation(FirstTok.getLocation());
|
|
|
|
|
|
|
|
while (Tok.isNot(tok::eod)) {
|
|
|
|
Pragma.push_back(Tok);
|
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
SourceLocation EodLoc = Tok.getLocation();
|
|
|
|
Tok.startToken();
|
|
|
|
Tok.setKind(tok::annot_pragma_openmp_end);
|
|
|
|
Tok.setLocation(EodLoc);
|
|
|
|
Pragma.push_back(Tok);
|
|
|
|
|
|
|
|
Token *Toks = new Token[Pragma.size()];
|
|
|
|
std::copy(Pragma.begin(), Pragma.end(), Toks);
|
|
|
|
PP.EnterTokenStream(Toks, Pragma.size(),
|
|
|
|
/*DisableMacroExpansion=*/true, /*OwnsTokens=*/true);
|
|
|
|
}
|