]>
Commit | Line | Data |
---|---|---|
596ea4e5 | 1 | /* -*-C-*- |
c8094d83 | 2 | |
596ea4e5 AS |
3 | This file contains definitions of the various C++ operators, |
4 | including both overloadable operators (like `+') and | |
c8094d83 | 5 | non-overloadable operators (like the `?:' ternary operator). |
b599b135 | 6 | Written by Mark Mitchell <mark@codesourcery.com> |
596ea4e5 | 7 | |
818ab71a | 8 | Copyright (C) 2000-2016 Free Software Foundation, Inc. |
596ea4e5 | 9 | |
b599b135 | 10 | This file is part of GCC. |
596ea4e5 | 11 | |
b599b135 | 12 | GCC is free software; you can redistribute it and/or modify |
596ea4e5 | 13 | it under the terms of the GNU General Public License as published by |
e77f031d | 14 | the Free Software Foundation; either version 3, or (at your option) |
596ea4e5 AS |
15 | any later version. |
16 | ||
b599b135 | 17 | GCC is distributed in the hope that it will be useful, |
596ea4e5 AS |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | GNU General Public License for more details. | |
21 | ||
22 | You should have received a copy of the GNU General Public License | |
e77f031d NC |
23 | along with GCC; see the file COPYING3. If not see |
24 | <http://www.gnu.org/licenses/>. */ | |
596ea4e5 AS |
25 | |
26 | /* The DEF_OPERATOR macro takes the following arguments: | |
27 | ||
28 | NAME | |
29 | ||
30 | The name of the operator, as a C string, but without the | |
aba649ba | 31 | preceding `operator'. This is the name that would be given in |
596ea4e5 AS |
32 | the source program. For `operator +', for example, this would be |
33 | `+'. | |
c8094d83 | 34 | |
596ea4e5 AS |
35 | CODE |
36 | ||
37 | The tree_code for this operator. For `operator +', for example, | |
38 | this would be PLUS_EXPR. Because there are no tree codes for | |
39 | assignment operators, the same tree-codes are reused; i.e., | |
40 | `operator +' will also have PLUS_EXPR as its CODE. | |
41 | ||
b80f8ef3 | 42 | MANGLING |
596ea4e5 AS |
43 | |
44 | The mangling prefix for the operator, as a C string, and as | |
45 | mangled under the new ABI. For `operator +', for example, this | |
46 | would be "pl". | |
47 | ||
596ea4e5 | 48 | ARITY |
c8094d83 | 49 | |
596ea4e5 AS |
50 | The arity of the operator, or -1 if any arity is allowed. (As |
51 | for `operator ()'.) Postincrement and postdecrement operators | |
52 | are marked as binary. | |
53 | ||
54 | ASSN_P | |
55 | ||
838dfd8a | 56 | A boolean value. If nonzero, this is an assignment operator. |
596ea4e5 | 57 | |
39a13be5 | 58 | Before including this file, you should define DEF_OPERATOR |
c8094d83 | 59 | to take these arguments. |
596ea4e5 AS |
60 | |
61 | There is code (such as in grok_op_properties) that depends on the | |
62 | order the operators are presented in this file. In particular, | |
aba649ba | 63 | unary operators must precede binary operators. */ |
c8094d83 | 64 | |
596ea4e5 AS |
65 | /* Use DEF_SIMPLE_OPERATOR to define a non-assignment operator. Its |
66 | arguments are as for DEF_OPERATOR, but there is no need to provide | |
67 | an ASSIGNMENT_P argument; it is always zero. */ | |
68 | ||
0c918ce5 MM |
69 | #define DEF_SIMPLE_OPERATOR(NAME, CODE, MANGLING, ARITY) \ |
70 | DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, 0) | |
596ea4e5 AS |
71 | |
72 | /* Use DEF_ASSN_OPERATOR to define an assignment operator. Its | |
73 | arguments are as for DEF_OPERATOR, but there is no need to provide | |
74 | an ASSIGNMENT_P argument; it is always one. */ | |
75 | ||
0c918ce5 MM |
76 | #define DEF_ASSN_OPERATOR(NAME, CODE, MANGLING, ARITY) \ |
77 | DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, 1) | |
596ea4e5 AS |
78 | |
79 | /* Memory allocation operators. */ | |
0c918ce5 MM |
80 | DEF_SIMPLE_OPERATOR ("new", NEW_EXPR, "nw", -1) |
81 | DEF_SIMPLE_OPERATOR ("new []", VEC_NEW_EXPR, "na", -1) | |
82 | DEF_SIMPLE_OPERATOR ("delete", DELETE_EXPR, "dl", -1) | |
83 | DEF_SIMPLE_OPERATOR ("delete []", VEC_DELETE_EXPR, "da", -1) | |
596ea4e5 AS |
84 | |
85 | /* Unary operators. */ | |
392e3d51 | 86 | DEF_SIMPLE_OPERATOR ("+", UNARY_PLUS_EXPR, "ps", 1) |
0c918ce5 MM |
87 | DEF_SIMPLE_OPERATOR ("-", NEGATE_EXPR, "ng", 1) |
88 | DEF_SIMPLE_OPERATOR ("&", ADDR_EXPR, "ad", 1) | |
89 | DEF_SIMPLE_OPERATOR ("*", INDIRECT_REF, "de", 1) | |
90 | DEF_SIMPLE_OPERATOR ("~", BIT_NOT_EXPR, "co", 1) | |
91 | DEF_SIMPLE_OPERATOR ("!", TRUTH_NOT_EXPR, "nt", 1) | |
92 | DEF_SIMPLE_OPERATOR ("++", PREINCREMENT_EXPR, "pp", 1) | |
93 | DEF_SIMPLE_OPERATOR ("--", PREDECREMENT_EXPR, "mm", 1) | |
94 | DEF_SIMPLE_OPERATOR ("sizeof", SIZEOF_EXPR, "sz", 1) | |
e05f7974 | 95 | /* These are extensions. */ |
448545cb | 96 | DEF_SIMPLE_OPERATOR ("alignof", ALIGNOF_EXPR, "az", 1) |
e05f7974 NN |
97 | DEF_SIMPLE_OPERATOR ("__imag__", IMAGPART_EXPR, "v18__imag__", 1) |
98 | DEF_SIMPLE_OPERATOR ("__real__", REALPART_EXPR, "v18__real__", 1) | |
596ea4e5 AS |
99 | |
100 | /* The cast operator. */ | |
0c918ce5 | 101 | DEF_SIMPLE_OPERATOR ("", TYPE_EXPR, "cv", 1) |
873ff987 | 102 | DEF_SIMPLE_OPERATOR ("", CAST_EXPR, "cv", 1) |
4b6aaa99 JM |
103 | DEF_SIMPLE_OPERATOR ("dynamic_cast", DYNAMIC_CAST_EXPR, "dc", 1) |
104 | DEF_SIMPLE_OPERATOR ("reinterpret_cast", REINTERPRET_CAST_EXPR, "rc", 1) | |
105 | DEF_SIMPLE_OPERATOR ("const_cast", CONST_CAST_EXPR, "cc", 1) | |
106 | DEF_SIMPLE_OPERATOR ("static_cast", STATIC_CAST_EXPR, "sc", 1) | |
596ea4e5 AS |
107 | |
108 | /* Binary operators. */ | |
0c918ce5 MM |
109 | DEF_SIMPLE_OPERATOR ("+", PLUS_EXPR, "pl", 2) |
110 | DEF_SIMPLE_OPERATOR ("-", MINUS_EXPR, "mi", 2) | |
111 | DEF_SIMPLE_OPERATOR ("*", MULT_EXPR, "ml", 2) | |
112 | DEF_SIMPLE_OPERATOR ("/", TRUNC_DIV_EXPR, "dv", 2) | |
113 | DEF_SIMPLE_OPERATOR ("%", TRUNC_MOD_EXPR, "rm", 2) | |
114 | DEF_SIMPLE_OPERATOR ("&", BIT_AND_EXPR, "an", 2) | |
115 | DEF_SIMPLE_OPERATOR ("|", BIT_IOR_EXPR, "or", 2) | |
116 | DEF_SIMPLE_OPERATOR ("^", BIT_XOR_EXPR, "eo", 2) | |
117 | DEF_SIMPLE_OPERATOR ("<<", LSHIFT_EXPR, "ls", 2) | |
118 | DEF_SIMPLE_OPERATOR (">>", RSHIFT_EXPR, "rs", 2) | |
119 | DEF_SIMPLE_OPERATOR ("==", EQ_EXPR, "eq", 2) | |
120 | DEF_SIMPLE_OPERATOR ("!=", NE_EXPR, "ne", 2) | |
121 | DEF_SIMPLE_OPERATOR ("<", LT_EXPR, "lt", 2) | |
122 | DEF_SIMPLE_OPERATOR (">", GT_EXPR, "gt", 2) | |
123 | DEF_SIMPLE_OPERATOR ("<=", LE_EXPR, "le", 2) | |
124 | DEF_SIMPLE_OPERATOR (">=", GE_EXPR, "ge", 2) | |
125 | DEF_SIMPLE_OPERATOR ("&&", TRUTH_ANDIF_EXPR, "aa", 2) | |
126 | DEF_SIMPLE_OPERATOR ("||", TRUTH_ORIF_EXPR, "oo", 2) | |
127 | DEF_SIMPLE_OPERATOR (",", COMPOUND_EXPR, "cm", 2) | |
128 | DEF_SIMPLE_OPERATOR ("->*", MEMBER_REF, "pm", 2) | |
4b6aaa99 | 129 | DEF_SIMPLE_OPERATOR (".*", DOTSTAR_EXPR, "ds", 2) |
ee429f84 | 130 | DEF_SIMPLE_OPERATOR ("->", COMPONENT_REF, "pt", 2) |
0c918ce5 MM |
131 | DEF_SIMPLE_OPERATOR ("[]", ARRAY_REF, "ix", 2) |
132 | DEF_SIMPLE_OPERATOR ("++", POSTINCREMENT_EXPR, "pp", 2) | |
133 | DEF_SIMPLE_OPERATOR ("--", POSTDECREMENT_EXPR, "mm", 2) | |
1f6e1acc | 134 | /* This one is needed for mangling. */ |
de94b46c | 135 | DEF_SIMPLE_OPERATOR ("::", SCOPE_REF, "sr", 2) |
596ea4e5 AS |
136 | |
137 | /* Assignment operators. */ | |
0c918ce5 MM |
138 | DEF_ASSN_OPERATOR ("=", NOP_EXPR, "aS", 2) |
139 | DEF_ASSN_OPERATOR ("+=", PLUS_EXPR, "pL", 2) | |
140 | DEF_ASSN_OPERATOR ("-=", MINUS_EXPR, "mI", 2) | |
141 | DEF_ASSN_OPERATOR ("*=", MULT_EXPR, "mL", 2) | |
142 | DEF_ASSN_OPERATOR ("/=", TRUNC_DIV_EXPR, "dV", 2) | |
143 | DEF_ASSN_OPERATOR ("%=", TRUNC_MOD_EXPR, "rM", 2) | |
144 | DEF_ASSN_OPERATOR ("&=", BIT_AND_EXPR, "aN", 2) | |
145 | DEF_ASSN_OPERATOR ("|=", BIT_IOR_EXPR, "oR", 2) | |
146 | DEF_ASSN_OPERATOR ("^=", BIT_XOR_EXPR, "eO", 2) | |
147 | DEF_ASSN_OPERATOR ("<<=", LSHIFT_EXPR, "lS", 2) | |
148 | DEF_ASSN_OPERATOR (">>=", RSHIFT_EXPR, "rS", 2) | |
596ea4e5 AS |
149 | |
150 | /* Ternary operators. */ | |
0c918ce5 | 151 | DEF_SIMPLE_OPERATOR ("?:", COND_EXPR, "qu", 3) |
596ea4e5 AS |
152 | |
153 | /* Miscellaneous. */ | |
0c918ce5 | 154 | DEF_SIMPLE_OPERATOR ("()", CALL_EXPR, "cl", -1) |
5d80a306 DG |
155 | |
156 | /* Variadic templates extension. */ | |
38179091 | 157 | DEF_SIMPLE_OPERATOR ("...", EXPR_PACK_EXPANSION, "sp", 1) |
aa30dfad JM |
158 | DEF_SIMPLE_OPERATOR ("... +", UNARY_LEFT_FOLD_EXPR, "fl", 2) |
159 | DEF_SIMPLE_OPERATOR ("+ ...", UNARY_RIGHT_FOLD_EXPR, "fr", 2) | |
160 | DEF_SIMPLE_OPERATOR ("+ ... +", BINARY_LEFT_FOLD_EXPR, "fL", 3) | |
161 | DEF_SIMPLE_OPERATOR ("+ ... +", BINARY_RIGHT_FOLD_EXPR, "fR", 3) |