aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c-family/c-lex.c')
-rw-r--r--gcc/c-family/c-lex.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index d2c231c..357d137 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -37,6 +37,8 @@ along with GCC; see the file COPYING3. If not see
#include "target.h"
#include "wide-int.h"
+#include "attribs.h"
+
/* We may keep statistics about how long which files took to compile. */
static int header_time, body_time;
static splay_tree file_info_tree;
@@ -62,6 +64,7 @@ static void cb_ident (cpp_reader *, unsigned int, const cpp_string *);
static void cb_def_pragma (cpp_reader *, unsigned int);
static void cb_define (cpp_reader *, unsigned int, cpp_hashnode *);
static void cb_undef (cpp_reader *, unsigned int, cpp_hashnode *);
+static int cb_has_attribute (cpp_reader *);
void
init_c_lex (void)
@@ -86,6 +89,7 @@ init_c_lex (void)
cb->def_pragma = cb_def_pragma;
cb->valid_pch = c_common_valid_pch;
cb->read_pch = c_common_read_pch;
+ cb->has_attribute = cb_has_attribute;
/* Set the debug callbacks if we can use them. */
if ((debug_info_level == DINFO_LEVEL_VERBOSE
@@ -283,6 +287,75 @@ cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc,
(*debug_hooks->undef) (SOURCE_LINE (map, loc),
(const char *) NODE_NAME (node));
}
+
+/* Callback for has_attribute. */
+static int
+cb_has_attribute (cpp_reader *pfile)
+{
+ int result = 0;
+ bool paren = false;
+ tree attr_ns = NULL_TREE, attr_id = NULL_TREE, attr_name = NULL_TREE;
+ const cpp_token *token;
+
+ token = cpp_get_token (pfile);
+ if (token->type == CPP_OPEN_PAREN)
+ {
+ paren = true;
+ token = cpp_get_token (pfile);
+ }
+
+ if (token->type == CPP_NAME)
+ {
+ //node = token->val.node.node;
+ const cpp_token *nxt_token = cpp_peek_token (pfile, 0);
+ if (c_dialect_cxx() && nxt_token->type == CPP_SCOPE)
+ {
+ nxt_token = cpp_get_token (pfile); // Eat scope.
+ nxt_token = cpp_get_token (pfile);
+ if (nxt_token->type == CPP_NAME)
+ {
+ attr_ns = get_identifier (
+ (const char *) cpp_token_as_text (pfile, token));
+ attr_id = get_identifier (
+ (const char *) cpp_token_as_text (pfile, nxt_token));
+ attr_name = build_tree_list (attr_ns, attr_id);
+ }
+ else
+ cpp_error (pfile, CPP_DL_ERROR,
+ "attribute identifier required after scope");
+ }
+ else
+ {
+ attr_ns = get_identifier ("gnu");
+ attr_id = get_identifier (
+ (const char *) cpp_token_as_text (pfile, token));
+ attr_name = build_tree_list (attr_ns, attr_id);
+ }
+ if (attr_name)
+ {
+ const struct attribute_spec *attr = lookup_attribute_spec (attr_name);
+ if (attr)
+ {
+ if (is_attribute_p ("noreturn", TREE_VALUE (attr_name)))
+ result = 200809;
+ else if (is_attribute_p ("deprecated", TREE_VALUE (attr_name)))
+ result = 201309;
+ else
+ result = 1;
+ }
+ }
+ }
+ else
+ cpp_error (pfile, CPP_DL_ERROR,
+ "operator \"__has_attribute__\" requires an identifier");
+
+ if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN)
+ cpp_error (pfile, CPP_DL_ERROR,
+ "missing ')' after \"__has_attribute__\"");
+
+ return result;
+}
+
/* Read a token and return its type. Fill *VALUE with its value, if
applicable. Fill *CPP_FLAGS with the token's flags, if it is