~ubuntu-branches/ubuntu/trusty/llvm-toolchain-snapshot/trusty-201310232150

« back to all changes in this revision

Viewing changes to clang/lib/Lex/Pragma.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-27 15:01:57 UTC
  • mfrom: (0.10.1) (0.9.1) (0.8.1) (0.7.1) (0.6.1) (0.5.2)
  • Revision ID: package-import@ubuntu.com-20130527150157-tdkrsjpuvht7v0qx
Tags: 1:3.4~svn182733-1~exp1
* New snapshot release (3.4 release)
* Add a symlink of libLLVM-3.4.so.1 to usr/lib/llvm-3.4/lib/libLLVM-3.4.so
    to fix make the llvm-config-3.4 --libdir work (Closes: #708677)
  * Various packages rename to allow co installations:
    * libclang1 => libclang1-3.4
    * libclang1-dbg => libclang1-3.4-dbg
    * libclang-dev => libclang-3.4-dev
    * libclang-common-dev => libclang-common-3.4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
254
254
           "Invalid string token!");
255
255
 
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
 
        --e;
 
262
        StrVal[ResultPos++] = StrVal[i];
263
263
      }
264
264
    }
 
265
    StrVal.erase(StrVal.begin() + ResultPos, StrVal.end() - 2);
265
266
  }
266
267
 
267
268
  // Remove the front quote, replacing it with a space, so that the pragma
492
493
  }
493
494
}
494
495
 
495
 
/// \brief Handle the microsoft \#pragma comment extension.
496
 
///
497
 
/// The syntax is:
498
 
/// \code
499
 
///   #pragma comment(linker, "foo")
500
 
/// \endcode
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();
506
 
  Lex(Tok);
507
 
  if (Tok.isNot(tok::l_paren)) {
508
 
    Diag(CommentLoc, diag::err_pragma_comment_malformed);
509
 
    return;
510
 
  }
511
 
 
512
 
  // Read the identifier.
513
 
  Lex(Tok);
514
 
  if (Tok.isNot(tok::identifier)) {
515
 
    Diag(CommentLoc, diag::err_pragma_comment_malformed);
516
 
    return;
517
 
  }
518
 
 
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);
525
 
    return;
526
 
  }
527
 
 
528
 
  // Read the optional string if present.
529
 
  Lex(Tok);
530
 
  std::string ArgumentString;
531
 
  if (Tok.is(tok::comma) && !LexStringLiteral(Tok, ArgumentString,
532
 
                                              "pragma comment",
533
 
                                              /*MacroExpansion=*/true))
534
 
    return;
535
 
 
536
 
  // FIXME: If the kind is "compiler" warn if the string is present (it is
537
 
  // ignored).
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.
541
 
 
542
 
  if (Tok.isNot(tok::r_paren)) {
543
 
    Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
544
 
    return;
545
 
  }
546
 
  Lex(Tok);  // eat the r_paren.
547
 
 
548
 
  if (Tok.isNot(tok::eod)) {
549
 
    Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
550
 
    return;
551
 
  }
552
 
 
553
 
  // If the pragma is lexically sound, notify any interested PPCallbacks.
554
 
  if (Callbacks)
555
 
    Callbacks->PragmaComment(CommentLoc, II, ArgumentString);
556
 
}
557
 
 
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.
1061
999
  }
1062
1000
};
1063
1001
 
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);
1070
 
  }
1071
 
};
1072
 
 
1073
1002
/// PragmaIncludeAliasHandler - "\#pragma include_alias("...")".
1074
1003
struct PragmaIncludeAliasHandler : public PragmaHandler {
1075
1004
  PragmaIncludeAliasHandler() : PragmaHandler("include_alias") {}
1333
1262
 
1334
1263
  // MS extensions.
1335
1264
  if (LangOpts.MicrosoftExt) {
1336
 
    AddPragmaHandler(new PragmaCommentHandler());
1337
1265
    AddPragmaHandler(new PragmaIncludeAliasHandler());
1338
1266
    AddPragmaHandler(new PragmaRegionHandler("region"));
1339
1267
    AddPragmaHandler(new PragmaRegionHandler("endregion"));