254
254
"Invalid string token!");
256
256
// Remove escaped quotes and escapes.
257
for (unsigned i = 1, e = StrVal.size(); i < e-2; ++i) {
258
if (StrVal[i] == '\\' &&
259
(StrVal[i+1] == '\\' || StrVal[i+1] == '"')) {
257
unsigned ResultPos = 1;
258
for (unsigned i = 1, e = StrVal.size() - 2; i != e; ++i) {
259
if (StrVal[i] != '\\' ||
260
(StrVal[i + 1] != '\\' && StrVal[i + 1] != '"')) {
260
261
// \\ -> '\' and \" -> '"'.
261
StrVal.erase(StrVal.begin()+i);
262
StrVal[ResultPos++] = StrVal[i];
265
StrVal.erase(StrVal.begin() + ResultPos, StrVal.end() - 2);
267
268
// Remove the front quote, replacing it with a space, so that the pragma
495
/// \brief Handle the microsoft \#pragma comment extension.
499
/// #pragma comment(linker, "foo")
501
/// 'linker' is one of five identifiers: compiler, exestr, lib, linker, user.
502
/// "foo" is a string, which is fully macro expanded, and permits string
503
/// concatenation, embedded escape characters etc. See MSDN for more details.
504
void Preprocessor::HandlePragmaComment(Token &Tok) {
505
SourceLocation CommentLoc = Tok.getLocation();
507
if (Tok.isNot(tok::l_paren)) {
508
Diag(CommentLoc, diag::err_pragma_comment_malformed);
512
// Read the identifier.
514
if (Tok.isNot(tok::identifier)) {
515
Diag(CommentLoc, diag::err_pragma_comment_malformed);
519
// Verify that this is one of the 5 whitelisted options.
520
// FIXME: warn that 'exestr' is deprecated.
521
const IdentifierInfo *II = Tok.getIdentifierInfo();
522
if (!II->isStr("compiler") && !II->isStr("exestr") && !II->isStr("lib") &&
523
!II->isStr("linker") && !II->isStr("user")) {
524
Diag(Tok.getLocation(), diag::err_pragma_comment_unknown_kind);
528
// Read the optional string if present.
530
std::string ArgumentString;
531
if (Tok.is(tok::comma) && !LexStringLiteral(Tok, ArgumentString,
533
/*MacroExpansion=*/true))
536
// FIXME: If the kind is "compiler" warn if the string is present (it is
538
// FIXME: 'lib' requires a comment string.
539
// FIXME: 'linker' requires a comment string, and has a specific list of
540
// things that are allowable.
542
if (Tok.isNot(tok::r_paren)) {
543
Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
546
Lex(Tok); // eat the r_paren.
548
if (Tok.isNot(tok::eod)) {
549
Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
553
// If the pragma is lexically sound, notify any interested PPCallbacks.
555
Callbacks->PragmaComment(CommentLoc, II, ArgumentString);
558
/// ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
496
/// ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
559
497
/// Return the IdentifierInfo* associated with the macro to push or pop.
560
498
IdentifierInfo *Preprocessor::ParsePragmaPushOrPopMacro(Token &Tok) {
561
499
// Remember the pragma token location.
1064
/// PragmaCommentHandler - "\#pragma comment ...".
1065
struct PragmaCommentHandler : public PragmaHandler {
1066
PragmaCommentHandler() : PragmaHandler("comment") {}
1067
virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1068
Token &CommentTok) {
1069
PP.HandlePragmaComment(CommentTok);
1073
1002
/// PragmaIncludeAliasHandler - "\#pragma include_alias("...")".
1074
1003
struct PragmaIncludeAliasHandler : public PragmaHandler {
1075
1004
PragmaIncludeAliasHandler() : PragmaHandler("include_alias") {}