]>
Commit | Line | Data |
---|---|---|
97cc4539 | 1 | /* -*-C-*- |
9031d10b | 2 | |
97cc4539 | 3 | This file contains definitions of the various C++ operators, |
4 | including both overloadable operators (like `+') and | |
9031d10b | 5 | non-overloadable operators (like the `?:' ternary operator). |
5d1e9c98 | 6 | Written by Mark Mitchell <mark@codesourcery.com> |
97cc4539 | 7 | |
fbd26352 | 8 | Copyright (C) 2000-2019 Free Software Foundation, Inc. |
97cc4539 | 9 | |
5d1e9c98 | 10 | This file is part of GCC. |
97cc4539 | 11 | |
5d1e9c98 | 12 | GCC is free software; you can redistribute it and/or modify |
97cc4539 | 13 | it under the terms of the GNU General Public License as published by |
aa139c3f | 14 | the Free Software Foundation; either version 3, or (at your option) |
97cc4539 | 15 | any later version. |
16 | ||
5d1e9c98 | 17 | GCC is distributed in the hope that it will be useful, |
97cc4539 | 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 | |
aa139c3f | 23 | along with GCC; see the file COPYING3. If not see |
24 | <http://www.gnu.org/licenses/>. */ | |
97cc4539 | 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 | |
4109ca29 | 31 | preceding `operator'. This is the name that would be given in |
97cc4539 | 32 | the source program. For `operator +', for example, this would be |
33 | `+'. | |
9031d10b | 34 | |
97cc4539 | 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 | ||
84303c41 | 42 | MANGLING |
97cc4539 | 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 | ||
02938df3 | 48 | FLAGS |
9031d10b | 49 | |
02938df3 | 50 | ovl_op_flags bits. Postincrement and postdecrement operators are |
51 | marked as binary. | |
97cc4539 | 52 | |
08cc44e7 | 53 | Before including this file, you should define DEF_OPERATOR |
9031d10b | 54 | to take these arguments. |
97cc4539 | 55 | |
56 | There is code (such as in grok_op_properties) that depends on the | |
a543234d | 57 | order the operators are presented in this file. Unary_ops must |
58 | preceed a matching binary op (i.e. '+'). Assignment operators must | |
59 | be last, after OPERATOR_TRANSITION. */ | |
97cc4539 | 60 | |
61 | /* Use DEF_ASSN_OPERATOR to define an assignment operator. Its | |
62 | arguments are as for DEF_OPERATOR, but there is no need to provide | |
a543234d | 63 | FLAGS (OVL_OP_FLAG_BINARY). */ |
97cc4539 | 64 | |
a543234d | 65 | #ifndef DEF_ASSN_OPERATOR |
66 | #define DEF_ASSN_OPERATOR(NAME, CODE, MANGLING) \ | |
67 | DEF_OPERATOR(NAME, CODE, MANGLING, OVL_OP_FLAG_BINARY) | |
68 | #endif | |
97cc4539 | 69 | |
a543234d | 70 | /* Memory allocation operators. ARITY has special meaning. */ |
71 | DEF_OPERATOR ("new", NEW_EXPR, "nw", OVL_OP_FLAG_ALLOC) | |
02938df3 | 72 | DEF_OPERATOR ("new []", VEC_NEW_EXPR, "na", |
a543234d | 73 | OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC) |
02938df3 | 74 | DEF_OPERATOR ("delete", DELETE_EXPR, "dl", |
a543234d | 75 | OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE) |
02938df3 | 76 | DEF_OPERATOR ("delete []", VEC_DELETE_EXPR, "da", |
a543234d | 77 | OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC) |
97cc4539 | 78 | |
79 | /* Unary operators. */ | |
a543234d | 80 | DEF_OPERATOR ("+", UNARY_PLUS_EXPR, "ps", OVL_OP_FLAG_UNARY) |
81 | DEF_OPERATOR ("-", NEGATE_EXPR, "ng", OVL_OP_FLAG_UNARY) | |
82 | DEF_OPERATOR ("&", ADDR_EXPR, "ad", OVL_OP_FLAG_UNARY) | |
83 | DEF_OPERATOR ("*", INDIRECT_REF, "de", OVL_OP_FLAG_UNARY) | |
84 | DEF_OPERATOR ("~", BIT_NOT_EXPR, "co", OVL_OP_FLAG_UNARY) | |
85 | DEF_OPERATOR ("!", TRUTH_NOT_EXPR, "nt", OVL_OP_FLAG_UNARY) | |
86 | DEF_OPERATOR ("++", PREINCREMENT_EXPR, "pp", OVL_OP_FLAG_UNARY) | |
87 | DEF_OPERATOR ("--", PREDECREMENT_EXPR, "mm", OVL_OP_FLAG_UNARY) | |
88 | DEF_OPERATOR ("->", COMPONENT_REF, "pt", OVL_OP_FLAG_UNARY) | |
89 | DEF_OPERATOR ("sizeof", SIZEOF_EXPR, "sz", OVL_OP_FLAG_UNARY) | |
90 | ||
4a70b590 | 91 | /* These are extensions. */ |
a543234d | 92 | DEF_OPERATOR ("alignof", ALIGNOF_EXPR, "az", OVL_OP_FLAG_UNARY) |
93 | DEF_OPERATOR ("__imag__", IMAGPART_EXPR, "v18__imag__", OVL_OP_FLAG_UNARY) | |
94 | DEF_OPERATOR ("__real__", REALPART_EXPR, "v18__real__", OVL_OP_FLAG_UNARY) | |
97cc4539 | 95 | |
97cc4539 | 96 | /* Binary operators. */ |
a543234d | 97 | DEF_OPERATOR ("+", PLUS_EXPR, "pl", OVL_OP_FLAG_BINARY) |
98 | DEF_OPERATOR ("-", MINUS_EXPR, "mi", OVL_OP_FLAG_BINARY) | |
99 | DEF_OPERATOR ("*", MULT_EXPR, "ml", OVL_OP_FLAG_BINARY) | |
100 | DEF_OPERATOR ("/", TRUNC_DIV_EXPR, "dv", OVL_OP_FLAG_BINARY) | |
101 | DEF_OPERATOR ("%", TRUNC_MOD_EXPR, "rm", OVL_OP_FLAG_BINARY) | |
102 | DEF_OPERATOR ("&", BIT_AND_EXPR, "an", OVL_OP_FLAG_BINARY) | |
103 | DEF_OPERATOR ("|", BIT_IOR_EXPR, "or", OVL_OP_FLAG_BINARY) | |
104 | DEF_OPERATOR ("^", BIT_XOR_EXPR, "eo", OVL_OP_FLAG_BINARY) | |
105 | DEF_OPERATOR ("<<", LSHIFT_EXPR, "ls", OVL_OP_FLAG_BINARY) | |
106 | DEF_OPERATOR (">>", RSHIFT_EXPR, "rs", OVL_OP_FLAG_BINARY) | |
107 | DEF_OPERATOR ("==", EQ_EXPR, "eq", OVL_OP_FLAG_BINARY) | |
108 | DEF_OPERATOR ("!=", NE_EXPR, "ne", OVL_OP_FLAG_BINARY) | |
109 | DEF_OPERATOR ("<", LT_EXPR, "lt", OVL_OP_FLAG_BINARY) | |
110 | DEF_OPERATOR (">", GT_EXPR, "gt", OVL_OP_FLAG_BINARY) | |
111 | DEF_OPERATOR ("<=", LE_EXPR, "le", OVL_OP_FLAG_BINARY) | |
112 | DEF_OPERATOR (">=", GE_EXPR, "ge", OVL_OP_FLAG_BINARY) | |
113 | DEF_OPERATOR ("&&", TRUTH_ANDIF_EXPR, "aa", OVL_OP_FLAG_BINARY) | |
114 | DEF_OPERATOR ("||", TRUTH_ORIF_EXPR, "oo", OVL_OP_FLAG_BINARY) | |
115 | DEF_OPERATOR (",", COMPOUND_EXPR, "cm", OVL_OP_FLAG_BINARY) | |
116 | DEF_OPERATOR ("->*", MEMBER_REF, "pm", OVL_OP_FLAG_BINARY) | |
117 | DEF_OPERATOR (".*", DOTSTAR_EXPR, "ds", OVL_OP_FLAG_BINARY) | |
118 | DEF_OPERATOR ("[]", ARRAY_REF, "ix", OVL_OP_FLAG_BINARY) | |
119 | DEF_OPERATOR ("++", POSTINCREMENT_EXPR, "pp", OVL_OP_FLAG_BINARY) | |
120 | DEF_OPERATOR ("--", POSTDECREMENT_EXPR, "mm", OVL_OP_FLAG_BINARY) | |
daad7ad7 | 121 | |
122 | /* Miscellaneous. */ | |
a543234d | 123 | DEF_OPERATOR ("?:", COND_EXPR, "qu", OVL_OP_FLAG_NONE) |
124 | DEF_OPERATOR ("()", CALL_EXPR, "cl", OVL_OP_FLAG_NONE) | |
daad7ad7 | 125 | |
126 | /* Operators needed for mangling. */ | |
a543234d | 127 | DEF_OPERATOR (NULL, CAST_EXPR, "cv", OVL_OP_FLAG_UNARY) |
128 | DEF_OPERATOR (NULL, DYNAMIC_CAST_EXPR, "dc", OVL_OP_FLAG_UNARY) | |
129 | DEF_OPERATOR (NULL, REINTERPRET_CAST_EXPR, "rc", OVL_OP_FLAG_UNARY) | |
130 | DEF_OPERATOR (NULL, CONST_CAST_EXPR, "cc", OVL_OP_FLAG_UNARY) | |
131 | DEF_OPERATOR (NULL, STATIC_CAST_EXPR, "sc", OVL_OP_FLAG_UNARY) | |
132 | DEF_OPERATOR (NULL, SCOPE_REF, "sr", OVL_OP_FLAG_NONE) | |
133 | DEF_OPERATOR (NULL, EXPR_PACK_EXPANSION, "sp", OVL_OP_FLAG_NONE) | |
134 | DEF_OPERATOR (NULL, UNARY_LEFT_FOLD_EXPR, "fl", OVL_OP_FLAG_NONE) | |
135 | DEF_OPERATOR (NULL, UNARY_RIGHT_FOLD_EXPR, "fr", OVL_OP_FLAG_NONE) | |
136 | DEF_OPERATOR (NULL, BINARY_LEFT_FOLD_EXPR, "fL", OVL_OP_FLAG_NONE) | |
137 | DEF_OPERATOR (NULL, BINARY_RIGHT_FOLD_EXPR, "fR", OVL_OP_FLAG_NONE) | |
138 | ||
139 | #ifdef OPERATOR_TRANSITION | |
140 | OPERATOR_TRANSITION | |
141 | #undef OPERATOR_TRANSITION | |
142 | #endif | |
97cc4539 | 143 | |
144 | /* Assignment operators. */ | |
a543234d | 145 | DEF_ASSN_OPERATOR ("=", NOP_EXPR, "aS") |
146 | DEF_ASSN_OPERATOR ("+=", PLUS_EXPR, "pL") | |
147 | DEF_ASSN_OPERATOR ("-=", MINUS_EXPR, "mI") | |
148 | DEF_ASSN_OPERATOR ("*=", MULT_EXPR, "mL") | |
149 | DEF_ASSN_OPERATOR ("/=", TRUNC_DIV_EXPR, "dV") | |
150 | DEF_ASSN_OPERATOR ("%=", TRUNC_MOD_EXPR, "rM") | |
151 | DEF_ASSN_OPERATOR ("&=", BIT_AND_EXPR, "aN") | |
152 | DEF_ASSN_OPERATOR ("|=", BIT_IOR_EXPR, "oR") | |
153 | DEF_ASSN_OPERATOR ("^=", BIT_XOR_EXPR, "eO") | |
154 | DEF_ASSN_OPERATOR ("<<=", LSHIFT_EXPR, "lS") | |
155 | DEF_ASSN_OPERATOR (">>=", RSHIFT_EXPR, "rS") | |
156 | ||
157 | #undef DEF_ASSN_OPERATOR | |
158 | #undef DEF_OPERATOR |