190075Sobrien/* -*-C-*- 2169689Skan 390075Sobrien This file contains definitions of the various C++ operators, 490075Sobrien including both overloadable operators (like `+') and 5169689Skan non-overloadable operators (like the `?:' ternary operator). 6132718Skan Written by Mark Mitchell <mark@codesourcery.com> 790075Sobrien 8169689Skan Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. 990075Sobrien 10132718SkanThis file is part of GCC. 1190075Sobrien 12132718SkanGCC is free software; you can redistribute it and/or modify 1390075Sobrienit under the terms of the GNU General Public License as published by 1490075Sobrienthe Free Software Foundation; either version 2, or (at your option) 1590075Sobrienany later version. 1690075Sobrien 17132718SkanGCC is distributed in the hope that it will be useful, 1890075Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of 1990075SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2090075SobrienGNU General Public License for more details. 2190075Sobrien 2290075SobrienYou should have received a copy of the GNU General Public License 23132718Skanalong with GCC; see the file COPYING. If not, write to 24169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor, 25169689SkanBoston, MA 02110-1301, USA. */ 2690075Sobrien 2790075Sobrien/* The DEF_OPERATOR macro takes the following arguments: 2890075Sobrien 2990075Sobrien NAME 3090075Sobrien 3190075Sobrien The name of the operator, as a C string, but without the 3290075Sobrien preceding `operator'. This is the name that would be given in 3390075Sobrien the source program. For `operator +', for example, this would be 3490075Sobrien `+'. 35169689Skan 3690075Sobrien CODE 3790075Sobrien 3890075Sobrien The tree_code for this operator. For `operator +', for example, 3990075Sobrien this would be PLUS_EXPR. Because there are no tree codes for 4090075Sobrien assignment operators, the same tree-codes are reused; i.e., 4190075Sobrien `operator +' will also have PLUS_EXPR as its CODE. 4290075Sobrien 43110611Skan MANGLING 4490075Sobrien 4590075Sobrien The mangling prefix for the operator, as a C string, and as 4690075Sobrien mangled under the new ABI. For `operator +', for example, this 4790075Sobrien would be "pl". 4890075Sobrien 4990075Sobrien ARITY 50169689Skan 5190075Sobrien The arity of the operator, or -1 if any arity is allowed. (As 5290075Sobrien for `operator ()'.) Postincrement and postdecrement operators 5390075Sobrien are marked as binary. 5490075Sobrien 5590075Sobrien ASSN_P 5690075Sobrien 57117395Skan A boolean value. If nonzero, this is an assignment operator. 5890075Sobrien 5990075Sobrien Before including this file, you should define DEFOPERATOR 60169689Skan to take these arguments. 6190075Sobrien 6290075Sobrien There is code (such as in grok_op_properties) that depends on the 6390075Sobrien order the operators are presented in this file. In particular, 6490075Sobrien unary operators must precede binary operators. */ 65169689Skan 6690075Sobrien/* Use DEF_SIMPLE_OPERATOR to define a non-assignment operator. Its 6790075Sobrien arguments are as for DEF_OPERATOR, but there is no need to provide 6890075Sobrien an ASSIGNMENT_P argument; it is always zero. */ 6990075Sobrien 7090075Sobrien#define DEF_SIMPLE_OPERATOR(NAME, CODE, MANGLING, ARITY) \ 7190075Sobrien DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, 0) 7290075Sobrien 7390075Sobrien/* Use DEF_ASSN_OPERATOR to define an assignment operator. Its 7490075Sobrien arguments are as for DEF_OPERATOR, but there is no need to provide 7590075Sobrien an ASSIGNMENT_P argument; it is always one. */ 7690075Sobrien 7790075Sobrien#define DEF_ASSN_OPERATOR(NAME, CODE, MANGLING, ARITY) \ 7890075Sobrien DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, 1) 7990075Sobrien 8090075Sobrien/* Memory allocation operators. */ 8190075SobrienDEF_SIMPLE_OPERATOR ("new", NEW_EXPR, "nw", -1) 8290075SobrienDEF_SIMPLE_OPERATOR ("new []", VEC_NEW_EXPR, "na", -1) 8390075SobrienDEF_SIMPLE_OPERATOR ("delete", DELETE_EXPR, "dl", -1) 8490075SobrienDEF_SIMPLE_OPERATOR ("delete []", VEC_DELETE_EXPR, "da", -1) 8590075Sobrien 8690075Sobrien/* Unary operators. */ 87169689SkanDEF_SIMPLE_OPERATOR ("+", UNARY_PLUS_EXPR, "ps", 1) 8890075SobrienDEF_SIMPLE_OPERATOR ("-", NEGATE_EXPR, "ng", 1) 8990075SobrienDEF_SIMPLE_OPERATOR ("&", ADDR_EXPR, "ad", 1) 9090075SobrienDEF_SIMPLE_OPERATOR ("*", INDIRECT_REF, "de", 1) 9190075SobrienDEF_SIMPLE_OPERATOR ("~", BIT_NOT_EXPR, "co", 1) 9290075SobrienDEF_SIMPLE_OPERATOR ("!", TRUTH_NOT_EXPR, "nt", 1) 9390075SobrienDEF_SIMPLE_OPERATOR ("++", PREINCREMENT_EXPR, "pp", 1) 9490075SobrienDEF_SIMPLE_OPERATOR ("--", PREDECREMENT_EXPR, "mm", 1) 9590075SobrienDEF_SIMPLE_OPERATOR ("sizeof", SIZEOF_EXPR, "sz", 1) 96132718Skan/* These are extensions. */ 9790075SobrienDEF_SIMPLE_OPERATOR ("alignof", ALIGNOF_EXPR, "v17alignof", 1) 98132718SkanDEF_SIMPLE_OPERATOR ("__imag__", IMAGPART_EXPR, "v18__imag__", 1) 99132718SkanDEF_SIMPLE_OPERATOR ("__real__", REALPART_EXPR, "v18__real__", 1) 10090075Sobrien 10190075Sobrien/* The cast operator. */ 10290075SobrienDEF_SIMPLE_OPERATOR ("", TYPE_EXPR, "cv", 1) 10390075SobrienDEF_SIMPLE_OPERATOR ("", CAST_EXPR, "cv", 1) 10490075SobrienDEF_SIMPLE_OPERATOR ("", CONST_CAST_EXPR, "cv", 1) 10590075SobrienDEF_SIMPLE_OPERATOR ("", STATIC_CAST_EXPR, "cv", 1) 10690075Sobrien 10790075Sobrien/* Binary operators. */ 10890075SobrienDEF_SIMPLE_OPERATOR ("+", PLUS_EXPR, "pl", 2) 10990075SobrienDEF_SIMPLE_OPERATOR ("-", MINUS_EXPR, "mi", 2) 11090075SobrienDEF_SIMPLE_OPERATOR ("*", MULT_EXPR, "ml", 2) 11190075SobrienDEF_SIMPLE_OPERATOR ("/", TRUNC_DIV_EXPR, "dv", 2) 11290075SobrienDEF_SIMPLE_OPERATOR ("%", TRUNC_MOD_EXPR, "rm", 2) 11390075SobrienDEF_SIMPLE_OPERATOR ("&", BIT_AND_EXPR, "an", 2) 11490075SobrienDEF_SIMPLE_OPERATOR ("|", BIT_IOR_EXPR, "or", 2) 11590075SobrienDEF_SIMPLE_OPERATOR ("^", BIT_XOR_EXPR, "eo", 2) 11690075SobrienDEF_SIMPLE_OPERATOR ("<<", LSHIFT_EXPR, "ls", 2) 11790075SobrienDEF_SIMPLE_OPERATOR (">>", RSHIFT_EXPR, "rs", 2) 11890075SobrienDEF_SIMPLE_OPERATOR ("==", EQ_EXPR, "eq", 2) 11990075SobrienDEF_SIMPLE_OPERATOR ("!=", NE_EXPR, "ne", 2) 12090075SobrienDEF_SIMPLE_OPERATOR ("<", LT_EXPR, "lt", 2) 12190075SobrienDEF_SIMPLE_OPERATOR (">", GT_EXPR, "gt", 2) 12290075SobrienDEF_SIMPLE_OPERATOR ("<=", LE_EXPR, "le", 2) 12390075SobrienDEF_SIMPLE_OPERATOR (">=", GE_EXPR, "ge", 2) 12490075SobrienDEF_SIMPLE_OPERATOR ("&&", TRUTH_ANDIF_EXPR, "aa", 2) 12590075SobrienDEF_SIMPLE_OPERATOR ("||", TRUTH_ORIF_EXPR, "oo", 2) 12690075SobrienDEF_SIMPLE_OPERATOR (",", COMPOUND_EXPR, "cm", 2) 12790075SobrienDEF_SIMPLE_OPERATOR ("->*", MEMBER_REF, "pm", 2) 12890075SobrienDEF_SIMPLE_OPERATOR ("->", COMPONENT_REF, "pt", 2) 12990075SobrienDEF_SIMPLE_OPERATOR ("[]", ARRAY_REF, "ix", 2) 13090075SobrienDEF_SIMPLE_OPERATOR ("++", POSTINCREMENT_EXPR, "pp", 2) 13190075SobrienDEF_SIMPLE_OPERATOR ("--", POSTDECREMENT_EXPR, "mm", 2) 13290075Sobrien/* This one is needed for mangling. */ 133132718SkanDEF_SIMPLE_OPERATOR ("::", SCOPE_REF, "sr", 2) 13490075Sobrien 13590075Sobrien/* Assignment operators. */ 13690075SobrienDEF_ASSN_OPERATOR ("=", NOP_EXPR, "aS", 2) 13790075SobrienDEF_ASSN_OPERATOR ("+=", PLUS_EXPR, "pL", 2) 13890075SobrienDEF_ASSN_OPERATOR ("-=", MINUS_EXPR, "mI", 2) 13990075SobrienDEF_ASSN_OPERATOR ("*=", MULT_EXPR, "mL", 2) 14090075SobrienDEF_ASSN_OPERATOR ("/=", TRUNC_DIV_EXPR, "dV", 2) 14190075SobrienDEF_ASSN_OPERATOR ("%=", TRUNC_MOD_EXPR, "rM", 2) 14290075SobrienDEF_ASSN_OPERATOR ("&=", BIT_AND_EXPR, "aN", 2) 14390075SobrienDEF_ASSN_OPERATOR ("|=", BIT_IOR_EXPR, "oR", 2) 14490075SobrienDEF_ASSN_OPERATOR ("^=", BIT_XOR_EXPR, "eO", 2) 14590075SobrienDEF_ASSN_OPERATOR ("<<=", LSHIFT_EXPR, "lS", 2) 14690075SobrienDEF_ASSN_OPERATOR (">>=", RSHIFT_EXPR, "rS", 2) 14790075Sobrien 14890075Sobrien/* Ternary operators. */ 14990075SobrienDEF_SIMPLE_OPERATOR ("?:", COND_EXPR, "qu", 3) 15090075Sobrien 15190075Sobrien/* Miscellaneous. */ 15290075SobrienDEF_SIMPLE_OPERATOR ("()", CALL_EXPR, "cl", -1) 153