This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH for type-checking improvements
>>>>> Mark Mitchell <mark@markmitchell.com> writes:
>>>>> "Jason" == Jason Merrill <jason@cygnus.com> writes:
Jason> You can simplify the handling of type in grokdeclarator
Jason> further; you can move the build_type_variant call down
Jason> instead of adding a new one, and remove the similar calls
Jason> in the main loop.
> I decided I didn't understand this comment. I checked in the patch,
> since you didn't seem to be talking about correctness, only about an
> optimization. Would you mind explaining it in more detail?
I went ahead and cleaned it up myself:
1998-10-04 Jason Merrill <jason@yorick.cygnus.com>
* decl.c (grokdeclarator): Remove redundant calls to
build_type_variant and some duplicated code.
* sig.c (build_signature_reference_type): Only take the type parm.
(build_signature_pointer_type): Likewise.
* tree.c (build_cplus_method_type): Adjust.
* cp-tree.h: Update.
Index: cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.144
diff -c -p -r1.144 cp-tree.h
*** cp-tree.h 1998/10/01 12:31:20 1.144
--- cp-tree.h 1998/10/04 23:18:16
*************** extern void enter_scope_of
*** 2960,2967 ****
extern tree finish_base_specifier PROTO((tree, tree, int));
/* in sig.c */
! extern tree build_signature_pointer_type PROTO((tree, int, int));
! extern tree build_signature_reference_type PROTO((tree, int, int));
extern tree build_signature_pointer_constructor PROTO((tree, tree));
extern tree build_signature_method_call PROTO((tree, tree));
extern tree build_optr_ref PROTO((tree));
--- 2960,2967 ----
extern tree finish_base_specifier PROTO((tree, tree, int));
/* in sig.c */
! extern tree build_signature_pointer_type PROTO((tree));
! extern tree build_signature_reference_type PROTO((tree));
extern tree build_signature_pointer_constructor PROTO((tree, tree));
extern tree build_signature_method_call PROTO((tree, tree));
extern tree build_optr_ref PROTO((tree));
Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.220
diff -c -p -r1.220 decl.c
*** decl.c 1998/10/03 23:11:10 1.220
--- decl.c 1998/10/04 23:18:17
*************** grokdeclarator (declarator, declspecs, d
*** 9460,9474 ****
resume_momentary (yes);
}
- /* Build the array type itself, then merge any constancy or
- volatility into the target type. We must do it in this order
- to ensure that the TYPE_MAIN_VARIANT field of the array type
- is set correctly. */
-
type = build_cplus_array_type (type, itype);
- if (constp || volatilep)
- type = cp_build_type_variant (type, constp, volatilep);
-
ctype = NULL_TREE;
}
break;
--- 9460,9466 ----
*************** grokdeclarator (declarator, declspecs, d
*** 9482,9504 ****
/* Declaring a function type.
Make sure we have a valid type for the function to return. */
- #if 0
- /* Is this an error? Should they be merged into TYPE here? */
- if (pedantic && (constp || volatilep))
- pedwarn ("function declared to return const or volatile result");
- #else
- /* Merge any constancy or volatility into the function return
- type. */
! if (constp || volatilep)
! {
! type = cp_build_type_variant (type, constp, volatilep);
! if (IS_AGGR_TYPE (type))
! build_pointer_type (type);
! constp = 0;
! volatilep = 0;
! }
! #endif
/* Warn about some types functions can't return. */
--- 9474,9483 ----
/* Declaring a function type.
Make sure we have a valid type for the function to return. */
! /* We now know that constp and volatilep don't apply to the
! decl, but to its return type. */
! constp = volatilep = 0;
/* Warn about some types functions can't return. */
*************** grokdeclarator (declarator, declspecs, d
*** 9703,9726 ****
type = TREE_TYPE (type);
}
! /* Merge any constancy or volatility into the target type
! for the pointer. */
!
! if (constp || volatilep)
! {
! /* A const or volatile signature pointer/reference is
! pointing to a const or volatile object, i.e., the
! `optr' is const or volatile, respectively, not the
! signature pointer/reference itself. */
! if (! IS_SIGNATURE (type))
! {
! type = cp_build_type_variant (type, constp, volatilep);
! if (IS_AGGR_TYPE (type))
! build_pointer_type (type);
! constp = 0;
! volatilep = 0;
! }
! }
if (IS_SIGNATURE (type))
{
--- 9682,9690 ----
type = TREE_TYPE (type);
}
! /* We now know that constp and volatilep don't apply to the
! decl, but to the target of the pointer. */
! constp = volatilep = 0;
if (IS_SIGNATURE (type))
{
*************** grokdeclarator (declarator, declspecs, d
*** 9731,9738 ****
cp_warning ("empty signature `%T' used in signature reference declaration",
type);
#if 0
! type = build_signature_reference_type (type,
! constp, volatilep);
#else
sorry ("signature reference");
return NULL_TREE;
--- 9695,9701 ----
cp_warning ("empty signature `%T' used in signature reference declaration",
type);
#if 0
! type = build_signature_reference_type (type);
#else
sorry ("signature reference");
return NULL_TREE;
*************** grokdeclarator (declarator, declspecs, d
*** 9744,9751 ****
&& TYPE_SIZE (type))
cp_warning ("empty signature `%T' used in signature pointer declaration",
type);
! type = build_signature_pointer_type (type,
! constp, volatilep);
}
constp = 0;
volatilep = 0;
--- 9707,9713 ----
&& TYPE_SIZE (type))
cp_warning ("empty signature `%T' used in signature pointer declaration",
type);
! type = build_signature_pointer_type (type);
}
constp = 0;
volatilep = 0;
*************** grokdeclarator (declarator, declspecs, d
*** 9904,9911 ****
{
if (current_class_type == NULL_TREE
|| friendp)
! type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
! TREE_TYPE (type), TYPE_ARG_TYPES (type));
else
{
cp_error ("cannot declare member function `%T::%s' within `%T'",
--- 9866,9873 ----
{
if (current_class_type == NULL_TREE
|| friendp)
! type = build_cplus_method_type (ctype, TREE_TYPE (type),
! TYPE_ARG_TYPES (type));
else
{
cp_error ("cannot declare member function `%T::%s' within `%T'",
*************** grokdeclarator (declarator, declspecs, d
*** 9933,9942 ****
{
if (TREE_CODE (type) == FUNCTION_TYPE)
type
! = build_cplus_method_type (build_type_variant (ctype,
! constp,
! volatilep),
! TREE_TYPE (type),
TYPE_ARG_TYPES (type));
}
else
--- 9895,9901 ----
{
if (TREE_CODE (type) == FUNCTION_TYPE)
type
! = build_cplus_method_type (ctype, TREE_TYPE (type),
TYPE_ARG_TYPES (type));
}
else
*************** grokdeclarator (declarator, declspecs, d
*** 9959,9965 ****
else
{
if (TREE_CODE (type) == FUNCTION_TYPE)
! type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
else
type = build_offset_type (ctype, type);
}
--- 9918,9925 ----
else
{
if (TREE_CODE (type) == FUNCTION_TYPE)
! type = build_cplus_method_type (ctype, TREE_TYPE (type),
! TYPE_ARG_TYPES (type));
else
type = build_offset_type (ctype, type);
}
*************** grokdeclarator (declarator, declspecs, d
*** 10016,10023 ****
/* Note that the grammar rejects storage classes
in typenames, fields or parameters. */
- if (constp || volatilep)
- type = cp_build_type_variant (type, constp, volatilep);
if (current_lang_name == lang_name_java)
TYPE_FOR_JAVA (type) = 1;
--- 9976,9981 ----
*************** grokdeclarator (declarator, declspecs, d
*** 10140,10147 ****
{
if (IS_SIGNATURE (type))
error ("`const' or `volatile' specified with signature type");
- else
- type = cp_build_type_variant (type, constp, volatilep);
}
/* Special case: "friend class foo" looks like a TYPENAME context. */
--- 10098,10103 ----
*************** grokdeclarator (declarator, declspecs, d
*** 10217,10251 ****
/* Now create the decl, which may be a VAR_DECL, a PARM_DECL
or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
{
register tree decl;
if (decl_context == PARM)
{
- if (ctype || in_namespace)
- error ("cannot use `::' in parameter declaration");
-
- /* A parameter declared as an array of T is really a pointer to T.
- One declared as a function is really a pointer to a function.
- One declared as a member is really a pointer to member. */
-
- if (TREE_CODE (type) == ARRAY_TYPE)
- {
- /* Transfer const-ness of array into that of type pointed to. */
- type = build_pointer_type
- (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
- volatilep = constp = 0;
- }
- else if (TREE_CODE (type) == FUNCTION_TYPE)
- type = build_pointer_type (type);
- else if (TREE_CODE (type) == OFFSET_TYPE)
- type = build_pointer_type (type);
- else if (TREE_CODE (type) == VOID_TYPE && declarator)
- {
- error ("declaration of `%s' as void", name);
- return NULL_TREE;
- }
-
decl = build_decl (PARM_DECL, declarator, complete_type (type));
bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
--- 10173,10209 ----
/* Now create the decl, which may be a VAR_DECL, a PARM_DECL
or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
+ if (decl_context == PARM || decl_context == CATCHPARM)
+ {
+ if (ctype || in_namespace)
+ error ("cannot use `::' in parameter declaration");
+
+ /* A parameter declared as an array of T is really a pointer to T.
+ One declared as a function is really a pointer to a function.
+ One declared as a member is really a pointer to member. */
+
+ if (TREE_CODE (type) == ARRAY_TYPE)
+ {
+ /* Transfer const-ness of array into that of type pointed to. */
+ type = build_pointer_type (TREE_TYPE (type));
+ volatilep = constp = 0;
+ }
+ else if (TREE_CODE (type) == FUNCTION_TYPE)
+ type = build_pointer_type (type);
+ else if (TREE_CODE (type) == OFFSET_TYPE)
+ type = build_pointer_type (type);
+ else if (TREE_CODE (type) == VOID_TYPE && declarator)
+ {
+ error ("declaration of `%s' as void", name);
+ return NULL_TREE;
+ }
+ }
+
{
register tree decl;
if (decl_context == PARM)
{
decl = build_decl (PARM_DECL, declarator, complete_type (type));
bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
*************** grokdeclarator (declarator, declspecs, d
*** 10330,10337 ****
}
}
else if (staticp < 2)
! type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
! TREE_TYPE (type), TYPE_ARG_TYPES (type));
}
/* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
--- 10288,10295 ----
}
}
else if (staticp < 2)
! type = build_cplus_method_type (ctype, TREE_TYPE (type),
! TYPE_ARG_TYPES (type));
}
/* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
*************** grokdeclarator (declarator, declspecs, d
*** 10571,10578 ****
declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
}
else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
! type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
! TREE_TYPE (type), TYPE_ARG_TYPES (type));
/* Record presence of `static'. */
publicp = (ctype != NULL_TREE
--- 10529,10536 ----
declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
}
else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
! type = build_cplus_method_type (ctype, TREE_TYPE (type),
! TYPE_ARG_TYPES (type));
/* Record presence of `static'. */
publicp = (ctype != NULL_TREE
*************** grokdeclarator (declarator, declspecs, d
*** 10625,10656 ****
else
{
/* It's a variable. */
-
- if (decl_context == CATCHPARM)
- {
- if (ctype)
- {
- ctype = NULL_TREE;
- error ("cannot use `::' in parameter declaration");
- }
-
- /* A parameter declared as an array of T is really a pointer to T.
- One declared as a function is really a pointer to a function.
- One declared as a member is really a pointer to member. */
-
- if (TREE_CODE (type) == ARRAY_TYPE)
- {
- /* Transfer const-ness of array into that of type
- pointed to. */
- type = build_pointer_type
- (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
- volatilep = constp = 0;
- }
- else if (TREE_CODE (type) == FUNCTION_TYPE)
- type = build_pointer_type (type);
- else if (TREE_CODE (type) == OFFSET_TYPE)
- type = build_pointer_type (type);
- }
/* An uninitialized decl with `extern' is a reference. */
decl = grokvardecl (type, declarator, &specbits,
--- 10583,10588 ----
Index: sig.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/sig.c,v
retrieving revision 1.11
diff -c -p -r1.11 sig.c
*** sig.c 1998/10/03 23:11:16 1.11
--- sig.c 1998/10/04 23:18:17
*************** build_signature_pointer_or_reference_typ
*** 250,272 ****
/* Construct, lay out and return the type of pointers to signature TO_TYPE. */
tree
! build_signature_pointer_type (to_type, constp, volatilep)
tree to_type;
- int constp, volatilep;
{
return
! build_signature_pointer_or_reference_type (to_type, constp, volatilep, 0);
}
/* Construct, lay out and return the type of pointers to signature TO_TYPE. */
tree
! build_signature_reference_type (to_type, constp, volatilep)
tree to_type;
- int constp, volatilep;
{
return
! build_signature_pointer_or_reference_type (to_type, constp, volatilep, 1);
}
/* Return the name of the signature table (as an IDENTIFIER_NODE)
--- 250,274 ----
/* Construct, lay out and return the type of pointers to signature TO_TYPE. */
tree
! build_signature_pointer_type (to_type)
tree to_type;
{
return
! build_signature_pointer_or_reference_type (TYPE_MAIN_VARIANT (to_type),
! TYPE_READONLY (to_type),
! TYPE_VOLATILE (to_type), 0);
}
/* Construct, lay out and return the type of pointers to signature TO_TYPE. */
tree
! build_signature_reference_type (to_type)
tree to_type;
{
return
! build_signature_pointer_or_reference_type (TYPE_MAIN_VARIANT (to_type),
! TYPE_READONLY (to_type),
! TYPE_VOLATILE (to_type), 1);
}
/* Return the name of the signature table (as an IDENTIFIER_NODE)
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/tree.c,v
retrieving revision 1.68
diff -c -p -r1.68 tree.c
*** tree.c 1998/10/03 23:11:17 1.68
--- tree.c 1998/10/04 23:18:17
*************** build_cplus_method_type (basetype, retty
*** 377,385 ****
TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
TREE_TYPE (t) = rettype;
if (IS_SIGNATURE (basetype))
! ptype = build_signature_pointer_type (TYPE_MAIN_VARIANT (basetype),
! TYPE_READONLY (basetype),
! TYPE_VOLATILE (basetype));
else
ptype = build_pointer_type (basetype);
--- 377,383 ----
TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
TREE_TYPE (t) = rettype;
if (IS_SIGNATURE (basetype))
! ptype = build_signature_pointer_type (basetype);
else
ptype = build_pointer_type (basetype);