1 /* Convert language-specific tree expression to rtl instructions, 2 for GNU compiler. 3 Copyright (C) 1988-2013 Free Software Foundation, Inc. 4 5 This file is part of GCC. 6 7 GCC is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3, or (at your option) 10 any later version. 11 12 GCC is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with GCC; see the file COPYING3. If not see 19 <http://www.gnu.org/licenses/>. */ 20 21 22 #include "config.h" 23 #include "system.h" 24 #include "coretypes.h" 25 #include "tm.h" 26 #include "tree.h" 27 #include "flags.h" 28 #include "cp-tree.h" 29 #include "tm_p.h" 30 31 /* Expand C++-specific constants. Currently, this means PTRMEM_CST. */ 32 33 tree 34 cplus_expand_constant (tree cst) 35 { 36 switch (TREE_CODE (cst)) 37 { 38 case PTRMEM_CST: 39 { 40 tree type = TREE_TYPE (cst); 41 tree member; 42 43 /* Find the member. */ 44 member = PTRMEM_CST_MEMBER (cst); 45 46 if (TREE_CODE (member) == FIELD_DECL) 47 { 48 /* Find the offset for the field. */ 49 cst = byte_position (member); 50 while (!same_type_p (DECL_CONTEXT (member), 51 TYPE_PTRMEM_CLASS_TYPE (type))) 52 { 53 /* The MEMBER must have been nestled within an 54 anonymous aggregate contained in TYPE. Find the 55 anonymous aggregate. */ 56 member = lookup_anon_field (TYPE_PTRMEM_CLASS_TYPE (type), 57 DECL_CONTEXT (member)); 58 cst = size_binop (PLUS_EXPR, cst, byte_position (member)); 59 } 60 cst = fold (build_nop (type, cst)); 61 } 62 else 63 { 64 tree delta; 65 tree pfn; 66 67 expand_ptrmemfunc_cst (cst, &delta, &pfn); 68 cst = build_ptrmemfunc1 (type, delta, pfn); 69 } 70 } 71 break; 72 73 default: 74 /* There's nothing to do. */ 75 break; 76 } 77 78 return cst; 79 } 80 81 /* Called whenever an expression is used 82 in a rvalue context. */ 83 84 tree 85 mark_rvalue_use (tree expr) 86 { 87 mark_exp_read (expr); 88 return expr; 89 } 90 91 /* Called whenever an expression is used 92 in a lvalue context. */ 93 94 tree 95 mark_lvalue_use (tree expr) 96 { 97 mark_exp_read (expr); 98 return expr; 99 } 100 101 /* Called whenever an expression is used in a type use context. */ 102 103 tree 104 mark_type_use (tree expr) 105 { 106 mark_exp_read (expr); 107 return expr; 108 } 109 110 /* Mark EXP as read, not just set, for set but not used -Wunused 111 warning purposes. */ 112 113 void 114 mark_exp_read (tree exp) 115 { 116 if (exp == NULL) 117 return; 118 119 switch (TREE_CODE (exp)) 120 { 121 case VAR_DECL: 122 case PARM_DECL: 123 DECL_READ_P (exp) = 1; 124 break; 125 case ARRAY_REF: 126 case COMPONENT_REF: 127 case MODIFY_EXPR: 128 case REALPART_EXPR: 129 case IMAGPART_EXPR: 130 CASE_CONVERT: 131 case ADDR_EXPR: 132 case INDIRECT_REF: 133 case FLOAT_EXPR: 134 mark_exp_read (TREE_OPERAND (exp, 0)); 135 break; 136 case COMPOUND_EXPR: 137 mark_exp_read (TREE_OPERAND (exp, 1)); 138 break; 139 case COND_EXPR: 140 if (TREE_OPERAND (exp, 1)) 141 mark_exp_read (TREE_OPERAND (exp, 1)); 142 if (TREE_OPERAND (exp, 2)) 143 mark_exp_read (TREE_OPERAND (exp, 2)); 144 break; 145 default: 146 break; 147 } 148 } 149 150