operators.def 6.33 KB
Newer Older
1
/* -*-C-*-
2

3 4
   This file contains definitions of the various C++ operators,
   including both overloadable operators (like `+') and
5
   non-overloadable operators (like the `?:' ternary operator).
6
   Written by Mark Mitchell <mark@codesourcery.com>
7

8
   Copyright (C) 2000-2017 Free Software Foundation, Inc.
9

10
This file is part of GCC.
11

12
GCC is free software; you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
14
the Free Software Foundation; either version 3, or (at your option)
15 16
any later version.

17
GCC is distributed in the hope that it will be useful,
18 19 20 21 22
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
23 24
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
25 26 27 28 29 30

/* The DEF_OPERATOR macro takes the following arguments:

   NAME

     The name of the operator, as a C string, but without the
31
     preceding `operator'.  This is the name that would be given in
32 33
     the source program.  For `operator +', for example, this would be
     `+'.
34

35 36 37 38 39 40 41
   CODE

     The tree_code for this operator.  For `operator +', for example,
     this would be PLUS_EXPR.  Because there are no tree codes for
     assignment operators, the same tree-codes are reused; i.e.,
     `operator +' will also have PLUS_EXPR as its CODE.

42
   MANGLING
43 44 45 46 47 48

     The mangling prefix for the operator, as a C string, and as
     mangled under the new ABI.  For `operator +', for example, this
     would be "pl".

   ARITY
49

50 51 52 53 54 55
     The arity of the operator, or -1 if any arity is allowed.  (As
     for `operator ()'.)  Postincrement and postdecrement operators
     are marked as binary.

   ASSN_P

56
     A boolean value.  If nonzero, this is an assignment operator.
57

58
   Before including this file, you should define DEF_OPERATOR
59
   to take these arguments.
60 61 62

   There is code (such as in grok_op_properties) that depends on the
   order the operators are presented in this file.  In particular,
63
   unary operators must precede binary operators.  */
64

65 66 67 68
/* Use DEF_SIMPLE_OPERATOR to define a non-assignment operator.  Its
   arguments are as for DEF_OPERATOR, but there is no need to provide
   an ASSIGNMENT_P argument; it is always zero.  */

69 70
#define DEF_SIMPLE_OPERATOR(NAME, CODE, MANGLING, ARITY) \
  DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, 0)
71 72 73 74 75

/* Use DEF_ASSN_OPERATOR to define an assignment operator.  Its
   arguments are as for DEF_OPERATOR, but there is no need to provide
   an ASSIGNMENT_P argument; it is always one.  */

76 77
#define DEF_ASSN_OPERATOR(NAME, CODE, MANGLING, ARITY) \
  DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, 1)
78 79

/* Memory allocation operators.  */
80 81 82 83
DEF_SIMPLE_OPERATOR ("new", NEW_EXPR, "nw", -1)
DEF_SIMPLE_OPERATOR ("new []", VEC_NEW_EXPR, "na", -1)
DEF_SIMPLE_OPERATOR ("delete", DELETE_EXPR, "dl", -1)
DEF_SIMPLE_OPERATOR ("delete []", VEC_DELETE_EXPR, "da", -1)
84 85

/* Unary operators.  */
86
DEF_SIMPLE_OPERATOR ("+", UNARY_PLUS_EXPR, "ps", 1)
87 88 89 90 91 92 93 94
DEF_SIMPLE_OPERATOR ("-", NEGATE_EXPR, "ng", 1)
DEF_SIMPLE_OPERATOR ("&", ADDR_EXPR, "ad", 1)
DEF_SIMPLE_OPERATOR ("*", INDIRECT_REF, "de", 1)
DEF_SIMPLE_OPERATOR ("~", BIT_NOT_EXPR, "co", 1)
DEF_SIMPLE_OPERATOR ("!", TRUTH_NOT_EXPR, "nt", 1)
DEF_SIMPLE_OPERATOR ("++", PREINCREMENT_EXPR, "pp", 1)
DEF_SIMPLE_OPERATOR ("--", PREDECREMENT_EXPR, "mm", 1)
DEF_SIMPLE_OPERATOR ("sizeof", SIZEOF_EXPR, "sz", 1)
95
/* These are extensions.  */
96
DEF_SIMPLE_OPERATOR ("alignof", ALIGNOF_EXPR, "az", 1)
97 98
DEF_SIMPLE_OPERATOR ("__imag__", IMAGPART_EXPR, "v18__imag__", 1)
DEF_SIMPLE_OPERATOR ("__real__", REALPART_EXPR, "v18__real__", 1)
99 100

/* The cast operator.  */
101
DEF_SIMPLE_OPERATOR ("", TYPE_EXPR, "cv", 1)
102
DEF_SIMPLE_OPERATOR ("", CAST_EXPR, "cv", 1)
103 104 105 106
DEF_SIMPLE_OPERATOR ("dynamic_cast", DYNAMIC_CAST_EXPR, "dc", 1)
DEF_SIMPLE_OPERATOR ("reinterpret_cast", REINTERPRET_CAST_EXPR, "rc", 1)
DEF_SIMPLE_OPERATOR ("const_cast", CONST_CAST_EXPR, "cc", 1)
DEF_SIMPLE_OPERATOR ("static_cast", STATIC_CAST_EXPR, "sc", 1)
107 108

/* Binary operators.  */
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
DEF_SIMPLE_OPERATOR ("+", PLUS_EXPR, "pl", 2)
DEF_SIMPLE_OPERATOR ("-", MINUS_EXPR, "mi", 2)
DEF_SIMPLE_OPERATOR ("*", MULT_EXPR, "ml", 2)
DEF_SIMPLE_OPERATOR ("/", TRUNC_DIV_EXPR, "dv", 2)
DEF_SIMPLE_OPERATOR ("%", TRUNC_MOD_EXPR, "rm", 2)
DEF_SIMPLE_OPERATOR ("&", BIT_AND_EXPR, "an", 2)
DEF_SIMPLE_OPERATOR ("|", BIT_IOR_EXPR, "or", 2)
DEF_SIMPLE_OPERATOR ("^", BIT_XOR_EXPR, "eo", 2)
DEF_SIMPLE_OPERATOR ("<<", LSHIFT_EXPR, "ls", 2)
DEF_SIMPLE_OPERATOR (">>", RSHIFT_EXPR, "rs", 2)
DEF_SIMPLE_OPERATOR ("==", EQ_EXPR, "eq", 2)
DEF_SIMPLE_OPERATOR ("!=", NE_EXPR, "ne", 2)
DEF_SIMPLE_OPERATOR ("<", LT_EXPR, "lt", 2)
DEF_SIMPLE_OPERATOR (">", GT_EXPR, "gt", 2)
DEF_SIMPLE_OPERATOR ("<=", LE_EXPR, "le", 2)
DEF_SIMPLE_OPERATOR (">=", GE_EXPR, "ge", 2)
DEF_SIMPLE_OPERATOR ("&&", TRUTH_ANDIF_EXPR, "aa", 2)
DEF_SIMPLE_OPERATOR ("||", TRUTH_ORIF_EXPR, "oo", 2)
DEF_SIMPLE_OPERATOR (",", COMPOUND_EXPR, "cm", 2)
DEF_SIMPLE_OPERATOR ("->*", MEMBER_REF, "pm", 2)
129
DEF_SIMPLE_OPERATOR (".*", DOTSTAR_EXPR, "ds", 2)
130
DEF_SIMPLE_OPERATOR ("->", COMPONENT_REF, "pt", 2)
131 132 133
DEF_SIMPLE_OPERATOR ("[]", ARRAY_REF, "ix", 2)
DEF_SIMPLE_OPERATOR ("++", POSTINCREMENT_EXPR, "pp", 2)
DEF_SIMPLE_OPERATOR ("--", POSTDECREMENT_EXPR, "mm", 2)
134
/* This one is needed for mangling.  */
135
DEF_SIMPLE_OPERATOR ("::", SCOPE_REF, "sr", 2)
136 137

/* Assignment operators.  */
138 139 140 141 142 143 144 145 146 147 148
DEF_ASSN_OPERATOR ("=", NOP_EXPR, "aS", 2)
DEF_ASSN_OPERATOR ("+=", PLUS_EXPR, "pL", 2)
DEF_ASSN_OPERATOR ("-=", MINUS_EXPR, "mI", 2)
DEF_ASSN_OPERATOR ("*=", MULT_EXPR, "mL", 2)
DEF_ASSN_OPERATOR ("/=", TRUNC_DIV_EXPR, "dV", 2)
DEF_ASSN_OPERATOR ("%=", TRUNC_MOD_EXPR, "rM", 2)
DEF_ASSN_OPERATOR ("&=", BIT_AND_EXPR, "aN", 2)
DEF_ASSN_OPERATOR ("|=", BIT_IOR_EXPR, "oR", 2)
DEF_ASSN_OPERATOR ("^=", BIT_XOR_EXPR, "eO", 2)
DEF_ASSN_OPERATOR ("<<=", LSHIFT_EXPR, "lS", 2)
DEF_ASSN_OPERATOR (">>=", RSHIFT_EXPR, "rS", 2)
149 150

/* Ternary operators.  */
151
DEF_SIMPLE_OPERATOR ("?:", COND_EXPR, "qu", 3)
152 153

/* Miscellaneous.  */
154
DEF_SIMPLE_OPERATOR ("()", CALL_EXPR, "cl", -1)
155 156

/* Variadic templates extension. */
157
DEF_SIMPLE_OPERATOR ("...", EXPR_PACK_EXPANSION, "sp", 1)
158 159 160 161
DEF_SIMPLE_OPERATOR ("... +", UNARY_LEFT_FOLD_EXPR, "fl", 2)
DEF_SIMPLE_OPERATOR ("+ ...", UNARY_RIGHT_FOLD_EXPR, "fr", 2)
DEF_SIMPLE_OPERATOR ("+ ... +", BINARY_LEFT_FOLD_EXPR, "fL", 3)
DEF_SIMPLE_OPERATOR ("+ ... +", BINARY_RIGHT_FOLD_EXPR, "fR", 3)