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