|
|
1.1.1.3 root 1: /* Variables and structures for overloading rules.
2: Copyright (C) 1993 Free Software Foundation, Inc.
3:
4: This file is part of GNU CC.
5:
6: GNU CC is free software; you can redistribute it and/or modify
7: it under the terms of the GNU General Public License as published by
8: the Free Software Foundation; either version 2, or (at your option)
9: any later version.
10:
11: GNU CC is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with GNU CC; see the file COPYING. If not, write to
18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19:
1.1 root 20: /* The following structure is used when comparing various alternatives
21: for overloading. The unsigned quantity `strikes.i' is used
22: for fast comparison of two possibilities. This number is an
23: aggregate of four constituents:
24:
25: EVIL: if this is non-zero, then the candidate should not be considered
1.1.1.3 root 26: ELLIPSIS: if this is non-zero, then some actual argument has been matched
27: against an ellipsis
1.1 root 28: USER: if this is non-zero, then a user-defined type conversion is needed
29: B_OR_D: if this is non-zero, then use a base pointer instead of the
30: type of the pointer we started with.
31: EASY: if this is non-zero, then we have a builtin conversion
32: (such as int to long, int to float, etc) to do.
33:
34: If two candidates require user-defined type conversions, and the
35: type conversions are not identical, then an ambiguity error
36: is reported.
37:
38: If two candidates agree on user-defined type conversions,
39: and one uses pointers of strictly higher type (derived where
40: another uses base), then that alternative is silently chosen.
41:
42: If two candidates have a non-monotonic derived/base pointer
43: relationship, and/or a non-monotonic easy conversion relationship,
44: then a warning is emitted to show which paths are possible, and
45: which one is being chosen.
46:
47: For example:
48:
49: int i;
50: double x;
51:
52: overload f;
53: int f (int, int);
54: double f (double, double);
55:
56: f (i, x); // draws a warning
57:
58: struct B
59: {
60: f (int);
61: } *bb;
62: struct D : B
63: {
64: f (double);
65: } *dd;
66:
67: dd->f (x); // exact match
68: dd->f (i); // draws warning
69:
70: Note that this technique really only works for 255 arguments. Perhaps
71: this is not enough. */
72:
1.1.1.4 ! root 73: /* These macros and harshness_code are used by the NEW METHOD. */
! 74: #define EVIL_CODE (1<<7)
! 75: #define CONST_CODE (1<<6)
! 76: #define ELLIPSIS_CODE (1<<5)
! 77: #define USER_CODE (1<<4)
! 78: #define STD_CODE (1<<3)
! 79: #define PROMO_CODE (1<<2)
! 80: #define QUAL_CODE (1<<1)
! 81: #define TRIVIAL_CODE (1<<0)
! 82:
! 83: struct harshness_code
! 84: {
! 85: /* What kind of conversion is involved. */
! 86: unsigned short code;
! 87:
! 88: /* The inheritance distance. */
! 89: short distance;
! 90:
! 91: /* For a PROMO_CODE, Any special penalties involved in integral conversions.
! 92: This exists because $4.1 of the ARM states that something like
! 93: `short unsigned int' should promote to `int', not `unsigned int'.
! 94: If, for example, it tries to match two fns, f(int) and f(unsigned),
! 95: f(int) should be a better match than f(unsigned) by this rule. Without
! 96: this extra metric, they both only appear as "integral promotions", which
! 97: will lead to an ambiguity.
! 98: For a TRIVIAL_CODE, This is also used by build_overload_call_real and
! 99: convert_harshness to keep track of other information we need. */
! 100: unsigned short int_penalty;
! 101: };
! 102:
1.1 root 103: struct candidate
104: {
1.1.1.4 ! root 105: /* OLD METHOD */
! 106: unsigned char evil; /* !0 if this will never convert. */
! 107: unsigned char ellipsis; /* !0 if a match against an ellipsis occurred */
! 108: unsigned char user; /* !0 if at least one user-defined type conv. */
! 109: unsigned short b_or_d; /* count number of derived->base or
! 110: base->derived conv. */
! 111: unsigned short easy; /* count number of builtin type conv. */
1.1 root 112:
1.1.1.4 ! root 113: /* NEW METHOD */
! 114: struct harshness_code h; /* Used for single-argument conversions. */
! 115:
! 116: int h_len; /* The length of the harshness vector. */
! 117:
! 118: /* Both methods. */
! 119: tree function; /* A FUNCTION_DECL */
1.1 root 120: tree arg; /* first parm to function. */
1.1.1.4 ! root 121:
! 122: /* This union is only here while we maintain both the old and new
! 123: argument matching schemes. When it goes away, all v.ansi_harshness
! 124: references will be just `harshness'. */
! 125: union
! 126: {
! 127: /* Indexed by argument number, encodes evil, user, d_to_b, and easy
! 128: strikes for that argument. At end of array, we store the index+1
! 129: of where we started using default parameters, or 0 if there are
! 130: none. */
! 131: struct harshness_code *ansi_harshness; /* NEW METHOD */
! 132: unsigned short *old_harshness; /* OLD METHOD */
! 133: } v;
! 134:
1.1 root 135: union
136: {
137: tree field; /* If no evil strikes, the FUNCTION_DECL of
138: the function (if a member function). */
139: int bad_arg; /* the index of the first bad argument:
1.1.1.2 root 140: 0 if no bad arguments
1.1 root 141: > 0 is first bad argument
142: -1 if extra actual arguments
143: -2 if too few actual arguments.
144: -3 if const/non const method mismatch.
145: -4 if type unification failed.
146: -5 if contravariance violation. */
147: } u;
148: };
149: int rank_for_overload ();
150:
151: /* Variables shared between cp-class.c and cp-call.c. */
152:
153: extern int n_vtables;
154: extern int n_vtable_entries;
155: extern int n_vtable_searches;
156: extern int n_vtable_elems;
157: extern int n_convert_harshness;
158: extern int n_compute_conversion_costs;
159: extern int n_build_method_call;
160: extern int n_inner_fields_searched;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.