aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorYvan Roux <yvan.roux@linaro.org>2014-10-24 07:50:18 +0000
committerYvan Roux <yvan.roux@linaro.org>2014-10-24 07:50:18 +0000
commit674d53a94a998dfd2f92658dccf539e3c68a9087 (patch)
tree71fbf23e2cf8af42d2b93b4eb0ed1f26f1d2ba3c /libcpp
parent6b8ae8760971f117772868002e5adff52972c982 (diff)
parentb099186fb993a9d67e6fb66d69123a8d726a96b6 (diff)
Fix broken merge branches/gcc-4_9-branch rev 216130
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/linaro/gcc-4_9-branch@216616 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog17
-rw-r--r--libcpp/directives.c14
-rw-r--r--libcpp/expr.c75
-rw-r--r--libcpp/files.c18
-rw-r--r--libcpp/identifiers.c2
-rw-r--r--libcpp/internal.h8
-rw-r--r--libcpp/pch.c2
-rw-r--r--libcpp/traditional.c19
8 files changed, 152 insertions, 3 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 32bb84f9426..b85cb67aecb 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,20 @@
+libcpp/
+
+2014-10-08 Edward Smith-Rowland <3dw4rd@verizon.net>
+
+ Implement SD-6: SG10 Feature Test Recommendations
+ * internal.h (lexer_state, spec_nodes): Add in__has_include__.
+ * directives.c: Support __has_include__ builtin.
+ * expr.c (parse_has_include): New function to parse __has_include__
+ builtin; (eval_token()): Use it.
+ * files.c (_cpp_has_header()): New funtion to look for header;
+ (open_file_failed()): Not an error to not find a header file for
+ __has_include__.
+ * identifiers.c (_cpp_init_hashtable()): Add entry for __has_include__.
+ * pch.c (cpp_read_state): Lookup __has_include__.
+ * traditional.c (enum ls, _cpp_scan_out_logical_line()): Walk through
+ __has_include__ statements.
+
2014-07-16 Release Manager
* GCC 4.9.1 released.
diff --git a/libcpp/directives.c b/libcpp/directives.c
index 3486a48d21e..22a034dd234 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -549,6 +549,11 @@ lex_macro_node (cpp_reader *pfile, bool is_def_or_undef)
if (is_def_or_undef && node == pfile->spec_nodes.n_defined)
cpp_error (pfile, CPP_DL_ERROR,
"\"defined\" cannot be used as a macro name");
+ else if (is_def_or_undef
+ && (node == pfile->spec_nodes.n__has_include__
+ || node == pfile->spec_nodes.n__has_include_next__))
+ cpp_error (pfile, CPP_DL_ERROR,
+ "\"__has_include__\" cannot be used as a macro name");
else if (! (node->flags & NODE_POISONED))
return node;
}
@@ -2601,3 +2606,12 @@ _cpp_init_directives (cpp_reader *pfile)
node->directive_index = i;
}
}
+
+/* Extract header file from a bracket include. Parsing starts after '<'.
+ The string is malloced and must be freed by the caller. */
+char *
+_cpp_bracket_include(cpp_reader *pfile)
+{
+ return glue_header_name (pfile);
+}
+
diff --git a/libcpp/expr.c b/libcpp/expr.c
index 147bd97c5ec..29cb0fa519e 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -64,6 +64,8 @@ static unsigned int interpret_float_suffix (cpp_reader *, const uchar *, size_t)
static unsigned int interpret_int_suffix (cpp_reader *, const uchar *, size_t);
static void check_promotion (cpp_reader *, const struct op *);
+static cpp_num parse_has_include (cpp_reader *, enum include_type);
+
/* Token type abuse to create unary plus and minus operators. */
#define CPP_UPLUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 1))
#define CPP_UMINUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 2))
@@ -1041,6 +1043,10 @@ eval_token (cpp_reader *pfile, const cpp_token *token,
case CPP_NAME:
if (token->val.node.node == pfile->spec_nodes.n_defined)
return parse_defined (pfile);
+ else if (token->val.node.node == pfile->spec_nodes.n__has_include__)
+ return parse_has_include (pfile, IT_INCLUDE);
+ else if (token->val.node.node == pfile->spec_nodes.n__has_include_next__)
+ return parse_has_include (pfile, IT_INCLUDE_NEXT);
else if (CPP_OPTION (pfile, cplusplus)
&& (token->val.node.node == pfile->spec_nodes.n_true
|| token->val.node.node == pfile->spec_nodes.n_false))
@@ -2065,3 +2071,72 @@ num_div_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op,
return lhs;
}
+
+/* Handle meeting "__has_include__" in a preprocessor expression. */
+static cpp_num
+parse_has_include (cpp_reader *pfile, enum include_type type)
+{
+ cpp_num result;
+ bool paren = false;
+ cpp_hashnode *node = 0;
+ const cpp_token *token;
+ bool bracket = false;
+ char *fname = 0;
+
+ result.unsignedp = false;
+ result.high = 0;
+ result.overflow = false;
+ result.low = 0;
+
+ pfile->state.in__has_include__++;
+
+ token = cpp_get_token (pfile);
+ if (token->type == CPP_OPEN_PAREN)
+ {
+ paren = true;
+ token = cpp_get_token (pfile);
+ }
+
+ if (token->type == CPP_STRING || token->type == CPP_HEADER_NAME)
+ {
+ if (token->type == CPP_HEADER_NAME)
+ bracket = true;
+ fname = XNEWVEC (char, token->val.str.len - 1);
+ memcpy (fname, token->val.str.text + 1, token->val.str.len - 2);
+ fname[token->val.str.len - 2] = '\0';
+ node = token->val.node.node;
+ }
+ else if (token->type == CPP_LESS)
+ {
+ bracket = true;
+ fname = _cpp_bracket_include (pfile);
+ }
+ else
+ cpp_error (pfile, CPP_DL_ERROR,
+ "operator \"__has_include__\" requires a header string");
+
+ if (fname)
+ {
+ int angle_brackets = (bracket ? 1 : 0);
+
+ if (_cpp_has_header (pfile, fname, angle_brackets, type))
+ result.low = 1;
+ else
+ result.low = 0;
+
+ XDELETEVEC (fname);
+ }
+
+ if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN)
+ cpp_error (pfile, CPP_DL_ERROR,
+ "missing ')' after \"__has_include__\"");
+
+ /* A possible controlling macro of the form #if !__has_include__ ().
+ _cpp_parse_expr checks there was no other junk on the line. */
+ if (node)
+ pfile->mi_ind_cmacro = node;
+
+ pfile->state.in__has_include__--;
+
+ return result;
+}
diff --git a/libcpp/files.c b/libcpp/files.c
index 7e887785444..149f06df201 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -1023,6 +1023,9 @@ open_file_failed (cpp_reader *pfile, _cpp_file *file, int angle_brackets)
int sysp = pfile->line_table->highest_line > 1 && pfile->buffer ? pfile->buffer->sysp : 0;
bool print_dep = CPP_OPTION (pfile, deps.style) > (angle_brackets || !!sysp);
+ if (pfile->state.in__has_include__)
+ return;
+
errno = file->err_no;
if (print_dep && CPP_OPTION (pfile, deps.missing_files) && errno == ENOENT)
{
@@ -1939,3 +1942,18 @@ check_file_against_entries (cpp_reader *pfile ATTRIBUTE_UNUSED,
return bsearch (&d, pchf->entries, pchf->count, sizeof (struct pchf_entry),
pchf_compare) != NULL;
}
+
+/* Return true if the file FNAME is found in the appropriate include file path
+ as indicated by ANGLE_BRACKETS. */
+
+bool
+_cpp_has_header (cpp_reader *pfile, const char *fname, int angle_brackets,
+ enum include_type type)
+{
+ cpp_dir *start_dir = search_path_head (pfile, fname, angle_brackets, type);
+ _cpp_file *file = _cpp_find_file (pfile, fname, start_dir,
+ /*fake=*/false, angle_brackets,
+ /*implicit_preinclude=*/false);
+ return file->err_no != ENOENT;
+}
+
diff --git a/libcpp/identifiers.c b/libcpp/identifiers.c
index cfb9979a6f7..8fba8c004ec 100644
--- a/libcpp/identifiers.c
+++ b/libcpp/identifiers.c
@@ -72,6 +72,8 @@ _cpp_init_hashtable (cpp_reader *pfile, cpp_hash_table *table)
s->n_false = cpp_lookup (pfile, DSC("false"));
s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__"));
s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
+ s->n__has_include__ = cpp_lookup (pfile, DSC("__has_include__"));
+ s->n__has_include_next__ = cpp_lookup (pfile, DSC("__has_include_next__"));
}
/* Tear down the identifier hash table. */
diff --git a/libcpp/internal.h b/libcpp/internal.h
index b5106211ccb..602a5035a11 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -258,6 +258,9 @@ struct lexer_state
/* Nonzero when parsing arguments to a function-like macro. */
unsigned char parsing_args;
+ /* Nonzero if in a __has_include__ or __has_include_next__ statement. */
+ unsigned char in__has_include__;
+
/* Nonzero if prevent_expansion is true only because output is
being discarded. */
unsigned char discarding_output;
@@ -279,6 +282,8 @@ struct spec_nodes
cpp_hashnode *n_true; /* C++ keyword true */
cpp_hashnode *n_false; /* C++ keyword false */
cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
+ cpp_hashnode *n__has_include__; /* __has_include__ operator */
+ cpp_hashnode *n__has_include_next__; /* __has_include_next__ operator */
};
typedef struct _cpp_line_note _cpp_line_note;
@@ -645,6 +650,8 @@ extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
extern const char *_cpp_get_file_name (_cpp_file *);
extern struct stat *_cpp_get_file_stat (_cpp_file *);
+extern bool _cpp_has_header (cpp_reader *, const char *, int,
+ enum include_type);
/* In expr.c */
extern bool _cpp_parse_expr (cpp_reader *, bool);
@@ -680,6 +687,7 @@ extern void _cpp_init_internal_pragmas (cpp_reader *);
extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
linenum_type, unsigned int);
extern void _cpp_pop_buffer (cpp_reader *);
+extern char *_cpp_bracket_include (cpp_reader *);
/* In directives.c */
struct _cpp_dir_only_callbacks
diff --git a/libcpp/pch.c b/libcpp/pch.c
index cddca837ffd..3ff39d7ef09 100644
--- a/libcpp/pch.c
+++ b/libcpp/pch.c
@@ -833,6 +833,8 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
s->n_true = cpp_lookup (r, DSC("true"));
s->n_false = cpp_lookup (r, DSC("false"));
s->n__VA_ARGS__ = cpp_lookup (r, DSC("__VA_ARGS__"));
+ s->n__has_include__ = cpp_lookup (r, DSC("__has_include__"));
+ s->n__has_include_next__ = cpp_lookup (r, DSC("__has_include_next__"));
}
old_state = r->state;
diff --git a/libcpp/traditional.c b/libcpp/traditional.c
index b770db7aba5..dfb53787a04 100644
--- a/libcpp/traditional.c
+++ b/libcpp/traditional.c
@@ -74,7 +74,9 @@ enum ls {ls_none = 0, /* Normal state. */
ls_defined_close, /* Looking for ')' of defined(). */
ls_hash, /* After # in preprocessor conditional. */
ls_predicate, /* After the predicate, maybe paren? */
- ls_answer}; /* In answer to predicate. */
+ ls_answer, /* In answer to predicate. */
+ ls_has_include, /* After __has_include__. */
+ ls_has_include_close}; /* Looking for ')' of __has_include__. */
/* Lexing TODO: Maybe handle space in escaped newlines. Stop lex.c
from recognizing comments and directives during its lexing pass. */
@@ -524,6 +526,13 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
lex_state = ls_defined;
continue;
}
+ else if (pfile->state.in_expression
+ && (node == pfile->spec_nodes.n__has_include__
+ || node == pfile->spec_nodes.n__has_include_next__))
+ {
+ lex_state = ls_has_include;
+ continue;
+ }
}
break;
@@ -547,6 +556,8 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
lex_state = ls_answer;
else if (lex_state == ls_defined)
lex_state = ls_defined_close;
+ else if (lex_state == ls_has_include)
+ lex_state = ls_has_include_close;
}
break;
@@ -584,7 +595,8 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
goto new_context;
}
}
- else if (lex_state == ls_answer || lex_state == ls_defined_close)
+ else if (lex_state == ls_answer || lex_state == ls_defined_close
+ || lex_state == ls_has_include_close)
lex_state = ls_none;
}
break;
@@ -665,7 +677,8 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
lex_state = ls_none;
else if (lex_state == ls_hash
|| lex_state == ls_predicate
- || lex_state == ls_defined)
+ || lex_state == ls_defined
+ || lex_state == ls_has_include)
lex_state = ls_none;
/* ls_answer and ls_defined_close keep going until ')'. */