Commit 3c01e5df by Mark Mitchell Committed by Mark Mitchell

cp-tree.h (cp_cv_quals): New type.

	* cp-tree.h (cp_cv_quals): New type.
	(cp_declarator): Use it instead of "tree" as appropriate.
	(grok_method_quals): Adjust prototype.
	(grokclassfn): Likewise.
	(do_friend): Likewise.
	* decl.c (grokfndecl): Use cp_cv_quals, not tree.
	(grokdeclarator): Likewise.
	* decl2.c (grok_method_quals): Likewise.
	(grokclassfn): Likewise.
	* friend.c (do_friend): Likewise.
	* method.c (implicitly_declare_fn): Adjust call to grokclassfn.
	* parser.c (make_call_declarator): Use cp_cv_quals, not tree.
	(make_pointer_declarator): Likewise.
	(make_reference_declarator): Likewise.
	(make_ptrmem_declarator): Likewise.
	(cp_parser_ptr_operator): Likewise.
	(cp_parser_cv_qualifier_seq_opt): Likewise.
	(cp_parser_cv_qualifier_opt): Remove.
	(cp_parser_new_declarator_opt): Adjust call to
	cp_parser_ptr_operator.
	(cp_parser_conversion_declaration_opt): Likewise.
	(cp_parser_declarator): Use cp_cv_quals, not tree.
	(cp_parser_direct_declarator): Likewise.

From-SVN: r83729
parent 808fd801
2004-06-26 Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (cp_cv_quals): New type.
(cp_declarator): Use it instead of "tree" as appropriate.
(grok_method_quals): Adjust prototype.
(grokclassfn): Likewise.
(do_friend): Likewise.
* decl.c (grokfndecl): Use cp_cv_quals, not tree.
(grokdeclarator): Likewise.
* decl2.c (grok_method_quals): Likewise.
(grokclassfn): Likewise.
* friend.c (do_friend): Likewise.
* method.c (implicitly_declare_fn): Adjust call to grokclassfn.
* parser.c (make_call_declarator): Use cp_cv_quals, not tree.
(make_pointer_declarator): Likewise.
(make_reference_declarator): Likewise.
(make_ptrmem_declarator): Likewise.
(cp_parser_ptr_operator): Likewise.
(cp_parser_cv_qualifier_seq_opt): Likewise.
(cp_parser_cv_qualifier_opt): Remove.
(cp_parser_new_declarator_opt): Adjust call to
cp_parser_ptr_operator.
(cp_parser_conversion_declaration_opt): Likewise.
(cp_parser_declarator): Use cp_cv_quals, not tree.
(cp_parser_direct_declarator): Likewise.
2004-06-26 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> 2004-06-26 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* call.c, cp-tree.h, cxx-pretty-print.c, decl.c, decl2.c: * call.c, cp-tree.h, cxx-pretty-print.c, decl.c, decl2.c:
......
...@@ -3503,6 +3503,11 @@ extern GTY(()) operator_name_info_t operator_name_info ...@@ -3503,6 +3503,11 @@ extern GTY(()) operator_name_info_t operator_name_info
extern GTY(()) operator_name_info_t assignment_operator_name_info extern GTY(()) operator_name_info_t assignment_operator_name_info
[(int) LAST_CPLUS_TREE_CODE]; [(int) LAST_CPLUS_TREE_CODE];
/* A type-qualifier, or bitmask therefore, using the TYPE_QUAL
constants. */
typedef int cp_cv_quals;
/* A storage class. */ /* A storage class. */
typedef enum cp_storage_class { typedef enum cp_storage_class {
...@@ -3628,7 +3633,7 @@ struct cp_declarator { ...@@ -3628,7 +3633,7 @@ struct cp_declarator {
/* The parameters to the function. */ /* The parameters to the function. */
cp_parameter_declarator *parameters; cp_parameter_declarator *parameters;
/* The cv-qualifiers for the function. */ /* The cv-qualifiers for the function. */
tree qualifiers; cp_cv_quals qualifiers;
/* The exception-specification for the function. */ /* The exception-specification for the function. */
tree exception_specification; tree exception_specification;
} function; } function;
...@@ -3640,7 +3645,7 @@ struct cp_declarator { ...@@ -3640,7 +3645,7 @@ struct cp_declarator {
/* For cdk_pointer, cdk_reference, and cdk_ptrmem. */ /* For cdk_pointer, cdk_reference, and cdk_ptrmem. */
struct { struct {
/* The cv-qualifiers for the pointer. */ /* The cv-qualifiers for the pointer. */
tree qualifiers; cp_cv_quals qualifiers;
/* For cdk_ptrmem, the class type containing the member. */ /* For cdk_ptrmem, the class type containing the member. */
tree class_type; tree class_type;
} pointer; } pointer;
...@@ -3866,10 +3871,10 @@ extern bool have_extern_spec; ...@@ -3866,10 +3871,10 @@ extern bool have_extern_spec;
/* in decl2.c */ /* in decl2.c */
extern bool check_java_method (tree); extern bool check_java_method (tree);
extern int grok_method_quals (tree, tree, tree); extern cp_cv_quals grok_method_quals (tree, tree, cp_cv_quals);
extern void maybe_retrofit_in_chrg (tree); extern void maybe_retrofit_in_chrg (tree);
extern void maybe_make_one_only (tree); extern void maybe_make_one_only (tree);
extern void grokclassfn (tree, tree, enum overload_flags, tree); extern void grokclassfn (tree, tree, enum overload_flags, cp_cv_quals);
extern tree grok_array_decl (tree, tree); extern tree grok_array_decl (tree, tree);
extern tree delete_sanity (tree, tree, bool, int); extern tree delete_sanity (tree, tree, bool, int);
extern tree check_classfn (tree, tree, tree); extern tree check_classfn (tree, tree, tree);
...@@ -3941,7 +3946,7 @@ extern tree cplus_expand_constant (tree); ...@@ -3941,7 +3946,7 @@ extern tree cplus_expand_constant (tree);
extern int is_friend (tree, tree); extern int is_friend (tree, tree);
extern void make_friend_class (tree, tree, bool); extern void make_friend_class (tree, tree, bool);
extern void add_friend (tree, tree, bool); extern void add_friend (tree, tree, bool);
extern tree do_friend (tree, tree, tree, tree, enum overload_flags, tree, int); extern tree do_friend (tree, tree, tree, tree, enum overload_flags, cp_cv_quals, int);
/* in init.c */ /* in init.c */
extern tree expand_member_init (tree); extern tree expand_member_init (tree);
......
...@@ -62,7 +62,7 @@ static int unary_op_p (enum tree_code); ...@@ -62,7 +62,7 @@ static int unary_op_p (enum tree_code);
static void push_local_name (tree); static void push_local_name (tree);
static tree grok_reference_init (tree, tree, tree, tree *); static tree grok_reference_init (tree, tree, tree, tree *);
static tree grokfndecl (tree, tree, tree, tree, tree, int, static tree grokfndecl (tree, tree, tree, tree, tree, int,
enum overload_flags, tree, enum overload_flags, cp_cv_quals,
tree, int, int, int, int, int, int, tree); tree, int, int, int, int, int, int, tree);
static tree grokvardecl (tree, tree, cp_decl_specifier_seq *, int, int, tree); static tree grokvardecl (tree, tree, cp_decl_specifier_seq *, int, int, tree);
static void record_unknown_type (tree, const char *); static void record_unknown_type (tree, const char *);
...@@ -5424,7 +5424,7 @@ grokfndecl (tree ctype, ...@@ -5424,7 +5424,7 @@ grokfndecl (tree ctype,
tree orig_declarator, tree orig_declarator,
int virtualp, int virtualp,
enum overload_flags flags, enum overload_flags flags,
tree quals, cp_cv_quals quals,
tree raises, tree raises,
int check, int check,
int friendp, int friendp,
...@@ -5544,11 +5544,11 @@ grokfndecl (tree ctype, ...@@ -5544,11 +5544,11 @@ grokfndecl (tree ctype,
DECL_INLINE (decl) = 1; DECL_INLINE (decl) = 1;
DECL_EXTERNAL (decl) = 1; DECL_EXTERNAL (decl) = 1;
if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) if (quals && TREE_CODE (type) == FUNCTION_TYPE)
{ {
error ("%smember function `%D' cannot have `%T' method qualifier", error ("%smember function `%D' cannot have cv-qualifier",
(ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); (ctype ? "static " : "non-"), decl);
quals = NULL_TREE; quals = TYPE_UNQUALIFIED;
} }
if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
...@@ -6287,7 +6287,7 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -6287,7 +6287,7 @@ grokdeclarator (const cp_declarator *declarator,
tree dname = NULL_TREE; tree dname = NULL_TREE;
tree ctor_return_type = NULL_TREE; tree ctor_return_type = NULL_TREE;
enum overload_flags flags = NO_SPECIAL; enum overload_flags flags = NO_SPECIAL;
tree quals = NULL_TREE; cp_cv_quals quals = TYPE_UNQUALIFIED;
tree raises = NULL_TREE; tree raises = NULL_TREE;
int template_count = 0; int template_count = 0;
tree returned_attrs = NULL_TREE; tree returned_attrs = NULL_TREE;
...@@ -6546,7 +6546,7 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -6546,7 +6546,7 @@ grokdeclarator (const cp_declarator *declarator,
} }
else if (declspecs->specs[(int)ds] > 1) else if (declspecs->specs[(int)ds] > 1)
{ {
static const char *decl_spec_names[] = { static const char *const decl_spec_names[] = {
"signed", "signed",
"unsigned", "unsigned",
"short", "short",
...@@ -7049,9 +7049,8 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -7049,9 +7049,8 @@ grokdeclarator (const cp_declarator *declarator,
error ("destructor cannot be static member function"); error ("destructor cannot be static member function");
if (quals) if (quals)
{ {
error ("destructors may not be `%E'", error ("destructors may not be cv-qualified");
TREE_VALUE (quals)); quals = TYPE_UNQUALIFIED;
quals = NULL_TREE;
} }
if (decl_context == FIELD) if (decl_context == FIELD)
{ {
...@@ -7078,9 +7077,8 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -7078,9 +7077,8 @@ grokdeclarator (const cp_declarator *declarator,
} }
if (quals) if (quals)
{ {
error ("constructors may not be `%E'", error ("constructors may not be cv-qualified");
TREE_VALUE (quals)); quals = TYPE_UNQUALIFIED;
quals = NULL_TREE;
} }
if (decl_context == FIELD) if (decl_context == FIELD)
{ {
...@@ -7163,7 +7161,7 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -7163,7 +7161,7 @@ grokdeclarator (const cp_declarator *declarator,
grok_method_quals (declarator->u.pointer.class_type, grok_method_quals (declarator->u.pointer.class_type,
dummy, quals); dummy, quals);
type = TREE_TYPE (dummy); type = TREE_TYPE (dummy);
quals = NULL_TREE; quals = TYPE_UNQUALIFIED;
} }
if (declarator->kind == cdk_reference) if (declarator->kind == cdk_reference)
...@@ -7184,45 +7182,9 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -7184,45 +7182,9 @@ grokdeclarator (const cp_declarator *declarator,
if (declarator->u.pointer.qualifiers) if (declarator->u.pointer.qualifiers)
{ {
tree typemodlist; type
int erred = 0; = cp_build_qualified_type (type,
int constp = 0; declarator->u.pointer.qualifiers);
int volatilep = 0;
int restrictp = 0;
for (typemodlist = declarator->u.pointer.qualifiers; typemodlist;
typemodlist = TREE_CHAIN (typemodlist))
{
tree qualifier = TREE_VALUE (typemodlist);
if (qualifier == ridpointers[(int) RID_CONST])
{
constp++;
type_quals |= TYPE_QUAL_CONST;
}
else if (qualifier == ridpointers[(int) RID_VOLATILE])
{
volatilep++;
type_quals |= TYPE_QUAL_VOLATILE;
}
else if (qualifier == ridpointers[(int) RID_RESTRICT])
{
restrictp++;
type_quals |= TYPE_QUAL_RESTRICT;
}
else if (!erred)
{
erred = 1;
error ("invalid type modifier within pointer declarator");
}
}
if (constp > 1)
pedwarn ("duplicate `const'");
if (volatilep > 1)
pedwarn ("duplicate `volatile'");
if (restrictp > 1)
pedwarn ("duplicate `restrict'");
type = cp_build_qualified_type (type, type_quals);
type_quals = cp_type_quals (type); type_quals = cp_type_quals (type);
} }
ctype = NULL_TREE; ctype = NULL_TREE;
...@@ -7488,7 +7450,7 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -7488,7 +7450,7 @@ grokdeclarator (const cp_declarator *declarator,
|| (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
bad_specifiers (decl, "type", virtualp, quals != NULL_TREE, bad_specifiers (decl, "type", virtualp, quals != TYPE_UNQUALIFIED,
inlinep, friendp, raises != NULL_TREE); inlinep, friendp, raises != NULL_TREE);
return decl; return decl;
...@@ -7654,7 +7616,7 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -7654,7 +7616,7 @@ grokdeclarator (const cp_declarator *declarator,
{ {
decl = cp_build_parm_decl (unqualified_id, type); decl = cp_build_parm_decl (unqualified_id, type);
bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, bad_specifiers (decl, "parameter", virtualp, quals != TYPE_UNQUALIFIED,
inlinep, friendp, raises != NULL_TREE); inlinep, friendp, raises != NULL_TREE);
} }
else if (decl_context == FIELD) else if (decl_context == FIELD)
...@@ -7908,7 +7870,7 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -7908,7 +7870,7 @@ grokdeclarator (const cp_declarator *declarator,
} }
} }
bad_specifiers (decl, "field", virtualp, quals != NULL_TREE, bad_specifiers (decl, "field", virtualp, quals != TYPE_UNQUALIFIED,
inlinep, friendp, raises != NULL_TREE); inlinep, friendp, raises != NULL_TREE);
} }
} }
...@@ -8009,7 +7971,7 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -8009,7 +7971,7 @@ grokdeclarator (const cp_declarator *declarator,
initialized, initialized,
(type_quals & TYPE_QUAL_CONST) != 0, (type_quals & TYPE_QUAL_CONST) != 0,
ctype ? ctype : in_namespace); ctype ? ctype : in_namespace);
bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, bad_specifiers (decl, "variable", virtualp, quals != TYPE_UNQUALIFIED,
inlinep, friendp, raises != NULL_TREE); inlinep, friendp, raises != NULL_TREE);
if (ctype) if (ctype)
......
...@@ -118,31 +118,15 @@ tree static_dtors; ...@@ -118,31 +118,15 @@ tree static_dtors;
TYPE_UNQUALIFIED will be an extension. */ TYPE_UNQUALIFIED will be an extension. */
int int
grok_method_quals (tree ctype, tree function, tree quals) grok_method_quals (tree ctype, tree function, cp_cv_quals quals)
{ {
tree fntype = TREE_TYPE (function); tree fntype = TREE_TYPE (function);
tree raises = TYPE_RAISES_EXCEPTIONS (fntype); tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
int type_quals = TYPE_UNQUALIFIED; int type_quals = TYPE_UNQUALIFIED;
int dup_quals = TYPE_UNQUALIFIED;
int this_quals = TYPE_UNQUALIFIED; int this_quals = TYPE_UNQUALIFIED;
while (quals) type_quals = quals & ~TYPE_QUAL_RESTRICT;
{ this_quals = quals & TYPE_QUAL_RESTRICT;
int tq = cp_type_qual_from_rid (TREE_VALUE (quals));
if ((type_quals | this_quals) & tq)
dup_quals |= tq;
else if (tq & TYPE_QUAL_RESTRICT)
this_quals |= tq;
else
type_quals |= tq;
quals = TREE_CHAIN (quals);
}
if (dup_quals != TYPE_UNQUALIFIED)
error ("duplicate type qualifiers in %s declaration",
TREE_CODE (function) == FUNCTION_DECL
? "member function" : "type");
ctype = cp_build_qualified_type (ctype, type_quals); ctype = cp_build_qualified_type (ctype, type_quals);
fntype = build_method_type_directly (ctype, TREE_TYPE (fntype), fntype = build_method_type_directly (ctype, TREE_TYPE (fntype),
...@@ -281,10 +265,11 @@ maybe_retrofit_in_chrg (tree fn) ...@@ -281,10 +265,11 @@ maybe_retrofit_in_chrg (tree fn)
QUALS are the qualifiers for the this pointer. */ QUALS are the qualifiers for the this pointer. */
void void
grokclassfn (tree ctype, tree function, enum overload_flags flags, tree quals) grokclassfn (tree ctype, tree function, enum overload_flags flags,
cp_cv_quals quals)
{ {
tree fn_name = DECL_NAME (function); tree fn_name = DECL_NAME (function);
int this_quals = TYPE_UNQUALIFIED; cp_cv_quals this_quals = TYPE_UNQUALIFIED;
/* Even within an `extern "C"' block, members get C++ linkage. See /* Even within an `extern "C"' block, members get C++ linkage. See
[dcl.link] for details. */ [dcl.link] for details. */
......
...@@ -325,7 +325,8 @@ make_friend_class (tree type, tree friend_type, bool complain) ...@@ -325,7 +325,8 @@ make_friend_class (tree type, tree friend_type, bool complain)
tree tree
do_friend (tree ctype, tree declarator, tree decl, do_friend (tree ctype, tree declarator, tree decl,
tree attrlist, enum overload_flags flags, tree quals, tree attrlist, enum overload_flags flags,
cp_cv_quals quals,
int funcdef_flag) int funcdef_flag)
{ {
/* Every decl that gets here is a friend of something. */ /* Every decl that gets here is a friend of something. */
......
...@@ -1020,7 +1020,7 @@ implicitly_declare_fn (special_function_kind kind, tree type, bool const_p) ...@@ -1020,7 +1020,7 @@ implicitly_declare_fn (special_function_kind kind, tree type, bool const_p)
} }
grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL, grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL,
/*quals=*/NULL_TREE); TYPE_UNQUALIFIED);
grok_special_member_properties (fn); grok_special_member_properties (fn);
cp_finish_decl (fn, /*init=*/NULL_TREE, /*asmspec_tree=*/NULL_TREE, cp_finish_decl (fn, /*init=*/NULL_TREE, /*asmspec_tree=*/NULL_TREE,
/*flags=*/LOOKUP_ONLYCONVERTING); /*flags=*/LOOKUP_ONLYCONVERTING);
......
...@@ -1019,17 +1019,17 @@ clear_decl_specs (cp_decl_specifier_seq *decl_specs) ...@@ -1019,17 +1019,17 @@ clear_decl_specs (cp_decl_specifier_seq *decl_specs)
static cp_declarator *make_id_declarator static cp_declarator *make_id_declarator
(tree); (tree);
static cp_declarator *make_call_declarator static cp_declarator *make_call_declarator
(cp_declarator *, cp_parameter_declarator *, tree, tree); (cp_declarator *, cp_parameter_declarator *, cp_cv_quals, tree);
static cp_declarator *make_array_declarator static cp_declarator *make_array_declarator
(cp_declarator *, tree); (cp_declarator *, tree);
static cp_declarator *make_pointer_declarator static cp_declarator *make_pointer_declarator
(tree, cp_declarator *); (cp_cv_quals, cp_declarator *);
static cp_declarator *make_reference_declarator static cp_declarator *make_reference_declarator
(tree, cp_declarator *); (cp_cv_quals, cp_declarator *);
static cp_parameter_declarator *make_parameter_declarator static cp_parameter_declarator *make_parameter_declarator
(cp_decl_specifier_seq *, cp_declarator *, tree); (cp_decl_specifier_seq *, cp_declarator *, tree);
static cp_declarator *make_ptrmem_declarator static cp_declarator *make_ptrmem_declarator
(tree, tree, cp_declarator *); (cp_cv_quals, tree, cp_declarator *);
cp_declarator *cp_error_declarator; cp_declarator *cp_error_declarator;
...@@ -1080,7 +1080,7 @@ make_id_declarator (tree id) ...@@ -1080,7 +1080,7 @@ make_id_declarator (tree id)
type, represented as identifiers. */ type, represented as identifiers. */
cp_declarator * cp_declarator *
make_pointer_declarator (tree cv_qualifiers, cp_declarator *target) make_pointer_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target)
{ {
cp_declarator *declarator; cp_declarator *declarator;
...@@ -1095,7 +1095,7 @@ make_pointer_declarator (tree cv_qualifiers, cp_declarator *target) ...@@ -1095,7 +1095,7 @@ make_pointer_declarator (tree cv_qualifiers, cp_declarator *target)
/* Like make_pointer_declarator -- but for references. */ /* Like make_pointer_declarator -- but for references. */
cp_declarator * cp_declarator *
make_reference_declarator (tree cv_qualifiers, cp_declarator *target) make_reference_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target)
{ {
cp_declarator *declarator; cp_declarator *declarator;
...@@ -1111,7 +1111,7 @@ make_reference_declarator (tree cv_qualifiers, cp_declarator *target) ...@@ -1111,7 +1111,7 @@ make_reference_declarator (tree cv_qualifiers, cp_declarator *target)
member of CLASS_TYPE. */ member of CLASS_TYPE. */
cp_declarator * cp_declarator *
make_ptrmem_declarator (tree cv_qualifiers, tree class_type, make_ptrmem_declarator (cp_cv_quals cv_qualifiers, tree class_type,
cp_declarator *pointee) cp_declarator *pointee)
{ {
cp_declarator *declarator; cp_declarator *declarator;
...@@ -1132,7 +1132,7 @@ make_ptrmem_declarator (tree cv_qualifiers, tree class_type, ...@@ -1132,7 +1132,7 @@ make_ptrmem_declarator (tree cv_qualifiers, tree class_type,
cp_declarator * cp_declarator *
make_call_declarator (cp_declarator *target, make_call_declarator (cp_declarator *target,
cp_parameter_declarator *parms, cp_parameter_declarator *parms,
tree cv_qualifiers, cp_cv_quals cv_qualifiers,
tree exception_specification) tree exception_specification)
{ {
cp_declarator *declarator; cp_declarator *declarator;
...@@ -1693,10 +1693,8 @@ static cp_declarator *cp_parser_declarator ...@@ -1693,10 +1693,8 @@ static cp_declarator *cp_parser_declarator
static cp_declarator *cp_parser_direct_declarator static cp_declarator *cp_parser_direct_declarator
(cp_parser *, cp_parser_declarator_kind, int *); (cp_parser *, cp_parser_declarator_kind, int *);
static enum tree_code cp_parser_ptr_operator static enum tree_code cp_parser_ptr_operator
(cp_parser *, tree *, tree *); (cp_parser *, tree *, cp_cv_quals *);
static tree cp_parser_cv_qualifier_seq_opt static cp_cv_quals cp_parser_cv_qualifier_seq_opt
(cp_parser *);
static tree cp_parser_cv_qualifier_opt
(cp_parser *); (cp_parser *);
static tree cp_parser_declarator_id static tree cp_parser_declarator_id
(cp_parser *); (cp_parser *);
...@@ -4956,12 +4954,12 @@ cp_parser_new_declarator_opt (cp_parser* parser) ...@@ -4956,12 +4954,12 @@ cp_parser_new_declarator_opt (cp_parser* parser)
{ {
enum tree_code code; enum tree_code code;
tree type; tree type;
tree cv_qualifier_seq; cp_cv_quals cv_quals;
/* We don't know if there's a ptr-operator next, or not. */ /* We don't know if there's a ptr-operator next, or not. */
cp_parser_parse_tentatively (parser); cp_parser_parse_tentatively (parser);
/* Look for a ptr-operator. */ /* Look for a ptr-operator. */
code = cp_parser_ptr_operator (parser, &type, &cv_qualifier_seq); code = cp_parser_ptr_operator (parser, &type, &cv_quals);
/* If that worked, look for more new-declarators. */ /* If that worked, look for more new-declarators. */
if (cp_parser_parse_definitely (parser)) if (cp_parser_parse_definitely (parser))
{ {
...@@ -4972,15 +4970,11 @@ cp_parser_new_declarator_opt (cp_parser* parser) ...@@ -4972,15 +4970,11 @@ cp_parser_new_declarator_opt (cp_parser* parser)
/* Create the representation of the declarator. */ /* Create the representation of the declarator. */
if (type) if (type)
declarator = make_ptrmem_declarator (cv_qualifier_seq, declarator = make_ptrmem_declarator (cv_quals, type, declarator);
type,
declarator);
else if (code == INDIRECT_REF) else if (code == INDIRECT_REF)
declarator = make_pointer_declarator (cv_qualifier_seq, declarator = make_pointer_declarator (cv_quals, declarator);
declarator);
else else
declarator = make_reference_declarator (cv_qualifier_seq, declarator = make_reference_declarator (cv_quals, declarator);
declarator);
return declarator; return declarator;
} }
...@@ -7570,13 +7564,12 @@ cp_parser_conversion_declarator_opt (cp_parser* parser) ...@@ -7570,13 +7564,12 @@ cp_parser_conversion_declarator_opt (cp_parser* parser)
{ {
enum tree_code code; enum tree_code code;
tree class_type; tree class_type;
tree cv_qualifier_seq; cp_cv_quals cv_quals;
/* We don't know if there's a ptr-operator next, or not. */ /* We don't know if there's a ptr-operator next, or not. */
cp_parser_parse_tentatively (parser); cp_parser_parse_tentatively (parser);
/* Try the ptr-operator. */ /* Try the ptr-operator. */
code = cp_parser_ptr_operator (parser, &class_type, code = cp_parser_ptr_operator (parser, &class_type, &cv_quals);
&cv_qualifier_seq);
/* If it worked, look for more conversion-declarators. */ /* If it worked, look for more conversion-declarators. */
if (cp_parser_parse_definitely (parser)) if (cp_parser_parse_definitely (parser))
{ {
...@@ -7587,15 +7580,12 @@ cp_parser_conversion_declarator_opt (cp_parser* parser) ...@@ -7587,15 +7580,12 @@ cp_parser_conversion_declarator_opt (cp_parser* parser)
/* Create the representation of the declarator. */ /* Create the representation of the declarator. */
if (class_type) if (class_type)
declarator = make_ptrmem_declarator (cv_qualifier_seq, declarator = make_ptrmem_declarator (cv_quals, class_type,
class_type,
declarator); declarator);
else if (code == INDIRECT_REF) else if (code == INDIRECT_REF)
declarator = make_pointer_declarator (cv_qualifier_seq, declarator = make_pointer_declarator (cv_quals, declarator);
declarator);
else else
declarator = make_reference_declarator (cv_qualifier_seq, declarator = make_reference_declarator (cv_quals, declarator);
declarator);
return declarator; return declarator;
} }
...@@ -10779,7 +10769,7 @@ cp_parser_declarator (cp_parser* parser, ...@@ -10779,7 +10769,7 @@ cp_parser_declarator (cp_parser* parser,
cp_token *token; cp_token *token;
cp_declarator *declarator; cp_declarator *declarator;
enum tree_code code; enum tree_code code;
tree cv_qualifier_seq; cp_cv_quals cv_quals;
tree class_type; tree class_type;
tree attributes = NULL_TREE; tree attributes = NULL_TREE;
...@@ -10799,7 +10789,7 @@ cp_parser_declarator (cp_parser* parser, ...@@ -10799,7 +10789,7 @@ cp_parser_declarator (cp_parser* parser,
/* Parse the ptr-operator. */ /* Parse the ptr-operator. */
code = cp_parser_ptr_operator (parser, code = cp_parser_ptr_operator (parser,
&class_type, &class_type,
&cv_qualifier_seq); &cv_quals);
/* If that worked, then we have a ptr-operator. */ /* If that worked, then we have a ptr-operator. */
if (cp_parser_parse_definitely (parser)) if (cp_parser_parse_definitely (parser))
{ {
...@@ -10825,15 +10815,13 @@ cp_parser_declarator (cp_parser* parser, ...@@ -10825,15 +10815,13 @@ cp_parser_declarator (cp_parser* parser,
/* Build the representation of the ptr-operator. */ /* Build the representation of the ptr-operator. */
if (class_type) if (class_type)
declarator = make_ptrmem_declarator (cv_qualifier_seq, declarator = make_ptrmem_declarator (cv_quals,
class_type, class_type,
declarator); declarator);
else if (code == INDIRECT_REF) else if (code == INDIRECT_REF)
declarator = make_pointer_declarator (cv_qualifier_seq, declarator = make_pointer_declarator (cv_quals, declarator);
declarator);
else else
declarator = make_reference_declarator (cv_qualifier_seq, declarator = make_reference_declarator (cv_quals, declarator);
declarator);
} }
/* Everything else is a direct-declarator. */ /* Everything else is a direct-declarator. */
else else
...@@ -10968,7 +10956,7 @@ cp_parser_direct_declarator (cp_parser* parser, ...@@ -10968,7 +10956,7 @@ cp_parser_direct_declarator (cp_parser* parser,
exception-specification. */ exception-specification. */
if (cp_parser_parse_definitely (parser)) if (cp_parser_parse_definitely (parser))
{ {
tree cv_qualifiers; cp_cv_quals cv_quals;
tree exception_specification; tree exception_specification;
if (ctor_dtor_or_conv_p) if (ctor_dtor_or_conv_p)
...@@ -10978,7 +10966,7 @@ cp_parser_direct_declarator (cp_parser* parser, ...@@ -10978,7 +10966,7 @@ cp_parser_direct_declarator (cp_parser* parser,
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"); cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
/* Parse the cv-qualifier-seq. */ /* Parse the cv-qualifier-seq. */
cv_qualifiers = cp_parser_cv_qualifier_seq_opt (parser); cv_quals = cp_parser_cv_qualifier_seq_opt (parser);
/* And the exception-specification. */ /* And the exception-specification. */
exception_specification exception_specification
= cp_parser_exception_specification_opt (parser); = cp_parser_exception_specification_opt (parser);
...@@ -10986,7 +10974,7 @@ cp_parser_direct_declarator (cp_parser* parser, ...@@ -10986,7 +10974,7 @@ cp_parser_direct_declarator (cp_parser* parser,
/* Create the function-declarator. */ /* Create the function-declarator. */
declarator = make_call_declarator (declarator, declarator = make_call_declarator (declarator,
params, params,
cv_qualifiers, cv_quals,
exception_specification); exception_specification);
/* Any subsequent parameter lists are to do with /* Any subsequent parameter lists are to do with
return type, so are not those of the declared return type, so are not those of the declared
...@@ -11226,17 +11214,17 @@ cp_parser_direct_declarator (cp_parser* parser, ...@@ -11226,17 +11214,17 @@ cp_parser_direct_declarator (cp_parser* parser,
ptr-operator: ptr-operator:
& cv-qualifier-seq [opt] & cv-qualifier-seq [opt]
Returns INDIRECT_REF if a pointer, or pointer-to-member, was Returns INDIRECT_REF if a pointer, or pointer-to-member, was used.
used. Returns ADDR_EXPR if a reference was used. In the Returns ADDR_EXPR if a reference was used. In the case of a
case of a pointer-to-member, *TYPE is filled in with the pointer-to-member, *TYPE is filled in with the TYPE containing the
TYPE containing the member. *CV_QUALIFIER_SEQ is filled in member. *CV_QUALS is filled in with the cv-qualifier-seq, or
with the cv-qualifier-seq, or NULL_TREE, if there are no TYPE_UNQUALIFIED, if there are no cv-qualifiers. Returns
cv-qualifiers. Returns ERROR_MARK if an error occurred. */ ERROR_MARK if an error occurred. */
static enum tree_code static enum tree_code
cp_parser_ptr_operator (cp_parser* parser, cp_parser_ptr_operator (cp_parser* parser,
tree* type, tree* type,
tree* cv_qualifier_seq) cp_cv_quals *cv_quals)
{ {
enum tree_code code = ERROR_MARK; enum tree_code code = ERROR_MARK;
cp_token *token; cp_token *token;
...@@ -11244,7 +11232,7 @@ cp_parser_ptr_operator (cp_parser* parser, ...@@ -11244,7 +11232,7 @@ cp_parser_ptr_operator (cp_parser* parser,
/* Assume that it's not a pointer-to-member. */ /* Assume that it's not a pointer-to-member. */
*type = NULL_TREE; *type = NULL_TREE;
/* And that there are no cv-qualifiers. */ /* And that there are no cv-qualifiers. */
*cv_qualifier_seq = NULL_TREE; *cv_quals = TYPE_UNQUALIFIED;
/* Peek at the next token. */ /* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer); token = cp_lexer_peek_token (parser->lexer);
...@@ -11263,7 +11251,7 @@ cp_parser_ptr_operator (cp_parser* parser, ...@@ -11263,7 +11251,7 @@ cp_parser_ptr_operator (cp_parser* parser,
enforced during semantic analysis. */ enforced during semantic analysis. */
if (code == INDIRECT_REF if (code == INDIRECT_REF
|| cp_parser_allow_gnu_extensions_p (parser)) || cp_parser_allow_gnu_extensions_p (parser))
*cv_qualifier_seq = cp_parser_cv_qualifier_seq_opt (parser); *cv_quals = cp_parser_cv_qualifier_seq_opt (parser);
} }
else else
{ {
...@@ -11293,7 +11281,7 @@ cp_parser_ptr_operator (cp_parser* parser, ...@@ -11293,7 +11281,7 @@ cp_parser_ptr_operator (cp_parser* parser,
/* Indicate that the `*' operator was used. */ /* Indicate that the `*' operator was used. */
code = INDIRECT_REF; code = INDIRECT_REF;
/* Look for the optional cv-qualifier-seq. */ /* Look for the optional cv-qualifier-seq. */
*cv_qualifier_seq = cp_parser_cv_qualifier_seq_opt (parser); *cv_quals = cp_parser_cv_qualifier_seq_opt (parser);
} }
/* If that didn't work we don't have a ptr-operator. */ /* If that didn't work we don't have a ptr-operator. */
if (!cp_parser_parse_definitely (parser)) if (!cp_parser_parse_definitely (parser))
...@@ -11308,35 +11296,6 @@ cp_parser_ptr_operator (cp_parser* parser, ...@@ -11308,35 +11296,6 @@ cp_parser_ptr_operator (cp_parser* parser,
cv-qualifier-seq: cv-qualifier-seq:
cv-qualifier cv-qualifier-seq [opt] cv-qualifier cv-qualifier-seq [opt]
Returns a TREE_LIST. The TREE_VALUE of each node is the
representation of a cv-qualifier. */
static tree
cp_parser_cv_qualifier_seq_opt (cp_parser* parser)
{
tree cv_qualifiers = NULL_TREE;
while (true)
{
tree cv_qualifier;
/* Look for the next cv-qualifier. */
cv_qualifier = cp_parser_cv_qualifier_opt (parser);
/* If we didn't find one, we're done. */
if (!cv_qualifier)
break;
/* Add this cv-qualifier to the list. */
cv_qualifiers
= tree_cons (NULL_TREE, cv_qualifier, cv_qualifiers);
}
/* We built up the list in reverse order. */
return nreverse (cv_qualifiers);
}
/* Parse an (optional) cv-qualifier.
cv-qualifier: cv-qualifier:
const const
volatile volatile
...@@ -11344,33 +11303,58 @@ cp_parser_cv_qualifier_seq_opt (cp_parser* parser) ...@@ -11344,33 +11303,58 @@ cp_parser_cv_qualifier_seq_opt (cp_parser* parser)
GNU Extension: GNU Extension:
cv-qualifier: cv-qualifier:
__restrict__ */ __restrict__
static tree Returns a bitmask representing the cv-qualifiers. */
cp_parser_cv_qualifier_opt (cp_parser* parser)
static cp_cv_quals
cp_parser_cv_qualifier_seq_opt (cp_parser* parser)
{ {
cp_token *token; cp_cv_quals cv_quals = TYPE_UNQUALIFIED;
tree cv_qualifier = NULL_TREE;
/* Peek at the next token. */ while (true)
token = cp_lexer_peek_token (parser->lexer);
/* See if it's a cv-qualifier. */
switch (token->keyword)
{ {
case RID_CONST: cp_token *token;
case RID_VOLATILE: cp_cv_quals cv_qualifier;
case RID_RESTRICT:
/* Save the value of the token. */ /* Peek at the next token. */
cv_qualifier = token->value; token = cp_lexer_peek_token (parser->lexer);
/* Consume the token. */ /* See if it's a cv-qualifier. */
cp_lexer_consume_token (parser->lexer); switch (token->keyword)
break; {
case RID_CONST:
cv_qualifier = TYPE_QUAL_CONST;
break;
case RID_VOLATILE:
cv_qualifier = TYPE_QUAL_VOLATILE;
break;
case RID_RESTRICT:
cv_qualifier = TYPE_QUAL_RESTRICT;
break;
default:
cv_qualifier = TYPE_UNQUALIFIED;
break;
}
if (!cv_qualifier)
break;
default: if (cv_quals & cv_qualifier)
break; {
error ("duplicate cv-qualifier");
cp_lexer_purge_token (parser->lexer);
}
else
{
cp_lexer_consume_token (parser->lexer);
cv_quals |= cv_qualifier;
}
} }
return cv_qualifier; return cv_quals;
} }
/* Parse a declarator-id. /* Parse a declarator-id.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment