Add C parser support for "restrict" and "_Atomic"
authorTom Tromey <tom@tromey.com>
Sat, 14 Mar 2020 18:11:42 +0000 (12:11 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 14 Mar 2020 18:32:10 +0000 (12:32 -0600)
commit3293bbaffac9a22fc6d1a08ac6602a4a63b5e68b
tree8d10f688849be05aea48fbc1a03ba602211f7133
parentab44624cea74dca3e6d19c3275d9d5a8d381c084
Add C parser support for "restrict" and "_Atomic"

A user noticed that "watch -location" would fail with a "restrict"
pointer.  The issue here is that if the DWARF mentions "restrict", gdb
will put this into the type name -- but then the C parser will not be
able to parse this type.

This patch adds support for "restrict" and "_Atomic" to the C parser.
C++ doesn't have "restrict", but does have some GCC extensions.  The
type printer is changed to handle this difference as well, so that
watch expressions will work properly.

gdb/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

* c-typeprint.c (cp_type_print_method_args): Print "__restrict__"
for C++.
(c_type_print_modifier): Likewise.  Add "language" parameter.
(c_type_print_varspec_prefix, c_type_print_base_struct_union)
(c_type_print_base_1): Update.
* type-stack.h (enum type_pieces) <tp_atomic, tp_restrict>: New
constants.
* type-stack.c (type_stack::insert): Handle tp_atomic and
tp_restrict.
(type_stack::follow_type_instance_flags): Likewise.
(type_stack::follow_types): Likewise.  Merge type-following code.
* c-exp.y (RESTRICT, ATOMIC): New tokens.
(space_identifier, cv_with_space_id)
(const_or_volatile_or_space_identifier_noopt)
(const_or_volatile_or_space_identifier): Remove.
(single_qualifier, qualifier_seq_noopt, qualifier_seq): New
rules.
(ptr_operator, typebase): Update.
(enum token_flag) <FLAG_C>: New constant.
(ident_tokens): Add "restrict", "__restrict__", "__restrict", and
"_Atomic".
(lex_one_token): Handle FLAG_C.

gdb/testsuite/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

* gdb.base/cvexpr.exp: Add test for _Atomic and restrict.
gdb/ChangeLog
gdb/c-exp.y
gdb/c-typeprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/cvexpr.exp
gdb/type-stack.c
gdb/type-stack.h