diff options
Diffstat (limited to 'lib/Lex/PPMacroExpansion.cpp')
-rw-r--r-- | lib/Lex/PPMacroExpansion.cpp | 72 |
1 files changed, 32 insertions, 40 deletions
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index dfb14ff..3792782 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -18,6 +18,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/FileManager.h" #include "clang/Lex/LexDiagnostic.h" +#include "llvm/ADT/StringSwitch.h" #include <cstdio> #include <ctime> using namespace clang; @@ -481,34 +482,27 @@ static void ComputeDATE_TIME(SourceLocation &DATELoc, SourceLocation &TIMELoc, static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) { const LangOptions &LangOpts = PP.getLangOptions(); - switch (II->getLength()) { - default: return false; - case 6: - if (II->isStr("blocks")) return LangOpts.Blocks; - return false; - case 8: - if (II->isStr("cxx_rtti")) return LangOpts.RTTI; - return false; - case 14: - if (II->isStr("cxx_exceptions")) return LangOpts.Exceptions; - return false; - case 19: - if (II->isStr("objc_nonfragile_abi")) return LangOpts.ObjCNonFragileABI; - return false; - case 22: - if (II->isStr("attribute_overloadable")) return true; - return false; - case 25: - if (II->isStr("attribute_ext_vector_type")) return true; - return false; - case 27: - if (II->isStr("attribute_analyzer_noreturn")) return true; - return false; - case 29: - if (II->isStr("attribute_ns_returns_retained")) return true; - if (II->isStr("attribute_cf_returns_retained")) return true; - return false; - } + return llvm::StringSwitch<bool>(II->getName()) + .Case("blocks", LangOpts.Blocks) + .Case("cxx_rtti", LangOpts.RTTI) + //.Case("cxx_lambdas", false) + //.Case("cxx_nullptr", false) + //.Case("cxx_concepts", false) + .Case("cxx_decltype", LangOpts.CPlusPlus0x) + .Case("cxx_auto_type", LangOpts.CPlusPlus0x) + .Case("cxx_exceptions", LangOpts.Exceptions) + .Case("cxx_attributes", LangOpts.CPlusPlus0x) + .Case("cxx_static_assert", LangOpts.CPlusPlus0x) + .Case("objc_nonfragile_abi", LangOpts.ObjCNonFragileABI) + .Case("cxx_deleted_functions", LangOpts.CPlusPlus0x) + //.Case("cxx_rvalue_references", false) + .Case("attribute_overloadable", true) + //.Case("cxx_variadic_templates", false) + .Case("attribute_ext_vector_type", true) + .Case("attribute_analyzer_noreturn", true) + .Case("attribute_ns_returns_retained", true) + .Case("attribute_cf_returns_retained", true) + .Default(false); } /// EvaluateHasIncludeCommon - Process a '__has_include("path")' @@ -535,8 +529,8 @@ static bool EvaluateHasIncludeCommon(bool &Result, Token &Tok, PP.getCurrentLexer()->LexIncludeFilename(Tok); // Reserve a buffer to get the spelling. - llvm::SmallVector<char, 128> FilenameBuffer; - const char *FilenameStart, *FilenameEnd; + llvm::SmallString<128> FilenameBuffer; + llvm::StringRef Filename; switch (Tok.getKind()) { case tok::eom: @@ -546,9 +540,9 @@ static bool EvaluateHasIncludeCommon(bool &Result, Token &Tok, case tok::angle_string_literal: case tok::string_literal: { FilenameBuffer.resize(Tok.getLength()); - FilenameStart = &FilenameBuffer[0]; + const char *FilenameStart = &FilenameBuffer[0]; unsigned Len = PP.getSpelling(Tok, FilenameStart); - FilenameEnd = FilenameStart+Len; + Filename = llvm::StringRef(FilenameStart, Len); break; } @@ -558,26 +552,24 @@ static bool EvaluateHasIncludeCommon(bool &Result, Token &Tok, FilenameBuffer.push_back('<'); if (PP.ConcatenateIncludeName(FilenameBuffer)) return false; // Found <eom> but no ">"? Diagnostic already emitted. - FilenameStart = FilenameBuffer.data(); - FilenameEnd = FilenameStart + FilenameBuffer.size(); + Filename = FilenameBuffer.str(); break; default: PP.Diag(Tok.getLocation(), diag::err_pp_expects_filename); return false; } - bool isAngled = PP.GetIncludeFilenameSpelling(Tok.getLocation(), - FilenameStart, FilenameEnd); + bool isAngled = PP.GetIncludeFilenameSpelling(Tok.getLocation(), Filename); // If GetIncludeFilenameSpelling set the start ptr to null, there was an // error. - if (FilenameStart == 0) { + if (Filename.empty()) return false; - } // Search include directories. const DirectoryLookup *CurDir; - const FileEntry *File = PP.LookupFile(FilenameStart, FilenameEnd, - isAngled, LookupFrom, CurDir); + const FileEntry *File = PP.LookupFile(Filename, + SourceLocation(),// produce no warnings. + isAngled, LookupFrom, CurDir); // Get the result value. Result = true means the file exists. Result = File != 0; |