diff options
author | Anders Carlsson <andersca@mac.com> | 2010-10-20 02:31:43 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-10-20 02:31:43 +0000 |
commit | 274a70ed7f4315c83273173fce4c3b0e097958d6 (patch) | |
tree | fccdd5042be19eff3d1c109477cdf047af8c70b8 /clang/lib/Lex | |
parent | 23c8341c3dfbb9b453cc3857eabc2405207887cf (diff) | |
download | bcm5719-llvm-274a70ed7f4315c83273173fce4c3b0e097958d6.tar.gz bcm5719-llvm-274a70ed7f4315c83273173fce4c3b0e097958d6.zip |
Add a __has_attribute macro that works much like __has_feature and __has_builtin.
llvm-svn: 116906
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r-- | clang/lib/Lex/CMakeLists.txt | 2 | ||||
-rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 16 |
2 files changed, 15 insertions, 3 deletions
diff --git a/clang/lib/Lex/CMakeLists.txt b/clang/lib/Lex/CMakeLists.txt index 0476384eff3..aa2c93af8ba 100644 --- a/clang/lib/Lex/CMakeLists.txt +++ b/clang/lib/Lex/CMakeLists.txt @@ -26,4 +26,4 @@ add_clang_library(clangLex TokenLexer.cpp ) -add_dependencies(clangLex ClangDiagnosticLex) +add_dependencies(clangLex ClangDiagnosticLex ClangAttrSpellings) diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 24a0f39b05d..19a6ca85211 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -70,6 +70,7 @@ void Preprocessor::RegisterBuiltinMacros() { // Clang Extensions. Ident__has_feature = RegisterBuiltinMacro(*this, "__has_feature"); Ident__has_builtin = RegisterBuiltinMacro(*this, "__has_builtin"); + Ident__has_attribute = RegisterBuiltinMacro(*this, "__has_attribute"); Ident__has_include = RegisterBuiltinMacro(*this, "__has_include"); Ident__has_include_next = RegisterBuiltinMacro(*this, "__has_include_next"); @@ -535,6 +536,14 @@ static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) { .Default(false); } +/// HasAttribute - Return true if we recognize and implement the attribute +/// specified by the given identifier. +static bool HasAttribute(const IdentifierInfo *II) { + return llvm::StringSwitch<bool>(II->getName()) +#include "clang/Lex/AttrSpellings.inc" + .Default(false); +} + /// EvaluateHasIncludeCommon - Process a '__has_include("path")' /// or '__has_include_next("path")' expression. /// Returns true if successful. @@ -767,7 +776,8 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { OS << CounterValue++; Tok.setKind(tok::numeric_constant); } else if (II == Ident__has_feature || - II == Ident__has_builtin) { + II == Ident__has_builtin || + II == Ident__has_attribute) { // The argument to these two builtins should be a parenthesized identifier. SourceLocation StartLoc = Tok.getLocation(); @@ -795,7 +805,9 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { else if (II == Ident__has_builtin) { // Check for a builtin is trivial. Value = FeatureII->getBuiltinID() != 0; - } else { + } else if (II == Ident__has_attribute) + Value = HasAttribute(FeatureII); + else { assert(II == Ident__has_feature && "Must be feature check"); Value = HasFeature(*this, FeatureII); } |