diff options
author | emsr <emsr@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-10-01 11:49:23 +0000 |
---|---|---|
committer | emsr <emsr@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-10-01 11:49:23 +0000 |
commit | f6751ff23dad167a2c05930363ec640ed2b0a3a3 (patch) | |
tree | 0305f88949de10054e322e52911e9a53306c454d /libcpp | |
parent | 61bcd046b7d40b28fc3e140b32d29f170581737d (diff) | |
download | gcc-f6751ff23dad167a2c05930363ec640ed2b0a3a3.tar.gz |
2014-10-01 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-10-01 Edward Smith-Rowland <3dw4rd@verizon.net>
Implement SD-6: SG10 Feature Test Recommendations
* c-cppbuiltin.c (c_cpp_builtins()): Define language feature
macros and the __has_header macro.
2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net>
Implement SD-6: SG10 Feature Test Recommendations
* include/bits/basic_string.h: Add __cpp_lib feature test macro.
* include/bits/stl_algobase.h: Ditto.
* include/bits/stl_function.h: Ditto.
* include/bits/unique_ptr.h: Ditto.
* include/std/chrono: Ditto.
* include/std/complex: Ditto.
* include/std/iomanip: Ditto.
* include/std/shared_mutex: Ditto.
* include/std/tuple: Ditto.
* include/std/type_traits: Ditto.
* include/std/utility: Ditto.
* testsuite/experimental/feat-cxx14.cc: New.
* testsuite/experimental/feat-lib-fund.cc: New.
* testsuite/20_util/declval/requirements/1_neg.cc: Adjust.
* testsuite/20_util/duration/literals/range.cc: Adjust.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Adjust.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Adjust.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Adjust.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
Adjust.
2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net>
Implement SD-6: SG10 Feature Test Recommendations
* g++.dg/cpp1y/feat-cxx11-neg.C: New.
* g++.dg/cpp1y/feat-cxx11.C: New.
* g++.dg/cpp1y/feat-cxx14.C: New.
* g++.dg/cpp1y/feat-cxx98.C: New.
* g++.dg/cpp1y/feat-cxx98-neg.C: New.
* g++.dg/cpp1y/phoobhar.h: New.
* g++.dg/cpp1y/testinc/phoobhar.h: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@215752 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 15 | ||||
-rw-r--r-- | libcpp/directives.c | 14 | ||||
-rw-r--r-- | libcpp/expr.c | 75 | ||||
-rw-r--r-- | libcpp/files.c | 18 | ||||
-rw-r--r-- | libcpp/identifiers.c | 2 | ||||
-rw-r--r-- | libcpp/internal.h | 8 | ||||
-rw-r--r-- | libcpp/pch.c | 2 | ||||
-rw-r--r-- | libcpp/traditional.c | 19 |
8 files changed, 150 insertions, 3 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 92999040a02..4ad851e705e 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,18 @@ +2014-10-01 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-09-30 Bernd Edlinger <bernd.edlinger@hotmail.de> PR preprocessor/58893 diff --git a/libcpp/directives.c b/libcpp/directives.c index 173e609d1e0..0a8569aeebf 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -566,6 +566,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; } @@ -2623,3 +2628,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 003fcb0560e..c24b640ba16 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)) @@ -1048,6 +1050,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)) @@ -2072,3 +2078,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 00302fd774f..e464259e458 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -1041,6 +1041,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) { @@ -1957,3 +1960,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 ')'. */ |