diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 1999-03-27 01:14:32 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 1999-03-27 01:14:32 +0000 |
commit | 3e8b52bc4d6c80a660e95df968955c1d36f94768 (patch) | |
tree | 4086e96a602efdf3a10ed4ec0732e7e00e382c80 /gcc | |
parent | f3516f2d9ceb0e12650d7f01f902ee96d06e556e (diff) | |
download | gcc-3e8b52bc4d6c80a660e95df968955c1d36f94768.tar.gz |
* call.c (build_field_call): Unify 'this' and non-'this' cases.
* typeck.c (build_indirect_ref): Check for 'this' sooner.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@26012 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/call.c | 100 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 6 |
3 files changed, 33 insertions, 79 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 14254ece8f3..0138c8461b4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +1999-03-27 Jason Merrill <jason@yorick.cygnus.com> + + * call.c (build_field_call): Unify 'this' and non-'this' cases. + + * typeck.c (build_indirect_ref): Check for 'this' sooner. + Fri Mar 26 10:20:34 1999 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> * call.c (op_error): Const-ify a char*. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 3a1af797657..9bc349e7999 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -128,92 +128,40 @@ build_field_call (basetype_path, instance_ptr, name, parms) if (name == ctor_identifier || name == dtor_identifier) return NULL_TREE; - if (instance_ptr == current_class_ptr) - { - /* Check to see if we really have a reference to an instance variable - with `operator()()' overloaded. */ - field = IDENTIFIER_CLASS_VALUE (name); - - if (field == NULL_TREE) - { - cp_error ("`this' has no member named `%D'", name); - return error_mark_node; - } - - if (TREE_CODE (field) == FIELD_DECL || TREE_CODE (field) == VAR_DECL) - { - /* If it's a field, try overloading operator (), - or calling if the field is a pointer-to-function. */ - instance = build_component_ref_1 (current_class_ref, field, 0); - if (instance == error_mark_node) - return error_mark_node; - - if (TYPE_LANG_SPECIFIC (TREE_TYPE (instance))) - return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, instance, parms, NULL_TREE); - - if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE) - { - if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == FUNCTION_TYPE) - return build_function_call (instance, parms); - else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == METHOD_TYPE) - return build_function_call (instance, expr_tree_cons (NULL_TREE, current_class_ptr, parms)); - } - } - return NULL_TREE; - } + /* Speed up the common case. */ + if (instance_ptr == current_class_ptr + && IDENTIFIER_CLASS_VALUE (name) == NULL_TREE) + return NULL_TREE; - /* Check to see if this is not really a reference to an instance variable - with `operator()()' overloaded. */ field = lookup_field (basetype_path, name, 1, 0); - /* This can happen if the reference was ambiguous or for access - violations. */ - if (field == error_mark_node) - return error_mark_node; + if (field == error_mark_node || field == NULL_TREE) + return field; - if (field && (TREE_CODE (field) == FIELD_DECL || - TREE_CODE (field) == VAR_DECL)) + if (TREE_CODE (field) == FIELD_DECL || TREE_CODE (field) == VAR_DECL) { - tree basetype; - tree ftype = TREE_TYPE (field); + /* If it's a field, try overloading operator (), + or calling if the field is a pointer-to-function. */ + instance = build_indirect_ref (instance_ptr, NULL_PTR); + instance = build_component_ref_1 (instance, field, 0); - if (TREE_CODE (ftype) == REFERENCE_TYPE) - ftype = TREE_TYPE (ftype); + if (instance == error_mark_node) + return error_mark_node; - if (TYPE_LANG_SPECIFIC (ftype)) - { - /* Make the next search for this field very short. */ - basetype = DECL_FIELD_CONTEXT (field); - instance_ptr = convert_pointer_to (basetype, instance_ptr); - - instance = build_indirect_ref (instance_ptr, NULL_PTR); - return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, - build_component_ref_1 (instance, field, 0), - parms, NULL_TREE); - } - if (TREE_CODE (ftype) == POINTER_TYPE) - { - if (TREE_CODE (TREE_TYPE (ftype)) == FUNCTION_TYPE - || TREE_CODE (TREE_TYPE (ftype)) == METHOD_TYPE) - { - /* This is a member which is a pointer to function. */ - tree ref - = build_component_ref_1 (build_indirect_ref (instance_ptr, - NULL_PTR), - field, LOOKUP_COMPLAIN); - if (ref == error_mark_node) - return error_mark_node; - return build_function_call (ref, parms); - } - } - else if (TREE_CODE (ftype) == METHOD_TYPE) + if (IS_AGGR_TYPE (TREE_TYPE (instance))) + return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, + instance, parms, NULL_TREE); + else if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE) { - error ("invalid call via pointer-to-member function"); - return error_mark_node; + if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == FUNCTION_TYPE) + return build_function_call (instance, parms); + else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) + == METHOD_TYPE) + return build_function_call + (instance, expr_tree_cons (NULL_TREE, instance_ptr, parms)); } - else - return NULL_TREE; } + return NULL_TREE; } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index f1fa51f4528..2012546f6f4 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2345,13 +2345,13 @@ build_indirect_ref (ptr, errorstring) if (ptr == error_mark_node) return error_mark_node; + if (ptr == current_class_ptr) + return current_class_ref; + pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE ? ptr : default_conversion (ptr)); type = TREE_TYPE (pointer); - if (ptr == current_class_ptr) - return current_class_ref; - if (TYPE_PTR_P (type) || TREE_CODE (type) == REFERENCE_TYPE) { /* [expr.unary.op] |