OSDN Git Service

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